Skip to content

Instantly share code, notes, and snippets.

@marlosirapuan
Created December 26, 2023 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marlosirapuan/16200d2f82ccf9db474b625ec16ac8cf to your computer and use it in GitHub Desktop.
Save marlosirapuan/16200d2f82ccf9db474b625ec16ac8cf to your computer and use it in GitHub Desktop.
Money Input for Mantine UI
// 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)
@marlosirapuan
Copy link
Author

and yes. you should install react-currency-mask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment