An open API service indexing awesome lists of open source software.

https://github.com/ozluy/calculate-text-width

Function that calculates width of typed text. Auto calculate input width.
https://github.com/ozluy/calculate-text-width

auto-width autoresize calculate input react-input-autowidth react-input-size text text-width width width-calculation

Last synced: 3 months ago
JSON representation

Function that calculates width of typed text. Auto calculate input width.

Awesome Lists containing this project

README

        

# Calculate Text Width
Function that calculates width of typed text

[![npm version](https://badge.fury.io/js/calculate-text-width.svg)](https://badge.fury.io/js/calculate-text-width)
![npm download](https://img.shields.io/npm/dt/calculate-text-width.svg)

Code Sandbox Demo

How to use
===

```js
import calculateTextWidth from "calculate-text-width";

/*
requires two props "value" and "font"
- defaultFont: normal 500 14px sans-serif
*/
const calculatedWidth = calculateTextWidth('calculate my width', 'normal 500 14px sans-serif')
console.log(calculatedWidth) // 114.37890625

```

How to use with React
===

```jsx
import React, { useState, useMemo } from "react"
import calculateTextWidth from "calculate-text-width"

export default () => {
const [value, setValue] = useState("change me")

return (
<>

Calcule Text Width


setValue(evt.target.value)}
/>
>
)
}

```

Thank you

#### Yusuf Özlü