koval-ui
Version:
React components collection with minimalistic design. Supports theming, layout, and input validation.
1 lines • 2.29 kB
Source Map (JSON)
{"version":3,"file":"NameRegion.cjs","sources":["../../../../src/lib/Name/NameRegion.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, CountryCodes} from '@/internal/locale';\n\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 * Provide a two-letter ISO 3166 region code\n * @see https://www.iso.org/iso-3166-country-codes.html\n */\n countryCode: keyof typeof CountryCodes;\n };\n\nexport const NameRegion = forwardRef<HTMLDivElement, Props>(\n ({className, locale: localeProp, countryCode, ...nativeProps}, ref) => {\n const userLocale = useBrowserLocale();\n const locale = localeProp ? localeProp : userLocale;\n const formattedValue = useMemo(\n () => new Intl.DisplayNames(locale, {type: 'region'}).of(countryCode),\n [countryCode, locale]\n );\n\n return (\n <span {...nativeProps} className={classNames(classes.name, className)} ref={ref}>\n {formattedValue}\n </span>\n );\n }\n);\n\nNameRegion.displayName = 'NameRegion';\n"],"names":["NameRegion","forwardRef","className","localeProp","countryCode","nativeProps","ref","userLocale","useBrowserLocale","locale","formattedValue","useMemo","jsx","classNames","classes"],"mappings":"wQAwBaA,EAAaC,EAAA,WACtB,CAAC,CAAC,UAAAC,EAAW,OAAQC,EAAY,YAAAC,EAAa,GAAGC,CAAW,EAAGC,IAAQ,CACnE,MAAMC,EAAaC,EAAAA,iBAAiB,EAC9BC,EAASN,GAA0BI,EACnCG,EAAiBC,EAAA,QACnB,IAAM,IAAI,KAAK,aAAaF,EAAQ,CAAC,KAAM,QAAS,CAAA,EAAE,GAAGL,CAAW,EACpE,CAACA,EAAaK,CAAM,CACxB,EAGI,OAAAG,EAAA,IAAC,OAAM,CAAA,GAAGP,EAAa,UAAWQ,EAAWC,UAAQ,KAAMZ,CAAS,EAAG,IAAAI,EAClE,SACLI,CAAA,CAAA,CAAA,CAGZ,EAEAV,EAAW,YAAc"}