koval-ui
Version:
React components collection with minimalistic design. Supports theming, layout, and input validation.
1 lines • 2.67 kB
Source Map (JSON)
{"version":3,"file":"NameCurrency.cjs","sources":["../../../../src/lib/Name/NameCurrency.tsx"],"sourcesContent":["import {forwardRef, useMemo} from 'react';\nimport classNames from 'classnames';\n\nimport type {DataAttributes, LibraryProps} from '@/internal/LibraryAPI';\nimport {useBrowserLocale} from '@/internal/locale';\nimport type {Locale, CurrencyCodes} from '@/internal/locale';\n\nimport type {Styles} from './types.ts';\nimport classes from './Name.module.css';\n\nexport type Props = DataAttributes &\n LibraryProps & {\n /**\n * Provide a string with a BCP 47 language tag or an Intl.Locale instance,\n * or an array of such locale identifiers. Defaults to user setting\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#locales\n */\n locale?: Locale;\n /**\n * Select the formatting style to use.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#style\n */\n style?: keyof typeof Styles;\n /**\n * Provide a three-letter ISO 4217 currency code\n * @see https://www.iso.org/iso-4217-currency-codes.html\n */\n currencyCode: keyof typeof CurrencyCodes;\n };\n\nexport const NameCurrency = forwardRef<HTMLDivElement, Props>(\n ({className, locale: localeProp, currencyCode, style, ...nativeProps}, ref) => {\n const userLocale = useBrowserLocale();\n const locale = localeProp ? localeProp : userLocale;\n const formattedValue = useMemo(\n () => new Intl.DisplayNames(locale, {type: 'currency', style}).of(currencyCode),\n [currencyCode, locale, style]\n );\n\n return (\n <span {...nativeProps} className={classNames(classes.name, className)} ref={ref}>\n {formattedValue}\n </span>\n );\n }\n);\n\nNameCurrency.displayName = 'NameCurrency';\n"],"names":["NameCurrency","forwardRef","className","localeProp","currencyCode","style","nativeProps","ref","userLocale","useBrowserLocale","locale","formattedValue","useMemo","jsx","classNames","classes"],"mappings":"wQA8BaA,EAAeC,EAAA,WACxB,CAAC,CAAC,UAAAC,EAAW,OAAQC,EAAY,aAAAC,EAAc,MAAAC,EAAO,GAAGC,CAAW,EAAGC,IAAQ,CAC3E,MAAMC,EAAaC,EAAAA,iBAAiB,EAC9BC,EAASP,GAA0BK,EACnCG,EAAiBC,EAAA,QACnB,IAAM,IAAI,KAAK,aAAaF,EAAQ,CAAC,KAAM,WAAY,MAAAL,CAAM,CAAA,EAAE,GAAGD,CAAY,EAC9E,CAACA,EAAcM,EAAQL,CAAK,CAChC,EAGI,OAAAQ,EAAA,IAAC,OAAM,CAAA,GAAGP,EAAa,UAAWQ,EAAWC,UAAQ,KAAMb,CAAS,EAAG,IAAAK,EAClE,SACLI,CAAA,CAAA,CAAA,CAGZ,EAEAX,EAAa,YAAc"}