@fanvue/ui 3.53.0 → 3.54.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/AudioPlayer/AudioPlayer.cjs +4 -2
- package/dist/cjs/components/AudioPlayer/AudioPlayer.cjs.map +1 -1
- package/dist/cjs/components/Badge/Badge.cjs +7 -6
- package/dist/cjs/components/Badge/Badge.cjs.map +1 -1
- package/dist/cjs/components/Button/Button.cjs +2 -1
- package/dist/cjs/components/Button/Button.cjs.map +1 -1
- package/dist/cjs/components/Card/Card.cjs +1 -1
- package/dist/cjs/components/Card/Card.cjs.map +1 -1
- package/dist/cjs/components/ChatMessage/ChatMessage.cjs +3 -1
- package/dist/cjs/components/ChatMessage/ChatMessage.cjs.map +1 -1
- package/dist/cjs/components/Chip/Chip.cjs +10 -9
- package/dist/cjs/components/Chip/Chip.cjs.map +1 -1
- package/dist/cjs/components/DatePicker/DatePicker.cjs +1 -1
- package/dist/cjs/components/DatePicker/DatePicker.cjs.map +1 -1
- package/dist/cjs/components/DatePicker/DateRangePanel.cjs +143 -0
- package/dist/cjs/components/DatePicker/DateRangePanel.cjs.map +1 -0
- package/dist/cjs/components/DatePicker/DateRangePicker.cjs +33 -0
- package/dist/cjs/components/DatePicker/DateRangePicker.cjs.map +1 -0
- package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs +3 -3
- package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs.map +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs.map +1 -1
- package/dist/cjs/components/FilterMenu/FilterMenu.cjs +45 -0
- package/dist/cjs/components/FilterMenu/FilterMenu.cjs.map +1 -0
- package/dist/cjs/components/IconButton/IconButton.cjs +2 -1
- package/dist/cjs/components/IconButton/IconButton.cjs.map +1 -1
- package/dist/cjs/components/Icons/ReorganiseIcon.cjs +65 -0
- package/dist/cjs/components/Icons/ReorganiseIcon.cjs.map +1 -0
- package/dist/cjs/components/Pagination/Pagination.cjs +3 -2
- package/dist/cjs/components/Pagination/Pagination.cjs.map +1 -1
- package/dist/cjs/components/Select/Select.cjs +20 -11
- package/dist/cjs/components/Select/Select.cjs.map +1 -1
- package/dist/cjs/components/Table/Table.cjs +59 -34
- package/dist/cjs/components/Table/Table.cjs.map +1 -1
- package/dist/cjs/components/Table/TableToolbarSearchFilters.cjs +152 -0
- package/dist/cjs/components/Table/TableToolbarSearchFilters.cjs.map +1 -0
- package/dist/cjs/components/Table/useFittingCount.cjs +51 -0
- package/dist/cjs/components/Table/useFittingCount.cjs.map +1 -0
- package/dist/cjs/date-picker.cjs +4 -0
- package/dist/cjs/date-picker.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/components/AudioPlayer/AudioPlayer.mjs +4 -2
- package/dist/components/AudioPlayer/AudioPlayer.mjs.map +1 -1
- package/dist/components/Badge/Badge.mjs +7 -6
- package/dist/components/Badge/Badge.mjs.map +1 -1
- package/dist/components/Button/Button.mjs +2 -1
- package/dist/components/Button/Button.mjs.map +1 -1
- package/dist/components/Card/Card.mjs +1 -1
- package/dist/components/Card/Card.mjs.map +1 -1
- package/dist/components/ChatMessage/ChatMessage.mjs +3 -1
- package/dist/components/ChatMessage/ChatMessage.mjs.map +1 -1
- package/dist/components/Chip/Chip.mjs +10 -9
- package/dist/components/Chip/Chip.mjs.map +1 -1
- package/dist/components/DatePicker/DatePicker.mjs +1 -1
- package/dist/components/DatePicker/DatePicker.mjs.map +1 -1
- package/dist/components/DatePicker/DateRangePanel.mjs +126 -0
- package/dist/components/DatePicker/DateRangePanel.mjs.map +1 -0
- package/dist/components/DatePicker/DateRangePicker.mjs +33 -0
- package/dist/components/DatePicker/DateRangePicker.mjs.map +1 -0
- package/dist/components/DropdownMenu/DropdownMenuItem.mjs +1 -1
- package/dist/components/DropdownMenu/DropdownMenuItem.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuRoot.mjs +3 -3
- package/dist/components/DropdownMenu/DropdownMenuRoot.mjs.map +1 -1
- package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs +1 -1
- package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs.map +1 -1
- package/dist/components/FilterMenu/FilterMenu.mjs +28 -0
- package/dist/components/FilterMenu/FilterMenu.mjs.map +1 -0
- package/dist/components/IconButton/IconButton.mjs +2 -1
- package/dist/components/IconButton/IconButton.mjs.map +1 -1
- package/dist/components/Icons/ReorganiseIcon.mjs +48 -0
- package/dist/components/Icons/ReorganiseIcon.mjs.map +1 -0
- package/dist/components/Pagination/Pagination.mjs +3 -2
- package/dist/components/Pagination/Pagination.mjs.map +1 -1
- package/dist/components/Select/Select.mjs +20 -11
- package/dist/components/Select/Select.mjs.map +1 -1
- package/dist/components/Table/Table.mjs +59 -34
- package/dist/components/Table/Table.mjs.map +1 -1
- package/dist/components/Table/TableToolbarSearchFilters.mjs +135 -0
- package/dist/components/Table/TableToolbarSearchFilters.mjs.map +1 -0
- package/dist/components/Table/useFittingCount.mjs +34 -0
- package/dist/components/Table/useFittingCount.mjs.map +1 -0
- package/dist/date-picker.d.ts +100 -0
- package/dist/date-picker.mjs +5 -1
- package/dist/date-picker.mjs.map +1 -1
- package/dist/index.d.ts +104 -9
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/styles/base.css +43 -0
- package/dist/styles/theme.css +25 -25
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenuRoot.cjs","sources":["../../../../src/components/DropdownMenu/DropdownMenuRoot.tsx"],"sourcesContent":["import * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { FLOATING_CONTENT_COLLISION_PADDING } from \"../../utils/floatingContentCollisionPadding\";\nimport {\n FLOATING_CONTENT_SURFACE_CLASS,\n FLOATING_CONTENT_Z_INDEX,\n} from \"../../utils/floatingContentSurface\";\nimport { capturePointer } from \"../../utils/pointerCapture\";\nimport { Drawer, DrawerContent, DrawerTrigger } from \"../Drawer/Drawer\";\nimport { IconDefaultsContext, NO_ICON_DEFAULTS } from \"../Icons/IconDefaults\";\nimport { type DropdownMenuVariant, DropdownMenuVariantContext, ToggleOpenContext } from \"./context\";\n\n// Movement, in CSS px, above which a touch press-and-release counts as a drag.\nconst TAP_MOVEMENT_THRESHOLD_PX = 10;\n\n// Radix menus swallow Tab (a menu has no tab stops, only items), which strands\n// any non-item control rendered inside one — header actions, a search input,\n// reorder handles. Containers of such controls carry this attribute and\n// `DropdownMenuContent` cycles Tab through the focusable elements inside them.\nconst TAB_STOPS_ATTRIBUTE = \"data-dropdown-menu-tab-stops\";\nconst FOCUSABLE_SELECTOR = \"a[href], button, input, select, textarea, [tabindex]\";\n\nfunction getMenuTabStops(content: HTMLElement): HTMLElement[] {\n const stops: HTMLElement[] = [];\n for (const container of content.querySelectorAll<HTMLElement>(`[${TAB_STOPS_ATTRIBUTE}]`)) {\n for (const element of container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)) {\n if (element.tabIndex < 0 || element.matches(\":disabled\") || element.hidden) continue;\n stops.push(element);\n }\n }\n return stops;\n}\n\n// Cycles focus through the menu's tab stops on Tab / Shift+Tab, skipping menu\n// items (which keep their arrow-key navigation). Returns without acting when\n// the key isn't a plain Tab, came from a nested menu, or there is nothing to\n// cycle through — Radix then swallows the key as it always has.\nfunction cycleMenuTabStops(event: React.KeyboardEvent<HTMLElement>): void {\n if (event.key !== \"Tab\" || event.altKey || event.ctrlKey || event.metaKey) return;\n // A nested menu's keydowns bubble here through React's portal tree; they are\n // the nested menu's to handle.\n const target = event.target as HTMLElement;\n if (target.closest(\"[data-radix-menu-content]\") !== event.currentTarget) return;\n const stops = getMenuTabStops(event.currentTarget);\n if (stops.length === 0) return;\n // Prevented here so Radix's own handler (which would swallow the key) is\n // skipped — Radix composes it after ours and checks `defaultPrevented`.\n event.preventDefault();\n const index = stops.indexOf(target);\n const last = stops.length - 1;\n const next = event.shiftKey\n ? stops[index <= 0 ? last : index - 1]\n : stops[index === -1 || index === last ? 0 : index + 1];\n // Radix's FocusScope also sees this Tab (after us, ignoring\n // `defaultPrevented`), but a menu's scope is trapped without `loop`, so it\n // only prevents the default — it never moves focus itself.\n next?.focus({ preventScroll: true });\n}\n\ntype ActiveTap = {\n pointerId: number;\n x: number;\n y: number;\n movedPastThreshold: boolean;\n};\n\n/** Props for the {@link DropdownMenu} root component. */\nexport interface DropdownMenuProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Root> {\n /** How the menu presents its content. @default \"menu\" */\n variant?: DropdownMenuVariant;\n}\n\n/** Root component that manages open/close state for a dropdown menu. */\nexport function DropdownMenu({\n open: openProp,\n defaultOpen,\n onOpenChange,\n variant = \"menu\",\n children,\n ...props\n}: DropdownMenuProps) {\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? false,\n onChange: onOpenChange,\n });\n\n if (variant === \"sheet\") {\n return (\n <DropdownMenuVariantContext.Provider value=\"sheet\">\n <ToggleOpenContext.Provider value={setOpen}>\n <Drawer open={open} onOpenChange={setOpen}>\n {children}\n </Drawer>\n </ToggleOpenContext.Provider>\n </DropdownMenuVariantContext.Provider>\n );\n }\n\n return (\n <DropdownMenuVariantContext.Provider value=\"menu\">\n <ToggleOpenContext.Provider value={setOpen}>\n <DropdownMenuPrimitive.Root open={open} onOpenChange={setOpen} {...props}>\n {children}\n </DropdownMenuPrimitive.Root>\n </ToggleOpenContext.Provider>\n </DropdownMenuVariantContext.Provider>\n );\n}\n\n/** Props for the {@link DropdownMenuTrigger} component. */\nexport type DropdownMenuTriggerProps = React.ComponentPropsWithoutRef<\n typeof DropdownMenuPrimitive.Trigger\n>;\n\n/**\n * The element that toggles the dropdown menu when clicked.\n *\n * On touch devices, the menu only opens if the press-and-release stays within\n * a small movement threshold. A drag that incidentally ends over the trigger\n * (common when scrolling a feed on Android Chrome) is ignored. Mouse and\n * keyboard interactions are unchanged.\n */\nexport const DropdownMenuTrigger = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Trigger>,\n DropdownMenuTriggerProps\n>((props, ref) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n const toggleOpen = React.useContext(ToggleOpenContext);\n const tapRef = React.useRef<ActiveTap | null>(null);\n\n // The sheet variant opens a Drawer (Dialog), which already suppresses\n // scroll-drag-end synthetic clicks itself — no need for the touch-tap gating below.\n if (variant === \"sheet\") {\n return <DrawerTrigger {...props} ref={ref} />;\n }\n\n // Used outside our DropdownMenu wrapper — fall through to Radix defaults.\n if (toggleOpen === null) {\n return <DropdownMenuPrimitive.Trigger {...props} ref={ref} />;\n }\n\n return (\n <DropdownMenuPrimitive.Trigger\n {...props}\n ref={ref}\n onPointerDown={(event) => {\n props.onPointerDown?.(event);\n if (event.pointerType === \"mouse\" || props.disabled) return;\n // Keep pointerup / pointercancel on this element if the finger drifts off.\n // Optional because jsdom (used in tests) doesn't implement it.\n capturePointer(event.currentTarget, event.pointerId);\n tapRef.current = {\n pointerId: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n movedPastThreshold: false,\n };\n // preventDefault stops Radix's pointerdown open path via composeEventHandlers.\n event.preventDefault();\n }}\n onPointerMove={(event) => {\n props.onPointerMove?.(event);\n const tap = tapRef.current;\n if (tap === null || event.pointerId !== tap.pointerId || tap.movedPastThreshold) {\n return;\n }\n const dx = event.clientX - tap.x;\n const dy = event.clientY - tap.y;\n if (Math.hypot(dx, dy) > TAP_MOVEMENT_THRESHOLD_PX) {\n tap.movedPastThreshold = true;\n }\n }}\n onPointerUp={(event) => {\n props.onPointerUp?.(event);\n const tap = tapRef.current;\n if (tap === null || event.pointerId !== tap.pointerId) return;\n const wasDrag = tap.movedPastThreshold;\n tapRef.current = null;\n if (!wasDrag && !props.disabled) {\n toggleOpen((prev) => !prev);\n }\n }}\n onPointerCancel={(event) => {\n props.onPointerCancel?.(event);\n const tap = tapRef.current;\n if (tap !== null && event.pointerId === tap.pointerId) {\n tapRef.current = null;\n }\n }}\n />\n );\n});\nDropdownMenuTrigger.displayName = \"DropdownMenuTrigger\";\n\n/** Props for the {@link DropdownMenuContent} component. */\nexport interface DropdownMenuContentProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> {}\n\n/**\n * The positioned content panel rendered inside a portal.\n *\n * Override the portal z-index per-instance via `style={{ zIndex: 1500 }}` or\n * globally with the `--fanvue-ui-portal-z-index` CSS custom property.\n *\n * @example\n * ```tsx\n * <DropdownMenu>\n * <DropdownMenuTrigger asChild>\n * <Button>Open</Button>\n * </DropdownMenuTrigger>\n * <DropdownMenuContent>\n * <DropdownMenuItem>Option 1</DropdownMenuItem>\n * <DropdownMenuItem>Option 2</DropdownMenuItem>\n * </DropdownMenuContent>\n * </DropdownMenu>\n * ```\n */\nexport const DropdownMenuContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Content>,\n DropdownMenuContentProps\n>(\n (\n {\n className,\n style,\n sideOffset = 4,\n // Radix defaults `avoidCollisions` to true, so passing `collisionPadding`\n // is enough to keep the menu flipping/shifting to stay on screen — no\n // hand-rolled reposition logic needed.\n collisionPadding = FLOATING_CONTENT_COLLISION_PADDING,\n onPointerDownOutside,\n onCloseAutoFocus,\n onKeyDown,\n children,\n ...props\n },\n ref,\n ) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n // Radix returns focus to the trigger when the menu closes. That is right for\n // the keyboard, but Chrome's :focus-visible heuristic also paints the ring on\n // that programmatic refocus, so dismissing with a click left a focus ring\n // sitting on the trigger. Track pointer dismissals and skip the restore for\n // them only — Escape and Tab still hand focus back with the ring.\n const dismissedByPointer = React.useRef(false);\n\n if (variant === \"sheet\") {\n return (\n <DrawerContent\n ref={ref}\n position=\"bottom\"\n // `\"sheet\"` sits flush to the bottom edge at full width; the design draws\n // this panel inset from all three sides and rounded on every corner, which\n // is `\"menu\"`. Both carry the same modal surface.\n variant=\"menu\"\n // The design's `blur + shadow/menu` effect is a background blur, and the\n // panel's own fill is opaque — so the blur has to go on the overlay to be\n // visible at all. Scoped here rather than on DrawerOverlay so only menus\n // shown this way blur the page behind them.\n overlayProps={{ className: \"backdrop-blur-[8px]\" }}\n // `pb-2` gives 8px below the last row, matching the popper panel. The rows\n // inset themselves horizontally (see the item's `mx-1`) rather than the\n // panel padding doing it, so the header and its rule can still run full width.\n className={cn(\"flex flex-col gap-[3px] p-1 pb-2\", className)}\n style={style}\n // Both are destructured above for the popper branch's focus-ring\n // handling, which takes them out of `props` — so the sheet branch has\n // to re-attach them or they are silently dropped. `DrawerContent`\n // forwards them to its `DialogPrimitive.Content`, which supports both.\n // Consumers stack sheets on these (a nested sheet's `onCloseAutoFocus`\n // is the only point at which the parent knows the child has finished\n // animating out), so dropping them breaks the flow with no error.\n onPointerDownOutside={onPointerDownOutside}\n onCloseAutoFocus={onCloseAutoFocus}\n onKeyDown={onKeyDown}\n {...props}\n >\n {/* A menu opened from inside another menu's row must not inherit that row's icon defaults. */}\n <IconDefaultsContext.Provider value={NO_ICON_DEFAULTS}>\n {children}\n </IconDefaultsContext.Provider>\n </DrawerContent>\n );\n }\n\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n ref={ref}\n onPointerDownOutside={(event) => {\n dismissedByPointer.current = true;\n onPointerDownOutside?.(event);\n }}\n onCloseAutoFocus={(event) => {\n if (dismissedByPointer.current) event.preventDefault();\n dismissedByPointer.current = false;\n onCloseAutoFocus?.(event);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) cycleMenuTabStops(event);\n }}\n sideOffset={sideOffset}\n collisionPadding={collisionPadding}\n className={cn(\n // The surface is shared with Select and Popover. `V2 Menu Dropdown`\n // (library node `17245:2317`) adds 8px of padding here. Rows inside it\n // are 12px `rounded-sm`, the library's `V2 Menu Item` radius.\n FLOATING_CONTENT_SURFACE_CLASS,\n \"flex w-max min-w-(--radix-dropdown-menu-trigger-width) max-w-(--radix-dropdown-menu-content-available-width) flex-col gap-[3px] overflow-y-auto p-2\",\n \"data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:animate-out\",\n \"data-[side=top]:slide-in-from-bottom-2 data-[side=bottom]:slide-in-from-top-2\",\n \"data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2\",\n className,\n )}\n style={{\n zIndex: FLOATING_CONTENT_Z_INDEX,\n maxHeight: \"var(--radix-dropdown-menu-content-available-height)\",\n ...style,\n }}\n {...props}\n >\n <IconDefaultsContext.Provider value={NO_ICON_DEFAULTS}>\n {children}\n </IconDefaultsContext.Provider>\n </DropdownMenuPrimitive.Content>\n </DropdownMenuPrimitive.Portal>\n );\n },\n);\nDropdownMenuContent.displayName = \"DropdownMenuContent\";\n\n/** Props for the {@link DropdownMenuGroup} component. */\nexport type DropdownMenuGroupProps = React.ComponentPropsWithoutRef<\n typeof DropdownMenuPrimitive.Group\n>;\n\n/**\n * Groups related menu items. Accepts an optional `DropdownMenuLabel`.\n *\n * Requires Radix menu context — not supported inside a `variant=\"sheet\"` menu.\n */\nexport const DropdownMenuGroup = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Group>,\n DropdownMenuGroupProps\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.Group\n ref={ref}\n className={cn(\"flex flex-col gap-[3px]\", className)}\n {...props}\n />\n));\nDropdownMenuGroup.displayName = \"DropdownMenuGroup\";\n"],"names":["useControllableState","DropdownMenuVariantContext","ToggleOpenContext","Drawer","jsx","DropdownMenuPrimitive","React","DrawerTrigger","capturePointer","FLOATING_CONTENT_COLLISION_PADDING","DrawerContent","cn","IconDefaultsContext","NO_ICON_DEFAULTS","FLOATING_CONTENT_SURFACE_CLASS","FLOATING_CONTENT_Z_INDEX"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,4BAA4B;AAMlC,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAE3B,SAAS,gBAAgB,SAAqC;AAC5D,QAAM,QAAuB,CAAA;AAC7B,aAAW,aAAa,QAAQ,iBAA8B,IAAI,mBAAmB,GAAG,GAAG;AACzF,eAAW,WAAW,UAAU,iBAA8B,kBAAkB,GAAG;AACjF,UAAI,QAAQ,WAAW,KAAK,QAAQ,QAAQ,WAAW,KAAK,QAAQ,OAAQ;AAC5E,YAAM,KAAK,OAAO;AAAA,IACpB;AAAA,EACF;AACA,SAAO;AACT;AAMA,SAAS,kBAAkB,OAA+C;AACxE,MAAI,MAAM,QAAQ,SAAS,MAAM,UAAU,MAAM,WAAW,MAAM,QAAS;AAG3E,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,QAAQ,2BAA2B,MAAM,MAAM,cAAe;AACzE,QAAM,QAAQ,gBAAgB,MAAM,aAAa;AACjD,MAAI,MAAM,WAAW,EAAG;AAGxB,QAAM,eAAA;AACN,QAAM,QAAQ,MAAM,QAAQ,MAAM;AAClC,QAAM,OAAO,MAAM,SAAS;AAC5B,QAAM,OAAO,MAAM,WACf,MAAM,SAAS,IAAI,OAAO,QAAQ,CAAC,IACnC,MAAM,UAAU,MAAM,UAAU,OAAO,IAAI,QAAQ,CAAC;AAIxD,QAAM,MAAM,EAAE,eAAe,KAAA,CAAM;AACrC;AAiBO,SAAS,aAAa;AAAA,EAC3B,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAsB;AACpB,QAAM,CAAC,OAAO,OAAO,O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,WAGrC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BF,2BAAAA;AAAAA,EAACC,iCAAsB;AAAA,EAAtB;AAAA,IACC;AAAA,IACA,WAAWM,GAAAA,GAAG,2BAA2B,SAAS;AAAA,IACjD,GAAG;AAAA,EAAA;AACN,CACD;AACD,kBAAkB,cAAc;;;;;"}
|
|
1
|
+
{"version":3,"file":"DropdownMenuRoot.cjs","sources":["../../../../src/components/DropdownMenu/DropdownMenuRoot.tsx"],"sourcesContent":["import * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { FLOATING_CONTENT_COLLISION_PADDING } from \"../../utils/floatingContentCollisionPadding\";\nimport {\n FLOATING_CONTENT_SURFACE_CLASS,\n FLOATING_CONTENT_Z_INDEX,\n} from \"../../utils/floatingContentSurface\";\nimport { capturePointer } from \"../../utils/pointerCapture\";\nimport { Drawer, DrawerContent, DrawerTrigger } from \"../Drawer/Drawer\";\nimport { IconDefaultsContext, NO_ICON_DEFAULTS } from \"../Icons/IconDefaults\";\nimport { type DropdownMenuVariant, DropdownMenuVariantContext, ToggleOpenContext } from \"./context\";\n\n// Movement, in CSS px, above which a touch press-and-release counts as a drag.\nconst TAP_MOVEMENT_THRESHOLD_PX = 10;\n\n// Radix menus swallow Tab (a menu has no tab stops, only items), which strands\n// any non-item control rendered inside one — header actions, a search input,\n// reorder handles. Containers of such controls carry this attribute and\n// `DropdownMenuContent` cycles Tab through the focusable elements inside them.\nconst TAB_STOPS_ATTRIBUTE = \"data-dropdown-menu-tab-stops\";\nconst FOCUSABLE_SELECTOR = \"a[href], button, input, select, textarea, [tabindex]\";\n\nfunction getMenuTabStops(content: HTMLElement): HTMLElement[] {\n const stops: HTMLElement[] = [];\n for (const container of content.querySelectorAll<HTMLElement>(`[${TAB_STOPS_ATTRIBUTE}]`)) {\n for (const element of container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)) {\n if (element.tabIndex < 0 || element.matches(\":disabled\") || element.hidden) continue;\n stops.push(element);\n }\n }\n return stops;\n}\n\n// Cycles focus through the menu's tab stops on Tab / Shift+Tab, skipping menu\n// items (which keep their arrow-key navigation). Returns without acting when\n// the key isn't a plain Tab, came from a nested menu, or there is nothing to\n// cycle through — Radix then swallows the key as it always has.\nfunction cycleMenuTabStops(event: React.KeyboardEvent<HTMLElement>): void {\n if (event.key !== \"Tab\" || event.altKey || event.ctrlKey || event.metaKey) return;\n // A nested menu's keydowns bubble here through React's portal tree; they are\n // the nested menu's to handle.\n const target = event.target as HTMLElement;\n if (target.closest(\"[data-radix-menu-content]\") !== event.currentTarget) return;\n const stops = getMenuTabStops(event.currentTarget);\n if (stops.length === 0) return;\n // Prevented here so Radix's own handler (which would swallow the key) is\n // skipped — Radix composes it after ours and checks `defaultPrevented`.\n event.preventDefault();\n const index = stops.indexOf(target);\n const last = stops.length - 1;\n const next = event.shiftKey\n ? stops[index <= 0 ? last : index - 1]\n : stops[index === -1 || index === last ? 0 : index + 1];\n // Radix's FocusScope also sees this Tab (after us, ignoring\n // `defaultPrevented`), but a menu's scope is trapped without `loop`, so it\n // only prevents the default — it never moves focus itself.\n next?.focus({ preventScroll: true });\n}\n\ntype ActiveTap = {\n pointerId: number;\n x: number;\n y: number;\n movedPastThreshold: boolean;\n};\n\n/** Props for the {@link DropdownMenu} root component. */\nexport interface DropdownMenuProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Root> {\n /** How the menu presents its content. @default \"menu\" */\n variant?: DropdownMenuVariant;\n}\n\n/** Root component that manages open/close state for a dropdown menu. */\nexport function DropdownMenu({\n open: openProp,\n defaultOpen,\n onOpenChange,\n variant = \"menu\",\n children,\n ...props\n}: DropdownMenuProps) {\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? false,\n onChange: onOpenChange,\n });\n\n if (variant === \"sheet\") {\n return (\n <DropdownMenuVariantContext.Provider value=\"sheet\">\n <ToggleOpenContext.Provider value={setOpen}>\n <Drawer open={open} onOpenChange={setOpen}>\n {children}\n </Drawer>\n </ToggleOpenContext.Provider>\n </DropdownMenuVariantContext.Provider>\n );\n }\n\n return (\n <DropdownMenuVariantContext.Provider value=\"menu\">\n <ToggleOpenContext.Provider value={setOpen}>\n <DropdownMenuPrimitive.Root open={open} onOpenChange={setOpen} {...props}>\n {children}\n </DropdownMenuPrimitive.Root>\n </ToggleOpenContext.Provider>\n </DropdownMenuVariantContext.Provider>\n );\n}\n\n/** Props for the {@link DropdownMenuTrigger} component. */\nexport type DropdownMenuTriggerProps = React.ComponentPropsWithoutRef<\n typeof DropdownMenuPrimitive.Trigger\n>;\n\n/**\n * The element that toggles the dropdown menu when clicked.\n *\n * On touch devices, the menu only opens if the press-and-release stays within\n * a small movement threshold. A drag that incidentally ends over the trigger\n * (common when scrolling a feed on Android Chrome) is ignored. Mouse and\n * keyboard interactions are unchanged.\n */\nexport const DropdownMenuTrigger = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Trigger>,\n DropdownMenuTriggerProps\n>((props, ref) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n const toggleOpen = React.useContext(ToggleOpenContext);\n const tapRef = React.useRef<ActiveTap | null>(null);\n\n // The sheet variant opens a Drawer (Dialog), which already suppresses\n // scroll-drag-end synthetic clicks itself — no need for the touch-tap gating below.\n if (variant === \"sheet\") {\n return <DrawerTrigger {...props} ref={ref} />;\n }\n\n // Used outside our DropdownMenu wrapper — fall through to Radix defaults.\n if (toggleOpen === null) {\n return <DropdownMenuPrimitive.Trigger {...props} ref={ref} />;\n }\n\n return (\n <DropdownMenuPrimitive.Trigger\n {...props}\n ref={ref}\n onPointerDown={(event) => {\n props.onPointerDown?.(event);\n if (event.pointerType === \"mouse\" || props.disabled) return;\n // Keep pointerup / pointercancel on this element if the finger drifts off.\n // Optional because jsdom (used in tests) doesn't implement it.\n capturePointer(event.currentTarget, event.pointerId);\n tapRef.current = {\n pointerId: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n movedPastThreshold: false,\n };\n // preventDefault stops Radix's pointerdown open path via composeEventHandlers.\n event.preventDefault();\n }}\n onPointerMove={(event) => {\n props.onPointerMove?.(event);\n const tap = tapRef.current;\n if (tap === null || event.pointerId !== tap.pointerId || tap.movedPastThreshold) {\n return;\n }\n const dx = event.clientX - tap.x;\n const dy = event.clientY - tap.y;\n if (Math.hypot(dx, dy) > TAP_MOVEMENT_THRESHOLD_PX) {\n tap.movedPastThreshold = true;\n }\n }}\n onPointerUp={(event) => {\n props.onPointerUp?.(event);\n const tap = tapRef.current;\n if (tap === null || event.pointerId !== tap.pointerId) return;\n const wasDrag = tap.movedPastThreshold;\n tapRef.current = null;\n if (!wasDrag && !props.disabled) {\n toggleOpen((prev) => !prev);\n }\n }}\n onPointerCancel={(event) => {\n props.onPointerCancel?.(event);\n const tap = tapRef.current;\n if (tap !== null && event.pointerId === tap.pointerId) {\n tapRef.current = null;\n }\n }}\n />\n );\n});\nDropdownMenuTrigger.displayName = \"DropdownMenuTrigger\";\n\n/** Props for the {@link DropdownMenuContent} component. */\nexport interface DropdownMenuContentProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> {}\n\n/**\n * The positioned content panel rendered inside a portal.\n *\n * Override the portal z-index per-instance via `style={{ zIndex: 1500 }}` or\n * globally with the `--fanvue-ui-portal-z-index` CSS custom property.\n *\n * @example\n * ```tsx\n * <DropdownMenu>\n * <DropdownMenuTrigger asChild>\n * <Button>Open</Button>\n * </DropdownMenuTrigger>\n * <DropdownMenuContent>\n * <DropdownMenuItem>Option 1</DropdownMenuItem>\n * <DropdownMenuItem>Option 2</DropdownMenuItem>\n * </DropdownMenuContent>\n * </DropdownMenu>\n * ```\n */\nexport const DropdownMenuContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Content>,\n DropdownMenuContentProps\n>(\n (\n {\n className,\n style,\n sideOffset = 4,\n // Radix defaults `avoidCollisions` to true, so passing `collisionPadding`\n // is enough to keep the menu flipping/shifting to stay on screen — no\n // hand-rolled reposition logic needed.\n collisionPadding = FLOATING_CONTENT_COLLISION_PADDING,\n onPointerDownOutside,\n onCloseAutoFocus,\n onKeyDown,\n children,\n ...props\n },\n ref,\n ) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n // Radix returns focus to the trigger when the menu closes. That is right for\n // the keyboard, but Chrome's :focus-visible heuristic also paints the ring on\n // that programmatic refocus, so dismissing with a click left a focus ring\n // sitting on the trigger. Track pointer dismissals and skip the restore for\n // them only — Escape and Tab still hand focus back with the ring.\n const dismissedByPointer = React.useRef(false);\n\n if (variant === \"sheet\") {\n return (\n <DrawerContent\n ref={ref}\n position=\"bottom\"\n // `\"sheet\"` sits flush to the bottom edge at full width; the design draws\n // this panel inset from all three sides and rounded on every corner, which\n // is `\"menu\"`. Both carry the same modal surface.\n variant=\"menu\"\n // The design's `blur + shadow/menu` effect is a background blur, and the\n // panel's own fill is opaque — so the blur has to go on the overlay to be\n // visible at all. Scoped here rather than on DrawerOverlay so only menus\n // shown this way blur the page behind them.\n overlayProps={{ className: \"backdrop-blur-[8px]\" }}\n // `pb-2` gives 8px below the last row, matching the popper panel. The rows\n // inset themselves horizontally (see the item's `mx-1`) rather than the\n // panel padding doing it, so the header and its rule can still run full width.\n className={cn(\"flex flex-col gap-0.5 p-1 pb-2\", className)}\n style={style}\n // Both are destructured above for the popper branch's focus-ring\n // handling, which takes them out of `props` — so the sheet branch has\n // to re-attach them or they are silently dropped. `DrawerContent`\n // forwards them to its `DialogPrimitive.Content`, which supports both.\n // Consumers stack sheets on these (a nested sheet's `onCloseAutoFocus`\n // is the only point at which the parent knows the child has finished\n // animating out), so dropping them breaks the flow with no error.\n onPointerDownOutside={onPointerDownOutside}\n onCloseAutoFocus={onCloseAutoFocus}\n onKeyDown={onKeyDown}\n {...props}\n >\n {/* A menu opened from inside another menu's row must not inherit that row's icon defaults. */}\n <IconDefaultsContext.Provider value={NO_ICON_DEFAULTS}>\n {children}\n </IconDefaultsContext.Provider>\n </DrawerContent>\n );\n }\n\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n ref={ref}\n onPointerDownOutside={(event) => {\n dismissedByPointer.current = true;\n onPointerDownOutside?.(event);\n }}\n onCloseAutoFocus={(event) => {\n if (dismissedByPointer.current) event.preventDefault();\n dismissedByPointer.current = false;\n onCloseAutoFocus?.(event);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) cycleMenuTabStops(event);\n }}\n sideOffset={sideOffset}\n collisionPadding={collisionPadding}\n className={cn(\n // The surface is shared with Select and Popover. `V2 Menu Dropdown`\n // (library node `17245:2317`) adds 8px of padding here. Rows inside it\n // are 12px `rounded-sm`, the library's `V2 Menu Item` radius.\n FLOATING_CONTENT_SURFACE_CLASS,\n \"flex w-max min-w-(--radix-dropdown-menu-trigger-width) max-w-(--radix-dropdown-menu-content-available-width) flex-col gap-0.5 overflow-y-auto p-2\",\n \"data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:animate-in\",\n \"data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:animate-out\",\n \"data-[side=top]:slide-in-from-bottom-2 data-[side=bottom]:slide-in-from-top-2\",\n \"data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2\",\n className,\n )}\n style={{\n zIndex: FLOATING_CONTENT_Z_INDEX,\n maxHeight: \"var(--radix-dropdown-menu-content-available-height)\",\n ...style,\n }}\n {...props}\n >\n <IconDefaultsContext.Provider value={NO_ICON_DEFAULTS}>\n {children}\n </IconDefaultsContext.Provider>\n </DropdownMenuPrimitive.Content>\n </DropdownMenuPrimitive.Portal>\n );\n },\n);\nDropdownMenuContent.displayName = \"DropdownMenuContent\";\n\n/** Props for the {@link DropdownMenuGroup} component. */\nexport type DropdownMenuGroupProps = React.ComponentPropsWithoutRef<\n typeof DropdownMenuPrimitive.Group\n>;\n\n/**\n * Groups related menu items. Accepts an optional `DropdownMenuLabel`.\n *\n * Requires Radix menu context — not supported inside a `variant=\"sheet\"` menu.\n */\nexport const DropdownMenuGroup = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Group>,\n DropdownMenuGroupProps\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.Group\n ref={ref}\n className={cn(\"flex flex-col gap-0.5\", className)}\n {...props}\n />\n));\nDropdownMenuGroup.displayName = \"DropdownMenuGroup\";\n"],"names":["useControllableState","DropdownMenuVariantContext","ToggleOpenContext","Drawer","jsx","DropdownMenuPrimitive","React","DrawerTrigger","capturePointer","FLOATING_CONTENT_COLLISION_PADDING","DrawerContent","cn","IconDefaultsContext","NO_ICON_DEFAULTS","FLOATING_CONTENT_SURFACE_CLASS","FLOATING_CONTENT_Z_INDEX"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,4BAA4B;AAMlC,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAE3B,SAAS,gBAAgB,SAAqC;AAC5D,QAAM,QAAuB,CAAA;AAC7B,aAAW,aAAa,QAAQ,iBAA8B,IAAI,mBAAmB,GAAG,GAAG;AACzF,eAAW,WAAW,UAAU,iBAA8B,kBAAkB,GAAG;AACjF,UAAI,QAAQ,WAAW,KAAK,QAAQ,QAAQ,WAAW,KAAK,QAAQ,OAAQ;AAC5E,YAAM,KAAK,OAAO;AAAA,IACpB;AAAA,EACF;AACA,SAAO;AACT;AAMA,SAAS,kBAAkB,OAA+C;AACxE,MAAI,MAAM,QAAQ,SAAS,MAAM,UAAU,MAAM,WAAW,MAAM,QAAS;AAG3E,QAAM,SAAS,MAAM;AACrB,MAAI,OAAO,QAAQ,2BAA2B,MAAM,MAAM,cAAe;AACzE,QAAM,QAAQ,gBAAgB,MAAM,aAAa;AACjD,MAAI,MAAM,WAAW,EAAG;AAGxB,QAAM,eAAA;AACN,QAAM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,UAITG,uBAAAA;AAAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAEF,OAAO;AAAA,UACL,QAAQC,uBAAAA;AAAAA,UACR,WAAW;AAAA,UACX,GAAG;AAAA,QAAA;AAAA,QAEJ,GAAG;AAAA,QAEJ,yCAACH,iCAAoB,UAApB,EAA6B,OAAOC,aAAAA,kBAClC,SAAA,CACH;AAAA,MAAA;AAAA,IAAA,GAEJ;AAAA,EAEJ;AACF;AACA,oBAAoB,cAAc;AAY3B,MAAM,oBAAoBP,iBAAM,WAGrC,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BF,2BAAAA;AAAAA,EAACC,iCAAsB;AAAA,EAAtB;AAAA,IACC;AAAA,IACA,WAAWM,GAAAA,GAAG,yBAAyB,SAAS;AAAA,IAC/C,GAAG;AAAA,EAAA;AACN,CACD;AACD,kBAAkB,cAAc;;;;;"}
|
|
@@ -28,7 +28,7 @@ const DropdownMenuRadioGroup = React__namespace.forwardRef(({ className, ...prop
|
|
|
28
28
|
DropdownMenuPrimitive__namespace.RadioGroup,
|
|
29
29
|
{
|
|
30
30
|
ref,
|
|
31
|
-
className: cn.cn("flex flex-col gap-
|
|
31
|
+
className: cn.cn("flex flex-col gap-0.5", className),
|
|
32
32
|
...props
|
|
33
33
|
}
|
|
34
34
|
));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenuSelectionItems.cjs","sources":["../../../../src/components/DropdownMenu/DropdownMenuSelectionItems.tsx"],"sourcesContent":["import * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { TickIcon } from \"../Icons/TickIcon\";\n\n/** Props for the {@link DropdownMenuRadioGroup} component. */\nexport interface DropdownMenuRadioGroupProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioGroup> {}\n\n/**\n * Groups {@link DropdownMenuRadioItem} children so they behave as a\n * single-select set. Controlled via `value`/`onValueChange`.\n *\n * @example\n * ```tsx\n * <DropdownMenuRadioGroup value={sort} onValueChange={setSort}>\n * <DropdownMenuRadioItem value=\"newest\">Newest first</DropdownMenuRadioItem>\n * <DropdownMenuRadioItem value=\"oldest\">Oldest first</DropdownMenuRadioItem>\n * </DropdownMenuRadioGroup>\n * ```\n *\n * Requires Radix menu context — not supported inside a `variant=\"sheet\"` menu.\n */\nexport const DropdownMenuRadioGroup = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.RadioGroup>,\n DropdownMenuRadioGroupProps\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.RadioGroup\n ref={ref}\n className={cn(\"flex flex-col gap-[3px]\", className)}\n {...props}\n />\n));\nDropdownMenuRadioGroup.displayName = \"DropdownMenuRadioGroup\";\n\n/**\n * Under the v2 palette a checked radio or checkbox row fills `Menu Item Selected`,\n * which is inverted there, with inverted content. A highlighted checked row moves to\n * `Menu Item Selected Hover` so keyboard focus stays visible. A disabled row takes the\n * library's Disabled state instead, which has no fill.\n */\nconst checkedV2Row = (disabled: boolean | undefined) =>\n disabled\n ? \"theme-v2:data-[state=checked]:bg-transparent\"\n : \"theme-v2:data-[state=checked]:bg-menu-item-selected theme-v2:data-[state=checked]:text-content-primary-inverted theme-v2:data-[state=checked]:data-[highlighted]:bg-menu-item-selected-hover\";\n\n/**\n * A helper line, inverted on a checked row under the v2 palette unless the row is disabled,\n * and `Menu Item Selected Hover Secondary` while that row is highlighted.\n */\nconst helperClassName = (disabled: boolean | undefined) =>\n cn(\n \"typography-description-12px-regular text-content-secondary\",\n \"group-data-[disabled]:text-content-disabled\",\n !disabled &&\n \"theme-v2:group-data-[state=checked]:text-content-secondary-inverted theme-v2:group-data-[state=checked]:group-data-[highlighted]:text-menu-item-selected-hover-secondary\",\n );\n\n/** Height preset for a {@link DropdownMenuRadioItem}. */\nexport type DropdownMenuRadioItemSize = \"40\";\n\nexport interface DropdownMenuRadioItemProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem> {\n /** Optional secondary text shown below the title. */\n helper?: string;\n /** Height of the item row. @default \"40\" */\n size?: DropdownMenuRadioItemSize;\n}\n\n/**\n * A single radio-style choice within a {@link DropdownMenuRadioGroup}. Shows\n * a circular indicator that fills when selected, plus an optional helper line\n * underneath the title. The checked row rests on `Buttons/Navigation/Hover`, and\n * hovering it shows `Interaction/Hover` like any other row. Under the v2 palette\n * the fill is inverted, with inverted content, and a highlighted checked row moves to\n * `Menu Item Selected Hover`. Rows do not shrink, so a two-line row stays whole when\n * the panel scrolls.\n */\nexport const DropdownMenuRadioItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.RadioItem>,\n DropdownMenuRadioItemProps\n>(({ className, children, helper, size: _size = \"40\", disabled, ...props }, ref) => {\n return (\n <DropdownMenuPrimitive.RadioItem\n ref={ref}\n className={cn(\n // `px-3` (12px), not 16px: `V2 Menu Radio Item` is `px-[12px] py-[8px]`\n // (node `7393:62008`), and at 16px a radio row indented 4px further than a\n // `DropdownMenuCheckboxItem` in the same menu. 12px radius and a 40px\n // minimum height, like `DropdownMenuItem`.\n \"group flex min-h-10 w-full shrink-0 cursor-pointer gap-3 rounded-sm px-3 py-2 outline-none\",\n // A helper line makes it a two-line row aligned to its title; a single\n // line centres in the 40px row like the checkbox and DropdownMenuItem.\n helper ? \"items-start\" : \"items-center\",\n \"data-[state=checked]:bg-menu-item-selected\",\n \"data-[highlighted]:bg-interaction-hover\",\n \"data-[state=checked]:data-[highlighted]:bg-interaction-hover\",\n checkedV2Row(disabled),\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled\",\n className,\n )}\n disabled={disabled}\n {...props}\n >\n <span\n className={cn(\n // In a two-line row `mt-px` centres the 16px circle on the 18px title line.\n helper && \"mt-px\",\n \"flex size-4 shrink-0 items-center justify-center rounded-full border border-icons-primary\",\n \"group-data-[disabled]:border-content-disabled theme-v2:group-data-[disabled]:border-icons-disabled\",\n !disabled && \"theme-v2:group-data-[state=checked]:border-icons-primary-inverted\",\n )}\n aria-hidden=\"true\"\n >\n <DropdownMenuPrimitive.ItemIndicator asChild>\n <span\n className={cn(\n \"size-2 rounded-full bg-content-primary\",\n disabled ? \"theme-v2:bg-icons-disabled\" : \"theme-v2:bg-icons-primary-inverted\",\n )}\n />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n <span className=\"flex min-w-0 flex-1 flex-col gap-1\">\n <span className=\"typography-body-small-14px-semibold truncate\">{children}</span>\n {helper && <span className={helperClassName(disabled)}>{helper}</span>}\n </span>\n </DropdownMenuPrimitive.RadioItem>\n );\n});\nDropdownMenuRadioItem.displayName = \"DropdownMenuRadioItem\";\n\nexport interface DropdownMenuCheckboxItemProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem> {\n /** Optional secondary text shown below the title. */\n helper?: string;\n /** Leading avatar rendered between the checkbox and the title. Render at 32px to match the design. */\n avatar?: React.ReactNode;\n}\n\n/**\n * A single multi-select choice within a dropdown menu. Shows a square indicator\n * that fills when checked, an optional leading avatar, and an optional helper\n * line underneath the title. Rows do not shrink, so a two-line row stays whole\n * when the panel scrolls.\n *\n * Pair with {@link DropdownMenuHeader} at `type=\"search\"` for filterable menus.\n * Use {@link DropdownMenuRadioItem} instead when only one option may be active.\n *\n * @example\n * ```tsx\n * <DropdownMenuCheckboxItem\n * checked={selected.has(creator.id)}\n * onCheckedChange={() => toggle(creator.id)}\n * avatar={<Avatar size={32} src={creator.avatarUrl} />}\n * >\n * @sofiabloom\n * </DropdownMenuCheckboxItem>\n * ```\n */\nexport const DropdownMenuCheckboxItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.CheckboxItem>,\n DropdownMenuCheckboxItemProps\n>(({ className, children, helper, avatar, disabled, ...props }, ref) => {\n return (\n <DropdownMenuPrimitive.CheckboxItem\n ref={ref}\n className={cn(\n \"group flex min-h-10 w-full shrink-0 cursor-pointer items-center gap-3 rounded-sm px-3 py-2 outline-none\",\n // In the current palette the checked state is carried by the tick alone.\n // A background here would leave every selected row shaded, which reads as\n // \"all highlighted\" on a menu that starts fully selected. The v2 palette\n // inverts checked rows like every other selected menu row.\n \"data-[highlighted]:bg-interaction-hover\",\n checkedV2Row(disabled),\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled\",\n className,\n )}\n disabled={disabled}\n {...props}\n >\n <span\n className={cn(\n \"flex size-4 shrink-0 items-center justify-center rounded-2xs border border-icons-primary\",\n \"group-data-[state=checked]:bg-icons-primary\",\n \"group-data-[disabled]:border-content-disabled theme-v2:group-data-[disabled]:border-icons-disabled\",\n disabled\n ? \"theme-v2:group-data-[state=checked]:bg-icons-disabled\"\n : \"theme-v2:group-data-[state=checked]:border-icons-primary-inverted theme-v2:group-data-[state=checked]:bg-icons-primary-inverted\",\n )}\n aria-hidden=\"true\"\n >\n <DropdownMenuPrimitive.ItemIndicator asChild>\n <TickIcon\n className={cn(\n \"size-4 text-content-primary-inverted\",\n !disabled && \"theme-v2:text-content-primary\",\n )}\n />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {avatar && (\n <span className={cn(\"shrink-0\", disabled && \"theme-v2:opacity-60\")}>{avatar}</span>\n )}\n <span className=\"flex min-w-0 flex-1 flex-col gap-1\">\n <span className=\"typography-body-small-14px-semibold truncate\">{children}</span>\n {helper && <span className={helperClassName(disabled)}>{helper}</span>}\n </span>\n </DropdownMenuPrimitive.CheckboxItem>\n );\n});\nDropdownMenuCheckboxItem.displayName = \"DropdownMenuCheckboxItem\";\n"],"names":["React","jsx","DropdownMenuPrimitive","cn","jsxs","TickIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,MAAM,yBAAyBA,iBAAM,WAG1C,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BC,2BAAAA;AAAAA,EAACC,iCAAsB;AAAA,EAAtB;AAAA,IACC;AAAA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,CAAO;AAAA,QAAA,EAAA,CACjE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;AACD,yBAAyB,cAAc;;;;"}
|
|
1
|
+
{"version":3,"file":"DropdownMenuSelectionItems.cjs","sources":["../../../../src/components/DropdownMenu/DropdownMenuSelectionItems.tsx"],"sourcesContent":["import * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { TickIcon } from \"../Icons/TickIcon\";\n\n/** Props for the {@link DropdownMenuRadioGroup} component. */\nexport interface DropdownMenuRadioGroupProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioGroup> {}\n\n/**\n * Groups {@link DropdownMenuRadioItem} children so they behave as a\n * single-select set. Controlled via `value`/`onValueChange`.\n *\n * @example\n * ```tsx\n * <DropdownMenuRadioGroup value={sort} onValueChange={setSort}>\n * <DropdownMenuRadioItem value=\"newest\">Newest first</DropdownMenuRadioItem>\n * <DropdownMenuRadioItem value=\"oldest\">Oldest first</DropdownMenuRadioItem>\n * </DropdownMenuRadioGroup>\n * ```\n *\n * Requires Radix menu context — not supported inside a `variant=\"sheet\"` menu.\n */\nexport const DropdownMenuRadioGroup = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.RadioGroup>,\n DropdownMenuRadioGroupProps\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.RadioGroup\n ref={ref}\n className={cn(\"flex flex-col gap-0.5\", className)}\n {...props}\n />\n));\nDropdownMenuRadioGroup.displayName = \"DropdownMenuRadioGroup\";\n\n/**\n * Under the v2 palette a checked radio or checkbox row fills `Menu Item Selected`,\n * which is inverted there, with inverted content. A highlighted checked row moves to\n * `Menu Item Selected Hover` so keyboard focus stays visible. A disabled row takes the\n * library's Disabled state instead, which has no fill.\n */\nconst checkedV2Row = (disabled: boolean | undefined) =>\n disabled\n ? \"theme-v2:data-[state=checked]:bg-transparent\"\n : \"theme-v2:data-[state=checked]:bg-menu-item-selected theme-v2:data-[state=checked]:text-content-primary-inverted theme-v2:data-[state=checked]:data-[highlighted]:bg-menu-item-selected-hover\";\n\n/**\n * A helper line, inverted on a checked row under the v2 palette unless the row is disabled,\n * and `Menu Item Selected Hover Secondary` while that row is highlighted.\n */\nconst helperClassName = (disabled: boolean | undefined) =>\n cn(\n \"typography-description-12px-regular text-content-secondary\",\n \"group-data-[disabled]:text-content-disabled\",\n !disabled &&\n \"theme-v2:group-data-[state=checked]:text-content-secondary-inverted theme-v2:group-data-[state=checked]:group-data-[highlighted]:text-menu-item-selected-hover-secondary\",\n );\n\n/** Height preset for a {@link DropdownMenuRadioItem}. */\nexport type DropdownMenuRadioItemSize = \"40\";\n\nexport interface DropdownMenuRadioItemProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem> {\n /** Optional secondary text shown below the title. */\n helper?: string;\n /** Height of the item row. @default \"40\" */\n size?: DropdownMenuRadioItemSize;\n}\n\n/**\n * A single radio-style choice within a {@link DropdownMenuRadioGroup}. Shows\n * a circular indicator that fills when selected, plus an optional helper line\n * underneath the title. The checked row rests on `Buttons/Navigation/Hover`, and\n * hovering it shows `Interaction/Hover` like any other row. Under the v2 palette\n * the fill is inverted, with inverted content, and a highlighted checked row moves to\n * `Menu Item Selected Hover`. Rows do not shrink, so a two-line row stays whole when\n * the panel scrolls.\n */\nexport const DropdownMenuRadioItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.RadioItem>,\n DropdownMenuRadioItemProps\n>(({ className, children, helper, size: _size = \"40\", disabled, ...props }, ref) => {\n return (\n <DropdownMenuPrimitive.RadioItem\n ref={ref}\n className={cn(\n // `px-3` (12px), not 16px: `V2 Menu Radio Item` is `px-[12px] py-[8px]`\n // (node `7393:62008`), and at 16px a radio row indented 4px further than a\n // `DropdownMenuCheckboxItem` in the same menu. 12px radius and a 40px\n // minimum height, like `DropdownMenuItem`.\n \"group flex min-h-10 w-full shrink-0 cursor-pointer gap-3 rounded-sm px-3 py-2 outline-none\",\n // A helper line makes it a two-line row aligned to its title; a single\n // line centres in the 40px row like the checkbox and DropdownMenuItem.\n helper ? \"items-start\" : \"items-center\",\n \"data-[state=checked]:bg-menu-item-selected\",\n \"data-[highlighted]:bg-interaction-hover\",\n \"data-[state=checked]:data-[highlighted]:bg-interaction-hover\",\n checkedV2Row(disabled),\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled\",\n className,\n )}\n disabled={disabled}\n {...props}\n >\n <span\n className={cn(\n // In a two-line row `mt-px` centres the 16px circle on the 18px title line.\n helper && \"mt-px\",\n \"flex size-4 shrink-0 items-center justify-center rounded-full border border-icons-primary\",\n \"group-data-[disabled]:border-content-disabled theme-v2:group-data-[disabled]:border-icons-disabled\",\n !disabled && \"theme-v2:group-data-[state=checked]:border-icons-primary-inverted\",\n )}\n aria-hidden=\"true\"\n >\n <DropdownMenuPrimitive.ItemIndicator asChild>\n <span\n className={cn(\n \"size-2 rounded-full bg-content-primary\",\n disabled ? \"theme-v2:bg-icons-disabled\" : \"theme-v2:bg-icons-primary-inverted\",\n )}\n />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n <span className=\"flex min-w-0 flex-1 flex-col gap-1\">\n <span className=\"typography-body-small-14px-semibold truncate\">{children}</span>\n {helper && <span className={helperClassName(disabled)}>{helper}</span>}\n </span>\n </DropdownMenuPrimitive.RadioItem>\n );\n});\nDropdownMenuRadioItem.displayName = \"DropdownMenuRadioItem\";\n\nexport interface DropdownMenuCheckboxItemProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem> {\n /** Optional secondary text shown below the title. */\n helper?: string;\n /** Leading avatar rendered between the checkbox and the title. Render at 32px to match the design. */\n avatar?: React.ReactNode;\n}\n\n/**\n * A single multi-select choice within a dropdown menu. Shows a square indicator\n * that fills when checked, an optional leading avatar, and an optional helper\n * line underneath the title. Rows do not shrink, so a two-line row stays whole\n * when the panel scrolls.\n *\n * Pair with {@link DropdownMenuHeader} at `type=\"search\"` for filterable menus.\n * Use {@link DropdownMenuRadioItem} instead when only one option may be active.\n *\n * @example\n * ```tsx\n * <DropdownMenuCheckboxItem\n * checked={selected.has(creator.id)}\n * onCheckedChange={() => toggle(creator.id)}\n * avatar={<Avatar size={32} src={creator.avatarUrl} />}\n * >\n * @sofiabloom\n * </DropdownMenuCheckboxItem>\n * ```\n */\nexport const DropdownMenuCheckboxItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.CheckboxItem>,\n DropdownMenuCheckboxItemProps\n>(({ className, children, helper, avatar, disabled, ...props }, ref) => {\n return (\n <DropdownMenuPrimitive.CheckboxItem\n ref={ref}\n className={cn(\n \"group flex min-h-10 w-full shrink-0 cursor-pointer items-center gap-3 rounded-sm px-3 py-2 outline-none\",\n // In the current palette the checked state is carried by the tick alone.\n // A background here would leave every selected row shaded, which reads as\n // \"all highlighted\" on a menu that starts fully selected. The v2 palette\n // inverts checked rows like every other selected menu row.\n \"data-[highlighted]:bg-interaction-hover\",\n checkedV2Row(disabled),\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled\",\n className,\n )}\n disabled={disabled}\n {...props}\n >\n <span\n className={cn(\n \"flex size-4 shrink-0 items-center justify-center rounded-2xs border border-icons-primary\",\n \"group-data-[state=checked]:bg-icons-primary\",\n \"group-data-[disabled]:border-content-disabled theme-v2:group-data-[disabled]:border-icons-disabled\",\n disabled\n ? \"theme-v2:group-data-[state=checked]:bg-icons-disabled\"\n : \"theme-v2:group-data-[state=checked]:border-icons-primary-inverted theme-v2:group-data-[state=checked]:bg-icons-primary-inverted\",\n )}\n aria-hidden=\"true\"\n >\n <DropdownMenuPrimitive.ItemIndicator asChild>\n <TickIcon\n className={cn(\n \"size-4 text-content-primary-inverted\",\n !disabled && \"theme-v2:text-content-primary\",\n )}\n />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {avatar && (\n <span className={cn(\"shrink-0\", disabled && \"theme-v2:opacity-60\")}>{avatar}</span>\n )}\n <span className=\"flex min-w-0 flex-1 flex-col gap-1\">\n <span className=\"typography-body-small-14px-semibold truncate\">{children}</span>\n {helper && <span className={helperClassName(disabled)}>{helper}</span>}\n </span>\n </DropdownMenuPrimitive.CheckboxItem>\n );\n});\nDropdownMenuCheckboxItem.displayName = \"DropdownMenuCheckboxItem\";\n"],"names":["React","jsx","DropdownMenuPrimitive","cn","jsxs","TickIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,MAAM,yBAAyBA,iBAAM,WAG1C,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BC,2BAAAA;AAAAA,EAACC,iCAAsB;AAAA,EAAtB;AAAA,IACC;AAAA,IACA,WAAWC,GAAAA,GAAG,yBAAyB,SAAS;AAAA,IAC/C,GAAG;AAAA,EAAA;AACN,CACD;AACD,uBAAuB,cAAc;AAQrC,MAAM,eAAe,CAAC,aACpB,WACI,iDACA;AAMN,MAAM,kBAAkB,CAAC,aACvBA,GAAAA;AAAAA,EACE;AAAA,EACA;AAAA,EACA,CAAC,YACC;AACJ;AAsBK,MAAM,wBAAwBH,iBAAM,WAGzC,CAAC,EAAE,WAAW,UAAU,QAAQ,MAAM,QAAQ,MAAM,UAAU,GAAG,MAAA,GAAS,QAAQ;AAClF,SACEI,2BAAAA;AAAAA,IAACF,iCAAsB;AAAA,IAAtB;AAAA,MACC;AAAA,MACA,WAAWC,GAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA,QAKT;AAAA;AAAA;AAAA,QAGA,SAAS,gBAAgB;AAAA,QACzB;AAAA,QACA;AAAA,QACA;AAAA,QACA,aAAa,QAAQ;AAAA,QACrB;AAAA,QACA;AAAA,MAAA;AAAA,MAEF;AAAA,MACC,GAAG;AAAA,MAEJ,UAAA;AAAA,QAAAF,2BAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAWE,GAAAA;AAAAA;AAAAA,cAET,UAAU;AAAA,cACV;AA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AAAA;AAAAA,cAAA;AAAA,gBACC,WAAWF,GAAAA;AAAAA,kBACT;AAAA,kBACA,CAAC,YAAY;AAAA,gBAAA;AAAA,cACf;AAAA,YAAA,EACF,CACF;AAAA,UAAA;AAAA,QAAA;AAAA,QAED,yCACE,QAAA,EAAK,WAAWA,GAAAA,GAAG,YAAY,YAAY,qBAAqB,GAAI,UAAA,OAAA,CAAO;AAAA,QAE9EC,2BAAAA,KAAC,QAAA,EAAK,WAAU,sCACd,UAAA;AAAA,UAAAH,2BAAAA,IAAC,QAAA,EAAK,WAAU,gDAAgD,SAAA,CAAS;AAAA,UACxE,UAAUA,2BAAAA,IAAC,QAAA,EAAK,WAAW,gBAAgB,QAAQ,GAAI,UAAA,OAAA,CAAO;AAAA,QAAA,EAAA,CACjE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;AACD,yBAAyB,cAAc;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const DropdownMenuRoot = require("../DropdownMenu/DropdownMenuRoot.cjs");
|
|
7
|
+
const DropdownMenuSelectionItems = require("../DropdownMenu/DropdownMenuSelectionItems.cjs");
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
25
|
+
function FilterMenuInner({ children, options, value, onValueChange, contentProps }, ref) {
|
|
26
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuRoot.DropdownMenu, { children: [
|
|
27
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuRoot.DropdownMenuTrigger, { asChild: true, children }),
|
|
28
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuRoot.DropdownMenuContent, { ref, align: "start", ...contentProps, children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
29
|
+
DropdownMenuSelectionItems.DropdownMenuCheckboxItem,
|
|
30
|
+
{
|
|
31
|
+
checked: value.includes(option.value),
|
|
32
|
+
onSelect: (event) => event.preventDefault(),
|
|
33
|
+
onCheckedChange: (checked) => onValueChange(
|
|
34
|
+
checked ? [...value, option.value] : value.filter((item) => item !== option.value)
|
|
35
|
+
),
|
|
36
|
+
children: option.label
|
|
37
|
+
},
|
|
38
|
+
option.value
|
|
39
|
+
)) })
|
|
40
|
+
] });
|
|
41
|
+
}
|
|
42
|
+
const FilterMenu = React__namespace.forwardRef(FilterMenuInner);
|
|
43
|
+
FilterMenu.displayName = "FilterMenu";
|
|
44
|
+
exports.FilterMenu = FilterMenu;
|
|
45
|
+
//# sourceMappingURL=FilterMenu.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilterMenu.cjs","sources":["../../../../src/components/FilterMenu/FilterMenu.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n DropdownMenu,\n DropdownMenuCheckboxItem,\n DropdownMenuContent,\n type DropdownMenuContentProps,\n DropdownMenuTrigger,\n} from \"../DropdownMenu/DropdownMenu\";\n\n/** One choice in a {@link FilterMenu}. */\nexport interface FilterMenuOption<V extends string = string> {\n /** Value reported through `onValueChange`. */\n value: V;\n /** Visible label. */\n label: string;\n}\n\nexport interface FilterMenuProps<V extends string = string> {\n /** The trigger element, e.g. a `TableToolbarAction`. It must forward its ref and spread props. */\n children: React.ReactElement;\n /** The choices, in display order. */\n options: readonly FilterMenuOption<V>[];\n /** The ticked values. */\n value: readonly V[];\n /** Called with the new ticked values each time an option is ticked or unticked. */\n onValueChange: (value: V[]) => void;\n /** Props for the menu content, such as `align` or `aria-label`. @default { align: \"start\" } */\n contentProps?: Omit<DropdownMenuContentProps, \"children\">;\n}\n\nfunction FilterMenuInner<V extends string>(\n { children, options, value, onValueChange, contentProps }: FilterMenuProps<V>,\n ref: React.ForwardedRef<HTMLDivElement>,\n) {\n return (\n <DropdownMenu>\n <DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger>\n <DropdownMenuContent ref={ref} align=\"start\" {...contentProps}>\n {options.map((option) => (\n <DropdownMenuCheckboxItem\n key={option.value}\n checked={value.includes(option.value)}\n onSelect={(event) => event.preventDefault()}\n onCheckedChange={(checked) =>\n onValueChange(\n checked ? [...value, option.value] : value.filter((item) => item !== option.value),\n )\n }\n >\n {option.label}\n </DropdownMenuCheckboxItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n}\n\n/**\n * A menu of options under a trigger you supply, where several can be ticked. Each tick calls\n * `onValueChange` at once and the menu stays open, so several can be ticked in one go. It holds no\n * state: pass `value` back in. The ref goes to the menu content.\n *\n * Keyboard support comes from the menu: arrow keys move, Space or Enter ticks, typing jumps to a\n * label, Escape closes.\n *\n * @example\n * ```tsx\n * <FilterMenu options={platforms} value={selected} onValueChange={setSelected}>\n * <TableToolbarAction icon={<ChevronDownIcon size={16} />} active={selected.length > 0}>\n * Platform\n * </TableToolbarAction>\n * </FilterMenu>\n * ```\n */\nexport const FilterMenu = React.forwardRef(FilterMenuInner) as (<V extends string>(\n props: FilterMenuProps<V> & React.RefAttributes<HTMLDivElement>,\n) => React.ReactElement | null) & { displayName?: string };\n\nFilterMenu.displayName = \"FilterMenu\";\n"],"names":["DropdownMenu","jsx","DropdownMenuTrigger","DropdownMenuContent","DropdownMenuCheckboxItem","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAS,gBACP,EAAE,UAAU,SAAS,OAAO,eAAe,aAAA,GAC3C,KACA;AACA,yCACGA,+BAAA,EACC,UAAA;AAAA,IAAAC,2BAAAA,IAACC,iBAAAA,qBAAA,EAAoB,SAAO,MAAE,SAAA,CAAS;AAAA,IACvCD,2BAAAA,IAACE,iBAAAA,qBAAA,EAAoB,KAAU,OAAM,SAAS,GAAG,cAC9C,UAAA,QAAQ,IAAI,CAAC,WACZF,2BAAAA;AAAAA,MAACG,2BAAAA;AAAAA,MAAA;AAAA,QAEC,SAAS,MAAM,SAAS,OAAO,KAAK;AAAA,QACpC,UAAU,CAAC,UAAU,MAAM,eAAA;AAAA,QAC3B,iBAAiB,CAAC,YAChB;AAAA,UACE,UAAU,CAAC,GAAG,OAAO,OAAO,KAAK,IAAI,MAAM,OAAO,CAAC,SAAS,SAAS,OAAO,KAAK;AAAA,QAAA;AAAA,QAIpF,UAAA,OAAO;AAAA,MAAA;AAAA,MATH,OAAO;AAAA,IAAA,CAWf,EAAA,CACH;AAAA,EAAA,GACF;AAEJ;AAmBO,MAAM,aAAaC,iBAAM,WAAW,eAAe;AAI1D,WAAW,cAAc;;"}
|
|
@@ -67,6 +67,7 @@ const NEGATIVE_AWARE_VARIANTS = /* @__PURE__ */ new Set([
|
|
|
67
67
|
]);
|
|
68
68
|
const DISABLED_FILL = "disabled:bg-buttons-disabled-default disabled:text-content-disabled";
|
|
69
69
|
const DISABLED_FILL_NEGATIVE = "disabled:bg-buttons-disabled-negative disabled:text-content-disabled";
|
|
70
|
+
const DISABLED_FILL_SECONDARY = `${DISABLED_FILL} theme-v2:disabled:bg-buttons-secondary-default`;
|
|
70
71
|
const UPSELL = "fv-upsell fv-upsell-shine bg-buttons-brand-default text-content-always-black not-disabled:hover:[--fv-upsell-end:var(--color-buttons-brand-hover)] not-disabled:active:[--fv-upsell-end:var(--color-buttons-brand-hover)]";
|
|
71
72
|
const DISABLED_TRANSPARENT = "disabled:text-content-disabled";
|
|
72
73
|
const DISABLED_OPACITY = "disabled:opacity-50";
|
|
@@ -79,7 +80,7 @@ const VARIANT_CLASSES = {
|
|
|
79
80
|
},
|
|
80
81
|
secondary: {
|
|
81
82
|
default: "bg-buttons-secondary-default text-content-primary not-disabled:hover:bg-buttons-secondary-hover not-disabled:active:bg-buttons-secondary-hover",
|
|
82
|
-
disabled:
|
|
83
|
+
disabled: DISABLED_FILL_SECONDARY,
|
|
83
84
|
negative: "bg-buttons-secondary-negative-default text-content-primary-inverted not-disabled:hover:bg-buttons-secondary-negative-hover not-disabled:active:bg-buttons-secondary-negative-hover",
|
|
84
85
|
negativeDisabled: DISABLED_FILL_NEGATIVE
|
|
85
86
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.cjs","sources":["../../../../src/components/IconButton/IconButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Count, type CountSize } from \"../Count/Count\";\nimport { IconDefaultsContext, NO_ICON_DEFAULTS } from \"../Icons/IconDefaults\";\n\n/**\n * Visual style variant of the icon button.\n *\n * `primary`, `secondary`, `tertiary`, `outline`, `error`, `white` and `black`\n * use the shared button colour tokens and a size-driven shape (squared at the\n * `24` size, circular otherwise). Of these, `primary`, `secondary`, `tertiary`\n * and `outline` also honour the {@link IconButtonProps.negative} prop, as does\n * `upsell`, which takes the other theme's glow.\n *\n * `upsell` is the Figma \"Upsell\" icon button and matches `Button`'s `brand`\n * variant: a green radial fill, a green glow and a highlight that circles the\n * rim once, held still when the user prefers reduced motion. It takes the same\n * size-driven shape as the standard variants.\n *\n * `overlay` is a translucent dark fill with a backdrop blur, for buttons that sit\n * on photos or video. Its fill and icon look the same in light and dark themes, while\n * the keyboard focus ring still follows the theme. It takes the same size-driven\n * shape as the standard variants.\n *\n * `brand`, `contrast`, `messaging`, `navTray`, `tertiaryDestructive`, `stop` and\n * `microphone` are bespoke variants that stay circular at every size.\n */\nexport type IconButtonVariant =\n | \"primary\"\n | \"secondary\"\n | \"tertiary\"\n | \"outline\"\n | \"error\"\n | \"white\"\n | \"black\"\n | \"brand\"\n | \"upsell\"\n | \"contrast\"\n | \"messaging\"\n | \"navTray\"\n | \"tertiaryDestructive\"\n | \"stop\"\n | \"microphone\"\n | \"overlay\"\n | \"field\";\n\n/** Icon button size in pixels. */\nexport type IconButtonSize = \"24\" | \"32\" | \"40\" | \"48\" | \"52\" | \"72\";\n\nconst iconSizeVariants: Record<IconButtonSize, string> = {\n 24: \"[&>svg]:size-4\",\n 32: \"[&>svg]:size-4\",\n 40: \"[&>svg]:size-4\",\n 48: \"[&>svg]:size-6\",\n 52: \"[&>svg]:size-7\",\n 72: \"[&>svg]:size-8\",\n};\n\nconst sizeVariants: Record<IconButtonSize, string> = {\n 24: \"size-6 p-1\",\n 32: \"size-8 p-1.5\",\n 40: \"size-10 p-[10px]\",\n 48: \"size-12 p-3\",\n 52: \"size-[52px] p-2\",\n 72: \"size-[72px] p-4\",\n};\n\nconst countSizeMap: Record<IconButtonSize, CountSize> = {\n 24: \"16\",\n 32: \"24\",\n 40: \"32\",\n 48: \"32\",\n 52: \"32\",\n 72: \"32\",\n};\n\n/**\n * Variants whose corner radius is size-driven (see {@link IconButton}): the `24`\n * size is squared (`rounded-xs`), every larger size stays circular. All other\n * variants are circular at every size.\n */\nconst SIZE_DRIVEN_SHAPE_VARIANTS = new Set<IconButtonVariant>([\n \"primary\",\n \"secondary\",\n \"tertiary\",\n \"outline\",\n \"error\",\n \"white\",\n \"black\",\n \"upsell\",\n \"overlay\",\n]);\n\n/** Variants that honour the `negative` (dark-surface) treatment. */\nconst NEGATIVE_AWARE_VARIANTS = new Set<IconButtonVariant>([\n \"primary\",\n \"secondary\",\n \"tertiary\",\n \"outline\",\n \"upsell\",\n]);\n\nconst DISABLED_FILL = \"disabled:bg-buttons-disabled-default disabled:text-content-disabled\";\nconst DISABLED_FILL_NEGATIVE =\n \"disabled:bg-buttons-disabled-negative disabled:text-content-disabled\";\nconst UPSELL =\n \"fv-upsell fv-upsell-shine bg-buttons-brand-default text-content-always-black not-disabled:hover:[--fv-upsell-end:var(--color-buttons-brand-hover)] not-disabled:active:[--fv-upsell-end:var(--color-buttons-brand-hover)]\";\nconst DISABLED_TRANSPARENT = \"disabled:text-content-disabled\";\nconst DISABLED_OPACITY = \"disabled:opacity-50\";\n\ntype VariantClasses = {\n default: string;\n disabled: string;\n negative?: string;\n negativeDisabled?: string;\n};\n\n/**\n * Icon button styling for every variant. The disabled treatment is expressed\n * with the CSS `disabled:` variant (not the `disabled` prop) so an ancestor\n * `<fieldset disabled>` is styled too; hover is guarded with `not-disabled:` so\n * it never fights the disabled state.\n */\nconst VARIANT_CLASSES: Record<IconButtonVariant, VariantClasses> = {\n primary: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted not-disabled:hover:bg-buttons-primary-hover not-disabled:active:bg-buttons-primary-hover\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-primary-negative-default text-content-primary not-disabled:hover:bg-buttons-primary-negative-hover not-disabled:active:bg-buttons-primary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n secondary: {\n default:\n \"bg-buttons-secondary-default text-content-primary not-disabled:hover:bg-buttons-secondary-hover not-disabled:active:bg-buttons-secondary-hover\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-secondary-negative-default text-content-primary-inverted not-disabled:hover:bg-buttons-secondary-negative-hover not-disabled:active:bg-buttons-secondary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n tertiary: {\n default:\n \"bg-transparent text-content-primary not-disabled:hover:bg-buttons-tertiary-hover not-disabled:active:bg-buttons-tertiary-hover\",\n disabled: DISABLED_TRANSPARENT,\n negative:\n \"bg-transparent text-content-primary-inverted not-disabled:hover:bg-buttons-tertiary-negative-hover not-disabled:active:bg-buttons-tertiary-negative-hover\",\n negativeDisabled: DISABLED_TRANSPARENT,\n },\n outline: {\n default:\n \"border border-buttons-outline-default bg-transparent text-content-primary not-disabled:hover:bg-buttons-outline-hover not-disabled:active:bg-buttons-outline-hover\",\n disabled: \"disabled:border-buttons-disabled-default disabled:text-content-disabled\",\n negative:\n \"border border-buttons-outline-negative-default bg-transparent text-content-primary-inverted not-disabled:hover:bg-buttons-outline-negative-hover not-disabled:active:bg-buttons-outline-negative-hover\",\n negativeDisabled: \"disabled:border-buttons-disabled-negative disabled:text-content-disabled\",\n },\n error: {\n default:\n \"bg-buttons-error-default text-content-always-white not-disabled:hover:bg-buttons-error-hover not-disabled:active:bg-buttons-error-hover\",\n disabled: DISABLED_FILL,\n },\n white: {\n default:\n \"bg-buttons-always-white-default text-content-always-black not-disabled:hover:bg-buttons-always-white-hover not-disabled:active:bg-buttons-always-white-hover\",\n disabled: DISABLED_FILL,\n },\n black: {\n default:\n \"bg-buttons-always-black-default text-content-always-white not-disabled:hover:bg-buttons-always-black-hover not-disabled:active:bg-buttons-always-black-hover\",\n disabled: DISABLED_FILL,\n },\n brand: {\n default:\n \"bg-content-always-black text-brand-primary-default hover:bg-brand-primary-default hover:text-content-always-black not-disabled:active:bg-brand-primary-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n upsell: {\n default: UPSELL,\n negative: `${UPSELL} fv-upsell-negative`,\n disabled: DISABLED_FILL,\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n contrast: {\n default:\n \"bg-transparent text-content-always-white hover:bg-brand-primary-muted not-disabled:active:bg-brand-primary-muted\",\n disabled: DISABLED_OPACITY,\n },\n messaging: {\n default:\n \"bg-content-always-black text-brand-primary-default hover:bg-brand-primary-default hover:text-content-always-black not-disabled:active:bg-brand-primary-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n navTray: {\n default:\n \"bg-transparent text-content-primary hover:bg-brand-primary-muted not-disabled:active:bg-brand-primary-muted\",\n disabled: DISABLED_OPACITY,\n },\n tertiaryDestructive: {\n default:\n \"bg-transparent text-error-content hover:bg-brand-primary-muted not-disabled:active:bg-brand-primary-muted\",\n disabled: DISABLED_OPACITY,\n },\n stop: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted hover:bg-buttons-brand-default hover:text-content-always-black not-disabled:active:bg-buttons-brand-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n microphone: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted hover:bg-buttons-brand-default hover:text-content-always-black not-disabled:active:bg-buttons-brand-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n overlay: {\n default:\n \"bg-buttons-overlay-default text-content-always-white backdrop-blur-sm not-disabled:hover:bg-buttons-overlay-hover not-disabled:active:bg-buttons-overlay-hover\",\n disabled: DISABLED_OPACITY,\n },\n // Carries the input surface rather than a button one, so an icon-only action can\n // sit flush in a row of fields (Figma draws these as a `V2 Input Fields` instance\n // with only an icon inside). Border and hover match the Select trigger it lines up\n // with, so the row reads as one control group.\n field: {\n default:\n \"border border-border-input bg-inputs-inputs-primary text-content-primary not-disabled:hover:border-border-input-hover theme-v2:focus-visible:not-disabled:border-border-selected theme-v2:focus-visible:shadow-none\",\n disabled: cn(\n DISABLED_TRANSPARENT,\n \"theme-v2:disabled:border-transparent theme-v2:disabled:bg-inputs-inputs-disabled theme-v2:disabled:text-icons-disabled\",\n ),\n },\n};\n\nfunction getVariantClasses(variant: IconButtonVariant, negative: boolean): string {\n const classes = VARIANT_CLASSES[variant];\n const isNegative = NEGATIVE_AWARE_VARIANTS.has(variant) && negative;\n const base = (isNegative && classes.negative) || classes.default;\n const disabledClasses = (isNegative && classes.negativeDisabled) || classes.disabled;\n return cn(base, disabledClasses);\n}\n\nexport interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Visual style variant of the icon button. @default \"primary\" */\n variant?: IconButtonVariant;\n /** Size of the button in pixels. @default \"40\" */\n size?: IconButtonSize;\n /** Icon element to render inside the button. */\n icon: React.ReactNode;\n /**\n * Forces the dark-surface treatment regardless of theme. Only honoured on the\n * `primary`, `secondary`, `tertiary`, and `outline` variants. @default false\n */\n negative?: boolean;\n /** When provided, displays a {@link Count} badge at the top-right corner. */\n counterValue?: number;\n}\n\n/**\n * A button containing only an icon. Use when an action can be represented by an\n * icon alone (e.g. close, send). Always pair with an `aria-label` for\n * accessibility.\n *\n * Shape is size-driven for the standard variants, `upsell` and `overlay`: the `24` size is\n * squared (`rounded-xs`), every larger size is circular. Bespoke variants (`brand`,\n * `contrast`, `messaging`, `navTray`, `tertiaryDestructive`, `stop`,\n * `microphone`) stay circular at all sizes. `field` is the exception that is\n * never circular — it takes the inputs' `rounded-sm` so it matches the fields it\n * sits beside. Use it at `32`, `40` or `48`: those are the sizes `Select` offers,\n * and the variant only earns its surface when it lines up with one.\n *\n * @example\n * ```tsx\n * <IconButton icon={<CloseIcon />} aria-label=\"Close\" variant=\"tertiary\" />\n * ```\n */\nexport const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(\n (\n {\n className,\n variant = \"primary\",\n size = \"40\",\n icon,\n counterValue,\n negative = false,\n disabled = false,\n ...props\n },\n ref,\n ) => {\n if (process.env.NODE_ENV !== \"production\") {\n if (!props[\"aria-label\"] && !props[\"aria-labelledby\"] && !props.title) {\n console.warn(\n \"IconButton: No accessible name provided. Add an `aria-label`, `aria-labelledby`, or `title` prop so screen readers can announce this button.\",\n );\n }\n }\n\n return (\n <button\n ref={ref}\n type=\"button\"\n data-testid=\"icon-button\"\n disabled={disabled}\n className={cn(\n \"relative inline-flex shrink-0 items-center justify-center focus-visible:outline-none\",\n \"cursor-pointer transition-all duration-150 ease-in-out disabled:cursor-default\",\n \"focus-visible:shadow-focus-ring\",\n // `field` takes the inputs' radius at every size so it lines up with the\n // fields around it; everything else keeps the existing size-driven shape.\n variant === \"field\"\n ? \"rounded-sm\"\n : SIZE_DRIVEN_SHAPE_VARIANTS.has(variant) && size === \"24\"\n ? \"rounded-xs\"\n : \"rounded-full\",\n sizeVariants[size],\n getVariantClasses(variant, negative),\n className,\n )}\n {...props}\n >\n <span\n className={cn(\"flex shrink-0 items-center justify-center\", iconSizeVariants[size])}\n aria-hidden=\"true\"\n >\n {/* A button sizes its own icon, so a menu row's icon defaults stop here. */}\n <IconDefaultsContext.Provider value={NO_ICON_DEFAULTS}>\n {icon}\n </IconDefaultsContext.Provider>\n </span>\n\n {counterValue !== undefined && (\n <Count\n value={counterValue}\n variant=\"alert\"\n size={countSizeMap[size]}\n className=\"absolute -top-0.5 -right-0.5 z-10\"\n />\n )}\n </button>\n );\n },\n);\n\nIconButton.displayName = \"IconButton\";\n"],"names":["cn","React","jsxs","jsx","IconDefaultsContext","NO_ICON_DEFAULTS","Count"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,mBAAmD;AAAA,EACvD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,eAA+C;AAAA,EACnD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,eAAkD;AAAA,EACtD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAOA,MAAM,iDAAiC,IAAuB;AAAA,EAC5D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGD,MAAM,8CAA8B,IAAuB;AAAA,EACzD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,MAAM,gBAAgB;AACtB,MAAM,yBACJ;AACF,MAAM,SACJ;AACF,MAAM,uBAAuB;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iB,IAAI,CAAC;AAAA,cACjF,eAAY;AAAA,cAGZ,yCAACI,aAAAA,oBAAoB,UAApB,EAA6B,OAAOC,aAAAA,kBAClC,UAAA,KAAA,CACH;AAAA,YAAA;AAAA,UAAA;AAAA,UAGD,iBAAiB,UAChBF,2BAAAA;AAAAA,YAACG,MAAAA;AAAAA,YAAA;AAAA,cACC,OAAO;AAAA,cACP,SAAQ;AAAA,cACR,MAAM,aAAa,IAAI;AAAA,cACvB,WAAU;AAAA,YAAA;AAAA,UAAA;AAAA,QACZ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,WAAW,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"IconButton.cjs","sources":["../../../../src/components/IconButton/IconButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Count, type CountSize } from \"../Count/Count\";\nimport { IconDefaultsContext, NO_ICON_DEFAULTS } from \"../Icons/IconDefaults\";\n\n/**\n * Visual style variant of the icon button.\n *\n * `primary`, `secondary`, `tertiary`, `outline`, `error`, `white` and `black`\n * use the shared button colour tokens and a size-driven shape (squared at the\n * `24` size, circular otherwise). Of these, `primary`, `secondary`, `tertiary`\n * and `outline` also honour the {@link IconButtonProps.negative} prop, as does\n * `upsell`, which takes the other theme's glow.\n *\n * `upsell` is the Figma \"Upsell\" icon button and matches `Button`'s `brand`\n * variant: a green radial fill, a green glow and a highlight that circles the\n * rim once, held still when the user prefers reduced motion. It takes the same\n * size-driven shape as the standard variants.\n *\n * `overlay` is a translucent dark fill with a backdrop blur, for buttons that sit\n * on photos or video. Its fill and icon look the same in light and dark themes, while\n * the keyboard focus ring still follows the theme. It takes the same size-driven\n * shape as the standard variants.\n *\n * `brand`, `contrast`, `messaging`, `navTray`, `tertiaryDestructive`, `stop` and\n * `microphone` are bespoke variants that stay circular at every size.\n */\nexport type IconButtonVariant =\n | \"primary\"\n | \"secondary\"\n | \"tertiary\"\n | \"outline\"\n | \"error\"\n | \"white\"\n | \"black\"\n | \"brand\"\n | \"upsell\"\n | \"contrast\"\n | \"messaging\"\n | \"navTray\"\n | \"tertiaryDestructive\"\n | \"stop\"\n | \"microphone\"\n | \"overlay\"\n | \"field\";\n\n/** Icon button size in pixels. */\nexport type IconButtonSize = \"24\" | \"32\" | \"40\" | \"48\" | \"52\" | \"72\";\n\nconst iconSizeVariants: Record<IconButtonSize, string> = {\n 24: \"[&>svg]:size-4\",\n 32: \"[&>svg]:size-4\",\n 40: \"[&>svg]:size-4\",\n 48: \"[&>svg]:size-6\",\n 52: \"[&>svg]:size-7\",\n 72: \"[&>svg]:size-8\",\n};\n\nconst sizeVariants: Record<IconButtonSize, string> = {\n 24: \"size-6 p-1\",\n 32: \"size-8 p-1.5\",\n 40: \"size-10 p-[10px]\",\n 48: \"size-12 p-3\",\n 52: \"size-[52px] p-2\",\n 72: \"size-[72px] p-4\",\n};\n\nconst countSizeMap: Record<IconButtonSize, CountSize> = {\n 24: \"16\",\n 32: \"24\",\n 40: \"32\",\n 48: \"32\",\n 52: \"32\",\n 72: \"32\",\n};\n\n/**\n * Variants whose corner radius is size-driven (see {@link IconButton}): the `24`\n * size is squared (`rounded-xs`), every larger size stays circular. All other\n * variants are circular at every size.\n */\nconst SIZE_DRIVEN_SHAPE_VARIANTS = new Set<IconButtonVariant>([\n \"primary\",\n \"secondary\",\n \"tertiary\",\n \"outline\",\n \"error\",\n \"white\",\n \"black\",\n \"upsell\",\n \"overlay\",\n]);\n\n/** Variants that honour the `negative` (dark-surface) treatment. */\nconst NEGATIVE_AWARE_VARIANTS = new Set<IconButtonVariant>([\n \"primary\",\n \"secondary\",\n \"tertiary\",\n \"outline\",\n \"upsell\",\n]);\n\nconst DISABLED_FILL = \"disabled:bg-buttons-disabled-default disabled:text-content-disabled\";\nconst DISABLED_FILL_NEGATIVE =\n \"disabled:bg-buttons-disabled-negative disabled:text-content-disabled\";\n/**\n * Under the v2 palette a disabled secondary icon button keeps its 5% resting fill, so it\n * never reads heavier than an enabled one; the disabled icon colour marks the state.\n */\nconst DISABLED_FILL_SECONDARY = `${DISABLED_FILL} theme-v2:disabled:bg-buttons-secondary-default`;\nconst UPSELL =\n \"fv-upsell fv-upsell-shine bg-buttons-brand-default text-content-always-black not-disabled:hover:[--fv-upsell-end:var(--color-buttons-brand-hover)] not-disabled:active:[--fv-upsell-end:var(--color-buttons-brand-hover)]\";\nconst DISABLED_TRANSPARENT = \"disabled:text-content-disabled\";\nconst DISABLED_OPACITY = \"disabled:opacity-50\";\n\ntype VariantClasses = {\n default: string;\n disabled: string;\n negative?: string;\n negativeDisabled?: string;\n};\n\n/**\n * Icon button styling for every variant. The disabled treatment is expressed\n * with the CSS `disabled:` variant (not the `disabled` prop) so an ancestor\n * `<fieldset disabled>` is styled too; hover is guarded with `not-disabled:` so\n * it never fights the disabled state.\n */\nconst VARIANT_CLASSES: Record<IconButtonVariant, VariantClasses> = {\n primary: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted not-disabled:hover:bg-buttons-primary-hover not-disabled:active:bg-buttons-primary-hover\",\n disabled: DISABLED_FILL,\n negative:\n \"bg-buttons-primary-negative-default text-content-primary not-disabled:hover:bg-buttons-primary-negative-hover not-disabled:active:bg-buttons-primary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n secondary: {\n default:\n \"bg-buttons-secondary-default text-content-primary not-disabled:hover:bg-buttons-secondary-hover not-disabled:active:bg-buttons-secondary-hover\",\n disabled: DISABLED_FILL_SECONDARY,\n negative:\n \"bg-buttons-secondary-negative-default text-content-primary-inverted not-disabled:hover:bg-buttons-secondary-negative-hover not-disabled:active:bg-buttons-secondary-negative-hover\",\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n tertiary: {\n default:\n \"bg-transparent text-content-primary not-disabled:hover:bg-buttons-tertiary-hover not-disabled:active:bg-buttons-tertiary-hover\",\n disabled: DISABLED_TRANSPARENT,\n negative:\n \"bg-transparent text-content-primary-inverted not-disabled:hover:bg-buttons-tertiary-negative-hover not-disabled:active:bg-buttons-tertiary-negative-hover\",\n negativeDisabled: DISABLED_TRANSPARENT,\n },\n outline: {\n default:\n \"border border-buttons-outline-default bg-transparent text-content-primary not-disabled:hover:bg-buttons-outline-hover not-disabled:active:bg-buttons-outline-hover\",\n disabled: \"disabled:border-buttons-disabled-default disabled:text-content-disabled\",\n negative:\n \"border border-buttons-outline-negative-default bg-transparent text-content-primary-inverted not-disabled:hover:bg-buttons-outline-negative-hover not-disabled:active:bg-buttons-outline-negative-hover\",\n negativeDisabled: \"disabled:border-buttons-disabled-negative disabled:text-content-disabled\",\n },\n error: {\n default:\n \"bg-buttons-error-default text-content-always-white not-disabled:hover:bg-buttons-error-hover not-disabled:active:bg-buttons-error-hover\",\n disabled: DISABLED_FILL,\n },\n white: {\n default:\n \"bg-buttons-always-white-default text-content-always-black not-disabled:hover:bg-buttons-always-white-hover not-disabled:active:bg-buttons-always-white-hover\",\n disabled: DISABLED_FILL,\n },\n black: {\n default:\n \"bg-buttons-always-black-default text-content-always-white not-disabled:hover:bg-buttons-always-black-hover not-disabled:active:bg-buttons-always-black-hover\",\n disabled: DISABLED_FILL,\n },\n brand: {\n default:\n \"bg-content-always-black text-brand-primary-default hover:bg-brand-primary-default hover:text-content-always-black not-disabled:active:bg-brand-primary-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n upsell: {\n default: UPSELL,\n negative: `${UPSELL} fv-upsell-negative`,\n disabled: DISABLED_FILL,\n negativeDisabled: DISABLED_FILL_NEGATIVE,\n },\n contrast: {\n default:\n \"bg-transparent text-content-always-white hover:bg-brand-primary-muted not-disabled:active:bg-brand-primary-muted\",\n disabled: DISABLED_OPACITY,\n },\n messaging: {\n default:\n \"bg-content-always-black text-brand-primary-default hover:bg-brand-primary-default hover:text-content-always-black not-disabled:active:bg-brand-primary-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n navTray: {\n default:\n \"bg-transparent text-content-primary hover:bg-brand-primary-muted not-disabled:active:bg-brand-primary-muted\",\n disabled: DISABLED_OPACITY,\n },\n tertiaryDestructive: {\n default:\n \"bg-transparent text-error-content hover:bg-brand-primary-muted not-disabled:active:bg-brand-primary-muted\",\n disabled: DISABLED_OPACITY,\n },\n stop: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted hover:bg-buttons-brand-default hover:text-content-always-black not-disabled:active:bg-buttons-brand-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n microphone: {\n default:\n \"bg-buttons-primary-default text-content-primary-inverted hover:bg-buttons-brand-default hover:text-content-always-black not-disabled:active:bg-buttons-brand-default not-disabled:active:text-content-always-black\",\n disabled: DISABLED_OPACITY,\n },\n overlay: {\n default:\n \"bg-buttons-overlay-default text-content-always-white backdrop-blur-sm not-disabled:hover:bg-buttons-overlay-hover not-disabled:active:bg-buttons-overlay-hover\",\n disabled: DISABLED_OPACITY,\n },\n // Carries the input surface rather than a button one, so an icon-only action can\n // sit flush in a row of fields (Figma draws these as a `V2 Input Fields` instance\n // with only an icon inside). Border and hover match the Select trigger it lines up\n // with, so the row reads as one control group.\n field: {\n default:\n \"border border-border-input bg-inputs-inputs-primary text-content-primary not-disabled:hover:border-border-input-hover theme-v2:focus-visible:not-disabled:border-border-selected theme-v2:focus-visible:shadow-none\",\n disabled: cn(\n DISABLED_TRANSPARENT,\n \"theme-v2:disabled:border-transparent theme-v2:disabled:bg-inputs-inputs-disabled theme-v2:disabled:text-icons-disabled\",\n ),\n },\n};\n\nfunction getVariantClasses(variant: IconButtonVariant, negative: boolean): string {\n const classes = VARIANT_CLASSES[variant];\n const isNegative = NEGATIVE_AWARE_VARIANTS.has(variant) && negative;\n const base = (isNegative && classes.negative) || classes.default;\n const disabledClasses = (isNegative && classes.negativeDisabled) || classes.disabled;\n return cn(base, disabledClasses);\n}\n\nexport interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Visual style variant of the icon button. @default \"primary\" */\n variant?: IconButtonVariant;\n /** Size of the button in pixels. @default \"40\" */\n size?: IconButtonSize;\n /** Icon element to render inside the button. */\n icon: React.ReactNode;\n /**\n * Forces the dark-surface treatment regardless of theme. Only honoured on the\n * `primary`, `secondary`, `tertiary`, and `outline` variants. @default false\n */\n negative?: boolean;\n /** When provided, displays a {@link Count} badge at the top-right corner. */\n counterValue?: number;\n}\n\n/**\n * A button containing only an icon. Use when an action can be represented by an\n * icon alone (e.g. close, send). Always pair with an `aria-label` for\n * accessibility.\n *\n * Shape is size-driven for the standard variants, `upsell` and `overlay`: the `24` size is\n * squared (`rounded-xs`), every larger size is circular. Bespoke variants (`brand`,\n * `contrast`, `messaging`, `navTray`, `tertiaryDestructive`, `stop`,\n * `microphone`) stay circular at all sizes. `field` is the exception that is\n * never circular — it takes the inputs' `rounded-sm` so it matches the fields it\n * sits beside. Use it at `32`, `40` or `48`: those are the sizes `Select` offers,\n * and the variant only earns its surface when it lines up with one.\n *\n * @example\n * ```tsx\n * <IconButton icon={<CloseIcon />} aria-label=\"Close\" variant=\"tertiary\" />\n * ```\n */\nexport const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(\n (\n {\n className,\n variant = \"primary\",\n size = \"40\",\n icon,\n counterValue,\n negative = false,\n disabled = false,\n ...props\n },\n ref,\n ) => {\n if (process.env.NODE_ENV !== \"production\") {\n if (!props[\"aria-label\"] && !props[\"aria-labelledby\"] && !props.title) {\n console.warn(\n \"IconButton: No accessible name provided. Add an `aria-label`, `aria-labelledby`, or `title` prop so screen readers can announce this button.\",\n );\n }\n }\n\n return (\n <button\n ref={ref}\n type=\"button\"\n data-testid=\"icon-button\"\n disabled={disabled}\n className={cn(\n \"relative inline-flex shrink-0 items-center justify-center focus-visible:outline-none\",\n \"cursor-pointer transition-all duration-150 ease-in-out disabled:cursor-default\",\n \"focus-visible:shadow-focus-ring\",\n // `field` takes the inputs' radius at every size so it lines up with the\n // fields around it; everything else keeps the existing size-driven shape.\n variant === \"field\"\n ? \"rounded-sm\"\n : SIZE_DRIVEN_SHAPE_VARIANTS.has(variant) && size === \"24\"\n ? \"rounded-xs\"\n : \"rounded-full\",\n sizeVariants[size],\n getVariantClasses(variant, negative),\n className,\n )}\n {...props}\n >\n <span\n className={cn(\"flex shrink-0 items-center justify-center\", iconSizeVariants[size])}\n aria-hidden=\"true\"\n >\n {/* A button sizes its own icon, so a menu row's icon defaults stop here. */}\n <IconDefaultsContext.Provider value={NO_ICON_DEFAULTS}>\n {icon}\n </IconDefaultsContext.Provider>\n </span>\n\n {counterValue !== undefined && (\n <Count\n value={counterValue}\n variant=\"alert\"\n size={countSizeMap[size]}\n className=\"absolute -top-0.5 -right-0.5 z-10\"\n />\n )}\n </button>\n );\n },\n);\n\nIconButton.displayName = \"IconButton\";\n"],"names":["cn","React","jsxs","jsx","IconDefaultsContext","NO_ICON_DEFAULTS","Count"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,mBAAmD;AAAA,EACvD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,eAA+C;AAAA,EACnD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,MAAM,eAAkD;AAAA,EACtD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAOA,MAAM,iDAAiC,IAAuB;AAAA,EAC5D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGD,MAAM,8CAA8B,IAAuB;AAAA,EACzD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,MAAM,gBAAgB;AACtB,MAAM,yBACJ;A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AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAWH,GAAAA,GAAG,6CAA6C,iBAAiB,IAAI,CAAC;AAAA,cACjF,eAAY;AAAA,cAGZ,yCAACI,aAAAA,oBAAoB,UAApB,EAA6B,OAAOC,aAAAA,kBAClC,UAAA,KAAA,CACH;AAAA,YAAA;AAAA,UAAA;AAAA,UAGD,iBAAiB,UAChBF,2BAAAA;AAAAA,YAACG,MAAAA;AAAAA,YAAA;AAAA,cACC,OAAO;AAAA,cACP,SAAQ;AAAA,cACR,MAAM,aAAa,IAAI;AAAA,cACvB,WAAU;AAAA,YAAA;AAAA,UAAA;AAAA,QACZ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,WAAW,cAAc;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const BaseIcon = require("./BaseIcon.cjs");
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
24
|
+
const VARIANTS = {
|
|
25
|
+
16: {
|
|
26
|
+
outlined: [
|
|
27
|
+
{
|
|
28
|
+
d: "M10.667 14.667a1.335 1.335 0 0 1-1.334-1.334 1.335 1.335 0 0 1 2.667 0c0 .736-.598 1.334-1.333 1.334m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71m-5.334 2.048A1.335 1.335 0 0 1 4 13.333a1.335 1.335 0 0 1 2.667 0c0 .736-.598 1.334-1.334 1.334m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71m5.334-3.286A1.335 1.335 0 0 1 9.333 8 1.335 1.335 0 0 1 12 8c0 .735-.598 1.333-1.333 1.333m0-2.047c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71M5.333 9.333A1.335 1.335 0 0 1 4 8a1.335 1.335 0 0 1 2.667 0c0 .735-.598 1.333-1.334 1.333m0-2.047c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71M10.667 4a1.335 1.335 0 0 1-1.334-1.333 1.335 1.335 0 0 1 2.667 0C12 3.402 11.402 4 10.667 4m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71M5.333 4A1.335 1.335 0 0 1 4 2.667c0-.736.598-1.334 1.333-1.334a1.335 1.335 0 0 1 0 2.667m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
filled: [
|
|
32
|
+
{
|
|
33
|
+
d: "M5.333 4a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667m0 5.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666m0 5.334a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667M10.667 4a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667m0 5.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666m0 5.334a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
24: {
|
|
38
|
+
outlined: [
|
|
39
|
+
{
|
|
40
|
+
d: "M16 22c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M8 22c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M16 14c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M8 14c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M16 6c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M8 6c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
filled: [
|
|
44
|
+
{
|
|
45
|
+
d: "M8 6a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m8-16a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
32: {
|
|
50
|
+
outlined: [
|
|
51
|
+
{
|
|
52
|
+
d: "M21.333 29.333a2.67 2.67 0 0 1-2.666-2.666A2.67 2.67 0 0 1 21.333 24 2.67 2.67 0 0 1 24 26.667a2.67 2.67 0 0 1-2.667 2.666m0-4.095c-.78 0-1.42.64-1.42 1.42 0 .781.64 1.42 1.42 1.42a1.42 1.42 0 1 0 0-2.841m-10.666 4.096A2.67 2.67 0 0 1 8 26.667 2.67 2.67 0 0 1 10.667 24a2.67 2.67 0 0 1 2.666 2.667 2.67 2.67 0 0 1-2.666 2.666m0-4.095c-.781 0-1.42.64-1.42 1.42 0 .781.639 1.42 1.42 1.42s1.42-.639 1.42-1.42-.631-1.42-1.42-1.42m10.666-6.571A2.67 2.67 0 0 1 18.667 16a2.67 2.67 0 0 1 2.666-2.667A2.67 2.67 0 0 1 24 16a2.67 2.67 0 0 1-2.667 2.667m0-4.096c-.78 0-1.42.64-1.42 1.42 0 .782.64 1.421 1.42 1.421a1.42 1.42 0 1 0 0-2.841m-10.666 4.096A2.67 2.67 0 0 1 8 16a2.67 2.67 0 0 1 2.667-2.667A2.67 2.67 0 0 1 13.333 16a2.67 2.67 0 0 1-2.666 2.667m0-4.096c-.781 0-1.42.64-1.42 1.42 0 .782.639 1.421 1.42 1.421s1.42-.64 1.42-1.42c0-.781-.631-1.42-1.42-1.42M21.333 8a2.67 2.67 0 0 1-2.666-2.667 2.67 2.67 0 0 1 2.666-2.666A2.67 2.67 0 0 1 24 5.333 2.67 2.67 0 0 1 21.333 8m0-4.095c-.78 0-1.42.64-1.42 1.42 0 .781.64 1.42 1.42 1.42a1.42 1.42 0 1 0 0-2.841M10.667 8A2.67 2.67 0 0 1 8 5.333a2.67 2.67 0 0 1 2.667-2.666 2.67 2.67 0 0 1 2.666 2.666A2.67 2.67 0 0 1 10.667 8m0-4.095c-.781 0-1.42.64-1.42 1.42 0 .781.639 1.42 1.42 1.42s1.42-.639 1.42-1.42-.631-1.42-1.42-1.42"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
filled: [
|
|
56
|
+
{
|
|
57
|
+
d: "M10.667 8a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333m0 10.667a2.667 2.667 0 1 0 0-5.334 2.667 2.667 0 0 0 0 5.334m0 10.666a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333M21.333 8a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333m0 10.667a2.667 2.667 0 1 0 0-5.334 2.667 2.667 0 0 0 0 5.334m0 10.666a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const ReorganiseIcon = React__namespace.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(BaseIcon.BaseIcon, { ref, variants: VARIANTS, ...props }));
|
|
63
|
+
ReorganiseIcon.displayName = "ReorganiseIcon";
|
|
64
|
+
exports.ReorganiseIcon = ReorganiseIcon;
|
|
65
|
+
//# sourceMappingURL=ReorganiseIcon.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReorganiseIcon.cjs","sources":["../../../../src/components/Icons/ReorganiseIcon.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { BaseIcon } from \"./BaseIcon\";\nimport type { BaseIconProps, IconVariants } from \"./types\";\n\nconst VARIANTS: IconVariants = {\n 16: {\n outlined: [\n {\n d: \"M10.667 14.667a1.335 1.335 0 0 1-1.334-1.334 1.335 1.335 0 0 1 2.667 0c0 .736-.598 1.334-1.333 1.334m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71m-5.334 2.048A1.335 1.335 0 0 1 4 13.333a1.335 1.335 0 0 1 2.667 0c0 .736-.598 1.334-1.334 1.334m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71m5.334-3.286A1.335 1.335 0 0 1 9.333 8 1.335 1.335 0 0 1 12 8c0 .735-.598 1.333-1.333 1.333m0-2.047c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71M5.333 9.333A1.335 1.335 0 0 1 4 8a1.335 1.335 0 0 1 2.667 0c0 .735-.598 1.333-1.334 1.333m0-2.047c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71M10.667 4a1.335 1.335 0 0 1-1.334-1.333 1.335 1.335 0 0 1 2.667 0C12 3.402 11.402 4 10.667 4m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71M5.333 4A1.335 1.335 0 0 1 4 2.667c0-.736.598-1.334 1.333-1.334a1.335 1.335 0 0 1 0 2.667m0-2.048c-.39 0-.71.32-.71.71s.32.71.71.71.71-.32.71-.71a.71.71 0 0 0-.71-.71\",\n },\n ],\n filled: [\n {\n d: \"M5.333 4a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667m0 5.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666m0 5.334a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667M10.667 4a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667m0 5.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666m0 5.334a1.333 1.333 0 1 0 0-2.667 1.333 1.333 0 0 0 0 2.667\",\n },\n ],\n },\n 24: {\n outlined: [\n {\n d: \"M16 22c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M8 22c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M16 14c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M8 14c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M16 6c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13M8 6c-1.103 0-2-.897-2-2s.897-2 2-2 2 .897 2 2-.897 2-2 2m0-3.072c-.586 0-1.065.48-1.065 1.066 0 .585.48 1.065 1.065 1.065a1.065 1.065 0 1 0 0-2.13\",\n },\n ],\n filled: [\n {\n d: \"M8 6a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m8-16a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4m0 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4\",\n },\n ],\n },\n 32: {\n outlined: [\n {\n d: \"M21.333 29.333a2.67 2.67 0 0 1-2.666-2.666A2.67 2.67 0 0 1 21.333 24 2.67 2.67 0 0 1 24 26.667a2.67 2.67 0 0 1-2.667 2.666m0-4.095c-.78 0-1.42.64-1.42 1.42 0 .781.64 1.42 1.42 1.42a1.42 1.42 0 1 0 0-2.841m-10.666 4.096A2.67 2.67 0 0 1 8 26.667 2.67 2.67 0 0 1 10.667 24a2.67 2.67 0 0 1 2.666 2.667 2.67 2.67 0 0 1-2.666 2.666m0-4.095c-.781 0-1.42.64-1.42 1.42 0 .781.639 1.42 1.42 1.42s1.42-.639 1.42-1.42-.631-1.42-1.42-1.42m10.666-6.571A2.67 2.67 0 0 1 18.667 16a2.67 2.67 0 0 1 2.666-2.667A2.67 2.67 0 0 1 24 16a2.67 2.67 0 0 1-2.667 2.667m0-4.096c-.78 0-1.42.64-1.42 1.42 0 .782.64 1.421 1.42 1.421a1.42 1.42 0 1 0 0-2.841m-10.666 4.096A2.67 2.67 0 0 1 8 16a2.67 2.67 0 0 1 2.667-2.667A2.67 2.67 0 0 1 13.333 16a2.67 2.67 0 0 1-2.666 2.667m0-4.096c-.781 0-1.42.64-1.42 1.42 0 .782.639 1.421 1.42 1.421s1.42-.64 1.42-1.42c0-.781-.631-1.42-1.42-1.42M21.333 8a2.67 2.67 0 0 1-2.666-2.667 2.67 2.67 0 0 1 2.666-2.666A2.67 2.67 0 0 1 24 5.333 2.67 2.67 0 0 1 21.333 8m0-4.095c-.78 0-1.42.64-1.42 1.42 0 .781.64 1.42 1.42 1.42a1.42 1.42 0 1 0 0-2.841M10.667 8A2.67 2.67 0 0 1 8 5.333a2.67 2.67 0 0 1 2.667-2.666 2.67 2.67 0 0 1 2.666 2.666A2.67 2.67 0 0 1 10.667 8m0-4.095c-.781 0-1.42.64-1.42 1.42 0 .781.639 1.42 1.42 1.42s1.42-.639 1.42-1.42-.631-1.42-1.42-1.42\",\n },\n ],\n filled: [\n {\n d: \"M10.667 8a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333m0 10.667a2.667 2.667 0 1 0 0-5.334 2.667 2.667 0 0 0 0 5.334m0 10.666a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333M21.333 8a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333m0 10.667a2.667 2.667 0 1 0 0-5.334 2.667 2.667 0 0 0 0 5.334m0 10.666a2.667 2.667 0 1 0 0-5.333 2.667 2.667 0 0 0 0 5.333\",\n },\n ],\n },\n};\n\n/** Props for {@link ReorganiseIcon}. See {@link BaseIconProps} for the shared shape. */\nexport type ReorganiseIconProps = BaseIconProps;\n\n/**\n * Reorganise icon. Renders at sizes 16, 24, or 32 px with outlined and filled variants.\n *\n * @example\n * ```tsx\n * <ReorganiseIcon size={24} filled />\n * ```\n */\nexport const ReorganiseIcon = React.forwardRef<SVGSVGElement, ReorganiseIconProps>((props, ref) => (\n <BaseIcon ref={ref} variants={VARIANTS} {...props} />\n));\n\nReorganiseIcon.displayName = \"ReorganiseIcon\";\n"],"names":["React","jsx","BaseIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,WAAyB;AAAA,EAC7B,IAAI;AAAA,IACF,UAAU;AAAA,MACR;AAAA,QACE,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,IAEF,QAAQ;AAAA,MACN;AAAA,QACE,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,EACF;AAAA,EAEF,IAAI;AAAA,IACF,UAAU;AAAA,MACR;AAAA,QACE,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,IAEF,QAAQ;AAAA,MACN;AAAA,QACE,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,EACF;AAAA,EAEF,IAAI;AAAA,IACF,UAAU;AAAA,MACR;AAAA,QACE,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,IAEF,QAAQ;AAAA,MACN;AAAA,QACE,GAAG;AAAA,MAAA;AAAA,IACL;AAAA,EACF;AAEJ;AAaO,MAAM,iBAAiBA,iBAAM,WAA+C,CAAC,OAAO,QACzFC,2BAAAA,IAACC,SAAAA,UAAA,EAAS,KAAU,UAAU,UAAW,GAAG,OAAO,CACpD;AAED,eAAe,cAAc;;"}
|
|
@@ -24,6 +24,7 @@ function _interopNamespaceDefault(e) {
|
|
|
24
24
|
return Object.freeze(n);
|
|
25
25
|
}
|
|
26
26
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
27
|
+
const PAGE_DOT = "bg-buttons-secondary-default group-hover:bg-buttons-secondary-hover group-active:bg-buttons-secondary-hover theme-v2:bg-neutral-alphas-200 theme-v2:group-hover:bg-neutral-alphas-300 theme-v2:group-active:bg-neutral-alphas-300";
|
|
27
28
|
function getVisiblePages(currentPage, totalPages) {
|
|
28
29
|
if (totalPages <= 7) {
|
|
29
30
|
return Array.from({ length: totalPages }, (_, i) => i + 1);
|
|
@@ -102,7 +103,7 @@ const Pagination = React__namespace.forwardRef(
|
|
|
102
103
|
onClick: () => onPageChange?.(page),
|
|
103
104
|
className: cn.cn(
|
|
104
105
|
"typography-description-12px-regular flex min-w-6 cursor-pointer items-center justify-center rounded-2xs p-1 focus-visible:shadow-focus-ring focus-visible:outline-none motion-safe:transition-colors motion-safe:duration-150",
|
|
105
|
-
page === currentPage ? "bg-surface-primary-inverted text-content-primary-inverted" : "text-content-primary hover:bg-buttons-secondary-default active:bg-buttons-secondary-hover"
|
|
106
|
+
page === currentPage ? "bg-surface-primary-inverted text-content-primary-inverted" : "text-content-primary hover:bg-buttons-secondary-default active:bg-buttons-secondary-hover theme-v2:hover:bg-buttons-secondary-hover"
|
|
106
107
|
),
|
|
107
108
|
children: page
|
|
108
109
|
},
|
|
@@ -122,7 +123,7 @@ const Pagination = React__namespace.forwardRef(
|
|
|
122
123
|
{
|
|
123
124
|
className: cn.cn(
|
|
124
125
|
"block size-2 rounded-2xs motion-safe:transition-colors motion-safe:duration-150",
|
|
125
|
-
page === currentPage ? "bg-surface-primary-inverted" :
|
|
126
|
+
page === currentPage ? "bg-surface-primary-inverted" : PAGE_DOT
|
|
126
127
|
)
|
|
127
128
|
}
|
|
128
129
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.cjs","sources":["../../../../src/components/Pagination/Pagination.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { ChevronLeftIcon } from \"../Icons/ChevronLeftIcon\";\nimport { ChevronRightIcon } from \"../Icons/ChevronRightIcon\";\n\n/** Pagination display style — numbered buttons or minimal dots. */\nexport type PaginationVariant = \"default\" | \"dots\";\n\nexport interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\"> {\n /** Display style — numbered page buttons or minimal dots. @default \"default\" */\n variant?: PaginationVariant;\n /** Total number of pages. */\n totalPages: number;\n /** Current active page (1-indexed). */\n currentPage: number;\n /** Callback fired when the active page changes. Receives the new 1-indexed page number. */\n onPageChange?: (page: number) => void;\n /** Accessible label for the `<nav>` landmark. @default \"Pagination\" */\n ariaLabel?: string;\n /** Accessible label for the previous-page button. @default \"Previous page\" */\n previousLabel?: string;\n /** Accessible label for the next-page button. @default \"Next page\" */\n nextLabel?: string;\n /** Function that returns an accessible label for each page button. @default (page) => \\`Page ${page}\\` */\n getPageLabel?: (page: number) => string;\n}\n\ntype PageItem = number | \"ellipsis-start\" | \"ellipsis-end\";\n\nfunction getVisiblePages(currentPage: number, totalPages: number): PageItem[] {\n if (totalPages <= 7) {\n return Array.from({ length: totalPages }, (_, i) => i + 1);\n }\n\n const pages: PageItem[] = [1];\n\n if (currentPage <= 4) {\n pages.push(2, 3, 4, 5, \"ellipsis-end\");\n } else if (currentPage >= totalPages - 3) {\n pages.push(\"ellipsis-start\", totalPages - 4, totalPages - 3, totalPages - 2, totalPages - 1);\n } else {\n pages.push(\"ellipsis-start\", currentPage - 1, currentPage, currentPage + 1, \"ellipsis-end\");\n }\n\n pages.push(totalPages);\n return pages;\n}\n\n/**\n * Page navigation control with previous/next buttons and numbered page\n * indicators. Supports a numbered-buttons layout (`\"default\"`) and a compact\n * dots layout (`\"dots\"`).\n *\n * @example\n * ```tsx\n * <Pagination totalPages={10} currentPage={page} onPageChange={setPage} />\n * ```\n */\nexport const Pagination = React.forwardRef<HTMLElement, PaginationProps>(\n (\n {\n variant = \"default\",\n totalPages,\n currentPage,\n onPageChange,\n ariaLabel = \"Pagination\",\n previousLabel = \"Previous page\",\n nextLabel = \"Next page\",\n getPageLabel = (page: number) => `Page ${page}`,\n className,\n ...props\n },\n ref,\n ) => {\n const isFirstPage = currentPage <= 1;\n const isLastPage = currentPage >= totalPages;\n\n const handlePrevious = () => {\n if (!isFirstPage) onPageChange?.(currentPage - 1);\n };\n\n const handleNext = () => {\n if (!isLastPage) onPageChange?.(currentPage + 1);\n };\n\n return (\n <nav\n ref={ref}\n aria-label={ariaLabel}\n className={cn(\n \"inline-flex items-center pb-4\",\n variant === \"default\" && \"gap-3\",\n variant === \"dots\" && \"gap-3\",\n className,\n )}\n {...props}\n >\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<ChevronLeftIcon />}\n aria-label={previousLabel}\n disabled={isFirstPage}\n onClick={handlePrevious}\n />\n\n {variant === \"default\" && (\n <div className=\"flex items-center gap-3\">\n {getVisiblePages(currentPage, totalPages).map((page) =>\n typeof page === \"string\" ? (\n <span\n key={page}\n className=\"typography-description-12px-regular flex min-w-6 items-center justify-center p-1 text-content-primary\"\n aria-hidden=\"true\"\n >\n …\n </span>\n ) : (\n <button\n key={page}\n type=\"button\"\n aria-label={getPageLabel(page)}\n aria-current={page === currentPage ? \"page\" : undefined}\n onClick={() => onPageChange?.(page)}\n className={cn(\n \"typography-description-12px-regular flex min-w-6 cursor-pointer items-center justify-center rounded-2xs p-1 focus-visible:shadow-focus-ring focus-visible:outline-none motion-safe:transition-colors motion-safe:duration-150\",\n page === currentPage\n ? \"bg-surface-primary-inverted text-content-primary-inverted\"\n : \"text-content-primary hover:bg-buttons-secondary-default active:bg-buttons-secondary-hover\",\n )}\n >\n {page}\n </button>\n ),\n )}\n </div>\n )}\n\n {variant === \"dots\" && (\n <div className=\"flex items-center\">\n {Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => (\n <button\n key={page}\n type=\"button\"\n aria-label={getPageLabel(page)}\n aria-current={page === currentPage ? \"page\" : undefined}\n onClick={() => onPageChange?.(page)}\n className=\"group flex size-6 cursor-pointer items-center justify-center rounded-2xs focus-visible:shadow-focus-ring focus-visible:outline-none\"\n >\n <span\n className={cn(\n \"block size-2 rounded-2xs motion-safe:transition-colors motion-safe:duration-150\",\n page === currentPage
|
|
1
|
+
{"version":3,"file":"Pagination.cjs","sources":["../../../../src/components/Pagination/Pagination.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { IconButton } from \"../IconButton/IconButton\";\nimport { ChevronLeftIcon } from \"../Icons/ChevronLeftIcon\";\nimport { ChevronRightIcon } from \"../Icons/ChevronRightIcon\";\n\n/** Pagination display style — numbered buttons or minimal dots. */\nexport type PaginationVariant = \"default\" | \"dots\";\n\nexport interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\"> {\n /** Display style — numbered page buttons or minimal dots. @default \"default\" */\n variant?: PaginationVariant;\n /** Total number of pages. */\n totalPages: number;\n /** Current active page (1-indexed). */\n currentPage: number;\n /** Callback fired when the active page changes. Receives the new 1-indexed page number. */\n onPageChange?: (page: number) => void;\n /** Accessible label for the `<nav>` landmark. @default \"Pagination\" */\n ariaLabel?: string;\n /** Accessible label for the previous-page button. @default \"Previous page\" */\n previousLabel?: string;\n /** Accessible label for the next-page button. @default \"Next page\" */\n nextLabel?: string;\n /** Function that returns an accessible label for each page button. @default (page) => \\`Page ${page}\\` */\n getPageLabel?: (page: number) => string;\n}\n\ntype PageItem = number | \"ellipsis-start\" | \"ellipsis-end\";\n\n/**\n * A dot for a page other than the current one. Under the v2 palette the button resting\n * fill is a 5% wash, too faint to show that more pages exist, so the dots take their own\n * 20% step, with 30% on hover.\n */\nconst PAGE_DOT =\n \"bg-buttons-secondary-default group-hover:bg-buttons-secondary-hover group-active:bg-buttons-secondary-hover theme-v2:bg-neutral-alphas-200 theme-v2:group-hover:bg-neutral-alphas-300 theme-v2:group-active:bg-neutral-alphas-300\";\n\nfunction getVisiblePages(currentPage: number, totalPages: number): PageItem[] {\n if (totalPages <= 7) {\n return Array.from({ length: totalPages }, (_, i) => i + 1);\n }\n\n const pages: PageItem[] = [1];\n\n if (currentPage <= 4) {\n pages.push(2, 3, 4, 5, \"ellipsis-end\");\n } else if (currentPage >= totalPages - 3) {\n pages.push(\"ellipsis-start\", totalPages - 4, totalPages - 3, totalPages - 2, totalPages - 1);\n } else {\n pages.push(\"ellipsis-start\", currentPage - 1, currentPage, currentPage + 1, \"ellipsis-end\");\n }\n\n pages.push(totalPages);\n return pages;\n}\n\n/**\n * Page navigation control with previous/next buttons and numbered page\n * indicators. Supports a numbered-buttons layout (`\"default\"`) and a compact\n * dots layout (`\"dots\"`).\n *\n * @example\n * ```tsx\n * <Pagination totalPages={10} currentPage={page} onPageChange={setPage} />\n * ```\n */\nexport const Pagination = React.forwardRef<HTMLElement, PaginationProps>(\n (\n {\n variant = \"default\",\n totalPages,\n currentPage,\n onPageChange,\n ariaLabel = \"Pagination\",\n previousLabel = \"Previous page\",\n nextLabel = \"Next page\",\n getPageLabel = (page: number) => `Page ${page}`,\n className,\n ...props\n },\n ref,\n ) => {\n const isFirstPage = currentPage <= 1;\n const isLastPage = currentPage >= totalPages;\n\n const handlePrevious = () => {\n if (!isFirstPage) onPageChange?.(currentPage - 1);\n };\n\n const handleNext = () => {\n if (!isLastPage) onPageChange?.(currentPage + 1);\n };\n\n return (\n <nav\n ref={ref}\n aria-label={ariaLabel}\n className={cn(\n \"inline-flex items-center pb-4\",\n variant === \"default\" && \"gap-3\",\n variant === \"dots\" && \"gap-3\",\n className,\n )}\n {...props}\n >\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<ChevronLeftIcon />}\n aria-label={previousLabel}\n disabled={isFirstPage}\n onClick={handlePrevious}\n />\n\n {variant === \"default\" && (\n <div className=\"flex items-center gap-3\">\n {getVisiblePages(currentPage, totalPages).map((page) =>\n typeof page === \"string\" ? (\n <span\n key={page}\n className=\"typography-description-12px-regular flex min-w-6 items-center justify-center p-1 text-content-primary\"\n aria-hidden=\"true\"\n >\n …\n </span>\n ) : (\n <button\n key={page}\n type=\"button\"\n aria-label={getPageLabel(page)}\n aria-current={page === currentPage ? \"page\" : undefined}\n onClick={() => onPageChange?.(page)}\n className={cn(\n \"typography-description-12px-regular flex min-w-6 cursor-pointer items-center justify-center rounded-2xs p-1 focus-visible:shadow-focus-ring focus-visible:outline-none motion-safe:transition-colors motion-safe:duration-150\",\n page === currentPage\n ? \"bg-surface-primary-inverted text-content-primary-inverted\"\n : \"text-content-primary hover:bg-buttons-secondary-default active:bg-buttons-secondary-hover theme-v2:hover:bg-buttons-secondary-hover\",\n )}\n >\n {page}\n </button>\n ),\n )}\n </div>\n )}\n\n {variant === \"dots\" && (\n <div className=\"flex items-center\">\n {Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => (\n <button\n key={page}\n type=\"button\"\n aria-label={getPageLabel(page)}\n aria-current={page === currentPage ? \"page\" : undefined}\n onClick={() => onPageChange?.(page)}\n className=\"group flex size-6 cursor-pointer items-center justify-center rounded-2xs focus-visible:shadow-focus-ring focus-visible:outline-none\"\n >\n <span\n className={cn(\n \"block size-2 rounded-2xs motion-safe:transition-colors motion-safe:duration-150\",\n page === currentPage ? \"bg-surface-primary-inverted\" : PAGE_DOT,\n )}\n />\n </button>\n ))}\n </div>\n )}\n\n <IconButton\n variant=\"tertiary\"\n size=\"32\"\n icon={<ChevronRightIcon />}\n aria-label={nextLabel}\n disabled={isLastPage}\n onClick={handleNext}\n />\n </nav>\n );\n },\n);\n\nPagination.displayName = \"Pagination\";\n"],"names":["React","jsxs","cn","jsx","IconButton","ChevronLeftIcon","ChevronRightIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,WACJ;AAEF,SAAS,gBAAgB,aAAqB,YAAgC;AAC5E,MAAI,cAAc,GAAG;AACnB,WAAO,MAAM,KAAK,EAAE,QAAQ,cAAc,CAAC,GAAG,MAAM,IAAI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MAAK;AAAA,cACL,qCAAOE,iBAAAA,kBAAA,EAAiB;AAAA,cACxB,cAAY;AAAA,cACZ,UAAU;AAAA,cACV,SAAS;AAAA,YAAA;AAAA,UAAA;AAAA,QACX;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,WAAW,cAAc;;"}
|
|
@@ -160,6 +160,22 @@ const Select = React__namespace.forwardRef(
|
|
|
160
160
|
}
|
|
161
161
|
);
|
|
162
162
|
Select.displayName = "Select";
|
|
163
|
+
function SelectViewport({ children }) {
|
|
164
|
+
const [interacted, setInteracted] = React__namespace.useState(false);
|
|
165
|
+
const markInteracted = () => {
|
|
166
|
+
if (!interacted) setInteracted(true);
|
|
167
|
+
};
|
|
168
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
169
|
+
SelectPrimitive__namespace.Viewport,
|
|
170
|
+
{
|
|
171
|
+
"data-interacted": interacted ? "" : void 0,
|
|
172
|
+
onPointerMove: markInteracted,
|
|
173
|
+
onKeyDown: markInteracted,
|
|
174
|
+
className: "group/select flex max-h-[var(--radix-select-content-available-height)] flex-col gap-0.5 overflow-y-auto p-2",
|
|
175
|
+
children
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
163
179
|
const SelectContent = React__namespace.forwardRef(
|
|
164
180
|
({
|
|
165
181
|
className,
|
|
@@ -187,7 +203,7 @@ const SelectContent = React__namespace.forwardRef(
|
|
|
187
203
|
className
|
|
188
204
|
),
|
|
189
205
|
...props,
|
|
190
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
206
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SelectViewport, { children: /* @__PURE__ */ jsxRuntime.jsx(IconDefaults.IconDefaultsContext.Provider, { value: IconDefaults.NO_ICON_DEFAULTS, children }) })
|
|
191
207
|
}
|
|
192
208
|
) })
|
|
193
209
|
);
|
|
@@ -203,8 +219,8 @@ const ITEM_DESCRIPTION_TYPOGRAPHY = {
|
|
|
203
219
|
function isRenderableNode(node) {
|
|
204
220
|
return node !== null && node !== void 0 && typeof node !== "boolean";
|
|
205
221
|
}
|
|
206
|
-
const CHECKED_V2_CLASSES = "theme-v2:data-[state=checked]:text-content-primary-inverted theme-v2:data-[state=checked]:data-highlighted:bg-menu-item-selected
|
|
207
|
-
const CHECKED_DESCRIPTION_V2_CLASSES = "theme-v2:group-data-[state=checked]:text-content-secondary-inverted theme-v2:group-data-[
|
|
222
|
+
const CHECKED_V2_CLASSES = "theme-v2:data-[state=checked]:text-content-primary-inverted theme-v2:data-[state=checked]:focus:bg-menu-item-selected theme-v2:data-[state=checked]:data-highlighted:bg-menu-item-selected theme-v2:group-data-[interacted]/select:data-[state=checked]:data-highlighted:bg-menu-item-selected-hover";
|
|
223
|
+
const CHECKED_DESCRIPTION_V2_CLASSES = "theme-v2:group-data-[state=checked]:text-content-secondary-inverted theme-v2:group-data-[interacted]/select:group-data-[state=checked]:group-data-highlighted:text-menu-item-selected-hover-secondary";
|
|
208
224
|
const CHECKED_DISABLED_V2_CLASSES = "theme-v2:data-[state=checked]:bg-transparent";
|
|
209
225
|
const SelectItem = React__namespace.forwardRef(({ className, children, size, leadingIcon, avatar, description, disabled, ...props }, ref) => {
|
|
210
226
|
const { size: triggerSize } = React__namespace.useContext(SelectContext);
|
|
@@ -270,14 +286,7 @@ const SelectItem = React__namespace.forwardRef(({ className, children, size, lea
|
|
|
270
286
|
);
|
|
271
287
|
});
|
|
272
288
|
SelectItem.displayName = "SelectItem";
|
|
273
|
-
const SelectGroup = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
274
|
-
SelectPrimitive__namespace.Group,
|
|
275
|
-
{
|
|
276
|
-
ref,
|
|
277
|
-
className: cn.cn("flex flex-col gap-[3px]", className),
|
|
278
|
-
...props
|
|
279
|
-
}
|
|
280
|
-
));
|
|
289
|
+
const SelectGroup = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Group, { ref, className: cn.cn("flex flex-col gap-0.5", className), ...props }));
|
|
281
290
|
SelectGroup.displayName = "SelectGroup";
|
|
282
291
|
const SelectLabel = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
283
292
|
SelectPrimitive__namespace.Label,
|