Skip to content

Commit

Permalink
- Update readme for linking the documentation in better way.
Browse files Browse the repository at this point in the history
- Added allowEmptyFormatting prop customization doc for NumericFormat
  • Loading branch information
s-yadav committed Aug 5, 2023
1 parent 29cc1d2 commit 1d1171f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# react-number-format

React Number Format is an input-formatter library with a sophisticated and light weight caret engine. It ensures that a user can only enter text that meets specific numeric or string patterns, and formats the input value for display.
React Number Format is an input-formatter library with a sophisticated and light weight caret engine. It ensures that a user can only enter text that meets specific numeric or string patterns, and formats the input value for display.

### Features

Expand Down Expand Up @@ -33,6 +33,11 @@ Using `yarn`
yarn add react-number-format
```

### Documentation

Read the full documentation here
[https://s-yadav.github.io/react-number-format/docs/intro](https://s-yadav.github.io/react-number-format/docs/intro)

#### ES6

Numeric Format
Expand All @@ -41,15 +46,15 @@ Numeric Format
import { NumericFormat } from 'react-number-format';
```

NumericFormat Props: [https://s-yadav.github.io/react-number-format/docs/numeric_format](https://s-yadav.github.io/react-number-format/docs/numeric_format)

Pattern Format

```js
import { PatternFormat } from 'react-number-format';
```

Read the full documentation here

[https://s-yadav.github.io/react-number-format/docs/intro](https://s-yadav.github.io/react-number-format/docs/intro)
PatternFormat Props: [https://s-yadav.github.io/react-number-format/docs/pattern_format](https://s-yadav.github.io/react-number-format/docs/pattern_format)

### Migrate from v4 to v5

Expand Down
29 changes: 29 additions & 0 deletions documentation/v5/docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,32 @@ function CustomNumeralNumericFormat(props) {
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
</details>
### AllowEmptyFormatting on NumericFormat

Currently allowEmptyFormatting is only available on the pattern lock, while it isn't a common usecase in NumericFormat, you still might want that behavior, you can achieve it like following.

```js
function CustomNumberFormat(props) {
const { prefix = '', suffix = '', allowEmptyFormatting } = props;
const { format, ...numberFormatBaseProps } = useNumericFormat(props);
const _format = (numStr, props) => {
const formattedValue = format(numStr, props);
return allowEmptyFormatting && formattedValue === '' ? prefix + suffix : formattedValue;
};

return <NumberFormatBase {...numberFormatBaseProps} format={_format} />;
}
```

<details>
<summary>
Demo
</summary>
<iframe src="https://codesandbox.io/embed/numeric-format-allowemptyformat-zt3mh8?fontsize=14&hidenavigation=1&theme=dark&view=preview"
title="Custom Numeral (Numer Format)"
className="csb"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
</details>

0 comments on commit 1d1171f

Please sign in to comment.