@spear-ai/spectral 1.21.0 → 1.21.2

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.
Files changed (84) hide show
  1. package/dist/ButtonGroup/ButtonGroupButton.d.ts.map +1 -1
  2. package/dist/ButtonGroup/ButtonGroupButton.js +6 -5
  3. package/dist/ButtonGroup/ButtonGroupButton.js.map +1 -1
  4. package/dist/ButtonGroup.js +1 -1
  5. package/dist/ButtonGroup.js.map +1 -1
  6. package/dist/ButtonIcon.js +2 -2
  7. package/dist/ButtonIcon.js.map +1 -1
  8. package/dist/Checkbox.d.ts +1 -0
  9. package/dist/Checkbox.d.ts.map +1 -1
  10. package/dist/Checkbox.js +3 -3
  11. package/dist/Checkbox.js.map +1 -1
  12. package/dist/Combobox.d.ts.map +1 -1
  13. package/dist/Combobox.js +2 -2
  14. package/dist/Combobox.js.map +1 -1
  15. package/dist/DateTimePicker/Calendar.d.ts +13 -1
  16. package/dist/DateTimePicker/Calendar.d.ts.map +1 -1
  17. package/dist/DateTimePicker/Calendar.js +11 -4
  18. package/dist/DateTimePicker/Calendar.js.map +1 -1
  19. package/dist/DateTimePicker/DateTimeDisplayInput.d.ts +2 -2
  20. package/dist/DateTimePicker/DateTimeDisplayInput.d.ts.map +1 -1
  21. package/dist/DateTimePicker/DateTimeDisplayInput.js +3 -3
  22. package/dist/DateTimePicker/DateTimeDisplayInput.js.map +1 -1
  23. package/dist/DateTimePicker.d.ts +17 -4
  24. package/dist/DateTimePicker.d.ts.map +1 -1
  25. package/dist/DateTimePicker.js +48 -33
  26. package/dist/DateTimePicker.js.map +1 -1
  27. package/dist/Input.d.ts +1 -1
  28. package/dist/Input.d.ts.map +1 -1
  29. package/dist/Input.js +24 -17
  30. package/dist/Input.js.map +1 -1
  31. package/dist/InputOTP.d.ts +2 -0
  32. package/dist/InputOTP.d.ts.map +1 -1
  33. package/dist/InputOTP.js +52 -40
  34. package/dist/InputOTP.js.map +1 -1
  35. package/dist/InputSearch.d.ts +2 -2
  36. package/dist/InputSearch.d.ts.map +1 -1
  37. package/dist/InputSearch.js +6 -5
  38. package/dist/InputSearch.js.map +1 -1
  39. package/dist/Kbd.d.ts.map +1 -1
  40. package/dist/Kbd.js.map +1 -1
  41. package/dist/MultiSelect/MultiSelectBase.d.ts.map +1 -1
  42. package/dist/MultiSelect/MultiSelectBase.js +6 -5
  43. package/dist/MultiSelect/MultiSelectBase.js.map +1 -1
  44. package/dist/RadialMenu.d.ts.map +1 -1
  45. package/dist/RadialMenu.js +3 -4
  46. package/dist/RadialMenu.js.map +1 -1
  47. package/dist/RadioButton.js +1 -1
  48. package/dist/RadioButton.js.map +1 -1
  49. package/dist/RadioButtonGroup/RadioButtonGroupBase.d.ts +1 -1
  50. package/dist/RadioButtonGroup/RadioButtonGroupBase.d.ts.map +1 -1
  51. package/dist/RadioButtonGroup/RadioButtonGroupBase.js +3 -3
  52. package/dist/RadioButtonGroup/RadioButtonGroupBase.js.map +1 -1
  53. package/dist/RadioButtonGroup.d.ts +1 -1
  54. package/dist/RadioGroup.d.ts +6 -5
  55. package/dist/RadioGroup.d.ts.map +1 -1
  56. package/dist/RadioGroup.js +18 -14
  57. package/dist/RadioGroup.js.map +1 -1
  58. package/dist/Select.d.ts +1 -0
  59. package/dist/Select.d.ts.map +1 -1
  60. package/dist/Select.js +3 -3
  61. package/dist/Select.js.map +1 -1
  62. package/dist/Slider.js +1 -1
  63. package/dist/Slider.js.map +1 -1
  64. package/dist/Switch.d.ts +3 -3
  65. package/dist/Switch.d.ts.map +1 -1
  66. package/dist/Switch.js +5 -5
  67. package/dist/Switch.js.map +1 -1
  68. package/dist/Textarea.d.ts +3 -3
  69. package/dist/Textarea.d.ts.map +1 -1
  70. package/dist/Textarea.js +4 -3
  71. package/dist/Textarea.js.map +1 -1
  72. package/dist/primitives/input.d.ts.map +1 -1
  73. package/dist/primitives/input.js +2 -0
  74. package/dist/primitives/input.js.map +1 -1
  75. package/dist/primitives/textarea.d.ts.map +1 -1
  76. package/dist/primitives/textarea.js +2 -0
  77. package/dist/primitives/textarea.js.map +1 -1
  78. package/dist/styles/horizon/colors.css +5 -3
  79. package/dist/styles/spectral.css +1 -1
  80. package/dist/utils/formFieldUtils.d.ts +9 -1
  81. package/dist/utils/formFieldUtils.d.ts.map +1 -1
  82. package/dist/utils/formFieldUtils.js +19 -2
  83. package/dist/utils/formFieldUtils.js.map +1 -1
  84. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimeDisplayInput.js","names":[],"sources":["../../src/components/DateTimePicker/DateTimeDisplayInput.tsx"],"sourcesContent":["import { Label } from '@components/Label/Label'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { getInputClasses } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { forwardRef, useCallback, useEffect, useId, useMemo, useRef, type ComponentProps, type KeyboardEvent, type ReactNode } from 'react'\nimport { formatSelectPeriodLabel, getLocalizedPeriodLabels, getResolvedLocale, type HourFormat, type PeriodLabels } from './DateTimeUtils'\n\nexport interface DateTimeDisplayInputProps extends Omit<ComponentProps<'div'>, 'onChange' | 'defaultValue'> {\n defaultValue?: Date\n disabled?: boolean\n endIcon?: ReactNode\n hourFormat?: HourFormat\n label?: string\n locale?: string\n onChange?: (date: Date | undefined) => void\n showTime?: boolean\n state?: 'default' | 'disabled' | 'error'\n value?: Date\n // Legacy prop names for backward compatibility\n /** @deprecated Use `value` instead */\n date?: Date\n /** @deprecated Use `onChange` instead */\n onDateChange?: (date: Date | undefined) => void\n}\n\ninterface SegmentConfig {\n length: number\n max: number\n min: number\n type: 'month' | 'day' | 'year' | 'hour' | 'minute' | 'period'\n}\n\nconst SEGMENT_CONFIGS: Record<string, SegmentConfig> = {\n month: { type: 'month', min: 1, max: 12, length: 2 },\n day: { type: 'day', min: 1, max: 31, length: 2 },\n year: { type: 'year', min: 1900, max: 2100, length: 4 },\n hour12: { type: 'hour', min: 1, max: 12, length: 2 },\n hour24: { type: 'hour', min: 0, max: 23, length: 2 },\n minute: { type: 'minute', min: 0, max: 59, length: 2 },\n period: { type: 'period', min: 0, max: 1, length: 2 },\n}\n\n/**\n * Get max days for a given month/year\n */\nconst getMaxDaysInMonth = (month: number, year: number): number => {\n if (month === 2) {\n const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n return isLeapYear ? 29 : 28\n }\n if ([4, 6, 9, 11].includes(month)) return 30\n return 31\n}\n\n/**\n * A single segment input (month, day, year, hour, minute)\n */\ninterface SegmentInputProps {\n ariaLabel: string\n config: SegmentConfig\n disabled?: boolean\n onLeftFocus?: () => void\n onRightFocus?: () => void\n onValueChange: (value: number) => void\n periodLabels?: PeriodLabels\n value: number | undefined\n}\n\n/**\n * SegmentInput - A single editable segment (month, day, year, hour, minute, period)\n *\n * Uses an uncontrolled input pattern to avoid React re-render issues during typing:\n * - Edit buffer stored in ref (not state) to prevent re-renders\n * - DOM value manipulated directly during typing\n * - Only syncs with React when value is committed (blur, tab, arrow keys)\n */\nconst SegmentInput = ({ ariaLabel, config, disabled, onLeftFocus, onRightFocus, onValueChange, periodLabels, value }: SegmentInputProps) => {\n const inputRef = useRef<HTMLInputElement>(null)\n // Use refs to avoid re-renders during typing - this is the key to making it work\n const editBufferRef = useRef('')\n const isEditingRef = useRef(false)\n\n // Placeholder text for empty segments\n const placeholderText = useMemo(() => {\n switch (config.type) {\n case 'month':\n return 'MM'\n case 'day':\n return 'dd'\n case 'year':\n return 'yyyy'\n case 'hour':\n return config.max === 23 ? 'HH' : 'hh'\n case 'minute':\n return 'mm'\n case 'period':\n return periodLabels?.am ?? 'am'\n default:\n return '––'\n }\n }, [config.type, config.max, periodLabels])\n\n // Format display value from the committed value prop\n const displayValue = useMemo(() => {\n if (value === undefined) {\n return placeholderText\n }\n if (config.type === 'period') {\n const label = value === 0 ? (periodLabels?.am ?? 'am') : (periodLabels?.pm ?? 'pm')\n return label\n }\n return value.toString().padStart(config.length, '0')\n }, [value, config, periodLabels, placeholderText])\n\n // Sync input value when external value changes (and we're not editing)\n useEffect(() => {\n if (inputRef.current && !isEditingRef.current) {\n inputRef.current.value = displayValue\n }\n }, [displayValue])\n\n // Commit the edit buffer - called on blur, tab, arrow navigation\n const commitEdit = useCallback(() => {\n const buffer = editBufferRef.current\n if (buffer) {\n let numValue = parseInt(buffer, 10)\n if (!isNaN(numValue)) {\n numValue = Math.max(config.min, Math.min(config.max, numValue))\n onValueChange(numValue)\n }\n }\n // Reset edit state\n editBufferRef.current = ''\n isEditingRef.current = false\n // Sync display value after commit\n if (inputRef.current) {\n inputRef.current.value = displayValue\n }\n }, [config.min, config.max, displayValue, onValueChange])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement>) => {\n if (disabled) return\n\n // Tab navigation (let it bubble naturally)\n if (e.key === 'Tab') {\n commitEdit()\n return\n }\n\n // Arrow navigation between segments\n if (e.key === 'ArrowRight') {\n e.preventDefault()\n commitEdit()\n onRightFocus?.()\n return\n }\n if (e.key === 'ArrowLeft') {\n e.preventDefault()\n commitEdit()\n onLeftFocus?.()\n return\n }\n\n // Period toggle (am/pm)\n if (config.type === 'period') {\n e.preventDefault()\n if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n onValueChange(value === 0 ? 1 : 0)\n } else if (e.key.toLowerCase() === 'a') {\n onValueChange(0)\n } else if (e.key.toLowerCase() === 'p') {\n onValueChange(1)\n }\n return\n }\n\n // Arrow up/down to increment/decrement\n if (e.key === 'ArrowUp') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n const newValue = value === undefined ? config.min : value >= config.max ? config.min : value + 1\n onValueChange(newValue)\n return\n }\n if (e.key === 'ArrowDown') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n const newValue = value === undefined ? config.max : value <= config.min ? config.max : value - 1\n onValueChange(newValue)\n return\n }\n\n // Home/End for min/max\n if (e.key === 'Home') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(config.min)\n return\n }\n if (e.key === 'End') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(config.max)\n return\n }\n\n // Numeric input - directly manipulate DOM, no React state\n if (e.key >= '0' && e.key <= '9') {\n e.preventDefault()\n const newBuffer = editBufferRef.current + e.key\n const numValue = parseInt(newBuffer, 10)\n\n // For 2-digit fields\n if (config.length === 2) {\n if (newBuffer.length >= 2) {\n // Two digits entered - commit and advance\n const clamped = Math.max(config.min, Math.min(config.max, numValue))\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(clamped)\n onRightFocus?.()\n } else if (numValue * 10 > config.max) {\n // First digit is too large to form a valid two-digit number\n const clamped = Math.max(config.min, Math.min(config.max, numValue))\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(clamped)\n onRightFocus?.()\n } else {\n // First digit could lead to valid values, wait for second digit\n // Update refs and DOM directly - NO state update\n editBufferRef.current = newBuffer\n isEditingRef.current = true\n if (inputRef.current) {\n inputRef.current.value = newBuffer\n }\n }\n } else if (config.length === 4) {\n // Year field - advance after 4 digits\n if (newBuffer.length >= 4) {\n const clamped = Math.max(config.min, Math.min(config.max, numValue))\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(clamped)\n onRightFocus?.()\n } else {\n // Update refs and DOM directly - NO state update\n editBufferRef.current = newBuffer\n isEditingRef.current = true\n if (inputRef.current) {\n inputRef.current.value = newBuffer\n }\n }\n }\n return\n }\n\n if (e.key === 'Backspace') {\n e.preventDefault()\n if (editBufferRef.current) {\n const newBuffer = editBufferRef.current.slice(0, -1)\n editBufferRef.current = newBuffer\n isEditingRef.current = newBuffer.length > 0\n if (inputRef.current) {\n inputRef.current.value = newBuffer || displayValue\n }\n } else if (value !== undefined) {\n editBufferRef.current = ''\n isEditingRef.current = true\n onValueChange(config.min)\n if (inputRef.current) {\n inputRef.current.value = placeholderText\n }\n }\n }\n },\n [disabled, config, value, displayValue, placeholderText, onValueChange, onLeftFocus, onRightFocus, commitEdit],\n )\n\n const handleBlur = useCallback(() => {\n // Only commit if we have a partial edit\n if (editBufferRef.current) {\n commitEdit()\n }\n }, [commitEdit])\n\n const handleFocus = useCallback(() => {\n // Only clear buffer if we're not in the middle of an edit\n if (!isEditingRef.current) {\n editBufferRef.current = ''\n }\n // Move cursor to end\n const input = inputRef.current\n if (input) {\n const len = input.value.length\n input.setSelectionRange(len, len)\n }\n }, [])\n\n // Prevent browser from changing the input value directly\n const handleChange = useCallback(() => {\n // Reset to our controlled value if browser tries to change it\n if (inputRef.current) {\n inputRef.current.value = editBufferRef.current || displayValue\n }\n }, [displayValue])\n\n // Width and padding based on segment type\n const getSegmentStyle = useCallback(() => {\n switch (config.type) {\n case 'year':\n return { width: 46, paddingLeft: 0 }\n case 'period':\n return { width: 28, paddingLeft: 0, marginLeft: 4 }\n case 'month':\n return { width: 28, paddingLeft: 0 }\n case 'day':\n return { width: 28, paddingLeft: 0 }\n case 'hour':\n return { width: 28, paddingLeft: 0 }\n case 'minute':\n return { width: 30, paddingLeft: 0 }\n default:\n return { width: 24, paddingLeft: 0 }\n }\n }, [config.type])\n\n const segmentStyle = useMemo(() => getSegmentStyle(), [getSegmentStyle])\n const isPlaceholder = useMemo(() => value === undefined, [value])\n\n return (\n <input\n aria-label={ariaLabel}\n aria-valuemax={config.max}\n aria-valuemin={config.min}\n aria-valuenow={value}\n className={cn(\n 'rounded inline-flex items-center justify-center text-center tabular-nums',\n 'border-none bg-transparent outline-none',\n 'focus:bg-bg-tertiary focus:text-text-primary focus:ring-1 focus:ring-accent',\n 'hover:bg-bg-secondary',\n disabled && 'cursor-not-allowed opacity-50',\n isPlaceholder && 'text-text-placeholder text-sm',\n )}\n data-segment={config.type}\n defaultValue={displayValue}\n disabled={disabled}\n inputMode='numeric'\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n ref={inputRef}\n role='spinbutton'\n style={segmentStyle}\n tabIndex={disabled ? -1 : 0}\n />\n )\n}\n\n/**\n * A segmented date/time input that mimics native date input behavior.\n * Each segment (month, day, year, hour, minute, period) is separately focusable.\n *\n * Supports both controlled and uncontrolled usage:\n * - Controlled: `<DateTimeDisplayInput value={date} onChange={setDate} />`\n * - Uncontrolled: `<DateTimeDisplayInput defaultValue={new Date()} />`\n *\n * @example\n * ```tsx\n * // Controlled usage\n * const [date, setDate] = useState<Date | undefined>(new Date())\n * <DateTimeDisplayInput value={date} onChange={setDate} />\n *\n * // Uncontrolled usage\n * <DateTimeDisplayInput defaultValue={new Date()} />\n *\n * // Legacy props (deprecated, use value/onChange instead)\n * <DateTimeDisplayInput date={date} onDateChange={setDate} />\n * ```\n */\nexport const DateTimeDisplayInput = forwardRef<HTMLDivElement, DateTimeDisplayInputProps>(\n (\n {\n className,\n defaultValue,\n disabled,\n endIcon,\n hourFormat = '12',\n id,\n label,\n locale,\n onChange,\n showTime = true,\n state = 'default',\n value,\n 'aria-labelledby': ariaLabelledBy,\n // Legacy props (deprecated)\n date: legacyDate,\n onDateChange: legacyOnDateChange,\n ...props\n },\n ref,\n ) => {\n const generatedId = useId()\n const displayInputId = id ?? `datetime-display-input-${generatedId}`\n const displayLabelId = `${displayInputId}-label`\n const containerRef = useRef<HTMLDivElement>(null)\n const resolvedAriaLabelledBy = [label ? displayLabelId : undefined, ariaLabelledBy].filter(Boolean).join(' ') || undefined\n\n // Support both new (value/onChange) and legacy (date/onDateChange) prop names\n const effectiveValue = value ?? legacyDate\n const effectiveOnChange = onChange ?? legacyOnDateChange\n\n // Use controllable state to support both controlled and uncontrolled usage\n const [date, setDate] = useUncontrolledState<Date | undefined>({\n defaultValue: defaultValue,\n onChange: effectiveOnChange,\n value: effectiveValue,\n })\n\n // Resolve locale and get period labels\n const resolvedLocale = useMemo(() => getResolvedLocale(locale), [locale])\n const periodLabels = useMemo(() => getLocalizedPeriodLabels(resolvedLocale), [resolvedLocale])\n\n // Extract values from date\n const values = useMemo(() => {\n if (!date) return { month: undefined, day: undefined, year: undefined, hour: undefined, minute: undefined, period: undefined as 0 | 1 | undefined }\n\n const hours = date.getHours()\n let displayHour: number\n let period: 0 | 1\n\n if (hourFormat === '24') {\n displayHour = hours\n period = 0\n } else {\n period = hours >= 12 ? 1 : 0\n displayHour = hours % 12\n if (displayHour === 0) displayHour = 12\n }\n\n return {\n month: date.getMonth() + 1,\n day: date.getDate(),\n year: date.getFullYear(),\n hour: displayHour,\n minute: date.getMinutes(),\n period,\n }\n }, [date, hourFormat])\n\n // Check if date is complete (all date parts filled in)\n // Time inputs should be disabled until a valid date is entered\n const isDateComplete = values.month !== undefined && values.day !== undefined && values.year !== undefined\n\n // Build the date from segment values\n const updateDate = useCallback(\n (updates: Partial<typeof values>) => {\n const newValues = { ...values, ...updates }\n\n // If all date parts are undefined, clear the date\n if (newValues.month === undefined && newValues.day === undefined && newValues.year === undefined) {\n setDate(undefined)\n return\n }\n\n // Use current date as base for any undefined values\n const now = new Date()\n const month = (newValues.month ?? now.getMonth() + 1) - 1\n const day = newValues.day ?? now.getDate()\n const year = newValues.year ?? now.getFullYear()\n\n // Clamp day to max days in month\n const maxDays = getMaxDaysInMonth(month + 1, year)\n const clampedDay = Math.min(day, maxDays)\n\n // Check if date just became complete (was incomplete before, complete now)\n const wasDateComplete = values.month !== undefined && values.day !== undefined && values.year !== undefined\n const isNowDateComplete = newValues.month !== undefined && newValues.day !== undefined && newValues.year !== undefined\n const dateJustCompleted = !wasDateComplete && isNowDateComplete\n\n let hours: number\n if (hourFormat === '24') {\n // Default to 0:00 (midnight) when date first completed in 24-hour format\n hours = dateJustCompleted ? 0 : (newValues.hour ?? 0)\n } else {\n // Default to 12:00 pm when date first completed in 12-hour format\n const defaultHour = dateJustCompleted ? 12 : (newValues.hour ?? 12)\n const defaultPeriod = dateJustCompleted ? 1 : (newValues.period ?? 0) // pm by default\n const hour12 = defaultHour\n const period = defaultPeriod\n if (hour12 === 12) {\n hours = period === 0 ? 0 : 12\n } else {\n hours = period === 0 ? hour12 : hour12 + 12\n }\n }\n\n const minutes = dateJustCompleted ? 0 : (newValues.minute ?? 0)\n\n const newDate = new Date(year, month, clampedDay, hours, minutes, 0, 0)\n setDate(newDate)\n },\n [values, hourFormat, setDate],\n )\n\n // Define segments based on format\n const segments = useMemo(() => {\n const dateSegments = [\n { key: 'month', config: SEGMENT_CONFIGS.month, ariaLabel: 'Month' },\n { key: 'day', config: SEGMENT_CONFIGS.day, ariaLabel: 'Day' },\n { key: 'year', config: SEGMENT_CONFIGS.year, ariaLabel: 'Year' },\n ]\n\n if (!showTime) return dateSegments\n\n const timeSegments =\n hourFormat === '24'\n ? [\n { key: 'hour', config: SEGMENT_CONFIGS.hour24, ariaLabel: 'Hours' },\n { key: 'minute', config: SEGMENT_CONFIGS.minute, ariaLabel: 'Minutes' },\n ]\n : [\n { key: 'hour', config: SEGMENT_CONFIGS.hour12, ariaLabel: 'Hours' },\n { key: 'minute', config: SEGMENT_CONFIGS.minute, ariaLabel: 'Minutes' },\n { key: 'period', config: SEGMENT_CONFIGS.period, ariaLabel: formatSelectPeriodLabel(periodLabels, 'Select {am} or {pm}') },\n ]\n\n return [...dateSegments, ...timeSegments]\n }, [showTime, hourFormat, periodLabels])\n\n // Focus helpers\n const focusSegment = useCallback((index: number) => {\n const segment = containerRef.current?.querySelectorAll(`[role='spinbutton']`)[index] as HTMLElement\n segment?.focus()\n }, [])\n\n const inputClasses = getInputClasses(state)\n\n return (\n <div className='gap-1.5 flex flex-col'>\n {label && (\n <Label className='text-sm font-medium text-text-primary' id={displayLabelId}>\n {label}\n </Label>\n )}\n <div className={cn(inputClasses, 'relative', (disabled ?? state === 'disabled') && 'cursor-not-allowed', className)} data-slot='datetime-display-input' id={displayInputId} ref={ref ?? containerRef} aria-labelledby={resolvedAriaLabelledBy} {...props}>\n <div className='flex items-center' ref={containerRef}>\n {segments.map((segment, index) => {\n const isDateSegment = ['month', 'day', 'year'].includes(segment.key)\n const isTimeSegment = ['hour', 'minute', 'period'].includes(segment.key)\n const isLastDateSegment = segment.key === 'year'\n const isFirstTimeSegment = segment.key === 'hour'\n\n // Disable time segments until date is complete\n const isSegmentDisabled = disabled ?? (isTimeSegment && !isDateComplete)\n\n return (\n <span key={segment.key} className='flex items-center'>\n {/* Add comma and space before time section */}\n {isFirstTimeSegment && (\n <span aria-hidden='true' className='text-text-secondary select-none'>\n ,&nbsp;\n </span>\n )}\n\n <SegmentInput\n ariaLabel={segment.ariaLabel}\n config={segment.config}\n disabled={isSegmentDisabled}\n onLeftFocus={() => index > 0 && focusSegment(index - 1)}\n onRightFocus={() => index < segments.length - 1 && focusSegment(index + 1)}\n onValueChange={(val) => updateDate({ [segment.key]: val })}\n periodLabels={periodLabels}\n value={values[segment.key as keyof typeof values]}\n />\n\n {/* Date separators */}\n {isDateSegment && !isLastDateSegment && (\n <span aria-hidden='true' className='text-text-secondary select-none'>\n /\n </span>\n )}\n\n {/* Time separator - colon between hour and minute */}\n {isFirstTimeSegment && (\n <span aria-hidden='true' className='text-inherit select-none'>\n :\n </span>\n )}\n </span>\n )\n })}\n </div>\n {endIcon}\n </div>\n </div>\n )\n },\n)\nDateTimeDisplayInput.displayName = 'DateTimeDisplayInput'\n"],"mappings":";;;;;;;;;;AAgCA,MAAM,kBAAiD;CACrD,OAAO;EAAE,MAAM;EAAS,KAAK;EAAG,KAAK;EAAI,QAAQ;EAAG;CACpD,KAAK;EAAE,MAAM;EAAO,KAAK;EAAG,KAAK;EAAI,QAAQ;EAAG;CAChD,MAAM;EAAE,MAAM;EAAQ,KAAK;EAAM,KAAK;EAAM,QAAQ;EAAG;CACvD,QAAQ;EAAE,MAAM;EAAQ,KAAK;EAAG,KAAK;EAAI,QAAQ;EAAG;CACpD,QAAQ;EAAE,MAAM;EAAQ,KAAK;EAAG,KAAK;EAAI,QAAQ;EAAG;CACpD,QAAQ;EAAE,MAAM;EAAU,KAAK;EAAG,KAAK;EAAI,QAAQ;EAAG;CACtD,QAAQ;EAAE,MAAM;EAAU,KAAK;EAAG,KAAK;EAAG,QA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MAAM,gBAAgB;MAAC;MAAS;MAAO;MAAO,CAAC,SAAS,QAAQ,IAAI;KACpE,MAAM,gBAAgB;MAAC;MAAQ;MAAU;MAAS,CAAC,SAAS,QAAQ,IAAI;KACxE,MAAM,oBAAoB,QAAQ,QAAQ;KAC1C,MAAM,qBAAqB,QAAQ,QAAQ;KAG3C,MAAM,oBAAoB,aAAa,iBAAiB,CAAC;AAEzD,YACE,qBAAC,QAAD;MAAwB,WAAU;gBAAlC;OAEG,sBACC,oBAAC,QAAD;QAAM,eAAY;QAAO,WAAU;kBAAkC;QAE9D;OAGT,oBAAC,cAAD;QACE,WAAW,QAAQ;QACnB,QAAQ,QAAQ;QAChB,UAAU;QACV,mBAAmB,QAAQ,KAAK,aAAa,QAAQ,EAAE;QACvD,oBAAoB,QAAQ,SAAS,SAAS,KAAK,aAAa,QAAQ,EAAE;QAC1E,gBAAgB,QAAQ,WAAW,GAAG,QAAQ,MAAM,KAAK,CAAC;QAC5C;QACd,OAAO,OAAO,QAAQ;QACtB;OAGD,iBAAiB,CAAC,qBACjB,oBAAC,QAAD;QAAM,eAAY;QAAO,WAAU;kBAAkC;QAE9D;OAIR,sBACC,oBAAC,QAAD;QAAM,eAAY;QAAO,WAAU;kBAA2B;QAEvD;OAEJ;QAhCI,QAAQ,IAgCZ;MAET;IACE,GACL,QACG;KACF;;EAGX;AACD,qBAAqB,cAAc"}
1
+ {"version":3,"file":"DateTimeDisplayInput.js","names":[],"sources":["../../src/components/DateTimePicker/DateTimeDisplayInput.tsx"],"sourcesContent":["import { Label } from '@components/Label/Label'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { getInputClasses } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { forwardRef, useCallback, useEffect, useId, useMemo, useRef, type ComponentProps, type KeyboardEvent, type ReactNode } from 'react'\nimport { formatSelectPeriodLabel, getLocalizedPeriodLabels, getResolvedLocale, type HourFormat, type PeriodLabels } from './DateTimeUtils'\n\nexport interface DateTimeDisplayInputProps extends Omit<ComponentProps<'div'>, 'onChange' | 'defaultValue'> {\n defaultValue?: Date\n disabled?: boolean\n endIcon?: ReactNode\n hideTime?: boolean\n hourFormat?: HourFormat\n label?: string\n locale?: string\n onChange?: (date: Date | undefined) => void\n state?: 'default' | 'disabled' | 'error' | 'warning'\n value?: Date\n // Legacy prop names for backward compatibility\n /** @deprecated Use `value` instead */\n date?: Date\n /** @deprecated Use `onChange` instead */\n onDateChange?: (date: Date | undefined) => void\n}\n\ninterface SegmentConfig {\n length: number\n max: number\n min: number\n type: 'month' | 'day' | 'year' | 'hour' | 'minute' | 'period'\n}\n\nconst SEGMENT_CONFIGS: Record<string, SegmentConfig> = {\n month: { type: 'month', min: 1, max: 12, length: 2 },\n day: { type: 'day', min: 1, max: 31, length: 2 },\n year: { type: 'year', min: 1900, max: 2100, length: 4 },\n hour12: { type: 'hour', min: 1, max: 12, length: 2 },\n hour24: { type: 'hour', min: 0, max: 23, length: 2 },\n minute: { type: 'minute', min: 0, max: 59, length: 2 },\n period: { type: 'period', min: 0, max: 1, length: 2 },\n}\n\n/**\n * Get max days for a given month/year\n */\nconst getMaxDaysInMonth = (month: number, year: number): number => {\n if (month === 2) {\n const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n return isLeapYear ? 29 : 28\n }\n if ([4, 6, 9, 11].includes(month)) return 30\n return 31\n}\n\n/**\n * A single segment input (month, day, year, hour, minute)\n */\ninterface SegmentInputProps {\n ariaLabel: string\n config: SegmentConfig\n disabled?: boolean\n onLeftFocus?: () => void\n onRightFocus?: () => void\n onValueChange: (value: number) => void\n periodLabels?: PeriodLabels\n value: number | undefined\n}\n\n/**\n * SegmentInput - A single editable segment (month, day, year, hour, minute, period)\n *\n * Uses an uncontrolled input pattern to avoid React re-render issues during typing:\n * - Edit buffer stored in ref (not state) to prevent re-renders\n * - DOM value manipulated directly during typing\n * - Only syncs with React when value is committed (blur, tab, arrow keys)\n */\nconst SegmentInput = ({ ariaLabel, config, disabled, onLeftFocus, onRightFocus, onValueChange, periodLabels, value }: SegmentInputProps) => {\n const inputRef = useRef<HTMLInputElement>(null)\n // Use refs to avoid re-renders during typing - this is the key to making it work\n const editBufferRef = useRef('')\n const isEditingRef = useRef(false)\n\n // Placeholder text for empty segments\n const placeholderText = useMemo(() => {\n switch (config.type) {\n case 'month':\n return 'MM'\n case 'day':\n return 'dd'\n case 'year':\n return 'yyyy'\n case 'hour':\n return config.max === 23 ? 'HH' : 'hh'\n case 'minute':\n return 'mm'\n case 'period':\n return periodLabels?.am ?? 'am'\n default:\n return '––'\n }\n }, [config.type, config.max, periodLabels])\n\n // Format display value from the committed value prop\n const displayValue = useMemo(() => {\n if (value === undefined) {\n return placeholderText\n }\n if (config.type === 'period') {\n const label = value === 0 ? (periodLabels?.am ?? 'am') : (periodLabels?.pm ?? 'pm')\n return label\n }\n return value.toString().padStart(config.length, '0')\n }, [value, config, periodLabels, placeholderText])\n\n // Sync input value when external value changes (and we're not editing)\n useEffect(() => {\n if (inputRef.current && !isEditingRef.current) {\n inputRef.current.value = displayValue\n }\n }, [displayValue])\n\n // Commit the edit buffer - called on blur, tab, arrow navigation\n const commitEdit = useCallback(() => {\n const buffer = editBufferRef.current\n if (buffer) {\n let numValue = parseInt(buffer, 10)\n if (!isNaN(numValue)) {\n numValue = Math.max(config.min, Math.min(config.max, numValue))\n onValueChange(numValue)\n }\n }\n // Reset edit state\n editBufferRef.current = ''\n isEditingRef.current = false\n // Sync display value after commit\n if (inputRef.current) {\n inputRef.current.value = displayValue\n }\n }, [config.min, config.max, displayValue, onValueChange])\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement>) => {\n if (disabled) return\n\n // Tab navigation (let it bubble naturally)\n if (e.key === 'Tab') {\n commitEdit()\n return\n }\n\n // Arrow navigation between segments\n if (e.key === 'ArrowRight') {\n e.preventDefault()\n commitEdit()\n onRightFocus?.()\n return\n }\n if (e.key === 'ArrowLeft') {\n e.preventDefault()\n commitEdit()\n onLeftFocus?.()\n return\n }\n\n // Period toggle (am/pm)\n if (config.type === 'period') {\n e.preventDefault()\n if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n onValueChange(value === 0 ? 1 : 0)\n } else if (e.key.toLowerCase() === 'a') {\n onValueChange(0)\n } else if (e.key.toLowerCase() === 'p') {\n onValueChange(1)\n }\n return\n }\n\n // Arrow up/down to increment/decrement\n if (e.key === 'ArrowUp') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n const newValue = value === undefined ? config.min : value >= config.max ? config.min : value + 1\n onValueChange(newValue)\n return\n }\n if (e.key === 'ArrowDown') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n const newValue = value === undefined ? config.max : value <= config.min ? config.max : value - 1\n onValueChange(newValue)\n return\n }\n\n // Home/End for min/max\n if (e.key === 'Home') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(config.min)\n return\n }\n if (e.key === 'End') {\n e.preventDefault()\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(config.max)\n return\n }\n\n // Numeric input - directly manipulate DOM, no React state\n if (e.key >= '0' && e.key <= '9') {\n e.preventDefault()\n const newBuffer = editBufferRef.current + e.key\n const numValue = parseInt(newBuffer, 10)\n\n // For 2-digit fields\n if (config.length === 2) {\n if (newBuffer.length >= 2) {\n // Two digits entered - commit and advance\n const clamped = Math.max(config.min, Math.min(config.max, numValue))\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(clamped)\n onRightFocus?.()\n } else if (numValue * 10 > config.max) {\n // First digit is too large to form a valid two-digit number\n const clamped = Math.max(config.min, Math.min(config.max, numValue))\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(clamped)\n onRightFocus?.()\n } else {\n // First digit could lead to valid values, wait for second digit\n // Update refs and DOM directly - NO state update\n editBufferRef.current = newBuffer\n isEditingRef.current = true\n if (inputRef.current) {\n inputRef.current.value = newBuffer\n }\n }\n } else if (config.length === 4) {\n // Year field - advance after 4 digits\n if (newBuffer.length >= 4) {\n const clamped = Math.max(config.min, Math.min(config.max, numValue))\n editBufferRef.current = ''\n isEditingRef.current = false\n onValueChange(clamped)\n onRightFocus?.()\n } else {\n // Update refs and DOM directly - NO state update\n editBufferRef.current = newBuffer\n isEditingRef.current = true\n if (inputRef.current) {\n inputRef.current.value = newBuffer\n }\n }\n }\n return\n }\n\n if (e.key === 'Backspace') {\n e.preventDefault()\n if (editBufferRef.current) {\n const newBuffer = editBufferRef.current.slice(0, -1)\n editBufferRef.current = newBuffer\n isEditingRef.current = newBuffer.length > 0\n if (inputRef.current) {\n inputRef.current.value = newBuffer || displayValue\n }\n } else if (value !== undefined) {\n editBufferRef.current = ''\n isEditingRef.current = true\n onValueChange(config.min)\n if (inputRef.current) {\n inputRef.current.value = placeholderText\n }\n }\n }\n },\n [disabled, config, value, displayValue, placeholderText, onValueChange, onLeftFocus, onRightFocus, commitEdit],\n )\n\n const handleBlur = useCallback(() => {\n // Only commit if we have a partial edit\n if (editBufferRef.current) {\n commitEdit()\n }\n }, [commitEdit])\n\n const handleFocus = useCallback(() => {\n // Only clear buffer if we're not in the middle of an edit\n if (!isEditingRef.current) {\n editBufferRef.current = ''\n }\n // Move cursor to end\n const input = inputRef.current\n if (input) {\n const len = input.value.length\n input.setSelectionRange(len, len)\n }\n }, [])\n\n // Prevent browser from changing the input value directly\n const handleChange = useCallback(() => {\n // Reset to our controlled value if browser tries to change it\n if (inputRef.current) {\n inputRef.current.value = editBufferRef.current || displayValue\n }\n }, [displayValue])\n\n // Width and padding based on segment type\n const getSegmentStyle = useCallback(() => {\n switch (config.type) {\n case 'year':\n return { width: 46, paddingLeft: 0 }\n case 'period':\n return { width: 28, paddingLeft: 0, marginLeft: 4 }\n case 'month':\n return { width: 28, paddingLeft: 0 }\n case 'day':\n return { width: 28, paddingLeft: 0 }\n case 'hour':\n return { width: 28, paddingLeft: 0 }\n case 'minute':\n return { width: 30, paddingLeft: 0 }\n default:\n return { width: 24, paddingLeft: 0 }\n }\n }, [config.type])\n\n const segmentStyle = useMemo(() => getSegmentStyle(), [getSegmentStyle])\n const isPlaceholder = useMemo(() => value === undefined, [value])\n\n return (\n <input\n aria-label={ariaLabel}\n aria-valuemax={config.max}\n aria-valuemin={config.min}\n aria-valuenow={value}\n className={cn(\n 'rounded inline-flex items-center justify-center text-center tabular-nums',\n 'border-none bg-transparent outline-none',\n 'focus:bg-bg-tertiary focus:text-text-primary focus:ring-1 focus:ring-accent',\n 'hover:bg-bg-secondary',\n disabled && 'cursor-not-allowed opacity-50',\n isPlaceholder && 'text-text-placeholder text-sm',\n )}\n data-segment={config.type}\n defaultValue={displayValue}\n disabled={disabled}\n inputMode='numeric'\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n ref={inputRef}\n role='spinbutton'\n style={segmentStyle}\n tabIndex={disabled ? -1 : 0}\n />\n )\n}\n\n/**\n * A segmented date/time input that mimics native date input behavior.\n * Each segment (month, day, year, hour, minute, period) is separately focusable.\n *\n * Supports both controlled and uncontrolled usage:\n * - Controlled: `<DateTimeDisplayInput value={date} onChange={setDate} />`\n * - Uncontrolled: `<DateTimeDisplayInput defaultValue={new Date()} />`\n *\n * @example\n * ```tsx\n * // Controlled usage\n * const [date, setDate] = useState<Date | undefined>(new Date())\n * <DateTimeDisplayInput value={date} onChange={setDate} />\n *\n * // Uncontrolled usage\n * <DateTimeDisplayInput defaultValue={new Date()} />\n *\n * // Legacy props (deprecated, use value/onChange instead)\n * <DateTimeDisplayInput date={date} onDateChange={setDate} />\n * ```\n */\nexport const DateTimeDisplayInput = forwardRef<HTMLDivElement, DateTimeDisplayInputProps>(\n (\n {\n className,\n defaultValue,\n disabled,\n endIcon,\n hourFormat = '12',\n id,\n label,\n locale,\n onChange,\n hideTime = false,\n state = 'default',\n value,\n 'aria-labelledby': ariaLabelledBy,\n // Legacy props (deprecated)\n date: legacyDate,\n onDateChange: legacyOnDateChange,\n ...props\n },\n ref,\n ) => {\n const generatedId = useId()\n const displayInputId = id ?? `datetime-display-input-${generatedId}`\n const displayLabelId = `${displayInputId}-label`\n const containerRef = useRef<HTMLDivElement>(null)\n const resolvedAriaLabelledBy = [label ? displayLabelId : undefined, ariaLabelledBy].filter(Boolean).join(' ') || undefined\n\n // Support both new (value/onChange) and legacy (date/onDateChange) prop names\n const effectiveValue = value ?? legacyDate\n const effectiveOnChange = onChange ?? legacyOnDateChange\n\n // Use controllable state to support both controlled and uncontrolled usage\n const [date, setDate] = useUncontrolledState<Date | undefined>({\n defaultValue: defaultValue,\n onChange: effectiveOnChange,\n value: effectiveValue,\n })\n\n // Resolve locale and get period labels\n const resolvedLocale = useMemo(() => getResolvedLocale(locale), [locale])\n const periodLabels = useMemo(() => getLocalizedPeriodLabels(resolvedLocale), [resolvedLocale])\n\n // Extract values from date\n const values = useMemo(() => {\n if (!date) return { month: undefined, day: undefined, year: undefined, hour: undefined, minute: undefined, period: undefined as 0 | 1 | undefined }\n\n const hours = date.getHours()\n let displayHour: number\n let period: 0 | 1\n\n if (hourFormat === '24') {\n displayHour = hours\n period = 0\n } else {\n period = hours >= 12 ? 1 : 0\n displayHour = hours % 12\n if (displayHour === 0) displayHour = 12\n }\n\n return {\n month: date.getMonth() + 1,\n day: date.getDate(),\n year: date.getFullYear(),\n hour: displayHour,\n minute: date.getMinutes(),\n period,\n }\n }, [date, hourFormat])\n\n // Check if date is complete (all date parts filled in)\n // Time inputs should be disabled until a valid date is entered\n const isDateComplete = values.month !== undefined && values.day !== undefined && values.year !== undefined\n\n // Build the date from segment values\n const updateDate = useCallback(\n (updates: Partial<typeof values>) => {\n const newValues = { ...values, ...updates }\n\n // If all date parts are undefined, clear the date\n if (newValues.month === undefined && newValues.day === undefined && newValues.year === undefined) {\n setDate(undefined)\n return\n }\n\n // Use current date as base for any undefined values\n const now = new Date()\n const month = (newValues.month ?? now.getMonth() + 1) - 1\n const day = newValues.day ?? now.getDate()\n const year = newValues.year ?? now.getFullYear()\n\n // Clamp day to max days in month\n const maxDays = getMaxDaysInMonth(month + 1, year)\n const clampedDay = Math.min(day, maxDays)\n\n // Check if date just became complete (was incomplete before, complete now)\n const wasDateComplete = values.month !== undefined && values.day !== undefined && values.year !== undefined\n const isNowDateComplete = newValues.month !== undefined && newValues.day !== undefined && newValues.year !== undefined\n const dateJustCompleted = !wasDateComplete && isNowDateComplete\n\n let hours: number\n if (hourFormat === '24') {\n // Default to 0:00 (midnight) when date first completed in 24-hour format\n hours = dateJustCompleted ? 0 : (newValues.hour ?? 0)\n } else {\n // Default to 12:00 pm when date first completed in 12-hour format\n const defaultHour = dateJustCompleted ? 12 : (newValues.hour ?? 12)\n const defaultPeriod = dateJustCompleted ? 1 : (newValues.period ?? 0) // pm by default\n const hour12 = defaultHour\n const period = defaultPeriod\n if (hour12 === 12) {\n hours = period === 0 ? 0 : 12\n } else {\n hours = period === 0 ? hour12 : hour12 + 12\n }\n }\n\n const minutes = dateJustCompleted ? 0 : (newValues.minute ?? 0)\n\n const newDate = new Date(year, month, clampedDay, hours, minutes, 0, 0)\n setDate(newDate)\n },\n [values, hourFormat, setDate],\n )\n\n // Define segments based on format\n const segments = useMemo(() => {\n const dateSegments = [\n { key: 'month', config: SEGMENT_CONFIGS.month, ariaLabel: 'Month' },\n { key: 'day', config: SEGMENT_CONFIGS.day, ariaLabel: 'Day' },\n { key: 'year', config: SEGMENT_CONFIGS.year, ariaLabel: 'Year' },\n ]\n\n if (hideTime) return dateSegments\n\n const timeSegments =\n hourFormat === '24'\n ? [\n { key: 'hour', config: SEGMENT_CONFIGS.hour24, ariaLabel: 'Hours' },\n { key: 'minute', config: SEGMENT_CONFIGS.minute, ariaLabel: 'Minutes' },\n ]\n : [\n { key: 'hour', config: SEGMENT_CONFIGS.hour12, ariaLabel: 'Hours' },\n { key: 'minute', config: SEGMENT_CONFIGS.minute, ariaLabel: 'Minutes' },\n { key: 'period', config: SEGMENT_CONFIGS.period, ariaLabel: formatSelectPeriodLabel(periodLabels, 'Select {am} or {pm}') },\n ]\n\n return [...dateSegments, ...timeSegments]\n }, [hideTime, hourFormat, periodLabels])\n\n // Focus helpers\n const focusSegment = useCallback((index: number) => {\n const segment = containerRef.current?.querySelectorAll(`[role='spinbutton']`)[index] as HTMLElement\n segment?.focus()\n }, [])\n\n const inputClasses = getInputClasses(state)\n\n return (\n <div className='gap-1.5 flex flex-col'>\n {label && (\n <Label className='text-sm font-medium text-text-primary' id={displayLabelId}>\n {label}\n </Label>\n )}\n <div className={cn(inputClasses, 'relative', (disabled ?? state === 'disabled') && 'cursor-not-allowed', className)} data-slot='datetime-display-input' id={displayInputId} ref={ref ?? containerRef} aria-labelledby={resolvedAriaLabelledBy} {...props}>\n <div className='flex items-center' ref={containerRef}>\n {segments.map((segment, index) => {\n const isDateSegment = ['month', 'day', 'year'].includes(segment.key)\n const isTimeSegment = ['hour', 'minute', 'period'].includes(segment.key)\n const isLastDateSegment = segment.key === 'year'\n const isFirstTimeSegment = segment.key === 'hour'\n\n // Disable time segments until date is complete\n const isSegmentDisabled = disabled ?? (isTimeSegment && !isDateComplete)\n\n return (\n <span key={segment.key} className='flex items-center'>\n {/* Add comma and space before time section */}\n {isFirstTimeSegment && (\n <span aria-hidden='true' className='text-text-secondary select-none'>\n ,&nbsp;\n </span>\n )}\n\n <SegmentInput\n ariaLabel={segment.ariaLabel}\n config={segment.config}\n disabled={isSegmentDisabled}\n onLeftFocus={() => index > 0 && focusSegment(index - 1)}\n onRightFocus={() => index < segments.length - 1 && focusSegment(index + 1)}\n onValueChange={(val) => updateDate({ [segment.key]: val })}\n periodLabels={periodLabels}\n value={values[segment.key as keyof typeof values]}\n />\n\n {/* Date separators */}\n {isDateSegment && !isLastDateSegment && (\n <span aria-hidden='true' className='text-text-secondary select-none'>\n /\n </span>\n )}\n\n {/* Time separator - colon between hour and minute */}\n {isFirstTimeSegment && (\n <span aria-hidden='true' className='text-inherit select-none'>\n :\n </span>\n )}\n </span>\n )\n })}\n </div>\n {end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oBAAC,QAAD;QAAM,eAAY;QAAO,WAAU;kBAAkC;QAE9D;OAIR,sBACC,oBAAC,QAAD;QAAM,eAAY;QAAO,WAAU;kBAA2B;QAEvD;OAEJ;QAhCI,QAAQ,IAgCZ;MAET;IACE,GACL,QACG;KACF;;EAGX;AACD,qBAAqB,cAAc"}
@@ -16,19 +16,28 @@ interface DateTimePickerProps extends Omit<ComponentProps<'div'>, 'onChange' | '
16
16
  disabled?: boolean;
17
17
  disablePastDates?: boolean;
18
18
  errorMessage?: string | string[] | Record<string, unknown> | null;
19
+ hideTimePicker?: boolean;
19
20
  hourFormat?: HourFormat;
20
21
  inputClassName?: string;
21
22
  label?: string;
22
23
  locale?: Partial<Locale$1>;
24
+ maxDate?: Date;
25
+ minDate?: Date;
23
26
  messageReserveLines?: number;
24
27
  messageReserveSpace?: boolean;
25
28
  onChange?: (date: Date | undefined) => void;
26
- showTimePicker?: boolean;
27
- state?: 'default' | 'disabled' | 'error';
29
+ state?: 'default' | 'disabled' | 'error' | 'warning';
28
30
  timeLocale?: string;
31
+ /**
32
+ * The date treated as "today" in the calendar. Receives the `rdp-today` styling and is used as
33
+ * the reference for `disablePastDates`. When no value is selected, the calendar opens to this
34
+ * date's month instead of the current month. Useful when assigning dates around historical data.
35
+ */
36
+ today?: Date;
29
37
  /** Override translation strings for time picker ARIA labels */
30
38
  timeTranslations?: Partial<TimePickerTranslations>;
31
39
  value?: Date;
40
+ warningMessage?: string | string[] | Record<string, unknown> | null;
32
41
  }
33
42
  declare function DateTimePicker({
34
43
  calendarProps,
@@ -37,19 +46,23 @@ declare function DateTimePicker({
37
46
  disabled,
38
47
  disablePastDates,
39
48
  errorMessage,
49
+ hideTimePicker,
40
50
  hourFormat,
51
+ id,
41
52
  inputClassName,
42
53
  label,
43
54
  locale,
55
+ maxDate,
44
56
  messageReserveLines,
45
57
  messageReserveSpace,
58
+ minDate,
46
59
  onChange,
47
- showTimePicker,
48
60
  state,
49
61
  timeLocale,
50
62
  timeTranslations,
63
+ today,
51
64
  value,
52
- id,
65
+ warningMessage,
53
66
  ...props
54
67
  }: DateTimePickerProps): _$react_jsx_runtime0.JSX.Element;
55
68
  declare namespace DateTimePicker {
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimePicker.d.ts","names":[],"sources":["../src/components/DateTimePicker/DateTimePicker.tsx"],"mappings":";;;;;;;;;;;;UAYiB,mBAAA,SAA4B,IAAA,CAAK,cAAA;EAChD,aAAA,GAAgB,IAAA,CAAK,aAAA;EACrB,YAAA,GAAe,IAAA;EACf,QAAA;EACA,gBAAA;EACA,YAAA,uBAAmC,MAAA;EACnC,UAAA,GAAa,UAAA;EACb,cAAA;EACA,KAAA;EACA,MAAA,GAAS,OAAA,CAAQ,QAAA;EACjB,mBAAA;EACA,mBAAA;EACA,QAAA,IAAY,IAAA,EAAM,IAAA;EAClB,cAAA;EACA,KAAA;EACA,UAAA;EANiB;EAQjB,gBAAA,GAAmB,OAAA,CAAQ,sBAAA;EAC3B,KAAA,GAAQ,IAAA;AAAA;AAAA;EAIR,aAAA;EACA,SAAA;EACA,YAAA;EACA,QAAA;EACA,gBAAA;EACA,YAAA;EACA,UAAA;EACA,cAAA;EACA,KAAA;EACA,MAAA;EACA,mBAAA;EACA,mBAAA;EACA,QAAA;EACA,cAAA;EACA,KAAA;EACA,UAAA;EACA,gBAAA;EACA,KAAA;EACA,EAAA;EAAA,GACG;AAAA,GACF,mBAAA,GAAmB,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
1
+ {"version":3,"file":"DateTimePicker.d.ts","names":[],"sources":["../src/components/DateTimePicker/DateTimePicker.tsx"],"mappings":";;;;;;;;;;;;UAYiB,mBAAA,SAA4B,IAAA,CAAK,cAAA;EAChD,aAAA,GAAgB,IAAA,CAAK,aAAA;EACrB,YAAA,GAAe,IAAA;EACf,QAAA;EACA,gBAAA;EACA,YAAA,uBAAmC,MAAA;EACnC,cAAA;EACA,UAAA,GAAa,UAAA;EACb,cAAA;EACA,KAAA;EACA,MAAA,GAAS,OAAA,CAAQ,QAAA;EACjB,OAAA,GAAU,IAAA;EACV,OAAA,GAAU,IAAA;EACV,mBAAA;EACA,mBAAA;EACA,QAAA,IAAY,IAAA,EAAM,IAAA;EAClB,KAAA;EACA,UAAA;EANU;;;;;EAYV,KAAA,GAAQ,IAAA;EAGA;EADR,gBAAA,GAAmB,OAAA,CAAQ,sBAAA;EAC3B,KAAA,GAAQ,IAAA;EACR,cAAA,uBAAqC,MAAA;AAAA;AAAA;EAIrC,aAAA;EACA,SAAA;EACA,YAAA;EACA,QAAA;EACA,gBAAA;EACA,YAAA;EACA,cAAA;EACA,UAAA;EACA,EAAA;EACA,cAAA;EACA,KAAA;EACA,MAAA;EACA,OAAA;EACA,mBAAA;EACA,mBAAA;EACA,OAAA;EACA,QAAA;EACA,KAAA;EACA,UAAA;EACA,gBAAA;EACA,KAAA;EACA,KAAA;EACA,cAAA;EAAA,GACG;AAAA,GACF,mBAAA,GAAmB,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
  import { CalendarIcon } from "./Icons/CalendarIcon.js";
3
3
  import { cn } from "./utils/twUtils.js";
4
- import { ErrorMessage } from "./FormFieldMessage.js";
5
- import { getErrorMessageId, useFormFieldId } from "./utils/formFieldUtils.js";
4
+ import { ErrorMessage, WarningMessage } from "./FormFieldMessage.js";
5
+ import { getErrorMessageId, getWarningMessageId, useFormFieldId } from "./utils/formFieldUtils.js";
6
6
  import { useUncontrolledState } from "./hooks/useUncontrolledState.js";
7
7
  import { Popover, PopoverContent, PopoverTrigger } from "./Popover.js";
8
8
  import { Calendar } from "./DateTimePicker/Calendar.js";
@@ -16,10 +16,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
16
16
  import "react-day-picker";
17
17
 
18
18
  //#region src/components/DateTimePicker/DateTimePicker.tsx
19
- const DateTimePicker = ({ calendarProps, className, defaultValue, disabled = false, disablePastDates = true, errorMessage, hourFormat, inputClassName, label, locale, messageReserveLines = 1, messageReserveSpace = false, onChange, showTimePicker = true, state = "default", timeLocale, timeTranslations, value, id, ...props }) => {
19
+ const DateTimePicker = ({ calendarProps, className, defaultValue, disabled = false, disablePastDates = true, errorMessage, hideTimePicker = false, hourFormat, id, inputClassName, label, locale, maxDate, messageReserveLines = 1, messageReserveSpace = false, minDate, onChange, state = "default", timeLocale, timeTranslations, today, value, warningMessage, ...props }) => {
20
20
  const fieldId = useFormFieldId(id);
21
21
  const errorMessageId = getErrorMessageId(fieldId);
22
- const describedBy = state === "error" && errorMessage ? errorMessageId : void 0;
22
+ const warningMessageId = getWarningMessageId(fieldId);
23
+ const describedBy = state === "error" && errorMessage ? errorMessageId : state === "warning" && warningMessage ? warningMessageId : void 0;
23
24
  const [date, setDate] = useUncontrolledState({
24
25
  defaultValue,
25
26
  onChange,
@@ -46,46 +47,60 @@ const DateTimePicker = ({ calendarProps, className, defaultValue, disabled = fal
46
47
  className: cn("w-full", className),
47
48
  "data-slot": "datetime-picker",
48
49
  ...props,
49
- children: [/* @__PURE__ */ jsx(DateTimeDisplayInput, {
50
- "aria-describedby": describedBy,
51
- "aria-invalid": state === "error",
52
- className: cn("gap-4 pr-12 flex w-full justify-start", !date && "text-text-secondary", inputClassName),
53
- disabled,
54
- endIcon: /* @__PURE__ */ jsx(PopoverTrigger, {
55
- asChild: true,
50
+ children: [
51
+ /* @__PURE__ */ jsx(DateTimeDisplayInput, {
52
+ "aria-describedby": describedBy,
53
+ "aria-invalid": state === "error",
54
+ className: cn("gap-4 pr-12 flex w-full justify-start", !date && "text-text-secondary", inputClassName),
56
55
  disabled,
57
- children: /* @__PURE__ */ jsx(CalendarIcon, {
58
- "aria-label": "Open date picker",
59
- className: cn("right-4 text-input-icon hover:text-input-icon--hover absolute top-1/2 -translate-y-1/2 cursor-pointer focus:outline-none", disabled ? "pointer-events-none cursor-not-allowed opacity-50" : "hover:text-input-icon--hover cursor-pointer"),
60
- disabled
61
- })
56
+ endIcon: /* @__PURE__ */ jsx(PopoverTrigger, {
57
+ asChild: true,
58
+ disabled,
59
+ children: /* @__PURE__ */ jsx(CalendarIcon, {
60
+ "aria-label": "Open date picker",
61
+ className: cn("right-4 text-input-icon hover:text-input-icon--hover absolute top-1/2 -translate-y-1/2 cursor-pointer focus:outline-none", disabled ? "pointer-events-none cursor-not-allowed opacity-50" : "hover:text-input-icon--hover cursor-pointer"),
62
+ disabled
63
+ })
64
+ }),
65
+ hourFormat: effectiveHourFormat,
66
+ id: fieldId,
67
+ label,
68
+ onChange: handleInputDateChange,
69
+ hideTime: hideTimePicker,
70
+ state,
71
+ value: date
62
72
  }),
63
- hourFormat: effectiveHourFormat,
64
- id: fieldId,
65
- label,
66
- onChange: handleInputDateChange,
67
- showTime: showTimePicker,
68
- state,
69
- value: date
70
- }), /* @__PURE__ */ jsx(ErrorMessage, {
71
- dataTestId: "spectral-datetime-picker-error-message",
72
- id: errorMessageId,
73
- message: state === "error" ? errorMessage : null,
74
- messageReserveLines,
75
- messageReserveSpace
76
- })]
73
+ /* @__PURE__ */ jsx(ErrorMessage, {
74
+ dataTestId: "spectral-datetime-picker-error-message",
75
+ id: errorMessageId,
76
+ message: state === "error" ? errorMessage : null,
77
+ messageReserveLines,
78
+ messageReserveSpace
79
+ }),
80
+ /* @__PURE__ */ jsx(WarningMessage, {
81
+ dataTestId: "spectral-datetime-picker-warning-message",
82
+ id: warningMessageId,
83
+ message: state === "warning" ? warningMessage : null,
84
+ messageReserveLines,
85
+ messageReserveSpace
86
+ })
87
+ ]
77
88
  }), /* @__PURE__ */ jsxs(PopoverContent, {
78
89
  align: "start",
79
- className: cn("rounded-lg py-4 px-6 flex", !showTimePicker && "w-[330px]", showTimePicker && effectiveHourFormat === "24" && "w-[486px]", showTimePicker && effectiveHourFormat === "12" && "w-[560px]"),
90
+ className: cn("rounded-lg py-4 px-6 flex", hideTimePicker ? "w-[330px]" : effectiveHourFormat === "24" ? "w-[486px]" : "w-[560px]"),
80
91
  onOpenAutoFocus: (e) => e.preventDefault(),
81
92
  children: [/* @__PURE__ */ jsx(Calendar, {
82
93
  ...calendarProps,
94
+ defaultMonth: calendarProps?.defaultMonth ?? date ?? today ?? minDate,
83
95
  disablePastDates,
84
96
  locale,
97
+ maxDate,
98
+ minDate,
85
99
  mode: "single",
86
100
  onSelect: handleDateSelect,
87
- selected: date
88
- }), showTimePicker && /* @__PURE__ */ jsx("div", {
101
+ selected: date,
102
+ today
103
+ }), !hideTimePicker && /* @__PURE__ */ jsx("div", {
89
104
  className: "pl-6 border-l border-border-secondary",
90
105
  children: /* @__PURE__ */ jsx(TimePicker, {
91
106
  date,
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimePicker.js","names":[],"sources":["../src/components/DateTimePicker/DateTimePicker.tsx"],"sourcesContent":["import { CalendarIcon } from '@components/Icons'\nimport { Popover, PopoverContent, PopoverTrigger } from '@components/Popover/Popover'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { ErrorMessage, getErrorMessageId, useFormFieldId } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useCallback, useMemo, type ComponentProps } from 'react'\nimport { type Locale } from 'react-day-picker'\nimport { Calendar, type CalendarProps } from './Calendar'\nimport { DateTimeDisplayInput } from './DateTimeDisplayInput'\nimport { detectHourFormat, getResolvedLocale, type HourFormat, type Period, type TimePickerTranslations } from './DateTimeUtils'\nimport { TimePicker } from './TimePicker'\n\nexport interface DateTimePickerProps extends Omit<ComponentProps<'div'>, 'onChange' | 'defaultValue'> {\n calendarProps?: Omit<CalendarProps, 'mode' | 'selected' | 'onSelect' | 'disablePastDates' | 'locale'>\n defaultValue?: Date\n disabled?: boolean\n disablePastDates?: boolean\n errorMessage?: string | string[] | Record<string, unknown> | null\n hourFormat?: HourFormat\n inputClassName?: string\n label?: string\n locale?: Partial<Locale>\n messageReserveLines?: number\n messageReserveSpace?: boolean\n onChange?: (date: Date | undefined) => void\n showTimePicker?: boolean\n state?: 'default' | 'disabled' | 'error'\n timeLocale?: string\n /** Override translation strings for time picker ARIA labels */\n timeTranslations?: Partial<TimePickerTranslations>\n value?: Date\n}\n\nexport const DateTimePicker = ({\n calendarProps,\n className,\n defaultValue,\n disabled = false,\n disablePastDates = true,\n errorMessage,\n hourFormat,\n inputClassName,\n label,\n locale,\n messageReserveLines = 1,\n messageReserveSpace = false,\n onChange,\n showTimePicker = true,\n state = 'default',\n timeLocale,\n timeTranslations,\n value,\n id,\n ...props\n}: DateTimePickerProps) => {\n const fieldId = useFormFieldId(id)\n const errorMessageId = getErrorMessageId(fieldId)\n const describedBy = state === 'error' && errorMessage ? errorMessageId : undefined\n const [date, setDate] = useUncontrolledState<Date | undefined>({\n defaultValue,\n onChange,\n value,\n })\n\n // Resolve time locale with fallback chain\n const resolvedTimeLocale = useMemo(() => getResolvedLocale(timeLocale), [timeLocale])\n\n // Auto-detect hour format from locale if not explicitly provided\n const effectiveHourFormat = useMemo(() => hourFormat ?? detectHourFormat(resolvedTimeLocale), [hourFormat, resolvedTimeLocale])\n\n const handleDateSelect = (selectedDate: Date | undefined) => {\n if (!selectedDate) {\n setDate(undefined)\n return\n }\n\n // Preserve the time from the existing date\n if (date) {\n selectedDate.setHours(date.getHours(), date.getMinutes(), 0, 0)\n }\n\n setDate(selectedDate)\n }\n\n const handleTimeChange = useCallback(\n (newDate: Date | undefined) => {\n setDate(newDate)\n },\n [setDate],\n )\n\n const handlePeriodChange = (period: Period) => {\n // Period change is already handled in TimePicker\n // This callback is for external consumers who want to react to period changes\n void period\n }\n\n const handleInputDateChange = (newDate: Date | undefined) => {\n setDate(newDate)\n }\n\n return (\n <Popover>\n <div className={cn('w-full', className)} data-slot='datetime-picker' data-testid='spectral-datetime-picker' {...props}>\n <DateTimeDisplayInput\n aria-describedby={describedBy}\n aria-invalid={state === 'error'}\n className={cn('gap-4 pr-12 flex w-full justify-start', !date && 'text-text-secondary', inputClassName)}\n data-testid='spectral-datetime-picker-input'\n disabled={disabled}\n endIcon={\n <PopoverTrigger asChild disabled={disabled}>\n <CalendarIcon\n aria-label='Open date picker'\n className={cn('right-4 text-input-icon hover:text-input-icon--hover absolute top-1/2 -translate-y-1/2 cursor-pointer focus:outline-none', disabled ? 'pointer-events-none cursor-not-allowed opacity-50' : 'hover:text-input-icon--hover cursor-pointer')}\n data-testid='spectral-datetime-picker-trigger'\n disabled={disabled}\n />\n </PopoverTrigger>\n }\n hourFormat={effectiveHourFormat}\n id={fieldId}\n label={label}\n onChange={handleInputDateChange}\n showTime={showTimePicker}\n state={state}\n value={date}\n />\n <ErrorMessage\n dataTestId='spectral-datetime-picker-error-message'\n id={errorMessageId}\n message={state === 'error' ? errorMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace}\n />\n </div>\n\n <PopoverContent\n align='start'\n className={cn('rounded-lg py-4 px-6 flex', !showTimePicker && 'w-[330px]', showTimePicker && effectiveHourFormat === '24' && 'w-[486px]', showTimePicker && effectiveHourFormat === '12' && 'w-[560px]')}\n data-testid='spectral-datetime-picker-popover'\n onOpenAutoFocus={(e) => e.preventDefault()}\n >\n <Calendar {...calendarProps} disablePastDates={disablePastDates} locale={locale} mode='single' onSelect={handleDateSelect} selected={date} />\n {showTimePicker && (\n <div className='pl-6 border-l border-border-secondary'>\n <TimePicker date={date} hourFormat={effectiveHourFormat} locale={resolvedTimeLocale} onChange={handleTimeChange} onPeriodChange={handlePeriodChange} translations={timeTranslations} />\n </div>\n )}\n </PopoverContent>\n </Popover>\n )\n}\n\nDateTimePicker.displayName = 'DateTimePicker'\n\n// Re-export sub-components for granular usage\nexport { Calendar } from './Calendar'\nexport { DateTimeDisplayInput } from './DateTimeDisplayInput'\nexport { DateTimeInput } from './DateTimeInput'\nexport { TimePeriodSelect } from './TimePeriodSelect'\nexport { TimePicker } from './TimePicker'\nexport * from './DateTimeUtils'\nexport { type Locale } from 'react-day-picker'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAa,kBAAkB,EAC7B,eACA,WACA,cACA,WAAW,OACX,m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AD;GACE,YAAW;GACX,IAAI;GACJ,SAAS,UAAU,UAAU,eAAe;GACvB;GACA;GACtB,EACE;KAEL,qBAAC,gBAAD;EACE,OAAM;EACN,WAAW,GAAG,6BAA6B,CAAC,kBAAkB,aAAa,kBAAkB,wBAAwB,QAAQ,aAAa,kBAAkB,wBAAwB,QAAQ,YAAY;EAExM,kBAAkB,MAAM,EAAE,gBAAgB;YAJ5C,CAME,oBAAC,UAAD;GAAU,GAAI;GAAiC;GAA0B;GAAQ,MAAK;GAAS,UAAU;GAAkB,UAAU;GAAO,GAC3I,kBACC,oBAAC,OAAD;GAAK,WAAU;aACb,oBAAC,YAAD;IAAkB;IAAM,YAAY;IAAqB,QAAQ;IAAoB,UAAU;IAAkB,gBAAgB;IAAoB,cAAc;IAAmB;GACnL,EAEO;IACT;;AAIb,eAAe,cAAc"}
1
+ {"version":3,"file":"DateTimePicker.js","names":[],"sources":["../src/components/DateTimePicker/DateTimePicker.tsx"],"sourcesContent":["import { CalendarIcon } from '@components/Icons'\nimport { Popover, PopoverContent, PopoverTrigger } from '@components/Popover/Popover'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { ErrorMessage, getErrorMessageId, getWarningMessageId, useFormFieldId, WarningMessage } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useCallback, useMemo, type ComponentProps } from 'react'\nimport { type Locale } from 'react-day-picker'\nimport { Calendar, type CalendarProps } from './Calendar'\nimport { DateTimeDisplayInput } from './DateTimeDisplayInput'\nimport { detectHourFormat, getResolvedLocale, type HourFormat, type Period, type TimePickerTranslations } from './DateTimeUtils'\nimport { TimePicker } from './TimePicker'\n\nexport interface DateTimePickerProps extends Omit<ComponentProps<'div'>, 'onChange' | 'defaultValue'> {\n calendarProps?: Omit<CalendarProps, 'mode' | 'selected' | 'onSelect' | 'disablePastDates' | 'locale'>\n defaultValue?: Date\n disabled?: boolean\n disablePastDates?: boolean\n errorMessage?: string | string[] | Record<string, unknown> | null\n hideTimePicker?: boolean\n hourFormat?: HourFormat\n inputClassName?: string\n label?: string\n locale?: Partial<Locale>\n maxDate?: Date\n minDate?: Date\n messageReserveLines?: number\n messageReserveSpace?: boolean\n onChange?: (date: Date | undefined) => void\n state?: 'default' | 'disabled' | 'error' | 'warning'\n timeLocale?: string\n /**\n * The date treated as \"today\" in the calendar. Receives the `rdp-today` styling and is used as\n * the reference for `disablePastDates`. When no value is selected, the calendar opens to this\n * date's month instead of the current month. Useful when assigning dates around historical data.\n */\n today?: Date\n /** Override translation strings for time picker ARIA labels */\n timeTranslations?: Partial<TimePickerTranslations>\n value?: Date\n warningMessage?: string | string[] | Record<string, unknown> | null\n}\n\nexport const DateTimePicker = ({\n calendarProps,\n className,\n defaultValue,\n disabled = false,\n disablePastDates = true,\n errorMessage,\n hideTimePicker = false,\n hourFormat,\n id,\n inputClassName,\n label,\n locale,\n maxDate,\n messageReserveLines = 1,\n messageReserveSpace = false,\n minDate,\n onChange,\n state = 'default',\n timeLocale,\n timeTranslations,\n today,\n value,\n warningMessage,\n ...props\n}: DateTimePickerProps) => {\n const fieldId = useFormFieldId(id)\n const errorMessageId = getErrorMessageId(fieldId)\n const warningMessageId = getWarningMessageId(fieldId)\n const describedBy = state === 'error' && errorMessage ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const [date, setDate] = useUncontrolledState<Date | undefined>({\n defaultValue,\n onChange,\n value,\n })\n\n // Resolve time locale with fallback chain\n const resolvedTimeLocale = useMemo(() => getResolvedLocale(timeLocale), [timeLocale])\n\n // Auto-detect hour format from locale if not explicitly provided\n const effectiveHourFormat = useMemo(() => hourFormat ?? detectHourFormat(resolvedTimeLocale), [hourFormat, resolvedTimeLocale])\n\n const handleDateSelect = (selectedDate: Date | undefined) => {\n if (!selectedDate) {\n setDate(undefined)\n return\n }\n\n // Preserve the time from the existing date\n if (date) {\n selectedDate.setHours(date.getHours(), date.getMinutes(), 0, 0)\n }\n\n setDate(selectedDate)\n }\n\n const handleTimeChange = useCallback(\n (newDate: Date | undefined) => {\n setDate(newDate)\n },\n [setDate],\n )\n\n const handlePeriodChange = (period: Period) => {\n // Period change is already handled in TimePicker\n // This callback is for external consumers who want to react to period changes\n void period\n }\n\n const handleInputDateChange = (newDate: Date | undefined) => {\n setDate(newDate)\n }\n\n return (\n <Popover>\n <div className={cn('w-full', className)} data-slot='datetime-picker' data-testid='spectral-datetime-picker' {...props}>\n <DateTimeDisplayInput\n aria-describedby={describedBy}\n aria-invalid={state === 'error'}\n className={cn('gap-4 pr-12 flex w-full justify-start', !date && 'text-text-secondary', inputClassName)}\n data-testid='spectral-datetime-picker-input'\n disabled={disabled}\n endIcon={\n <PopoverTrigger asChild disabled={disabled}>\n <CalendarIcon\n aria-label='Open date picker'\n className={cn('right-4 text-input-icon hover:text-input-icon--hover absolute top-1/2 -translate-y-1/2 cursor-pointer focus:outline-none', disabled ? 'pointer-events-none cursor-not-allowed opacity-50' : 'hover:text-input-icon--hover cursor-pointer')}\n data-testid='spectral-datetime-picker-trigger'\n disabled={disabled}\n />\n </PopoverTrigger>\n }\n hourFormat={effectiveHourFormat}\n id={fieldId}\n label={label}\n onChange={handleInputDateChange}\n hideTime={hideTimePicker}\n state={state}\n value={date}\n />\n <ErrorMessage\n dataTestId='spectral-datetime-picker-error-message'\n id={errorMessageId}\n message={state === 'error' ? errorMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace}\n />\n <WarningMessage\n dataTestId='spectral-datetime-picker-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? warningMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace}\n />\n </div>\n\n <PopoverContent\n align='start'\n className={cn('rounded-lg py-4 px-6 flex', hideTimePicker ? 'w-[330px]' : effectiveHourFormat === '24' ? 'w-[486px]' : 'w-[560px]')}\n data-testid='spectral-datetime-picker-popover'\n onOpenAutoFocus={(e) => e.preventDefault()}\n >\n <Calendar {...calendarProps} defaultMonth={calendarProps?.defaultMonth ?? date ?? today ?? minDate} disablePastDates={disablePastDates} locale={locale} maxDate={maxDate} minDate={minDate} mode='single' onSelect={handleDateSelect} selected={date} today={today} />\n {!hideTimePicker && (\n <div className='pl-6 border-l border-border-secondary'>\n <TimePicker date={date} hourFormat={effectiveHourFormat} locale={resolvedTimeLocale} onChange={handleTimeChange} onPeriodChange={handlePeriodChange} translations={timeTranslations} />\n </div>\n )}\n </PopoverContent>\n </Popover>\n )\n}\n\nDateTimePicker.displayName = 'DateTimePicker'\n\n// Re-export sub-components for granular usage\nexport { Calendar } from './Calendar'\nexport { DateTimeDisplayInput } from './DateTimeDisplayInput'\nexport { DateTimeInput } from './DateTimeInput'\nexport { TimePeriodSelect } from './TimePeriodSelect'\nexport { TimePicker } from './TimePicker'\nexport * from './DateTimeUtils'\nexport { type Locale } from 'react-day-picker'\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0CA,MAAa,kBAAkB,EAC7B,eACA,WACA,cACA,WAAW,OACX,mBAAmB,MACnB,cACA,iBAAiB,OACjB,YACA,IACA,gBACA,OACA,QACA,SACA,sBAAsB,GACtB,sBAAsB,OACtB,SACA,UACA,QAAQ,WACR,YACA,kBACA,OACA,OACA,gBACA,GAAG,YACsB;CACzB,MAAM,UAAU,eAAe,GAAE;CACjC,MAAM,iBAAiB,kBAAkB,QAAO;CAChD,MAAM,mBAAmB,oBAAoB,QAAO;CACpD,MAAM,cAAc,UAAU,WAAW,eAAe,iBAAiB,UAAU,aAAa,iBAAiB,mBAAmB;CACpI,MAAM,CAAC,MAAM,WAAW,qBAAuC;EAC7D;EACA;EACA;EACD,CAAA;CAGD,MAAM,qBAAqB,cAAc,kBAAkB,WAAW,EAAE,CAAC,WAAW,CAAA;CAGpF,MAAM,sBAAsB,cAAc,cAAc,iBAAiB,mBAAmB,EAAE,CAAC,YAAY,mBAAmB,CAAA;CAE9H,MAAM,oBAAoB,iBAAmC;AAC3D,MAAI,CAAC,cAAc;AACjB,WAAQ,OAAS;AACjB;;AAIF,MAAI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,QAAQ;IAAoB,UAAU;IAAkB,gBAAgB;IAAoB,cAAc;IAAmB;GACnL,EAEO;IACT;;AAIb,eAAe,cAAc"}
package/dist/Input.d.ts CHANGED
@@ -8,6 +8,7 @@ type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'onChange'>
8
8
  className?: string;
9
9
  clearOnFocus?: boolean;
10
10
  endIcon?: ReactElement;
11
+ hideStateIcon?: boolean;
11
12
  labelClassName?: string;
12
13
  onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
13
14
  onChange?: (value: string) => void;
@@ -15,7 +16,6 @@ type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'onChange'>
15
16
  placeholder?: string;
16
17
  prefix?: string;
17
18
  showClearButton?: boolean;
18
- showStateIcon?: boolean;
19
19
  startIcon?: ReactElement;
20
20
  suppressHydrationWarning?: boolean;
21
21
  type?: InputType;
@@ -1 +1 @@
1
- {"version":3,"file":"Input.d.ts","names":[],"sources":["../src/components/Input/Input.tsx"],"mappings":";;;;;KAQY,SAAA;AAAA,KAEA,UAAA,GAAa,IAAA,CAAK,mBAAA,CAAoB,gBAAA,wBAChD,kBAAA;EACE,SAAA;EACA,YAAA;EACA,OAAA,GAAU,YAAA;EACV,cAAA;EACA,MAAA,IAAU,CAAA,EAAG,UAAA,CAAW,gBAAA;EACxB,QAAA,IAAY,KAAA;EACZ,OAAA,IAAW,CAAA,EAAG,UAAA,CAAW,gBAAA;EACzB,WAAA;EACA,MAAA;EACA,eAAA;EACA,aAAA;EACA,SAAA,GAAY,YAAA;EACZ,wBAAA;EACA,IAAA,GAAO,SAAA;EACP,KAAA;EACA,cAAA,GAAiB,kBAAA;AAAA;AAAA,uBA+BnB,QAAA,EAAU,UAAA;EACR,GAAA,GAAM,GAAA,CAAI,gBAAA;AAAA,IAEX,YAAA;AAAA"}
1
+ {"version":3,"file":"Input.d.ts","names":[],"sources":["../src/components/Input/Input.tsx"],"mappings":";;;;;KAoBY,SAAA;AAAA,KAEA,UAAA,GAAa,IAAA,CAAK,mBAAA,CAAoB,gBAAA,wBAChD,kBAAA;EACE,SAAA;EACA,YAAA;EACA,OAAA,GAAU,YAAA;EACV,aAAA;EACA,cAAA;EACA,MAAA,IAAU,CAAA,EAAG,UAAA,CAAW,gBAAA;EACxB,QAAA,IAAY,KAAA;EACZ,OAAA,IAAW,CAAA,EAAG,UAAA,CAAW,gBAAA;EACzB,WAAA;EACA,MAAA;EACA,eAAA;EACA,SAAA,GAAY,YAAA;EACZ,wBAAA;EACA,IAAA,GAAO,SAAA;EACP,KAAA;EACA,cAAA,GAAiB,kBAAA;AAAA;AAAA,uBAoCnB,QAAA,EAAU,UAAA;EACR,GAAA,GAAM,GAAA,CAAI,gBAAA;AAAA,IAEX,YAAA;AAAA"}
package/dist/Input.js CHANGED
@@ -8,7 +8,7 @@ import { LoaderIcon } from "./Icons/LoaderIcon.js";
8
8
  import { WarningIcon } from "./Icons/WarningIcon.js";
9
9
  import { cn } from "./utils/twUtils.js";
10
10
  import { ErrorMessage, WarningMessage } from "./FormFieldMessage.js";
11
- import { getAriaProps, getFormFieldCSSProperties, getInputClasses, useFormFieldId, useFormFieldState } from "./utils/formFieldUtils.js";
11
+ import { getAriaProps, getErrorMessageId, getFormFieldCSSProperties, getInputClasses, getPasswordManagerIgnoreProps, getWarningMessageId, useFormFieldId, useFormFieldState } from "./utils/formFieldUtils.js";
12
12
  import { useUncontrolledState } from "./hooks/useUncontrolledState.js";
13
13
  import { Label } from "./Label.js";
14
14
  import { useClearOnFocus, usePasswordVisibility, usePrefixWidth } from "./Input/InputUtils.js";
@@ -25,6 +25,10 @@ const mergeRefs = (...refs) => {
25
25
  });
26
26
  };
27
27
  };
28
+ const iconBaseClasses = "absolute top-1/2 -translate-y-1/2";
29
+ const endIconClasses = cn(iconBaseClasses, "right-3 text-input-icon");
30
+ const startIconClasses = cn(iconBaseClasses, "left-3 text-input-icon");
31
+ const iconButtonClasses = cn(endIconClasses, "aspect-square max-h-6 rounded-sm hover:text-input-icon--hover cursor-pointer focus:outline-none focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1");
28
32
  const getAutoCompleteValue = (type) => {
29
33
  return {
30
34
  date: "off",
@@ -38,10 +42,10 @@ const getAutoCompleteValue = (type) => {
38
42
  }[type] || "off";
39
43
  };
40
44
  const Input = (allProps) => {
41
- const { className, clearOnFocus = false, defaultValue, disabled, endIcon, errorMessage, id, label, labelClassName, messageReserveLines = 1, messageReserveSpace = false, name, onBlur, onChange, onFocus, placeholder, prefix, ref, required, showClearButton = false, showStateIcon = true, startIcon, state = "default", suppressHydrationWarning = true, type = "text", value: valueProp, warningMessage, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, ...props } = allProps;
45
+ const { className, clearOnFocus = false, defaultValue, disabled, endIcon, errorMessage, hideStateIcon = false, id, label, labelClassName, messageReserveLines = 1, messageReserveSpace = false, name, onBlur, onChange, onFocus, placeholder, prefix, ref, required, showClearButton = false, startIcon, state = "default", suppressHydrationWarning = true, type = "text", value: valueProp, warningMessage, autoComplete, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, ...props } = allProps;
42
46
  const inputId = useFormFieldId(id, name);
43
- const errorMessageId = `${inputId}-error`;
44
- const warningMessageId = `${inputId}-warning`;
47
+ const errorMessageId = getErrorMessageId(inputId);
48
+ const warningMessageId = getWarningMessageId(inputId);
45
49
  const { isDisabled, isLoading, isInvalid } = useFormFieldState(disabled, state);
46
50
  const ariaProps = getAriaProps(state, ariaDescribedBy, required, state === "error" ? errorMessageId : state === "warning" && warningMessage ? warningMessageId : void 0);
47
51
  const [value, setValue] = useUncontrolledState({
@@ -73,60 +77,62 @@ const Input = (allProps) => {
73
77
  }, [setValue]);
74
78
  const showClearButtonNow = showClearButton && value.length > 0;
75
79
  const getEndIcon = () => {
76
- const iconClasses = "absolute right-4 top-1/2 -translate-y-1/2 text-input-icon hover:text-input-icon--hover focus:outline-none cursor-pointer";
77
80
  const iconComponents = {
78
81
  password: () => /* @__PURE__ */ jsx("button", {
79
82
  "aria-controls": inputId,
80
83
  "aria-label": isVisible ? `Hide ${label ?? "password"}` : `Show ${label ?? "password"}`,
81
84
  "aria-pressed": isVisible,
82
- className: iconClasses,
85
+ className: iconButtonClasses,
83
86
  onClick: toggleVisibility,
84
87
  type: "button",
85
88
  children: isVisible ? /* @__PURE__ */ jsx(EyeClosedIcon, { size: 22 }) : /* @__PURE__ */ jsx(EyeOpenIcon, { size: 22 })
86
89
  }),
87
90
  clear: () => /* @__PURE__ */ jsx("button", {
88
91
  "aria-label": String(`Clear ${label ?? "input"}`),
89
- className: iconClasses,
92
+ className: iconButtonClasses,
90
93
  onClick: handleClear,
91
94
  type: "button",
92
- children: /* @__PURE__ */ jsx(CloseCircleIcon, { size: 24 })
95
+ children: /* @__PURE__ */ jsx(CloseCircleIcon, { size: 22 })
93
96
  }),
94
97
  loading: () => /* @__PURE__ */ jsx("div", {
95
- className: "right-4 text-input-icon absolute top-1/2 -translate-y-1/2",
98
+ className: endIconClasses,
96
99
  children: /* @__PURE__ */ jsx(LoaderIcon, { size: 24 })
97
100
  }),
98
101
  error: () => /* @__PURE__ */ jsx("div", {
99
- className: "right-4 absolute top-1/2 -translate-y-1/2 text-danger-400",
102
+ className: cn(iconBaseClasses, "right-3 text-danger-400"),
100
103
  children: /* @__PURE__ */ jsx(ErrorIcon, { size: 24 })
101
104
  }),
102
105
  success: () => /* @__PURE__ */ jsx("div", {
103
- className: "right-4 absolute top-1/2 -translate-y-1/2 text-success-400",
106
+ className: cn(iconBaseClasses, "right-3 text-success-400"),
104
107
  children: /* @__PURE__ */ jsx(CheckCircleIcon, { size: 24 })
105
108
  }),
106
109
  warning: () => /* @__PURE__ */ jsx("div", {
107
- className: "right-4 absolute top-1/2 -translate-y-1/2 text-warning-400",
110
+ className: cn(iconBaseClasses, "right-3 text-warning-400"),
108
111
  children: /* @__PURE__ */ jsx(WarningIcon, { size: 24 })
109
112
  })
110
113
  };
111
114
  if (endIcon) return /* @__PURE__ */ jsx("div", {
112
- className: "right-4 text-input-icon absolute top-1/2 -translate-y-1/2",
115
+ className: endIconClasses,
113
116
  children: endIcon
114
117
  });
115
118
  if (type === "password") return iconComponents.password();
116
119
  if (showClearButtonNow) return iconComponents.clear();
117
120
  if (isLoading) return iconComponents.loading();
118
- if (!showStateIcon && (state === "success" || state === "warning" || state === "error")) return null;
121
+ if (hideStateIcon && (state === "success" || state === "warning" || state === "error")) return null;
119
122
  if (state === "success") return iconComponents.success();
120
123
  if (state === "warning") return iconComponents.warning();
121
124
  if (state === "error") return iconComponents.error();
122
125
  return null;
123
126
  };
124
127
  const getStartIcon = () => {
125
- if (startIcon) return startIcon;
128
+ if (startIcon) return /* @__PURE__ */ jsx("div", {
129
+ className: startIconClasses,
130
+ children: startIcon
131
+ });
126
132
  return null;
127
133
  };
128
134
  const usesTabularNumbers = type === "number" || type === "date" || type === "datetime-local";
129
- const inputClasses = cn(getInputClasses(state, className), "[text-indent:var(--prefix-width)]", showClearButtonNow && "pr-10", usesTabularNumbers && "tabular-nums");
135
+ const inputClasses = cn(getInputClasses(state, className), "[text-indent:var(--prefix-width)]", startIcon && "pl-10", showClearButtonNow && "pr-10", usesTabularNumbers && "tabular-nums");
130
136
  const prefixClasses = cn("inset-y-0 left-4 text-base pointer-events-none absolute flex items-center text-input-text-prefix opacity-100 peer-disabled:opacity-50");
131
137
  return /* @__PURE__ */ jsxs("div", {
132
138
  className: "flex w-full flex-col gap-1.5",
@@ -148,7 +154,7 @@ const Input = (allProps) => {
148
154
  }),
149
155
  /* @__PURE__ */ jsx("input", {
150
156
  "aria-label": ariaLabel ?? label,
151
- autoComplete: getAutoCompleteValue(type),
157
+ autoComplete: autoComplete ?? getAutoCompleteValue(type),
152
158
  className: inputClasses,
153
159
  "data-state": state,
154
160
  disabled: isDisabled,
@@ -164,6 +170,7 @@ const Input = (allProps) => {
164
170
  suppressHydrationWarning,
165
171
  type: type === "password" ? inputType : type,
166
172
  value,
173
+ ...getPasswordManagerIgnoreProps(type),
167
174
  ...ariaProps,
168
175
  ...props
169
176
  }),
package/dist/Input.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","names":[],"sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import { CheckCircleIcon, CloseCircleIcon, ErrorIcon, EyeClosedIcon, EyeOpenIcon, LoaderIcon, WarningIcon } from '@components/Icons'\nimport { Label } from '@components/Label/Label'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { ErrorMessage, WarningMessage, getAriaProps, getFormFieldCSSProperties, getInputClasses, useFormFieldId, useFormFieldState, type BaseFormFieldProps } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useCallback, useRef, type ChangeEvent, type CSSProperties, type FocusEvent, type InputHTMLAttributes, type ReactElement, type Ref } from 'react'\nimport { useClearOnFocus, usePasswordVisibility, usePrefixWidth } from './InputUtils'\n\nexport type InputType = 'text' | 'email' | 'url' | 'tel' | 'password' | 'number' | 'date' | 'datetime-local'\n\nexport type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'onChange'> &\n BaseFormFieldProps & {\n className?: string\n clearOnFocus?: boolean\n endIcon?: ReactElement\n labelClassName?: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n onChange?: (value: string) => void\n onFocus?: (e: FocusEvent<HTMLInputElement>) => void\n placeholder?: string\n prefix?: string\n showClearButton?: boolean\n showStateIcon?: boolean\n startIcon?: ReactElement\n suppressHydrationWarning?: boolean\n type?: InputType\n value?: string\n warningMessage?: BaseFormFieldProps['errorMessage']\n }\n\nconst mergeRefs = <T,>(...refs: (Ref<T> | undefined)[]): Ref<T> => {\n return (value: T | null) => {\n refs.forEach((ref) => {\n if (!ref) return\n if (typeof ref === 'function') {\n ref(value)\n } else {\n ;(ref as { current: T | null }).current = value\n }\n })\n }\n}\n\nconst getAutoCompleteValue = (type: InputType): string => {\n const autoCompleteMap: Record<InputType, string> = {\n date: 'off',\n email: 'email',\n number: 'off',\n password: 'current-password',\n tel: 'tel',\n text: 'off',\n url: 'url',\n 'datetime-local': 'off',\n }\n return autoCompleteMap[type] || 'off'\n}\n\nexport const Input = (\n allProps: InputProps & {\n ref?: Ref<HTMLInputElement>\n },\n): ReactElement => {\n const {\n className,\n clearOnFocus = false,\n defaultValue,\n disabled,\n endIcon,\n errorMessage,\n id,\n label,\n labelClassName,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n prefix,\n ref,\n required,\n showClearButton = false,\n showStateIcon = true,\n startIcon,\n state = 'default',\n suppressHydrationWarning = true,\n type = 'text',\n value: valueProp,\n warningMessage,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n ...props\n } = allProps\n const inputId = useFormFieldId(id, name)\n const errorMessageId = `${inputId}-error`\n const warningMessageId = `${inputId}-warning`\n const { isDisabled, isLoading, isInvalid } = useFormFieldState(disabled, state)\n const messageId = state === 'error' ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const ariaProps = getAriaProps(state, ariaDescribedBy, required, messageId)\n const normalizedDefaultValue = typeof defaultValue === 'string' ? defaultValue : defaultValue !== undefined && defaultValue !== null ? String(defaultValue) : ''\n const [value, setValue] = useUncontrolledState<string>({\n value: valueProp,\n defaultValue: normalizedDefaultValue,\n onChange,\n })\n\n const internalRef = useRef<HTMLInputElement>(null)\n const inputRef = mergeRefs(ref, internalRef)\n\n const { isVisible, toggleVisibility, inputType } = usePasswordVisibility()\n const { prefixWidth, prefixRef } = usePrefixWidth(prefix)\n const { handleFocus: clearOnFocusHandler } = useClearOnFocus(clearOnFocus, (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value))\n\n const handleBlur = useCallback(\n (e: FocusEvent<HTMLInputElement>): void => {\n onBlur?.(e)\n },\n [onBlur],\n )\n\n const handleFocus = useCallback(\n (e: FocusEvent<HTMLInputElement>): void => {\n clearOnFocusHandler(e, onFocus)\n },\n [clearOnFocusHandler, onFocus],\n )\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>): void => {\n const newValue = e.target.value\n setValue(newValue)\n },\n [setValue],\n )\n\n const handleClear = useCallback((): void => {\n const element = internalRef.current\n if (element) {\n setValue('')\n element.focus()\n }\n }, [setValue])\n\n const showClearButtonNow = showClearButton && value.length > 0\n\n const getEndIcon = (): ReactElement | null => {\n const iconClasses = 'absolute right-4 top-1/2 -translate-y-1/2 text-input-icon hover:text-input-icon--hover focus:outline-none cursor-pointer'\n\n const iconComponents = {\n password: () => (\n <button aria-controls={inputId} aria-label={isVisible ? `Hide ${label ?? 'password'}` : `Show ${label ?? 'password'}`} aria-pressed={isVisible} className={iconClasses} data-testid='spectral-input-password-toggle' onClick={toggleVisibility} type='button'>\n {isVisible ? <EyeClosedIcon size={22} /> : <EyeOpenIcon size={22} />}\n </button>\n ),\n clear: () => (\n <button aria-label={String(`Clear ${label ?? 'input'}`)} className={iconClasses} data-testid='spectral-input-clear-button' onClick={handleClear} type='button'>\n <CloseCircleIcon size={24} />\n </button>\n ),\n loading: () => (\n <div className='right-4 text-input-icon absolute top-1/2 -translate-y-1/2' data-testid='spectral-input-loading-icon'>\n <LoaderIcon size={24} />\n </div>\n ),\n error: () => (\n <div className='right-4 absolute top-1/2 -translate-y-1/2 text-danger-400' data-testid='spectral-input-error-icon'>\n <ErrorIcon size={24} />\n </div>\n ),\n success: () => (\n <div className='right-4 absolute top-1/2 -translate-y-1/2 text-success-400' data-testid='spectral-input-success-icon'>\n <CheckCircleIcon size={24} />\n </div>\n ),\n warning: () => (\n <div className='right-4 absolute top-1/2 -translate-y-1/2 text-warning-400' data-testid='spectral-input-warning-icon'>\n <WarningIcon size={24} />\n </div>\n ),\n }\n\n if (endIcon) return <div className='right-4 text-input-icon absolute top-1/2 -translate-y-1/2'>{endIcon}</div>\n if (type === 'password') return iconComponents.password()\n if (showClearButtonNow) return iconComponents.clear()\n if (isLoading) return iconComponents.loading()\n if (!showStateIcon && (state === 'success' || state === 'warning' || state === 'error')) return null\n if (state === 'success') return iconComponents.success()\n if (state === 'warning') return iconComponents.warning()\n if (state === 'error') return iconComponents.error()\n\n return null\n }\n\n const getStartIcon = (): ReactElement | null => {\n if (startIcon) return startIcon\n return null\n }\n\n const usesTabularNumbers = type === 'number' || type === 'date' || type === 'datetime-local'\n const inputClasses = cn(getInputClasses(state, className), '[text-indent:var(--prefix-width)]', showClearButtonNow && 'pr-10', usesTabularNumbers && 'tabular-nums')\n\n const prefixClasses = cn('inset-y-0 left-4 text-base pointer-events-none absolute flex items-center text-input-text-prefix opacity-100 peer-disabled:opacity-50')\n\n return (\n <div className='flex w-full flex-col gap-1.5' data-testid='spectral-input-container'>\n {label && (\n <Label className={cn('mb-2 block', labelClassName, isDisabled && 'cursor-not-allowed text-input-text--disabled placeholder:text-input-text-placeholder')} data-testid='spectral-input-label' htmlFor={inputId}>\n {label}\n </Label>\n )}\n <div className='relative' data-testid='spectral-input-wrapper'>\n <div className='relative'>\n {getStartIcon()}\n {prefix && (\n <span ref={prefixRef} className={prefixClasses}>\n {prefix}\n </span>\n )}\n <input\n aria-label={ariaLabel ?? label}\n autoComplete={getAutoCompleteValue(type)}\n className={inputClasses}\n data-state={state}\n data-testid='spectral-input'\n disabled={isDisabled}\n id={inputId}\n name={name}\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n placeholder={placeholder ?? label}\n ref={inputRef}\n required={required}\n style={\n getFormFieldCSSProperties({\n '--prefix-width': prefix ? `${prefixWidth}px` : '0',\n }) as CSSProperties\n }\n suppressHydrationWarning={suppressHydrationWarning}\n type={type === 'password' ? inputType : type}\n value={value}\n {...ariaProps}\n {...props}\n />\n {getEndIcon()}\n </div>\n\n <ErrorMessage\n dataTestId='spectral-input-error-message'\n id={errorMessageId}\n message={isInvalid ? (errorMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-input-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? (warningMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n </div>\n )\n}\nInput.displayName = 'Input'\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA,MAAM,aAAiB,GAAG,SAAyC;AACjE,SAAQ,UAAoB;AAC1B,OAAK,SAAS,QAAQ;AACpB,OAAI,CAAC,IAAK;AACV,OAAI,OAAO,QAAQ,WACjB,KAAI,MAAK;OAER,CAAC,IAA8B,UAAU;IAE7C;;;AAIL,MAAM,wBAAwB,SAA4B;AAWxD,QAAO;EATL,MAAM;EACN,OAAO;EACP,QAAQ;EACR,UAAU;EACV,KAAK;EACL,MAAM;EACN,KAAK;EACL,kBAAkB;EAEE,CAAC,SAAS;;AAGlC,MAAa,SACX,aAGiB;CACjB,MAAM,EACJ,WACA,eAAe,OACf,cACA,UACA,SACA,cACA,IACA,OACA,gBACA,sBAAsB,GACtB,sBAAsB,OACtB,MACA,QACA,UACA,SACA,aACA,QACA,KACA,UACA,kBAAkB,OAClB,gBAAgB,MAChB,WACA,QAAQ,WACR,2BAA2B,MAC3B,OAAO,QACP,OAAO,WACP,gBACA,cAAc,WACd,oBAAoB,iBACpB,GAAG,UACD;CACJ,MAAM,UAAU,eAAe,IAAI,KAAI;CACvC,MAAM,iBAAiB,GAAG,QAAQ;CAClC,MAAM,mBAAmB,GAAG,QAAQ;CACpC,MAAM,EAAE,YAAY,WAAW,cAAc,kBAAkB,UAAU,MAAK;CAE9E,MAAM,YAAY,aAAa,OAAO,iBAAiB,UADrC,UAAU,UAAU,iBAAiB,UAAU,aAAa,iBAAiB,mBAAmB,OACxC;CAE1E,MAAM,CAAC,OAAO,YAAY,qBAA6B;EACrD,OAAO;EACP,cAH6B,OAAO,iBAAiB,WAAW,eAAe,iBAAiB,UAAa,iBAAiB,OAAO,OAAO,aAAa,GAAG;EAI5J;EACD,CAAA;CAED,MAAM,cAAc,OAAyB,KAAI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ACV,SAAS;OACT,aAAa,eAAe;OAC5B,KAAK;OACK;OACV,OACE,0BAA0B,EACxB,kBAAkB,SAAS,GAAG,YAAY,MAAM,KACjD,CAAC;OAEsB;OAC1B,MAAM,SAAS,aAAa,YAAY;OACjC;OACP,GAAI;OACJ,GAAI;OACL;MACA,YAAY;MACV;;IAEL,oBAAC,cAAD;KACE,YAAW;KACX,IAAI;KACJ,SAAS,YAAa,gBAAgB,OAAQ;KACzB;KACrB,qBAAqB,uBAAuB,UAAU;KACvD;IACD,oBAAC,gBAAD;KACE,YAAW;KACX,IAAI;KACJ,SAAS,UAAU,YAAa,kBAAkB,OAAQ;KACrC;KACrB,qBAAqB,uBAAuB,UAAU;KACvD;IACE;KACF;;;AAGT,MAAM,cAAc"}
1
+ {"version":3,"file":"Input.js","names":[],"sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import { CheckCircleIcon, CloseCircleIcon, ErrorIcon, EyeClosedIcon, EyeOpenIcon, LoaderIcon, WarningIcon } from '@components/Icons'\nimport { Label } from '@components/Label/Label'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport {\n ErrorMessage,\n getAriaProps,\n getErrorMessageId,\n getFormFieldCSSProperties,\n getInputClasses,\n getPasswordManagerIgnoreProps,\n getWarningMessageId,\n useFormFieldId,\n useFormFieldState,\n WarningMessage,\n type BaseFormFieldProps,\n} from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useCallback, useRef, type ChangeEvent, type CSSProperties, type FocusEvent, type InputHTMLAttributes, type ReactElement, type Ref } from 'react'\nimport { useClearOnFocus, usePasswordVisibility, usePrefixWidth } from './InputUtils'\n\nexport type InputType = 'text' | 'email' | 'url' | 'tel' | 'password' | 'number' | 'date' | 'datetime-local'\n\nexport type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'onChange'> &\n BaseFormFieldProps & {\n className?: string\n clearOnFocus?: boolean\n endIcon?: ReactElement\n hideStateIcon?: boolean\n labelClassName?: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n onChange?: (value: string) => void\n onFocus?: (e: FocusEvent<HTMLInputElement>) => void\n placeholder?: string\n prefix?: string\n showClearButton?: boolean\n startIcon?: ReactElement\n suppressHydrationWarning?: boolean\n type?: InputType\n value?: string\n warningMessage?: BaseFormFieldProps['errorMessage']\n }\n\nconst mergeRefs = <T,>(...refs: (Ref<T> | undefined)[]): Ref<T> => {\n return (value: T | null) => {\n refs.forEach((ref) => {\n if (!ref) return\n if (typeof ref === 'function') {\n ref(value)\n } else {\n ;(ref as { current: T | null }).current = value\n }\n })\n }\n}\n\nconst iconBaseClasses = 'absolute top-1/2 -translate-y-1/2'\nconst endIconClasses = cn(iconBaseClasses, 'right-3 text-input-icon')\nconst startIconClasses = cn(iconBaseClasses, 'left-3 text-input-icon')\nconst iconButtonClasses = cn(endIconClasses, 'aspect-square max-h-6 rounded-sm hover:text-input-icon--hover cursor-pointer focus:outline-none focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1')\n\nconst getAutoCompleteValue = (type: InputType): string => {\n const autoCompleteMap: Record<InputType, string> = {\n date: 'off',\n email: 'email',\n number: 'off',\n password: 'current-password',\n tel: 'tel',\n text: 'off',\n url: 'url',\n 'datetime-local': 'off',\n }\n return autoCompleteMap[type] || 'off'\n}\n\nexport const Input = (\n allProps: InputProps & {\n ref?: Ref<HTMLInputElement>\n },\n): ReactElement => {\n const {\n className,\n clearOnFocus = false,\n defaultValue,\n disabled,\n endIcon,\n errorMessage,\n hideStateIcon = false,\n id,\n label,\n labelClassName,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n prefix,\n ref,\n required,\n showClearButton = false,\n startIcon,\n state = 'default',\n suppressHydrationWarning = true,\n type = 'text',\n value: valueProp,\n warningMessage,\n autoComplete,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n ...props\n } = allProps\n const inputId = useFormFieldId(id, name)\n const errorMessageId = getErrorMessageId(inputId)\n const warningMessageId = getWarningMessageId(inputId)\n const { isDisabled, isLoading, isInvalid } = useFormFieldState(disabled, state)\n const messageId = state === 'error' ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const ariaProps = getAriaProps(state, ariaDescribedBy, required, messageId)\n const normalizedDefaultValue = typeof defaultValue === 'string' ? defaultValue : defaultValue !== undefined && defaultValue !== null ? String(defaultValue) : ''\n const [value, setValue] = useUncontrolledState<string>({\n value: valueProp,\n defaultValue: normalizedDefaultValue,\n onChange,\n })\n\n const internalRef = useRef<HTMLInputElement>(null)\n const inputRef = mergeRefs(ref, internalRef)\n\n const { isVisible, toggleVisibility, inputType } = usePasswordVisibility()\n const { prefixWidth, prefixRef } = usePrefixWidth(prefix)\n const { handleFocus: clearOnFocusHandler } = useClearOnFocus(clearOnFocus, (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value))\n\n const handleBlur = useCallback(\n (e: FocusEvent<HTMLInputElement>): void => {\n onBlur?.(e)\n },\n [onBlur],\n )\n\n const handleFocus = useCallback(\n (e: FocusEvent<HTMLInputElement>): void => {\n clearOnFocusHandler(e, onFocus)\n },\n [clearOnFocusHandler, onFocus],\n )\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>): void => {\n const newValue = e.target.value\n setValue(newValue)\n },\n [setValue],\n )\n\n const handleClear = useCallback((): void => {\n const element = internalRef.current\n if (element) {\n setValue('')\n element.focus()\n }\n }, [setValue])\n\n const showClearButtonNow = showClearButton && value.length > 0\n\n const getEndIcon = (): ReactElement | null => {\n const iconComponents = {\n password: () => (\n <button aria-controls={inputId} aria-label={isVisible ? `Hide ${label ?? 'password'}` : `Show ${label ?? 'password'}`} aria-pressed={isVisible} className={iconButtonClasses} data-testid='spectral-input-password-toggle' onClick={toggleVisibility} type='button'>\n {isVisible ? <EyeClosedIcon size={22} /> : <EyeOpenIcon size={22} />}\n </button>\n ),\n clear: () => (\n <button aria-label={String(`Clear ${label ?? 'input'}`)} className={iconButtonClasses} data-testid='spectral-input-clear-button' onClick={handleClear} type='button'>\n <CloseCircleIcon size={22} />\n </button>\n ),\n loading: () => (\n <div className={endIconClasses} data-testid='spectral-input-loading-icon'>\n <LoaderIcon size={24} />\n </div>\n ),\n error: () => (\n <div className={cn(iconBaseClasses, 'right-3 text-danger-400')} data-testid='spectral-input-error-icon'>\n <ErrorIcon size={24} />\n </div>\n ),\n success: () => (\n <div className={cn(iconBaseClasses, 'right-3 text-success-400')} data-testid='spectral-input-success-icon'>\n <CheckCircleIcon size={24} />\n </div>\n ),\n warning: () => (\n <div className={cn(iconBaseClasses, 'right-3 text-warning-400')} data-testid='spectral-input-warning-icon'>\n <WarningIcon size={24} />\n </div>\n ),\n }\n\n if (endIcon) return <div className={endIconClasses}>{endIcon}</div>\n if (type === 'password') return iconComponents.password()\n if (showClearButtonNow) return iconComponents.clear()\n if (isLoading) return iconComponents.loading()\n if (hideStateIcon && (state === 'success' || state === 'warning' || state === 'error')) return null\n if (state === 'success') return iconComponents.success()\n if (state === 'warning') return iconComponents.warning()\n if (state === 'error') return iconComponents.error()\n\n return null\n }\n\n const getStartIcon = (): ReactElement | null => {\n if (startIcon) return <div className={startIconClasses}>{startIcon}</div>\n return null\n }\n\n const usesTabularNumbers = type === 'number' || type === 'date' || type === 'datetime-local'\n const inputClasses = cn(getInputClasses(state, className), '[text-indent:var(--prefix-width)]', startIcon && 'pl-10', showClearButtonNow && 'pr-10', usesTabularNumbers && 'tabular-nums')\n\n const prefixClasses = cn('inset-y-0 left-4 text-base pointer-events-none absolute flex items-center text-input-text-prefix opacity-100 peer-disabled:opacity-50')\n\n return (\n <div className='flex w-full flex-col gap-1.5' data-testid='spectral-input-container'>\n {label && (\n <Label className={cn('mb-2 block', labelClassName, isDisabled && 'cursor-not-allowed text-input-text--disabled placeholder:text-input-text-placeholder')} data-testid='spectral-input-label' htmlFor={inputId}>\n {label}\n </Label>\n )}\n <div className='relative' data-testid='spectral-input-wrapper'>\n <div className='relative'>\n {getStartIcon()}\n {prefix && (\n <span ref={prefixRef} className={prefixClasses}>\n {prefix}\n </span>\n )}\n <input\n aria-label={ariaLabel ?? label}\n autoComplete={autoComplete ?? getAutoCompleteValue(type)}\n className={inputClasses}\n data-state={state}\n data-testid='spectral-input'\n disabled={isDisabled}\n id={inputId}\n name={name}\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n placeholder={placeholder ?? label}\n ref={inputRef}\n required={required}\n style={\n getFormFieldCSSProperties({\n '--prefix-width': prefix ? `${prefixWidth}px` : '0',\n }) as CSSProperties\n }\n suppressHydrationWarning={suppressHydrationWarning}\n type={type === 'password' ? inputType : type}\n value={value}\n {...getPasswordManagerIgnoreProps(type)}\n {...ariaProps}\n {...props}\n />\n {getEndIcon()}\n </div>\n\n <ErrorMessage\n dataTestId='spectral-input-error-message'\n id={errorMessageId}\n message={isInvalid ? (errorMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-input-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? (warningMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n </div>\n )\n}\nInput.displayName = 'Input'\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0CA,MAAM,aAAiB,GAAG,SAAyC;AACjE,SAAQ,UAAoB;AAC1B,OAAK,SAAS,QAAQ;AACpB,OAAI,CAAC,IAAK;AACV,OAAI,OAAO,QAAQ,WACjB,KAAI,MAAK;OAER,CAAC,IAA8B,UAAU;IAE7C;;;AAIL,MAAM,kBAAkB;AACxB,MAAM,iBAAiB,GAAG,iBAAiB,0BAAyB;AACpE,MAAM,mBAAmB,GAAG,iBAAiB,yBAAwB;AACrE,MAAM,oBAAoB,GAAG,gBAAgB,sLAAqL;AAElO,MAAM,wBAAwB,SAA4B;AAWxD,QAAO;EATL,MAAM;EACN,OAAO;EACP,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