Skip to content

Instantly share code, notes, and snippets.

@arky
Created May 26, 2022 15:20
Show Gist options
  • Save arky/ace36ceac31f89e01ceb8cb8b5eabeeb to your computer and use it in GitHub Desktop.
Save arky/ace36ceac31f89e01ceb8cb8b5eabeeb to your computer and use it in GitHub Desktop.
React Number input with support for abbreviations k, m and b
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