@manakind/ui-core 0.28.1 → 0.30.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/README.md +7 -3
- package/dist/accordion/accordion.css +89 -0
- package/dist/accordion/accordion.css.d.ts +2 -0
- package/dist/accordion/accordion.d.ts +79 -0
- package/dist/accordion/accordion.d.ts.map +1 -0
- package/dist/accordion/accordion.js +44 -0
- package/dist/accordion/accordion.js.map +1 -0
- package/dist/accordion/index.d.ts +2 -0
- package/dist/accordion/index.d.ts.map +1 -0
- package/dist/accordion/index.js +2 -0
- package/dist/accordion/index.js.map +1 -0
- package/dist/button/button.css +7 -1
- package/dist/button/button.d.ts +5 -3
- package/dist/button/button.d.ts.map +1 -1
- package/dist/button/button.js +7 -4
- package/dist/button/button.js.map +1 -1
- package/dist/button/icon-button.d.ts +4 -2
- package/dist/button/icon-button.d.ts.map +1 -1
- package/dist/button/icon-button.js +5 -2
- package/dist/button/icon-button.js.map +1 -1
- package/dist/button/loading-interaction.d.ts +6 -0
- package/dist/button/loading-interaction.d.ts.map +1 -0
- package/dist/button/loading-interaction.js +26 -0
- package/dist/button/loading-interaction.js.map +1 -0
- package/dist/calendar/calendar.d.ts +3 -4
- package/dist/calendar/calendar.d.ts.map +1 -1
- package/dist/calendar/calendar.js +5 -2
- package/dist/calendar/calendar.js.map +1 -1
- package/dist/checkbox/checkbox.d.ts +2 -4
- package/dist/checkbox/checkbox.d.ts.map +1 -1
- package/dist/checkbox/checkbox.js +4 -2
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/combobox/combobox.d.ts +3 -3
- package/dist/combobox/combobox.d.ts.map +1 -1
- package/dist/combobox/combobox.js +5 -2
- package/dist/combobox/combobox.js.map +1 -1
- package/dist/dialog/dialog.d.ts +3 -4
- package/dist/dialog/dialog.d.ts.map +1 -1
- package/dist/dialog/dialog.js +4 -2
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/fallback-glyphs.js +3 -3
- package/dist/fallback-glyphs.js.map +1 -1
- package/dist/icon-defaults.d.ts +45 -0
- package/dist/icon-defaults.d.ts.map +1 -0
- package/dist/icon-defaults.js +43 -0
- package/dist/icon-defaults.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/menu/action-menu.d.ts +3 -3
- package/dist/menu/action-menu.d.ts.map +1 -1
- package/dist/menu/action-menu.js +4 -2
- package/dist/menu/action-menu.js.map +1 -1
- package/dist/menu/menu.d.ts +5 -7
- package/dist/menu/menu.d.ts.map +1 -1
- package/dist/menu/menu.js +7 -3
- package/dist/menu/menu.js.map +1 -1
- package/dist/radio-group/index.d.ts +2 -0
- package/dist/radio-group/index.d.ts.map +1 -0
- package/dist/radio-group/index.js +2 -0
- package/dist/radio-group/index.js.map +1 -0
- package/dist/radio-group/radio-group.css +70 -0
- package/dist/radio-group/radio-group.css.d.ts +2 -0
- package/dist/radio-group/radio-group.d.ts +74 -0
- package/dist/radio-group/radio-group.d.ts.map +1 -0
- package/dist/radio-group/radio-group.js +57 -0
- package/dist/radio-group/radio-group.js.map +1 -0
- package/dist/select/select.d.ts +3 -3
- package/dist/select/select.d.ts.map +1 -1
- package/dist/select/select.js +5 -2
- package/dist/select/select.js.map +1 -1
- package/dist/sticky/sticky.css +13 -1
- package/dist/sticky/sticky.d.ts +8 -2
- package/dist/sticky/sticky.d.ts.map +1 -1
- package/dist/sticky/sticky.js +3 -3
- package/dist/sticky/sticky.js.map +1 -1
- package/package.json +18 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAIL,WAAW,EACX,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AAC,CAAC,CAAC,SAAS,YACjF,cAAK,SAAS,EAAC,yBAAyB,YAAE,QAAQ,GAAO,GACrD,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { Dialog as ArkDialog, useDialogContext } from '@ark-ui/react/dialog';\nimport { Portal } from '@ark-ui/react/portal';\nimport {\n type ReactElement,\n type ReactNode,\n type RefObject,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { IconButton } from '../button/icon-button';\nimport type { IconSource } from '../icon/icon';\nimport { PortalContainerContext } from '../portal-container';\nimport { type SidePanelSlot, SidePanelSlotContext } from '../side-panel-layout/side-panel-context';\nimport './dialog.css';\nimport { cx } from '../cx';\nimport { Cross } from '../fallback-glyphs';\n\nexport type DialogRole = 'dialog' | 'alertdialog';\n\n/** How wide the panel may grow: a message or short form, or a form with fields side by side. */\nexport type DialogSize = 'md' | 'lg';\n\n/** Over the page with the rest of it shut off, or in a drawer beside it. */\nexport type DialogPresentation = 'modal' | 'side';\n\nexport interface DialogProps {\n /**\n * The dialog's name: rendered as its `<h2>` heading and announced when it\n * opens (`aria-labelledby`). Write it as a short statement or question —\n * \"Remove “Site foreman”?\".\n */\n title: ReactNode;\n /**\n * One or two sentences under the title, announced with it\n * (`aria-describedby`). For a confirmation, say what the action does and\n * what it leaves alone.\n */\n description?: ReactNode;\n /** Body content. Scrolls inside the panel when it outgrows the viewport. */\n children?: ReactNode;\n /**\n * The footer's buttons, end-aligned, in reading order: the dismissive one\n * first, the committing one last. They wrap onto a second line on a narrow\n * screen. Wrap a dismissive button in `DialogClose` to make it close.\n */\n actions?: ReactNode;\n /**\n * The one element that opens the dialog, such as a `Button`. Focus returns\n * to it when the dialog closes, unless `finalFocusRef` names another\n * element. Leave it out to open the dialog with `open` from elsewhere.\n */\n trigger?: ReactElement;\n /** Controlled open state. Pair with `onOpenChange`. */\n open?: boolean;\n /** Initial open state when uncontrolled. */\n defaultOpen?: boolean;\n /**\n * Fired with the requested state whenever the dialog asks to open (its\n * trigger) or close (a `DialogClose`, the close button, Escape, or for\n * `role=\"dialog\"` a click outside). A controlled dialog stays as it is\n * until `open` changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * `dialog` (default) shows a close button and closes on Escape and on a\n * click outside. `alertdialog` is for confirmations: no close button, and a\n * click outside does nothing, so the explicit cancel action is the way\n * out. Escape still cancels.\n */\n role?: DialogRole;\n /**\n * Where focus lands when the dialog opens. Defaults to the first focusable\n * element: the close button of a `dialog`, the first action of an\n * `alertdialog` with no focusable body. Point an alertdialog at its least\n * destructive action.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus lands when the dialog closes, in place of the trigger. Use it\n * when the confirmed action removes the trigger, such as a row's Remove\n * button: focus would return to an element that is about to unmount and\n * fall to the page body. Point it at something that stays, such as the\n * list's heading, which needs `tabIndex={-1}` to take focus.\n *\n * The ref is read as the dialog closes, however it closes. Fill it in the\n * committing action, so Cancel and Escape still return focus to the\n * trigger, which is still there. While the ref holds no element, focus\n * returns to the trigger as usual.\n */\n finalFocusRef?: RefObject<HTMLElement | null>;\n /** Accessible name of the close button. Translate it with the rest of the UI. */\n closeLabel?: string;\n /**\n * Glyph for the close button. Defaults to a plain built-in cross so\n * `@manakind/ui-core` renders on its own; products pass their own icon set,\n * as they do for Select's indicators.\n */\n closeIcon?: IconSource;\n /**\n * How wide the panel may grow: `md` (the default) for a message or a short\n * form, `lg` for a form with fields side by side.\n */\n size?: DialogSize;\n /**\n * `modal` (the default) floats the panel over a dimmed page. `side` opens\n * it in the drawer of the nearest `SidePanelLayout`, beside the content,\n * which stays in view and usable: a form for one item of a list the user\n * may want to browse while filling it in. A side panel traps no focus,\n * locks no scroll and stays open on a click outside. Escape closes it\n * while focus is in it or on no control, and leaves an Escape pressed on a\n * control in the page to that control. On close, focus returns as from a\n * modal unless the user had moved it onto the page. It is as wide as a `md` dialog, so `size`\n * does not apply. Opening another side dialog in the layout closes this\n * one through `onOpenChange`; a controlled dialog should honour it.\n *\n * Outside a `SidePanelLayout`, for `role=\"alertdialog\"`, which must hold\n * the user until they answer, and inside another dialog, the dialog opens\n * as a modal.\n */\n presentation?: DialogPresentation;\n /** Extra class names appended to the panel's `ds-dialog`. */\n className?: string;\n}\n\n/**\n * A modal dialog: a raised panel over a dimmed page, built on Ark UI.\n *\n * Ark owns the behaviour: the focus trap, focus returning to the trigger\n * (or to `finalFocusRef`), Escape, the page's scroll lock, `aria-modal`, and the title and\n * description wiring. This wrapper adds the `ds-` classes, the\n * `--ds-dialog-*` bindings, and a slot API in place of Ark's anatomy.\n *\n * ```tsx\n * <Dialog\n * role=\"alertdialog\"\n * title=\"Remove “Site foreman”?\"\n * description=\"2 people and 1 Landfall lose this type; nothing else is deleted.\"\n * trigger={<Button variant=\"secondary\">Remove</Button>}\n * initialFocusRef={cancelRef}\n * actions={\n * <>\n * <DialogClose>\n * <Button ref={cancelRef} variant=\"secondary\">Cancel</Button>\n * </DialogClose>\n * <Button variant=\"danger\" onClick={remove}>Remove</Button>\n * </>\n * }\n * />\n * ```\n *\n * The committing action is the consumer's own button. To close after it\n * runs, control the dialog with `open` and set it false in the handler, or\n * wrap the button in `DialogClose` when closing at once is right.\n *\n * The backdrop and panel portal into `<body>` at `z-index: 50`, the layer\n * the product apps use for their own overlays. A Select or Menu inside the\n * dialog portals into its panel (see `PortalContainerContext`) and opens at\n * 60, above it. Nothing is mounted while the dialog is closed.\n */\nexport function Dialog({\n title,\n description,\n children,\n actions,\n trigger,\n open,\n defaultOpen,\n onOpenChange,\n role = 'dialog',\n initialFocusRef,\n finalFocusRef,\n closeLabel = 'Close',\n closeIcon = Cross,\n size = 'md',\n presentation = 'modal',\n className,\n}: DialogProps) {\n const dismissible = role === 'dialog';\n const slot = useContext(SidePanelSlotContext);\n const side = presentation === 'side' && dismissible && slot ? slot : undefined;\n const panelRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [sidePanel, setSidePanel] = useState<HTMLDivElement | null>(null);\n const sidePanelRef = useCallback((element: HTMLDivElement | null) => {\n panelRef.current = element;\n setSidePanel(element);\n }, []);\n const handleOpenChange = (details: { open: boolean }) => onOpenChange?.(details.open);\n // Zag types this as returning `HTMLElement | null`, but its focus trap\n // reads undefined as \"the first focusable element\" and, given null, fails\n // to start at all, leaving the page reachable by Tab.\n const initialFocusEl = (() => initialFocusRef?.current ?? undefined) as () => HTMLElement | null;\n const finalFocusEl = () => finalFocusRef?.current ?? null;\n // Zag's dismiss layer takes Escape anywhere in the document. A side panel\n // leaves the page usable, so an Escape meant for a control on the page,\n // such as a ReorderControl dropping its draft, must not close it too.\n const keepEscapeOnThePage = (event: KeyboardEvent) => {\n const target = event.target;\n const onThePage =\n target instanceof Node &&\n target !== target.ownerDocument?.body &&\n !panelRef.current?.contains(target);\n if (onThePage) event.preventDefault();\n };\n const panel = (\n <PortalContainerContext.Provider value={panelRef}>\n <div className=\"ds-dialog__header\">\n <div className=\"ds-dialog__heading\">\n <ArkDialog.Title className=\"ds-dialog__title\">{title}</ArkDialog.Title>\n {description && (\n <ArkDialog.Description className=\"ds-dialog__description\">\n {description}\n </ArkDialog.Description>\n )}\n </div>\n {dismissible && (\n <ArkDialog.CloseTrigger asChild>\n <IconButton\n icon={closeIcon}\n aria-label={closeLabel}\n variant=\"tertiary\"\n size=\"sm\"\n className=\"ds-dialog__close\"\n />\n </ArkDialog.CloseTrigger>\n )}\n </div>\n {children && <DialogBody>{children}</DialogBody>}\n {actions && <div className=\"ds-dialog__actions\">{actions}</div>}\n </PortalContainerContext.Provider>\n );\n const content = (\n <SidePanelSlotContext.Provider value={undefined}>{panel}</SidePanelSlotContext.Provider>\n );\n\n return (\n <ArkDialog.Root\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={handleOpenChange}\n role={role}\n modal={!side}\n closeOnInteractOutside={dismissible && !side}\n onEscapeKeyDown={side ? keepEscapeOnThePage : undefined}\n initialFocusEl={initialFocusEl}\n finalFocusEl={finalFocusEl}\n lazyMount\n unmountOnExit\n >\n {trigger && (\n <ArkDialog.Trigger ref={triggerRef} asChild>\n {trigger}\n </ArkDialog.Trigger>\n )}\n {side ? (\n side.container &&\n createPortal(\n <ArkDialog.Content\n ref={sidePanelRef}\n className={cx('ds-dialog', 'ds-dialog--side', className)}\n >\n <SidePanelSeat\n claim={side.claim}\n panel={sidePanel}\n triggerRef={triggerRef}\n finalFocusRef={finalFocusRef}\n />\n {content}\n </ArkDialog.Content>,\n side.container,\n )\n ) : (\n <Portal>\n <ArkDialog.Backdrop className=\"ds-dialog__backdrop\" />\n <ArkDialog.Positioner className=\"ds-dialog__positioner\">\n <ArkDialog.Content\n ref={panelRef}\n className={cx('ds-dialog', size === 'lg' && 'ds-dialog--lg', className)}\n >\n {content}\n </ArkDialog.Content>\n </ArkDialog.Positioner>\n </Portal>\n )}\n </ArkDialog.Root>\n );\n}\n\n/**\n * What a side panel needs that Ark leaves to a modal's focus trap: the slot,\n * taken on open so any other panel closes; the panel scrolled into view,\n * since below the `lg` step it sits above the content in the page's flow;\n * and focus put back on close. Focus moves when it was inside the panel or\n * on nothing, as after a save whose button disabled itself and so dropped\n * focus, so closing the panel never pulls the user out of the list they\n * moved to but never leaves them on the page's body either.\n * It goes where the trap would send it: `finalFocusRef`'s element, else the\n * trigger, else what had focus when the panel opened. The trigger is named\n * outright because Safari does not focus a button on click.\n *\n * The panel arrives as state from its callback ref: a child's layout effect\n * runs before its parent's ref is attached. A layout effect, because its\n * cleanup runs while the panel is still in the document and can still hold\n * focus, and before Ark moves focus into the panel a frame after it opens.\n * It runs once per opening: the callbacks and refs it reads at close are\n * kept current beside it, so a re-render never closes and reopens the seat.\n */\nfunction SidePanelSeat({\n claim,\n panel,\n triggerRef,\n finalFocusRef,\n}: {\n claim: SidePanelSlot['claim'];\n panel: HTMLDivElement | null;\n triggerRef: RefObject<HTMLElement | null>;\n finalFocusRef?: RefObject<HTMLElement | null>;\n}) {\n const dialog = useDialogContext();\n const latest = useRef({ setOpen: dialog.setOpen, finalFocusRef });\n useLayoutEffect(() => {\n latest.current = { setOpen: dialog.setOpen, finalFocusRef };\n });\n\n useLayoutEffect(() => {\n if (!panel) return;\n const opener = panel.ownerDocument.activeElement;\n const release = claim(() => latest.current.setOpen(false));\n panel.scrollIntoView({ block: 'nearest' });\n return () => {\n release();\n const active = panel.ownerDocument.activeElement;\n const movedToThePage =\n active && active !== panel.ownerDocument.body && !panel.contains(active);\n if (movedToThePage) return;\n const target = [latest.current.finalFocusRef?.current, triggerRef.current, opener].find(\n (element) => element instanceof HTMLElement && element.isConnected,\n );\n if (target instanceof HTMLElement) target.focus();\n };\n }, [claim, panel, triggerRef]);\n\n return null;\n}\n\n/**\n * The scrolling body. While its content overflows it joins the tab order, so\n * a keyboard user can focus it and scroll; a body with nothing to scroll\n * stays out of the way.\n *\n * Two boxes are observed because either can change the answer: the outer one\n * resizes with the viewport, the inner one with the content.\n */\nfunction DialogBody({ children }: { children: ReactNode }) {\n const [scrollable, setScrollable] = useState(false);\n const observe = useCallback((scroller: HTMLDivElement | null) => {\n const content = scroller?.firstElementChild;\n if (!scroller || !content) return;\n const observer = new ResizeObserver(() =>\n setScrollable(scroller.scrollHeight > scroller.clientHeight),\n );\n observer.observe(scroller);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n\n return (\n <div ref={observe} className=\"ds-dialog__body\" tabIndex={scrollable ? 0 : undefined}>\n <div className=\"ds-dialog__body-content\">{children}</div>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAIL,WAAW,EACX,UAAU,EACV,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf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EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YACjF,cAAK,SAAS,EAAC,yBAAyB,YAAE,QAAQ,GAAO,GACrD,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { Dialog as ArkDialog, useDialogContext } from '@ark-ui/react/dialog';\nimport { Portal } from '@ark-ui/react/portal';\nimport {\n type ReactElement,\n type ReactNode,\n type RefObject,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { IconButton } from '../button/icon-button';\nimport type { IconSource } from '../icon/icon';\nimport { PortalContainerContext } from '../portal-container';\nimport { type SidePanelSlot, SidePanelSlotContext } from '../side-panel-layout/side-panel-context';\nimport './dialog.css';\nimport { cx } from '../cx';\nimport { useIconDefaults } from '../icon-defaults';\n\nexport type DialogRole = 'dialog' | 'alertdialog';\n\n/** How wide the panel may grow: a message or short form, or a form with fields side by side. */\nexport type DialogSize = 'md' | 'lg';\n\n/** Over the page with the rest of it shut off, or in a drawer beside it. */\nexport type DialogPresentation = 'modal' | 'side';\n\nexport interface DialogProps {\n /**\n * The dialog's name: rendered as its `<h2>` heading and announced when it\n * opens (`aria-labelledby`). Write it as a short statement or question —\n * \"Remove “Site foreman”?\".\n */\n title: ReactNode;\n /**\n * One or two sentences under the title, announced with it\n * (`aria-describedby`). For a confirmation, say what the action does and\n * what it leaves alone.\n */\n description?: ReactNode;\n /** Body content. Scrolls inside the panel when it outgrows the viewport. */\n children?: ReactNode;\n /**\n * The footer's buttons, end-aligned, in reading order: the dismissive one\n * first, the committing one last. They wrap onto a second line on a narrow\n * screen. Wrap a dismissive button in `DialogClose` to make it close.\n */\n actions?: ReactNode;\n /**\n * The one element that opens the dialog, such as a `Button`. Focus returns\n * to it when the dialog closes, unless `finalFocusRef` names another\n * element. Leave it out to open the dialog with `open` from elsewhere.\n */\n trigger?: ReactElement;\n /** Controlled open state. Pair with `onOpenChange`. */\n open?: boolean;\n /** Initial open state when uncontrolled. */\n defaultOpen?: boolean;\n /**\n * Fired with the requested state whenever the dialog asks to open (its\n * trigger) or close (a `DialogClose`, the close button, Escape, or for\n * `role=\"dialog\"` a click outside). A controlled dialog stays as it is\n * until `open` changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * `dialog` (default) shows a close button and closes on Escape and on a\n * click outside. `alertdialog` is for confirmations: no close button, and a\n * click outside does nothing, so the explicit cancel action is the way\n * out. Escape still cancels.\n */\n role?: DialogRole;\n /**\n * Where focus lands when the dialog opens. Defaults to the first focusable\n * element: the close button of a `dialog`, the first action of an\n * `alertdialog` with no focusable body. Point an alertdialog at its least\n * destructive action.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus lands when the dialog closes, in place of the trigger. Use it\n * when the confirmed action removes the trigger, such as a row's Remove\n * button: focus would return to an element that is about to unmount and\n * fall to the page body. Point it at something that stays, such as the\n * list's heading, which needs `tabIndex={-1}` to take focus.\n *\n * The ref is read as the dialog closes, however it closes. Fill it in the\n * committing action, so Cancel and Escape still return focus to the\n * trigger, which is still there. While the ref holds no element, focus\n * returns to the trigger as usual.\n */\n finalFocusRef?: RefObject<HTMLElement | null>;\n /** Accessible name of the close button. Translate it with the rest of the UI. */\n closeLabel?: string;\n /**\n * Glyph for the close button. Defaults to the `IconDefaultsProvider`'s\n * `cross`, or a plain built-in one.\n */\n closeIcon?: IconSource;\n /**\n * How wide the panel may grow: `md` (the default) for a message or a short\n * form, `lg` for a form with fields side by side.\n */\n size?: DialogSize;\n /**\n * `modal` (the default) floats the panel over a dimmed page. `side` opens\n * it in the drawer of the nearest `SidePanelLayout`, beside the content,\n * which stays in view and usable: a form for one item of a list the user\n * may want to browse while filling it in. A side panel traps no focus,\n * locks no scroll and stays open on a click outside. Escape closes it\n * while focus is in it or on no control, and leaves an Escape pressed on a\n * control in the page to that control. On close, focus returns as from a\n * modal unless the user had moved it onto the page. It is as wide as a `md` dialog, so `size`\n * does not apply. Opening another side dialog in the layout closes this\n * one through `onOpenChange`; a controlled dialog should honour it.\n *\n * Outside a `SidePanelLayout`, for `role=\"alertdialog\"`, which must hold\n * the user until they answer, and inside another dialog, the dialog opens\n * as a modal.\n */\n presentation?: DialogPresentation;\n /** Extra class names appended to the panel's `ds-dialog`. */\n className?: string;\n}\n\n/**\n * A modal dialog: a raised panel over a dimmed page, built on Ark UI.\n *\n * Ark owns the behaviour: the focus trap, focus returning to the trigger\n * (or to `finalFocusRef`), Escape, the page's scroll lock, `aria-modal`, and the title and\n * description wiring. This wrapper adds the `ds-` classes, the\n * `--ds-dialog-*` bindings, and a slot API in place of Ark's anatomy.\n *\n * ```tsx\n * <Dialog\n * role=\"alertdialog\"\n * title=\"Remove “Site foreman”?\"\n * description=\"2 people and 1 Landfall lose this type; nothing else is deleted.\"\n * trigger={<Button variant=\"secondary\">Remove</Button>}\n * initialFocusRef={cancelRef}\n * actions={\n * <>\n * <DialogClose>\n * <Button ref={cancelRef} variant=\"secondary\">Cancel</Button>\n * </DialogClose>\n * <Button variant=\"danger\" onClick={remove}>Remove</Button>\n * </>\n * }\n * />\n * ```\n *\n * The committing action is the consumer's own button. To close after it\n * runs, control the dialog with `open` and set it false in the handler, or\n * wrap the button in `DialogClose` when closing at once is right.\n *\n * The backdrop and panel portal into `<body>` at `z-index: 50`, the layer\n * the product apps use for their own overlays. A Select or Menu inside the\n * dialog portals into its panel (see `PortalContainerContext`) and opens at\n * 60, above it. Nothing is mounted while the dialog is closed.\n */\nexport function Dialog({\n title,\n description,\n children,\n actions,\n trigger,\n open,\n defaultOpen,\n onOpenChange,\n role = 'dialog',\n initialFocusRef,\n finalFocusRef,\n closeLabel = 'Close',\n closeIcon: closeIconProp,\n size = 'md',\n presentation = 'modal',\n className,\n}: DialogProps) {\n const icons = useIconDefaults();\n const closeIcon = closeIconProp ?? icons.cross;\n const dismissible = role === 'dialog';\n const slot = useContext(SidePanelSlotContext);\n const side = presentation === 'side' && dismissible && slot ? slot : undefined;\n const panelRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [sidePanel, setSidePanel] = useState<HTMLDivElement | null>(null);\n const sidePanelRef = useCallback((element: HTMLDivElement | null) => {\n panelRef.current = element;\n setSidePanel(element);\n }, []);\n const handleOpenChange = (details: { open: boolean }) => onOpenChange?.(details.open);\n // Zag types this as returning `HTMLElement | null`, but its focus trap\n // reads undefined as \"the first focusable element\" and, given null, fails\n // to start at all, leaving the page reachable by Tab.\n const initialFocusEl = (() => initialFocusRef?.current ?? undefined) as () => HTMLElement | null;\n const finalFocusEl = () => finalFocusRef?.current ?? null;\n // Zag's dismiss layer takes Escape anywhere in the document. A side panel\n // leaves the page usable, so an Escape meant for a control on the page,\n // such as a ReorderControl dropping its draft, must not close it too.\n const keepEscapeOnThePage = (event: KeyboardEvent) => {\n const target = event.target;\n const onThePage =\n target instanceof Node &&\n target !== target.ownerDocument?.body &&\n !panelRef.current?.contains(target);\n if (onThePage) event.preventDefault();\n };\n const panel = (\n <PortalContainerContext.Provider value={panelRef}>\n <div className=\"ds-dialog__header\">\n <div className=\"ds-dialog__heading\">\n <ArkDialog.Title className=\"ds-dialog__title\">{title}</ArkDialog.Title>\n {description && (\n <ArkDialog.Description className=\"ds-dialog__description\">\n {description}\n </ArkDialog.Description>\n )}\n </div>\n {dismissible && (\n <ArkDialog.CloseTrigger asChild>\n <IconButton\n icon={closeIcon}\n aria-label={closeLabel}\n variant=\"tertiary\"\n size=\"sm\"\n className=\"ds-dialog__close\"\n />\n </ArkDialog.CloseTrigger>\n )}\n </div>\n {children && <DialogBody>{children}</DialogBody>}\n {actions && <div className=\"ds-dialog__actions\">{actions}</div>}\n </PortalContainerContext.Provider>\n );\n const content = (\n <SidePanelSlotContext.Provider value={undefined}>{panel}</SidePanelSlotContext.Provider>\n );\n\n return (\n <ArkDialog.Root\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={handleOpenChange}\n role={role}\n modal={!side}\n closeOnInteractOutside={dismissible && !side}\n onEscapeKeyDown={side ? keepEscapeOnThePage : undefined}\n initialFocusEl={initialFocusEl}\n finalFocusEl={finalFocusEl}\n lazyMount\n unmountOnExit\n >\n {trigger && (\n <ArkDialog.Trigger ref={triggerRef} asChild>\n {trigger}\n </ArkDialog.Trigger>\n )}\n {side ? (\n side.container &&\n createPortal(\n <ArkDialog.Content\n ref={sidePanelRef}\n className={cx('ds-dialog', 'ds-dialog--side', className)}\n >\n <SidePanelSeat\n claim={side.claim}\n panel={sidePanel}\n triggerRef={triggerRef}\n finalFocusRef={finalFocusRef}\n />\n {content}\n </ArkDialog.Content>,\n side.container,\n )\n ) : (\n <Portal>\n <ArkDialog.Backdrop className=\"ds-dialog__backdrop\" />\n <ArkDialog.Positioner className=\"ds-dialog__positioner\">\n <ArkDialog.Content\n ref={panelRef}\n className={cx('ds-dialog', size === 'lg' && 'ds-dialog--lg', className)}\n >\n {content}\n </ArkDialog.Content>\n </ArkDialog.Positioner>\n </Portal>\n )}\n </ArkDialog.Root>\n );\n}\n\n/**\n * What a side panel needs that Ark leaves to a modal's focus trap: the slot,\n * taken on open so any other panel closes; the panel scrolled into view,\n * since below the `lg` step it sits above the content in the page's flow;\n * and focus put back on close. Focus moves when it was inside the panel or\n * on nothing, as after a save whose button disabled itself and so dropped\n * focus, so closing the panel never pulls the user out of the list they\n * moved to but never leaves them on the page's body either.\n * It goes where the trap would send it: `finalFocusRef`'s element, else the\n * trigger, else what had focus when the panel opened. The trigger is named\n * outright because Safari does not focus a button on click.\n *\n * The panel arrives as state from its callback ref: a child's layout effect\n * runs before its parent's ref is attached. A layout effect, because its\n * cleanup runs while the panel is still in the document and can still hold\n * focus, and before Ark moves focus into the panel a frame after it opens.\n * It runs once per opening: the callbacks and refs it reads at close are\n * kept current beside it, so a re-render never closes and reopens the seat.\n */\nfunction SidePanelSeat({\n claim,\n panel,\n triggerRef,\n finalFocusRef,\n}: {\n claim: SidePanelSlot['claim'];\n panel: HTMLDivElement | null;\n triggerRef: RefObject<HTMLElement | null>;\n finalFocusRef?: RefObject<HTMLElement | null>;\n}) {\n const dialog = useDialogContext();\n const latest = useRef({ setOpen: dialog.setOpen, finalFocusRef });\n useLayoutEffect(() => {\n latest.current = { setOpen: dialog.setOpen, finalFocusRef };\n });\n\n useLayoutEffect(() => {\n if (!panel) return;\n const opener = panel.ownerDocument.activeElement;\n const release = claim(() => latest.current.setOpen(false));\n panel.scrollIntoView({ block: 'nearest' });\n return () => {\n release();\n const active = panel.ownerDocument.activeElement;\n const movedToThePage =\n active && active !== panel.ownerDocument.body && !panel.contains(active);\n if (movedToThePage) return;\n const target = [latest.current.finalFocusRef?.current, triggerRef.current, opener].find(\n (element) => element instanceof HTMLElement && element.isConnected,\n );\n if (target instanceof HTMLElement) target.focus();\n };\n }, [claim, panel, triggerRef]);\n\n return null;\n}\n\n/**\n * The scrolling body. While its content overflows it joins the tab order, so\n * a keyboard user can focus it and scroll; a body with nothing to scroll\n * stays out of the way.\n *\n * Two boxes are observed because either can change the answer: the outer one\n * resizes with the viewport, the inner one with the content.\n */\nfunction DialogBody({ children }: { children: ReactNode }) {\n const [scrollable, setScrollable] = useState(false);\n const observe = useCallback((scroller: HTMLDivElement | null) => {\n const content = scroller?.firstElementChild;\n if (!scroller || !content) return;\n const observer = new ResizeObserver(() =>\n setScrollable(scroller.scrollHeight > scroller.clientHeight),\n );\n observer.observe(scroller);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n\n return (\n <div ref={observe} className=\"ds-dialog__body\" tabIndex={scrollable ? 0 : undefined}>\n <div className=\"ds-dialog__body-content\">{children}</div>\n </div>\n );\n}\n"]}
|
package/dist/fallback-glyphs.js
CHANGED
|
@@ -11,9 +11,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
11
11
|
* `check:tarballs` enforces that. A default that ships inside ui-core's own
|
|
12
12
|
* runtime therefore cannot be a licensed icon.
|
|
13
13
|
*
|
|
14
|
-
* These exist only so the package works standalone.
|
|
15
|
-
*
|
|
16
|
-
* render Lineicons here.
|
|
14
|
+
* These exist only so the package works standalone. A product sets its own
|
|
15
|
+
* once with `IconDefaultsProvider`, which is how the Humanity Plus apps
|
|
16
|
+
* render Lineicons here; a component's own icon prop still wins.
|
|
17
17
|
*
|
|
18
18
|
* Note: that audit is a plain string scan over the built output, and tsc
|
|
19
19
|
* keeps comments, so naming the private package here — even in prose —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback-glyphs.js","sourceRoot":"","sources":["../src/fallback-glyphs.tsx"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CACjD,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,cAAc,EAChB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,GACE,CACP,CAAC;AACF,YAAY,CAAC,WAAW,GAAG,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,WAAW,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAChD,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,eAAe,EACjB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,GACE,CACP,CAAC;AACF,WAAW,CAAC,WAAW,GAAG,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,KAAK,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAC1C,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,kBAAkB,EACpB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,GACE,CACP,CAAC;AACF,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC;AAEpC,MAAM,CAAC,MAAM,KAAK,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAC1C,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,kBAAkB,EACpB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACrB,GACE,CACP,CAAC;AACF,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC;AAEpC,MAAM,CAAC,MAAM,GAAG,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CACxC,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,gDAAgD,EAClD,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,GACE,CACP,CAAC;AACF,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { IconSource } from './icon/icon';\n\n/*\n * Fallback glyphs for the components whose icon slots default to something\n * (Select's indicators, Menu's check, Dialog's close button), inlined on\n * purpose and kept in one place. The package root exports them as\n * `Fallback*`, so a product composition with the same default reuses these\n * rather than copying the path data.\n *\n * ui-core is public and MIT; the Lineicons Pro icon package is private and\n * carries proprietary payloads, so a public package must not reference it —\n * `check:tarballs` enforces that. A default that ships inside ui-core's own\n * runtime therefore cannot be a licensed icon.\n *\n * These exist only so the package works standalone.
|
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K,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAC1C,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,kBAAkB,EACpB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACrB,GACE,CACP,CAAC;AACF,KAAK,CAAC,WAAW,GAAG,eAAe,CAAC;AAEpC,MAAM,CAAC,MAAM,GAAG,GAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CACxC,6BAAiB,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,KAAK,KAAK,YAC/D,eACE,CAAC,EAAC,gDAAgD,EAClD,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACtB,GACE,CACP,CAAC;AACF,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { IconSource } from './icon/icon';\n\n/*\n * Fallback glyphs for the components whose icon slots default to something\n * (Select's indicators, Menu's check, Dialog's close button), inlined on\n * purpose and kept in one place. The package root exports them as\n * `Fallback*`, so a product composition with the same default reuses these\n * rather than copying the path data.\n *\n * ui-core is public and MIT; the Lineicons Pro icon package is private and\n * carries proprietary payloads, so a public package must not reference it —\n * `check:tarballs` enforces that. A default that ships inside ui-core's own\n * runtime therefore cannot be a licensed icon.\n *\n * These exist only so the package works standalone. A product sets its own\n * once with `IconDefaultsProvider`, which is how the Humanity Plus apps\n * render Lineicons here; a component's own icon prop still wins.\n *\n * Note: that audit is a plain string scan over the built output, and tsc\n * keeps comments, so naming the private package here — even in prose —\n * would fail CI. Describe it, do not spell it.\n */\nexport const ChevronRight: IconSource = (props) => (\n <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" {...props}>\n <path\n d=\"m6 4 4 4-4 4\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n);\nChevronRight.displayName = 'FallbackChevronRight';\n\nexport const ChevronLeft: IconSource = (props) => (\n <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" {...props}>\n <path\n d=\"M10 4 6 8l4 4\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n);\nChevronLeft.displayName = 'FallbackChevronLeft';\n\nexport const Check: IconSource = (props) => (\n <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" {...props}>\n <path\n d=\"m3.5 8.5 3 3 6-6\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n);\nCheck.displayName = 'FallbackCheck';\n\nexport const Cross: IconSource = (props) => (\n <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" {...props}>\n <path\n d=\"m4 4 8 8m0-8-8 8\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n />\n </svg>\n);\nCross.displayName = 'FallbackCross';\n\nexport const Pin: IconSource = (props) => (\n <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" {...props}>\n <path\n d=\"M6 2.5h4M7 2.5v3.75L4.5 9h7L9 6.25V2.5M8 9v4.5\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n);\nPin.displayName = 'FallbackPin';\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { IconSource } from './icon/icon';
|
|
3
|
+
/**
|
|
4
|
+
* The glyphs ui-core draws when a component's icon prop is left out, by
|
|
5
|
+
* shape: a select's and a menu's chevron, a checkbox's check, a dialog's
|
|
6
|
+
* close cross. Chevrons point right, and a component that needs another
|
|
7
|
+
* direction turns the one it is given.
|
|
8
|
+
*/
|
|
9
|
+
export interface IconDefaults {
|
|
10
|
+
/** Select's and Menu's indicator, Calendar's next month, Accordion's indicator. */
|
|
11
|
+
chevronRight: IconSource;
|
|
12
|
+
/** Calendar's previous month. */
|
|
13
|
+
chevronLeft: IconSource;
|
|
14
|
+
/** Checkbox's check, and the chosen option in Select and the menus. */
|
|
15
|
+
check: IconSource;
|
|
16
|
+
/** Dialog's close button and Combobox's remove. */
|
|
17
|
+
cross: IconSource;
|
|
18
|
+
/** Combobox's pin. */
|
|
19
|
+
pin: IconSource;
|
|
20
|
+
}
|
|
21
|
+
export interface IconDefaultsProviderProps {
|
|
22
|
+
/** The product's glyphs. A shape left out keeps the one around it, or the built-in fallback. */
|
|
23
|
+
icons: Partial<IconDefaults>;
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets the glyphs every ui-core component below it draws by default, so a
|
|
28
|
+
* product puts its own icon set in once, at its root, instead of passing
|
|
29
|
+
* `indicator`, `itemIndicator` or `closeIcon` at every call. A prop passed to
|
|
30
|
+
* one component still wins.
|
|
31
|
+
*
|
|
32
|
+
* The icons are functions, which a Next.js Server Component cannot pass to a
|
|
33
|
+
* client one, so a Next.js app mounts the provider from a client component of
|
|
34
|
+
* its own.
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <IconDefaultsProvider icons={{ chevronRight: ChevronRight, check: Check }}>
|
|
38
|
+
* <App />
|
|
39
|
+
* </IconDefaultsProvider>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function IconDefaultsProvider({ icons, children }: IconDefaultsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
/** The glyphs in force here: the nearest provider's, or the built-in fallbacks. */
|
|
44
|
+
export declare function useIconDefaults(): IconDefaults;
|
|
45
|
+
//# sourceMappingURL=icon-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-defaults.d.ts","sourceRoot":"","sources":["../src/icon-defaults.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,YAAY,EAAE,UAAU,CAAC;IACzB,iCAAiC;IACjC,WAAW,EAAE,UAAU,CAAC;IACxB,uEAAuE;IACvE,KAAK,EAAE,UAAU,CAAC;IAClB,mDAAmD;IACnD,KAAK,EAAE,UAAU,CAAC;IAClB,sBAAsB;IACtB,GAAG,EAAE,UAAU,CAAC;CACjB;AAYD,MAAM,WAAW,yBAAyB;IACxC,gGAAgG;IAChG,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,yBAAyB,2CAOlF;AAED,mFAAmF;AACnF,wBAAgB,eAAe,IAAI,YAAY,CAE9C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// A client boundary, so a React Server Component can import the provider:
|
|
2
|
+
// React's server build has no createContext. See docs/decisions/icon-defaults.mdx.
|
|
3
|
+
'use client';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
6
|
+
import { Check, ChevronLeft, ChevronRight, Cross, Pin } from './fallback-glyphs';
|
|
7
|
+
const FALLBACKS = {
|
|
8
|
+
chevronRight: ChevronRight,
|
|
9
|
+
chevronLeft: ChevronLeft,
|
|
10
|
+
check: Check,
|
|
11
|
+
cross: Cross,
|
|
12
|
+
pin: Pin,
|
|
13
|
+
};
|
|
14
|
+
const IconDefaultsContext = createContext(FALLBACKS);
|
|
15
|
+
/**
|
|
16
|
+
* Sets the glyphs every ui-core component below it draws by default, so a
|
|
17
|
+
* product puts its own icon set in once, at its root, instead of passing
|
|
18
|
+
* `indicator`, `itemIndicator` or `closeIcon` at every call. A prop passed to
|
|
19
|
+
* one component still wins.
|
|
20
|
+
*
|
|
21
|
+
* The icons are functions, which a Next.js Server Component cannot pass to a
|
|
22
|
+
* client one, so a Next.js app mounts the provider from a client component of
|
|
23
|
+
* its own.
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <IconDefaultsProvider icons={{ chevronRight: ChevronRight, check: Check }}>
|
|
27
|
+
* <App />
|
|
28
|
+
* </IconDefaultsProvider>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function IconDefaultsProvider({ icons, children }) {
|
|
32
|
+
const outer = useContext(IconDefaultsContext);
|
|
33
|
+
const value = useMemo(() => {
|
|
34
|
+
const given = Object.entries(icons).filter(([, icon]) => icon !== undefined);
|
|
35
|
+
return { ...outer, ...Object.fromEntries(given) };
|
|
36
|
+
}, [outer, icons]);
|
|
37
|
+
return _jsx(IconDefaultsContext.Provider, { value: value, children: children });
|
|
38
|
+
}
|
|
39
|
+
/** The glyphs in force here: the nearest provider's, or the built-in fallbacks. */
|
|
40
|
+
export function useIconDefaults() {
|
|
41
|
+
return useContext(IconDefaultsContext);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=icon-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-defaults.js","sourceRoot":"","sources":["../src/icon-defaults.tsx"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mFAAmF;AACnF,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAsBjF,MAAM,SAAS,GAAiB;IAC9B,YAAY,EAAE,YAAY;IAC1B,WAAW,EAAE,WAAW;IACxB,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAe,SAAS,CAAC,CAAC;AAQnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA6B;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC7E,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACnB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC","sourcesContent":["// A client boundary, so a React Server Component can import the provider:\n// React's server build has no createContext. See docs/decisions/icon-defaults.mdx.\n'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\nimport { Check, ChevronLeft, ChevronRight, Cross, Pin } from './fallback-glyphs';\nimport type { IconSource } from './icon/icon';\n\n/**\n * The glyphs ui-core draws when a component's icon prop is left out, by\n * shape: a select's and a menu's chevron, a checkbox's check, a dialog's\n * close cross. Chevrons point right, and a component that needs another\n * direction turns the one it is given.\n */\nexport interface IconDefaults {\n /** Select's and Menu's indicator, Calendar's next month, Accordion's indicator. */\n chevronRight: IconSource;\n /** Calendar's previous month. */\n chevronLeft: IconSource;\n /** Checkbox's check, and the chosen option in Select and the menus. */\n check: IconSource;\n /** Dialog's close button and Combobox's remove. */\n cross: IconSource;\n /** Combobox's pin. */\n pin: IconSource;\n}\n\nconst FALLBACKS: IconDefaults = {\n chevronRight: ChevronRight,\n chevronLeft: ChevronLeft,\n check: Check,\n cross: Cross,\n pin: Pin,\n};\n\nconst IconDefaultsContext = createContext<IconDefaults>(FALLBACKS);\n\nexport interface IconDefaultsProviderProps {\n /** The product's glyphs. A shape left out keeps the one around it, or the built-in fallback. */\n icons: Partial<IconDefaults>;\n children: ReactNode;\n}\n\n/**\n * Sets the glyphs every ui-core component below it draws by default, so a\n * product puts its own icon set in once, at its root, instead of passing\n * `indicator`, `itemIndicator` or `closeIcon` at every call. A prop passed to\n * one component still wins.\n *\n * The icons are functions, which a Next.js Server Component cannot pass to a\n * client one, so a Next.js app mounts the provider from a client component of\n * its own.\n *\n * ```tsx\n * <IconDefaultsProvider icons={{ chevronRight: ChevronRight, check: Check }}>\n * <App />\n * </IconDefaultsProvider>\n * ```\n */\nexport function IconDefaultsProvider({ icons, children }: IconDefaultsProviderProps) {\n const outer = useContext(IconDefaultsContext);\n const value = useMemo(() => {\n const given = Object.entries(icons).filter(([, icon]) => icon !== undefined);\n return { ...outer, ...Object.fromEntries(given) };\n }, [outer, icons]);\n return <IconDefaultsContext.Provider value={value}>{children}</IconDefaultsContext.Provider>;\n}\n\n/** The glyphs in force here: the nearest provider's, or the built-in fallbacks. */\nexport function useIconDefaults(): IconDefaults {\n return useContext(IconDefaultsContext);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './accordion';
|
|
1
2
|
export * from './alert';
|
|
2
3
|
export * from './avatar';
|
|
3
4
|
export * from './badge';
|
|
@@ -17,6 +18,7 @@ export { Check as FallbackCheck, ChevronLeft as FallbackChevronLeft, ChevronRigh
|
|
|
17
18
|
export * from './field';
|
|
18
19
|
export * from './form-layout';
|
|
19
20
|
export * from './icon';
|
|
21
|
+
export * from './icon-defaults';
|
|
20
22
|
export * from './illustration';
|
|
21
23
|
export * from './layout';
|
|
22
24
|
export * from './link';
|
|
@@ -25,6 +27,7 @@ export * from './menu';
|
|
|
25
27
|
export * from './page-layout';
|
|
26
28
|
export * from './popover';
|
|
27
29
|
export * from './progress';
|
|
30
|
+
export * from './radio-group';
|
|
28
31
|
export * from './reorder-control';
|
|
29
32
|
export * from './scroll-area';
|
|
30
33
|
export * from './section';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CA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Ae,CAAC;AAC9B,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './accordion';
|
|
1
2
|
export * from './alert';
|
|
2
3
|
export * from './avatar';
|
|
3
4
|
export * from './badge';
|
|
@@ -17,6 +18,7 @@ export { Check as FallbackCheck, ChevronLeft as FallbackChevronLeft, ChevronRigh
|
|
|
17
18
|
export * from './field';
|
|
18
19
|
export * from './form-layout';
|
|
19
20
|
export * from './icon';
|
|
21
|
+
export * from './icon-defaults';
|
|
20
22
|
export * from './illustration';
|
|
21
23
|
export * from './layout';
|
|
22
24
|
export * from './link';
|
|
@@ -24,6 +26,7 @@ export * from './menu';
|
|
|
24
26
|
export * from './page-layout';
|
|
25
27
|
export * from './popover';
|
|
26
28
|
export * from './progress';
|
|
29
|
+
export * from './radio-group';
|
|
27
30
|
export * from './reorder-control';
|
|
28
31
|
export * from './scroll-area';
|
|
29
32
|
export * from './section';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AAEvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './alert';\nexport * from './avatar';\nexport * from './badge';\nexport * from './breadcrumb';\nexport * from './button';\nexport * from './calendar';\nexport * from './card';\nexport * from './centered-layout';\nexport * from './checkbox';\nexport * from './combobox';\nexport { cx } from './cx';\nexport * from './date-input';\nexport * from './dialog';\nexport * from './divider';\nexport * from './empty-state';\nexport {\n Check as FallbackCheck,\n ChevronLeft as FallbackChevronLeft,\n ChevronRight as FallbackChevronRight,\n Cross as FallbackCross,\n Pin as FallbackPin,\n} from './fallback-glyphs';\nexport * from './field';\nexport * from './form-layout';\nexport * from './icon';\nexport * from './illustration';\nexport * from './layout';\nexport * from './link';\nexport type { LinkComponentProps } from './link-component';\nexport * from './menu';\nexport * from './page-layout';\nexport * from './popover';\nexport * from './progress';\nexport * from './reorder-control';\nexport * from './scroll-area';\nexport * from './section';\nexport * from './segment-group';\nexport * from './select';\nexport * from './show';\nexport * from './side-panel-layout';\nexport * from './skeleton';\nexport * from './slider';\nexport * from './spinner';\nexport * from './split-layout';\nexport * from './sticky';\nexport * from './switch';\nexport * from './tabs';\nexport * from './text';\nexport * from './tooltip';\nexport * from './visually-hidden';\nexport * from './wizard-layout';\n"]}
|
|
1
|
+
{"version":3,"file":"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AAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './accordion';\nexport * from './alert';\nexport * from './avatar';\nexport * from './badge';\nexport * from './breadcrumb';\nexport * from './button';\nexport * from './calendar';\nexport * from './card';\nexport * from './centered-layout';\nexport * from './checkbox';\nexport * from './combobox';\nexport { cx } from './cx';\nexport * from './date-input';\nexport * from './dialog';\nexport * from './divider';\nexport * from './empty-state';\nexport {\n Check as FallbackCheck,\n ChevronLeft as FallbackChevronLeft,\n ChevronRight as FallbackChevronRight,\n Cross as FallbackCross,\n Pin as FallbackPin,\n} from './fallback-glyphs';\nexport * from './field';\nexport * from './form-layout';\nexport * from './icon';\nexport * from './icon-defaults';\nexport * from './illustration';\nexport * from './layout';\nexport * from './link';\nexport type { LinkComponentProps } from './link-component';\nexport * from './menu';\nexport * from './page-layout';\nexport * from './popover';\nexport * from './progress';\nexport * from './radio-group';\nexport * from './reorder-control';\nexport * from './scroll-area';\nexport * from './section';\nexport * from './segment-group';\nexport * from './select';\nexport * from './show';\nexport * from './side-panel-layout';\nexport * from './skeleton';\nexport * from './slider';\nexport * from './spinner';\nexport * from './split-layout';\nexport * from './sticky';\nexport * from './switch';\nexport * from './tabs';\nexport * from './text';\nexport * from './tooltip';\nexport * from './visually-hidden';\nexport * from './wizard-layout';\n"]}
|
|
@@ -73,8 +73,8 @@ export interface ActionMenuProps {
|
|
|
73
73
|
*/
|
|
74
74
|
linkComponent?: ElementType<ActionMenuLinkProps>;
|
|
75
75
|
/**
|
|
76
|
-
* Glyph marking the `current` link. Defaults to
|
|
77
|
-
*
|
|
76
|
+
* Glyph marking the `current` link. Defaults to the `IconDefaultsProvider`'s
|
|
77
|
+
* `check`, or a plain built-in one.
|
|
78
78
|
*/
|
|
79
79
|
itemIndicator?: IconSource;
|
|
80
80
|
/** Controlled open state. Pair with `onOpenChange`. */
|
|
@@ -114,5 +114,5 @@ export interface ActionMenuProps {
|
|
|
114
114
|
* The popup renders in a portal, at the same `z-index: 60` as Select's
|
|
115
115
|
* listbox, and is mounted only while open, as `Menu`'s is.
|
|
116
116
|
*/
|
|
117
|
-
export declare function ActionMenu({ trigger, items, onSelect, header, footer, linkComponent, itemIndicator, open, onOpenChange, className, }: ActionMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
117
|
+
export declare function ActionMenu({ trigger, items, onSelect, header, footer, linkComponent, itemIndicator: itemIndicatorProp, open, onOpenChange, className, }: ActionMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
118
118
|
//# sourceMappingURL=action-menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-menu.d.ts","sourceRoot":"","sources":["../../src/menu/action-menu.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAsB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"action-menu.d.ts","sourceRoot":"","sources":["../../src/menu/action-menu.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAsB,MAAM,OAAO,CAAC;AAEhG,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,YAAY,CAAC;AAEpB,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,OAAO,EAAE,YAAY,CAAC;IACtB,uCAAuC;IACvC,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAC;IACjD;;;OAGG;IACH,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,uDAAuD;IACvD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,8EAA8E;IAC9E,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA4CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,UAAU,CAAC,EACzB,OAAO,EACP,KAAK,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,aAAmB,EACnB,aAAa,EAAE,iBAAiB,EAChC,IAAI,EACJ,YAAY,EACZ,SAAS,GACV,EAAE,eAAe,2CAmEjB"}
|
package/dist/menu/action-menu.js
CHANGED
|
@@ -3,8 +3,8 @@ import { Menu as ArkMenu } from '@ark-ui/react/menu';
|
|
|
3
3
|
import { Portal } from '@ark-ui/react/portal';
|
|
4
4
|
import { useContext, useRef } from 'react';
|
|
5
5
|
import { cx } from '../cx';
|
|
6
|
-
import { Check } from '../fallback-glyphs';
|
|
7
6
|
import { Icon } from '../icon/icon';
|
|
7
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
8
8
|
import { PortalContainerContext } from '../portal-container';
|
|
9
9
|
import './menu.css';
|
|
10
10
|
function ActionMenuRow({ item, linkComponent: LinkComponent, itemIndicator }) {
|
|
@@ -51,7 +51,9 @@ function ActionMenuRow({ item, linkComponent: LinkComponent, itemIndicator }) {
|
|
|
51
51
|
* The popup renders in a portal, at the same `z-index: 60` as Select's
|
|
52
52
|
* listbox, and is mounted only while open, as `Menu`'s is.
|
|
53
53
|
*/
|
|
54
|
-
export function ActionMenu({ trigger, items, onSelect, header, footer, linkComponent = 'a', itemIndicator
|
|
54
|
+
export function ActionMenu({ trigger, items, onSelect, header, footer, linkComponent = 'a', itemIndicator: itemIndicatorProp, open, onOpenChange, className, }) {
|
|
55
|
+
const icons = useIconDefaults();
|
|
56
|
+
const itemIndicator = itemIndicatorProp ?? icons.check;
|
|
55
57
|
const portalContainer = useContext(PortalContainerContext);
|
|
56
58
|
const handleSelect = (details) => onSelect?.(details.value);
|
|
57
59
|
const handleOpenChange = (details) => onOpenChange?.(details.open);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-menu.js","sourceRoot":"","sources":["../../src/menu/action-menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAuD,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChG,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,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,OAAO,CAAC,SAAS,eAChB,KAAC,OAAO,CAAC,cAAc,IAAC,SAAS,EAAC,iBAAiB,YAAE,MAAM,GAA0B,EACpF,IAAI,IACa,CACrB,CAAC;IAEJ,OAAO,CACL,MAAC,OAAO,CAAC,IAAI,IACX,SAAS,QACT,aAAa,QACb,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,QAAQ,EAClB,iBAAiB,EAAE,iBAAiB,aAEpC,KAAC,OAAO,CAAC,OAAO,IAAC,OAAO,kBAAE,OAAO,GAAmB,EAEpD,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,OAAO,CAAC,UAAU,cACjB,eAAK,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,aAC7C,KAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAC,kBAAkB,YAAE,IAAI,GAAmB,EACtE,cAAK,GAAG,EAAE,SAAS,EAAE,SAAS,EAAC,iBAAiB,eAAW,QAAQ,YAChE,MAAM,GACH,IACF,GACa,GACd,IACI,CAChB,CAAC;AACJ,CAAC","sourcesContent":["import { Menu as ArkMenu } from '@ark-ui/react/menu';\nimport { Portal } from '@ark-ui/react/portal';\nimport { type ElementType, type ReactElement, type ReactNode, useContext, useRef } from 'react';\nimport { cx } from '../cx';\nimport { Check } from '../fallback-glyphs';\nimport { Icon, type IconSource } from '../icon/icon';\nimport type { LinkComponentProps } from '../link-component';\nimport { PortalContainerContext } from '../portal-container';\nimport './menu.css';\n\nexport interface ActionMenuItem {\n /** Stable value reported by `onSelect`. */\n value: string;\n /** Text shown in the menu. Also what typeahead matches against. */\n label: string;\n /** Glyph before the label. Decorative: the label says what the item does. */\n icon?: IconSource;\n /**\n * Makes the item a link to this address, rendered through `linkComponent`.\n * Choosing it follows the link, with the keyboard too; `onSelect` still\n * reports its value.\n */\n href?: string;\n /**\n * Marks the link to the page the user is on: `aria-current=\"page\"`, and\n * the `itemIndicator` glyph after the label so the mark is not colour alone.\n */\n current?: boolean;\n /** Individually disable this item without removing it. */\n disabled?: boolean;\n /**\n * Whether choosing the item closes the menu. Defaults to `true`. Keep an\n * item open when its outcome shows in the `footer`, so a failure appears\n * where the click happened.\n */\n closeOnSelect?: boolean;\n}\n\n/**\n * The props a `linkComponent` receives. A plain `'a'` and a router's link\n * component both accept them; Ark adds the menu item's role, id, state\n * attributes and handlers on top, so the component must pass unknown props\n * and its `ref` on to the anchor it renders.\n */\nexport interface ActionMenuLinkProps extends LinkComponentProps {\n 'aria-current'?: 'page';\n}\n\nexport interface ActionMenuProps {\n /**\n * The element that opens the menu: a `<button>`, or a component that\n * passes its props and `ref` on to one, such as `IconButton` or\n * `MenuTrigger`. Ark renders it as the trigger, adding `aria-haspopup`,\n * `aria-expanded`, `aria-controls`, the open and close handlers and\n * `data-state`. Give it an accessible name that says what the menu holds,\n * such as \"Account menu\" or \"Main navigation\": the menu takes its name\n * from the trigger.\n */\n trigger: ReactElement;\n /** The actions and links, in order. */\n items: ActionMenuItem[];\n /** Fired with the item's `value` when one is chosen, a link included. */\n onSelect?: (value: string) => void;\n /**\n * Content above the items that says whose menu this is, such as the\n * signed-in user's name and email. It names the group of items for\n * assistive technology, so keep it to text and decorative elements.\n */\n header?: ReactNode;\n /**\n * A line under the items about the last action, such as \"Couldn't sign\n * out. Check your connection, then try again.\" It is announced when it\n * appears, and a press on it leaves the menu open. It is not an item and\n * sits beside the `menu` element, which may own only items, so keep it to\n * text and a decorative glyph rather than an `Alert`.\n */\n footer?: ReactNode;\n /**\n * Renders an item with an `href`. Defaults to `'a'`; pass a router's link\n * component for client-side navigation.\n */\n linkComponent?: ElementType<ActionMenuLinkProps>;\n /**\n * Glyph marking the `current` link. Defaults to a plain built-in check so\n * `@manakind/ui-core` renders on its own; products pass their own icon.\n */\n itemIndicator?: IconSource;\n /** Controlled open state. Pair with `onOpenChange`. */\n open?: boolean;\n /** Fired with the requested state whenever the menu asks to open or close. */\n onOpenChange?: (open: boolean) => void;\n /** Extra class names on the menu's popup: the frame around the items and the footer. */\n className?: string;\n}\n\ninterface ActionMenuRowProps {\n item: ActionMenuItem;\n linkComponent: ElementType<ActionMenuLinkProps>;\n itemIndicator: IconSource;\n}\n\nfunction ActionMenuRow({ item, linkComponent: LinkComponent, itemIndicator }: ActionMenuRowProps) {\n const body = (\n <>\n <span className=\"ds-menu__item-body\">\n {item.icon && (\n <Icon source={item.icon} size=\"sm\" decorative className=\"ds-menu__item-icon\" />\n )}\n <ArkMenu.ItemText>{item.label}</ArkMenu.ItemText>\n </span>\n {item.current && (\n <span className=\"ds-menu__item-indicator\">\n <Icon source={itemIndicator} size=\"sm\" decorative />\n </span>\n )}\n </>\n );\n const itemProps = {\n value: item.value,\n valueText: item.label,\n disabled: item.disabled,\n closeOnSelect: item.closeOnSelect,\n className: 'ds-menu__item',\n };\n\n if (item.href === undefined) {\n return <ArkMenu.Item {...itemProps}>{body}</ArkMenu.Item>;\n }\n return (\n <ArkMenu.Item {...itemProps} asChild>\n <LinkComponent href={item.href} aria-current={item.current ? 'page' : undefined}>\n {body}\n </LinkComponent>\n </ArkMenu.Item>\n );\n}\n\n/**\n * A menu of actions and links, opened from a trigger, built on Ark UI's\n * Menu. The counterpart of `Menu`, whose items are mutually exclusive\n * choices: here every item does something or goes somewhere.\n *\n * Ark owns the hard parts: `menu` / `menuitem` semantics, roving highlight\n * with the arrow keys, Home/End, typeahead, Escape and click outside to\n * dismiss, following a link on Enter, and focus returning to the trigger on\n * close. This wrapper contributes the `ds-menu` classes and `--ds-menu-*`\n * bindings it shares with `Menu`, a flat `items` API, and the header and\n * footer slots.\n *\n * ```tsx\n * <ActionMenu\n * trigger={<IconButton icon={MenuGlyph} variant=\"tertiary\" aria-label=\"Main navigation\" />}\n * linkComponent={Link}\n * items={[\n * { value: 'dashboard', label: 'Dashboard', href: '/dashboard', current: true },\n * { value: 'goals', label: 'Goals', href: '/goals' },\n * ]}\n * />\n * ```\n *\n * Reach for this for an account menu, a row's overflow actions, or a\n * navigation that folds into a button on a phone. A set of choices where\n * exactly one is in effect is a `Menu`; a form field is a `Select`.\n *\n * The popup renders in a portal, at the same `z-index: 60` as Select's\n * listbox, and is mounted only while open, as `Menu`'s is.\n */\nexport function ActionMenu({\n trigger,\n items,\n onSelect,\n header,\n footer,\n linkComponent = 'a',\n itemIndicator = Check,\n open,\n onOpenChange,\n className,\n}: ActionMenuProps) {\n const portalContainer = useContext(PortalContainerContext);\n const handleSelect = (details: { value: string }) => onSelect?.(details.value);\n const handleOpenChange = (details: { open: boolean }) => onOpenChange?.(details.open);\n /*\n * Enter on a link item. Zag's default dispatches a click that does not\n * bubble, which the browser follows as a document load but React never\n * sees, so a router's link component could not take it over. `click()`\n * bubbles, and the link navigates the way a pointer click would.\n */\n const navigate = (details: { node: HTMLAnchorElement }) =>\n queueMicrotask(() => details.node.click());\n /*\n * The footer sits beside the `menu` element, not in it, because a menu may\n * own only items. To Zag that makes it outside, so a press on the message\n * would dismiss the menu; this keeps it open.\n */\n const footerRef = useRef<HTMLDivElement>(null);\n const keepOpenForFooter = (event: CustomEvent<{ originalEvent: Event }>) => {\n const target = event.detail.originalEvent.target;\n if (target instanceof Node && footerRef.current?.contains(target)) event.preventDefault();\n };\n\n const rows = items.map((item) => (\n <ActionMenuRow\n key={item.value}\n item={item}\n linkComponent={linkComponent}\n itemIndicator={itemIndicator}\n />\n ));\n const list =\n header === undefined ? (\n rows\n ) : (\n <ArkMenu.ItemGroup>\n <ArkMenu.ItemGroupLabel className=\"ds-menu__header\">{header}</ArkMenu.ItemGroupLabel>\n {rows}\n </ArkMenu.ItemGroup>\n );\n\n return (\n <ArkMenu.Root\n lazyMount\n unmountOnExit\n open={open}\n onOpenChange={handleOpenChange}\n onSelect={handleSelect}\n navigate={navigate}\n onInteractOutside={keepOpenForFooter}\n >\n <ArkMenu.Trigger asChild>{trigger}</ArkMenu.Trigger>\n\n <Portal container={portalContainer}>\n <ArkMenu.Positioner>\n <div className={cx('ds-menu__popup', className)}>\n <ArkMenu.Content className=\"ds-menu__content\">{list}</ArkMenu.Content>\n <div ref={footerRef} className=\"ds-menu__footer\" aria-live=\"polite\">\n {footer}\n </div>\n </div>\n </ArkMenu.Positioner>\n </Portal>\n </ArkMenu.Root>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"action-menu.js","sourceRoot":"","sources":["../../src/menu/action-menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAuD,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChG,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,YAAY,CAAC;AA6FpB,SAAS,aAAa,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAsB;IAC9F,MAAM,IAAI,GAAG,CACX,8BACE,gBAAM,SAAS,EAAC,oBAAoB,aACjC,IAAI,CAAC,IAAI,IAAI,CACZ,KAAC,IAAI,IAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,QAAC,SAAS,EAAC,oBAAoB,GAAG,CAChF,EACD,KAAC,OAAO,CAAC,QAAQ,cAAE,IAAI,CAAC,KAAK,GAAoB,IAC5C,EACN,IAAI,CAAC,OAAO,IAAI,CACf,eAAM,SAAS,EAAC,yBAAyB,YACvC,KAAC,IAAI,IAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,SAAG,GAC/C,CACR,IACA,CACJ,CAAC;IACF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AAE,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,aAC7C,KAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAC,kBAAkB,YAAE,IAAI,GAAmB,EACtE,cAAK,GAAG,EAAE,SAAS,EAAE,SAAS,EAAC,iBAAiB,eAAW,QAAQ,YAChE,MAAM,GACH,IACF,GACa,GACd,IACI,CAChB,CAAC;AACJ,CAAC","sourcesContent":["import { Menu as ArkMenu } from '@ark-ui/react/menu';\nimport { Portal } from '@ark-ui/react/portal';\nimport { type ElementType, type ReactElement, type ReactNode, useContext, useRef } from 'react';\nimport { cx } from '../cx';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\nimport type { LinkComponentProps } from '../link-component';\nimport { PortalContainerContext } from '../portal-container';\nimport './menu.css';\n\nexport interface ActionMenuItem {\n /** Stable value reported by `onSelect`. */\n value: string;\n /** Text shown in the menu. Also what typeahead matches against. */\n label: string;\n /** Glyph before the label. Decorative: the label says what the item does. */\n icon?: IconSource;\n /**\n * Makes the item a link to this address, rendered through `linkComponent`.\n * Choosing it follows the link, with the keyboard too; `onSelect` still\n * reports its value.\n */\n href?: string;\n /**\n * Marks the link to the page the user is on: `aria-current=\"page\"`, and\n * the `itemIndicator` glyph after the label so the mark is not colour alone.\n */\n current?: boolean;\n /** Individually disable this item without removing it. */\n disabled?: boolean;\n /**\n * Whether choosing the item closes the menu. Defaults to `true`. Keep an\n * item open when its outcome shows in the `footer`, so a failure appears\n * where the click happened.\n */\n closeOnSelect?: boolean;\n}\n\n/**\n * The props a `linkComponent` receives. A plain `'a'` and a router's link\n * component both accept them; Ark adds the menu item's role, id, state\n * attributes and handlers on top, so the component must pass unknown props\n * and its `ref` on to the anchor it renders.\n */\nexport interface ActionMenuLinkProps extends LinkComponentProps {\n 'aria-current'?: 'page';\n}\n\nexport interface ActionMenuProps {\n /**\n * The element that opens the menu: a `<button>`, or a component that\n * passes its props and `ref` on to one, such as `IconButton` or\n * `MenuTrigger`. Ark renders it as the trigger, adding `aria-haspopup`,\n * `aria-expanded`, `aria-controls`, the open and close handlers and\n * `data-state`. Give it an accessible name that says what the menu holds,\n * such as \"Account menu\" or \"Main navigation\": the menu takes its name\n * from the trigger.\n */\n trigger: ReactElement;\n /** The actions and links, in order. */\n items: ActionMenuItem[];\n /** Fired with the item's `value` when one is chosen, a link included. */\n onSelect?: (value: string) => void;\n /**\n * Content above the items that says whose menu this is, such as the\n * signed-in user's name and email. It names the group of items for\n * assistive technology, so keep it to text and decorative elements.\n */\n header?: ReactNode;\n /**\n * A line under the items about the last action, such as \"Couldn't sign\n * out. Check your connection, then try again.\" It is announced when it\n * appears, and a press on it leaves the menu open. It is not an item and\n * sits beside the `menu` element, which may own only items, so keep it to\n * text and a decorative glyph rather than an `Alert`.\n */\n footer?: ReactNode;\n /**\n * Renders an item with an `href`. Defaults to `'a'`; pass a router's link\n * component for client-side navigation.\n */\n linkComponent?: ElementType<ActionMenuLinkProps>;\n /**\n * Glyph marking the `current` link. Defaults to the `IconDefaultsProvider`'s\n * `check`, or a plain built-in one.\n */\n itemIndicator?: IconSource;\n /** Controlled open state. Pair with `onOpenChange`. */\n open?: boolean;\n /** Fired with the requested state whenever the menu asks to open or close. */\n onOpenChange?: (open: boolean) => void;\n /** Extra class names on the menu's popup: the frame around the items and the footer. */\n className?: string;\n}\n\ninterface ActionMenuRowProps {\n item: ActionMenuItem;\n linkComponent: ElementType<ActionMenuLinkProps>;\n itemIndicator: IconSource;\n}\n\nfunction ActionMenuRow({ item, linkComponent: LinkComponent, itemIndicator }: ActionMenuRowProps) {\n const body = (\n <>\n <span className=\"ds-menu__item-body\">\n {item.icon && (\n <Icon source={item.icon} size=\"sm\" decorative className=\"ds-menu__item-icon\" />\n )}\n <ArkMenu.ItemText>{item.label}</ArkMenu.ItemText>\n </span>\n {item.current && (\n <span className=\"ds-menu__item-indicator\">\n <Icon source={itemIndicator} size=\"sm\" decorative />\n </span>\n )}\n </>\n );\n const itemProps = {\n value: item.value,\n valueText: item.label,\n disabled: item.disabled,\n closeOnSelect: item.closeOnSelect,\n className: 'ds-menu__item',\n };\n\n if (item.href === undefined) {\n return <ArkMenu.Item {...itemProps}>{body}</ArkMenu.Item>;\n }\n return (\n <ArkMenu.Item {...itemProps} asChild>\n <LinkComponent href={item.href} aria-current={item.current ? 'page' : undefined}>\n {body}\n </LinkComponent>\n </ArkMenu.Item>\n );\n}\n\n/**\n * A menu of actions and links, opened from a trigger, built on Ark UI's\n * Menu. The counterpart of `Menu`, whose items are mutually exclusive\n * choices: here every item does something or goes somewhere.\n *\n * Ark owns the hard parts: `menu` / `menuitem` semantics, roving highlight\n * with the arrow keys, Home/End, typeahead, Escape and click outside to\n * dismiss, following a link on Enter, and focus returning to the trigger on\n * close. This wrapper contributes the `ds-menu` classes and `--ds-menu-*`\n * bindings it shares with `Menu`, a flat `items` API, and the header and\n * footer slots.\n *\n * ```tsx\n * <ActionMenu\n * trigger={<IconButton icon={MenuGlyph} variant=\"tertiary\" aria-label=\"Main navigation\" />}\n * linkComponent={Link}\n * items={[\n * { value: 'dashboard', label: 'Dashboard', href: '/dashboard', current: true },\n * { value: 'goals', label: 'Goals', href: '/goals' },\n * ]}\n * />\n * ```\n *\n * Reach for this for an account menu, a row's overflow actions, or a\n * navigation that folds into a button on a phone. A set of choices where\n * exactly one is in effect is a `Menu`; a form field is a `Select`.\n *\n * The popup renders in a portal, at the same `z-index: 60` as Select's\n * listbox, and is mounted only while open, as `Menu`'s is.\n */\nexport function ActionMenu({\n trigger,\n items,\n onSelect,\n header,\n footer,\n linkComponent = 'a',\n itemIndicator: itemIndicatorProp,\n open,\n onOpenChange,\n className,\n}: ActionMenuProps) {\n const icons = useIconDefaults();\n const itemIndicator = itemIndicatorProp ?? icons.check;\n const portalContainer = useContext(PortalContainerContext);\n const handleSelect = (details: { value: string }) => onSelect?.(details.value);\n const handleOpenChange = (details: { open: boolean }) => onOpenChange?.(details.open);\n /*\n * Enter on a link item. Zag's default dispatches a click that does not\n * bubble, which the browser follows as a document load but React never\n * sees, so a router's link component could not take it over. `click()`\n * bubbles, and the link navigates the way a pointer click would.\n */\n const navigate = (details: { node: HTMLAnchorElement }) =>\n queueMicrotask(() => details.node.click());\n /*\n * The footer sits beside the `menu` element, not in it, because a menu may\n * own only items. To Zag that makes it outside, so a press on the message\n * would dismiss the menu; this keeps it open.\n */\n const footerRef = useRef<HTMLDivElement>(null);\n const keepOpenForFooter = (event: CustomEvent<{ originalEvent: Event }>) => {\n const target = event.detail.originalEvent.target;\n if (target instanceof Node && footerRef.current?.contains(target)) event.preventDefault();\n };\n\n const rows = items.map((item) => (\n <ActionMenuRow\n key={item.value}\n item={item}\n linkComponent={linkComponent}\n itemIndicator={itemIndicator}\n />\n ));\n const list =\n header === undefined ? (\n rows\n ) : (\n <ArkMenu.ItemGroup>\n <ArkMenu.ItemGroupLabel className=\"ds-menu__header\">{header}</ArkMenu.ItemGroupLabel>\n {rows}\n </ArkMenu.ItemGroup>\n );\n\n return (\n <ArkMenu.Root\n lazyMount\n unmountOnExit\n open={open}\n onOpenChange={handleOpenChange}\n onSelect={handleSelect}\n navigate={navigate}\n onInteractOutside={keepOpenForFooter}\n >\n <ArkMenu.Trigger asChild>{trigger}</ArkMenu.Trigger>\n\n <Portal container={portalContainer}>\n <ArkMenu.Positioner>\n <div className={cx('ds-menu__popup', className)}>\n <ArkMenu.Content className=\"ds-menu__content\">{list}</ArkMenu.Content>\n <div ref={footerRef} className=\"ds-menu__footer\" aria-live=\"polite\">\n {footer}\n </div>\n </div>\n </ArkMenu.Positioner>\n </Portal>\n </ArkMenu.Root>\n );\n}\n"]}
|
package/dist/menu/menu.d.ts
CHANGED
|
@@ -54,9 +54,7 @@ export interface MenuProps<V extends string = string> {
|
|
|
54
54
|
/**
|
|
55
55
|
* Glyph marking the checked choice.
|
|
56
56
|
*
|
|
57
|
-
* Defaults to a plain built-in
|
|
58
|
-
* renders on its own. Products override it with their own icon set, as
|
|
59
|
-
* they do Select's `itemIndicator`.
|
|
57
|
+
* Defaults to the `IconDefaultsProvider`'s `check`, or a plain built-in one.
|
|
60
58
|
*/
|
|
61
59
|
itemIndicator?: IconSource;
|
|
62
60
|
/** Extra class names on the menu's popup: the frame around the items. */
|
|
@@ -68,8 +66,8 @@ export interface MenuTriggerProps extends Omit<ComponentProps<'button'>, 'type'>
|
|
|
68
66
|
* Select's indicator does: the trigger turns it down while closed and up
|
|
69
67
|
* while open, so one glyph serves both states.
|
|
70
68
|
*
|
|
71
|
-
* Defaults to
|
|
72
|
-
*
|
|
69
|
+
* Defaults to the `IconDefaultsProvider`'s `chevronRight`, or a plain
|
|
70
|
+
* built-in one.
|
|
73
71
|
*/
|
|
74
72
|
indicator?: IconSource;
|
|
75
73
|
}
|
|
@@ -92,7 +90,7 @@ export interface MenuTriggerProps extends Omit<ComponentProps<'button'>, 'type'>
|
|
|
92
90
|
* />
|
|
93
91
|
* ```
|
|
94
92
|
*/
|
|
95
|
-
export declare function MenuTrigger({ indicator, className, children, ...props }: MenuTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
93
|
+
export declare function MenuTrigger({ indicator: indicatorProp, className, children, ...props }: MenuTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
96
94
|
/**
|
|
97
95
|
* A menu of mutually exclusive choices, opened from a trigger and applied
|
|
98
96
|
* at once, built on Ark UI's Menu.
|
|
@@ -126,5 +124,5 @@ export declare function MenuTrigger({ indicator, className, children, ...props }
|
|
|
126
124
|
* the page or dialog it opens from. It is mounted only while open, so a list
|
|
127
125
|
* of a hundred menus adds nothing to the page until one is opened.
|
|
128
126
|
*/
|
|
129
|
-
export declare function Menu<V extends string = string>({ trigger, label, items, value, onValueChange, itemIndicator, className, }: MenuProps<V>): import("react/jsx-runtime").JSX.Element;
|
|
127
|
+
export declare function Menu<V extends string = string>({ trigger, label, items, value, onValueChange, itemIndicator: itemIndicatorProp, className, }: MenuProps<V>): import("react/jsx-runtime").JSX.Element;
|
|
130
128
|
//# sourceMappingURL=menu.d.ts.map
|
package/dist/menu/menu.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/menu/menu.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAA2B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/menu/menu.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAA2B,MAAM,OAAO,CAAC;AAExF,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,YAAY,CAAC;AAEpB,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACjD,0EAA0E;IAC1E,KAAK,EAAE,CAAC,CAAC;IACT,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAClD;;;;;;;;;;OAUG;IACH,OAAO,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB;;;;OAIG;IACH,KAAK,EAAE,CAAC,CAAC;IACT;;;;OAIG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAClC;;;;OAIG;IACH,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC9E;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EAAE,aAAa,EACxB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,gBAAgB,2CASlB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAC9C,OAAO,EACP,KAAK,EACL,KAAK,EACL,KAAK,EACL,aAAa,EACb,aAAa,EAAE,iBAAiB,EAChC,SAAS,GACV,EAAE,SAAS,CAAC,CAAC,CAAC,2CA2Dd"}
|
package/dist/menu/menu.js
CHANGED
|
@@ -3,8 +3,8 @@ import { Menu as ArkMenu } from '@ark-ui/react/menu';
|
|
|
3
3
|
import { Portal } from '@ark-ui/react/portal';
|
|
4
4
|
import { useCallback, useContext } from 'react';
|
|
5
5
|
import { cx } from '../cx';
|
|
6
|
-
import { Check, ChevronRight } from '../fallback-glyphs';
|
|
7
6
|
import { Icon } from '../icon/icon';
|
|
7
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
8
8
|
import { PortalContainerContext } from '../portal-container';
|
|
9
9
|
import './menu.css';
|
|
10
10
|
/**
|
|
@@ -26,7 +26,9 @@ import './menu.css';
|
|
|
26
26
|
* />
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export function MenuTrigger({ indicator
|
|
29
|
+
export function MenuTrigger({ indicator: indicatorProp, className, children, ...props }) {
|
|
30
|
+
const icons = useIconDefaults();
|
|
31
|
+
const indicator = indicatorProp ?? icons.chevronRight;
|
|
30
32
|
return (_jsxs("button", { type: "button", className: cx('ds-menu__trigger', className), ...props, children: [children, _jsx(Icon, { source: indicator, size: "sm", decorative: true, className: "ds-menu__trigger-indicator" })] }));
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -62,7 +64,9 @@ export function MenuTrigger({ indicator = ChevronRight, className, children, ...
|
|
|
62
64
|
* the page or dialog it opens from. It is mounted only while open, so a list
|
|
63
65
|
* of a hundred menus adds nothing to the page until one is opened.
|
|
64
66
|
*/
|
|
65
|
-
export function Menu({ trigger, label, items, value, onValueChange, itemIndicator
|
|
67
|
+
export function Menu({ trigger, label, items, value, onValueChange, itemIndicator: itemIndicatorProp, className, }) {
|
|
68
|
+
const icons = useIconDefaults();
|
|
69
|
+
const itemIndicator = itemIndicatorProp ?? icons.check;
|
|
66
70
|
/*
|
|
67
71
|
* Ark reports the value as a string; mapping it back through `items`
|
|
68
72
|
* returns the caller's own type without a cast, and drops anything that is
|
package/dist/menu/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/menu/menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAA0C,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,YAAY,CAAC;AA6EpB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW,CAAC,EAC1B,SAAS,GAAG,YAAY,EACxB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACS;IACjB,OAAO,CACL,kBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC,KAAM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BAAgB,YAAE,KAAK,GAA0B,EAClF,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACnB,MAAC,OAAO,CAAC,SAAS,IAEhB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,SAAS,EAAE,IAAI,CAAC,KAAK,EACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,SAAS,EAAC,eAAe,aAEzB,gBAAM,SAAS,EAAC,oBAAoB,aACjC,IAAI,CAAC,IAAI,IAAI,CACZ,KAAC,IAAI,IACH,MAAM,EAAE,IAAI,CAAC,IAAI,EACjB,IAAI,EAAC,IAAI,EACT,UAAU,QACV,SAAS,EAAC,oBAAoB,GAC9B,CACH,EACD,KAAC,OAAO,CAAC,QAAQ,cAAE,IAAI,CAAC,KAAK,GAAoB,IAC5C,EACP,KAAC,OAAO,CAAC,aAAa,IAAC,SAAS,EAAC,yBAAyB,YACxD,KAAC,IAAI,IAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,SAAG,GAC9B,KAnBnB,IAAI,CAAC,KAAK,CAoBG,CACrB,CAAC,IACqB,GACT,GACd,GACa,GACd,IACI,CAChB,CAAC;AACJ,CAAC","sourcesContent":["import { Menu as ArkMenu } from '@ark-ui/react/menu';\nimport { Portal } from '@ark-ui/react/portal';\nimport { type ComponentProps, type ReactElement, useCallback, useContext } from 'react';\nimport { cx } from '../cx';\nimport { Check, ChevronRight } from '../fallback-glyphs';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { PortalContainerContext } from '../portal-container';\nimport './menu.css';\n\nexport interface MenuItem<V extends string = string> {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: V;\n /** Text shown in the menu. Also what typeahead matches against. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n /**\n * Glyph before the label, supplied by the product, as on an ActionMenu\n * item: the mark a choice also carries on its trigger. Decorative; the\n * label carries the meaning.\n */\n icon?: IconSource;\n}\n\n/**\n * Generic over the value type, so a union of choices (`'draft' | 'live'`)\n * comes back out of `onValueChange` as that union rather than as `string`.\n */\nexport interface MenuProps<V extends string = string> {\n /**\n * The element that opens the menu: a `<button>`, or a component that\n * passes its props and `ref` on to one.\n *\n * Ark renders it as the trigger, adding `aria-haspopup`, `aria-expanded`,\n * `aria-controls`, the open/close handlers and `data-state` (`open` or\n * `closed`, for a product's own indicator). Its own handlers still run.\n * Give it an accessible name that says what is chosen and what pressing\n * it does, such as \"Status: In progress. Change status\": the menu takes\n * its name from the trigger.\n */\n trigger: ReactElement;\n /**\n * What the items choose between, such as \"Status\". Names the group of\n * choices for assistive technology; it is not shown.\n */\n label: string;\n /** The choices, in order. Exactly one is checked: the one matching `value`. */\n items: MenuItem<V>[];\n /**\n * The checked choice. Controlled only: the menu reports a choice through\n * `onValueChange` and shows whatever `value` says next. A value matching\n * no item leaves nothing checked.\n */\n value: V;\n /**\n * Fired when a different choice is made. Choosing the item that is already\n * checked closes the menu without firing, so a consumer that saves on\n * change never writes the same value twice.\n */\n onValueChange: (value: V) => void;\n /**\n * Glyph marking the checked choice.\n *\n * Defaults to a plain built-in check so `@manakind/ui-core` installs and\n * renders on its own. Products override it with their own icon set, as\n * they do Select's `itemIndicator`.\n */\n itemIndicator?: IconSource;\n /** Extra class names on the menu's popup: the frame around the items. */\n className?: string;\n}\n\nexport interface MenuTriggerProps extends Omit<ComponentProps<'button'>, 'type'> {\n /**\n * Glyph after the content saying it opens a menu. Must point RIGHT, as\n * Select's indicator does: the trigger turns it down while closed and up\n * while open, so one glyph serves both states.\n *\n * Defaults to a plain built-in chevron. Products override it with their\n * own icon set.\n */\n indicator?: IconSource;\n}\n\n/**\n * A quiet, compact trigger for a `Menu`: the content it is given, then a\n * chevron, with a fill on hover and while open, and the focus ring.\n *\n * For a trigger that wraps something with its own look, such as a status\n * `Badge`, where a `Button` would add a second frame and its own height. It\n * takes the size of its content and inherits its font and colour.\n *\n * ```tsx\n * <Menu\n * trigger={\n * <MenuTrigger aria-label={`Status: ${status}. Change status`}>\n * <Badge variant=\"info\" appearance=\"plain\">{status}</Badge>\n * </MenuTrigger>\n * }\n * …\n * />\n * ```\n */\nexport function MenuTrigger({\n indicator = ChevronRight,\n className,\n children,\n ...props\n}: MenuTriggerProps) {\n return (\n <button type=\"button\" className={cx('ds-menu__trigger', className)} {...props}>\n {children}\n <Icon source={indicator} size=\"sm\" decorative className=\"ds-menu__trigger-indicator\" />\n </button>\n );\n}\n\n/**\n * A menu of mutually exclusive choices, opened from a trigger and applied\n * at once, built on Ark UI's Menu.\n *\n * Ark owns the hard parts: `menu` / `menuitemradio` semantics, roving\n * highlight with the arrow keys, Home/End, typeahead, Escape and click\n * outside to dismiss, and focus returning to the trigger on close. This\n * wrapper contributes `ds-` classes, the `--ds-menu-*` bindings, and a flat\n * `items` API in place of Ark's anatomy.\n *\n * ```tsx\n * <Menu\n * trigger={<button type=\"button\" aria-label=\"Status: In Progress. Change status\">…</button>}\n * label=\"Status\"\n * items={[\n * { value: 'Not Started', label: 'Not Started' },\n * { value: 'In Progress', label: 'In Progress' },\n * { value: 'Completed', label: 'Completed' },\n * ]}\n * value={status}\n * onValueChange={setStatus}\n * />\n * ```\n *\n * Reach for this when the choice takes effect immediately, from a control\n * that is not a form field — a status badge, a sort order. A form field\n * whose value is submitted later is a `Select`.\n *\n * The popup renders in a portal, at the same `z-index: 60` as Select's\n * listbox, a step above the products' overlay layer (50), so it paints above\n * the page or dialog it opens from. It is mounted only while open, so a list\n * of a hundred menus adds nothing to the page until one is opened.\n */\nexport function Menu<V extends string = string>({\n trigger,\n label,\n items,\n value,\n onValueChange,\n itemIndicator = Check,\n className,\n}: MenuProps<V>) {\n /*\n * Ark reports the value as a string; mapping it back through `items`\n * returns the caller's own type without a cast, and drops anything that is\n * not one of the choices.\n */\n const handleValueChange = useCallback(\n (details: { value: string }) => {\n const chosen = items.find((item) => item.value === details.value);\n if (chosen && chosen.value !== value) onValueChange(chosen.value);\n },\n [items, value, onValueChange],\n );\n\n const portalContainer = useContext(PortalContainerContext);\n\n return (\n <ArkMenu.Root lazyMount unmountOnExit>\n <ArkMenu.Trigger asChild>{trigger}</ArkMenu.Trigger>\n\n <Portal container={portalContainer}>\n <ArkMenu.Positioner>\n <div className={cx('ds-menu__popup', className)}>\n <ArkMenu.Content className=\"ds-menu__content\">\n <ArkMenu.RadioItemGroup value={value} onValueChange={handleValueChange}>\n <ArkMenu.ItemGroupLabel className=\"ds-menu__label\">{label}</ArkMenu.ItemGroupLabel>\n {items.map((item) => (\n <ArkMenu.RadioItem\n key={item.value}\n value={item.value}\n valueText={item.label}\n disabled={item.disabled}\n className=\"ds-menu__item\"\n >\n <span className=\"ds-menu__item-body\">\n {item.icon && (\n <Icon\n source={item.icon}\n size=\"sm\"\n decorative\n className=\"ds-menu__item-icon\"\n />\n )}\n <ArkMenu.ItemText>{item.label}</ArkMenu.ItemText>\n </span>\n <ArkMenu.ItemIndicator className=\"ds-menu__item-indicator\">\n <Icon source={itemIndicator} size=\"sm\" decorative />\n </ArkMenu.ItemIndicator>\n </ArkMenu.RadioItem>\n ))}\n </ArkMenu.RadioItemGroup>\n </ArkMenu.Content>\n </div>\n </ArkMenu.Positioner>\n </Portal>\n </ArkMenu.Root>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/menu/menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAA0C,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAA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AAC","sourcesContent":["import { Menu as ArkMenu } from '@ark-ui/react/menu';\nimport { Portal } from '@ark-ui/react/portal';\nimport { type ComponentProps, type ReactElement, useCallback, useContext } from 'react';\nimport { cx } from '../cx';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\nimport { PortalContainerContext } from '../portal-container';\nimport './menu.css';\n\nexport interface MenuItem<V extends string = string> {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: V;\n /** Text shown in the menu. Also what typeahead matches against. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n /**\n * Glyph before the label, supplied by the product, as on an ActionMenu\n * item: the mark a choice also carries on its trigger. Decorative; the\n * label carries the meaning.\n */\n icon?: IconSource;\n}\n\n/**\n * Generic over the value type, so a union of choices (`'draft' | 'live'`)\n * comes back out of `onValueChange` as that union rather than as `string`.\n */\nexport interface MenuProps<V extends string = string> {\n /**\n * The element that opens the menu: a `<button>`, or a component that\n * passes its props and `ref` on to one.\n *\n * Ark renders it as the trigger, adding `aria-haspopup`, `aria-expanded`,\n * `aria-controls`, the open/close handlers and `data-state` (`open` or\n * `closed`, for a product's own indicator). Its own handlers still run.\n * Give it an accessible name that says what is chosen and what pressing\n * it does, such as \"Status: In progress. Change status\": the menu takes\n * its name from the trigger.\n */\n trigger: ReactElement;\n /**\n * What the items choose between, such as \"Status\". Names the group of\n * choices for assistive technology; it is not shown.\n */\n label: string;\n /** The choices, in order. Exactly one is checked: the one matching `value`. */\n items: MenuItem<V>[];\n /**\n * The checked choice. Controlled only: the menu reports a choice through\n * `onValueChange` and shows whatever `value` says next. A value matching\n * no item leaves nothing checked.\n */\n value: V;\n /**\n * Fired when a different choice is made. Choosing the item that is already\n * checked closes the menu without firing, so a consumer that saves on\n * change never writes the same value twice.\n */\n onValueChange: (value: V) => void;\n /**\n * Glyph marking the checked choice.\n *\n * Defaults to the `IconDefaultsProvider`'s `check`, or a plain built-in one.\n */\n itemIndicator?: IconSource;\n /** Extra class names on the menu's popup: the frame around the items. */\n className?: string;\n}\n\nexport interface MenuTriggerProps extends Omit<ComponentProps<'button'>, 'type'> {\n /**\n * Glyph after the content saying it opens a menu. Must point RIGHT, as\n * Select's indicator does: the trigger turns it down while closed and up\n * while open, so one glyph serves both states.\n *\n * Defaults to the `IconDefaultsProvider`'s `chevronRight`, or a plain\n * built-in one.\n */\n indicator?: IconSource;\n}\n\n/**\n * A quiet, compact trigger for a `Menu`: the content it is given, then a\n * chevron, with a fill on hover and while open, and the focus ring.\n *\n * For a trigger that wraps something with its own look, such as a status\n * `Badge`, where a `Button` would add a second frame and its own height. It\n * takes the size of its content and inherits its font and colour.\n *\n * ```tsx\n * <Menu\n * trigger={\n * <MenuTrigger aria-label={`Status: ${status}. Change status`}>\n * <Badge variant=\"info\" appearance=\"plain\">{status}</Badge>\n * </MenuTrigger>\n * }\n * …\n * />\n * ```\n */\nexport function MenuTrigger({\n indicator: indicatorProp,\n className,\n children,\n ...props\n}: MenuTriggerProps) {\n const icons = useIconDefaults();\n const indicator = indicatorProp ?? icons.chevronRight;\n return (\n <button type=\"button\" className={cx('ds-menu__trigger', className)} {...props}>\n {children}\n <Icon source={indicator} size=\"sm\" decorative className=\"ds-menu__trigger-indicator\" />\n </button>\n );\n}\n\n/**\n * A menu of mutually exclusive choices, opened from a trigger and applied\n * at once, built on Ark UI's Menu.\n *\n * Ark owns the hard parts: `menu` / `menuitemradio` semantics, roving\n * highlight with the arrow keys, Home/End, typeahead, Escape and click\n * outside to dismiss, and focus returning to the trigger on close. This\n * wrapper contributes `ds-` classes, the `--ds-menu-*` bindings, and a flat\n * `items` API in place of Ark's anatomy.\n *\n * ```tsx\n * <Menu\n * trigger={<button type=\"button\" aria-label=\"Status: In Progress. Change status\">…</button>}\n * label=\"Status\"\n * items={[\n * { value: 'Not Started', label: 'Not Started' },\n * { value: 'In Progress', label: 'In Progress' },\n * { value: 'Completed', label: 'Completed' },\n * ]}\n * value={status}\n * onValueChange={setStatus}\n * />\n * ```\n *\n * Reach for this when the choice takes effect immediately, from a control\n * that is not a form field — a status badge, a sort order. A form field\n * whose value is submitted later is a `Select`.\n *\n * The popup renders in a portal, at the same `z-index: 60` as Select's\n * listbox, a step above the products' overlay layer (50), so it paints above\n * the page or dialog it opens from. It is mounted only while open, so a list\n * of a hundred menus adds nothing to the page until one is opened.\n */\nexport function Menu<V extends string = string>({\n trigger,\n label,\n items,\n value,\n onValueChange,\n itemIndicator: itemIndicatorProp,\n className,\n}: MenuProps<V>) {\n const icons = useIconDefaults();\n const itemIndicator = itemIndicatorProp ?? icons.check;\n /*\n * Ark reports the value as a string; mapping it back through `items`\n * returns the caller's own type without a cast, and drops anything that is\n * not one of the choices.\n */\n const handleValueChange = useCallback(\n (details: { value: string }) => {\n const chosen = items.find((item) => item.value === details.value);\n if (chosen && chosen.value !== value) onValueChange(chosen.value);\n },\n [items, value, onValueChange],\n );\n\n const portalContainer = useContext(PortalContainerContext);\n\n return (\n <ArkMenu.Root lazyMount unmountOnExit>\n <ArkMenu.Trigger asChild>{trigger}</ArkMenu.Trigger>\n\n <Portal container={portalContainer}>\n <ArkMenu.Positioner>\n <div className={cx('ds-menu__popup', className)}>\n <ArkMenu.Content className=\"ds-menu__content\">\n <ArkMenu.RadioItemGroup value={value} onValueChange={handleValueChange}>\n <ArkMenu.ItemGroupLabel className=\"ds-menu__label\">{label}</ArkMenu.ItemGroupLabel>\n {items.map((item) => (\n <ArkMenu.RadioItem\n key={item.value}\n value={item.value}\n valueText={item.label}\n disabled={item.disabled}\n className=\"ds-menu__item\"\n >\n <span className=\"ds-menu__item-body\">\n {item.icon && (\n <Icon\n source={item.icon}\n size=\"sm\"\n decorative\n className=\"ds-menu__item-icon\"\n />\n )}\n <ArkMenu.ItemText>{item.label}</ArkMenu.ItemText>\n </span>\n <ArkMenu.ItemIndicator className=\"ds-menu__item-indicator\">\n <Icon source={itemIndicator} size=\"sm\" decorative />\n </ArkMenu.ItemIndicator>\n </ArkMenu.RadioItem>\n ))}\n </ArkMenu.RadioItemGroup>\n </ArkMenu.Content>\n </div>\n </ArkMenu.Positioner>\n </Portal>\n </ArkMenu.Root>\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/radio-group/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/radio-group/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6C,MAAM,eAAe,CAAC","sourcesContent":["export { RadioGroup, type RadioGroupItem, type RadioGroupProps } from './radio-group';\n"]}
|