UNPKG

koval-ui

Version:

React components collection with minimalistic design. Supports theming, layout, and input validation.

1 lines 2.56 kB
{"version":3,"file":"NameTime.cjs","sources":["../../../../src/lib/Name/NameTime.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} from '@/internal/locale';\n\nimport type {Styles, TimePeriods} 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 * Define a time period name to localize\n */\n timePeriod: keyof typeof TimePeriods;\n };\n\nexport const NameTime = forwardRef<HTMLDivElement, Props>(\n ({className, locale: localeProp, timePeriod, style, ...nativeProps}, ref) => {\n const userLocale = useBrowserLocale();\n const locale = localeProp ? localeProp : userLocale;\n const formattedValue = useMemo(\n () => new Intl.DisplayNames(locale, {type: 'dateTimeField', style}).of(timePeriod),\n [timePeriod, locale, style]\n );\n\n return (\n <span {...nativeProps} className={classNames(classes.name, className)} ref={ref}>\n {formattedValue}\n </span>\n );\n }\n);\n\nNameTime.displayName = 'NameTime';\n"],"names":["NameTime","forwardRef","className","localeProp","timePeriod","style","nativeProps","ref","userLocale","useBrowserLocale","locale","formattedValue","useMemo","jsx","classNames","classes"],"mappings":"wQA6BaA,EAAWC,EAAA,WACpB,CAAC,CAAC,UAAAC,EAAW,OAAQC,EAAY,WAAAC,EAAY,MAAAC,EAAO,GAAGC,CAAW,EAAGC,IAAQ,CACzE,MAAMC,EAAaC,EAAAA,iBAAiB,EAC9BC,EAASP,GAA0BK,EACnCG,EAAiBC,EAAA,QACnB,IAAM,IAAI,KAAK,aAAaF,EAAQ,CAAC,KAAM,gBAAiB,MAAAL,CAAM,CAAA,EAAE,GAAGD,CAAU,EACjF,CAACA,EAAYM,EAAQL,CAAK,CAC9B,EAGI,OAAAQ,EAAA,IAAC,OAAM,CAAA,GAAGP,EAAa,UAAWQ,EAAWC,UAAQ,KAAMb,CAAS,EAAG,IAAAK,EAClE,SACLI,CAAA,CAAA,CAAA,CAGZ,EAEAX,EAAS,YAAc"}