@fuf-stack/uniform 2.0.0-next.3 → 2.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Checkboxes/index.d.mts +50 -50
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +14 -12
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +27 -90
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +31 -39
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.d.mts +6 -6
- package/dist/FieldArray/index.mjs +19 -17
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.mjs +10 -13
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/FieldHelper-B1DWl7eu.mjs +38 -0
- package/dist/FieldHelper-B1DWl7eu.mjs.map +1 -0
- package/dist/FieldLabel-DMTqq0Jj.mjs +29 -0
- package/dist/FieldLabel-DMTqq0Jj.mjs.map +1 -0
- package/dist/{FieldLayout-DcvQU0zN.mjs → FieldLayout-C9MEBZAC.mjs} +10 -17
- package/dist/FieldLayout-C9MEBZAC.mjs.map +1 -0
- package/dist/FieldReset/index.d.mts +1 -1
- package/dist/FieldReset/index.mjs +1 -1
- package/dist/{FieldValidationError-iAayfTEw.mjs → FieldValidationError-BuLvuRyi.mjs} +3 -3
- package/dist/FieldValidationError-BuLvuRyi.mjs.map +1 -0
- package/dist/Form/index.d.mts +2 -2
- package/dist/Form/index.mjs +4 -4
- package/dist/Form/index.mjs.map +1 -1
- package/dist/{FormContext-PXkVlBdU.mjs → FormContext-CVq3glVW.mjs} +5 -5
- package/dist/FormContext-CVq3glVW.mjs.map +1 -0
- package/dist/{FormContext-BnNJYZOo.d.mts → FormContext-Dvt3MiKq.d.mts} +3 -3
- package/dist/{FormContext-BnNJYZOo.d.mts.map → FormContext-Dvt3MiKq.d.mts.map} +1 -1
- package/dist/Input/index.d.mts +583 -418
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +16 -19
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +101 -85
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +6 -14
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +590 -335
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +15 -15
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +52 -49
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +5 -13
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +762 -570
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +14 -15
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +658 -348
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +24 -32
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +1 -1
- package/dist/Switch/index.mjs +12 -17
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-3ujfKWwt.d.mts +990 -0
- package/dist/{Switch-Db2dpGz7.d.mts.map → Switch-3ujfKWwt.d.mts.map} +1 -1
- package/dist/SwitchBox/index.d.mts +583 -221
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +14 -18
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +544 -207
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +13 -16
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +47 -47
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +17 -22
- package/dist/Time/index.mjs.map +1 -1
- package/dist/fieldHelperVariants-ClP8taiS.mjs +20 -0
- package/dist/fieldHelperVariants-ClP8taiS.mjs.map +1 -0
- package/dist/fieldLabelVariants-C4ZqECec.mjs +13 -0
- package/dist/fieldLabelVariants-C4ZqECec.mjs.map +1 -0
- package/dist/{FieldDescription-X_0s1Lhu.mjs → fieldProps-DWfz2jSO.mjs} +2 -13
- package/dist/fieldProps-DWfz2jSO.mjs.map +1 -0
- package/dist/hooks/useClientValidation/index.mjs +1 -1
- package/dist/hooks/useController/index.mjs +1 -1
- package/dist/hooks/useFormContext/index.d.mts +1 -1
- package/dist/hooks/useFormContext/index.mjs +1 -1
- package/dist/hooks/useInputValueDebounce/index.mjs +1 -1
- package/dist/hooks/useWatchFormReset/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs +1 -1
- package/dist/{Switch-Db2dpGz7.d.mts → partials/FieldHelper/index.d.mts} +308 -407
- package/dist/partials/FieldHelper/index.d.mts.map +1 -0
- package/dist/partials/FieldHelper/index.mjs +7 -0
- package/dist/partials/FieldHelper/index.mjs.map +1 -0
- package/dist/partials/FieldLabel/index.d.mts +160 -0
- package/dist/partials/FieldLabel/index.d.mts.map +1 -0
- package/dist/partials/FieldLabel/index.mjs +7 -0
- package/dist/partials/FieldLabel/index.mjs.map +1 -0
- package/dist/partials/FieldValidationError/index.d.mts +13 -13
- package/dist/partials/FieldValidationError/index.mjs +1 -1
- package/dist/{radioControlVariants-BYRfaD6y.mjs → radioControlVariants-CxA0og5-.mjs} +16 -12
- package/dist/radioControlVariants-CxA0og5-.mjs.map +1 -0
- package/dist/{switchVariants-D16b2VaT.mjs → switchVariants-B8dq8DYP.mjs} +12 -15
- package/dist/switchVariants-B8dq8DYP.mjs.map +1 -0
- package/dist/{timeVariants-CtXyNKmW.mjs → timeVariants-CIX6R59-.mjs} +17 -15
- package/dist/timeVariants-CIX6R59-.mjs.map +1 -0
- package/dist/{useController-JtIeurpw.mjs → useController-SEAuP3G4.mjs} +6 -6
- package/dist/useController-SEAuP3G4.mjs.map +1 -0
- package/dist/{useFormContext-piqnN2L-.mjs → useFormContext-CQzJhAU4.mjs} +12 -8
- package/dist/useFormContext-CQzJhAU4.mjs.map +1 -0
- package/dist/{FieldLabel-DrNWJIVh.mjs → useUniformField-BvPoQyLL.mjs} +6 -31
- package/dist/useUniformField-BvPoQyLL.mjs.map +1 -0
- package/package.json +6 -4
- package/dist/FieldDescription-X_0s1Lhu.mjs.map +0 -1
- package/dist/FieldLabel-DrNWJIVh.mjs.map +0 -1
- package/dist/FieldLayout-DcvQU0zN.mjs.map +0 -1
- package/dist/FieldValidationError-iAayfTEw.mjs.map +0 -1
- package/dist/FormContext-PXkVlBdU.mjs.map +0 -1
- package/dist/radioControlVariants-BYRfaD6y.mjs.map +0 -1
- package/dist/switchVariants-D16b2VaT.mjs.map +0 -1
- package/dist/timeVariants-CtXyNKmW.mjs.map +0 -1
- package/dist/useController-JtIeurpw.mjs.map +0 -1
- package/dist/useFormContext-piqnN2L-.mjs.map +0 -1
package/dist/Time/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/Time/timeHelpers.ts","../../src/Time/subcomponents/TimeInput.tsx","../../src/Time/subcomponents/TimeControl.tsx","../../src/Time/subcomponents/TimeReset.tsx","../../src/Time/Time.tsx","../../src/Time/index.ts"],"sourcesContent":["import type {\n CalendarDateTime,\n Time,\n ZonedDateTime,\n} from '@internationalized/date';\nimport type { InputValueTransform } from '../hooks/useInputValueTransform';\nimport type { TimeProps } from './Time';\n\nimport {\n getLocalTimeZone,\n parseAbsolute,\n parseAbsoluteToLocal,\n parseDateTime,\n parseZonedDateTime,\n} from '@internationalized/date';\n\n/** Supported segmented time values, including an empty field. */\nexport type TimeValue =\n Time | CalendarDateTime | ZonedDateTime | null | undefined;\n\n/** Cast unknown input to the TimeInput value union type. */\nconst asTimeValue = (value: unknown): TimeValue => {\n return value as TimeValue;\n};\n\n/** Check whether a value already looks like an @internationalized/date value. */\nconst isTimeValueLike = (value: unknown): value is object => {\n if (!value || typeof value !== 'object') {\n return false;\n }\n\n return 'hour' in value || 'calendar' in value;\n};\n\n/** Check if the incoming string represents a plain time (e.g. 09:30 or 09:30:45). */\nconst isTimeOnlyString = (value: string): boolean => {\n return /^\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,3})?)?$/.test(value);\n};\n\n/** Check if the incoming string is a UTC time-only value (e.g. 09:30Z). */\nconst isUtcTimeOnlyString = (value: string): boolean => {\n return /^\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,3})?)?Z$/.test(value);\n};\n\n/** Zero-pad integer segments for time serialization. */\nconst pad = (value: number): string => {\n return String(value).padStart(2, '0');\n};\n\n/** Convert an absolute ISO string into UTC time-only store format. */\nconst toUtcTimeString = (\n absoluteIsoString: string,\n granularity: 'hour' | 'minute',\n): string | null => {\n const utcDate = new Date(absoluteIsoString);\n if (Number.isNaN(utcDate.getTime())) {\n return null;\n }\n\n const hour = pad(utcDate.getUTCHours());\n if (granularity === 'hour') {\n return `${hour}:00Z`;\n }\n\n return `${hour}:${pad(utcDate.getUTCMinutes())}Z`;\n};\n\n/** True when an input already carries timezone/offset information. */\nconst hasExplicitTimeZone = (value: string): boolean => {\n if (value.includes('[') && value.includes(']')) {\n return true;\n }\n\n return /(?:[zZ]|[+-]\\d{2}:\\d{2})$/.test(value);\n};\n\n/** True for date-time strings without timezone/offset. */\nconst isNaiveDateTimeString = (value: string): boolean => {\n return /^\\d{4}-\\d{2}-\\d{2}T/.test(value) && !hasExplicitTimeZone(value);\n};\n\n/** Safely run a parser and return `null` on parsing errors. */\nconst tryParse = (parser: () => unknown): TimeValue => {\n try {\n return asTimeValue(parser());\n } catch {\n return null;\n }\n};\n\n/**\n * Parse a form value into a segmented time field compatible `TimeValue`.\n *\n * Supports existing `TimeValue` objects, native `Date` instances, plain time\n * strings (`HH:mm[:ss]`), absolute ISO date-time strings, zoned date-time\n * strings, and local date-time strings.\n *\n * Time-only strings are interpreted in the active timezone and normalized to a\n * `ZonedDateTime` (using a fixed reference date) so timezone abbreviations can\n * remain visible in the UI.\n */\nexport const parseTimeValue = (\n value: unknown,\n timeZone?: string,\n): TimeValue => {\n if (value == null || value === '') {\n return null;\n }\n\n if (isTimeValueLike(value)) {\n return asTimeValue(value);\n }\n\n if (value instanceof Date) {\n return asTimeValue(\n timeZone\n ? parseAbsolute(value.toISOString(), timeZone)\n : parseAbsoluteToLocal(value.toISOString()),\n );\n }\n\n if (typeof value !== 'string') {\n return null;\n }\n\n const normalizedValue = value.trim();\n if (normalizedValue === '') {\n return null;\n }\n\n if (isTimeOnlyString(normalizedValue)) {\n return tryParse(() => {\n const [hourValue, minuteValue, secondValue] = normalizedValue\n .split(':')\n .map(Number);\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n const hour = pad(hourValue);\n const minute = pad(minuteValue);\n const second = pad(secondValue ?? 0);\n\n return parseZonedDateTime(\n `1970-01-01T${hour}:${minute}:${second}[${resolvedTimeZone}]`,\n );\n });\n }\n\n if (isUtcTimeOnlyString(normalizedValue)) {\n return tryParse(() => {\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n return parseAbsolute(`1970-01-01T${normalizedValue}`, resolvedTimeZone);\n });\n }\n\n const parsers: (() => unknown)[] = [\n ...(timeZone && isNaiveDateTimeString(normalizedValue)\n ? [\n () => {\n return parseZonedDateTime(`${normalizedValue}[${timeZone}]`);\n },\n ]\n : []),\n () => {\n return timeZone\n ? parseAbsolute(normalizedValue, timeZone)\n : parseAbsoluteToLocal(normalizedValue);\n },\n () => {\n return parseZonedDateTime(normalizedValue);\n },\n () => {\n return parseDateTime(normalizedValue);\n },\n ];\n\n return (\n parsers\n .map((parser) => {\n return tryParse(parser);\n })\n .find((parsedValue) => {\n return parsedValue != null;\n }) ?? null\n );\n};\n\n/** Resolve the timezone used for parsing and string conversion. */\nexport const resolveTimeFieldTimeZone = (timeZone?: string): string => {\n return timeZone ?? getLocalTimeZone();\n};\n\n/**\n * Build default placeholder value for TimeInput.\n *\n * Uses a fixed reference time to keep snapshots deterministic.\n */\nexport const getTimeFieldPlaceholderValue = (timeZone?: string): TimeValue => {\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n return asTimeValue(\n parseZonedDateTime(`1970-01-01T00:00:00[${resolvedTimeZone}]`),\n );\n};\n\n/**\n * Convert a TimeValue into a UTC time-only string for form state.\n *\n * The stored format is `HH:mmZ` (or `HH:00Z` when granularity is `hour`).\n */\nexport const timeValueToString = (\n value: TimeValue,\n timeZone: string,\n granularity: 'hour' | 'minute' = 'minute',\n): string | null => {\n if (value == null) {\n return null;\n }\n\n const maybeWithAbsoluteString = value as { toAbsoluteString?: () => string };\n if (typeof maybeWithAbsoluteString.toAbsoluteString === 'function') {\n return toUtcTimeString(\n maybeWithAbsoluteString.toAbsoluteString(),\n granularity,\n );\n }\n\n const maybeWithToDate = value as { toDate?: (zone: string) => Date };\n if (typeof maybeWithToDate.toDate === 'function') {\n return toUtcTimeString(\n maybeWithToDate.toDate(timeZone).toISOString(),\n granularity,\n );\n }\n\n const maybeTime = value as {\n hour?: number;\n minute?: number;\n second?: number;\n };\n if (\n typeof maybeTime.hour === 'number' &&\n typeof maybeTime.minute === 'number'\n ) {\n const hour = pad(maybeTime.hour);\n const minute = pad(maybeTime.minute);\n const second = pad(maybeTime.second ?? 0);\n return toUtcTimeString(\n parseZonedDateTime(\n `1970-01-01T${hour}:${minute}:${second}[${timeZone}]`,\n ).toAbsoluteString(),\n granularity,\n );\n }\n\n return null;\n};\n\n/** Converts edited times to UTC strings, numeric hours or time objects */\nexport const createTimeValueTransform = ({\n granularity = 'minute',\n hourAsNumber,\n timeZone,\n valueType,\n}: Pick<\n TimeProps,\n 'granularity' | 'hourAsNumber' | 'timeZone' | 'valueType'\n>): InputValueTransform => {\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n const effectiveGranularity = hourAsNumber ? 'hour' : granularity;\n\n return {\n toDisplayValue: (value) => {\n return value ?? '';\n },\n toFormValue: (value) => {\n const nextValue = value as TimeValue;\n if (nextValue == null) {\n return null;\n }\n\n if (hourAsNumber) {\n const serializedValue = timeValueToString(\n nextValue,\n resolvedTimeZone,\n 'hour',\n );\n if (!serializedValue) {\n return null;\n }\n\n const [hoursSegment] = serializedValue.split(':');\n const hours = Number(hoursSegment);\n\n return Number.isNaN(hours) ? null : hours;\n }\n\n if (valueType === 'timeValue') {\n return nextValue;\n }\n\n return (\n timeValueToString(nextValue, resolvedTimeZone, effectiveGranularity) ??\n String(nextValue)\n );\n },\n };\n};\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { TimeValue } from '../timeHelpers';\nimport type { TimeClassNames } from '../timeVariants';\n\nimport { DateInput, DateSegment } from 'react-aria-components';\n\nimport FieldDescription from '../../partials/FieldDescription/FieldDescription';\n\ninterface TimeInputProps {\n /** CSS class name */\n className: TimeClassNames;\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, TimeValue>;\n}\n\n/**\n * Editable time segments and supporting messages inside a TimeField\n *\n * @see https://react-aria.adobe.com/TimeField\n */\nconst TimeInput = ({ className: classNames, field }: TimeInputProps) => {\n const { description, errorMessage, ids, invalid, testId } = field;\n\n return (\n <div className={classNames.inputWrapper} data-slot=\"input-wrapper\">\n <div className={classNames.innerWrapper} data-slot=\"inner-wrapper\">\n <DateInput\n className={classNames.input}\n data-slot=\"input\"\n data-testid={testId}\n >\n {(segment) => {\n return (\n <DateSegment\n className={classNames.segment}\n data-editable={segment.isEditable || undefined}\n data-slot=\"segment\"\n data-type={segment.type}\n segment={segment}\n />\n );\n }}\n </DateInput>\n </div>\n\n {/* help text and validation messages */}\n {description || invalid ? (\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldDescription\n className={classNames.description}\n id={ids.description}\n >\n {description}\n </FieldDescription>\n {invalid ? (\n <div\n className={classNames.errorMessage}\n data-slot=\"error-message\"\n id={ids.error}\n >\n {errorMessage}\n </div>\n ) : null}\n </div>\n ) : null}\n </div>\n );\n};\n\nexport default TimeInput;\n","import type { ReactNode } from 'react';\nimport type { UniformField } from '../../hooks/useUniformField/types';\nimport type { TimeProps } from '../Time';\nimport type { TimeValue } from '../timeHelpers';\n\nimport { Label, TimeField } from 'react-aria-components';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { getTimeFieldPlaceholderValue, parseTimeValue } from '../timeHelpers';\nimport { timeVariants } from '../timeVariants';\nimport TimeInput from './TimeInput';\n\ninterface TimeControlProps extends Pick<\n TimeProps,\n | 'className'\n | 'granularity'\n | 'hideTimeZone'\n | 'hourAsNumber'\n | 'hourCycle'\n | 'timeZone'\n> {\n /** Reset bridge rendered inside the time engine */\n children: ReactNode;\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, TimeValue>;\n}\n\n/**\n * Segmented time presentation with label, messages and editable-segment focus\n *\n * @see https://react-aria.adobe.com/TimeField\n */\nconst TimeControl = ({\n field,\n children,\n className,\n granularity,\n hideTimeZone,\n hourAsNumber,\n hourCycle,\n timeZone,\n}: TimeControlProps) => {\n const styling = useStyling();\n\n const {\n disabled,\n ids,\n ref: inputRef,\n invalid,\n label,\n name,\n onBlur,\n onChange: onValueChange,\n readOnly,\n required,\n } = field;\n\n // associate the editable control with its label and messages\n const controlProps = getFieldControlProps(field);\n\n const effectiveGranularity = hourAsNumber ? 'hour' : granularity;\n\n // numeric hours represent UTC, including midnight as zero\n const normalizedValue =\n hourAsNumber && typeof field.value === 'number'\n ? `${String(Math.max(0, Math.min(23, field.value))).padStart(2, '0')}:00Z`\n : field.value;\n const value = parseTimeValue(normalizedValue, timeZone);\n\n const placeholderValue = getTimeFieldPlaceholderValue(timeZone);\n\n // classNames from slots\n const variants = styling.resolve(timeVariants, {\n disabled,\n invalid,\n readOnly,\n });\n const classNames = styling.variantsToClassNames(variants, className, 'base');\n\n // route form focus to the first enabled segment\n const handleControlRef = (element: HTMLDivElement | null) => {\n inputRef(\n element\n ? {\n focus: () => {\n element\n .querySelector<HTMLElement>(\n '[role=\"spinbutton\"]:not([aria-disabled=\"true\"])',\n )\n ?.focus();\n },\n }\n : null,\n );\n };\n\n return (\n <TimeField\n ref={handleControlRef}\n aria-describedby={controlProps['aria-describedby']}\n aria-invalid={controlProps['aria-invalid']}\n aria-label={controlProps['aria-label']}\n className={classNames.base}\n data-component=\"time\"\n data-slot=\"base\"\n granularity={effectiveGranularity}\n hideTimeZone={hideTimeZone}\n hourCycle={hourCycle}\n id={controlProps.id}\n isDisabled={disabled}\n isInvalid={invalid}\n isReadOnly={readOnly}\n isRequired={required}\n name={name}\n onBlur={onBlur}\n onChange={onValueChange}\n placeholderValue={placeholderValue ?? undefined}\n shouldForceLeadingZeros\n validationBehavior=\"aria\"\n value={value ?? null}\n >\n {children}\n\n {/* field label */}\n {label ? (\n <FieldLabel\n as={Label}\n className={classNames.label}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n ) : null}\n\n {/* editable time segments */}\n <TimeInput className={classNames} field={field} />\n </TimeField>\n );\n};\n\nexport default TimeControl;\n","import { useContext } from 'react';\nimport { TimeFieldStateContext } from 'react-aria-components';\n\nimport { useWatchFormReset } from '../../hooks/useWatchFormReset';\n\n/**\n * Clears partial segment edits when the form resets an empty field\n *\n * @see https://react-aria.adobe.com/TimeField\n */\nconst TimeReset = () => {\n const state = useContext(TimeFieldStateContext);\n\n useWatchFormReset({\n onReset: () => {\n if (state?.value == null) {\n state?.setValue(null);\n }\n },\n });\n\n return null;\n};\n\nexport default TimeReset;\n","import type { ReactNode } from 'react';\nimport type { ClassName } from './timeVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport TimeControl from './subcomponents/TimeControl';\nimport TimeReset from './subcomponents/TimeReset';\nimport { createTimeValueTransform } from './timeHelpers';\n\nexport { timeVariants } from './timeVariants';\n\nexport interface TimeProps {\n /** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */\n ariaLabel?: string;\n /** CSS class name */\n className?: ClassName;\n /** Optional help text associated with the editable time segments. */\n description?: ReactNode;\n /** input is disabled */\n disabled?: boolean;\n /** smallest visible unit in the segmented time input */\n granularity?: 'hour' | 'minute';\n /** hide timezone abbreviation for zoned values */\n hideTimeZone?: boolean;\n /** force hour granularity and store UTC hour as number (0-23) */\n hourAsNumber?: boolean;\n /** hour cycle formatting */\n hourCycle?: 12 | 24;\n /** form field label */\n label?: ReactNode;\n /** form field name */\n name: string;\n /** Prevents changes while keeping the value in validation and submission */\n readOnly?: boolean;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /**\n * Optional timezone used for parsing date-time strings and serializing values.\n * When omitted, local timezone is used.\n */\n timeZone?: string;\n /** value format stored in form state (`string` stores UTC minute values, e.g. `10:15Z`) */\n valueType?: 'string' | 'timeValue';\n}\n\n/** Form input field for a time of day */\nconst Time = ({\n className = undefined,\n granularity = 'minute',\n hideTimeZone = false,\n hourAsNumber = false,\n hourCycle = undefined,\n name,\n timeZone = undefined,\n valueType = 'string',\n ...uniformFieldProps\n}: TimeProps) => {\n const transform = createTimeValueTransform({\n granularity,\n hourAsNumber,\n timeZone,\n valueType,\n });\n\n const { field } = useUniformField({\n ...uniformFieldProps,\n name,\n transform,\n });\n\n return (\n <TimeControl\n className={className}\n field={field}\n granularity={granularity}\n hideTimeZone={hideTimeZone}\n hourAsNumber={hourAsNumber}\n hourCycle={hourCycle}\n timeZone={timeZone}\n >\n <TimeReset />\n </TimeControl>\n );\n};\n\nexport default Time;\n","import Time from './Time';\n\nexport type { TimeProps } from './Time';\n\nexport { timeVariants } from './Time';\n\nexport default Time;\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,eAAe,UAA8B;CACjD,OAAO;AACT;;AAGA,MAAM,mBAAmB,UAAoC;CAC3D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;CAGT,OAAO,UAAU,SAAS,cAAc;AAC1C;;AAGA,MAAM,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qBAAC,WAAD;EACE,KAAK;EACL,oBAAkB,aAAa;EAC/B,gBAAc,aAAa;EAC3B,cAAY,aAAa;EACzB,WAAW,WAAW;EACtB,kBAAe;EACf,aAAU;EACV,aAAa;EACC;EACH;EACX,IAAI,aAAa;EACjB,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,YAAY;EACN;EACE;EACR,UAAU;EACV,kBAAkB,oBAAoB,KAAA;EACtC,yBAAA;EACA,oBAAmB;EACnB,OAAO,SAAS;EAtBlB,UAAA;GAwBG;GAGA,QACC,oBAAC,YAAD;IACE,IAAI;IACJ,WAAW,WAAW;IACtB,IAAI,IAAI;IACE;IAET,UAAA;GACS,CAAA,IACV;GAGJ,oBAAC,WAAD;IAAW,WAAW;IAAmB;GAAQ,CAAA;EACxC;;AAEf;;;;;;;ACpIA,MAAM,kBAAkB;CACtB,MAAM,QAAQ,WAAW,qBAAqB;CAE9C,kBAAkB,EAChB,eAAe;EACb,IAAI,OAAO,SAAS,MAClB,OAAO,SAAS,IAAI;CAExB,EACF,CAAC;CAED,OAAO;AACT;;;ACuBA,MAAM,QAAQ,EACZ,YAAY,KAAA,GACZ,cAAc,UACd,eAAe,OACf,eAAe,OACf,YAAY,KAAA,GACZ,MACA,WAAW,KAAA,GACX,YAAY,UACZ,GAAG,wBACY;CACf,MAAM,YAAY,yBAAyB;EACzC;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,EAAE,UAAU,gBAAgB;EAChC,GAAG;EACH;EACA;CACF,CAAC;CAED,OACE,oBAAC,aAAD;EACa;EACJ;EACM;EACC;EACA;EACH;EACD;EAEV,UAAA,oBAAC,WAAD,CAAY,CAAA;CACD,CAAA;AAEjB;;AC5EA,IAAA,eAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/Time/timeHelpers.ts","../../src/Time/subcomponents/TimeInput.tsx","../../src/Time/subcomponents/TimeControl.tsx","../../src/Time/subcomponents/TimeReset.tsx","../../src/Time/Time.tsx","../../src/Time/index.ts"],"sourcesContent":["import type {\n CalendarDateTime,\n Time,\n ZonedDateTime,\n} from '@internationalized/date';\nimport type { InputValueTransform } from '../hooks/useInputValueTransform';\nimport type { TimeProps } from './Time';\n\nimport {\n getLocalTimeZone,\n parseAbsolute,\n parseAbsoluteToLocal,\n parseDateTime,\n parseZonedDateTime,\n} from '@internationalized/date';\n\n/** Supported segmented time values, including an empty field. */\nexport type TimeValue =\n Time | CalendarDateTime | ZonedDateTime | null | undefined;\n\n/** Cast unknown input to the TimeInput value union type. */\nconst asTimeValue = (value: unknown): TimeValue => {\n return value as TimeValue;\n};\n\n/** Check whether a value already looks like an @internationalized/date value. */\nconst isTimeValueLike = (value: unknown): value is object => {\n if (!value || typeof value !== 'object') {\n return false;\n }\n\n return 'hour' in value || 'calendar' in value;\n};\n\n/** Check if the incoming string represents a plain time (e.g. 09:30 or 09:30:45). */\nconst isTimeOnlyString = (value: string): boolean => {\n return /^\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,3})?)?$/.test(value);\n};\n\n/** Check if the incoming string is a UTC time-only value (e.g. 09:30Z). */\nconst isUtcTimeOnlyString = (value: string): boolean => {\n return /^\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,3})?)?Z$/.test(value);\n};\n\n/** Zero-pad integer segments for time serialization. */\nconst pad = (value: number): string => {\n return String(value).padStart(2, '0');\n};\n\n/** Convert an absolute ISO string into UTC time-only store format. */\nconst toUtcTimeString = (\n absoluteIsoString: string,\n granularity: 'hour' | 'minute',\n): string | null => {\n const utcDate = new Date(absoluteIsoString);\n if (Number.isNaN(utcDate.getTime())) {\n return null;\n }\n\n const hour = pad(utcDate.getUTCHours());\n if (granularity === 'hour') {\n return `${hour}:00Z`;\n }\n\n return `${hour}:${pad(utcDate.getUTCMinutes())}Z`;\n};\n\n/** True when an input already carries timezone/offset information. */\nconst hasExplicitTimeZone = (value: string): boolean => {\n if (value.includes('[') && value.includes(']')) {\n return true;\n }\n\n return /(?:[zZ]|[+-]\\d{2}:\\d{2})$/.test(value);\n};\n\n/** True for date-time strings without timezone/offset. */\nconst isNaiveDateTimeString = (value: string): boolean => {\n return /^\\d{4}-\\d{2}-\\d{2}T/.test(value) && !hasExplicitTimeZone(value);\n};\n\n/** Safely run a parser and return `null` on parsing errors. */\nconst tryParse = (parser: () => unknown): TimeValue => {\n try {\n return asTimeValue(parser());\n } catch {\n return null;\n }\n};\n\n/**\n * Parse a form value into a segmented time field compatible `TimeValue`.\n *\n * Supports existing `TimeValue` objects, native `Date` instances, plain time\n * strings (`HH:mm[:ss]`), absolute ISO date-time strings, zoned date-time\n * strings, and local date-time strings.\n *\n * Time-only strings are interpreted in the active timezone and normalized to a\n * `ZonedDateTime` (using a fixed reference date) so timezone abbreviations can\n * remain visible in the UI.\n */\nexport const parseTimeValue = (\n value: unknown,\n timeZone?: string,\n): TimeValue => {\n if (value == null || value === '') {\n return null;\n }\n\n if (isTimeValueLike(value)) {\n return asTimeValue(value);\n }\n\n if (value instanceof Date) {\n return asTimeValue(\n timeZone\n ? parseAbsolute(value.toISOString(), timeZone)\n : parseAbsoluteToLocal(value.toISOString()),\n );\n }\n\n if (typeof value !== 'string') {\n return null;\n }\n\n const normalizedValue = value.trim();\n if (normalizedValue === '') {\n return null;\n }\n\n if (isTimeOnlyString(normalizedValue)) {\n return tryParse(() => {\n const [hourValue, minuteValue, secondValue] = normalizedValue\n .split(':')\n .map(Number);\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n const hour = pad(hourValue);\n const minute = pad(minuteValue);\n const second = pad(secondValue ?? 0);\n\n return parseZonedDateTime(\n `1970-01-01T${hour}:${minute}:${second}[${resolvedTimeZone}]`,\n );\n });\n }\n\n if (isUtcTimeOnlyString(normalizedValue)) {\n return tryParse(() => {\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n return parseAbsolute(`1970-01-01T${normalizedValue}`, resolvedTimeZone);\n });\n }\n\n const parsers: (() => unknown)[] = [\n ...(timeZone && isNaiveDateTimeString(normalizedValue)\n ? [\n () => {\n return parseZonedDateTime(`${normalizedValue}[${timeZone}]`);\n },\n ]\n : []),\n () => {\n return timeZone\n ? parseAbsolute(normalizedValue, timeZone)\n : parseAbsoluteToLocal(normalizedValue);\n },\n () => {\n return parseZonedDateTime(normalizedValue);\n },\n () => {\n return parseDateTime(normalizedValue);\n },\n ];\n\n return (\n parsers\n .map((parser) => {\n return tryParse(parser);\n })\n .find((parsedValue) => {\n return parsedValue != null;\n }) ?? null\n );\n};\n\n/** Resolve the timezone used for parsing and string conversion. */\nexport const resolveTimeFieldTimeZone = (timeZone?: string): string => {\n return timeZone ?? getLocalTimeZone();\n};\n\n/**\n * Build default placeholder value for TimeInput.\n *\n * Uses a fixed reference time to keep snapshots deterministic.\n */\nexport const getTimeFieldPlaceholderValue = (timeZone?: string): TimeValue => {\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n return asTimeValue(\n parseZonedDateTime(`1970-01-01T00:00:00[${resolvedTimeZone}]`),\n );\n};\n\n/**\n * Convert a TimeValue into a UTC time-only string for form state.\n *\n * The stored format is `HH:mmZ` (or `HH:00Z` when granularity is `hour`).\n */\nexport const timeValueToString = (\n value: TimeValue,\n timeZone: string,\n granularity: 'hour' | 'minute' = 'minute',\n): string | null => {\n if (value == null) {\n return null;\n }\n\n const maybeWithAbsoluteString = value as { toAbsoluteString?: () => string };\n if (typeof maybeWithAbsoluteString.toAbsoluteString === 'function') {\n return toUtcTimeString(\n maybeWithAbsoluteString.toAbsoluteString(),\n granularity,\n );\n }\n\n const maybeWithToDate = value as { toDate?: (zone: string) => Date };\n if (typeof maybeWithToDate.toDate === 'function') {\n return toUtcTimeString(\n maybeWithToDate.toDate(timeZone).toISOString(),\n granularity,\n );\n }\n\n const maybeTime = value as {\n hour?: number;\n minute?: number;\n second?: number;\n };\n if (\n typeof maybeTime.hour === 'number' &&\n typeof maybeTime.minute === 'number'\n ) {\n const hour = pad(maybeTime.hour);\n const minute = pad(maybeTime.minute);\n const second = pad(maybeTime.second ?? 0);\n return toUtcTimeString(\n parseZonedDateTime(\n `1970-01-01T${hour}:${minute}:${second}[${timeZone}]`,\n ).toAbsoluteString(),\n granularity,\n );\n }\n\n return null;\n};\n\n/** Converts edited times to UTC strings, numeric hours or time objects */\nexport const createTimeValueTransform = ({\n granularity = 'minute',\n hourAsNumber,\n timeZone,\n valueType,\n}: Pick<\n TimeProps,\n 'granularity' | 'hourAsNumber' | 'timeZone' | 'valueType'\n>): InputValueTransform => {\n const resolvedTimeZone = resolveTimeFieldTimeZone(timeZone);\n const effectiveGranularity = hourAsNumber ? 'hour' : granularity;\n\n return {\n toDisplayValue: (value) => {\n return value ?? '';\n },\n toFormValue: (value) => {\n const nextValue = value as TimeValue;\n if (nextValue == null) {\n return null;\n }\n\n if (hourAsNumber) {\n const serializedValue = timeValueToString(\n nextValue,\n resolvedTimeZone,\n 'hour',\n );\n if (!serializedValue) {\n return null;\n }\n\n const [hoursSegment] = serializedValue.split(':');\n const hours = Number(hoursSegment);\n\n return Number.isNaN(hours) ? null : hours;\n }\n\n if (valueType === 'timeValue') {\n return nextValue;\n }\n\n return (\n timeValueToString(nextValue, resolvedTimeZone, effectiveGranularity) ??\n String(nextValue)\n );\n },\n };\n};\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { TimeValue } from '../timeHelpers';\nimport type { TimeClassNames } from '../timeVariants';\n\nimport { DateInput, DateSegment } from 'react-aria-components';\n\nimport FieldHelper from '../../partials/FieldHelper/FieldHelper';\n\ninterface TimeInputProps {\n /** CSS class name */\n className: TimeClassNames;\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, TimeValue>;\n}\n\n/**\n * Editable time segments and supporting messages below them, inside a TimeField\n *\n * @see https://react-aria.adobe.com/TimeField\n */\nconst TimeInput = ({ className: classNames, field }: TimeInputProps) => {\n const { description, errorMessage, ids, invalid, testId } = field;\n\n return (\n <>\n <div className={classNames.inputWrapper} data-slot=\"input-wrapper\">\n <div className={classNames.innerWrapper} data-slot=\"inner-wrapper\">\n <DateInput\n className={classNames.input}\n data-slot=\"input\"\n data-testid={testId}\n >\n {(segment) => {\n return (\n <DateSegment\n className={classNames.segment}\n data-editable={segment.isEditable || undefined}\n data-slot=\"segment\"\n data-type={segment.type}\n segment={segment}\n />\n );\n }}\n </DateInput>\n </div>\n </div>\n\n {/* help text and validation messages, below the input surface */}\n <FieldHelper\n className={classNames}\n description={description}\n errorMessage={errorMessage}\n ids={ids}\n invalid={invalid}\n />\n </>\n );\n};\n\nexport default TimeInput;\n","import type { ReactNode } from 'react';\nimport type { UniformField } from '../../hooks/useUniformField/types';\nimport type { TimeProps } from '../Time';\nimport type { TimeValue } from '../timeHelpers';\n\nimport { Label, TimeField } from 'react-aria-components';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { getTimeFieldPlaceholderValue, parseTimeValue } from '../timeHelpers';\nimport { timeVariants } from '../timeVariants';\nimport TimeInput from './TimeInput';\n\ninterface TimeControlProps extends Pick<\n TimeProps,\n | 'className'\n | 'granularity'\n | 'hideTimeZone'\n | 'hourAsNumber'\n | 'hourCycle'\n | 'timeZone'\n> {\n /** Reset bridge rendered inside the time engine */\n children: ReactNode;\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, TimeValue>;\n}\n\n/**\n * Segmented time presentation with label, messages and editable-segment focus\n *\n * @see https://react-aria.adobe.com/TimeField\n */\nconst TimeControl = ({\n field,\n children,\n className,\n granularity,\n hideTimeZone,\n hourAsNumber,\n hourCycle,\n timeZone,\n}: TimeControlProps) => {\n const styling = useStyling();\n\n const {\n disabled,\n ids,\n ref: inputRef,\n invalid,\n label,\n name,\n onBlur,\n onChange: onValueChange,\n readOnly,\n required,\n } = field;\n\n // associate the editable control with its label and messages\n const controlProps = getFieldControlProps(field);\n\n const effectiveGranularity = hourAsNumber ? 'hour' : granularity;\n\n // numeric hours represent UTC, including midnight as zero\n const normalizedValue =\n hourAsNumber && typeof field.value === 'number'\n ? `${String(Math.max(0, Math.min(23, field.value))).padStart(2, '0')}:00Z`\n : field.value;\n const value = parseTimeValue(normalizedValue, timeZone);\n\n const placeholderValue = getTimeFieldPlaceholderValue(timeZone);\n\n // classNames from slots\n const variants = styling.resolve(timeVariants, {\n disabled,\n invalid,\n readOnly,\n });\n const classNames = styling.variantsToClassNames(variants, className, 'base');\n\n // route form focus to the first enabled segment\n const handleControlRef = (element: HTMLDivElement | null) => {\n inputRef(\n element\n ? {\n focus: () => {\n element\n .querySelector<HTMLElement>(\n '[role=\"spinbutton\"]:not([aria-disabled=\"true\"])',\n )\n ?.focus();\n },\n }\n : null,\n );\n };\n\n return (\n <TimeField\n ref={handleControlRef}\n aria-describedby={controlProps['aria-describedby']}\n aria-invalid={controlProps['aria-invalid']}\n aria-label={controlProps['aria-label']}\n className={classNames.base}\n data-component=\"time\"\n data-slot=\"base\"\n granularity={effectiveGranularity}\n hideTimeZone={hideTimeZone}\n hourCycle={hourCycle}\n id={controlProps.id}\n isDisabled={disabled}\n isInvalid={invalid}\n isReadOnly={readOnly}\n isRequired={required}\n name={name}\n onBlur={onBlur}\n onChange={onValueChange}\n placeholderValue={placeholderValue ?? undefined}\n shouldForceLeadingZeros\n validationBehavior=\"aria\"\n value={value ?? null}\n >\n {children}\n\n {/* field label */}\n {label ? (\n <FieldLabel\n as={Label}\n className={classNames.label}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n ) : null}\n\n {/* editable time segments */}\n <TimeInput className={classNames} field={field} />\n </TimeField>\n );\n};\n\nexport default TimeControl;\n","import { useContext } from 'react';\nimport { TimeFieldStateContext } from 'react-aria-components';\n\nimport { useWatchFormReset } from '../../hooks/useWatchFormReset';\n\n/**\n * Clears partial segment edits when the form resets an empty field\n *\n * @see https://react-aria.adobe.com/TimeField\n */\nconst TimeReset = () => {\n const state = useContext(TimeFieldStateContext);\n\n useWatchFormReset({\n onReset: () => {\n if (state?.value == null) {\n state?.setValue(null);\n }\n },\n });\n\n return null;\n};\n\nexport default TimeReset;\n","import type { ReactNode } from 'react';\nimport type { ClassName } from './timeVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport TimeControl from './subcomponents/TimeControl';\nimport TimeReset from './subcomponents/TimeReset';\nimport { createTimeValueTransform } from './timeHelpers';\n\nexport { timeVariants } from './timeVariants';\n\nexport interface TimeProps {\n /** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */\n ariaLabel?: string;\n /** CSS class name */\n className?: ClassName;\n /** Optional help text associated with the editable time segments. */\n description?: ReactNode;\n /** input is disabled */\n disabled?: boolean;\n /** smallest visible unit in the segmented time input */\n granularity?: 'hour' | 'minute';\n /** hide timezone abbreviation for zoned values */\n hideTimeZone?: boolean;\n /** force hour granularity and store UTC hour as number (0-23) */\n hourAsNumber?: boolean;\n /** hour cycle formatting */\n hourCycle?: 12 | 24;\n /** form field label */\n label?: ReactNode;\n /** form field name */\n name: string;\n /** Prevents changes while keeping the value in validation and submission */\n readOnly?: boolean;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /**\n * Optional timezone used for parsing date-time strings and serializing values.\n * When omitted, local timezone is used.\n */\n timeZone?: string;\n /** value format stored in form state (`string` stores UTC minute values, e.g. `10:15Z`) */\n valueType?: 'string' | 'timeValue';\n}\n\n/** Form input field for a time of day */\nconst Time = ({\n className = undefined,\n granularity = 'minute',\n hideTimeZone = false,\n hourAsNumber = false,\n hourCycle = undefined,\n name,\n timeZone = undefined,\n valueType = 'string',\n ...uniformFieldProps\n}: TimeProps) => {\n const transform = createTimeValueTransform({\n granularity,\n hourAsNumber,\n timeZone,\n valueType,\n });\n\n const { field } = useUniformField({\n ...uniformFieldProps,\n name,\n transform,\n });\n\n return (\n <TimeControl\n className={className}\n field={field}\n granularity={granularity}\n hideTimeZone={hideTimeZone}\n hourAsNumber={hourAsNumber}\n hourCycle={hourCycle}\n timeZone={timeZone}\n >\n <TimeReset />\n </TimeControl>\n );\n};\n\nexport default Time;\n","import Time from './Time';\n\nexport type { TimeProps } from './Time';\n\nexport { timeVariants } from './Time';\n\nexport default Time;\n"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,eAAe,UAA8B;CACjD,OAAO;AACT;;AAGA,MAAM,mBAAmB,UAAoC;CAC3D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;CAGT,OAAO,UAAU,SAAS,cAAc;AAC1C;;AAGA,MAAM,oBAAoB,UAA2B;CACnD,OAAO,yCAAyC,KAAK,KAAK;AAC5D;;AAGA,MAAM,uBAAuB,UAA2B;CACtD,OAAO,0CAA0C,KAAK,KAAK;AAC7D;;AAGA,MAAM,OAAO,UAA0B;CACrC,OAAO,OAAO,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG;AACtC;;AAGA,MAAM,mBACJ,mBACA,gBACkB;CAClB,MAAM,UAAU,IAAI,KAAK,iBAAiB;CAC1C,IAAI,OAAO,MAAM,QAAQ,QAAQ,CAAC,GAChC,OAAO;CAGT,MAAM,OAAO,IAAI,QAAQ,YAAY,CAAC;CACtC,IAAI,gBAAgB,QAClB,OAAO,GAAG,KAAK;CAGjB,OAAO,GAAG,KAAK,GAAG,IAAI,QAAQ,cAAc,CAAC,EAAE;AACjD;;AAGA,MAAM,uBAAuB,UAA2B;CACtD,IAAI,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,GAAG,GAC3C,OAAO;CAGT,OAAO,4BAA4B,KAAK,KAAK;AAC/C;;AAGA,MAAM,yBAAyB,UAA2B;CACxD,OAAO,sBAAsB,KAAK,KAAK,KAAK,CAAC,oBAAoB,KAAK;AACxE;;AAGA,MAAM,YAAY,WAAqC;CACrD,IAAI;EACF,OAAO,YAAY,OAAO,CAAC;CAC7B,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;;AAaA,MAAa,kBACX,OACA,aACc;CACd,IAAI,SAAS,QAAQ,UAAU,IAC7B,OAAO;CAGT,I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@@
|
|
|
1
|
+
import { tv } from "@fuf-stack/pixel-utils";
|
|
2
|
+
// src/partials/FieldHelper/fieldHelperVariants.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared help text and validation message styles
|
|
5
|
+
*
|
|
6
|
+
* Field recipes compose `fieldHelperVariants.slots`. Help text and each
|
|
7
|
+
* validation message carry their own top padding, so messages animate in
|
|
8
|
+
* without a jump and the wrapper adds no spacing while empty.
|
|
9
|
+
*/
|
|
10
|
+
const fieldHelperVariants = tv({ slots: {
|
|
11
|
+
/** Help text below the control */
|
|
12
|
+
description: "pt-1 text-tiny text-foreground-500",
|
|
13
|
+
/** Validation message container */
|
|
14
|
+
errorMessage: "text-tiny text-danger",
|
|
15
|
+
/** Container for help text and validation messages */
|
|
16
|
+
helperWrapper: "relative flex flex-col p-0"
|
|
17
|
+
} });
|
|
18
|
+
export { fieldHelperVariants as t };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=fieldHelperVariants-ClP8taiS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldHelperVariants-ClP8taiS.mjs","names":[],"sources":["../src/partials/FieldHelper/fieldHelperVariants.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\n/**\n * Shared help text and validation message styles\n *\n * Field recipes compose `fieldHelperVariants.slots`. Help text and each\n * validation message carry their own top padding, so messages animate in\n * without a jump and the wrapper adds no spacing while empty.\n */\nexport const fieldHelperVariants = tv({\n slots: {\n /** Help text below the control */\n description: 'pt-1 text-tiny text-foreground-500',\n /** Validation message container */\n errorMessage: 'text-tiny text-danger',\n /** Container for help text and validation messages */\n helperWrapper: 'relative flex flex-col p-0',\n },\n});\n\nexport type FieldHelperVariantsClassName = TVClassName<\n typeof fieldHelperVariants\n>;\n"],"mappings":";;;;;;;;;AAWA,MAAa,sBAAsB,GAAG,EACpC,OAAO;;CAEL,aAAa;;CAEb,cAAc;;CAEd,eAAe;AACjB,EACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { tv } from "@fuf-stack/pixel-utils";
|
|
2
|
+
// src/partials/FieldLabel/fieldLabelVariants.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared field label style, red while the field is invalid
|
|
5
|
+
*
|
|
6
|
+
* Field recipes compose `fieldLabelVariants.base` and add only structural
|
|
7
|
+
* classes, such as display or a label beside the control. The bottom padding
|
|
8
|
+
* spaces a stacked label from its control, so fields need no base gap.
|
|
9
|
+
*/
|
|
10
|
+
const fieldLabelVariants = tv({ base: "cursor-default pb-1.5 text-small text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger" });
|
|
11
|
+
export { fieldLabelVariants as t };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=fieldLabelVariants-C4ZqECec.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldLabelVariants-C4ZqECec.mjs","names":[],"sources":["../src/partials/FieldLabel/fieldLabelVariants.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\n/**\n * Shared field label style, red while the field is invalid\n *\n * Field recipes compose `fieldLabelVariants.base` and add only structural\n * classes, such as display or a label beside the control. The bottom padding\n * spaces a stacked label from its control, so fields need no base gap.\n */\nexport const fieldLabelVariants = tv({\n base: 'cursor-default pb-1.5 text-small text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger',\n});\n\nexport type FieldLabelVariantsClassName = TVClassName<\n typeof fieldLabelVariants\n>;\n"],"mappings":";;;;;;;;;AAWA,MAAa,qBAAqB,GAAG,EACnC,MAAM,8GACR,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
1
|
// src/helpers/fieldProps/fieldProps.ts
|
|
3
2
|
/** Shared styling attributes for field state, inactive flags are omitted */
|
|
4
3
|
const getFieldDataAttributes = ({ disabled, invalid, readOnly, required }) => {
|
|
@@ -20,16 +19,6 @@ const getFieldControlProps = ({ ariaLabel, customAriaLabel, description, hasErro
|
|
|
20
19
|
"aria-required": required || void 0
|
|
21
20
|
};
|
|
22
21
|
};
|
|
23
|
-
|
|
24
|
-
/** Help text associated with a field through its description ID */
|
|
25
|
-
const FieldDescription = ({ children, ...props }) => {
|
|
26
|
-
if (!children) return null;
|
|
27
|
-
return /* @__PURE__ */ jsx("div", {
|
|
28
|
-
"data-slot": "description",
|
|
29
|
-
...props,
|
|
30
|
-
children
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
export { getFieldControlProps as n, getFieldDataAttributes as r, FieldDescription as t };
|
|
22
|
+
export { getFieldDataAttributes as n, getFieldControlProps as t };
|
|
34
23
|
|
|
35
|
-
//# sourceMappingURL=
|
|
24
|
+
//# sourceMappingURL=fieldProps-DWfz2jSO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldProps-DWfz2jSO.mjs","names":[],"sources":["../src/helpers/fieldProps/fieldProps.ts"],"sourcesContent":["import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { FieldControlProps } from '../../partials/types';\n\ninterface FieldDataState {\n /** Disables interaction with the field */\n disabled?: boolean;\n /** Marks visible validation failure */\n invalid?: boolean;\n /** Prevents changes to the field */\n readOnly?: boolean;\n /** Marks a required field */\n required?: boolean;\n}\n\n/** Shared styling attributes for field state, inactive flags are omitted */\nexport const getFieldDataAttributes = ({\n disabled,\n invalid,\n readOnly,\n required,\n}: FieldDataState) => {\n return {\n 'data-disabled': disabled ? true : undefined,\n 'data-invalid': invalid ? true : undefined,\n 'data-readonly': readOnly ? true : undefined,\n 'data-required': required ? true : undefined,\n };\n};\n\n/** Field metadata needed to associate an editable control with its content */\ntype FieldControlState = Pick<\n UniformField,\n | 'ariaLabel'\n | 'customAriaLabel'\n | 'description'\n | 'hasErrors'\n | 'hasLabel'\n | 'ids'\n | 'invalid'\n | 'required'\n>;\n\n/** ID and ARIA associations for the editable control or selection group */\nexport const getFieldControlProps = ({\n ariaLabel,\n customAriaLabel,\n description,\n hasErrors,\n hasLabel,\n ids,\n invalid,\n required,\n}: FieldControlState): FieldControlProps => {\n return {\n id: ids.control,\n 'aria-label': customAriaLabel ?? (!hasLabel ? ariaLabel : undefined),\n 'aria-labelledby': !customAriaLabel && hasLabel ? ids.label : undefined,\n 'aria-describedby':\n [\n description ? ids.description : undefined,\n invalid && hasErrors ? ids.error : undefined,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n 'aria-invalid': invalid || undefined,\n 'aria-required': required || undefined,\n };\n};\n"],"mappings":";;AAeA,MAAa,0BAA0B,EACrC,UACA,SACA,UACA,eACoB;CACpB,OAAO;EACL,iBAAiB,WAAW,OAAO,KAAA;EACnC,gBAAgB,UAAU,OAAO,KAAA;EACjC,iBAAiB,WAAW,OAAO,KAAA;EACnC,iBAAiB,WAAW,OAAO,KAAA;CACrC;AACF;;AAgBA,MAAa,wBAAwB,EACnC,WACA,iBACA,aACA,WACA,UACA,KACA,SACA,eAC0C;CAC1C,OAAO;EACL,IAAI,IAAI;EACR,cAAc,oBAAoB,CAAC,WAAW,YAAY,KAAA;EAC1D,mBAAmB,CAAC,mBAAmB,WAAW,IAAI,QAAQ,KAAA;EAC9D,oBACE,CACE,cAAc,IAAI,cAAc,KAAA,GAChC,WAAW,YAAY,IAAI,QAAQ,KAAA,CACrC,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;EAClB,gBAAgB,WAAW,KAAA;EAC3B,iBAAiB,YAAY,KAAA;CAC/B;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../../helpers/index.mjs";
|
|
2
|
-
import { n as useFormContext } from "../../useFormContext-
|
|
2
|
+
import { n as useFormContext } from "../../useFormContext-CQzJhAU4.mjs";
|
|
3
3
|
import { useEffect, useId } from "react";
|
|
4
4
|
import { array, objectLoose } from "@fuf-stack/veto";
|
|
5
5
|
// src/hooks/useClientValidation/useClientValidation.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as UniformContext } from "../../FormContext-
|
|
1
|
+
import { n as UniformContext } from "../../FormContext-Dvt3MiKq.mjs";
|
|
2
2
|
import { ContextType } from "react";
|
|
3
3
|
import { FieldError, FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
4
4
|
import { VetoInstance } from "@fuf-stack/veto";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/hooks/useFormContext/index.ts
|
|
2
2
|
/* v8 ignore stop */
|
|
3
|
-
export { t as checkFieldIsRequired, n as useFormContext } from "../../useFormContext-
|
|
3
|
+
export { t as checkFieldIsRequired, n as useFormContext } from "../../useFormContext-CQzJhAU4.mjs";
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as useFormContext } from "../../useFormContext-
|
|
1
|
+
import { n as useFormContext } from "../../useFormContext-CQzJhAU4.mjs";
|
|
2
2
|
import { useWatchFormReset } from "../useWatchFormReset/index.mjs";
|
|
3
3
|
import { useCallback, useRef, useState } from "react";
|
|
4
4
|
// src/hooks/useInputValueDebounce/useInputValueDebounce.ts
|