@fanvue/ui 3.39.0 → 3.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Checkbox/Checkbox.cjs +1 -1
- package/dist/cjs/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/cjs/components/Chip/Chip.cjs +2 -2
- package/dist/cjs/components/Chip/Chip.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Dialog.cjs +12 -1
- package/dist/cjs/components/Dialog/Dialog.cjs.map +1 -1
- package/dist/cjs/components/Drawer/Drawer.cjs +12 -3
- package/dist/cjs/components/Drawer/Drawer.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuHeader.cjs +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuHeader.cjs.map +1 -1
- package/dist/cjs/components/SearchField/SearchField.cjs +5 -1
- package/dist/cjs/components/SearchField/SearchField.cjs.map +1 -1
- package/dist/cjs/components/TextField/TextField.cjs +16 -3
- package/dist/cjs/components/TextField/TextField.cjs.map +1 -1
- package/dist/cjs/utils/useDragToDismiss.cjs +145 -0
- package/dist/cjs/utils/useDragToDismiss.cjs.map +1 -0
- package/dist/components/Checkbox/Checkbox.mjs +1 -1
- package/dist/components/Checkbox/Checkbox.mjs.map +1 -1
- package/dist/components/Chip/Chip.mjs +2 -2
- package/dist/components/Chip/Chip.mjs.map +1 -1
- package/dist/components/Dialog/Dialog.mjs +12 -1
- package/dist/components/Dialog/Dialog.mjs.map +1 -1
- package/dist/components/Drawer/Drawer.mjs +12 -3
- package/dist/components/Drawer/Drawer.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuHeader.mjs +1 -1
- package/dist/components/DropdownMenu/DropdownMenuHeader.mjs.map +1 -1
- package/dist/components/SearchField/SearchField.mjs +5 -1
- package/dist/components/SearchField/SearchField.mjs.map +1 -1
- package/dist/components/TextField/TextField.mjs +16 -3
- package/dist/components/TextField/TextField.mjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/utils/useDragToDismiss.mjs +128 -0
- package/dist/utils/useDragToDismiss.mjs.map +1 -0
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.mjs","sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useSuppressClickAfterDrag } from \"../../utils/useSuppressClickAfterDrag\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\n\n/** The side from which the drawer slides in. */\nexport type DrawerPosition = \"left\" | \"right\" | \"top\" | \"bottom\";\n\n/** Size presets for the drawer panel. Maps to max-width (left/right) or max-height (top/bottom). */\nexport type DrawerSize = \"sm\" | \"md\" | \"lg\" | \"full\";\n\n/**\n * Visual treatment of the drawer panel.\n *\n * - `\"panel\"` (default) — the standard edge-anchored surface.\n * - `\"sheet\"` — a bottom-sheet treatment matching the modal surface: large\n * top-only radius (32px), modal background/stroke, and menu blur+shadow.\n * Intended for `position=\"bottom\"`.\n * - `\"menu\"` — a floating menu near the bottom edge rather than a sheet fixed to\n * it: inset from all three sides and rounded on every corner. Shares the modal\n * surface with `\"sheet\"`; only the shape differs. Intended for\n * `position=\"bottom\"`.\n */\nexport type DrawerVariant = \"panel\" | \"sheet\" | \"menu\";\n\n/**\n * Shared surface classes for the `\"sheet\"` variant. Mirrors the mobile sheet\n * treatment used by {@link Dialog} so bottom sheets are visually consistent.\n */\nconst SHEET_CLASSES =\n \"rounded-t-xl border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Surface and inset for the `\"menu\"` variant. Same modal background and stroke as\n * a sheet — the design puts this panel on `background/secondary` with\n * `border/strong`, not on the lighter surface the trigger-anchored dropdown uses.\n * The 24px radius is the design's `rounded-lg`.\n *\n * The insets restate position on purpose — they override `SLIDE_CLASSES.bottom`,\n * which pins a sheet flush to the bottom edge at full width.\n */\nconst MENU_CLASSES =\n \"inset-x-4 bottom-4 w-auto rounded-lg border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Props for the {@link Drawer} root component.\n *\n * Inherits `open`, `onOpenChange`, and `defaultOpen` from Radix Dialog.Root.\n *\n * The Radix `modal` prop (default `true`) can also be passed to create a\n * non-modal drawer — useful for persistent side navigation that does not\n * block interaction with the rest of the page.\n *\n * **`overlay` behaviour:** When `overlay` is `false`, the component\n * automatically sets `modal={false}` on the underlying Radix Dialog.Root.\n * A modal dialog without a visible overlay is confusing because focus is\n * still trapped and scroll is blocked even though the page appears\n * interactive. Passing `modal={true}` explicitly will override this.\n */\nexport interface DrawerProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root> {\n /**\n * Whether the default {@link DrawerOverlay} is rendered.\n * When `false`, `modal` is automatically set to `false` as well\n * (unless explicitly overridden) so focus-trap and scroll-lock are disabled.\n * @default true\n */\n overlay?: boolean;\n}\n\nconst DrawerContext = React.createContext<{ overlay: boolean }>({\n overlay: true,\n});\n\n/**\n * Root component that manages open/close state for a drawer.\n * Wraps Radix Dialog.Root.\n *\n * @example\n * ```tsx\n * <Drawer>\n * <DrawerTrigger>Open</DrawerTrigger>\n * <DrawerContent position=\"right\">\n * <DrawerHeader>\n * <DrawerTitle>Settings</DrawerTitle>\n * <DrawerDescription>Adjust your preferences.</DrawerDescription>\n * </DrawerHeader>\n * <p>Content goes here.</p>\n * <DrawerFooter>\n * <DrawerClose>Done</DrawerClose>\n * </DrawerFooter>\n * </DrawerContent>\n * </Drawer>\n * ```\n */\nexport function Drawer({ overlay = true, modal, children, ...props }: DrawerProps) {\n const resolvedModal = modal ?? (overlay ? undefined : false);\n return (\n <DrawerContext.Provider value={{ overlay }}>\n <DialogPrimitive.Root modal={resolvedModal} {...props}>\n {children}\n </DialogPrimitive.Root>\n </DrawerContext.Provider>\n );\n}\nDrawer.displayName = \"Drawer\";\n\n/** Props for the {@link DrawerTrigger} component. */\nexport type DrawerTriggerProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Trigger>;\n\n/**\n * The element that opens the drawer when clicked.\n *\n * On touch / pen, a press-and-release that crosses a small movement threshold\n * is treated as a drag and the resulting synthetic click is suppressed —\n * defends against Android Chrome opening the drawer on a scroll-drag-end.\n */\nexport const DrawerTrigger = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Trigger>,\n DrawerTriggerProps\n>((props, ref) => <DialogPrimitive.Trigger ref={ref} {...useSuppressClickAfterDrag(props)} />);\nDrawerTrigger.displayName = \"DrawerTrigger\";\n\n/** Props for the {@link DrawerClose} component. */\nexport type DrawerCloseProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>;\n\n/** Closes the drawer when clicked. Can be placed anywhere inside the drawer. */\nexport const DrawerClose = DialogPrimitive.Close;\nDrawerClose.displayName = \"DrawerClose\";\n\n/** Props for the {@link DrawerOverlay} component. */\nexport interface DrawerOverlayProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> {}\n\n/**\n * A translucent backdrop rendered behind the drawer content.\n * Clicking the overlay closes the drawer by default.\n */\nexport const DrawerOverlay = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Overlay>,\n DrawerOverlayProps\n>(({ className, style, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\", ...style }}\n className={cn(\n \"fixed inset-0 bg-background-overlay-default\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:fade-in-0 data-[state=open]:duration-200 data-[state=open]:ease-out\",\n className,\n )}\n {...props}\n />\n));\nDrawerOverlay.displayName = \"DrawerOverlay\";\n\n/**\n * Slide-in animation classes keyed by position.\n * Uses Tailwind animate utilities (animate-in / animate-out).\n */\nconst SLIDE_CLASSES: Record<DrawerPosition, string> = {\n right:\n \"inset-y-0 right-0 h-full w-2/3 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right\",\n left: \"inset-y-0 left-0 h-full w-2/3 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left\",\n top: \"inset-x-0 top-0 w-full data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top\",\n bottom:\n \"inset-x-0 bottom-0 w-full rounded-t-xs data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom\",\n};\n\n/** Props for the {@link DrawerContent} component. */\nexport interface DrawerContentProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {\n /**\n * The edge from which the drawer slides in.\n *\n * Named `position` (rather than `side`) to avoid confusion with the CSS\n * `side` concept used by Radix Popover/Tooltip and to better convey the\n * spatial relationship of the drawer to the viewport.\n *\n * @default \"right\"\n */\n position?: DrawerPosition;\n /**\n * Controls the maximum extent of the drawer panel.\n * For left/right drawers this sets `max-width`; for top/bottom it sets `max-height`.\n * @default \"sm\"\n */\n size?: DrawerSize;\n /**\n * Visual treatment of the panel. Use `\"sheet\"` (with `position=\"bottom\"`) for\n * a bottom sheet with the modal surface treatment, or `\"menu\"` for a floating\n * inset menu carrying the dropdown surface. @default \"panel\"\n */\n variant?: DrawerVariant;\n /**\n * Whether to render the default {@link DrawerOverlay} behind the content.\n * Set to `false` to provide your own overlay or omit it entirely.\n *\n * Prefer setting `overlay` on the {@link Drawer} root instead so that\n * `modal` is also adjusted automatically.\n *\n * @default true\n */\n overlay?: boolean;\n /** Props forwarded to the default {@link DrawerOverlay} when `overlay` is `true`. */\n overlayProps?: DrawerOverlayProps;\n}\n\n/**\n * The panel that slides in from the chosen edge. Renders inside a portal with\n * an overlay backdrop by default.\n *\n * Includes focus-trap, `aria-describedby`, and Escape-to-close from Radix Dialog.\n */\nexport const DrawerContent = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Content>,\n DrawerContentProps\n>(\n (\n {\n className,\n position = \"right\",\n size = \"sm\",\n variant = \"panel\",\n overlay: overlayProp,\n overlayProps,\n style,\n children,\n ...props\n },\n ref,\n ) => {\n const ctx = React.useContext(DrawerContext);\n const overlay = overlayProp ?? ctx.overlay;\n const isHorizontal = position === \"left\" || position === \"right\";\n const sizeClass = isHorizontal\n ? (\n {\n sm: \"max-w-sm\",\n md: \"max-w-md\",\n lg: \"max-w-lg\",\n full: \"max-w-full\",\n } as const\n )[size]\n : (\n {\n sm: \"max-h-[24rem]\",\n md: \"max-h-[28rem]\",\n lg: \"max-h-[32rem]\",\n full: \"max-h-full\",\n } as const\n )[size];\n\n return (\n <DialogPrimitive.Portal>\n {overlay && <DrawerOverlay {...overlayProps} />}\n <DialogPrimitive.Content\n ref={ref}\n style={{\n zIndex: \"calc(var(--fanvue-ui-portal-z-index, 50) + 1)\",\n ...style,\n }}\n className={cn(\n \"fixed flex flex-col bg-surface-secondary outline-none backdrop-blur-lg\",\n // `shadow-lg` is scoped to `panel` rather than sitting in the base classes.\n // tailwind-merge does not recognise `shadow-blur-menu` as a box-shadow\n // utility, so it never deduped the two and `shadow-lg` won on stylesheet\n // order — meaning the sheet and menu surfaces silently rendered `shadow-lg`\n // instead of the menu shadow their tokens name.\n variant === \"panel\" && \"shadow-lg\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:duration-200 data-[state=open]:ease-out\",\n SLIDE_CLASSES[position],\n sizeClass,\n variant === \"sheet\" && SHEET_CLASSES,\n variant === \"menu\" && MENU_CLASSES,\n className,\n )}\n {...props}\n >\n {children}\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n );\n },\n);\nDrawerContent.displayName = \"DrawerContent\";\n\n/** Props for the {@link DrawerHeader} component. */\nexport interface DrawerHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Whether to show a built-in close (X) button. @default true */\n showClose?: boolean;\n /** Accessible label for the close button. @default \"Close drawer\" */\n closeLabel?: string;\n}\n\n/**\n * A semantic header area for the drawer, typically containing a title and description.\n * Renders a built-in close button by default.\n */\nexport const DrawerHeader = React.forwardRef<HTMLDivElement, DrawerHeaderProps>(\n ({ className, showClose = true, closeLabel = \"Close drawer\", children, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex items-center gap-2 p-4\", className)} {...props}>\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">{children}</div>\n {showClose && (\n <DialogPrimitive.Close asChild>\n <IconButton\n icon={<CloseIcon />}\n aria-label={closeLabel}\n variant=\"secondary\"\n size=\"32\"\n className=\"shrink-0\"\n />\n </DialogPrimitive.Close>\n )}\n </div>\n ),\n);\nDrawerHeader.displayName = \"DrawerHeader\";\n\n/** Props for the {@link DrawerFooter} component. */\nexport interface DrawerFooterProps extends React.HTMLAttributes<HTMLDivElement> {}\n\n/** A semantic footer area for the drawer, typically containing action buttons. */\nexport const DrawerFooter = React.forwardRef<HTMLDivElement, DrawerFooterProps>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex flex-col gap-2 p-4\", className)} {...props} />\n ),\n);\nDrawerFooter.displayName = \"DrawerFooter\";\n\n/** Props for the {@link DrawerTitle} component. */\nexport interface DrawerTitleProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> {}\n\n/** An accessible title for the drawer. Required for screen readers. */\nexport const DrawerTitle = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Title>,\n DrawerTitleProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn(\"typography-body-default-16px-semibold truncate text-content-primary\", className)}\n {...props}\n />\n));\nDrawerTitle.displayName = \"DrawerTitle\";\n\n/** Props for the {@link DrawerDescription} component. */\nexport interface DrawerDescriptionProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> {}\n\n/** An accessible description for the drawer, providing supplementary context. */\nexport const DrawerDescription = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Description>,\n DrawerDescriptionProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description\n ref={ref}\n className={cn(\"typography-body-small-14px-regular text-content-secondary\", className)}\n {...props}\n />\n));\nDrawerDescription.displayName = \"DrawerDescription\";\n"],"names":[],"mappings":";;;;;;;;AA+BA,MAAM,gBACJ;AAWF,MAAM,eACJ;AA2BF,MAAM,gBAAgB,MAAM,cAAoC;AAAA,EAC9D,SAAS;AACX,CAAC;AAuBM,SAAS,OAAO,EAAE,UAAU,MAAM,OAAO,UAAU,GAAG,SAAsB;AACjF,QAAM,gBAAgB,UAAU,UAAU,SAAY;AACtD,6BACG,cAAc,UAAd,EAAuB,OAAO,EAAE,QAAA,GAC/B,UAAA,oBAAC,gBAAgB,MAAhB,EAAqB,OAAO,eAAgB,GAAG,OAC7C,UACH,GACF;AAEJ;AACA,OAAO,cAAc;AAYd,MAAM,gBAAgB,MAAM,WAGjC,CAAC,OAAO,QAAQ,oBAAC,gBAAgB,SAAhB,EAAwB,KAAW,GAAG,0BAA0B,KAAK,GAAG,CAAE;AAC7F,cAAc,cAAc;AAMrB,MAAM,cAAc,gBAAgB;AAC3C,YAAY,cAAc;AAUnB,MAAM,gBAAgB,MAAM,WAGjC,CAAC,EAAE,WAAW,OAAO,GAAG,SAAS,QACjC;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,OAAO,EAAE,QAAQ,uCAAuC,GAAG,MAAA;AAAA,IAC3D,WAAW;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAED,GAAG;AAAA,EAAA;AACN,CACD;AACD,cAAc,cAAc;AAM5B,MAAM,gBAAgD;AAAA,EACpD,OACE;AAAA,EACF,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QACE;AACJ;AA+CO,MAAM,gBAAgB,MAAM;AAAA,EAIjC,CACE;AAAA,IACE;AAAA,IACA,WAAW;AAA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AAA,IAC/D,aACC,oBAAC,gBAAgB,OAAhB,EAAsB,SAAO,MAC5B,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,0BAAO,WAAA,EAAU;AAAA,QACjB,cAAY;AAAA,QACZ,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,WAAU;AAAA,MAAA;AAAA,IAAA,EACZ,CACF;AAAA,EAAA,EAAA,CAEJ;AAEJ;AACA,aAAa,cAAc;AAMpB,MAAM,eAAe,MAAM;AAAA,EAChC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QACxB,oBAAC,OAAA,EAAI,KAAU,WAAW,GAAG,2BAA2B,SAAS,GAAI,GAAG,MAAA,CAAO;AAEnF;AACA,aAAa,cAAc;AAOpB,MAAM,cAAc,MAAM,WAG/B,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,uEAAuE,SAAS;AAAA,IAC7F,GAAG;AAAA,EAAA;AACN,CACD;AACD,YAAY,cAAc;AAOnB,MAAM,oBAAoB,MAAM,WAGrC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,6DAA6D,SAAS;AAAA,IACnF,GAAG;AAAA,EAAA;AACN,CACD;AACD,kBAAkB,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Drawer.mjs","sources":["../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["import * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { useDragToDismiss } from \"../../utils/useDragToDismiss\";\nimport { useSuppressClickAfterDrag } from \"../../utils/useSuppressClickAfterDrag\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\n\n/** The side from which the drawer slides in. */\nexport type DrawerPosition = \"left\" | \"right\" | \"top\" | \"bottom\";\n\n/** Size presets for the drawer panel. Maps to max-width (left/right) or max-height (top/bottom). */\nexport type DrawerSize = \"sm\" | \"md\" | \"lg\" | \"full\";\n\n/**\n * Visual treatment of the drawer panel.\n *\n * - `\"panel\"` (default) — the standard edge-anchored surface.\n * - `\"sheet\"` — a bottom-sheet treatment matching the modal surface: large\n * top-only radius (32px), modal background/stroke, and menu blur+shadow.\n * Intended for `position=\"bottom\"`.\n * - `\"menu\"` — a floating menu near the bottom edge rather than a sheet fixed to\n * it: inset from all three sides and rounded on every corner. Shares the modal\n * surface with `\"sheet\"`; only the shape differs. Intended for\n * `position=\"bottom\"`.\n */\nexport type DrawerVariant = \"panel\" | \"sheet\" | \"menu\";\n\n/**\n * Shared surface classes for the `\"sheet\"` variant. Mirrors the mobile sheet\n * treatment used by {@link Dialog} so bottom sheets are visually consistent.\n */\nconst SHEET_CLASSES =\n \"rounded-t-xl border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Surface and inset for the `\"menu\"` variant. Same modal background and stroke as\n * a sheet — the design puts this panel on `background/secondary` with\n * `border/strong`, not on the lighter surface the trigger-anchored dropdown uses.\n * The 24px radius is the design's `rounded-lg`.\n *\n * The insets restate position on purpose — they override `SLIDE_CLASSES.bottom`,\n * which pins a sheet flush to the bottom edge at full width.\n */\nconst MENU_CLASSES =\n \"inset-x-4 bottom-4 w-auto rounded-lg border border-modal-stroke bg-modal-background shadow-blur-menu backdrop-blur-[4px]\";\n\n/**\n * Props for the {@link Drawer} root component.\n *\n * Inherits `open`, `onOpenChange`, and `defaultOpen` from Radix Dialog.Root.\n *\n * The Radix `modal` prop (default `true`) can also be passed to create a\n * non-modal drawer — useful for persistent side navigation that does not\n * block interaction with the rest of the page.\n *\n * **`overlay` behaviour:** When `overlay` is `false`, the component\n * automatically sets `modal={false}` on the underlying Radix Dialog.Root.\n * A modal dialog without a visible overlay is confusing because focus is\n * still trapped and scroll is blocked even though the page appears\n * interactive. Passing `modal={true}` explicitly will override this.\n */\nexport interface DrawerProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root> {\n /**\n * Whether the default {@link DrawerOverlay} is rendered.\n * When `false`, `modal` is automatically set to `false` as well\n * (unless explicitly overridden) so focus-trap and scroll-lock are disabled.\n * @default true\n */\n overlay?: boolean;\n}\n\nconst DrawerContext = React.createContext<{ overlay: boolean }>({\n overlay: true,\n});\n\n/**\n * Root component that manages open/close state for a drawer.\n * Wraps Radix Dialog.Root.\n *\n * @example\n * ```tsx\n * <Drawer>\n * <DrawerTrigger>Open</DrawerTrigger>\n * <DrawerContent position=\"right\">\n * <DrawerHeader>\n * <DrawerTitle>Settings</DrawerTitle>\n * <DrawerDescription>Adjust your preferences.</DrawerDescription>\n * </DrawerHeader>\n * <p>Content goes here.</p>\n * <DrawerFooter>\n * <DrawerClose>Done</DrawerClose>\n * </DrawerFooter>\n * </DrawerContent>\n * </Drawer>\n * ```\n */\nexport function Drawer({ overlay = true, modal, children, ...props }: DrawerProps) {\n const resolvedModal = modal ?? (overlay ? undefined : false);\n return (\n <DrawerContext.Provider value={{ overlay }}>\n <DialogPrimitive.Root modal={resolvedModal} {...props}>\n {children}\n </DialogPrimitive.Root>\n </DrawerContext.Provider>\n );\n}\nDrawer.displayName = \"Drawer\";\n\n/** Props for the {@link DrawerTrigger} component. */\nexport type DrawerTriggerProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Trigger>;\n\n/**\n * The element that opens the drawer when clicked.\n *\n * On touch / pen, a press-and-release that crosses a small movement threshold\n * is treated as a drag and the resulting synthetic click is suppressed —\n * defends against Android Chrome opening the drawer on a scroll-drag-end.\n */\nexport const DrawerTrigger = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Trigger>,\n DrawerTriggerProps\n>((props, ref) => <DialogPrimitive.Trigger ref={ref} {...useSuppressClickAfterDrag(props)} />);\nDrawerTrigger.displayName = \"DrawerTrigger\";\n\n/** Props for the {@link DrawerClose} component. */\nexport type DrawerCloseProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>;\n\n/** Closes the drawer when clicked. Can be placed anywhere inside the drawer. */\nexport const DrawerClose = DialogPrimitive.Close;\nDrawerClose.displayName = \"DrawerClose\";\n\n/** Props for the {@link DrawerOverlay} component. */\nexport interface DrawerOverlayProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> {}\n\n/**\n * A translucent backdrop rendered behind the drawer content.\n * Clicking the overlay closes the drawer by default.\n */\nexport const DrawerOverlay = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Overlay>,\n DrawerOverlayProps\n>(({ className, style, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n style={{ zIndex: \"var(--fanvue-ui-portal-z-index, 50)\", ...style }}\n className={cn(\n \"fixed inset-0 bg-background-overlay-default\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:fade-in-0 data-[state=open]:duration-200 data-[state=open]:ease-out\",\n className,\n )}\n {...props}\n />\n));\nDrawerOverlay.displayName = \"DrawerOverlay\";\n\n/**\n * Slide-in animation classes keyed by position.\n * Uses Tailwind animate utilities (animate-in / animate-out).\n */\nconst SLIDE_CLASSES: Record<DrawerPosition, string> = {\n right:\n \"inset-y-0 right-0 h-full w-2/3 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right\",\n left: \"inset-y-0 left-0 h-full w-2/3 data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left\",\n top: \"inset-x-0 top-0 w-full data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top\",\n bottom:\n \"inset-x-0 bottom-0 w-full rounded-t-xs data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom\",\n};\n\n/** Props for the {@link DrawerContent} component. */\nexport interface DrawerContentProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {\n /**\n * The edge from which the drawer slides in.\n *\n * Named `position` (rather than `side`) to avoid confusion with the CSS\n * `side` concept used by Radix Popover/Tooltip and to better convey the\n * spatial relationship of the drawer to the viewport.\n *\n * @default \"right\"\n */\n position?: DrawerPosition;\n /**\n * Controls the maximum extent of the drawer panel.\n * For left/right drawers this sets `max-width`; for top/bottom it sets `max-height`.\n * @default \"sm\"\n */\n size?: DrawerSize;\n /**\n * Visual treatment of the panel. Use `\"sheet\"` (with `position=\"bottom\"`) for\n * a bottom sheet with the modal surface treatment, or `\"menu\"` for a floating\n * inset menu carrying the dropdown surface. @default \"panel\"\n */\n variant?: DrawerVariant;\n /**\n * Whether to render the default {@link DrawerOverlay} behind the content.\n * Set to `false` to provide your own overlay or omit it entirely.\n *\n * Prefer setting `overlay` on the {@link Drawer} root instead so that\n * `modal` is also adjusted automatically.\n *\n * @default true\n */\n overlay?: boolean;\n /** Props forwarded to the default {@link DrawerOverlay} when `overlay` is `true`. */\n overlayProps?: DrawerOverlayProps;\n}\n\n/**\n * The panel that slides in from the chosen edge. Renders inside a portal with\n * an overlay backdrop by default.\n *\n * Includes focus-trap, `aria-describedby`, and Escape-to-close from Radix Dialog.\n */\nexport const DrawerContent = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Content>,\n DrawerContentProps\n>(\n (\n {\n className,\n position = \"right\",\n size = \"sm\",\n variant = \"panel\",\n overlay: overlayProp,\n overlayProps,\n style,\n children,\n ...props\n },\n ref,\n ) => {\n const ctx = React.useContext(DrawerContext);\n const overlay = overlayProp ?? ctx.overlay;\n const closeRef = React.useRef<HTMLButtonElement>(null);\n const contentProps = useDragToDismiss(\n { enabled: position === \"bottom\", onDismiss: () => closeRef.current?.click() },\n props,\n );\n const isHorizontal = position === \"left\" || position === \"right\";\n const sizeClass = isHorizontal\n ? (\n {\n sm: \"max-w-sm\",\n md: \"max-w-md\",\n lg: \"max-w-lg\",\n full: \"max-w-full\",\n } as const\n )[size]\n : (\n {\n sm: \"max-h-[24rem]\",\n md: \"max-h-[28rem]\",\n lg: \"max-h-[32rem]\",\n full: \"max-h-full\",\n } as const\n )[size];\n\n return (\n <DialogPrimitive.Portal>\n {overlay && <DrawerOverlay {...overlayProps} />}\n <DialogPrimitive.Content\n ref={ref}\n style={{\n zIndex: \"calc(var(--fanvue-ui-portal-z-index, 50) + 1)\",\n ...style,\n }}\n className={cn(\n \"fixed flex flex-col bg-surface-secondary outline-none backdrop-blur-lg\",\n // `shadow-lg` is scoped to `panel` rather than sitting in the base classes.\n // tailwind-merge does not recognise `shadow-blur-menu` as a box-shadow\n // utility, so it never deduped the two and `shadow-lg` won on stylesheet\n // order — meaning the sheet and menu surfaces silently rendered `shadow-lg`\n // instead of the menu shadow their tokens name.\n variant === \"panel\" && \"shadow-lg\",\n \"data-[state=closed]:animate-out data-[state=open]:animate-in\",\n \"data-[state=closed]:duration-150 data-[state=closed]:ease-in\",\n \"data-[state=open]:duration-200 data-[state=open]:ease-out\",\n SLIDE_CLASSES[position],\n sizeClass,\n variant === \"sheet\" && SHEET_CLASSES,\n variant === \"menu\" && MENU_CLASSES,\n className,\n )}\n {...contentProps}\n >\n <DialogPrimitive.Close ref={closeRef} hidden tabIndex={-1} aria-hidden=\"true\" />\n {children}\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n );\n },\n);\nDrawerContent.displayName = \"DrawerContent\";\n\n/** Props for the {@link DrawerHeader} component. */\nexport interface DrawerHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Whether to show a built-in close (X) button. @default true */\n showClose?: boolean;\n /** Accessible label for the close button. @default \"Close drawer\" */\n closeLabel?: string;\n}\n\n/**\n * A semantic header area for the drawer, typically containing a title and description.\n * Renders a built-in close button by default.\n */\nexport const DrawerHeader = React.forwardRef<HTMLDivElement, DrawerHeaderProps>(\n ({ className, showClose = true, closeLabel = \"Close drawer\", children, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex items-center gap-2 p-4\", className)} {...props}>\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">{children}</div>\n {showClose && (\n <DialogPrimitive.Close asChild>\n <IconButton\n icon={<CloseIcon />}\n aria-label={closeLabel}\n variant=\"secondary\"\n size=\"32\"\n className=\"shrink-0\"\n />\n </DialogPrimitive.Close>\n )}\n </div>\n ),\n);\nDrawerHeader.displayName = \"DrawerHeader\";\n\n/** Props for the {@link DrawerFooter} component. */\nexport interface DrawerFooterProps extends React.HTMLAttributes<HTMLDivElement> {}\n\n/** A semantic footer area for the drawer, typically containing action buttons. */\nexport const DrawerFooter = React.forwardRef<HTMLDivElement, DrawerFooterProps>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex flex-col gap-2 p-4\", className)} {...props} />\n ),\n);\nDrawerFooter.displayName = \"DrawerFooter\";\n\n/** Props for the {@link DrawerTitle} component. */\nexport interface DrawerTitleProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> {}\n\n/** An accessible title for the drawer. Required for screen readers. */\nexport const DrawerTitle = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Title>,\n DrawerTitleProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn(\"typography-body-default-16px-semibold truncate text-content-primary\", className)}\n {...props}\n />\n));\nDrawerTitle.displayName = \"DrawerTitle\";\n\n/** Props for the {@link DrawerDescription} component. */\nexport interface DrawerDescriptionProps\n extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> {}\n\n/** An accessible description for the drawer, providing supplementary context. */\nexport const DrawerDescription = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Description>,\n DrawerDescriptionProps\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description\n ref={ref}\n className={cn(\"typography-body-small-14px-regular text-content-secondary\", className)}\n {...props}\n />\n));\nDrawerDescription.displayName = \"DrawerDescription\";\n"],"names":[],"mappings":";;;;;;;;;AAgCA,MAAM,gBACJ;AAWF,MAAM,eACJ;AA2BF,MAAM,gBA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wC,SAAA,CAAS;AAAA,IAC/D,aACC,oBAAC,gBAAgB,OAAhB,EAAsB,SAAO,MAC5B,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,0BAAO,WAAA,EAAU;AAAA,QACjB,cAAY;AAAA,QACZ,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,WAAU;AAAA,MAAA;AAAA,IAAA,EACZ,CACF;AAAA,EAAA,EAAA,CAEJ;AAEJ;AACA,aAAa,cAAc;AAMpB,MAAM,eAAe,MAAM;AAAA,EAChC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QACxB,oBAAC,OAAA,EAAI,KAAU,WAAW,GAAG,2BAA2B,SAAS,GAAI,GAAG,MAAA,CAAO;AAEnF;AACA,aAAa,cAAc;AAOpB,MAAM,cAAc,MAAM,WAG/B,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,uEAAuE,SAAS;AAAA,IAC7F,GAAG;AAAA,EAAA;AACN,CACD;AACD,YAAY,cAAc;AAOnB,MAAM,oBAAoB,MAAM,WAGrC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1B;AAAA,EAAC,gBAAgB;AAAA,EAAhB;AAAA,IACC;AAAA,IACA,WAAW,GAAG,6DAA6D,SAAS;AAAA,IACnF,GAAG;AAAA,EAAA;AACN,CACD;AACD,kBAAkB,cAAc;"}
|
|
@@ -112,7 +112,7 @@ const DropdownMenuHeader = React.forwardRef(
|
|
|
112
112
|
]
|
|
113
113
|
}
|
|
114
114
|
),
|
|
115
|
-
/* @__PURE__ */ jsx(DropdownMenuSeparator, { className: "-mx-2 my-0 bg-border-
|
|
115
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, { className: "-mx-2 my-0 bg-border-primary" })
|
|
116
116
|
]
|
|
117
117
|
}
|
|
118
118
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenuHeader.mjs","sources":["../../../src/components/DropdownMenu/DropdownMenuHeader.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { ArrowLeftIcon } from \"../Icons/ArrowLeftIcon\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { SearchIcon } from \"../Icons/SearchIcon\";\nimport { DropdownMenuVariantContext, ToggleOpenContext } from \"./context\";\nimport { DropdownMenuSeparator } from \"./DropdownMenuItem\";\n\n// Keys that the menu must keep handling even when focus is inside a child\n// input — arrows move the highlight into the list, Tab leaves the menu, and\n// Enter / Escape close it.\nconst NAVIGATION_KEYS = new Set([\n \"ArrowDown\",\n \"ArrowUp\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Escape\",\n \"Tab\",\n \"Enter\",\n]);\n\n/** Header type. `\"default\"` shows a title; `\"search\"` shows a search input. */\nexport type DropdownMenuHeaderType = \"default\" | \"search\";\n\n/** Header height preset. Matches the menu item sizing scale. */\nexport type DropdownMenuHeaderSize = \"40\" | \"32\";\n\n/** Search-input configuration for {@link DropdownMenuHeader} when `type=\"search\"`. */\nexport interface DropdownMenuHeaderSearchProps {\n /** Controlled value of the search input. */\n value?: string;\n /** Uncontrolled default value. */\n defaultValue?: string;\n /** Fires when the input value changes. */\n onChange?: (value: string) => void;\n /** Placeholder text shown when the input is empty. @default \"Search…\" */\n placeholder?: string;\n /** Accessible label for the search input. @default \"Search\" */\n \"aria-label\"?: string;\n /**\n * Focus the input as soon as the menu opens, so typing filters immediately.\n * Radix parks initial focus on the content element (which is what drives its\n * typeahead), so without this the first keystrokes never reach the input.\n */\n autoFocus?: boolean;\n}\n\nexport interface DropdownMenuHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Visual type. `\"default\"` shows a title; `\"search\"` shows a search input. @default \"default\" */\n type?: DropdownMenuHeaderType;\n /** Height preset for the header row. @default \"40\" */\n size?: DropdownMenuHeaderSize;\n /** Title text shown when `type=\"default\"`. Ignored if `children` is provided. */\n title?: string;\n /** Configuration for the embedded search input when `type=\"search\"`. */\n searchProps?: DropdownMenuHeaderSearchProps;\n /**\n * Action elements rendered at the end of the header row, before the close\n * button — e.g. icon buttons for search/add, or a primary \"Done\" button that\n * commits a {@link DropdownMenuReorderGroup} reorder. An action that should\n * close the menu needs the menu's `open` state controlled (only the built-in\n * close button can dismiss an uncontrolled menu).\n */\n actions?: React.ReactNode;\n /** Whether to render the close icon button on the right. @default true */\n showClose?: boolean;\n /** Fires when the close icon button is activated. */\n onClose?: () => void;\n /** Accessible label for the close button. @default \"Close menu\" */\n closeLabel?: string;\n /**\n * Fires when the back icon button at the start of the row is activated.\n * Rendering it lets a menu step back from a sub-view — a `type=\"search\"`\n * header returning to its title, for instance — without closing the menu.\n */\n onBack?: () => void;\n /** Whether to render the back icon button. @default `onBack !== undefined` */\n showBack?: boolean;\n /** Accessible label for the back button. @default \"Back\" */\n backLabel?: string;\n}\n\n/**\n * Optional header rendered at the top of a {@link DropdownMenuContent}. Use\n * `type=\"default\"` to title the menu, or `type=\"search\"` to embed a search\n * input for filtering long lists.\n *\n * Renders an inset separator beneath the row so it slots cleanly above the\n * first group of items.\n *\n * @example\n * ```tsx\n * <DropdownMenuContent>\n * <DropdownMenuHeader title=\"Sort by\" onClose={() => setOpen(false)} />\n * <DropdownMenuItem>Newest</DropdownMenuItem>\n * <DropdownMenuItem>Oldest</DropdownMenuItem>\n * </DropdownMenuContent>\n * ```\n */\nexport const DropdownMenuHeader = React.forwardRef<HTMLDivElement, DropdownMenuHeaderProps>(\n (\n {\n type = \"default\",\n size = \"40\",\n title,\n searchProps,\n actions,\n showClose = true,\n onClose,\n closeLabel = \"Close menu\",\n onBack,\n showBack = onBack !== undefined,\n backLabel = \"Back\",\n className,\n children,\n ...props\n },\n ref,\n ) => {\n // Regular, not semibold: `V2 Menu Header` titles the menu at\n // `Body Default 16px/Regular`. The weight belongs to the rows' own titles,\n // which is where the two-line layout puts a semibold.\n const titleTypography =\n size === \"32\" ? \"typography-body-small-14px-regular\" : \"typography-body-default-16px-regular\";\n const toggleOpen = React.useContext(ToggleOpenContext);\n const variant = React.useContext(DropdownMenuVariantContext);\n\n const handleClose = () => {\n onClose?.();\n // Also dismiss the Radix menu when used in uncontrolled mode — otherwise\n // the close button would look broken to consumers that don't wire up\n // `open` / `onOpenChange` themselves.\n toggleOpen?.(() => false);\n };\n\n return (\n <div\n ref={ref}\n className={cn(\n \"mb-1 flex flex-col px-1 pt-1\",\n // Search needs an 8px gap between the input and the divider; the\n // default (title) variant uses 4px because the title baseline sits\n // closer to the divider naturally.\n type === \"search\" ? \"gap-2\" : \"gap-1\",\n // With action buttons the design draws a roomier header: 12px above\n // the 32px actions row (the panel's own 4px padding makes up the\n // difference), 8px between it and the divider, and 8px between the\n // divider and the first row.\n actions != null && \"mb-2 gap-2 pt-2\",\n // The sheet is a taller, roomier surface than a trigger-anchored panel:\n // the design sets 16px between the rule and the first row, which this\n // margin plus the panel's own 4px gap adds up to.\n variant === \"sheet\" && \"mb-3\",\n className,\n )}\n {...props}\n >\n {/*\n * The title is inset a further 8px so it clears the panel's rounded\n * corner; the search input is not, because the design runs it to the\n * header's own padding (`V2 Menu Dropdown` node `7393:62008`: the search\n * row is `flex gap-16 w-full` with no inset, so the field sits 8px from\n * the panel edge on both sides). Insetting it left-only left the field\n * 16px in on the left and 8px on the right.\n */}\n <div\n className={cn(\n \"flex items-center gap-4\",\n // With action buttons the title sits a further 4px in (20px from\n // the panel edge) than the close-only header's 16px. A back button\n // supplies its own inset.\n type === \"default\" && !showBack && (actions != null ? \"pl-3\" : \"pl-2\"),\n )}\n >\n {showBack && (\n <div data-dropdown-menu-tab-stops=\"\" className=\"flex shrink-0 items-center\">\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<ArrowLeftIcon />}\n onClick={onBack}\n aria-label={backLabel}\n />\n </div>\n )}\n {type === \"default\" ? (\n <div className={cn(\"min-w-0 flex-1 truncate text-content-primary\", titleTypography)}>\n {children ?? title}\n </div>\n ) : (\n <SearchInput {...searchProps} />\n )}\n {(actions != null || showClose) && (\n // The extra right margin only applies with action buttons: filled\n // actions like a \"Done\" pill sit 12px off the panel edge, while the\n // bare tertiary close icon keeps the header's own 8px inset.\n <div\n data-dropdown-menu-tab-stops=\"\"\n className={cn(\"flex shrink-0 items-center gap-1\", actions != null && \"mr-1\")}\n >\n {actions}\n {showClose && (\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<CloseIcon />}\n onClick={handleClose}\n aria-label={closeLabel}\n />\n )}\n </div>\n )}\n </div>\n {/*\n * Full-bleed, as the design draws it: the rule runs the panel's whole\n * width rather than stopping at the text. `-mx-2` cancels both insets it\n * sits inside — this header's own `px-1` and the content panel's `p-1`.\n *\n * `border-strong` is the colour the design gives this rule. The separator's\n * own default is `neutral-alphas-200`, which in the dark theme is a 20%\n * *white* alpha — as a hairline running the full width it reads as a white\n * line rather than a divider. Group separators between items keep the\n * alpha; this is the header's rule only.\n */}\n <DropdownMenuSeparator className=\"-mx-2 my-0 bg-border-strong\" />\n </div>\n );\n },\n);\nDropdownMenuHeader.displayName = \"DropdownMenuHeader\";\n\nfunction SearchInput({\n value,\n defaultValue,\n onChange,\n placeholder = \"Search\\u2026\",\n \"aria-label\": ariaLabel = \"Search\",\n autoFocus,\n}: DropdownMenuHeaderSearchProps = {}) {\n const inputRef = React.useRef<HTMLInputElement>(null);\n\n // Focus after mount rather than via the `autoFocus` attribute, so the focus\n // move is explicit and only happens when the consumer asked for it.\n React.useEffect(() => {\n if (autoFocus) inputRef.current?.focus();\n }, [autoFocus]);\n\n return (\n <label\n data-dropdown-menu-tab-stops=\"\"\n className={cn(\n \"flex min-w-0 flex-1 items-center gap-2 rounded-xs border border-border-primary\",\n \"bg-inputs-inputs-primary px-3 py-1 text-content-primary\",\n \"focus-within:shadow-focus-ring focus-within:outline-none\",\n )}\n >\n <SearchIcon className=\"size-4 shrink-0 text-content-primary\" aria-hidden=\"true\" />\n <input\n type=\"search\"\n className={cn(\n \"typography-body-default-16px-regular min-w-0 flex-1 bg-transparent outline-none\",\n \"placeholder:text-content-tertiary\",\n )}\n ref={inputRef}\n value={value}\n defaultValue={defaultValue}\n placeholder={placeholder}\n aria-label={ariaLabel}\n onChange={(event) => onChange?.(event.target.value)}\n // Radix DropdownMenu listens for keystrokes on Content for its\n // typeahead (typing letters jumps focus to a matching item). That\n // listener steals focus from the input after the first letter, so we\n // stop character keys from bubbling. Navigation keys (arrows / Tab /\n // Escape / Enter) are still allowed through so the user can leave the\n // input for the list or close the menu. Pointer events are stopped so\n // clicking back into the input doesn't fight the menu's focus\n // management either.\n onKeyDown={(event) => {\n if (!NAVIGATION_KEYS.has(event.key)) event.stopPropagation();\n }}\n onPointerDown={(event) => event.stopPropagation()}\n onMouseDown={(event) => event.stopPropagation()}\n />\n </label>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AAYA,MAAM,sCAAsB,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAgFM,MAAM,qBAAqB,MAAM;AAAA,EACtC,CACE;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AAIH,UAAM,kBACJ,SAAS,OAAO,uCAAuC;AACzD,UAAM,aAAa,MAAM,WAAW,iBAAiB;AACrD,UAAM,UAAU,MAAM,WAAW,0BAA0B;AAE3D,UAAM,cAAc,MAAM;AACxB,gBAAA;AAIA,mBAAa,MAAM,KAAK;AAAA,IAC1B;AAEA,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT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AA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGrE;AACF;AACA,mBAAmB,cAAc;AAEjC,SAAS,YAAY;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,cAAc,YAAY;AAAA,EAC1B;AACF,IAAmC,IAAI;AACrC,QAAM,WAAW,MAAM,OAAyB,IAAI;AAIpD,QAAM,UAAU,MAAM;AACpB,QAAI,UAAW,UAAS,SAAS,MAAA;AAAA,EACnC,GAAG,CAAC,SAAS,CAAC;AAEd,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,gCAA6B;AAAA,MAC7B,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAGF,UAAA;AAAA,QAAA,oBAAC,YAAA,EAAW,WAAU,wCAAuC,eAAY,QAAO;AAAA,QAChF;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAW;AAAA,cACT;AAAA,cACA;AAAA,YAAA;AAAA,YAEF,KAAK;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA,cAAY;AAAA,YACZ,UAAU,CAAC,UAAU,WAAW,MAAM,OAAO,KAAK;AAAA,YASlD,WAAW,CAAC,UAAU;AACpB,kBAAI,CAAC,gBAAgB,IAAI,MAAM,GAAG,SAAS,gBAAA;AAAA,YAC7C;AAAA,YACA,eAAe,CAAC,UAAU,MAAM,gBAAA;AAAA,YAChC,aAAa,CAAC,UAAU,MAAM,gBAAA;AAAA,UAAgB;AAAA,QAAA;AAAA,MAChD;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"DropdownMenuHeader.mjs","sources":["../../../src/components/DropdownMenu/DropdownMenuHeader.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { ArrowLeftIcon } from \"../Icons/ArrowLeftIcon\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { SearchIcon } from \"../Icons/SearchIcon\";\nimport { DropdownMenuVariantContext, ToggleOpenContext } from \"./context\";\nimport { DropdownMenuSeparator } from \"./DropdownMenuItem\";\n\n// Keys that the menu must keep handling even when focus is inside a child\n// input — arrows move the highlight into the list, Tab leaves the menu, and\n// Enter / Escape close it.\nconst NAVIGATION_KEYS = new Set([\n \"ArrowDown\",\n \"ArrowUp\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Escape\",\n \"Tab\",\n \"Enter\",\n]);\n\n/** Header type. `\"default\"` shows a title; `\"search\"` shows a search input. */\nexport type DropdownMenuHeaderType = \"default\" | \"search\";\n\n/** Header height preset. Matches the menu item sizing scale. */\nexport type DropdownMenuHeaderSize = \"40\" | \"32\";\n\n/** Search-input configuration for {@link DropdownMenuHeader} when `type=\"search\"`. */\nexport interface DropdownMenuHeaderSearchProps {\n /** Controlled value of the search input. */\n value?: string;\n /** Uncontrolled default value. */\n defaultValue?: string;\n /** Fires when the input value changes. */\n onChange?: (value: string) => void;\n /** Placeholder text shown when the input is empty. @default \"Search…\" */\n placeholder?: string;\n /** Accessible label for the search input. @default \"Search\" */\n \"aria-label\"?: string;\n /**\n * Focus the input as soon as the menu opens, so typing filters immediately.\n * Radix parks initial focus on the content element (which is what drives its\n * typeahead), so without this the first keystrokes never reach the input.\n */\n autoFocus?: boolean;\n}\n\nexport interface DropdownMenuHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Visual type. `\"default\"` shows a title; `\"search\"` shows a search input. @default \"default\" */\n type?: DropdownMenuHeaderType;\n /** Height preset for the header row. @default \"40\" */\n size?: DropdownMenuHeaderSize;\n /** Title text shown when `type=\"default\"`. Ignored if `children` is provided. */\n title?: string;\n /** Configuration for the embedded search input when `type=\"search\"`. */\n searchProps?: DropdownMenuHeaderSearchProps;\n /**\n * Action elements rendered at the end of the header row, before the close\n * button — e.g. icon buttons for search/add, or a primary \"Done\" button that\n * commits a {@link DropdownMenuReorderGroup} reorder. An action that should\n * close the menu needs the menu's `open` state controlled (only the built-in\n * close button can dismiss an uncontrolled menu).\n */\n actions?: React.ReactNode;\n /** Whether to render the close icon button on the right. @default true */\n showClose?: boolean;\n /** Fires when the close icon button is activated. */\n onClose?: () => void;\n /** Accessible label for the close button. @default \"Close menu\" */\n closeLabel?: string;\n /**\n * Fires when the back icon button at the start of the row is activated.\n * Rendering it lets a menu step back from a sub-view — a `type=\"search\"`\n * header returning to its title, for instance — without closing the menu.\n */\n onBack?: () => void;\n /** Whether to render the back icon button. @default `onBack !== undefined` */\n showBack?: boolean;\n /** Accessible label for the back button. @default \"Back\" */\n backLabel?: string;\n}\n\n/**\n * Optional header rendered at the top of a {@link DropdownMenuContent}. Use\n * `type=\"default\"` to title the menu, or `type=\"search\"` to embed a search\n * input for filtering long lists.\n *\n * Renders an inset separator beneath the row so it slots cleanly above the\n * first group of items.\n *\n * @example\n * ```tsx\n * <DropdownMenuContent>\n * <DropdownMenuHeader title=\"Sort by\" onClose={() => setOpen(false)} />\n * <DropdownMenuItem>Newest</DropdownMenuItem>\n * <DropdownMenuItem>Oldest</DropdownMenuItem>\n * </DropdownMenuContent>\n * ```\n */\nexport const DropdownMenuHeader = React.forwardRef<HTMLDivElement, DropdownMenuHeaderProps>(\n (\n {\n type = \"default\",\n size = \"40\",\n title,\n searchProps,\n actions,\n showClose = true,\n onClose,\n closeLabel = \"Close menu\",\n onBack,\n showBack = onBack !== undefined,\n backLabel = \"Back\",\n className,\n children,\n ...props\n },\n ref,\n ) => {\n // Regular, not semibold: `V2 Menu Header` titles the menu at\n // `Body Default 16px/Regular`. The weight belongs to the rows' own titles,\n // which is where the two-line layout puts a semibold.\n const titleTypography =\n size === \"32\" ? \"typography-body-small-14px-regular\" : \"typography-body-default-16px-regular\";\n const toggleOpen = React.useContext(ToggleOpenContext);\n const variant = React.useContext(DropdownMenuVariantContext);\n\n const handleClose = () => {\n onClose?.();\n // Also dismiss the Radix menu when used in uncontrolled mode — otherwise\n // the close button would look broken to consumers that don't wire up\n // `open` / `onOpenChange` themselves.\n toggleOpen?.(() => false);\n };\n\n return (\n <div\n ref={ref}\n className={cn(\n \"mb-1 flex flex-col px-1 pt-1\",\n // Search needs an 8px gap between the input and the divider; the\n // default (title) variant uses 4px because the title baseline sits\n // closer to the divider naturally.\n type === \"search\" ? \"gap-2\" : \"gap-1\",\n // With action buttons the design draws a roomier header: 12px above\n // the 32px actions row (the panel's own 4px padding makes up the\n // difference), 8px between it and the divider, and 8px between the\n // divider and the first row.\n actions != null && \"mb-2 gap-2 pt-2\",\n // The sheet is a taller, roomier surface than a trigger-anchored panel:\n // the design sets 16px between the rule and the first row, which this\n // margin plus the panel's own 4px gap adds up to.\n variant === \"sheet\" && \"mb-3\",\n className,\n )}\n {...props}\n >\n {/*\n * The title is inset a further 8px so it clears the panel's rounded\n * corner; the search input is not, because the design runs it to the\n * header's own padding (`V2 Menu Dropdown` node `7393:62008`: the search\n * row is `flex gap-16 w-full` with no inset, so the field sits 8px from\n * the panel edge on both sides). Insetting it left-only left the field\n * 16px in on the left and 8px on the right.\n */}\n <div\n className={cn(\n \"flex items-center gap-4\",\n // With action buttons the title sits a further 4px in (20px from\n // the panel edge) than the close-only header's 16px. A back button\n // supplies its own inset.\n type === \"default\" && !showBack && (actions != null ? \"pl-3\" : \"pl-2\"),\n )}\n >\n {showBack && (\n <div data-dropdown-menu-tab-stops=\"\" className=\"flex shrink-0 items-center\">\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<ArrowLeftIcon />}\n onClick={onBack}\n aria-label={backLabel}\n />\n </div>\n )}\n {type === \"default\" ? (\n <div className={cn(\"min-w-0 flex-1 truncate text-content-primary\", titleTypography)}>\n {children ?? title}\n </div>\n ) : (\n <SearchInput {...searchProps} />\n )}\n {(actions != null || showClose) && (\n // The extra right margin only applies with action buttons: filled\n // actions like a \"Done\" pill sit 12px off the panel edge, while the\n // bare tertiary close icon keeps the header's own 8px inset.\n <div\n data-dropdown-menu-tab-stops=\"\"\n className={cn(\"flex shrink-0 items-center gap-1\", actions != null && \"mr-1\")}\n >\n {actions}\n {showClose && (\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<CloseIcon />}\n onClick={handleClose}\n aria-label={closeLabel}\n />\n )}\n </div>\n )}\n </div>\n {/*\n * Full-bleed, as the design draws it: the rule runs the panel's whole\n * width rather than stopping at the text. `-mx-2` cancels both insets it\n * sits inside — this header's own `px-1` and the content panel's `p-1`.\n *\n * `Border/Primary` is the token the design binds to this rule. The\n * separator's own default is `neutral-alphas-200`, which in the dark theme\n * is a 20% *white* alpha — as a hairline running the full width it reads as\n * a white line rather than a divider. Group separators between items keep\n * the alpha; this is the header's rule only.\n */}\n <DropdownMenuSeparator className=\"-mx-2 my-0 bg-border-primary\" />\n </div>\n );\n },\n);\nDropdownMenuHeader.displayName = \"DropdownMenuHeader\";\n\nfunction SearchInput({\n value,\n defaultValue,\n onChange,\n placeholder = \"Search\\u2026\",\n \"aria-label\": ariaLabel = \"Search\",\n autoFocus,\n}: DropdownMenuHeaderSearchProps = {}) {\n const inputRef = React.useRef<HTMLInputElement>(null);\n\n // Focus after mount rather than via the `autoFocus` attribute, so the focus\n // move is explicit and only happens when the consumer asked for it.\n React.useEffect(() => {\n if (autoFocus) inputRef.current?.focus();\n }, [autoFocus]);\n\n return (\n <label\n data-dropdown-menu-tab-stops=\"\"\n className={cn(\n \"flex min-w-0 flex-1 items-center gap-2 rounded-xs border border-border-primary\",\n \"bg-inputs-inputs-primary px-3 py-1 text-content-primary\",\n \"focus-within:shadow-focus-ring focus-within:outline-none\",\n )}\n >\n <SearchIcon className=\"size-4 shrink-0 text-content-primary\" aria-hidden=\"true\" />\n <input\n type=\"search\"\n className={cn(\n \"typography-body-default-16px-regular min-w-0 flex-1 bg-transparent outline-none\",\n \"placeholder:text-content-tertiary\",\n )}\n ref={inputRef}\n value={value}\n defaultValue={defaultValue}\n placeholder={placeholder}\n aria-label={ariaLabel}\n onChange={(event) => onChange?.(event.target.value)}\n // Radix DropdownMenu listens for keystrokes on Content for its\n // typeahead (typing letters jumps focus to a matching item). That\n // listener steals focus from the input after the first letter, so we\n // stop character keys from bubbling. Navigation keys (arrows / Tab /\n // Escape / Enter) are still allowed through so the user can leave the\n // input for the list or close the menu. Pointer events are stopped so\n // clicking back into the input doesn't fight the menu's focus\n // management either.\n onKeyDown={(event) => {\n if (!NAVIGATION_KEYS.has(event.key)) event.stopPropagation();\n }}\n onPointerDown={(event) => event.stopPropagation()}\n onMouseDown={(event) => event.stopPropagation()}\n />\n </label>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AAYA,MAAM,sCAAsB,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAgFM,MAAM,qBAAqB,MAAM;AAAA,EACtC,CACE;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AAIH,UAAM,kBACJ,SAAS,OAAO,uCAAuC;AACzD,UAAM,aAAa,MAAM,WAAW,iBAAiB;AACrD,UAAM,UAAU,MAAM,WAAW,0BAA0B;AAE3D,UAAM,cAAc,MAAM;AACxB,gBAAA;AAIA,mBAAa,MAAM,KAAK;AAAA,IAC1B;AAEA,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA;AAAA;AAAA;AAAA,UAIA,SAAS,WAAW,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,UAK9B,WAAW,QAAQ;AAAA;AAAA;AAAA;AAAA,UAInB,YAAY,WAAW;AAAA,UACvB;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAUJ,UAAA;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AAM,WAAW,MAAM,OAAyB,IAAI;AAIpD,QAAM,UAAU,MAAM;AACpB,QAAI,UAAW,UAAS,SAAS,MAAA;AAAA,EACnC,GAAG,CAAC,SAAS,CAAC;AAEd,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,gCAA6B;AAAA,MAC7B,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAGF,UAAA;AAAA,QAAA,oBAAC,YAAA,EAAW,WAAU,wCAAuC,eAAY,QAAO;AAAA,QAChF;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,WAAW;AAAA,cACT;AAAA,cACA;AAAA,YAAA;AAAA,YAEF,KAAK;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA,cAAY;AAAA,YACZ,UAAU,CAAC,UAAU,WAAW,MAAM,OAAO,KAAK;AAAA,YASlD,WAAW,CAAC,UAAU;AACpB,kBAAI,CAAC,gBAAgB,IAAI,MAAM,GAAG,SAAS,gBAAA;AAAA,YAC7C;AAAA,YACA,eAAe,CAAC,UAAU,MAAM,gBAAA;AAAA,YAChC,aAAa,CAAC,UAAU,MAAM,gBAAA;AAAA,UAAgB;AAAA,QAAA;AAAA,MAChD;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -14,6 +14,7 @@ const SearchField = React.forwardRef(
|
|
|
14
14
|
minChars,
|
|
15
15
|
onChange,
|
|
16
16
|
clearAriaLabel = "Clear search",
|
|
17
|
+
size = "48",
|
|
17
18
|
...props
|
|
18
19
|
}, ref) => {
|
|
19
20
|
const [internalValue, setInternalValue] = React.useState(value ?? "");
|
|
@@ -54,7 +55,8 @@ const SearchField = React.forwardRef(
|
|
|
54
55
|
onClear?.();
|
|
55
56
|
}, [onClear]);
|
|
56
57
|
const displayValue = debounceMs || minChars ? internalValue : value;
|
|
57
|
-
const
|
|
58
|
+
const isCompact = size === "32";
|
|
59
|
+
const leftIcon = /* @__PURE__ */ jsx(SearchIcon, { size: isCompact ? 16 : 24 });
|
|
58
60
|
const showClearButton = onClear && displayValue !== void 0 && displayValue !== "";
|
|
59
61
|
const rightIcon = showClearButton ? /* @__PURE__ */ jsx(
|
|
60
62
|
IconButton,
|
|
@@ -72,8 +74,10 @@ const SearchField = React.forwardRef(
|
|
|
72
74
|
{
|
|
73
75
|
ref,
|
|
74
76
|
type: "search",
|
|
77
|
+
size,
|
|
75
78
|
disabled,
|
|
76
79
|
leftIcon,
|
|
80
|
+
leftIconSize: isCompact ? "16" : "24",
|
|
77
81
|
rightIcon,
|
|
78
82
|
value: displayValue,
|
|
79
83
|
onChange: handleChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchField.mjs","sources":["../../../src/components/SearchField/SearchField.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { SearchIcon } from \"../Icons/SearchIcon\";\nimport { TextField, type TextFieldProps } from \"../TextField/TextField\";\n\nexport type SearchFieldSize = \"48\" | \"40\" | \"32\";\n\nexport interface SearchFieldProps
|
|
1
|
+
{"version":3,"file":"SearchField.mjs","sources":["../../../src/components/SearchField/SearchField.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { CloseIcon } from \"../Icons/CloseIcon\";\nimport { SearchIcon } from \"../Icons/SearchIcon\";\nimport { TextField, type TextFieldProps } from \"../TextField/TextField\";\n\nexport type SearchFieldSize = \"48\" | \"40\" | \"32\";\n\nexport interface SearchFieldProps\n extends Omit<TextFieldProps, \"type\" | \"leftIcon\" | \"leftIconSize\"> {\n /** Size variant of the search field. @default \"48\" */\n size?: SearchFieldSize;\n /** Callback fired when the clear button is clicked. If provided, a clear button appears when the field has a value. */\n onClear?: () => void;\n /** Debounce delay in milliseconds for the onChange callback. When set, the input maintains internal state for responsive typing while debouncing onChange to the parent. */\n debounceMs?: number;\n /** Minimum number of characters required before onChange fires. The input still updates visually, but onChange is suppressed until the threshold is met. Clearing always fires onClear regardless. */\n minChars?: number;\n /** Accessible name for the clear button. @default \"Clear search\" */\n clearAriaLabel?: string;\n}\n\n/**\n * A text input field with a search icon and optional clear button.\n *\n * @example\n * ```tsx\n * <SearchField\n * placeholder=\"Search...\"\n * value={query}\n * onChange={(e) => setQuery(e.target.value)}\n * onClear={() => setQuery(\"\")}\n * debounceMs={500}\n * minChars={3}\n * />\n * ```\n */\nexport const SearchField = React.forwardRef<HTMLInputElement, SearchFieldProps>(\n (\n {\n disabled,\n onClear,\n value,\n debounceMs,\n minChars,\n onChange,\n clearAriaLabel = \"Clear search\",\n size = \"48\",\n ...props\n },\n ref,\n ) => {\n const [internalValue, setInternalValue] = React.useState(value ?? \"\");\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n\n React.useEffect(() => {\n if (value !== undefined) {\n setInternalValue(value);\n }\n }, [value]);\n\n React.useEffect(() => {\n return () => {\n if (timeoutRef.current) clearTimeout(timeoutRef.current);\n };\n }, []);\n\n const shouldFireChange = React.useCallback(\n (val: string) => !minChars || val.length >= minChars,\n [minChars],\n );\n\n const handleChange = React.useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const val = e.target.value;\n\n if (!debounceMs) {\n setInternalValue(val);\n if (shouldFireChange(val)) onChange?.(e);\n return;\n }\n\n setInternalValue(val);\n\n if (timeoutRef.current) clearTimeout(timeoutRef.current);\n\n timeoutRef.current = setTimeout(() => {\n if (shouldFireChange(val)) onChange?.(e);\n }, debounceMs);\n },\n [debounceMs, onChange, shouldFireChange],\n );\n\n const handleClear = React.useCallback(() => {\n if (timeoutRef.current) clearTimeout(timeoutRef.current);\n setInternalValue(\"\");\n onClear?.();\n }, [onClear]);\n\n const displayValue = debounceMs || minChars ? internalValue : value;\n const isCompact = size === \"32\";\n const leftIcon = <SearchIcon size={isCompact ? 16 : 24} />;\n\n const showClearButton = onClear && displayValue !== undefined && displayValue !== \"\";\n\n const rightIcon = showClearButton ? (\n <IconButton\n variant=\"tertiary\"\n size=\"24\"\n icon={<CloseIcon />}\n aria-label={clearAriaLabel}\n disabled={disabled}\n onClick={handleClear}\n />\n ) : undefined;\n\n return (\n <TextField\n ref={ref}\n type=\"search\"\n size={size}\n disabled={disabled}\n leftIcon={leftIcon}\n leftIconSize={isCompact ? \"16\" : \"24\"}\n rightIcon={rightIcon}\n value={displayValue}\n onChange={handleChange}\n aria-label={!props.label ? \"Search field\" : undefined}\n {...props}\n />\n );\n },\n);\n\nSearchField.displayName = \"SearchField\";\n"],"names":[],"mappings":";;;;;;;AAqCO,MAAM,cAAc,MAAM;AAAA,EAC/B,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB,OAAO;AAAA,IACP,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,CAAC,eAAe,gBAAgB,IAAI,MAAM,SAAS,SAAS,EAAE;AACpE,UAAM,aAAa,MAAM,OAAsC,MAAS;AAExE,UAAM,UAAU,MAAM;AACpB,UAAI,UAAU,QAAW;AACvB,yBAAiB,KAAK;AAAA,MACxB;AAAA,IACF,GAAG,CAAC,KAAK,CAAC;AAEV,UAAM,UAAU,MAAM;AACpB,aAAO,MAAM;AACX,YAAI,WAAW,QAAS,cAAa,WAAW,OAAO;AAAA,MACzD;AAAA,IACF,GAAG,CAAA,CAAE;AAEL,UAAM,mBAAmB,MAAM;AAAA,MAC7B,CAAC,QAAgB,CAAC,YAAY,IAAI,UAAU;AAAA,MAC5C,CAAC,QAAQ;AAAA,IAAA;AAGX,UAAM,eAAe,MAAM;AAAA,MACzB,CAAC,MAA2C;AAC1C,cAAM,MAAM,EAAE,OAAO;AAErB,YAAI,CAAC,YAAY;AACf,2BAAiB,GAAG;AACpB,cAAI,iBAAiB,GAAG,EAAG,YAAW,CAAC;AACvC;AAAA,QACF;AAEA,yBAAiB,GAAG;AAEpB,YAAI,WAAW,QAAS,cAAa,WAAW,OAAO;AAEvD,mBAAW,UAAU,WAAW,MAAM;AACpC,cAAI,iBAAiB,GAAG,EAAG,YAAW,CAAC;AAAA,QACzC,GAAG,UAAU;AAAA,MACf;AAAA,MACA,CAAC,YAAY,UAAU,gBAAgB;AAAA,IAAA;AAGzC,UAAM,cAAc,MAAM,YAAY,MAAM;AAC1C,UAAI,WAAW,QAAS,cAAa,WAAW,OAAO;AACvD,uBAAiB,EAAE;AACnB,gBAAA;AAAA,IACF,GAAG,CAAC,OAAO,CAAC;AAEZ,UAAM,eAAe,cAAc,WAAW,gBAAgB;AAC9D,UAAM,YAAY,SAAS;AAC3B,UAAM,WAAW,oBAAC,YAAA,EAAW,MAAM,YAAY,KAAK,IAAI;AAExD,UAAM,kBAAkB,WAAW,iBAAiB,UAAa,iBAAiB;AAElF,UAAM,YAAY,kBAChB;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,0BAAO,WAAA,EAAU;AAAA,QACjB,cAAY;AAAA,QACZ;AAAA,QACA,SAAS;AAAA,MAAA;AAAA,IAAA,IAET;AAEJ,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,MAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,YAAY,OAAO;AAAA,QACjC;AAAA,QACA,OAAO;AAAA,QACP,UAAU;AAAA,QACV,cAAY,CAAC,MAAM,QAAQ,iBAAiB;AAAA,QAC3C,GAAG;AAAA,MAAA;AAAA,IAAA;AAAA,EAGV;AACF;AAEA,YAAY,cAAc;"}
|
|
@@ -45,9 +45,21 @@ function getContainerClassName(size, error, disabled, hasAction) {
|
|
|
45
45
|
disabled && "opacity-50"
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
|
-
function LeadingIcon({
|
|
48
|
+
function LeadingIcon({
|
|
49
|
+
size = "16",
|
|
50
|
+
children
|
|
51
|
+
}) {
|
|
49
52
|
if (!children) return null;
|
|
50
|
-
return /* @__PURE__ */ jsx(
|
|
53
|
+
return /* @__PURE__ */ jsx(
|
|
54
|
+
"span",
|
|
55
|
+
{
|
|
56
|
+
className: cn(
|
|
57
|
+
"pointer-events-none flex shrink-0 items-center justify-center text-content-secondary",
|
|
58
|
+
size === "24" ? "size-6" : "size-4"
|
|
59
|
+
),
|
|
60
|
+
children
|
|
61
|
+
}
|
|
62
|
+
);
|
|
51
63
|
}
|
|
52
64
|
function SideLabel({
|
|
53
65
|
id,
|
|
@@ -114,6 +126,7 @@ const TextField = React.forwardRef(
|
|
|
114
126
|
errorMessage,
|
|
115
127
|
validated = false,
|
|
116
128
|
leftIcon,
|
|
129
|
+
leftIconSize,
|
|
117
130
|
rightIcon,
|
|
118
131
|
leftLabel,
|
|
119
132
|
rightLabel,
|
|
@@ -174,7 +187,7 @@ const TextField = React.forwardRef(
|
|
|
174
187
|
className: getContainerClassName(size, error, disabled, action != null),
|
|
175
188
|
onMouseDown: handleContainerMouseDown,
|
|
176
189
|
children: [
|
|
177
|
-
/* @__PURE__ */ jsx(LeadingIcon, { children: leftIcon }),
|
|
190
|
+
/* @__PURE__ */ jsx(LeadingIcon, { size: leftIconSize, children: leftIcon }),
|
|
178
191
|
/* @__PURE__ */ jsx(SideLabel, { id: leftLabelId, size, align: "left", children: leftLabel }),
|
|
179
192
|
/* @__PURE__ */ jsx(
|
|
180
193
|
"input",
|
|
@@ -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;AAEA,SAAS,UAAU;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,MAAI,CAAC,SAAU,QAAO;AACtB,SACE;AAAA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A,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;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA,SAAS,OAAO,WAAW;AAAA,MAAA;AAAA,MAG5B;AAAA,IAAA;AAAA,E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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,QAAI,CAAC,QAAQ,CAAC,MAAO;AACrB,UAAM,SAAS,MAAM,UAAU,KAAK;AACpC,QAAI,KAAK,YAAY,SAAS,KAAK,IAAI,MAAM,UAAU,KAAK,MAAM,EAAG,OAAM,eAAA;AAAA,EAC7E;AACA,UAAQ,iBAAiB,aAAa,aAAa,EAAE,SAAS,OAAO;AACrE,SAAO,MAAM,QAAQ,oBAAoB,aAAa,WAAW;AACnE;AASO,SAAS,i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AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fanvue/ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.40.0",
|
|
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",
|