@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,9 +1,9 @@
1
1
  'use client';
2
2
  import { cn } from "./utils/twUtils.js";
3
3
  import { ErrorMessage, WarningMessage } from "./FormFieldMessage.js";
4
- import { useFormFieldId } from "./utils/formFieldUtils.js";
4
+ import { getErrorMessageId, getWarningMessageId, useFormFieldId } from "./utils/formFieldUtils.js";
5
5
  import { Label } from "./Label.js";
6
- import { createContext, memo, useContext, useId, useMemo } from "react";
6
+ import { Children, createContext, memo, useContext, useId, useMemo } from "react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
9
9
  import { AnimatePresence, motion, useReducedMotion } from "motion/react";
@@ -21,12 +21,12 @@ const RadioGroup = (allProps) => {
21
21
  const { className, disabled, errorMessage, itemClassName, messageReserveLines = 1, messageReserveSpace = false, name, onChange, onValueChange, orientation = "vertical", ref, selected: selectedProp, state = "default", variant = "default", warningMessage, "aria-describedby": ariaDescribedBy, ...props } = allProps;
22
22
  const selected = isControlled ? selectedProp ?? "" : selectedProp;
23
23
  const groupId = useFormFieldId(props.id, name);
24
- const errorMessageId = `${groupId}-error`;
25
- const warningMessageId = `${groupId}-warning`;
24
+ const errorMessageId = getErrorMessageId(groupId);
25
+ const warningMessageId = getWarningMessageId(groupId);
26
26
  const messageId = state === "error" && errorMessage ? errorMessageId : state === "warning" && warningMessage ? warningMessageId : void 0;
27
27
  const handleValueChange = (nextValue) => {
28
- onValueChange(nextValue);
29
- onChange?.(nextValue);
28
+ onChange(nextValue);
29
+ onValueChange?.(nextValue);
30
30
  };
31
31
  const contextValue = useMemo(() => ({
32
32
  disabledValues: Array.isArray(disabled) ? disabled : [],
@@ -49,12 +49,12 @@ const RadioGroup = (allProps) => {
49
49
  className: "flex w-full flex-col gap-1.5",
50
50
  children: [
51
51
  /* @__PURE__ */ jsx(RadioGroupPrimitive.Root, {
52
- className: cn("flex w-full text-text-primary", orientation === "vertical" ? "gap-4 flex-col" : "gap-5 flex-row", variant === "unstyled" && "gap-2.5 w-fit", className),
53
- "data-state": state,
54
- id: groupId,
55
52
  "aria-invalid": state === "error" ? true : void 0,
56
53
  "aria-describedby": [messageId, ariaDescribedBy].filter(Boolean).join(" ") || void 0,
54
+ className: cn("group/radio-field flex w-full text-text-primary", orientation === "vertical" ? "gap-4 flex-col" : "gap-5 flex-row", variant === "unstyled" && "gap-2.5 w-fit", className),
55
+ "data-state": state,
57
56
  disabled: contextValue.groupDisabled,
57
+ id: groupId,
58
58
  name,
59
59
  onValueChange: handleValueChange,
60
60
  ref,
@@ -85,9 +85,12 @@ const DEFAULT_TRANSITION = {
85
85
  stiffness: 200,
86
86
  damping: 16
87
87
  };
88
+ const RADIO_BUTTON_CLASSES = cn("size-4.5 border-border-subtle relative aspect-square cursor-pointer rounded-full border-2 bg-radio-bg transition-colors hover:border-radio-border--hover", "focus:outline-none focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-accent data-[state=checked]:border-radio-border--selected data-[state=checked]:bg-radio-bg", "group-data-[state=error]/radio-field:data-[state=unchecked]:border-danger-400 group-data-[state=error]/radio-field:data-[state=unchecked]:hover:border-danger-500 group-data-[state=error]/radio-field:focus-visible:outline-danger-400", "group-data-[state=warning]/radio-field:data-[state=unchecked]:border-warning-400 group-data-[state=warning]/radio-field:data-[state=unchecked]:hover:border-warning-500 group-data-[state=warning]/radio-field:focus-visible:outline-warning-400");
88
89
  const RadioButton = memo(({ className, id, isDisabled, ref, transition = DEFAULT_TRANSITION, value, ...props }) => {
89
- if (useReducedMotion()) return /* @__PURE__ */ jsx(RadioGroupPrimitive.Item, {
90
- className: cn("h-4.5 w-4.5 border-border-subtle ring-black relative aspect-square cursor-pointer rounded-full border-2 bg-radio-bg transition-colors", "hover:border-radio-border--hover focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-accent", "data-[state=checked]:border-radio-border--selected data-[state=checked]:bg-radio-bg", isDisabled && DISABLED_STYLES, className),
90
+ const prefersReducedMotion = useReducedMotion();
91
+ const buttonClassName = cn(RADIO_BUTTON_CLASSES, isDisabled && DISABLED_STYLES, className);
92
+ if (prefersReducedMotion) return /* @__PURE__ */ jsx(RadioGroupPrimitive.Item, {
93
+ className: buttonClassName,
91
94
  disabled: isDisabled,
92
95
  id,
93
96
  ref,
@@ -102,7 +105,7 @@ const RadioButton = memo(({ className, id, isDisabled, ref, transition = DEFAULT
102
105
  asChild: true,
103
106
  ...props,
104
107
  children: /* @__PURE__ */ jsx(motion.button, {
105
- className: cn("h-4.5 w-4.5 border-border-subtle ring-black relative aspect-square cursor-pointer rounded-full border-2 bg-radio-bg transition-colors", "hover:border-radio-border--hover focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-accent", "data-[state=checked]:border-radio-border--selected data-[state=checked]:bg-radio-bg", isDisabled && DISABLED_STYLES, className),
108
+ className: buttonClassName,
106
109
  ref,
107
110
  whileHover: { scale: 1.05 },
108
111
  whileTap: { scale: .95 },
@@ -135,6 +138,7 @@ const RadioGroupItem = ({ children, className, disabled, ref, value, ...props })
135
138
  const stringValue = value.toString();
136
139
  const id = props.id?.toString() ?? `${stringValue}-${generatedId}`;
137
140
  const isDisabled = groupDisabled || disabledValues.includes(stringValue) || Boolean(disabled);
141
+ const isTextContent = Children.toArray(children).every((child) => typeof child === "string" || typeof child === "number");
138
142
  if (variant === "unstyled") return /* @__PURE__ */ jsx(RadioGroupPrimitive.Item, {
139
143
  asChild: true,
140
144
  disabled: isDisabled,
@@ -143,7 +147,7 @@ const RadioGroupItem = ({ children, className, disabled, ref, value, ...props })
143
147
  value: stringValue,
144
148
  ...props,
145
149
  children: /* @__PURE__ */ jsx(Label, {
146
- className: cn("rounded flex h-fit w-fit border-2 border-transparent data-[state=checked]:border-radio-border--selected", isDisabled && DISABLED_STYLES, itemClassName, className),
150
+ className: cn("rounded cursor-pointer flex h-fit w-fit border-2 border-transparent data-[state=checked]:border-radio-border--selected [&_*]:cursor-[inherit]", isTextContent && "p-1.5", isDisabled && DISABLED_STYLES, itemClassName, className),
147
151
  htmlFor: id,
148
152
  children
149
153
  })
@@ -157,7 +161,7 @@ const RadioGroupItem = ({ children, className, disabled, ref, value, ...props })
157
161
  isDisabled,
158
162
  ...props
159
163
  }), children && /* @__PURE__ */ jsx(Label, {
160
- className: cn("text-md font-normal cursor-pointer", orientation === "vertical" ? "ml-2" : "ml-1"),
164
+ className: cn("text-md font-normal cursor-pointer", orientation === "vertical" ? "ml-2" : "ml-1.5"),
161
165
  htmlFor: id,
162
166
  children
163
167
  })]
@@ -1 +1 @@
1
- {"version":3,"file":"RadioGroup.js","names":[],"sources":["../src/components/RadioGroup/RadioGroup.tsx"],"sourcesContent":["import { Label } from '@components/Label/Label'\nimport * as RadioGroupPrimitive from '@radix-ui/react-radio-group'\nimport { ErrorMessage, WarningMessage, useFormFieldId, type BaseFormFieldProps, type FormFieldState } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from 'motion/react'\nimport { createContext, memo, useContext, useId, useMemo, type ComponentProps, type ComponentRef, type ReactElement, type ReactNode, type Ref } from 'react'\n\ntype RadioGroupVariant = 'default' | 'unstyled'\n\nexport interface RadioGroupProps extends Omit<ComponentProps<typeof RadioGroupPrimitive.Root>, 'onChange' | 'disabled'> {\n 'aria-describedby'?: string\n 'aria-label'?: string\n className?: string\n disabled?: boolean | string[]\n errorMessage?: BaseFormFieldProps['errorMessage']\n itemClassName?: string\n messageReserveLines?: number\n messageReserveSpace?: boolean\n name: string\n onChange?: (selected: string) => void\n onValueChange: (selected: string) => void\n orientation?: 'horizontal' | 'vertical'\n required?: boolean\n selected?: string\n state?: FormFieldState\n variant?: RadioGroupVariant\n warningMessage?: BaseFormFieldProps['errorMessage']\n}\n\nexport interface RadioGroupItemProps extends ComponentProps<typeof RadioGroupPrimitive.Item> {\n className?: string\n children?: ReactNode\n description?: string | ReactNode\n id?: string\n value: string\n}\n\ninterface RadioGroupContextType {\n disabledValues: string[]\n groupDisabled: boolean\n itemClassName?: string\n orientation: 'horizontal' | 'vertical'\n selected?: string\n variant: RadioGroupVariant\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextType>({\n disabledValues: [],\n groupDisabled: false,\n orientation: 'vertical',\n variant: 'default',\n})\n\nconst DISABLED_STYLES = 'pointer-events-none opacity-60'\n\nconst RadioGroup = (\n allProps: RadioGroupProps & {\n ref?: Ref<ComponentRef<typeof RadioGroupPrimitive.Root>>\n },\n): ReactElement => {\n const isControlled = 'selected' in allProps\n const {\n className,\n disabled,\n errorMessage,\n itemClassName,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onChange,\n onValueChange,\n orientation = 'vertical',\n ref,\n selected: selectedProp,\n state = 'default',\n variant = 'default',\n warningMessage,\n 'aria-describedby': ariaDescribedBy,\n ...props\n } = allProps\n const selected = isControlled ? (selectedProp ?? '') : selectedProp\n const groupId = useFormFieldId(props.id, name)\n const errorMessageId = `${groupId}-error`\n const warningMessageId = `${groupId}-warning`\n const messageId = state === 'error' && errorMessage ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const handleValueChange = (nextValue: string) => {\n onValueChange(nextValue)\n onChange?.(nextValue)\n }\n\n const contextValue = useMemo(\n () => ({\n disabledValues: Array.isArray(disabled) ? disabled : [],\n groupDisabled: typeof disabled === 'boolean' ? disabled : false,\n itemClassName,\n orientation,\n selected,\n variant,\n }),\n [orientation, variant, disabled, itemClassName, selected],\n )\n\n return (\n <RadioGroupContext.Provider value={contextValue}>\n <div data-slot='radio-group-field' className='flex w-full flex-col gap-1.5'>\n <RadioGroupPrimitive.Root\n className={cn('flex w-full text-text-primary', orientation === 'vertical' ? 'gap-4 flex-col' : 'gap-5 flex-row', variant === 'unstyled' && 'gap-2.5 w-fit', className)}\n data-state={state}\n data-testid='spectral-radio-group'\n id={groupId}\n aria-invalid={state === 'error' ? true : undefined}\n aria-describedby={[messageId, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n disabled={contextValue.groupDisabled}\n name={name}\n onValueChange={handleValueChange}\n ref={ref}\n value={selected}\n {...props}\n />\n <ErrorMessage\n dataTestId='spectral-radio-group-error-message'\n id={errorMessageId}\n message={state === 'error' ? errorMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-radio-group-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? warningMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n </RadioGroupContext.Provider>\n )\n}\nRadioGroup.displayName = 'RadioGroup'\n\nconst DEFAULT_TRANSITION: Transition = { type: 'spring', stiffness: 200, damping: 16 }\n\nconst RadioButton = memo(\n ({\n className,\n id,\n isDisabled,\n ref,\n transition = DEFAULT_TRANSITION,\n value,\n ...props\n }: Omit<ComponentProps<typeof RadioGroupPrimitive.Item>, 'asChild'> & {\n isDisabled?: boolean\n ref?: Ref<HTMLButtonElement>\n transition?: Transition\n }) => {\n const prefersReducedMotion = useReducedMotion()\n\n // When reduced motion is preferred, fall back to original non-animated behavior\n if (prefersReducedMotion) {\n return (\n <RadioGroupPrimitive.Item\n className={cn(\n 'h-4.5 w-4.5 border-border-subtle ring-black relative aspect-square cursor-pointer rounded-full border-2 bg-radio-bg transition-colors',\n 'hover:border-radio-border--hover focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-accent',\n 'data-[state=checked]:border-radio-border--selected data-[state=checked]:bg-radio-bg',\n isDisabled && DISABLED_STYLES,\n className,\n )}\n data-testid='spectral-radio-group-item'\n disabled={isDisabled}\n id={id}\n ref={ref as Ref<ComponentRef<typeof RadioGroupPrimitive.Item>>}\n value={value}\n {...props}\n >\n <RadioGroupPrimitive.Indicator className={cn(`after:inset-0 after:h-2.5 after:w-2.5 after:absolute after:m-auto after:rounded-full after:bg-radio-bg--selected after:content-['']`, isDisabled && DISABLED_STYLES)} />\n </RadioGroupPrimitive.Item>\n )\n }\n\n return (\n <RadioGroupPrimitive.Item value={value} id={id} disabled={isDisabled} asChild {...props}>\n <motion.button\n className={cn(\n 'h-4.5 w-4.5 border-border-subtle ring-black relative aspect-square cursor-pointer rounded-full border-2 bg-radio-bg transition-colors',\n 'hover:border-radio-border--hover focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-accent',\n 'data-[state=checked]:border-radio-border--selected data-[state=checked]:bg-radio-bg',\n isDisabled && DISABLED_STYLES,\n className,\n )}\n data-testid='spectral-radio-group-item'\n ref={ref}\n whileHover={{ scale: 1.05 }}\n whileTap={{ scale: 0.95 }}\n >\n <RadioGroupPrimitive.Indicator className='relative flex items-center justify-center'>\n <AnimatePresence>\n <motion.div animate={{ opacity: 1, scale: 1 }} className='h-2.5 w-2.5 absolute rounded-full bg-radio-bg--selected' exit={{ opacity: 0, scale: 0 }} initial={{ opacity: 0, scale: 0 }} key='radio-indicator' transition={transition} />\n </AnimatePresence>\n </RadioGroupPrimitive.Indicator>\n </motion.button>\n </RadioGroupPrimitive.Item>\n )\n },\n)\nRadioButton.displayName = 'RadioButton'\n\nconst RadioGroupItem = ({\n children,\n className,\n disabled,\n ref,\n value,\n ...props\n}: RadioGroupItemProps & {\n ref?: Ref<ComponentRef<typeof RadioGroupPrimitive.Item>>\n}): ReactElement => {\n const { disabledValues, groupDisabled, itemClassName, variant, orientation } = useContext(RadioGroupContext)\n const generatedId = useId()\n\n const stringValue = value.toString()\n const id = props.id?.toString() ?? `${stringValue}-${generatedId}`\n const isDisabled = groupDisabled || disabledValues.includes(stringValue) || Boolean(disabled)\n\n if (variant === 'unstyled') {\n return (\n <RadioGroupPrimitive.Item asChild data-testid='spectral-radio-group-item' disabled={isDisabled} id={id} ref={ref} value={stringValue} {...props}>\n <Label className={cn('rounded flex h-fit w-fit border-2 border-transparent data-[state=checked]:border-radio-border--selected', isDisabled && DISABLED_STYLES, itemClassName, className)} data-testid='spectral-radio-group-item-label' htmlFor={id}>\n {children}\n </Label>\n </RadioGroupPrimitive.Item>\n )\n }\n\n return (\n <div className={cn('flex items-center', isDisabled && DISABLED_STYLES, itemClassName, className, orientation)}>\n <RadioButton ref={ref} value={stringValue} id={id} isDisabled={isDisabled} {...props} />\n {children && (\n <Label className={cn('text-md font-normal cursor-pointer', orientation === 'vertical' ? 'ml-2' : 'ml-1')} htmlFor={id}>\n {children}\n </Label>\n )}\n </div>\n )\n}\nRadioGroupItem.displayName = 'RadioGroup.Item'\n\nconst RadioGroupLabel = ({\n ref,\n className,\n ...props\n}: ComponentProps<typeof Label> & {\n ref?: Ref<ComponentRef<typeof Label>>\n}): ReactElement => {\n return <Label ref={ref} data-testid='spectral-radio-group-label' className={cn('text-md font-medium block', className)} {...props} />\n}\nRadioGroupLabel.displayName = 'RadioGroup.Label'\n\nexport { RadioGroup, RadioGroupItem, RadioGroupLabel }\n"],"mappings":";;;;;;;;;;;AA8CA,MAAM,oBAAoB,cAAqC;CAC7D,gBAAgB,EAAE;CAClB,eAAe;CACf,aAAa;CACb,SAAS;CACV,CAAA;AAED,MAAM,kBAAkB;AAExB,MAAM,cACJ,aAGiB;CACjB,MAAM,eAAe,cAAc;CACnC,MAAM,EACJ,WACA,UACA,cACA,eACA,sBAAsB,GACtB,sBAAsB,OACtB,MACA,UACA,eACA,cAAc,YACd,KACA,UAAU,cACV,QAAQ,WACR,UAAU,WACV,gBACA,oBAAoB,iBACpB,GAAG,UACD;CACJ,MAAM,WAAW,eAAgB,gBAAgB,KAAM;CACvD,MAAM,UAAU,eAAe,MAAM,IAAI,KAAI;CAC7C,MAAM,iBAAiB,G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,qBAAC,OAAD;EAAK,WAAW,GAAG,qBAAqB,cAAc,iBAAiB,eAAe,WAAW,YAAY;YAA7G,CACE,oBAAC,aAAD;GAAkB;GAAK,OAAO;GAAiB;GAAgB;GAAY,GAAI;GAAQ,GACtF,YACC,oBAAC,OAAD;GAAO,WAAW,GAAG,sCAAsC,gBAAgB,aAAa,SAAS,OAAO;GAAE,SAAS;GAChH;GACI,EAEN;;;AAGT,eAAe,cAAc;AAE7B,MAAM,mBAAmB,EACvB,KACA,WACA,GAAG,YAGe;AAClB,QAAO,oBAAC,OAAD;EAAY;EAA8C,WAAW,GAAG,6BAA6B,UAAU;EAAE,GAAI;EAAQ;;AAEtI,gBAAgB,cAAc"}
1
+ {"version":3,"file":"RadioGroup.js","names":[],"sources":["../src/components/RadioGroup/RadioGroup.tsx"],"sourcesContent":["import { Label } from '@components/Label/Label'\nimport * as RadioGroupPrimitive from '@radix-ui/react-radio-group'\nimport {\n ErrorMessage,\n getErrorMessageId,\n getWarningMessageId,\n useFormFieldId,\n WarningMessage,\n type BaseFormFieldProps,\n type FormFieldState,\n} from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from 'motion/react'\nimport { Children, createContext, memo, useContext, useId, useMemo, type ComponentProps, type ComponentRef, type ReactElement, type ReactNode, type Ref } from 'react'\n\ntype RadioGroupVariant = 'default' | 'unstyled'\n\nexport interface RadioGroupProps extends Omit<ComponentProps<typeof RadioGroupPrimitive.Root>, 'onChange' | 'disabled'> {\n className?: string\n disabled?: boolean | string[]\n errorMessage?: BaseFormFieldProps['errorMessage']\n itemClassName?: string\n messageReserveLines?: number\n messageReserveSpace?: boolean\n name: string\n onChange: (selected: string) => void\n /** @deprecated Use `onChange` instead. `onValueChange` will be removed in a future release. */\n onValueChange?: (selected: string) => void\n orientation?: 'horizontal' | 'vertical'\n required?: boolean\n selected?: string\n state?: FormFieldState\n variant?: RadioGroupVariant\n warningMessage?: BaseFormFieldProps['errorMessage']\n 'aria-describedby'?: string\n 'aria-label'?: string\n}\n\nexport interface RadioGroupItemProps extends ComponentProps<typeof RadioGroupPrimitive.Item> {\n children?: ReactNode\n className?: string\n description?: string | ReactNode\n id?: string\n value: string\n}\n\ninterface RadioGroupContextType {\n disabledValues: string[]\n groupDisabled: boolean\n itemClassName?: string\n orientation: 'horizontal' | 'vertical'\n selected?: string\n variant: RadioGroupVariant\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextType>({\n disabledValues: [],\n groupDisabled: false,\n orientation: 'vertical',\n variant: 'default',\n})\n\nconst DISABLED_STYLES = 'pointer-events-none opacity-60'\n\nconst RadioGroup = (\n allProps: RadioGroupProps & {\n ref?: Ref<ComponentRef<typeof RadioGroupPrimitive.Root>>\n },\n): ReactElement => {\n const isControlled = 'selected' in allProps\n const {\n className,\n disabled,\n errorMessage,\n itemClassName,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onChange,\n onValueChange,\n orientation = 'vertical',\n ref,\n selected: selectedProp,\n state = 'default',\n variant = 'default',\n warningMessage,\n 'aria-describedby': ariaDescribedBy,\n ...props\n } = allProps\n const selected = isControlled ? (selectedProp ?? '') : selectedProp\n const groupId = useFormFieldId(props.id, name)\n const errorMessageId = getErrorMessageId(groupId)\n const warningMessageId = getWarningMessageId(groupId)\n const messageId = state === 'error' && errorMessage ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const handleValueChange = (nextValue: string) => {\n onChange(nextValue)\n onValueChange?.(nextValue)\n }\n\n const contextValue = useMemo(\n () => ({\n disabledValues: Array.isArray(disabled) ? disabled : [],\n groupDisabled: typeof disabled === 'boolean' ? disabled : false,\n itemClassName,\n orientation,\n selected,\n variant,\n }),\n [orientation, variant, disabled, itemClassName, selected],\n )\n\n return (\n <RadioGroupContext.Provider value={contextValue}>\n <div data-slot='radio-group-field' className='flex w-full flex-col gap-1.5'>\n <RadioGroupPrimitive.Root\n aria-invalid={state === 'error' ? true : undefined}\n aria-describedby={[messageId, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n className={cn('group/radio-field flex w-full text-text-primary', orientation === 'vertical' ? 'gap-4 flex-col' : 'gap-5 flex-row', variant === 'unstyled' && 'gap-2.5 w-fit', className)}\n data-state={state}\n data-testid='spectral-radio-group'\n disabled={contextValue.groupDisabled}\n id={groupId}\n name={name}\n onValueChange={handleValueChange}\n ref={ref}\n value={selected}\n {...props}\n />\n <ErrorMessage\n dataTestId='spectral-radio-group-error-message'\n id={errorMessageId}\n message={state === 'error' ? errorMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-radio-group-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? warningMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n </RadioGroupContext.Provider>\n )\n}\nRadioGroup.displayName = 'RadioGroup'\n\nconst DEFAULT_TRANSITION: Transition = { type: 'spring', stiffness: 200, damping: 16 }\n\nconst RADIO_BUTTON_CLASSES = cn(\n 'size-4.5 border-border-subtle relative aspect-square cursor-pointer rounded-full border-2 bg-radio-bg transition-colors hover:border-radio-border--hover',\n 'focus:outline-none focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-accent data-[state=checked]:border-radio-border--selected data-[state=checked]:bg-radio-bg',\n 'group-data-[state=error]/radio-field:data-[state=unchecked]:border-danger-400 group-data-[state=error]/radio-field:data-[state=unchecked]:hover:border-danger-500 group-data-[state=error]/radio-field:focus-visible:outline-danger-400',\n 'group-data-[state=warning]/radio-field:data-[state=unchecked]:border-warning-400 group-data-[state=warning]/radio-field:data-[state=unchecked]:hover:border-warning-500 group-data-[state=warning]/radio-field:focus-visible:outline-warning-400',\n)\n\nconst RadioButton = memo(\n ({\n className,\n id,\n isDisabled,\n ref,\n transition = DEFAULT_TRANSITION,\n value,\n ...props\n }: Omit<ComponentProps<typeof RadioGroupPrimitive.Item>, 'asChild'> & {\n isDisabled?: boolean\n ref?: Ref<HTMLButtonElement>\n transition?: Transition\n }) => {\n const prefersReducedMotion = useReducedMotion()\n const buttonClassName = cn(RADIO_BUTTON_CLASSES, isDisabled && DISABLED_STYLES, className)\n\n // When reduced motion is preferred, fall back to original non-animated behavior\n if (prefersReducedMotion) {\n return (\n <RadioGroupPrimitive.Item className={buttonClassName} data-testid='spectral-radio-group-item' disabled={isDisabled} id={id} ref={ref as Ref<ComponentRef<typeof RadioGroupPrimitive.Item>>} value={value} {...props}>\n <RadioGroupPrimitive.Indicator className={cn(`after:inset-0 after:h-2.5 after:w-2.5 after:absolute after:m-auto after:rounded-full after:bg-radio-bg--selected after:content-['']`, isDisabled && DISABLED_STYLES)} />\n </RadioGroupPrimitive.Item>\n )\n }\n\n return (\n <RadioGroupPrimitive.Item value={value} id={id} disabled={isDisabled} asChild {...props}>\n <motion.button className={buttonClassName} data-testid='spectral-radio-group-item' ref={ref} whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }}>\n <RadioGroupPrimitive.Indicator className='relative flex items-center justify-center'>\n <AnimatePresence>\n <motion.div animate={{ opacity: 1, scale: 1 }} className='h-2.5 w-2.5 absolute rounded-full bg-radio-bg--selected' exit={{ opacity: 0, scale: 0 }} initial={{ opacity: 0, scale: 0 }} key='radio-indicator' transition={transition} />\n </AnimatePresence>\n </RadioGroupPrimitive.Indicator>\n </motion.button>\n </RadioGroupPrimitive.Item>\n )\n },\n)\nRadioButton.displayName = 'RadioButton'\n\nconst RadioGroupItem = ({\n children,\n className,\n disabled,\n ref,\n value,\n ...props\n}: RadioGroupItemProps & {\n ref?: Ref<ComponentRef<typeof RadioGroupPrimitive.Item>>\n}): ReactElement => {\n const { disabledValues, groupDisabled, itemClassName, variant, orientation } = useContext(RadioGroupContext)\n const generatedId = useId()\n\n const stringValue = value.toString()\n const id = props.id?.toString() ?? `${stringValue}-${generatedId}`\n const isDisabled = groupDisabled || disabledValues.includes(stringValue) || Boolean(disabled)\n const isTextContent = Children.toArray(children).every((child) => typeof child === 'string' || typeof child === 'number')\n\n if (variant === 'unstyled') {\n return (\n <RadioGroupPrimitive.Item asChild data-testid='spectral-radio-group-item' disabled={isDisabled} id={id} ref={ref} value={stringValue} {...props}>\n <Label className={cn('rounded cursor-pointer flex h-fit w-fit border-2 border-transparent data-[state=checked]:border-radio-border--selected [&_*]:cursor-[inherit]', isTextContent && 'p-1.5', isDisabled && DISABLED_STYLES, itemClassName, className)} data-testid='spectral-radio-group-item-label' htmlFor={id}>\n {children}\n </Label>\n </RadioGroupPrimitive.Item>\n )\n }\n\n return (\n <div className={cn('flex items-center', isDisabled && DISABLED_STYLES, itemClassName, className, orientation)}>\n <RadioButton ref={ref} value={stringValue} id={id} isDisabled={isDisabled} {...props} />\n {children && (\n <Label className={cn('text-md font-normal cursor-pointer', orientation === 'vertical' ? 'ml-2' : 'ml-1.5')} htmlFor={id}>\n {children}\n </Label>\n )}\n </div>\n )\n}\nRadioGroupItem.displayName = 'RadioGroup.Item'\n\nconst RadioGroupLabel = ({\n ref,\n className,\n ...props\n}: ComponentProps<typeof Label> & {\n ref?: Ref<ComponentRef<typeof Label>>\n}): ReactElement => {\n return <Label ref={ref} data-testid='spectral-radio-group-label' className={cn('text-md font-medium block', className)} {...props} />\n}\nRadioGroupLabel.displayName = 'RadioGroup.Label'\n\nexport { RadioGroup, RadioGroupItem, RadioGroupLabel }\n"],"mappings":";;;;;;;;;;;AAuDA,MAAM,oBAAoB,cAAqC;CAC7D,gBAAgB,EAAE;CAClB,eAAe;CACf,aAAa;CACb,SAAS;CACV,CAAA;AAED,MAAM,kBAAkB;AAExB,MAAM,cACJ,aAGiB;CACjB,MAAM,eAAe,cAAc;CACnC,MAAM,EACJ,WACA,UACA,cACA,eACA,sBAAsB,GACtB,sBAAsB,OACtB,MACA,UACA,eACA,cAAc,YACd,KACA,UAAU,cACV,QAAQ,WACR,UAAU,WACV,gBACA,oBAAoB,iBACpB,GAAG,UACD;CACJ,MAAM,W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UAAU,YAAY,OAAO,UAAU,SAAQ;AAExH,KAAI,YAAY,WACd,QACE,oBAAC,oBAAoB,MAArB;EAA0B;EAAgD,UAAU;EAAgB;EAAS;EAAK,OAAO;EAAa,GAAI;YACxI,oBAAC,OAAD;GAAO,WAAW,GAAG,iJAAiJ,iBAAiB,SAAS,cAAc,iBAAiB,eAAe,UAAU;GAAgD,SAAS;GAC9S;GACI;EACiB;AAI9B,QACE,qBAAC,OAAD;EAAK,WAAW,GAAG,qBAAqB,cAAc,iBAAiB,eAAe,WAAW,YAAY;YAA7G,CACE,oBAAC,aAAD;GAAkB;GAAK,OAAO;GAAiB;GAAgB;GAAY,GAAI;GAAQ,GACtF,YACC,oBAAC,OAAD;GAAO,WAAW,GAAG,sCAAsC,gBAAgB,aAAa,SAAS,SAAS;GAAE,SAAS;GAClH;GACI,EAEN;;;AAGT,eAAe,cAAc;AAE7B,MAAM,mBAAmB,EACvB,KACA,WACA,GAAG,YAGe;AAClB,QAAO,oBAAC,OAAD;EAAY;EAA8C,WAAW,GAAG,6BAA6B,UAAU;EAAE,GAAI;EAAQ;;AAEtI,gBAAgB,cAAc"}
package/dist/Select.d.ts CHANGED
@@ -16,6 +16,7 @@ interface SelectProps extends Omit<ComponentPropsWithoutRef<'button'>, 'value' |
16
16
  labelClassName?: string;
17
17
  loadingMessage?: string;
18
18
  onChange?: (value: string) => void;
19
+ /** @deprecated Use `onChange` instead. `onValueChange` will be removed in a future release. */
19
20
  onValueChange?: (value: string) => void;
20
21
  options: SelectOption[];
21
22
  placeholder?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Select.d.ts","names":[],"sources":["../src/components/Select/Select.tsx"],"mappings":";;;;;;KA2BK,YAAA,GAAe,UAAA;AAAA,KACf,KAAA;AAAA,KACA,IAAA;AAAA,UAEY,WAAA,SAAoB,IAAA,CAAK,wBAAA,4HAAoJ,IAAA,CAAK,kBAAA;EACjM,YAAA;EACA,aAAA,GAAgB,aAAA;EAChB,YAAA,GAAe,SAA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AA;EACP,UAAA;AAAA;AAAA,wBAIA,QAAA,EAAU,mBAAA;EACR,GAAA,GAAM,GAAA,CAAI,iBAAA;AAAA,IACX,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
package/dist/Select.js CHANGED
@@ -4,7 +4,7 @@ import { ChevronDownIcon } from "./Icons/ChevronDownIcon.js";
4
4
  import { LoaderIcon } from "./Icons/LoaderIcon.js";
5
5
  import { cn } from "./utils/twUtils.js";
6
6
  import { ErrorMessage, WarningMessage } from "./FormFieldMessage.js";
7
- import { EmptyState, LoadingState, getAriaProps, getDropdownSurfaceClasses, getDropdownWidthStyles, getErrorMessageId, getFormFieldCSSProperties, getOptionClasses, getTriggerClasses, groupOptions, useFormFieldId } from "./utils/formFieldUtils.js";
7
+ import { EmptyState, LoadingState, getAriaProps, getDropdownSurfaceClasses, getDropdownWidthStyles, getErrorMessageId, getFormFieldCSSProperties, getOptionClasses, getTriggerClasses, getWarningMessageId, groupOptions, useFormFieldId } from "./utils/formFieldUtils.js";
8
8
  import { Label } from "./Label.js";
9
9
  import { useAutoDropdownHorizontalShift } from "./utils/dropdownPositioning.js";
10
10
  import { SelectValue } from "./primitives/select.js";
@@ -22,7 +22,7 @@ const Select = (allProps) => {
22
22
  const selectId = useFormFieldId(id, name);
23
23
  const listboxId = `${selectId}-listbox`;
24
24
  const errorMessageId = getErrorMessageId(selectId);
25
- const warningMessageId = `${selectId}-warning`;
25
+ const warningMessageId = getWarningMessageId(selectId);
26
26
  const messageId = state === "error" && errorMessage ? errorMessageId : state === "warning" && warningMessage ? warningMessageId : void 0;
27
27
  const { dropdownWidthMode, dropdownWidthStyle, resolvedDropdownWidth } = getDropdownWidthStyles({
28
28
  dropdownWidth,
@@ -127,8 +127,8 @@ const Select = (allProps) => {
127
127
  collisionPadding,
128
128
  "data-dropdown-width-mode": dropdownWidthMode,
129
129
  "data-dropdown-width-value": dropdownWidthMode === "custom" ? dropdownWidth : void 0,
130
- id: listboxId,
131
130
  "data-slot": "select-content",
131
+ id: listboxId,
132
132
  position,
133
133
  ref: setDropdownElement,
134
134
  side,
@@ -1 +1 @@
1
- {"version":3,"file":"Select.js","names":[],"sources":["../src/components/Select/Select.tsx"],"sourcesContent":["import { CheckmarkIcon, ChevronDownIcon, LoaderIcon } from '@components/Icons'\nimport { Label } from '@components/Label/Label'\nimport { SelectValue } from '@primitives/select'\nimport * as SelectPrimitive from '@radix-ui/react-select'\nimport { useAutoDropdownHorizontalShift } from '@utils/dropdownPositioning'\nimport {\n EmptyState,\n ErrorMessage,\n getAriaProps,\n getDropdownWidthStyles,\n getDropdownSurfaceClasses,\n getErrorMessageId,\n getFormFieldCSSProperties,\n getOptionClasses,\n getTriggerClasses,\n groupOptions,\n LoadingState,\n WarningMessage,\n useFormFieldId,\n type BaseFormFieldProps,\n type BaseOption,\n type DropdownWidth,\n type FormFieldState,\n} from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useState, type ComponentPropsWithoutRef, type CSSProperties, type ReactNode, type Ref } from 'react'\n\ntype SelectOption = BaseOption\ntype Align = 'start' | 'center' | 'end'\ntype Side = 'top' | 'bottom' | 'left' | 'right'\n\nexport interface SelectProps extends Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'onChange' | 'aria-disabled' | 'aria-invalid' | 'aria-required' | 'aria-describedby' | 'aria-label'>, Omit<BaseFormFieldProps, 'state'> {\n defaultValue?: string\n dropdownWidth?: DropdownWidth\n emptyMessage?: ReactNode\n id?: string\n label?: string\n labelClassName?: string\n loadingMessage?: string\n onChange?: (value: string) => void\n onValueChange?: (value: string) => void\n options: SelectOption[]\n placeholder?: string\n state?: Exclude<FormFieldState, 'disabled'>\n value?: string\n warningMessage?: BaseFormFieldProps['errorMessage']\n}\n\nexport interface SelectExtendedProps extends SelectProps {\n align?: Align\n alignOffset?: number\n avoidCollisions?: boolean\n collisionBoundary?: Element | Element[] | null\n collisionPadding?: number | Partial<Record<Side, number>>\n position?: 'popper' | 'item-aligned'\n side?: Side\n sideOffset?: number\n}\n\nexport const Select = (\n allProps: SelectExtendedProps & {\n ref?: Ref<HTMLButtonElement>\n },\n) => {\n const isControlled = 'value' in allProps\n const {\n align = 'start',\n alignOffset = 0,\n avoidCollisions = true,\n className,\n collisionBoundary,\n collisionPadding = 10,\n defaultValue,\n dropdownWidth = 'trigger',\n emptyMessage = 'No options found',\n errorMessage,\n disabled,\n id,\n label,\n labelClassName,\n loadingMessage = 'Loading…',\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onChange,\n onValueChange,\n options,\n placeholder = 'Select an option',\n position = 'popper',\n ref,\n required,\n side = 'bottom',\n sideOffset = 4,\n state = 'default',\n value: valueProp,\n warningMessage,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n ...props\n } = allProps\n const value = isControlled ? (valueProp ?? '') : valueProp\n const [open, setOpen] = useState(false)\n const { dropdownShiftStyle, setDropdownElement } = useAutoDropdownHorizontalShift(open)\n const selectId = useFormFieldId(id, name)\n const listboxId = `${selectId}-listbox`\n const errorMessageId = getErrorMessageId(selectId)\n const warningMessageId = `${selectId}-warning`\n const messageId = state === 'error' && errorMessage ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const { dropdownWidthMode, dropdownWidthStyle, resolvedDropdownWidth } = getDropdownWidthStyles({\n dropdownWidth,\n triggerWidth: 'var(--radix-select-trigger-width)',\n })\n const selectContentStyle = {\n '--spectral-select-content-width': resolvedDropdownWidth,\n ...(position === 'item-aligned' ? { width: resolvedDropdownWidth } : {}),\n ...dropdownWidthStyle,\n ...dropdownShiftStyle,\n } as CSSProperties\n const isDisabled = Boolean(disabled)\n const isLoading = state === 'loading'\n const isInvalid = state === 'error'\n const ariaProps = getAriaProps(state, ariaDescribedBy, required, messageId)\n const { groups, ungrouped } = groupOptions(options)\n const handleValueChange = (nextValue: string) => {\n onChange?.(nextValue)\n onValueChange?.(nextValue)\n }\n\n const renderOptions = () => {\n if (isLoading) {\n return <LoadingState data-testid='spectral-select-loading' message={loadingMessage} />\n }\n\n if (options.length === 0) {\n return <EmptyState data-testid='spectral-select-empty' message={emptyMessage} />\n }\n\n const renderOption = (option: SelectOption) => {\n const isSelected = value === option.value\n\n return (\n <SelectPrimitive.Item className={cn(getOptionClasses(!!option.disabled, false, isSelected), 'relative flex w-full cursor-pointer items-center')} data-testid='spectral-select-item' disabled={option.disabled} key={option.value} value={option.value}>\n <SelectPrimitive.ItemText data-testid='spectral-select-item-text' className='block truncate'>\n {option.label}\n </SelectPrimitive.ItemText>\n <SelectPrimitive.ItemIndicator data-testid='spectral-select-item-selected-indicator' asChild>\n <span className='right-2 h-4 w-4 absolute flex items-center justify-center'>\n <CheckmarkIcon size={16} />\n </span>\n </SelectPrimitive.ItemIndicator>\n </SelectPrimitive.Item>\n )\n }\n\n return (\n <>\n {ungrouped.length > 0 && (\n <>\n {ungrouped.map(renderOption)}\n {Object.keys(groups).length > 0 && <SelectPrimitive.Separator className='-mx-1 my-1 h-px bg-border-secondary' data-testid='spectral-select-separator' />}\n </>\n )}\n\n {Object.entries(groups).map(([groupName, groupOptions], groupIndex) => (\n <SelectPrimitive.Group key={groupName} data-testid='spectral-select-group'>\n {groupIndex > 0 && <SelectPrimitive.Separator className='-mx-1 my-1 h-px bg-border-secondary' data-testid='spectral-select-group-separator' />}\n <Label className={cn('px-2 py-1.5 text-base font-semibold text-text-primary', labelClassName)} data-testid='spectral-select-group-label'>\n {groupName}\n </Label>\n {groupOptions.map((option: BaseOption) => renderOption(option))}\n </SelectPrimitive.Group>\n ))}\n </>\n )\n }\n\n return (\n <div className='w-full'>\n {label && (\n <Label className={cn('mb-2 block text-text-primary', labelClassName, isDisabled && 'text-text-secondary')} data-testid='spectral-select-label' htmlFor={selectId}>\n {label}\n </Label>\n )}\n <SelectPrimitive.Root data-testid='spectral-select' defaultValue={defaultValue} disabled={isDisabled} name={name} onOpenChange={setOpen} onValueChange={handleValueChange} open={open} required={required} value={value}>\n <SelectPrimitive.Trigger\n aria-controls={listboxId}\n aria-expanded={open}\n aria-label={ariaLabel ?? label}\n asChild\n className={cn(getTriggerClasses(open, state), 'text-input-text data-placeholder:text-input-text-placeholder!', className)}\n data-slot='select-trigger'\n data-state={state}\n data-testid='spectral-select-trigger'\n id={selectId}\n ref={ref}\n style={getFormFieldCSSProperties() as CSSProperties}\n {...ariaProps}\n {...props}\n >\n <button\n className='min-w-0 gap-2 [&>span]:min-w-0 grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center overflow-hidden text-left whitespace-nowrap text-input-text! data-placeholder:text-input-text-placeholder! [&>span]:block [&>span]:overflow-hidden [&>span]:text-ellipsis [&>span]:whitespace-nowrap [&>span[data-placeholder]]:text-input-text-placeholder!'\n type='button'\n disabled={isDisabled}\n >\n <SelectValue data-testid='spectral-select-value' placeholder={placeholder} />\n <SelectPrimitive.Icon asChild>\n <div className='flex shrink-0 cursor-pointer items-center'>{isLoading ? <LoaderIcon size={20} /> : <ChevronDownIcon className={cn('transition-transform duration-200', open && 'rotate-180')} size={20} />}</div>\n </SelectPrimitive.Icon>\n </button>\n </SelectPrimitive.Trigger>\n\n <SelectPrimitive.Portal>\n <SelectPrimitive.Content\n align={align}\n alignOffset={alignOffset}\n avoidCollisions={avoidCollisions}\n className={cn(\n 'relative z-50 max-h-[min(var(--radix-select-content-available-height),300px)] min-w-32 origin-(--radix-select-content-transform-origin) overflow-hidden pb-1',\n getDropdownSurfaceClasses(),\n 'motion-safe:data-[state=closed]:animate-out motion-safe:data-[state=open]:animate-in motion-safe:data-[state=closed]:fade-out-0 motion-safe:data-[state=closed]:zoom-out-95',\n 'motion-safe:data-[state=open]:fade-in-0 motion-safe:data-[state=open]:zoom-in-95 motion-safe:data-[side=bottom]:slide-in-from-top-2 motion-safe:data-[side=top]:slide-in-from-bottom-2',\n position === 'popper' && 'data-[side=bottom]:translate-y-1 data-[side=top]:-translate-y-1',\n )}\n collisionBoundary={collisionBoundary}\n collisionPadding={collisionPadding}\n data-dropdown-width-mode={dropdownWidthMode}\n data-dropdown-width-value={dropdownWidthMode === 'custom' ? dropdownWidth : undefined}\n id={listboxId}\n data-slot='select-content'\n data-testid='spectral-select-content'\n position={position}\n ref={setDropdownElement}\n side={side}\n sideOffset={sideOffset}\n style={selectContentStyle}\n >\n <SelectPrimitive.ScrollUpButton className='py-1 flex cursor-default items-center justify-center' data-testid='spectral-select-scroll-up-button'>\n <ChevronDownIcon aria-hidden='true' className='rotate-180' size={18} />\n </SelectPrimitive.ScrollUpButton>\n\n <SelectPrimitive.Viewport asChild>\n <div\n className={cn(\n 'p-1 overflow-x-hidden overflow-y-auto [&>div]:leading-5',\n position === 'popper' && (dropdownWidth === 'trigger' ? 'scroll-my-1 h-(--radix-select-trigger-height) w-(--spectral-select-content-width) min-w-(--spectral-select-content-width)' : 'scroll-my-1 h-(--radix-select-trigger-height)'),\n )}\n data-testid='spectral-select-items'\n >\n {renderOptions()}\n </div>\n </SelectPrimitive.Viewport>\n\n <SelectPrimitive.ScrollDownButton className='py-1 flex cursor-default items-center justify-center' data-testid='spectral-select-scroll-down-button'>\n <ChevronDownIcon aria-hidden='true' size={18} />\n </SelectPrimitive.ScrollDownButton>\n </SelectPrimitive.Content>\n </SelectPrimitive.Portal>\n </SelectPrimitive.Root>\n\n <ErrorMessage\n dataTestId='spectral-select-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-select-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? (warningMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n )\n}\nSelect.displayName = 'Select'\n"],"mappings":";;;;;;;;;;;;;;;AA2DA,MAAa,UACX,aAGG;CACH,MAAM,eAAe,WAAW;CAChC,MAAM,EACJ,QAAQ,SACR,cAAc,GACd,kBAAkB,MAClB,WACA,mBACA,mBAAmB,IACnB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uB,UAAU;IACvD;GACE;;;AAGT,OAAO,cAAc"}
1
+ {"version":3,"file":"Select.js","names":[],"sources":["../src/components/Select/Select.tsx"],"sourcesContent":["import { CheckmarkIcon, ChevronDownIcon, LoaderIcon } from '@components/Icons'\nimport { Label } from '@components/Label/Label'\nimport { SelectValue } from '@primitives/select'\nimport * as SelectPrimitive from '@radix-ui/react-select'\nimport { useAutoDropdownHorizontalShift } from '@utils/dropdownPositioning'\nimport {\n EmptyState,\n ErrorMessage,\n getAriaProps,\n getDropdownSurfaceClasses,\n getDropdownWidthStyles,\n getErrorMessageId,\n getFormFieldCSSProperties,\n getOptionClasses,\n getTriggerClasses,\n getWarningMessageId,\n groupOptions,\n LoadingState,\n useFormFieldId,\n WarningMessage,\n type BaseFormFieldProps,\n type BaseOption,\n type DropdownWidth,\n type FormFieldState,\n} from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useState, type ComponentPropsWithoutRef, type CSSProperties, type ReactNode, type Ref } from 'react'\n\ntype SelectOption = BaseOption\ntype Align = 'start' | 'center' | 'end'\ntype Side = 'top' | 'bottom' | 'left' | 'right'\n\nexport interface SelectProps extends Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'onChange' | 'aria-disabled' | 'aria-invalid' | 'aria-required' | 'aria-describedby' | 'aria-label'>, Omit<BaseFormFieldProps, 'state'> {\n defaultValue?: string\n dropdownWidth?: DropdownWidth\n emptyMessage?: ReactNode\n id?: string\n label?: string\n labelClassName?: string\n loadingMessage?: string\n onChange?: (value: string) => void\n /** @deprecated Use `onChange` instead. `onValueChange` will be removed in a future release. */\n onValueChange?: (value: string) => void\n options: SelectOption[]\n placeholder?: string\n state?: Exclude<FormFieldState, 'disabled'>\n value?: string\n warningMessage?: BaseFormFieldProps['errorMessage']\n}\n\nexport interface SelectExtendedProps extends SelectProps {\n align?: Align\n alignOffset?: number\n avoidCollisions?: boolean\n collisionBoundary?: Element | Element[] | null\n collisionPadding?: number | Partial<Record<Side, number>>\n position?: 'popper' | 'item-aligned'\n side?: Side\n sideOffset?: number\n}\n\nexport const Select = (\n allProps: SelectExtendedProps & {\n ref?: Ref<HTMLButtonElement>\n },\n) => {\n const isControlled = 'value' in allProps\n const {\n align = 'start',\n alignOffset = 0,\n avoidCollisions = true,\n className,\n collisionBoundary,\n collisionPadding = 10,\n defaultValue,\n dropdownWidth = 'trigger',\n emptyMessage = 'No options found',\n errorMessage,\n disabled,\n id,\n label,\n labelClassName,\n loadingMessage = 'Loading…',\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onChange,\n onValueChange,\n options,\n placeholder = 'Select an option',\n position = 'popper',\n ref,\n required,\n side = 'bottom',\n sideOffset = 4,\n state = 'default',\n value: valueProp,\n warningMessage,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n ...props\n } = allProps\n const value = isControlled ? (valueProp ?? '') : valueProp\n const [open, setOpen] = useState(false)\n const { dropdownShiftStyle, setDropdownElement } = useAutoDropdownHorizontalShift(open)\n const selectId = useFormFieldId(id, name)\n const listboxId = `${selectId}-listbox`\n const errorMessageId = getErrorMessageId(selectId)\n const warningMessageId = getWarningMessageId(selectId)\n const messageId = state === 'error' && errorMessage ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const { dropdownWidthMode, dropdownWidthStyle, resolvedDropdownWidth } = getDropdownWidthStyles({\n dropdownWidth,\n triggerWidth: 'var(--radix-select-trigger-width)',\n })\n const selectContentStyle = {\n '--spectral-select-content-width': resolvedDropdownWidth,\n ...(position === 'item-aligned' ? { width: resolvedDropdownWidth } : {}),\n ...dropdownWidthStyle,\n ...dropdownShiftStyle,\n } as CSSProperties\n const isDisabled = Boolean(disabled)\n const isLoading = state === 'loading'\n const isInvalid = state === 'error'\n const ariaProps = getAriaProps(state, ariaDescribedBy, required, messageId)\n const { groups, ungrouped } = groupOptions(options)\n const handleValueChange = (nextValue: string) => {\n onChange?.(nextValue)\n onValueChange?.(nextValue)\n }\n\n const renderOptions = () => {\n if (isLoading) {\n return <LoadingState data-testid='spectral-select-loading' message={loadingMessage} />\n }\n\n if (options.length === 0) {\n return <EmptyState data-testid='spectral-select-empty' message={emptyMessage} />\n }\n\n const renderOption = (option: SelectOption) => {\n const isSelected = value === option.value\n\n return (\n <SelectPrimitive.Item className={cn(getOptionClasses(!!option.disabled, false, isSelected), 'relative flex w-full cursor-pointer items-center')} data-testid='spectral-select-item' disabled={option.disabled} key={option.value} value={option.value}>\n <SelectPrimitive.ItemText data-testid='spectral-select-item-text' className='block truncate'>\n {option.label}\n </SelectPrimitive.ItemText>\n <SelectPrimitive.ItemIndicator data-testid='spectral-select-item-selected-indicator' asChild>\n <span className='right-2 h-4 w-4 absolute flex items-center justify-center'>\n <CheckmarkIcon size={16} />\n </span>\n </SelectPrimitive.ItemIndicator>\n </SelectPrimitive.Item>\n )\n }\n\n return (\n <>\n {ungrouped.length > 0 && (\n <>\n {ungrouped.map(renderOption)}\n {Object.keys(groups).length > 0 && <SelectPrimitive.Separator className='-mx-1 my-1 h-px bg-border-secondary' data-testid='spectral-select-separator' />}\n </>\n )}\n\n {Object.entries(groups).map(([groupName, groupOptions], groupIndex) => (\n <SelectPrimitive.Group key={groupName} data-testid='spectral-select-group'>\n {groupIndex > 0 && <SelectPrimitive.Separator className='-mx-1 my-1 h-px bg-border-secondary' data-testid='spectral-select-group-separator' />}\n <Label className={cn('px-2 py-1.5 text-base font-semibold text-text-primary', labelClassName)} data-testid='spectral-select-group-label'>\n {groupName}\n </Label>\n {groupOptions.map((option: BaseOption) => renderOption(option))}\n </SelectPrimitive.Group>\n ))}\n </>\n )\n }\n\n return (\n <div className='w-full'>\n {label && (\n <Label className={cn('mb-2 block text-text-primary', labelClassName, isDisabled && 'text-text-secondary')} data-testid='spectral-select-label' htmlFor={selectId}>\n {label}\n </Label>\n )}\n <SelectPrimitive.Root data-testid='spectral-select' defaultValue={defaultValue} disabled={isDisabled} name={name} onOpenChange={setOpen} onValueChange={handleValueChange} open={open} required={required} value={value}>\n <SelectPrimitive.Trigger\n aria-controls={listboxId}\n aria-expanded={open}\n aria-label={ariaLabel ?? label}\n asChild\n className={cn(getTriggerClasses(open, state), 'text-input-text data-placeholder:text-input-text-placeholder!', className)}\n data-slot='select-trigger'\n data-state={state}\n data-testid='spectral-select-trigger'\n id={selectId}\n ref={ref}\n style={getFormFieldCSSProperties() as CSSProperties}\n {...ariaProps}\n {...props}\n >\n <button\n className='min-w-0 gap-2 [&>span]:min-w-0 grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center overflow-hidden text-left whitespace-nowrap text-input-text! data-placeholder:text-input-text-placeholder! [&>span]:block [&>span]:overflow-hidden [&>span]:text-ellipsis [&>span]:whitespace-nowrap [&>span[data-placeholder]]:text-input-text-placeholder!'\n type='button'\n disabled={isDisabled}\n >\n <SelectValue data-testid='spectral-select-value' placeholder={placeholder} />\n <SelectPrimitive.Icon asChild>\n <div className='flex shrink-0 cursor-pointer items-center'>{isLoading ? <LoaderIcon size={20} /> : <ChevronDownIcon className={cn('transition-transform duration-200', open && 'rotate-180')} size={20} />}</div>\n </SelectPrimitive.Icon>\n </button>\n </SelectPrimitive.Trigger>\n\n <SelectPrimitive.Portal>\n <SelectPrimitive.Content\n align={align}\n alignOffset={alignOffset}\n avoidCollisions={avoidCollisions}\n className={cn(\n 'relative z-50 max-h-[min(var(--radix-select-content-available-height),300px)] min-w-32 origin-(--radix-select-content-transform-origin) overflow-hidden pb-1',\n getDropdownSurfaceClasses(),\n 'motion-safe:data-[state=closed]:animate-out motion-safe:data-[state=open]:animate-in motion-safe:data-[state=closed]:fade-out-0 motion-safe:data-[state=closed]:zoom-out-95',\n 'motion-safe:data-[state=open]:fade-in-0 motion-safe:data-[state=open]:zoom-in-95 motion-safe:data-[side=bottom]:slide-in-from-top-2 motion-safe:data-[side=top]:slide-in-from-bottom-2',\n position === 'popper' && 'data-[side=bottom]:translate-y-1 data-[side=top]:-translate-y-1',\n )}\n collisionBoundary={collisionBoundary}\n collisionPadding={collisionPadding}\n data-dropdown-width-mode={dropdownWidthMode}\n data-dropdown-width-value={dropdownWidthMode === 'custom' ? dropdownWidth : undefined}\n data-slot='select-content'\n data-testid='spectral-select-content'\n id={listboxId}\n position={position}\n ref={setDropdownElement}\n side={side}\n sideOffset={sideOffset}\n style={selectContentStyle}\n >\n <SelectPrimitive.ScrollUpButton className='py-1 flex cursor-default items-center justify-center' data-testid='spectral-select-scroll-up-button'>\n <ChevronDownIcon aria-hidden='true' className='rotate-180' size={18} />\n </SelectPrimitive.ScrollUpButton>\n\n <SelectPrimitive.Viewport asChild>\n <div\n className={cn(\n 'p-1 overflow-x-hidden overflow-y-auto [&>div]:leading-5',\n position === 'popper' && (dropdownWidth === 'trigger' ? 'scroll-my-1 h-(--radix-select-trigger-height) w-(--spectral-select-content-width) min-w-(--spectral-select-content-width)' : 'scroll-my-1 h-(--radix-select-trigger-height)'),\n )}\n data-testid='spectral-select-items'\n >\n {renderOptions()}\n </div>\n </SelectPrimitive.Viewport>\n\n <SelectPrimitive.ScrollDownButton className='py-1 flex cursor-default items-center justify-center' data-testid='spectral-select-scroll-down-button'>\n <ChevronDownIcon aria-hidden='true' size={18} />\n </SelectPrimitive.ScrollDownButton>\n </SelectPrimitive.Content>\n </SelectPrimitive.Portal>\n </SelectPrimitive.Root>\n\n <ErrorMessage\n dataTestId='spectral-select-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-select-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? (warningMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n )\n}\nSelect.displayName = 'Select'\n"],"mappings":";;;;;;;;;;;;;;;AA6DA,MAAa,UACX,aAGG;CACH,MAAM,eAAe,WAAW;CAChC,MAAM,EACJ,QAAQ,SACR,cAAc,GACd,kBAAk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B,OAAQ;IACrC;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACE;;;AAGT,OAAO,cAAc"}
package/dist/Slider.js CHANGED
@@ -121,7 +121,7 @@ const Slider = ({ accessibleName, className, defaultValue, disabled, inputPositi
121
121
  "data-slot": "slider-range"
122
122
  })
123
123
  }), Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsx(SliderBase.Thumb, {
124
- className: "size-5 shadow-sm block shrink-0 rounded-full border border-slider-thumb-border bg-slider-thumb-bg ring-slider-thumb-ring/50 transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",
124
+ className: "size-4 shadow-sm block shrink-0 rounded-full border border-slider-thumb-border bg-slider-thumb-bg ring-slider-thumb-ring/50 transition-[color,box-shadow,ring] hover:ring-4 focus-visible:ring-4 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",
125
125
  "data-slot": "slider-thumb"
126
126
  }, index))]
127
127
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.js","names":[],"sources":["../src/components/Slider/Slider.tsx"],"sourcesContent":["import { Input } from '@primitives/input'\nimport * as SliderBase from '@radix-ui/react-slider'\nimport { cn } from '@utils/twUtils'\nimport { useCallback, useEffect, useMemo, useState, type ChangeEvent, type KeyboardEvent, type ReactNode } from 'react'\n\nexport type SliderLabelPosition = 'end' | 'both'\nexport type SliderInputPosition = 'start' | 'both'\n\nexport interface SliderLabelRenderProps {\n max: number\n min: number\n position: 'start' | 'end'\n values: number[]\n}\n\nexport interface SliderProps {\n accessibleName?: string\n className?: string\n defaultValue?: number[]\n disabled?: boolean\n inputPosition?: SliderInputPosition\n label?: (props: SliderLabelRenderProps) => ReactNode\n labelPosition?: SliderLabelPosition\n max?: number\n min?: number\n minStepsBetweenThumbs?: number\n name?: string\n onValueChange?: (value: number[]) => void\n onValueCommit?: (value: number[]) => void\n orientation?: 'horizontal' | 'vertical'\n step?: number\n value?: number[]\n}\n\nexport const Slider = ({ accessibleName, className, defaultValue, disabled, inputPosition, label, labelPosition, max = 100, min = 0, minStepsBetweenThumbs = 1, name, onValueChange, onValueCommit, orientation = 'horizontal', step = 1, value }: SliderProps) => {\n const isControlled = value !== undefined\n const initialValues = useMemo(\n () => (Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min]),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n )\n const [internalValues, setInternalValues] = useState(initialValues)\n const _values = isControlled ? value : internalValues\n\n // Local state for input text to allow intermediate typing states\n const [inputTexts, setInputTexts] = useState<string[]>(() => _values.map(String))\n\n // Sync input text when slider values change externally\n useEffect(() => {\n setInputTexts(_values.map(String))\n }, [_values])\n\n const handleValueChange = useCallback(\n (newValues: number[]) => {\n if (!isControlled) {\n setInternalValues(newValues)\n }\n onValueChange?.(newValues)\n },\n [isControlled, onValueChange],\n )\n\n const handleInputTextChange = useCallback(\n (index: number, e: ChangeEvent<HTMLInputElement>) => {\n const newTexts = [...inputTexts]\n newTexts[index] = e.target.value\n setInputTexts(newTexts)\n },\n [inputTexts],\n )\n\n const commitInputValue = useCallback(\n (index: number) => {\n const inputValue = inputTexts[index]\n if (inputValue === '') {\n // Reset to current slider value if empty\n setInputTexts(_values.map(String))\n return\n }\n\n let newValue = parseFloat(inputValue)\n if (isNaN(newValue)) {\n // Reset to current slider value if invalid\n setInputTexts(_values.map(String))\n return\n }\n\n // Clamp to min/max\n newValue = Math.max(min, Math.min(max, newValue))\n\n // Respect minStepsBetweenThumbs for range sliders\n const newValues = [..._values]\n if (index === 0 && _values.length > 1) {\n // Start input: ensure it doesn't exceed end value minus gap\n const maxAllowed = _values[1] - minStepsBetweenThumbs * step\n newValue = Math.min(newValue, maxAllowed)\n } else if (index === 1) {\n // End input: ensure it doesn't go below start value plus gap\n const minAllowed = _values[0] + minStepsBetweenThumbs * step\n newValue = Math.max(newValue, minAllowed)\n }\n\n newValues[index] = newValue\n handleValueChange(newValues)\n onValueCommit?.(newValues)\n },\n [inputTexts, _values, min, max, step, minStepsBetweenThumbs, handleValueChange, onValueCommit],\n )\n\n const handleInputKeyDown = useCallback(\n (index: number, e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Enter') {\n commitInputValue(index)\n e.currentTarget.blur()\n }\n },\n [commitInputValue],\n )\n\n const isVertical = orientation === 'vertical'\n const showStartLabel = labelPosition === 'both'\n const showEndLabel = label && (labelPosition === 'end' || labelPosition === 'both')\n const showStartInput = inputPosition === 'start' || inputPosition === 'both'\n const showEndInput = inputPosition === 'both' && _values.length > 1\n\n const labelClasses = cn('text-slider-label text-sm shrink-0 tabular-nums', isVertical ? 'text-center' : '')\n\n const inputClasses = 'w-10 h-fit px-1 shrink-0 text-center text-sm tabular-nums [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none'\n\n return (\n <div className={cn('gap-3 flex items-center', isVertical ? 'flex-col' : 'w-full', className)} data-testid='spectral-slider-container'>\n {showStartLabel && (\n <span className={labelClasses} data-slot='slider-label' data-testid='spectral-slider-label-start'>\n {label?.({ values: _values, min, max, position: 'start' })}\n </span>\n )}\n\n {showStartInput && (\n <Input\n aria-label={accessibleName ? `${accessibleName} start value` : 'Slider start value'}\n className={inputClasses}\n data-slot='slider-input'\n data-testid='spectral-slider-input-start'\n disabled={disabled}\n max={_values.length > 1 ? _values[1] - minStepsBetweenThumbs * step : max}\n min={min}\n onBlur={() => commitInputValue(0)}\n onChange={(e) => handleInputTextChange(0, e)}\n onKeyDown={(e) => handleInputKeyDown(0, e)}\n step={step}\n type='number'\n value={inputTexts[0] ?? ''}\n />\n )}\n\n <SliderBase.Root\n aria-label={accessibleName}\n aria-valuemax={max}\n aria-valuemin={min}\n aria-valuenow={_values[0]}\n className='data-[orientation=vertical]:min-h-44 relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col'\n data-slot='slider'\n data-testid='spectral-slider'\n disabled={disabled}\n max={max}\n min={min}\n minStepsBetweenThumbs={minStepsBetweenThumbs}\n name={name}\n onValueChange={handleValueChange}\n onValueCommit={onValueCommit}\n orientation={orientation}\n step={step}\n value={_values}\n >\n <SliderBase.Track\n className='data-[orientation=horizontal]:h-1.5 data-[orientation=vertical]:w-1.5 relative grow overflow-hidden rounded-full bg-slider-track data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full'\n data-slot='slider-track'\n data-testid='spectral-slider-track'\n >\n <SliderBase.Range className='absolute bg-slider-range data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full' data-slot='slider-range' data-testid='spectral-slider-range' />\n </SliderBase.Track>\n {Array.from({ length: _values.length }, (_, index) => (\n <SliderBase.Thumb\n className='size-5 shadow-sm block shrink-0 rounded-full border border-slider-thumb-border bg-slider-thumb-bg ring-slider-thumb-ring/50 transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50'\n data-slot='slider-thumb'\n data-testid='spectral-slider-thumb'\n key={index}\n />\n ))}\n </SliderBase.Root>\n\n {showEndInput && (\n <Input\n aria-label={accessibleName ? `${accessibleName} end value` : 'Slider end value'}\n className={inputClasses}\n data-slot='slider-input'\n data-testid='spectral-slider-input-end'\n disabled={disabled}\n max={max}\n min={_values[0] + minStepsBetweenThumbs * step}\n onBlur={() => commitInputValue(1)}\n onChange={(e) => handleInputTextChange(1, e)}\n onKeyDown={(e) => handleInputKeyDown(1, e)}\n step={step}\n type='number'\n value={inputTexts[1] ?? ''}\n />\n )}\n\n {showEndLabel && (\n <span className={labelClasses} data-slot='slider-label' data-testid='spectral-slider-label-end'>\n {label({ values: _values, min, max, position: 'end' })}\n </span>\n )}\n </div>\n )\n}\n"],"mappings":";;;;;;;;AAkCA,MAAa,UAAU,EAAE,gBAAgB,WAAW,cAAc,UAAU,eAAe,OAAO,eAAe,MAAM,KAAK,MAAM,GAAG,wBAAwB,GAAG,MAAM,eAAe,eAAe,cAA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AU;KACV,aAAU;eAGV,oBAAC,WAAW,OAAZ;MAAkB,WAAU;MAAmG,aAAU;MAAoD;KAC7K,GACjB,MAAM,KAAK,EAAE,QAAQ,QAAQ,QAAQ,GAAG,GAAG,UAC1C,oBAAC,WAAW,OAAZ;KACE,WAAU;KACV,aAAU;KAGX,EADM,MACN,CACD,CACa;;GAEhB,gBACC,oBAAC,OAAD;IACE,cAAY,iBAAiB,GAAG,eAAe,cAAc;IAC7D,WAAW;IACX,aAAU;IAEA;IACL;IACL,KAAK,QAAQ,KAAK,wBAAwB;IAC1C,cAAc,iBAAiB,EAAE;IACjC,WAAW,MAAM,sBAAsB,GAAG,EAAE;IAC5C,YAAY,MAAM,mBAAmB,GAAG,EAAE;IACpC;IACN,MAAK;IACL,OAAO,WAAW,MAAM;IACzB;GAGF,gBACC,oBAAC,QAAD;IAAM,WAAW;IAAc,aAAU;cACtC,MAAM;KAAE,QAAQ;KAAS;KAAK;KAAK,UAAU;KAAO,CAAC;IAClD;GAEL"}
1
+ {"version":3,"file":"Slider.js","names":[],"sources":["../src/components/Slider/Slider.tsx"],"sourcesContent":["import { Input } from '@primitives/input'\nimport * as SliderBase from '@radix-ui/react-slider'\nimport { cn } from '@utils/twUtils'\nimport { useCallback, useEffect, useMemo, useState, type ChangeEvent, type KeyboardEvent, type ReactNode } from 'react'\n\nexport type SliderLabelPosition = 'end' | 'both'\nexport type SliderInputPosition = 'start' | 'both'\n\nexport interface SliderLabelRenderProps {\n max: number\n min: number\n position: 'start' | 'end'\n values: number[]\n}\n\nexport interface SliderProps {\n accessibleName?: string\n className?: string\n defaultValue?: number[]\n disabled?: boolean\n inputPosition?: SliderInputPosition\n label?: (props: SliderLabelRenderProps) => ReactNode\n labelPosition?: SliderLabelPosition\n max?: number\n min?: number\n minStepsBetweenThumbs?: number\n name?: string\n onValueChange?: (value: number[]) => void\n onValueCommit?: (value: number[]) => void\n orientation?: 'horizontal' | 'vertical'\n step?: number\n value?: number[]\n}\n\nexport const Slider = ({ accessibleName, className, defaultValue, disabled, inputPosition, label, labelPosition, max = 100, min = 0, minStepsBetweenThumbs = 1, name, onValueChange, onValueCommit, orientation = 'horizontal', step = 1, value }: SliderProps) => {\n const isControlled = value !== undefined\n const initialValues = useMemo(\n () => (Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min]),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n )\n const [internalValues, setInternalValues] = useState(initialValues)\n const _values = isControlled ? value : internalValues\n\n // Local state for input text to allow intermediate typing states\n const [inputTexts, setInputTexts] = useState<string[]>(() => _values.map(String))\n\n // Sync input text when slider values change externally\n useEffect(() => {\n setInputTexts(_values.map(String))\n }, [_values])\n\n const handleValueChange = useCallback(\n (newValues: number[]) => {\n if (!isControlled) {\n setInternalValues(newValues)\n }\n onValueChange?.(newValues)\n },\n [isControlled, onValueChange],\n )\n\n const handleInputTextChange = useCallback(\n (index: number, e: ChangeEvent<HTMLInputElement>) => {\n const newTexts = [...inputTexts]\n newTexts[index] = e.target.value\n setInputTexts(newTexts)\n },\n [inputTexts],\n )\n\n const commitInputValue = useCallback(\n (index: number) => {\n const inputValue = inputTexts[index]\n if (inputValue === '') {\n // Reset to current slider value if empty\n setInputTexts(_values.map(String))\n return\n }\n\n let newValue = parseFloat(inputValue)\n if (isNaN(newValue)) {\n // Reset to current slider value if invalid\n setInputTexts(_values.map(String))\n return\n }\n\n // Clamp to min/max\n newValue = Math.max(min, Math.min(max, newValue))\n\n // Respect minStepsBetweenThumbs for range sliders\n const newValues = [..._values]\n if (index === 0 && _values.length > 1) {\n // Start input: ensure it doesn't exceed end value minus gap\n const maxAllowed = _values[1] - minStepsBetweenThumbs * step\n newValue = Math.min(newValue, maxAllowed)\n } else if (index === 1) {\n // End input: ensure it doesn't go below start value plus gap\n const minAllowed = _values[0] + minStepsBetweenThumbs * step\n newValue = Math.max(newValue, minAllowed)\n }\n\n newValues[index] = newValue\n handleValueChange(newValues)\n onValueCommit?.(newValues)\n },\n [inputTexts, _values, min, max, step, minStepsBetweenThumbs, handleValueChange, onValueCommit],\n )\n\n const handleInputKeyDown = useCallback(\n (index: number, e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Enter') {\n commitInputValue(index)\n e.currentTarget.blur()\n }\n },\n [commitInputValue],\n )\n\n const isVertical = orientation === 'vertical'\n const showStartLabel = labelPosition === 'both'\n const showEndLabel = label && (labelPosition === 'end' || labelPosition === 'both')\n const showStartInput = inputPosition === 'start' || inputPosition === 'both'\n const showEndInput = inputPosition === 'both' && _values.length > 1\n\n const labelClasses = cn('text-slider-label text-sm shrink-0 tabular-nums', isVertical ? 'text-center' : '')\n const inputClasses = 'w-10 h-fit px-1 shrink-0 text-center text-sm tabular-nums [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none'\n\n return (\n <div className={cn('gap-3 flex items-center', isVertical ? 'flex-col' : 'w-full', className)} data-testid='spectral-slider-container'>\n {showStartLabel && (\n <span className={labelClasses} data-slot='slider-label' data-testid='spectral-slider-label-start'>\n {label?.({ values: _values, min, max, position: 'start' })}\n </span>\n )}\n\n {showStartInput && (\n <Input\n aria-label={accessibleName ? `${accessibleName} start value` : 'Slider start value'}\n className={inputClasses}\n data-slot='slider-input'\n data-testid='spectral-slider-input-start'\n disabled={disabled}\n max={_values.length > 1 ? _values[1] - minStepsBetweenThumbs * step : max}\n min={min}\n onBlur={() => commitInputValue(0)}\n onChange={(e) => handleInputTextChange(0, e)}\n onKeyDown={(e) => handleInputKeyDown(0, e)}\n step={step}\n type='number'\n value={inputTexts[0] ?? ''}\n />\n )}\n\n <SliderBase.Root\n aria-label={accessibleName}\n aria-valuemax={max}\n aria-valuemin={min}\n aria-valuenow={_values[0]}\n className='data-[orientation=vertical]:min-h-44 relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col'\n data-slot='slider'\n data-testid='spectral-slider'\n disabled={disabled}\n max={max}\n min={min}\n minStepsBetweenThumbs={minStepsBetweenThumbs}\n name={name}\n onValueChange={handleValueChange}\n onValueCommit={onValueCommit}\n orientation={orientation}\n step={step}\n value={_values}\n >\n <SliderBase.Track\n className='data-[orientation=horizontal]:h-1.5 data-[orientation=vertical]:w-1.5 relative grow overflow-hidden rounded-full bg-slider-track data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full'\n data-slot='slider-track'\n data-testid='spectral-slider-track'\n >\n <SliderBase.Range className='absolute bg-slider-range data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full' data-slot='slider-range' data-testid='spectral-slider-range' />\n </SliderBase.Track>\n {Array.from({ length: _values.length }, (_, index) => (\n <SliderBase.Thumb\n className='size-4 shadow-sm block shrink-0 rounded-full border border-slider-thumb-border bg-slider-thumb-bg ring-slider-thumb-ring/50 transition-[color,box-shadow,ring] hover:ring-4 focus-visible:ring-4 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50'\n data-slot='slider-thumb'\n data-testid='spectral-slider-thumb'\n key={index}\n />\n ))}\n </SliderBase.Root>\n\n {showEndInput && (\n <Input\n aria-label={accessibleName ? `${accessibleName} end value` : 'Slider end value'}\n className={inputClasses}\n data-slot='slider-input'\n data-testid='spectral-slider-input-end'\n disabled={disabled}\n max={max}\n min={_values[0] + minStepsBetweenThumbs * step}\n onBlur={() => commitInputValue(1)}\n onChange={(e) => handleInputTextChange(1, e)}\n onKeyDown={(e) => handleInputKeyDown(1, e)}\n step={step}\n type='number'\n value={inputTexts[1] ?? ''}\n />\n )}\n\n {showEndLabel && (\n <span className={labelClasses} data-slot='slider-label' data-testid='spectral-slider-label-end'>\n {label({ values: _values, min, max, position: 'end' })}\n </span>\n )}\n </div>\n )\n}\n"],"mappings":";;;;;;;;AAkCA,MAAa,UAAU,EAAE,gBAAgB,WAAW,cAAc,UAAU,eAAe,OAAO,eAAe,MAAM,KAAK,MAAM,GAAG,wBAAwB,GAAG,MAAM,eAAe,eAAe,cAAc,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;KACV,aAAU;eAGV,oBAAC,WAAW,OAAZ;MAAkB,WAAU;MAAmG,aAAU;MAAoD;KAC7K,GACjB,MAAM,KAAK,EAAE,QAAQ,QAAQ,QAAQ,GAAG,GAAG,UAC1C,oBAAC,WAAW,OAAZ;KACE,WAAU;KACV,aAAU;KAGX,EADM,MACN,CACD,CACa;;GAEhB,gBACC,oBAAC,OAAD;IACE,cAAY,iBAAiB,GAAG,eAAe,cAAc;IAC7D,WAAW;IACX,aAAU;IAEA;IACL;IACL,KAAK,QAAQ,KAAK,wBAAwB;IAC1C,cAAc,iBAAiB,EAAE;IACjC,WAAW,MAAM,sBAAsB,GAAG,EAAE;IAC5C,YAAY,MAAM,mBAAmB,GAAG,EAAE;IACpC;IACN,MAAK;IACL,OAAO,WAAW,MAAM;IACzB;GAGF,gBACC,oBAAC,QAAD;IAAM,WAAW;IAAc,aAAU;cACtC,MAAM;KAAE,QAAQ;KAAS;KAAK;KAAK,UAAU;KAAO,CAAC;IAClD;GAEL"}
package/dist/Switch.d.ts CHANGED
@@ -7,13 +7,11 @@ import * as _$react_jsx_runtime0 from "react/jsx-runtime";
7
7
  //#region src/components/Switch/Switch.d.ts
8
8
  type SwitchVisualState = Exclude<FormFieldState, 'disabled'>;
9
9
  type SwitchProps = Omit<SwitchProps$1, 'onCheckedChange'> & {
10
- 'aria-describedby'?: string;
11
- 'aria-label'?: string;
12
10
  errorMessage?: BaseFormFieldProps['errorMessage'];
13
11
  hideLabel?: boolean;
14
12
  id?: string;
15
13
  label?: string;
16
- labelPosition?: 'left' | 'right';
14
+ labelPosition?: 'left' | 'right'; /** @deprecated Use `label` instead. `labelText` will be removed in a future release. */
17
15
  labelText?: string;
18
16
  messageReserveLines?: number;
19
17
  messageReserveSpace?: boolean;
@@ -24,6 +22,8 @@ type SwitchProps = Omit<SwitchProps$1, 'onCheckedChange'> & {
24
22
  value?: string;
25
23
  variant?: 'default' | 'squared' | 'permanent-indicator';
26
24
  warningMessage?: BaseFormFieldProps['errorMessage'];
25
+ 'aria-describedby'?: string;
26
+ 'aria-label'?: string;
27
27
  };
28
28
  declare function Switch({
29
29
  className,
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.d.ts","names":[],"sources":["../src/components/Switch/Switch.tsx"],"mappings":";;;;;;;KAOK,iBAAA,GAAoB,OAAA,CAAQ,cAAA;AAAA,KAErB,WAAA,GAAc,IAAA,CAAK,aAAA;EAC7B,kBAAA;EACA,YAAA;EACA,YAAA,GAAe,kBAAA;EACf,SAAA;EACA,EAAA;EACA,KAAA;EACA,aAAA;EACA,SAAA;EACA,mBAAA;EACA,mBAAA;EACA,QAAA,IAAY,OAAA;EACZ,GAAA,GAAM,GAAA,CAAI,iBAAA;EACV,QAAA;EACA,KAAA,GAAQ,iBAAA;EACR,KAAA;EACA,OAAA;EACA,cAAA,GAAiB,kBAAA;AAAA;AAAA;EAMjB,SAAA;EACA,QAAA;EACA,YAAA;EACA,SAAA;EACA,EAAA;EACA,KAAA;EACA,aAAA;EACA,SAAA;EACA,mBAAA;EACA,mBAAA;EACA,IAAA;EACA,QAAA;EACA,GAAA;EACA,QAAA;EACA,KAAA;EACA,KAAA;EACA,OAAA;EACA,cAAA;EAAA,oBACoB,eAAA;EAAA,cACN,SAAA;EAAA,GACX;AAAA,GACF,WAAA,GAAW,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
1
+ {"version":3,"file":"Switch.d.ts","names":[],"sources":["../src/components/Switch/Switch.tsx"],"mappings":";;;;;;;KAOK,iBAAA,GAAoB,OAAA,CAAQ,cAAA;AAAA,KAErB,WAAA,GAAc,IAAA,CAAK,aAAA;EAC7B,YAAA,GAAe,kBAAA;EACf,SAAA;EACA,EAAA;EACA,KAAA;EACA,aAAA,qBAP6C;EAS7C,SAAA;EACA,mBAAA;EACA,mBAAA;EACA,QAAA,IAAY,OAAA;EACZ,GAAA,GAAM,GAAA,CAAI,iBAAA;EACV,QAAA;EACA,KAAA,GAAQ,iBAAA;EACR,KAAA;EACA,OAAA;EACA,cAAA,GAAiB,kBAAA;EACjB,kBAAA;EACA,YAAA;AAAA;AAAA;EAMA,SAAA;EACA,QAAA;EACA,YAAA;EACA,SAAA;EACA,EAAA;EACA,KAAA;EACA,aAAA;EACA,SAAA;EACA,mBAAA;EACA,mBAAA;EACA,IAAA;EACA,QAAA;EACA,GAAA;EACA,QAAA;EACA,KAAA;EACA,KAAA;EACA,OAAA;EACA,cAAA;EAAA,oBACoB,eAAA;EAAA,cACN,SAAA;EAAA,GACX;AAAA,GACF,WAAA,GAAW,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
package/dist/Switch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { cn } from "./utils/twUtils.js";
3
3
  import { ErrorMessage, WarningMessage } from "./FormFieldMessage.js";
4
- import { useFormFieldId } from "./utils/formFieldUtils.js";
4
+ import { getErrorMessageId, getWarningMessageId, useFormFieldId } from "./utils/formFieldUtils.js";
5
5
  import { Label } from "./Label.js";
6
6
  import { Switch as Switch$1, SwitchThumb } from "./Switch/SwitchBase.js";
7
7
  import "react";
@@ -13,9 +13,9 @@ const thumbBase = "bg-switch-thumb--checked data-[state=checked]:bg-switch-thumb
13
13
  const Switch = ({ className, disabled, errorMessage, hideLabel = false, id, label, labelPosition = "right", labelText, messageReserveLines = 1, messageReserveSpace = false, name, onChange, ref, required, state = "default", value, variant, warningMessage, "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel, ...props }) => {
14
14
  const switchId = useFormFieldId(id, name);
15
15
  const isDisabled = Boolean(disabled);
16
- const resolvedLabelText = labelText ?? label;
17
- const errorMessageId = `${switchId}-error`;
18
- const warningMessageId = `${switchId}-warning`;
16
+ const resolvedLabelText = label ?? labelText;
17
+ const errorMessageId = getErrorMessageId(switchId);
18
+ const warningMessageId = getWarningMessageId(switchId);
19
19
  const messageId = state === "error" && errorMessage && errorMessageId ? errorMessageId : state === "warning" && warningMessage && warningMessageId ? warningMessageId : void 0;
20
20
  const isSquared = variant === "squared";
21
21
  return /* @__PURE__ */ jsxs("div", {
@@ -31,10 +31,10 @@ const Switch = ({ className, disabled, errorMessage, hideLabel = false, id, labe
31
31
  className: "h-7 text-sm font-medium relative inline-grid grid-cols-[1fr_1fr] items-center",
32
32
  children: [
33
33
  /* @__PURE__ */ jsx(Switch$1, {
34
- "aria-required": required,
35
34
  "aria-describedby": [messageId, ariaDescribedBy].filter(Boolean).join(" ") || void 0,
36
35
  "aria-invalid": state === "error" ? true : void 0,
37
36
  "aria-label": ariaLabel ?? (hideLabel ? resolvedLabelText : void 0),
37
+ "aria-required": required,
38
38
  className: cn("peer inset-0 w-14 focus-visible:ring-ring absolute inline-flex h-[inherit] items-center focus-visible:ring-offset-background data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg/50", "shadow-2xs cursor-pointer rounded-full border-2 border-transparent transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none", "disabled:cursor-not-allowed disabled:opacity-50", className),
39
39
  disabled: isDisabled,
40
40
  id: switchId,
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.js","names":[],"sources":["../src/components/Switch/Switch.tsx"],"sourcesContent":["import { Label } from '@components/Label/Label'\nimport { ErrorMessage, WarningMessage, useFormFieldId, type BaseFormFieldProps, type FormFieldState } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { CheckIcon, XIcon } from 'lucide-react'\nimport { type Ref } from 'react'\nimport { Switch as SwitchBase, SwitchThumb, type SwitchProps as SwitchBaseProps } from './SwitchBase'\n\ntype SwitchVisualState = Exclude<FormFieldState, 'disabled'>\n\nexport type SwitchProps = Omit<SwitchBaseProps, 'onCheckedChange'> & {\n 'aria-describedby'?: string\n 'aria-label'?: string\n errorMessage?: BaseFormFieldProps['errorMessage']\n hideLabel?: boolean\n id?: string\n label?: string\n labelPosition?: 'left' | 'right'\n labelText?: string\n messageReserveLines?: number\n messageReserveSpace?: boolean\n onChange?: (checked: boolean) => void\n ref?: Ref<HTMLButtonElement>\n required?: boolean\n state?: SwitchVisualState\n value?: string\n variant?: 'default' | 'squared' | 'permanent-indicator'\n warningMessage?: BaseFormFieldProps['errorMessage']\n}\n\nconst thumbBase = 'bg-switch-thumb--checked data-[state=checked]:bg-switch-thumb pointer-events-none block rounded-full ring-0 transition-transform motion-reduce:transition-none'\n\nexport const Switch = ({\n className,\n disabled,\n errorMessage,\n hideLabel = false,\n id,\n label,\n labelPosition = 'right',\n labelText,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onChange,\n ref,\n required,\n state = 'default',\n value,\n variant,\n warningMessage,\n 'aria-describedby': ariaDescribedBy,\n 'aria-label': ariaLabel,\n ...props\n}: SwitchProps) => {\n const switchId = useFormFieldId(id, name)\n const isDisabled = Boolean(disabled)\n const resolvedLabelText = labelText ?? label\n const errorMessageId = `${switchId}-error`\n const warningMessageId = `${switchId}-warning`\n const messageId = state === 'error' && errorMessage && errorMessageId ? errorMessageId : state === 'warning' && warningMessage && warningMessageId ? warningMessageId : undefined\n const isSquared = variant === 'squared'\n const isPermanentIndicator = variant === 'permanent-indicator'\n\n return (\n <div className='flex items-center' data-testid='spectral-switch-container' data-state={state}>\n {labelPosition === 'left' && !hideLabel && resolvedLabelText && (\n <Label className='mr-2' data-testid='spectral-switch-label-left' htmlFor={switchId}>\n {resolvedLabelText}\n </Label>\n )}\n\n {isPermanentIndicator ? (\n <div className='h-7 text-sm font-medium relative inline-grid grid-cols-[1fr_1fr] items-center'>\n <SwitchBase\n aria-required={required}\n aria-describedby={[messageId, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n aria-invalid={state === 'error' ? true : undefined}\n aria-label={ariaLabel ?? (hideLabel ? resolvedLabelText : undefined)}\n className={cn(\n 'peer inset-0 w-14 focus-visible:ring-ring absolute inline-flex h-[inherit] items-center focus-visible:ring-offset-background data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg/50',\n 'shadow-2xs cursor-pointer rounded-full border-2 border-transparent transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n className,\n )}\n data-testid='spectral-switch'\n disabled={isDisabled}\n id={switchId}\n name={name}\n onCheckedChange={onChange}\n ref={ref}\n required={required}\n value={value}\n {...props}\n >\n <SwitchThumb className={cn(thumbBase, 'size-6.5 shadow-xs relative z-10 duration-200 ease-out data-[state=checked]:translate-x-[26px] motion-reduce:duration-0 data-[state=checked]:rtl:translate-x-[-26px]')} />\n </SwitchBase>\n <span className='ml-0.5 min-w-8 peer-data-[state=unchecked]:translate-x-6 peer-data-[state=unchecked]:rtl:-translate-x-6 motion-reduce:translate-x-0 pointer-events-none relative flex items-center justify-center text-center transition-transform duration-200 ease-out peer-data-[state=checked]:invisible motion-reduce:transition-none motion-reduce:duration-0'>\n <XIcon aria-hidden='true' className='size-4' />\n </span>\n <span className='min-w-8 motion-reduce:translate-x-0 pointer-events-none relative flex items-center justify-center text-center transition-transform duration-200 ease-out peer-data-[state=checked]:-translate-x-full peer-data-[state=checked]:text-background peer-data-[state=unchecked]:invisible motion-reduce:transition-none motion-reduce:duration-0 peer-data-[state=checked]:rtl:translate-x-full'>\n <CheckIcon aria-hidden='true' className='size-4' />\n </span>\n </div>\n ) : (\n <SwitchBase\n aria-required={required}\n aria-describedby={[messageId, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n aria-invalid={state === 'error' ? true : undefined}\n aria-label={ariaLabel ?? (hideLabel ? resolvedLabelText : undefined)}\n className={cn(\n isSquared\n ? 'peer h-6 w-10 rounded-sm focus-visible:ring-black inline-flex shrink-0 items-center border-2 border-transparent transition-colors outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg [&_span]:rounded-[4px]'\n : 'focus-visible:ring-ring peer h-6 w-10 shadow-2xs inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg',\n className,\n )}\n data-testid='spectral-switch'\n disabled={isDisabled}\n id={switchId}\n name={name}\n onCheckedChange={onChange}\n ref={ref}\n required={required}\n value={value}\n {...props}\n >\n <SwitchThumb className={cn(thumbBase, isSquared ? 'size-5 shadow-xs data-[state=checked]:translate-x-4 data-[state=checked]:rtl:-translate-x-4' : 'h-5 w-5 shadow-lg data-[state=checked]:translate-x-4')} />\n </SwitchBase>\n )}\n\n {labelPosition === 'right' && !hideLabel && resolvedLabelText && (\n <Label className='ml-2' data-testid='spectral-switch-label-right' htmlFor={switchId} id={`${switchId}-label`}>\n {resolvedLabelText}\n </Label>\n )}\n\n {hideLabel && resolvedLabelText && (\n <Label className='sr-only' data-testid='spectral-switch-label-hidden' htmlFor={switchId}>\n {resolvedLabelText}\n </Label>\n )}\n <ErrorMessage\n dataTestId='spectral-switch-error-message'\n id={errorMessageId}\n message={state === 'error' ? (errorMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-switch-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? (warningMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n )\n}\nSwitch.displayName = 'Switch'\n"],"mappings":";;;;;;;;;;;AA6BA,MAAM,YAAY;AAElB,MAAa,UAAU,EACrB,WACA,UACA,cACA,YAAY,OACZ,IACA,OACA,gBAAgB,SAChB,WACA,sBAAsB,GACtB,sBAAsB,OACtB,MACA,UACA,KACA,UACA,QAAQ,WACR,OACA,SACA,gBACA,oBAAoB,iBACpB,cAAc,WACd,GAAG,YACc;CACjB,MAAM,WAAW,eAAe,IAAI,KAAI;CACxC,MAAM,aAAa,QAAQ,SAAQ;CACnC,MAA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W,GAAG,WAAW,YAAY,gGAAgG,uDAAuD,EAAG;IAClM;GAGb,kBAAkB,WAAW,CAAC,aAAa,qBAC1C,oBAAC,OAAD;IAAO,WAAU;IAAiD,SAAS;IAAU,IAAI,GAAG,SAAS;cAClG;IACI;GAGR,aAAa,qBACZ,oBAAC,OAAD;IAAO,WAAU;IAAqD,SAAS;cAC5E;IACI;GAET,oBAAC,cAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,UAAW,gBAAgB,OAAQ;IACjC;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACD,oBAAC,gBAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,YAAa,kBAAkB,OAAQ;IACrC;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACE;;;AAGT,OAAO,cAAc"}
1
+ {"version":3,"file":"Switch.js","names":[],"sources":["../src/components/Switch/Switch.tsx"],"sourcesContent":["import { Label } from '@components/Label/Label'\nimport { ErrorMessage, getErrorMessageId, getWarningMessageId, useFormFieldId, WarningMessage, type BaseFormFieldProps, type FormFieldState } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { CheckIcon, XIcon } from 'lucide-react'\nimport { type Ref } from 'react'\nimport { Switch as SwitchBase, SwitchThumb, type SwitchProps as SwitchBaseProps } from './SwitchBase'\n\ntype SwitchVisualState = Exclude<FormFieldState, 'disabled'>\n\nexport type SwitchProps = Omit<SwitchBaseProps, 'onCheckedChange'> & {\n errorMessage?: BaseFormFieldProps['errorMessage']\n hideLabel?: boolean\n id?: string\n label?: string\n labelPosition?: 'left' | 'right'\n /** @deprecated Use `label` instead. `labelText` will be removed in a future release. */\n labelText?: string\n messageReserveLines?: number\n messageReserveSpace?: boolean\n onChange?: (checked: boolean) => void\n ref?: Ref<HTMLButtonElement>\n required?: boolean\n state?: SwitchVisualState\n value?: string\n variant?: 'default' | 'squared' | 'permanent-indicator'\n warningMessage?: BaseFormFieldProps['errorMessage']\n 'aria-describedby'?: string\n 'aria-label'?: string\n}\n\nconst thumbBase = 'bg-switch-thumb--checked data-[state=checked]:bg-switch-thumb pointer-events-none block rounded-full ring-0 transition-transform motion-reduce:transition-none'\n\nexport const Switch = ({\n className,\n disabled,\n errorMessage,\n hideLabel = false,\n id,\n label,\n labelPosition = 'right',\n labelText,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onChange,\n ref,\n required,\n state = 'default',\n value,\n variant,\n warningMessage,\n 'aria-describedby': ariaDescribedBy,\n 'aria-label': ariaLabel,\n ...props\n}: SwitchProps) => {\n const switchId = useFormFieldId(id, name)\n const isDisabled = Boolean(disabled)\n const resolvedLabelText = label ?? labelText\n const errorMessageId = getErrorMessageId(switchId)\n const warningMessageId = getWarningMessageId(switchId)\n const messageId = state === 'error' && errorMessage && errorMessageId ? errorMessageId : state === 'warning' && warningMessage && warningMessageId ? warningMessageId : undefined\n const isSquared = variant === 'squared'\n const isPermanentIndicator = variant === 'permanent-indicator'\n\n return (\n <div className='flex items-center' data-testid='spectral-switch-container' data-state={state}>\n {labelPosition === 'left' && !hideLabel && resolvedLabelText && (\n <Label className='mr-2' data-testid='spectral-switch-label-left' htmlFor={switchId}>\n {resolvedLabelText}\n </Label>\n )}\n\n {isPermanentIndicator ? (\n <div className='h-7 text-sm font-medium relative inline-grid grid-cols-[1fr_1fr] items-center'>\n <SwitchBase\n aria-describedby={[messageId, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n aria-invalid={state === 'error' ? true : undefined}\n aria-label={ariaLabel ?? (hideLabel ? resolvedLabelText : undefined)}\n aria-required={required}\n className={cn(\n 'peer inset-0 w-14 focus-visible:ring-ring absolute inline-flex h-[inherit] items-center focus-visible:ring-offset-background data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg/50',\n 'shadow-2xs cursor-pointer rounded-full border-2 border-transparent transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n className,\n )}\n data-testid='spectral-switch'\n disabled={isDisabled}\n id={switchId}\n name={name}\n onCheckedChange={onChange}\n ref={ref}\n required={required}\n value={value}\n {...props}\n >\n <SwitchThumb className={cn(thumbBase, 'size-6.5 shadow-xs relative z-10 duration-200 ease-out data-[state=checked]:translate-x-[26px] motion-reduce:duration-0 data-[state=checked]:rtl:translate-x-[-26px]')} />\n </SwitchBase>\n <span className='ml-0.5 min-w-8 peer-data-[state=unchecked]:translate-x-6 peer-data-[state=unchecked]:rtl:-translate-x-6 motion-reduce:translate-x-0 pointer-events-none relative flex items-center justify-center text-center transition-transform duration-200 ease-out peer-data-[state=checked]:invisible motion-reduce:transition-none motion-reduce:duration-0'>\n <XIcon aria-hidden='true' className='size-4' />\n </span>\n <span className='min-w-8 motion-reduce:translate-x-0 pointer-events-none relative flex items-center justify-center text-center transition-transform duration-200 ease-out peer-data-[state=checked]:-translate-x-full peer-data-[state=checked]:text-background peer-data-[state=unchecked]:invisible motion-reduce:transition-none motion-reduce:duration-0 peer-data-[state=checked]:rtl:translate-x-full'>\n <CheckIcon aria-hidden='true' className='size-4' />\n </span>\n </div>\n ) : (\n <SwitchBase\n aria-required={required}\n aria-describedby={[messageId, ariaDescribedBy].filter(Boolean).join(' ') || undefined}\n aria-invalid={state === 'error' ? true : undefined}\n aria-label={ariaLabel ?? (hideLabel ? resolvedLabelText : undefined)}\n className={cn(\n isSquared\n ? 'peer h-6 w-10 rounded-sm focus-visible:ring-black inline-flex shrink-0 items-center border-2 border-transparent transition-colors outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg [&_span]:rounded-[4px]'\n : 'focus-visible:ring-ring peer h-6 w-10 shadow-2xs inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-switch-bg--checked data-[state=unchecked]:bg-switch-bg',\n className,\n )}\n data-testid='spectral-switch'\n disabled={isDisabled}\n id={switchId}\n name={name}\n onCheckedChange={onChange}\n ref={ref}\n required={required}\n value={value}\n {...props}\n >\n <SwitchThumb className={cn(thumbBase, isSquared ? 'size-5 shadow-xs data-[state=checked]:translate-x-4 data-[state=checked]:rtl:-translate-x-4' : 'h-5 w-5 shadow-lg data-[state=checked]:translate-x-4')} />\n </SwitchBase>\n )}\n\n {labelPosition === 'right' && !hideLabel && resolvedLabelText && (\n <Label className='ml-2' data-testid='spectral-switch-label-right' htmlFor={switchId} id={`${switchId}-label`}>\n {resolvedLabelText}\n </Label>\n )}\n\n {hideLabel && resolvedLabelText && (\n <Label className='sr-only' data-testid='spectral-switch-label-hidden' htmlFor={switchId}>\n {resolvedLabelText}\n </Label>\n )}\n <ErrorMessage\n dataTestId='spectral-switch-error-message'\n id={errorMessageId}\n message={state === 'error' ? (errorMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-switch-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? (warningMessage ?? null) : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n )\n}\nSwitch.displayName = 'Switch'\n"],"mappings":";;;;;;;;;;;AA8BA,MAAM,YAAY;AAElB,MAAa,UAAU,EACrB,WACA,UACA,cACA,YAAY,OACZ,IACA,OACA,gBAAgB,SAChB,WACA,sBAAsB,GACtB,sBAAsB,OACtB,MACA,UACA,KACA,UACA,QAAQ,WACR,OACA,SACA,gBACA,oBAAoB,iBACpB,cAAc,WACd,GAAG,YACc;CACjB,MAAM,WAAW,eAAe,IAAI,KAAI;CACxC,MAAM,aAAa,QAAQ,SAAQ;CACnC,MAAM,oBAAoB,SAAS;CACnC,MAAM,iBAAiB,kBAAkB,SAAQ;CACjD,MAAM,mBAAmB,oBAAoB,SAA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Aa,qBAC1C,oBAAC,OAAD;IAAO,WAAU;IAAiD,SAAS;IAAU,IAAI,GAAG,SAAS;cAClG;IACI;GAGR,aAAa,qBACZ,oBAAC,OAAD;IAAO,WAAU;IAAqD,SAAS;cAC5E;IACI;GAET,oBAAC,cAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,UAAW,gBAAgB,OAAQ;IACjC;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACD,oBAAC,gBAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,YAAa,kBAAkB,OAAQ;IACrC;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACE;;;AAGT,OAAO,cAAc"}
@@ -8,12 +8,12 @@ type TextareaState = FormFieldState;
8
8
  type TextareaProps = Omit<ComponentProps<'textarea'>, 'onChange'> & {
9
9
  className?: string | undefined;
10
10
  errorMessage?: BaseFormFieldProps['errorMessage'];
11
+ hideCounter?: boolean;
11
12
  id?: string | undefined;
12
13
  label: string;
13
14
  labelClassName?: string;
14
- maxLength?: number | undefined; /** Controls visibility of the bottom-right character counter (default: true). */
15
- showCounter?: boolean; /** Number of message lines to reserve (default: 1). */
16
- messageReserveLines?: number; /** Whether to keep message space reserved when hidden (default: false). */
15
+ maxLength?: number | undefined;
16
+ messageReserveLines?: number;
17
17
  messageReserveSpace?: boolean;
18
18
  name: string;
19
19
  onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.d.ts","names":[],"sources":["../src/components/Textarea/Textarea.tsx"],"mappings":";;;;;;KAQY,aAAA,GAAgB,cAAA;AAAA,KAIhB,aAAA,GAAgB,IAAA,CAAK,cAAA;EAC/B,SAAA;EACA,YAAA,GAAe,kBAAA;EACf,EAAA;EACA,KAAA;EACA,cAAA;EACA,SAAA,uBANU;EAQV,WAAA;EAEA,mBAAA,WAV0B;EAY1B,mBAAA;EACA,IAAA;EACA,MAAA,IAAU,CAAA,EAAG,UAAA,CAAW,mBAAA;EACxB,QAAA,IAAY,KAAA;EACZ,OAAA,IAAW,CAAA,EAAG,UAAA,CAAW,mBAAA;EACzB,WAAA;EACA,QAAA;EACA,KAAA,GAAQ,aAAA;EACR,KAAA;EACA,cAAA,GAAiB,kBAAA;AAAA;AAAA,0BAiBjB,QAAA,EAAU,aAAA;EACR,GAAA,GAAM,GAAA,CAAI,mBAAA;AAAA,IACX,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
1
+ {"version":3,"file":"Textarea.d.ts","names":[],"sources":["../src/components/Textarea/Textarea.tsx"],"mappings":";;;;;;KAQY,aAAA,GAAgB,cAAA;AAAA,KAIhB,aAAA,GAAgB,IAAA,CAAK,cAAA;EAC/B,SAAA;EACA,YAAA,GAAe,kBAAA;EACf,WAAA;EACA,EAAA;EACA,KAAA;EACA,cAAA;EACA,SAAA;EACA,mBAAA;EACA,mBAAA;EACA,IAAA;EACA,MAAA,IAAU,CAAA,EAAG,UAAA,CAAW,mBAAA;EACxB,QAAA,IAAY,KAAA;EACZ,OAAA,IAAW,CAAA,EAAG,UAAA,CAAW,mBAAA;EACzB,WAAA;EACA,QAAA;EACA,KAAA,GAAQ,aAAA;EACR,KAAA;EACA,cAAA,GAAiB,kBAAA;AAAA;AAAA,0BAiBjB,QAAA,EAAU,aAAA;EACR,GAAA,GAAM,GAAA,CAAI,mBAAA;AAAA,IACX,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA"}
package/dist/Textarea.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { LoaderIcon } from "./Icons/LoaderIcon.js";
3
3
  import { cn } from "./utils/twUtils.js";
4
4
  import { ErrorMessage, WarningMessage } from "./FormFieldMessage.js";
5
- import { getAriaProps, getErrorMessageId, getTextareaClasses, useFormFieldId, useFormFieldState } from "./utils/formFieldUtils.js";
5
+ import { getAriaProps, getErrorMessageId, getPasswordManagerIgnoreProps, getTextareaClasses, useFormFieldId, useFormFieldState } from "./utils/formFieldUtils.js";
6
6
  import { useUncontrolledState } from "./hooks/useUncontrolledState.js";
7
7
  import { Label } from "./Label.js";
8
8
  import { useTextarea } from "./Textarea/TextareaUtils.js";
@@ -19,7 +19,7 @@ const getCounterClasses = (currentLength, maxLength) => {
19
19
  return cn("absolute bottom-2 right-3 text-xs pointer-events-none z-10 tabular-nums", currentLength >= maxLength ? "text-danger-400" : "text-text-secondary");
20
20
  };
21
21
  const Textarea = (allProps) => {
22
- const { ref, autoComplete, className, defaultValue, disabled, errorMessage, id, label, labelClassName, maxLength = 280, messageReserveLines = 1, messageReserveSpace = false, name, onBlur, onChange, onFocus, placeholder, required, showCounter = true, state = "default", value: valueProp, warningMessage, ...props } = allProps;
22
+ const { ref, autoComplete, className, defaultValue, disabled, errorMessage, hideCounter = false, id, label, labelClassName, maxLength = 280, messageReserveLines = 1, messageReserveSpace = false, name, onBlur, onChange, onFocus, placeholder, required, state = "default", value: valueProp, warningMessage, ...props } = allProps;
23
23
  const textareaId = useFormFieldId(id, name);
24
24
  const errorMessageId = getErrorMessageId(textareaId);
25
25
  const warningMessageId = `${textareaId}-warning`;
@@ -76,6 +76,7 @@ const Textarea = (allProps) => {
76
76
  spellCheck: "true",
77
77
  style: getCSSCustomProperties(),
78
78
  value,
79
+ ...getPasswordManagerIgnoreProps(),
79
80
  ...ariaProps,
80
81
  ...props
81
82
  }),
@@ -83,7 +84,7 @@ const Textarea = (allProps) => {
83
84
  className: LOADING_ICON_CLASSES,
84
85
  children: /* @__PURE__ */ jsx(LoaderIcon, { size: 24 })
85
86
  }),
86
- showCounter && /* @__PURE__ */ jsxs("div", {
87
+ !hideCounter && /* @__PURE__ */ jsxs("div", {
87
88
  "aria-label": currentLength + " of " + maxLength + " characters used",
88
89
  "aria-live": "polite",
89
90
  className: getCounterClasses(currentLength, maxLength),
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","names":[],"sources":["../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import { LoaderIcon } from '@components/Icons'\nimport { Label } from '@components/Label/Label'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { ErrorMessage, getAriaProps, getErrorMessageId, getTextareaClasses, useFormFieldId, useFormFieldState, WarningMessage, type BaseFormFieldProps, type FormFieldState } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useRef, type ComponentProps, type CSSProperties, type FocusEvent, type Ref } from 'react'\nimport { useTextarea } from './TextareaUtils'\n\nexport type TextareaState = FormFieldState\n\ntype AutoCompleteValue = 'on' | 'off' | 'name' | 'email' | 'username' | 'street-address' | (string & {})\n\nexport type TextareaProps = Omit<ComponentProps<'textarea'>, 'onChange'> & {\n className?: string | undefined\n errorMessage?: BaseFormFieldProps['errorMessage']\n id?: string | undefined\n label: string\n labelClassName?: string\n maxLength?: number | undefined\n /** Controls visibility of the bottom-right character counter (default: true). */\n showCounter?: boolean\n /** Number of message lines to reserve (default: 1). */\n messageReserveLines?: number\n /** Whether to keep message space reserved when hidden (default: false). */\n messageReserveSpace?: boolean\n name: string\n onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void\n onChange?: (value: string) => void\n onFocus?: (e: FocusEvent<HTMLTextAreaElement>) => void\n placeholder?: string | undefined\n required?: boolean\n state?: TextareaState\n value?: string | undefined\n warningMessage?: BaseFormFieldProps['errorMessage']\n}\n\nconst LOADING_ICON_CLASSES = 'absolute right-4 top-4'\n\nconst getAutoCompleteValue = (autoComplete?: string): AutoCompleteValue => {\n if (autoComplete) return autoComplete\n return 'off'\n}\n\nconst getCounterClasses = (currentLength: number, maxLength: number): string => {\n const baseClasses = 'absolute bottom-2 right-3 text-xs pointer-events-none z-10 tabular-nums'\n const colorClass = currentLength >= maxLength ? 'text-danger-400' : 'text-text-secondary'\n return cn(baseClasses, colorClass)\n}\n\nexport const Textarea = (\n allProps: TextareaProps & {\n ref?: Ref<HTMLTextAreaElement>\n },\n) => {\n const {\n ref,\n autoComplete,\n className,\n defaultValue,\n disabled,\n errorMessage,\n id,\n label,\n labelClassName,\n maxLength = 280,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n required,\n showCounter = true,\n state = 'default',\n value: valueProp,\n warningMessage,\n ...props\n } = allProps\n const textareaId = useFormFieldId(id, name)\n const errorMessageId = getErrorMessageId(textareaId)\n const warningMessageId = `${textareaId}-warning`\n const messageId = state === 'error' ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const internalRef = useRef<HTMLTextAreaElement>(null)\n const textareaRef = ref ?? internalRef\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 { handleFocus, handleBlur, handleChange, handlePaste } = useTextarea({\n maxLength,\n value,\n onChange: setValue,\n onFocus,\n onBlur,\n })\n\n const { isDisabled, isLoading } = useFormFieldState(disabled, state)\n const ariaProps = getAriaProps(state, props['aria-describedby'], required, messageId)\n const currentLength = value?.length || 0\n const textareaClasses = getTextareaClasses(state, className)\n\n const getCSSCustomProperties = () => ({\n '--textarea-min-height': '6rem',\n '--textarea-max-height': '12rem',\n '--textarea-border-radius': '0.5rem',\n })\n\n return (\n <div className='w-full'>\n {label && (\n <Label\n data-testid='spectral-textarea-label'\n htmlFor={textareaId}\n className={cn('mb-2 block', isDisabled && 'cursor-not-allowed opacity-50', labelClassName)}\n >\n {label}\n </Label>\n )}\n <div className='relative'>\n <textarea\n aria-multiline='true'\n autoComplete={getAutoCompleteValue(autoComplete)}\n className={textareaClasses}\n data-state={state}\n data-testid='spectral-textarea'\n disabled={isDisabled}\n id={textareaId}\n name={name}\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n onPaste={handlePaste}\n placeholder={placeholder}\n ref={textareaRef}\n required={required}\n spellCheck='true'\n style={getCSSCustomProperties() as CSSProperties}\n value={value}\n {...ariaProps}\n {...props}\n />\n\n {isLoading && (\n <div className={LOADING_ICON_CLASSES} data-testid='spectral-textarea-loading-icon'>\n <LoaderIcon size={24} />\n </div>\n )}\n\n {showCounter && (\n <div\n // oxlint will throw an error when passing ternaries in for aria-label\n aria-label={currentLength + ' of ' + maxLength + ' characters used'}\n aria-live='polite'\n className={getCounterClasses(currentLength, maxLength)}\n data-testid='spectral-textarea-counter'\n role='status'\n >\n {currentLength}/{maxLength}\n </div>\n )}\n </div>\n\n <ErrorMessage\n dataTestId='spectral-textarea-error-message'\n id={errorMessageId}\n message={state === 'error' ? errorMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-textarea-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? warningMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n )\n}\nTextarea.displayName = 'Textarea'\n"],"mappings":";;;;;;;;;;;;AAoCA,MAAM,uBAAuB;AAE7B,MAAM,wBAAwB,iBAA6C;AACzE,KAAI,aAAc,QAAO;AACzB,QAAO;;AAGT,MAAM,qBAAqB,eAAuB,cAA8B;AAG9E,QAAO,GAAG,2EADS,iBAAiB,YAAY,oBAAoB,sBACnC;;AAGnC,MAAa,YACX,aAGG;CACH,MAAM,EACJ,KACA,cACA,WACA,cACA,UACA,cACA,IACA,OACA,gBACA,YAAY,KACZ,sBAAsB,GACtB,sBAAsB,OACtB,MACA,QACA,UACA,SACA,aACA,UACA,cAAc,MACd,QAAQ,WACR,OAAO,WACP,gBACA,GAAG,UACD;CACJ,MAAM,aAAa,eAAe,IAAI,KAAI;CAC1C,MAAM,iBAAiB,kBAAkB,WAAU;CACnD,MAAM,mBAAmB,GAAG,WAAW;CACvC,MAAM,YAAY,UAAU,UAAU,iBAAiB,UAAU,aAAa,iBAAiB,mBAAmB;CAClH,MAAM,cAAc,OAA4B,KAAI;CACpD,MAAM,cAAc,OAAO;CAE3B,MAAM,CAAC,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AAC,gBAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,YAAY,iBAAiB;IAC3B;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACE;;;AAGT,SAAS,cAAc"}
1
+ {"version":3,"file":"Textarea.js","names":[],"sources":["../src/components/Textarea/Textarea.tsx"],"sourcesContent":["import { LoaderIcon } from '@components/Icons'\nimport { Label } from '@components/Label/Label'\nimport { useUncontrolledState } from '@hooks/useUncontrolledState'\nimport { ErrorMessage, getAriaProps, getErrorMessageId, getPasswordManagerIgnoreProps, getTextareaClasses, useFormFieldId, useFormFieldState, WarningMessage, type BaseFormFieldProps, type FormFieldState } from '@utils/formFieldUtils'\nimport { cn } from '@utils/twUtils'\nimport { useRef, type ComponentProps, type CSSProperties, type FocusEvent, type Ref } from 'react'\nimport { useTextarea } from './TextareaUtils'\n\nexport type TextareaState = FormFieldState\n\ntype AutoCompleteValue = 'on' | 'off' | 'name' | 'email' | 'username' | 'street-address' | (string & {})\n\nexport type TextareaProps = Omit<ComponentProps<'textarea'>, 'onChange'> & {\n className?: string | undefined\n errorMessage?: BaseFormFieldProps['errorMessage']\n hideCounter?: boolean\n id?: string | undefined\n label: string\n labelClassName?: string\n maxLength?: number | undefined\n messageReserveLines?: number\n messageReserveSpace?: boolean\n name: string\n onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void\n onChange?: (value: string) => void\n onFocus?: (e: FocusEvent<HTMLTextAreaElement>) => void\n placeholder?: string | undefined\n required?: boolean\n state?: TextareaState\n value?: string | undefined\n warningMessage?: BaseFormFieldProps['errorMessage']\n}\n\nconst LOADING_ICON_CLASSES = 'absolute right-4 top-4'\n\nconst getAutoCompleteValue = (autoComplete?: string): AutoCompleteValue => {\n if (autoComplete) return autoComplete\n return 'off'\n}\n\nconst getCounterClasses = (currentLength: number, maxLength: number): string => {\n const baseClasses = 'absolute bottom-2 right-3 text-xs pointer-events-none z-10 tabular-nums'\n const colorClass = currentLength >= maxLength ? 'text-danger-400' : 'text-text-secondary'\n return cn(baseClasses, colorClass)\n}\n\nexport const Textarea = (\n allProps: TextareaProps & {\n ref?: Ref<HTMLTextAreaElement>\n },\n) => {\n const {\n ref,\n autoComplete,\n className,\n defaultValue,\n disabled,\n errorMessage,\n hideCounter = false,\n id,\n label,\n labelClassName,\n maxLength = 280,\n messageReserveLines = 1,\n messageReserveSpace = false,\n name,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n required,\n state = 'default',\n value: valueProp,\n warningMessage,\n ...props\n } = allProps\n const textareaId = useFormFieldId(id, name)\n const errorMessageId = getErrorMessageId(textareaId)\n const warningMessageId = `${textareaId}-warning`\n const messageId = state === 'error' ? errorMessageId : state === 'warning' && warningMessage ? warningMessageId : undefined\n const internalRef = useRef<HTMLTextAreaElement>(null)\n const textareaRef = ref ?? internalRef\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 { handleFocus, handleBlur, handleChange, handlePaste } = useTextarea({\n maxLength,\n value,\n onChange: setValue,\n onFocus,\n onBlur,\n })\n\n const { isDisabled, isLoading } = useFormFieldState(disabled, state)\n const ariaProps = getAriaProps(state, props['aria-describedby'], required, messageId)\n const currentLength = value?.length || 0\n const textareaClasses = getTextareaClasses(state, className)\n\n const getCSSCustomProperties = () => ({\n '--textarea-min-height': '6rem',\n '--textarea-max-height': '12rem',\n '--textarea-border-radius': '0.5rem',\n })\n\n return (\n <div className='w-full'>\n {label && (\n <Label\n data-testid='spectral-textarea-label'\n htmlFor={textareaId}\n className={cn('mb-2 block', isDisabled && 'cursor-not-allowed opacity-50', labelClassName)}\n >\n {label}\n </Label>\n )}\n <div className='relative'>\n <textarea\n aria-multiline='true'\n autoComplete={getAutoCompleteValue(autoComplete)}\n className={textareaClasses}\n data-state={state}\n data-testid='spectral-textarea'\n disabled={isDisabled}\n id={textareaId}\n name={name}\n onBlur={handleBlur}\n onChange={handleChange}\n onFocus={handleFocus}\n onPaste={handlePaste}\n placeholder={placeholder}\n ref={textareaRef}\n required={required}\n spellCheck='true'\n style={getCSSCustomProperties() as CSSProperties}\n value={value}\n {...getPasswordManagerIgnoreProps()}\n {...ariaProps}\n {...props}\n />\n\n {isLoading && (\n <div className={LOADING_ICON_CLASSES} data-testid='spectral-textarea-loading-icon'>\n <LoaderIcon size={24} />\n </div>\n )}\n\n {!hideCounter && (\n <div\n // oxlint will throw an error when passing ternaries in for aria-label\n aria-label={currentLength + ' of ' + maxLength + ' characters used'}\n aria-live='polite'\n className={getCounterClasses(currentLength, maxLength)}\n data-testid='spectral-textarea-counter'\n role='status'\n >\n {currentLength}/{maxLength}\n </div>\n )}\n </div>\n <ErrorMessage\n dataTestId='spectral-textarea-error-message'\n id={errorMessageId}\n message={state === 'error' ? errorMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'error'}\n />\n <WarningMessage\n dataTestId='spectral-textarea-warning-message'\n id={warningMessageId}\n message={state === 'warning' ? warningMessage : null}\n messageReserveLines={messageReserveLines}\n messageReserveSpace={messageReserveSpace && state === 'warning'}\n />\n </div>\n )\n}\nTextarea.displayName = 'Textarea'\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,uBAAuB;AAE7B,MAAM,wBAAwB,iBAA6C;AACzE,KAAI,aAAc,QAAO;AACzB,QAAO;;AAGT,MAAM,qBAAqB,eAAuB,cAA8B;AAG9E,QAAO,GAAG,2EADS,iBAAiB,YAAY,oBAAoB,sBACnC;;AAGnC,MAAa,YACX,aAGG;CACH,MAAM,EACJ,KACA,cACA,WACA,cACA,UACA,cACA,cAAc,OACd,IACA,OACA,gBACA,YAAY,KACZ,sBAAsB,GACtB,sBAAsB,OACtB,MACA,QACA,UACA,SACA,aACA,UACA,QAAQ,WACR,OAAO,WACP,gBACA,GAAG,UACD;CACJ,MAAM,aAAa,eAAe,IAAI,KAA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AAY,gBAAgB,SAAS,YAAY;MACjD,aAAU;MACV,WAAW,kBAAkB,eAAe,UAAU;MAEtD,MAAK;gBANP;OAQG;OAAc;OAAE;OACd;;KAEJ;;GACL,oBAAC,cAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,UAAU,eAAe;IACvB;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACD,oBAAC,gBAAD;IACE,YAAW;IACX,IAAI;IACJ,SAAS,UAAU,YAAY,iBAAiB;IAC3B;IACrB,qBAAqB,uBAAuB,UAAU;IACvD;GACE;;;AAGT,SAAS,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"input.d.ts","names":[],"sources":["../../src/primitives/input.tsx"],"mappings":";;;;;KAGY,SAAA;AAAA,UAEK,UAAA,SAAmB,cAAA;EAClC,SAAA;EACA,IAAA,GAAO,SAAA;AAAA;AAAA,cAGI,KAAA;EAAK,SAAA;EAAA,IAAA;EAAA,GAAA;AAAA,GAAmC,UAAA,KAAU,oBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"input.d.ts","names":[],"sources":["../../src/primitives/input.tsx"],"mappings":";;;;;KAIY,SAAA;AAAA,UAEK,UAAA,SAAmB,cAAA;EAClC,SAAA;EACA,IAAA,GAAO,SAAA;AAAA;AAAA,cAGI,KAAA;EAAK,SAAA;EAAA,IAAA;EAAA,GAAA;AAAA,GAAmC,UAAA,KAAU,oBAAA,CAAA,GAAA,CAAA,OAAA"}