@fanvue/ui 3.39.0 → 3.40.1

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 (50) hide show
  1. package/dist/cjs/components/Checkbox/Checkbox.cjs +1 -1
  2. package/dist/cjs/components/Checkbox/Checkbox.cjs.map +1 -1
  3. package/dist/cjs/components/Chip/Chip.cjs +2 -2
  4. package/dist/cjs/components/Chip/Chip.cjs.map +1 -1
  5. package/dist/cjs/components/Dialog/Dialog.cjs +12 -1
  6. package/dist/cjs/components/Dialog/Dialog.cjs.map +1 -1
  7. package/dist/cjs/components/Drawer/Drawer.cjs +12 -3
  8. package/dist/cjs/components/Drawer/Drawer.cjs.map +1 -1
  9. package/dist/cjs/components/DropdownMenu/DropdownMenuHeader.cjs +8 -2
  10. package/dist/cjs/components/DropdownMenu/DropdownMenuHeader.cjs.map +1 -1
  11. package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs +1 -1
  12. package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs.map +1 -1
  13. package/dist/cjs/components/DropdownMenu/DropdownMenuReorderItem.cjs +2 -2
  14. package/dist/cjs/components/DropdownMenu/DropdownMenuReorderItem.cjs.map +1 -1
  15. package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs +6 -4
  16. package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs.map +1 -1
  17. package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs +4 -3
  18. package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs.map +1 -1
  19. package/dist/cjs/components/SearchField/SearchField.cjs +5 -1
  20. package/dist/cjs/components/SearchField/SearchField.cjs.map +1 -1
  21. package/dist/cjs/components/TextField/TextField.cjs +16 -3
  22. package/dist/cjs/components/TextField/TextField.cjs.map +1 -1
  23. package/dist/cjs/utils/useDragToDismiss.cjs +145 -0
  24. package/dist/cjs/utils/useDragToDismiss.cjs.map +1 -0
  25. package/dist/components/Checkbox/Checkbox.mjs +1 -1
  26. package/dist/components/Checkbox/Checkbox.mjs.map +1 -1
  27. package/dist/components/Chip/Chip.mjs +2 -2
  28. package/dist/components/Chip/Chip.mjs.map +1 -1
  29. package/dist/components/Dialog/Dialog.mjs +12 -1
  30. package/dist/components/Dialog/Dialog.mjs.map +1 -1
  31. package/dist/components/Drawer/Drawer.mjs +12 -3
  32. package/dist/components/Drawer/Drawer.mjs.map +1 -1
  33. package/dist/components/DropdownMenu/DropdownMenuHeader.mjs +8 -2
  34. package/dist/components/DropdownMenu/DropdownMenuHeader.mjs.map +1 -1
  35. package/dist/components/DropdownMenu/DropdownMenuItem.mjs +1 -1
  36. package/dist/components/DropdownMenu/DropdownMenuItem.mjs.map +1 -1
  37. package/dist/components/DropdownMenu/DropdownMenuReorderItem.mjs +2 -2
  38. package/dist/components/DropdownMenu/DropdownMenuReorderItem.mjs.map +1 -1
  39. package/dist/components/DropdownMenu/DropdownMenuRoot.mjs +6 -4
  40. package/dist/components/DropdownMenu/DropdownMenuRoot.mjs.map +1 -1
  41. package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs +4 -3
  42. package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs.map +1 -1
  43. package/dist/components/SearchField/SearchField.mjs +5 -1
  44. package/dist/components/SearchField/SearchField.mjs.map +1 -1
  45. package/dist/components/TextField/TextField.mjs +16 -3
  46. package/dist/components/TextField/TextField.mjs.map +1 -1
  47. package/dist/index.d.ts +3 -1
  48. package/dist/utils/useDragToDismiss.mjs +128 -0
  49. package/dist/utils/useDragToDismiss.mjs.map +1 -0
  50. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"TextField.mjs","sources":["../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { CheckOutlineIcon } from \"@/index\";\nimport { cn } from \"../../utils/cn\";\n\n/** Text field height in pixels. */\nexport type TextFieldSize = \"48\" | \"40\" | \"32\";\n\nexport interface TextFieldProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"size\" | \"prefix\"> {\n /** Label text displayed above the input. Also used as the accessible name. */\n label?: string;\n /** Helper text displayed below the input. Replaced by `errorMessage` when `error` is `true`. */\n helperText?: string;\n /** Height of the text field in pixels. @default \"48\" */\n size?: TextFieldSize;\n /** Whether the text field is in an error state. @default false */\n error?: boolean;\n /** Error message displayed below the input. Shown instead of `helperText` when `error` is `true`. */\n errorMessage?: string;\n /** Whether the text field is validated. @default false */\n validated?: boolean;\n /** Icon element displayed at the left side of the input. */\n leftIcon?: React.ReactNode;\n /** Icon element displayed at the right side of the input. */\n rightIcon?: React.ReactNode;\n /** Fixed, non-editable label pinned inside the left edge of the field — for a prefix such as a currency symbol or country code. */\n leftLabel?: React.ReactNode;\n /** Fixed, non-editable label pinned inside the right edge of the field — for a unit or suffix such as a currency code or domain. */\n rightLabel?: React.ReactNode;\n /**\n * Trailing interactive element pinned to the right edge — typically a `Chip`\n * or `Button` (the \"with button\" field type). Reduces the right padding so the\n * control sits flush, and clicks on it do not steal focus from the input.\n */\n action?: React.ReactNode;\n /** Whether the text field stretches to fill its container width. @default false */\n fullWidth?: boolean;\n}\n\nconst CONTAINER_HEIGHT: Record<TextFieldSize, string> = {\n \"48\": \"h-12\",\n \"40\": \"h-10\",\n \"32\": \"h-8\",\n};\n\nconst CONTAINER_PADDING_X: Record<TextFieldSize, string> = {\n \"48\": \"px-4\",\n \"40\": \"px-4\",\n \"32\": \"px-3\",\n};\n\nconst CONTAINER_PADDING_X_WITH_ACTION: Record<TextFieldSize, string> = {\n \"48\": \"pl-4 pr-2\",\n \"40\": \"pl-4 pr-2\",\n \"32\": \"pl-3 pr-2\",\n};\n\nconst CONTAINER_GAP: Record<TextFieldSize, string> = {\n \"48\": \"gap-2.5\",\n \"40\": \"gap-2.5\",\n \"32\": \"gap-2\",\n};\n\nconst INPUT_TYPOGRAPHY: Record<TextFieldSize, string> = {\n \"48\": \"typography-body-default-16px-regular autofill-body-lg\",\n \"40\": \"typography-body-default-16px-regular autofill-body-lg\",\n \"32\": \"typography-body-small-14px-regular autofill-body-md\",\n};\n\nconst SIDE_LABEL_TYPOGRAPHY: Record<TextFieldSize, string> = {\n \"48\": \"typography-body-default-16px-regular\",\n \"40\": \"typography-body-default-16px-regular\",\n \"32\": \"typography-body-small-14px-regular\",\n};\n\nfunction getContainerClassName(\n size: TextFieldSize,\n error: boolean,\n disabled?: boolean,\n hasAction?: boolean,\n) {\n return cn(\n \"relative flex items-center overflow-hidden rounded-sm border bg-inputs-inputs-primary after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] has-focus-visible:outline-none has-focus-visible:after:shadow-focus-ring motion-safe:transition-colors\",\n hasAction ? CONTAINER_PADDING_X_WITH_ACTION[size] : CONTAINER_PADDING_X[size],\n CONTAINER_GAP[size],\n error ? \"border-error-content\" : \"border-border-primary\",\n !disabled && !error && \"hover:border-neutral-alphas-400\",\n CONTAINER_HEIGHT[size],\n disabled && \"opacity-50\",\n );\n}\n\nfunction LeadingIcon({ children }: { children?: React.ReactNode }) {\n if (!children) return null;\n return (\n <span className=\"pointer-events-none flex size-4 shrink-0 items-center justify-center text-content-secondary\">\n {children}\n </span>\n );\n}\n\nfunction SideLabel({\n id,\n size,\n align,\n children,\n}: {\n id?: string;\n size: TextFieldSize;\n align: \"left\" | \"right\";\n children?: React.ReactNode;\n}) {\n if (!children) return null;\n return (\n <span\n id={id}\n className={cn(\n \"shrink-0 select-none whitespace-nowrap text-content-tertiary\",\n align === \"right\" && \"text-right\",\n SIDE_LABEL_TYPOGRAPHY[size],\n )}\n >\n {children}\n </span>\n );\n}\n\nfunction TrailingAdornment({\n rightIcon,\n validated,\n}: {\n rightIcon?: React.ReactNode;\n validated: boolean;\n}) {\n if (!rightIcon && !validated) return null;\n return (\n <span className=\"flex shrink-0 items-center gap-2 text-content-secondary\">\n {rightIcon && (\n <span data-tf-interactive=\"\" className=\"flex size-4 shrink-0 items-center justify-center\">\n {rightIcon}\n </span>\n )}\n {validated && (\n <span className=\"pointer-events-none flex size-4 shrink-0 items-center justify-center\">\n <CheckOutlineIcon className=\"text-success-content\" />\n </span>\n )}\n </span>\n );\n}\n\nfunction TextFieldHelperText({\n id,\n error,\n children,\n}: {\n id: string;\n error: boolean;\n children: React.ReactNode;\n}) {\n return (\n <p\n id={id}\n className={cn(\n \"typography-description-12px-regular pt-2\",\n error ? \"text-error-content\" : \"text-content-tertiary\",\n )}\n >\n {children}\n </p>\n );\n}\n\nfunction warnMissingAccessibleName(label?: string, ariaLabel?: string, ariaLabelledBy?: string) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn(\n \"TextField: no accessible name provided. Pass a `label`, `aria-label`, or `aria-labelledby` prop.\",\n );\n }\n }\n}\n\n/**\n * A text input field with optional label, helper/error text, icon slots, and side labels.\n *\n * Use `leftLabel` / `rightLabel` for fixed unit or prefix affordances (currency symbol,\n * country code, domain suffix). Provide at least one of `label`, `aria-label`, or\n * `aria-labelledby` for accessibility — a console warning is emitted in development if none are set.\n *\n * @example\n * ```tsx\n * <TextField\n * label=\"Email\"\n * placeholder=\"you@example.com\"\n * error={!!emailError}\n * errorMessage={emailError}\n * />\n * ```\n *\n * @example\n * ```tsx\n * <TextField label=\"Price\" leftLabel=\"$\" rightLabel=\"USD\" placeholder=\"0.00\" />\n * ```\n *\n * @example\n * ```tsx\n * <TextField\n * label=\"Promo code\"\n * placeholder=\"Enter code\"\n * action={<Chip size=\"32\" onClick={apply}>Apply</Chip>}\n * />\n * ```\n */\nexport const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(\n (\n {\n label,\n helperText,\n size = \"48\",\n error = false,\n errorMessage,\n validated = false,\n leftIcon,\n rightIcon,\n leftLabel,\n rightLabel,\n action,\n className,\n id,\n disabled,\n fullWidth = false,\n ...props\n },\n ref,\n ) => {\n const generatedId = React.useId();\n const inputId = id || generatedId;\n const helperTextId = `${inputId}-helper`;\n const leftLabelId = `${inputId}-left-label`;\n const rightLabelId = `${inputId}-right-label`;\n const bottomText = error && errorMessage ? errorMessage : helperText;\n\n const describedBy =\n [\n leftLabel != null ? leftLabelId : null,\n rightLabel != null ? rightLabelId : null,\n bottomText ? helperTextId : null,\n ]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n const innerRef = React.useRef<HTMLInputElement>(null);\n const setRefs = React.useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLInputElement | null>).current = node;\n },\n [ref],\n );\n\n // Keep clicks on the non-interactive adornments (icons, side labels, padding)\n // focusing the input, matching the old absolute/pointer-events-none layout.\n const handleContainerMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) return;\n const target = event.target as HTMLElement;\n if (target === innerRef.current) return;\n if (target.closest(\"[data-tf-interactive]\")) return;\n event.preventDefault();\n innerRef.current?.focus();\n };\n\n warnMissingAccessibleName(label, props[\"aria-label\"], props[\"aria-labelledby\"]);\n\n return (\n <div\n className={cn(\"flex flex-col\", fullWidth && \"w-full\", className)}\n data-disabled={disabled ? \"\" : undefined}\n data-error={error ? \"\" : undefined}\n >\n {label && (\n <label\n htmlFor={inputId}\n className=\"typography-description-12px-semibold pb-2 text-content-primary\"\n >\n {label}\n </label>\n )}\n\n {/* biome-ignore lint/a11y/noStaticElementInteractions: focus bridge delegates pointer clicks on adornments to the input */}\n <div\n className={getContainerClassName(size, error, disabled, action != null)}\n onMouseDown={handleContainerMouseDown}\n >\n <LeadingIcon>{leftIcon}</LeadingIcon>\n <SideLabel id={leftLabelId} size={size} align=\"left\">\n {leftLabel}\n </SideLabel>\n\n <input\n ref={setRefs}\n id={inputId}\n disabled={disabled}\n aria-describedby={describedBy}\n aria-invalid={error || undefined}\n className={cn(\n \"h-full min-w-0 flex-1 bg-transparent text-content-primary no-underline placeholder:text-content-tertiary focus:outline-none disabled:cursor-not-allowed\",\n INPUT_TYPOGRAPHY[size],\n \"[&[type='search']::-webkit-search-cancel-button]:hidden [&[type='search']::-webkit-search-cancel-button]:appearance-none\",\n )}\n {...props}\n />\n\n <SideLabel id={rightLabelId} size={size} align=\"right\">\n {rightLabel}\n </SideLabel>\n <TrailingAdornment rightIcon={rightIcon} validated={validated} />\n {action != null && (\n <span data-tf-interactive=\"\" className=\"flex shrink-0 items-center\">\n {action}\n </span>\n )}\n </div>\n\n {bottomText && (\n <TextFieldHelperText id={helperTextId} error={error}>\n {bottomText}\n </TextFieldHelperText>\n )}\n </div>\n );\n },\n);\n\nTextField.displayName = \"TextField\";\n"],"names":[],"mappings":";;;;;;AAuCA,MAAM,mBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,sBAAqD;AAAA,EACzD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,kCAAiE;AAAA,EACrE,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,gBAA+C;AAAA,EACnD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,wBAAuD;AAAA,EAC3D,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,sBACP,MACA,OACA,UACA,WACA;AACA,SAAO;AAAA,IACL;AAAA,IACA,YAAY,gCAAgC,IAAI,IAAI,oBAAoB,IAAI;AAAA,IAC5E,cAAc,IAAI;AAAA,IAClB,QAAQ,yBAAyB;AAAA,IACjC,CAAC,YAAY,CAAC,SAAS;AAAA,IACvB,iBAAiB,IAAI;AAAA,IACrB,YAAY;AAAA,EAAA;AAEhB;AAEA,SAAS,YAAY,EAAE,YAA4C;AACjE,MAAI,CAAC,SAAU,QAAO;AACtB,SACE,oBAAC,QAAA,EAAK,WAAU,+FACb,SAAA,CACH;AAEJ;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A,cACC,WAAW,sBAAsB,MAAM,OAAO,UAAU,UAAU,IAAI;AAAA,cACtE,aAAa;AAAA,cAEb,UAAA;AAAA,gBAAA,oBAAC,eAAa,UAAA,SAAA,CAAS;AAAA,oCACtB,WAAA,EAAU,IAAI,aAAa,MAAY,OAAM,QAC3C,UAAA,WACH;AAAA,gBAEA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,KAAK;AAAA,oBACL,IAAI;AAAA,oBACJ;AAAA,oBACA,oBAAkB;AAAA,oBAClB,gBAAc,SAAS;AAAA,oBACvB,WAAW;AAAA,sBACT;AAAA,sBACA,iBAAiB,IAAI;AAAA,sBACrB;AAAA,oBAAA;AAAA,oBAED,GAAG;AAAA,kBAAA;AAAA,gBAAA;AAAA,oCAGL,WAAA,EAAU,IAAI,cAAc,MAAY,OAAM,SAC5C,UAAA,YACH;AAAA,gBACA,oBAAC,mBAAA,EAAkB,WAAsB,UAAA,CAAsB;AAAA,gBAC9D,UAAU,QACT,oBAAC,QAAA,EAAK,uBAAoB,IAAG,WAAU,8BACpC,UAAA,OAAA,CACH;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,UAIH,cACC,oBAAC,qBAAA,EAAoB,IAAI,cAAc,OACpC,UAAA,WAAA,CACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,UAAU,cAAc;"}
