Created
December 26, 2023 12:08
-
-
Save marlosirapuan/16200d2f82ccf9db474b625ec16ac8cf to your computer and use it in GitHub Desktop.
Money Input for Mantine UI
This file contains 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
// calc values divided by 100, ex: | |
// defaultValue={item.price / 100} | |
// values.item.price / 100 | |
import { forwardRef } from 'react' | |
import { CurrencyInput, ICurrencyMaskProps } from 'react-currency-mask' | |
import { MantineSize, TextInput, TextInputProps } from '@mantine/core' | |
type MoneyInputComponentProps = ICurrencyMaskProps & | |
TextInputProps & { | |
size?: MantineSize | |
} | |
export const MoneyInputComponent: React.ForwardRefRenderFunction<HTMLInputElement, MoneyInputComponentProps> = ( | |
// eslint-disable-next-line react/prop-types | |
{ size = 'xs', ...rest }, | |
ref | |
) => { | |
return <CurrencyInput ref={ref} {...rest} InputElement={<TextInput size={size} />} /> | |
} | |
export const MoneyInput = forwardRef(MoneyInputComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and yes. you should install
react-currency-mask