Created
May 26, 2022 15:20
-
-
Save arky/ace36ceac31f89e01ceb8cb8b5eabeeb to your computer and use it in GitHub Desktop.
React Number input with support for abbreviations k, m and b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import CurrencyInput from 'react-currency-input-field'; | |
import { FormFieldWrapper } from '@plone/volto/components'; | |
const CurrencyWidget = (props) => { | |
const { id, value, isDisabled, onClick, onChange, maximum, minimum } = props; | |
return ( | |
<FormFieldWrapper {...props}> | |
<CurrencyInput | |
id={`field-${id}`} | |
name={id} | |
type="number" | |
disabled={isDisabled} | |
defaultValue={value} | |
allowDecimals={true} | |
decimalsLimit={2} | |
onChange={({ target }) => | |
onChange(id, target.value === '' ? undefined : target.value) | |
} | |
onBlur={({ target }) => | |
onBlur(id, target.value === '' ? undefined : target.value) | |
} | |
onClick={() => onClick()} | |
/> | |
</FormFieldWrapper> | |
); | |
}; | |
export default CurrencyWidget; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment