UNPKG

koval-ui

Version:

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

1 lines 3.9 kB
{"version":3,"file":"DateTime.cjs","sources":["../../../../src/lib/DateTime/DateTime.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 classes from './DateTime.module.css';\nimport type {DateFormatOptions} from './types.ts';\n\nexport type Props = DataAttributes &\n LibraryProps & {\n /**\n * String representing the date in a simplified format based on ISO 8601.\n * Is always 24 or 27 characters long.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format\n * @see https://en.wikipedia.org/wiki/ISO_8601\n */\n value?: string;\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/DateTimeFormat/DateTimeFormat#locales\n */\n locale?: Locale;\n /**\n * Prevents line wrapping of formatted dates and times\n */\n enableNoWrap?: boolean;\n } & DateFormatOptions;\n\nexport const DateTime = forwardRef<HTMLSpanElement, Props>(\n (\n {\n className,\n locale: localeProp,\n value = '',\n weekday,\n era,\n year,\n month,\n day,\n hour,\n minute,\n second,\n timeZoneName,\n hour12,\n timeZone,\n enableNoWrap = true,\n ...nativeProps\n },\n ref\n ) => {\n const userLocale = useBrowserLocale();\n const locale = localeProp ? localeProp : userLocale;\n const date = useMemo(() => new Date(value), [value]);\n const formattedValue = new Intl.DateTimeFormat(locale, {\n weekday,\n era,\n year,\n month,\n day,\n hour,\n minute,\n second,\n timeZoneName,\n hour12,\n timeZone,\n }).format(date);\n return (\n value && (\n <span\n {...nativeProps}\n className={classNames(\n classes.number,\n {[classes.noWrap]: enableNoWrap},\n className\n )}\n ref={ref}>\n {formattedValue}\n </span>\n )\n );\n }\n);\n\nDateTime.displayName = 'DateTime';\n"],"names":["DateTime","forwardRef","className","localeProp","value","weekday","era","year","month","day","hour","minute","second","timeZoneName","hour12","timeZone","enableNoWrap","nativeProps","ref","userLocale","useBrowserLocale","locale","date","useMemo","formattedValue","jsx","classNames","classes"],"mappings":"4QA+BaA,EAAWC,EAAA,WACpB,CACI,CACI,UAAAC,EACA,OAAQC,EACR,MAAAC,EAAQ,GACR,QAAAC,EACA,IAAAC,EACA,KAAAC,EACA,MAAAC,EACA,IAAAC,EACA,KAAAC,EACA,OAAAC,EACA,OAAAC,EACA,aAAAC,EACA,OAAAC,EACA,SAAAC,EACA,aAAAC,EAAe,GACf,GAAGC,GAEPC,IACC,CACD,MAAMC,EAAaC,EAAAA,iBAAiB,EAC9BC,EAASlB,GAA0BgB,EACnCG,EAAOC,EAAAA,QAAQ,IAAM,IAAI,KAAKnB,CAAK,EAAG,CAACA,CAAK,CAAC,EAC7CoB,EAAiB,IAAI,KAAK,eAAeH,EAAQ,CACnD,QAAAhB,EACA,IAAAC,EACA,KAAAC,EACA,MAAAC,EACA,IAAAC,EACA,KAAAC,EACA,OAAAC,EACA,OAAAC,EACA,aAAAC,EACA,OAAAC,EACA,SAAAC,CAAA,CACH,EAAE,OAAOO,CAAI,EACd,OACIlB,GACIqB,EAAA,IAAC,OAAA,CACI,GAAGR,EACJ,UAAWS,EACPC,EAAAA,QAAQ,OACR,CAAC,CAACA,EAAAA,QAAQ,MAAM,EAAGX,CAAY,EAC/Bd,CACJ,EACA,IAAAgB,EACC,SAAAM,CAAA,CACL,CAAA,CAIhB,EAEAxB,EAAS,YAAc"}