1
+ {"version":3,"file":"TextField.mjs","sources":["../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { CheckOutlineIcon } from \"@/index\";\nimport { cn } from \"../../utils/cn\";\n\n/** Text field height in pixels. */\nexport type TextFieldSize = \"48\" | \"40\" | \"32\";\n\nexport interface TextFieldProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"size\" | \"prefix\"> {\n /** Label text displayed above the input. Also used as the accessible name. */\n label?: string;\n /** Helper text displayed below the input. Replaced by `errorMessage` when `error` is `true`. */\n helperText?: string;\n /** Height of the text field in pixels. @default \"48\" */\n size?: TextFieldSize;\n /** Whether the text field is in an error state. @default false */\n error?: boolean;\n /** Error message displayed below the input. Shown instead of `helperText` when `error` is `true`. */\n errorMessage?: string;\n /** Whether the text field is validated. @default false */\n validated?: boolean;\n /** Icon element displayed at the left side of the input. */\n leftIcon?: React.ReactNode;\n /** Size in pixels of the slot that holds `leftIcon`. @default \"16\" */\n leftIconSize?: \"16\" | \"24\";\n /** Icon element displayed at the right side of the input. */\n rightIcon?: React.ReactNode;\n /** Fixed, non-editable label pinned inside the left edge of the field — for a prefix such as a currency symbol or country code. */\n leftLabel?: React.ReactNode;\n /** Fixed, non-editable label pinned inside the right edge of the field — for a unit or suffix such as a currency code or domain. */\n rightLabel?: React.ReactNode;\n /**\n * Trailing interactive element pinned to the right edge — typically a `Chip`\n * or `Button` (the \"with button\" field type). Reduces the right padding so the\n * control sits flush, and clicks on it do not steal focus from the input.\n */\n action?: React.ReactNode;\n /** Whether the text field stretches to fill its container width. @default false */\n fullWidth?: boolean;\n}\n\nconst CONTAINER_HEIGHT: Record<TextFieldSize, string> = {\n \"48\": \"h-12\",\n \"40\": \"h-10\",\n \"32\": \"h-8\",\n};\n\nconst CONTAINER_PADDING_X: Record<TextFieldSize, string> = {\n \"48\": \"px-4\",\n \"40\": \"px-4\",\n \"32\": \"px-3\",\n};\n\nconst CONTAINER_PADDING_X_WITH_ACTION: Record<TextFieldSize, string> = {\n \"48\": \"pl-4 pr-2\",\n \"40\": \"pl-4 pr-2\",\n \"32\": \"pl-3 pr-2\",\n};\n\nconst CONTAINER_GAP: Record<TextFieldSize, string> = {\n \"48\": \"gap-2.5\",\n \"40\": \"gap-2.5\",\n \"32\": \"gap-2\",\n};\n\nconst INPUT_TYPOGRAPHY: Record<TextFieldSize, string> = {\n \"48\": \"typography-body-default-16px-regular autofill-body-lg\",\n \"40\": \"typography-body-default-16px-regular autofill-body-lg\",\n \"32\": \"typography-body-small-14px-regular autofill-body-md\",\n};\n\nconst SIDE_LABEL_TYPOGRAPHY: Record<TextFieldSize, string> = {\n \"48\": \"typography-body-default-16px-regular\",\n \"40\": \"typography-body-default-16px-regular\",\n \"32\": \"typography-body-small-14px-regular\",\n};\n\nfunction getContainerClassName(\n size: TextFieldSize,\n error: boolean,\n disabled?: boolean,\n hasAction?: boolean,\n) {\n return cn(\n \"relative flex items-center overflow-hidden rounded-sm border bg-inputs-inputs-primary after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] has-focus-visible:outline-none has-focus-visible:after:shadow-focus-ring motion-safe:transition-colors\",\n hasAction ? CONTAINER_PADDING_X_WITH_ACTION[size] : CONTAINER_PADDING_X[size],\n CONTAINER_GAP[size],\n error ? \"border-error-content\" : \"border-border-primary\",\n !disabled && !error && \"hover:border-neutral-alphas-400\",\n CONTAINER_HEIGHT[size],\n disabled && \"opacity-50\",\n );\n}\n\nfunction LeadingIcon({\n size = \"16\",\n children,\n}: {\n size?: \"16\" | \"24\";\n children?: React.ReactNode;\n}) {\n if (!children) return null;\n return (\n <span\n className={cn(\n \"pointer-events-none flex shrink-0 items-center justify-center text-content-secondary\",\n size === \"24\" ? \"size-6\" : \"size-4\",\n )}\n >\n {children}\n </span>\n );\n}\n\nfunction SideLabel({\n id,\n size,\n align,\n children,\n}: {\n id?: string;\n size: TextFieldSize;\n align: \"left\" | \"right\";\n children?: React.ReactNode;\n}) {\n if (!children) return null;\n return (\n <span\n id={id}\n className={cn(\n \"shrink-0 select-none whitespace-nowrap text-content-tertiary\",\n align === \"right\" && \"text-right\",\n SIDE_LABEL_TYPOGRAPHY[size],\n )}\n >\n {children}\n </span>\n );\n}\n\nfunction TrailingAdornment({\n rightIcon,\n validated,\n}: {\n rightIcon?: React.ReactNode;\n validated: boolean;\n}) {\n if (!rightIcon && !validated) return null;\n return (\n <span className=\"flex shrink-0 items-center gap-2 text-content-secondary\">\n {rightIcon && (\n <span data-tf-interactive=\"\" className=\"flex size-4 shrink-0 items-center justify-center\">\n {rightIcon}\n </span>\n )}\n {validated && (\n <span className=\"pointer-events-none flex size-4 shrink-0 items-center justify-center\">\n <CheckOutlineIcon className=\"text-success-content\" />\n </span>\n )}\n </span>\n );\n}\n\nfunction TextFieldHelperText({\n id,\n error,\n children,\n}: {\n id: string;\n error: boolean;\n children: React.ReactNode;\n}) {\n return (\n <p\n id={id}\n className={cn(\n \"typography-description-12px-regular pt-2\",\n error ? \"text-error-content\" : \"text-content-tertiary\",\n )}\n >\n {children}\n </p>\n );\n}\n\nfunction warnMissingAccessibleName(label?: string, ariaLabel?: string, ariaLabelledBy?: string) {\n if (process.env.NODE_ENV !== \"production\") {\n if (!label && !ariaLabel && !ariaLabelledBy) {\n console.warn(\n \"TextField: no accessible name provided. Pass a `label`, `aria-label`, or `aria-labelledby` prop.\",\n );\n }\n }\n}\n\n/**\n * A text input field with optional label, helper/error text, icon slots, and side labels.\n *\n * Use `leftLabel` / `rightLabel` for fixed unit or prefix affordances (currency symbol,\n * country code, domain suffix). Provide at least one of `label`, `aria-label`, or\n * `aria-labelledby` for accessibility — a console warning is emitted in development if none are set.\n *\n * @example\n * ```tsx\n * <TextField\n * label=\"Email\"\n * placeholder=\"you@example.com\"\n * error={!!emailError}\n * errorMessage={emailError}\n * />\n * ```\n *\n * @example\n * ```tsx\n * <TextField label=\"Price\" leftLabel=\"$\" rightLabel=\"USD\" placeholder=\"0.00\" />\n * ```\n *\n * @example\n * ```tsx\n * <TextField\n * label=\"Promo code\"\n * placeholder=\"Enter code\"\n * action={<Chip size=\"32\" onClick={apply}>Apply</Chip>}\n * />\n * ```\n */\nexport const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(\n (\n {\n label,\n helperText,\n size = \"48\",\n error = false,\n errorMessage,\n validated = false,\n leftIcon,\n leftIconSize,\n rightIcon,\n leftLabel,\n rightLabel,\n action,\n className,\n id,\n disabled,\n fullWidth = false,\n ...props\n },\n ref,\n ) => {\n const generatedId = React.useId();\n const inputId = id || generatedId;\n const helperTextId = `${inputId}-helper`;\n const leftLabelId = `${inputId}-left-label`;\n const rightLabelId = `${inputId}-right-label`;\n const bottomText = error && errorMessage ? errorMessage : helperText;\n\n const describedBy =\n [\n leftLabel != null ? leftLabelId : null,\n rightLabel != null ? rightLabelId : null,\n bottomText ? helperTextId : null,\n ]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n const innerRef = React.useRef<HTMLInputElement>(null);\n const setRefs = React.useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLInputElement | null>).current = node;\n },\n [ref],\n );\n\n // Keep clicks on the non-interactive adornments (icons, side labels, padding)\n // focusing the input, matching the old absolute/pointer-events-none layout.\n const handleContainerMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) return;\n const target = event.target as HTMLElement;\n if (target === innerRef.current) return;\n if (target.closest(\"[data-tf-interactive]\")) return;\n event.preventDefault();\n innerRef.current?.focus();\n };\n\n warnMissingAccessibleName(label, props[\"aria-label\"], props[\"aria-labelledby\"]);\n\n return (\n <div\n className={cn(\"flex flex-col\", fullWidth && \"w-full\", className)}\n data-disabled={disabled ? \"\" : undefined}\n data-error={error ? \"\" : undefined}\n >\n {label && (\n <label\n htmlFor={inputId}\n className=\"typography-description-12px-semibold pb-2 text-content-primary\"\n >\n {label}\n </label>\n )}\n\n {/* biome-ignore lint/a11y/noStaticElementInteractions: focus bridge delegates pointer clicks on adornments to the input */}\n <div\n className={getContainerClassName(size, error, disabled, action != null)}\n onMouseDown={handleContainerMouseDown}\n >\n <LeadingIcon size={leftIconSize}>{leftIcon}</LeadingIcon>\n <SideLabel id={leftLabelId} size={size} align=\"left\">\n {leftLabel}\n </SideLabel>\n\n <input\n ref={setRefs}\n id={inputId}\n disabled={disabled}\n aria-describedby={describedBy}\n aria-invalid={error || undefined}\n className={cn(\n \"h-full min-w-0 flex-1 bg-transparent text-content-primary no-underline placeholder:text-content-tertiary focus:outline-none disabled:cursor-not-allowed\",\n INPUT_TYPOGRAPHY[size],\n \"[&[type='search']::-webkit-search-cancel-button]:hidden [&[type='search']::-webkit-search-cancel-button]:appearance-none\",\n )}\n {...props}\n />\n\n <SideLabel id={rightLabelId} size={size} align=\"right\">\n {rightLabel}\n </SideLabel>\n <TrailingAdornment rightIcon={rightIcon} validated={validated} />\n {action != null && (\n <span data-tf-interactive=\"\" className=\"flex shrink-0 items-center\">\n {action}\n </span>\n )}\n </div>\n\n {bottomText && (\n <TextFieldHelperText id={helperTextId} error={error}>\n {bottomText}\n </TextFieldHelperText>\n )}\n </div>\n );\n },\n);\n\nTextField.displayName = \"TextField\";\n"],"names":[],"mappings":";;;;;;AAyCA,MAAM,mBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,sBAAqD;AAAA,EACzD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,kCAAiE;AAAA,EACrE,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,gBAA+C;AAAA,EACnD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,wBAAuD;AAAA,EAC3D,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,sBACP,MACA,OACA,UACA,WACA;AACA,SAAO;AAAA,IACL;AAAA,IACA,YAAY,gCAAgC,IAAI,IAAI,oBAAoB,IAAI;AAAA,IAC5E,cAAc,IAAI;AAAA,IAClB,QAAQ,yBAAyB;AAAA,IACjC,CAAC,YAAY,CAAC,SAAS;AAAA,IACvB,iBAAiB,IAAI;AAAA,IACrB,YAAY;AAAA,EAAA;AAEhB;AAEA,SAAS,YAAY;AAAA,EACnB,OAAO;AAAA,EACP;AACF,GAGG;AACD,MAAI,CAAC,SAAU,QAAO;AACtB,SACE;AAAA,IAAC;AA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YAAC;AAAA,YAAA;AAAA,cACC,SAAS;AAAA,cACT,WAAU;AAAA,cAET,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,UAKL;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAW,sBAAsB,MAAM,OAAO,UAAU,UAAU,IAAI;AAAA,cACtE,aAAa;AAAA,cAEb,UAAA;AAAA,gBAAA,oBAAC,aAAA,EAAY,MAAM,cAAe,UAAA,UAAS;AAAA,oCAC1C,WAAA,EAAU,IAAI,aAAa,MAAY,OAAM,QAC3C,UAAA,WACH;AAAA,gBAEA;AAAA,kBAAC;AAAA,kBAAA;AAAA,oBACC,KAAK;AAAA,oBACL,IAAI;AAAA,oBACJ;AAAA,oBACA,oBAAkB;AAAA,oBAClB,gBAAc,SAAS;AAAA,oBACvB,WAAW;AAAA,sBACT;AAAA,sBACA,iBAAiB,IAAI;AAAA,sBACrB;AAAA,oBAAA;AAAA,oBAED,GAAG;AAAA,kBAAA;AAAA,gBAAA;AAAA,oCAGL,WAAA,EAAU,IAAI,cAAc,MAAY,OAAM,SAC5C,UAAA,YACH;AAAA,gBACA,oBAAC,mBAAA,EAAkB,WAAsB,UAAA,CAAsB;AAAA,gBAC9D,UAAU,QACT,oBAAC,QAAA,EAAK,uBAAoB,IAAG,WAAU,8BACpC,UAAA,OAAA,CACH;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,UAIH,cACC,oBAAC,qBAAA,EAAoB,IAAI,cAAc,OACpC,UAAA,WAAA,CACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,UAAU,cAAc;"}
package/dist/index.d.ts CHANGED
@@ -5257,7 +5257,7 @@ export declare interface ReviewCardProps extends Omit<React_2.HTMLAttributes<HTM
5257
5257
  */
