UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 2.29 kB
{"version":3,"file":"NumberFormatter.cjs","names":["useProps","NumericFormat"],"sources":["../../../src/components/NumberFormatter/NumberFormatter.tsx"],"sourcesContent":["import { NumericFormat } from 'react-number-format';\nimport { ExtendComponent, Factory, MantineThemeComponent, useProps } from '../../core';\n\nexport interface NumberFormatterProps extends React.ComponentProps<'span'> {\n /** Value to format */\n value?: number | string;\n\n /** If set, negative values are allowed @default true */\n allowNegative?: boolean;\n\n /** Limits the number of digits that are displayed after the decimal point @default Infinity */\n decimalScale?: number;\n\n /** Character used as a decimal separator, `'.'` by default */\n decimalSeparator?: string;\n\n /** If set, zeros are added after `decimalSeparator` to match given `decimalScale`. @default false */\n fixedDecimalScale?: boolean;\n\n /** Prefix added before the value */\n prefix?: string;\n\n /** Suffix added after the value */\n suffix?: string;\n\n /** Defines the thousand grouping style */\n thousandsGroupStyle?: 'thousand' | 'lakh' | 'wan' | 'none';\n\n /** A character used to separate thousands @default ',' */\n thousandSeparator?: string | boolean;\n}\n\nexport type NumberFormatterFactory = Factory<{\n props: NumberFormatterProps;\n ref: HTMLDivElement;\n}>;\n\nexport function NumberFormatter(_props: NumberFormatterProps) {\n const { value, defaultValue, ...others } = useProps('NumberFormatter', null, _props);\n\n if (value === undefined) {\n return null;\n }\n\n return <NumericFormat displayType=\"text\" value={value} {...others} />;\n}\n\nconst extendNumberFormatter = (c: ExtendComponent<NumberFormatterFactory>): MantineThemeComponent =>\n c;\n\nNumberFormatter.extend = extendNumberFormatter;\nNumberFormatter.displayName = '@mantine/core/NumberFormatter';\n\nexport namespace NumberFormatter {\n export type Props = NumberFormatterProps;\n export type Factory = NumberFormatterFactory;\n}\n"],"mappings":";;;;;;AAqCA,SAAgB,gBAAgB,QAA8B;CAC5D,MAAM,EAAE,OAAO,cAAc,GAAG,WAAWA,kBAAAA,SAAS,mBAAmB,MAAM,OAAO;AAEpF,KAAI,UAAU,KAAA,EACZ,QAAO;AAGT,QAAO,iBAAA,GAAA,kBAAA,KAACC,oBAAAA,eAAD;EAAe,aAAY;EAAc;EAAO,GAAI;EAAU,CAAA;;AAGvE,MAAM,yBAAyB,MAC7B;AAEF,gBAAgB,SAAS;AACzB,gBAAgB,cAAc"}