5258
5258
  export declare const SearchField: React_2.ForwardRefExoticComponent<SearchFieldProps & React_2.RefAttributes<HTMLInputElement>>;
5259
5259
 
5260
- export declare interface SearchFieldProps extends Omit<TextFieldProps, "type" | "leftIcon"> {
5260
+ export declare interface SearchFieldProps extends Omit<TextFieldProps, "type" | "leftIcon" | "leftIconSize"> {
5261
5261
  /** Size variant of the search field. @default "48" */
5262
5262
  size?: SearchFieldSize;
5263
5263
  /** Callback fired when the clear button is clicked. If provided, a clear button appears when the field has a value. */
@@ -6709,6 +6709,8 @@ export declare interface TextFieldProps extends Omit<React_2.InputHTMLAttributes
6709
6709
  validated?: boolean;
6710
6710
  /** Icon element displayed at the left side of the input. */
6711
6711
  leftIcon?: React_2.ReactNode;
6712
+ /** Size in pixels of the slot that holds `leftIcon`. @default "16" */
6713
+ leftIconSize?: "16" | "24";
6712
6714
  /** Icon element displayed at the right side of the input. */
6713
6715
  rightIcon?: React_2.ReactNode;
6714
6716
  /** Fixed, non-editable label pinned inside the left edge of the field — for a prefix such as a currency symbol or country code. */
@@ -0,0 +1,128 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { usePrefersReducedMotion } from "./usePrefersReducedMotion.mjs";
4
+ const DRAG_START_THRESHOLD_PX = 8;
5
+ const DISMISS_DISTANCE_RATIO = 0.25;
6
+ const DISMISS_VELOCITY_PX_PER_MS = 0.5;
7
+ const FLICK_WINDOW_MS = 100;
8
+ const SNAP_BACK_TRANSITION = "transform 200ms ease-out";
9
+ const NON_DRAGGABLE_TARGETS = "input, textarea, select, [contenteditable='true']";
10
+ function shouldDismissDrag({
11
+ offset,
12
+ height,
13
+ velocity
14
+ }) {
15
+ if (offset <= 0) return false;
16
+ return offset >= height * DISMISS_DISTANCE_RATIO || velocity >= DISMISS_VELOCITY_PX_PER_MS;
17
+ }
18
+ function isScrolledAwayFromTop(target, container) {
19
+ let node = target instanceof HTMLElement ? target : null;
20
+ while (node && node !== container) {
21
+ if (node.scrollTop > 0) return true;
22
+ node = node.parentElement;
23
+ }
24
+ return container.scrollTop > 0;
25
+ }
26
+ function blockTouchScrollWhileDragging(element, getDrag) {
27
+ const onTouchMove = (event) => {
28
+ const drag = getDrag();
29
+ const touch = event.touches[0];
30
+ if (!drag || !touch) return;
31
+ const offset = touch.clientY - drag.startY;
32
+ if (drag.dragging || offset > Math.abs(touch.clientX - drag.startX)) event.preventDefault();
33
+ };
34
+ element.addEventListener("touchmove", onTouchMove, { passive: false });
35
+ return () => element.removeEventListener("touchmove", onTouchMove);
36
+ }
37
+ function useDragToDismiss({ enabled, onDismiss, media }, props) {
38
+ const dragRef = React.useRef(null);
39
+ const prefersReducedMotion = usePrefersReducedMotion();
40
+ const snapBack = (element) => {
41
+ element.style.transition = prefersReducedMotion ? "" : SNAP_BACK_TRANSITION;
42
+ element.style.transform = "";
43
+ };
44
+ const release = (drag, dismiss) => {
45
+ dragRef.current = null;
46
+ drag.stopBlockingTouchScroll();
47
+ drag.element.releasePointerCapture?.(drag.pointerId);
48
+ if (!drag.dragging) return;
49
+ if (!dismiss) {
50
+ snapBack(drag.element);
51
+ return;
52
+ }
53
+ onDismiss();
54
+ requestAnimationFrame(() => {
55
+ if (drag.element.isConnected && drag.element.dataset.state !== "closed") {
56
+ snapBack(drag.element);
57
+ }
58
+ });
59
+ };
60
+ return {
61
+ ...props,
62
+ onPointerDown(event) {
63
+ props.onPointerDown?.(event);
64
+ if (!enabled || event.defaultPrevented || event.button !== 0) return;
65
+ if (media && typeof window.matchMedia === "function" && !window.matchMedia(media).matches)
66
+ return;
67
+ const target = event.target instanceof Element ? event.target : null;
68
+ if (target?.closest(NON_DRAGGABLE_TARGETS)) return;
69
+ if (isScrolledAwayFromTop(event.target, event.currentTarget)) return;
70
+ const element = event.currentTarget;
71
+ dragRef.current = {
72
+ pointerId: event.pointerId,
73
+ element,
74
+ startY: event.clientY,
75
+ startX: event.clientX,
76
+ lastY: event.clientY,
77
+ lastTime: event.timeStamp,
78
+ velocity: 0,
79
+ dragging: false,
80
+ stopBlockingTouchScroll: blockTouchScrollWhileDragging(element, () => dragRef.current)
81
+ };
82
+ },
83
+ onPointerMove(event) {
84
+ props.onPointerMove?.(event);
85
+ const drag = dragRef.current;
86
+ if (!drag || event.pointerId !== drag.pointerId) return;
87
+ const offset = event.clientY - drag.startY;
88
+ if (!drag.dragging) {
89
+ const dx = Math.abs(event.clientX - drag.startX);
90
+ if (Math.max(Math.abs(offset), dx) < DRAG_START_THRESHOLD_PX) return;
91
+ if (offset <= dx) {
92
+ release(drag, false);
93
+ return;
94
+ }
95
+ drag.dragging = true;
96
+ drag.element.setPointerCapture?.(event.pointerId);
97
+ drag.element.style.transition = "none";
98
+ }
99
+ const elapsed = event.timeStamp - drag.lastTime;
100
+ if (elapsed > 0) drag.velocity = (event.clientY - drag.lastY) / elapsed;
101
+ drag.lastY = event.clientY;
102
+ drag.lastTime = event.timeStamp;
103
+ drag.element.style.transform = `translate3d(0, ${Math.max(offset, 0)}px, 0)`;
104
+ },
105
+ onPointerUp(event) {
106
+ props.onPointerUp?.(event);
107
+ const drag = dragRef.current;
108
+ if (!drag || event.pointerId !== drag.pointerId) return;
109
+ const dismiss = shouldDismissDrag({
110
+ offset: event.clientY - drag.startY,
111
+ height: drag.element.getBoundingClientRect().height,
112
+ velocity: event.timeStamp - drag.lastTime > FLICK_WINDOW_MS ? 0 : drag.velocity
113
+ });
114
+ release(drag, dismiss);
115
+ },
116
+ onPointerCancel(event) {
117
+ props.onPointerCancel?.(event);
118
+ const drag = dragRef.current;
119
+ if (!drag || event.pointerId !== drag.pointerId) return;
120
+ release(drag, false);
121
+ }
122
+ };
123
+ }
124
+ export {
125
+ shouldDismissDrag,
126
+ useDragToDismiss
127
+ };
128
+ //# sourceMappingURL=useDragToDismiss.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDragToDismiss.mjs","sources":["../../src/utils/useDragToDismiss.ts"],"sourcesContent":["import * as React from \"react\";\nimport { usePrefersReducedMotion } from \"./usePrefersReducedMotion\";\n\nconst DRAG_START_THRESHOLD_PX = 8;\nconst DISMISS_DISTANCE_RATIO = 0.25;\nconst DISMISS_VELOCITY_PX_PER_MS = 0.5;\nconst FLICK_WINDOW_MS = 100;\nconst SNAP_BACK_TRANSITION = \"transform 200ms ease-out\";\nconst NON_DRAGGABLE_TARGETS = \"input, textarea, select, [contenteditable='true']\";\n\n/**\n * Whether a released sheet drag should dismiss the sheet: past a quarter of\n * the sheet's height, or a fast downward flick at any distance.\n */\nexport function shouldDismissDrag({\n offset,\n height,\n velocity,\n}: {\n offset: number;\n height: number;\n velocity: number;\n}): boolean {\n if (offset <= 0) return false;\n return offset >= height * DISMISS_DISTANCE_RATIO || velocity >= DISMISS_VELOCITY_PX_PER_MS;\n}\n\ntype DragHandlers = {\n onPointerDown?: React.PointerEventHandler<HTMLDivElement>;\n onPointerMove?: React.PointerEventHandler<HTMLDivElement>;\n onPointerUp?: React.PointerEventHandler<HTMLDivElement>;\n onPointerCancel?: React.PointerEventHandler<HTMLDivElement>;\n};\n\ntype ActiveDrag = {\n pointerId: number;\n element: HTMLDivElement;\n startY: number;\n startX: number;\n lastY: number;\n lastTime: number;\n velocity: number;\n dragging: boolean;\n stopBlockingTouchScroll: () => void;\n};\n\nexport interface UseDragToDismissOptions {\n /** Whether dragging is active at all. */\n enabled: boolean;\n /** Called once a release passes the dismiss threshold. */\n onDismiss: () => void;\n /** Media query that must match for a drag to start, e.g. to limit it to mobile. */\n media?: string;\n}\n\nfunction isScrolledAwayFromTop(target: EventTarget | null, container: HTMLElement): boolean {\n let node = target instanceof HTMLElement ? target : null;\n while (node && node !== container) {\n if (node.scrollTop > 0) return true;\n node = node.parentElement;\n }\n return container.scrollTop > 0;\n}\n\nfunction blockTouchScrollWhileDragging(\n element: HTMLElement,\n getDrag: () => ActiveDrag | null,\n): () => void {\n const onTouchMove = (event: TouchEvent) => {\n const drag = getDrag();\n const touch = event.touches[0];\n if (!drag || !touch) return;\n const offset = touch.clientY - drag.startY;\n if (drag.dragging || offset > Math.abs(touch.clientX - drag.startX)) event.preventDefault();\n };\n element.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n return () => element.removeEventListener(\"touchmove\", onTouchMove);\n}\n\n/**\n * Composes the consumer's pointer handlers with drag-down-to-dismiss for a\n * bottom sheet. The sheet follows the pointer downwards, and on release either\n * dismisses or snaps back. A drag never starts inside a form field or inside\n * scrollable content that is not scrolled to the top, so it does not fight\n * text selection or scrolling.\n */\nexport function useDragToDismiss<P extends DragHandlers>(\n { enabled, onDismiss, media }: UseDragToDismissOptions,\n props: P,\n): P & Required<DragHandlers> {\n const dragRef = React.useRef<ActiveDrag | null>(null);\n const prefersReducedMotion = usePrefersReducedMotion();\n\n const snapBack = (element: HTMLDivElement) => {\n element.style.transition = prefersReducedMotion ? \"\" : SNAP_BACK_TRANSITION;\n element.style.transform = \"\";\n };\n\n const release = (drag: ActiveDrag, dismiss: boolean) => {\n dragRef.current = null;\n drag.stopBlockingTouchScroll();\n drag.element.releasePointerCapture?.(drag.pointerId);\n if (!drag.dragging) return;\n if (!dismiss) {\n snapBack(drag.element);\n return;\n }\n onDismiss();\n requestAnimationFrame(() => {\n if (drag.element.isConnected && drag.element.dataset.state !== \"closed\") {\n snapBack(drag.element);\n }\n });\n };\n\n return {\n ...props,\n onPointerDown(event) {\n props.onPointerDown?.(event);\n if (!enabled || event.defaultPrevented || event.button !== 0) return;\n if (media && typeof window.matchMedia === \"function\" && !window.matchMedia(media).matches)\n return;\n const target = event.target instanceof Element ? event.target : null;\n if (target?.closest(NON_DRAGGABLE_TARGETS)) return;\n if (isScrolledAwayFromTop(event.target, event.currentTarget)) return;\n const element = event.currentTarget;\n dragRef.current = {\n pointerId: event.pointerId,\n element,\n startY: event.clientY,\n startX: event.clientX,\n lastY: event.clientY,\n lastTime: event.timeStamp,\n velocity: 0,\n dragging: false,\n stopBlockingTouchScroll: blockTouchScrollWhileDragging(element, () => dragRef.current),\n };\n },\n onPointerMove(event) {\n props.onPointerMove?.(event);\n const drag = dragRef.current;\n if (!drag || event.pointerId !== drag.pointerId) return;\n const offset = event.clientY - drag.startY;\n if (!drag.dragging) {\n const dx = Math.abs(event.clientX - drag.startX);\n if (Math.max(Math.abs(offset), dx) < DRAG_START_THRESHOLD_PX) return;\n if (offset <= dx) {\n release(drag, false);\n return;\n }\n drag.dragging = true;\n drag.element.setPointerCapture?.(event.pointerId);\n drag.element.style.transition = \"none\";\n }\n const elapsed = event.timeStamp - drag.lastTime;\n if (elapsed > 0) drag.velocity = (event.clientY - drag.lastY) / elapsed;\n drag.lastY = event.clientY;\n drag.lastTime = event.timeStamp;\n drag.element.style.transform = `translate3d(0, ${Math.max(offset, 0)}px, 0)`;\n },\n onPointerUp(event) {\n props.onPointerUp?.(event);\n const drag = dragRef.current;\n if (!drag || event.pointerId !== drag.pointerId) return;\n const dismiss = shouldDismissDrag({\n offset: event.clientY - drag.startY,\n height: drag.element.getBoundingClientRect().height,\n velocity: event.timeStamp - drag.lastTime > FLICK_WINDOW_MS ? 0 : drag.velocity,\n });\n release(drag, dismiss);\n },\n onPointerCancel(event) {\n props.onPointerCancel?.(event);\n const drag = dragRef.current;\n if (!drag || event.pointerId !== drag.pointerId) return;\n release(drag, false);\n },\n };\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,0BAA0B;AAChC,MAAM,yBAAyB;AAC/B,MAAM,6BAA6B;AACnC,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAC7B,MAAM,wBAAwB;AAMvB,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAIY;AACV,MAAI,UAAU,EAAG,QAAO;AACxB,SAAO,UAAU,SAAS,0BAA0B,YAAY;AAClE;AA8BA,SAAS,sBAAsB,QAA4B,WAAiC;AAC1F,MAAI,OAAO,kBAAkB,cAAc,SAAS;AACpD,SAAO,QAAQ,SAAS,WAAW;AACjC,QAAI,KAAK,YAAY,EAAG,QAAO;AAC/B,WAAO,KAAK;AAAA,EACd;AACA,SAAO,UAAU,YAAY;AAC/B;AAEA,SAAS,8BACP,SACA,SACY;AACZ,QAAM,cAAc,CAAC,UAAsB;AACzC,UAAM,OAAO,QAAA;AACb,UAAM,QAAQ,MAAM,QAAQ,CAAC;AAC7B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AA,QAC7C,UAAU,MAAM,YAAY,KAAK,WAAW,kBAAkB,IAAI,KAAK;AAAA,MAAA,CACxE;AACD,cAAQ,MAAM,OAAO;AAAA,IACvB;AAAA,IACA,gBAAgB,OAAO;AACrB,YAAM,kBAAkB,KAAK;AAC7B,YAAM,OAAO,QAAQ;AACrB,UAAI,CAAC,QAAQ,MAAM,cAAc,KAAK,UAAW;AACjD,cAAQ,MAAM,KAAK;AAAA,IACrB;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanvue/ui",
3
- "version": "3.39.0",
3
+ "version": "3.40.1",
4
4
  "description": "React component library built with Tailwind CSS for Fanvue ecosystem",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -201,6 +201,7 @@
201
201
  "brace-expansion": ">=5.0.11",
202
202
  "yaml": ">=2.8.3",
203
203
  "postcss": ">=8.5.23",
204
+ "source-map-js": ">=1.2.2",
204
205
  "nanoid@^3": "^3.3.18",
205
206
  "nanoid@^5": "^5.1.16",
206
207
  "tmp": ">=0.2.7",