@funstack/ui 0.1.0-alpha.21 → 0.1.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/components/menu.md +1 -1
- package/dist/docs/components/menubar.md +309 -0
- package/dist/docs/components/meter.md +1 -1
- package/dist/docs/components/navigation-menu.md +501 -0
- package/dist/docs/components/number-field.md +2 -2
- package/dist/docs/components/otp-field.md +8 -1
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/radio-group.md +1 -1
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/concepts/direction-and-locales.md +106 -0
- package/dist/docs/index.md +4 -1
- package/dist/docs/roadmap.md +7 -0
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +3 -1
- package/dist/internal/menubar-context.mjs +12 -0
- package/dist/internal/menubar-context.mjs.map +1 -0
- package/dist/internal/overlay/trigger-ref.mjs +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +3 -2
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.mjs +2 -2
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/range-value.mjs +5 -3
- package/dist/internal/range-value.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +33 -6
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +10 -3
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +53 -5
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menubar/index.d.mts +3 -0
- package/dist/menubar/index.mjs +1 -0
- package/dist/menubar/menubar.d.mts +49 -0
- package/dist/menubar/menubar.d.mts.map +1 -0
- package/dist/menubar/menubar.mjs +147 -0
- package/dist/menubar/menubar.mjs.map +1 -0
- package/dist/meter/meter-root.d.mts +3 -2
- package/dist/meter/meter-root.d.mts.map +1 -1
- package/dist/meter/meter-root.mjs.map +1 -1
- package/dist/multi-select/multi-select-root.mjs +1 -1
- package/dist/multi-select/multi-select-trigger.mjs +1 -1
- package/dist/navigation-menu/index.d.mts +32 -0
- package/dist/navigation-menu/index.d.mts.map +1 -0
- package/dist/navigation-menu/index.mjs +32 -0
- package/dist/navigation-menu/index.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-context.mjs +19 -0
- package/dist/navigation-menu/navigation-menu-context.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts +79 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.mjs +80 -0
- package/dist/navigation-menu/navigation-menu-item.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts +48 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.mjs +66 -0
- package/dist/navigation-menu/navigation-menu-link.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.mjs +30 -0
- package/dist/navigation-menu/navigation-menu-list.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts +102 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs +93 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.mjs +27 -0
- package/dist/navigation-menu/navigation-menu-root.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts +32 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs +42 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs.map +1 -0
- package/dist/otp-field/otp-field-root.d.mts +9 -0
- package/dist/otp-field/otp-field-root.d.mts.map +1 -1
- package/dist/otp-field/otp-field-root.mjs +5 -2
- package/dist/otp-field/otp-field-root.mjs.map +1 -1
- package/dist/popover/index.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/progress/progress-root.d.mts +3 -2
- package/dist/progress/progress-root.d.mts.map +1 -1
- package/dist/progress/progress-root.mjs.map +1 -1
- package/package.json +4 -1
- package/skills/funstack-ui-knowledge/SKILL.md +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menubar.mjs","names":[],"sources":["../../src/menubar/menubar.tsx"],"sourcesContent":["\"use client\";\nimport { useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n ReactNode,\n} from \"react\";\nimport { focusWithRing } from \"../internal/arrow-keys.js\";\nimport { sortByDocumentOrder } from \"../internal/dom-order.js\";\nimport { MenubarContext } from \"../internal/menubar-context.js\";\nimport type {\n MenubarContextValue,\n MenubarMenu,\n MenubarOpenFocus,\n} from \"../internal/menubar-context.js\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useRovingFocus } from \"../internal/use-roving-focus.js\";\n\n/**\n * State of `Menubar`, passed to the function forms of `className`, `style`, `children` and\n * `render`. Empty: the bar holds no open state (each menu is its own state owner).\n */\nexport interface MenubarState {}\n\n/**\n * Props of `Menubar`.\n *\n * @see https://ui.funstack.work/components/menubar\n */\nexport interface MenubarProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"onKeyDown\" | \"onFocus\" | \"onBlur\" | \"onPointerDown\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Arrow keys (on the bar and from inside its menus) wrap from the last menu to the first and\n * back.\n *\n * @defaultValue `true`\n */\n loop?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenubarState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenubarState>;\n /** The menus of the bar (`Menu.Root`s), or a function of the part's state. */\n children?: StateValue<ReactNode, MenubarState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenubarState>;\n}\n\nconst STATE: MenubarState = {};\n\n/** The roving engine's entry: the first Trigger before any was focused. */\nfunction firstItem(items: readonly HTMLElement[]): HTMLElement | undefined {\n return items[0];\n}\n\n/**\n * The shown popup of a menu of the bar is hidden at once (a dismissal, reported by its `toggle`);\n * an open still pending is superseded (design/components/menubar.md 2.2 step 2, 4).\n */\nfunction closeMenu(menu: MenubarMenu, event: Event): void {\n const popup = menu.popup();\n if (popup !== null && isPopoverOpen(popup)) {\n popup.hidePopover();\n } else if (menu.intended() && !menu.hiddenBeforeToggle()) {\n menu.supersede(event);\n }\n}\n\n/**\n * `<div role=\"menubar\">` (WAI-ARIA APG Menubar): a row of top-level `Menu.Root`s whose\n * `Menu.Trigger`s are the items of the bar (`role=\"menuitem\"`). One Tab stop with\n * ArrowLeft / ArrowRight / Home / End between the Triggers (the Toolbar's roving engine);\n * ArrowRight / ArrowLeft inside a menu, the same keys on the Trigger of an open menu and the\n * pointer moving onto another Trigger while a menu is open switch menus. The bar holds no open\n * state: each `Menu.Root` keeps its own (design/components/menubar.md). Name it with\n * `aria-label` or `aria-labelledby`.\n *\n * Owned keys (conventions 1.2): `role`, `onKeyDown`, `onFocus`, `onBlur`, `onPointerDown`.\n *\n * @see https://ui.funstack.work/components/menubar\n */\nexport function Menubar({\n loop = true,\n className,\n style,\n children,\n render,\n ...rest\n}: MenubarProps) {\n const rootRef = useRef<HTMLElement | null>(null);\n const roving = useRovingFocus(rootRef, {\n orientation: \"horizontal\",\n loop,\n native: false,\n entry: firstItem,\n memory: true,\n });\n const latestLoop = useLatest(loop);\n\n // The menus of the bar, keyed by their Trigger element (design 2.1). Order is the DOM order of\n // the Triggers, read when a key is pressed.\n const registry = useRef(new Map<HTMLElement, MenubarMenu>());\n // Menu mode held on a disabled Trigger a switch reached (design 2.2 step 3): no menu can vouch\n // for it, so the bar keeps it, with the switch's focus cause for the next switch. Cleared by\n // every switch, by Escape on that Trigger and when that Trigger loses focus.\n const held = useRef<{ readonly trigger: HTMLElement; readonly focus: MenubarOpenFocus } | null>(\n null,\n );\n\n const context = useMemo<MenubarContextValue>(() => {\n const menus = registry.current;\n const switchTo = (\n target: HTMLElement,\n focus: MenubarOpenFocus,\n event: Event,\n pointer: boolean,\n ) => {\n const menu = menus.get(target);\n if (menu === undefined) return;\n held.current = null;\n // 1. The Trigger first: a menu holding focus closes by its own rule, and the platform\n // records this Trigger as the focus-return target of the menu about to open.\n if (target.ownerDocument.activeElement !== target) {\n if (pointer) target.focus({ focusVisible: false } as FocusOptions);\n else focusWithRing(target);\n }\n // 2. Every other menu of the bar, at once.\n for (const [trigger, other] of menus) {\n if (trigger !== target) closeMenu(other, event);\n }\n // 3. The target's open; a disabled target holds menu mode instead.\n if (menu.disabled()) held.current = { trigger: target, focus };\n else menu.open(event, focus);\n };\n return {\n register: (trigger, menu) => {\n menus.set(trigger, menu);\n return () => {\n if (menus.get(trigger) === menu) menus.delete(trigger);\n };\n },\n switchTo,\n step: (from, delta, event) => {\n const triggers = sortByDocumentOrder([...menus.keys()], (el) => el);\n const index = triggers.indexOf(from);\n if (index < 0) return false;\n const last = triggers.length - 1;\n let next = index + delta;\n if (next > last) next = latestLoop.current ? 0 : last;\n else if (next < 0) next = latestLoop.current ? last : 0;\n const target = triggers[next];\n if (target === undefined || target === from) return false;\n switchTo(target, \"first\", event, false);\n return true;\n },\n otherIntended: (trigger) => {\n if (held.current !== null && held.current.trigger !== trigger) return true;\n for (const [other, menu] of menus) {\n if (other !== trigger && menu.intended() && !menu.hiddenBeforeToggle()) return true;\n }\n return false;\n },\n rtl: () => {\n const root = rootRef.current;\n return root !== null && getComputedStyle(root).direction === \"rtl\";\n },\n };\n }, [latestLoop]);\n\n // On a Trigger whose menu is intended open, or a disabled one holding menu mode, the engine's\n // move is a switch to the Trigger it moved to (design 2.3): focus left on it, or the held cause.\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n const target = event.target as HTMLElement;\n const menu = registry.current.get(target);\n // Read before the engine moves focus: the blur of the held Trigger clears the hold.\n const hold = held.current !== null && held.current.trigger === target ? held.current : null;\n if (hold !== null && event.key === \"Escape\") {\n // Ends menu mode; focus stays, and the key is not consumed.\n held.current = null;\n return;\n }\n const menuMode =\n menu !== undefined && !event.defaultPrevented && (hold !== null || menu.intended());\n roving.onKeyDown(event);\n if (!menuMode || !event.defaultPrevented) return;\n const focused = target.ownerDocument.activeElement;\n if (focused instanceof HTMLElement && focused !== target && registry.current.has(focused)) {\n context.switchTo(focused, hold?.focus ?? \"none\", event.nativeEvent, false);\n }\n };\n\n // Focus leaving the bar (its popups are DOM descendants, so focus in a menu is inside) hides a\n // menu still shown and supersedes a pending open (design 4). A null `relatedTarget` (window\n // blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n roving.onBlur(event);\n if (held.current !== null && event.target === held.current.trigger) held.current = null;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || event.currentTarget.contains(next)) return;\n for (const menu of registry.current.values()) closeMenu(menu, event.nativeEvent);\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenubarState>({\n defaultElement: \"div\",\n render,\n state: STATE,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n role: \"menubar\",\n onKeyDown,\n onFocus: roving.onFocus,\n onBlur,\n onPointerDown: roving.onPointerDown,\n },\n ref: rootRef,\n });\n\n return <MenubarContext value={context}>{element}</MenubarContext>;\n}\n\nMenubar.displayName = \"Menubar\";\n"],"mappings":";;;;;;;;;;;AAuDA,MAAM,QAAsB,CAAC;;AAG7B,SAAS,UAAU,OAAwD;CACzE,OAAO,MAAM;AACf;;;;;AAMA,SAAS,UAAU,MAAmB,OAAoB;CACxD,MAAM,QAAQ,KAAK,MAAM;CACzB,IAAI,UAAU,QAAQ,cAAc,KAAK,GACvC,MAAM,YAAY;MACb,IAAI,KAAK,SAAS,KAAK,CAAC,KAAK,mBAAmB,GACrD,KAAK,UAAU,KAAK;AAExB;;;;;;;;;;;;;;AAeA,SAAgB,QAAQ,EACtB,OAAO,MACP,WACA,OACA,UACA,QACA,GAAG,QACY;CACf,MAAM,UAAU,OAA2B,IAAI;CAC/C,MAAM,SAAS,eAAe,SAAS;EACrC,aAAa;EACb;EACA,QAAQ;EACR,OAAO;EACP,QAAQ;CACV,CAAC;CACD,MAAM,aAAa,UAAU,IAAI;CAIjC,MAAM,WAAW,uBAAO,IAAI,IAA8B,CAAC;CAI3D,MAAM,OAAO,OACX,IACF;CAEA,MAAM,UAAU,cAAmC;EACjD,MAAM,QAAQ,SAAS;EACvB,MAAM,YACJ,QACA,OACA,OACA,YACG;GACH,MAAM,OAAO,MAAM,IAAI,MAAM;GAC7B,IAAI,SAAS,KAAA,GAAW;GACxB,KAAK,UAAU;GAGf,IAAI,OAAO,cAAc,kBAAkB,QAAQ;IACjD,IAAI,SAAS,OAAO,MAAM,EAAE,cAAc,MAAM,CAAiB;SAC5D,cAAc,MAAM;GAC3B;GAEA,KAAK,MAAM,CAAC,SAAS,UAAU,OAC7B,IAAI,YAAY,QAAQ,UAAU,OAAO,KAAK;GAGhD,IAAI,KAAK,SAAS,GAAG,KAAK,UAAU;IAAE,SAAS;IAAQ;GAAM;QACxD,KAAK,KAAK,OAAO,KAAK;EAC7B;EACA,OAAO;GACL,WAAW,SAAS,SAAS;IAC3B,MAAM,IAAI,SAAS,IAAI;IACvB,aAAa;KACX,IAAI,MAAM,IAAI,OAAO,MAAM,MAAM,MAAM,OAAO,OAAO;IACvD;GACF;GACA;GACA,OAAO,MAAM,OAAO,UAAU;IAC5B,MAAM,WAAW,oBAAoB,CAAC,GAAG,MAAM,KAAK,CAAC,IAAI,OAAO,EAAE;IAClE,MAAM,QAAQ,SAAS,QAAQ,IAAI;IACnC,IAAI,QAAQ,GAAG,OAAO;IACtB,MAAM,OAAO,SAAS,SAAS;IAC/B,IAAI,OAAO,QAAQ;IACnB,IAAI,OAAO,MAAM,OAAO,WAAW,UAAU,IAAI;SAC5C,IAAI,OAAO,GAAG,OAAO,WAAW,UAAU,OAAO;IACtD,MAAM,SAAS,SAAS;IACxB,IAAI,WAAW,KAAA,KAAa,WAAW,MAAM,OAAO;IACpD,SAAS,QAAQ,SAAS,OAAO,KAAK;IACtC,OAAO;GACT;GACA,gBAAgB,YAAY;IAC1B,IAAI,KAAK,YAAY,QAAQ,KAAK,QAAQ,YAAY,SAAS,OAAO;IACtE,KAAK,MAAM,CAAC,OAAO,SAAS,OAC1B,IAAI,UAAU,WAAW,KAAK,SAAS,KAAK,CAAC,KAAK,mBAAmB,GAAG,OAAO;IAEjF,OAAO;GACT;GACA,WAAW;IACT,MAAM,OAAO,QAAQ;IACrB,OAAO,SAAS,QAAQ,iBAAiB,IAAI,CAAC,CAAC,cAAc;GAC/D;EACF;CACF,GAAG,CAAC,UAAU,CAAC;CAIf,MAAM,aAAa,UAAsC;EACvD,MAAM,SAAS,MAAM;EACrB,MAAM,OAAO,SAAS,QAAQ,IAAI,MAAM;EAExC,MAAM,OAAO,KAAK,YAAY,QAAQ,KAAK,QAAQ,YAAY,SAAS,KAAK,UAAU;EACvF,IAAI,SAAS,QAAQ,MAAM,QAAQ,UAAU;GAE3C,KAAK,UAAU;GACf;EACF;EACA,MAAM,WACJ,SAAS,KAAA,KAAa,CAAC,MAAM,qBAAqB,SAAS,QAAQ,KAAK,SAAS;EACnF,OAAO,UAAU,KAAK;EACtB,IAAI,CAAC,YAAY,CAAC,MAAM,kBAAkB;EAC1C,MAAM,UAAU,OAAO,cAAc;EACrC,IAAI,mBAAmB,eAAe,YAAY,UAAU,SAAS,QAAQ,IAAI,OAAO,GACtF,QAAQ,SAAS,SAAS,MAAM,SAAS,QAAQ,MAAM,aAAa,KAAK;CAE7E;CAKA,MAAM,UAAU,UAAmC;EACjD,OAAO,OAAO,KAAK;EACnB,IAAI,KAAK,YAAY,QAAQ,MAAM,WAAW,KAAK,QAAQ,SAAS,KAAK,UAAU;EACnF,MAAM,OAAO,MAAM;EACnB,IAAI,EAAE,gBAAgB,SAAS,MAAM,cAAc,SAAS,IAAI,GAAG;EACnE,KAAK,MAAM,QAAQ,SAAS,QAAQ,OAAO,GAAG,UAAU,MAAM,MAAM,WAAW;CACjF;CAEA,MAAM,UAAU,UAAsD;EACpE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,MAAM;GACN;GACA,SAAS,OAAO;GAChB;GACA,eAAe,OAAO;EACxB;EACA,KAAK;CACP,CAAC;CAED,OAAO,oBAAC,gBAAD;EAAgB,OAAO;EAAU,UAAA;CAAwB,CAAA;AAClE;AAEA,QAAQ,cAAc"}
|
|
@@ -75,11 +75,12 @@ export interface MeterRootProps extends Omit<ComponentPropsWithRef<"div">, "role
|
|
|
75
75
|
*/
|
|
76
76
|
format?: Intl.NumberFormatOptions;
|
|
77
77
|
/**
|
|
78
|
-
* BCP 47 tag for `Intl.NumberFormat`. Pass it when a client
|
|
78
|
+
* BCP 47 tag, or a preference list of tags, for `Intl.NumberFormat`. Pass it when a client
|
|
79
|
+
* tree is server-rendered.
|
|
79
80
|
*
|
|
80
81
|
* @defaultValue the runtime's locale
|
|
81
82
|
*/
|
|
82
|
-
locale?: string;
|
|
83
|
+
locale?: string | readonly string[];
|
|
83
84
|
/**
|
|
84
85
|
* The `aria-valuetext` to render instead of `formattedValue`. Called with the clamped value
|
|
85
86
|
* and the state as it would be without this prop. Return `null` to render no
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter-root.d.mts","names":[],"sources":["../../src/meter/meter-root.tsx"],"mappings":";;;;;iBAkBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA,QAAQ;;;;;;;iBAQF,uBAAuB,KACtC;;EAaA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;;EAQA,SAAS,KAAK;;;;;;
|
|
1
|
+
{"version":3,"file":"meter-root.d.mts","names":[],"sources":["../../src/meter/meter-root.tsx"],"mappings":";;;;;iBAkBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA,QAAQ;;;;;;;iBAQF,uBAAuB,KACtC;;EAaA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;;EAQA,SAAS,KAAK;;;;;;;EAOd;;;;;;EAMA,oBAAoB,eAAe,OAAO;;EAE1C,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;wBAYpC,YACd,OACA,KACA,KACA,KACA,MACA,SACA,QACA,QACA,kBACA,WACA,OACA,UACA,QACA,QACG,QACF,iCAAc,IAAA;yBAhBD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter-root.mjs","names":[],"sources":["../../src/meter/meter-root.tsx"],"sourcesContent":["// No \"use client\": `Meter.Root` uses only `useId`, arithmetic and `Intl`, and renders the client\n// context's provider (conventions 7.1's second exception). Rendered by a Server Component it runs\n// once, on the server (design/components/progress.md 8.1). It must not import from any\n// \"use client\" module except its context (checked by src/__tests__/directives.test.ts).\nimport { useId } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { warnOnce } from \"../internal/dev-warn.js\";\nimport { clamp, formatRangeValue, isDegenerate, percentage } from \"../internal/range-value.js\";\nimport { mergeRenderRef, renderElement, resolveStateValue } from \"../internal/render-element.js\";\nimport type { DataAttributes } from \"../internal/render-element.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { MeterContext } from \"./meter-context.js\";\nimport { meterRegion, resolveMeterBounds } from \"./meter-region.js\";\nimport type { MeterRegion } from \"./meter-region.js\";\n\nexport type { MeterRegion } from \"./meter-region.js\";\n\n/** The state every Meter part receives. */\nexport interface MeterState {\n /** Clamped to `[min, max]`. */\n readonly value: number;\n /** The `min` prop. */\n readonly min: number;\n /** The `max` prop. */\n readonly max: number;\n /** After HTML's defaults and clamping. */\n readonly low: number;\n /** After HTML's defaults and clamping. */\n readonly high: number;\n /** After HTML's defaults and clamping. */\n readonly optimum: number;\n /** A number 0–100. */\n readonly percentage: number;\n /** The `Intl.NumberFormat` text of the value (or of the fraction, for the percent style). */\n readonly formattedValue: string;\n /** What `aria-valuetext` carries: `getAriaValueText`'s result, else `formattedValue`. */\n readonly valueText: string | null;\n /**\n * Which region of the range the value is in, as the platform computes it; rendered as\n * `data-region` on every part.\n */\n readonly region: MeterRegion;\n}\n\n/**\n * Props of `Meter.Root`.\n *\n * @see https://ui.funstack.work/components/meter\n */\nexport interface MeterRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"role\"\n | \"aria-valuemin\"\n | \"aria-valuemax\"\n | \"aria-valuenow\"\n | \"aria-valuetext\"\n | \"defaultValue\"\n | \"defaultChecked\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Required: a meter always has a value. Clamped to `[min, max]`. */\n value: number;\n /**\n * Lower bound of the range.\n *\n * @defaultValue `0`\n */\n min?: number;\n /**\n * Upper bound of the range.\n *\n * @defaultValue `100`\n */\n max?: number;\n /**\n * Upper bound of the \"low\" part of the range.\n *\n * @defaultValue `min`\n */\n low?: number;\n /**\n * Lower bound of the \"high\" part of the range.\n *\n * @defaultValue `max`\n */\n high?: number;\n /**\n * The best value. Decides which part of the range is `optimum`.\n *\n * @defaultValue the midpoint, `(min + max) / 2`\n */\n optimum?: number;\n /**\n * `Intl.NumberFormat` options for `aria-valuetext` and `Meter.Value`. A `percent` style formats\n * the fraction of the range; any other style formats the value. Serialisable: a Server\n * Component may pass it.\n *\n * @defaultValue `{ style: \"percent\" }`\n */\n format?: Intl.NumberFormatOptions;\n /**\n * BCP 47 tag for `Intl.NumberFormat`. Pass it when a client tree is server-rendered.\n *\n * @defaultValue the runtime's locale\n */\n locale?: string;\n /**\n * The `aria-valuetext` to render instead of `formattedValue`. Called with the clamped value\n * and the state as it would be without this prop. Return `null` to render no\n * `aria-valuetext`.\n */\n getAriaValueText?: (value: number, state: MeterState) => string | null | undefined;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MeterState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MeterState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MeterState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MeterState>;\n}\n\n/**\n * `Meter.Root`: a `div[role=meter]` with the ARIA values and `aria-valuetext` always,\n * `data-region`, and `--meter-value` / `--meter-low` / `--meter-high` / `--meter-optimum` (the\n * percentages) in `style`, where the consumer's entries win. Owned keys: `role`,\n * `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext`, `aria-labelledby`\n * (token-merged: the consumer's tokens, then `Meter.Label`'s id, always), `data-region`.\n *\n * @see https://ui.funstack.work/components/meter\n */\nexport function MeterRoot({\n value,\n min = 0,\n max = 100,\n low,\n high,\n optimum,\n format,\n locale,\n getAriaValueText,\n className,\n style,\n children,\n render,\n ref,\n ...rest\n}: MeterRootProps) {\n const id = useId();\n\n let given = value;\n if (!Number.isFinite(given)) {\n warnOnce(\n `Meter.Root:non-finite:${given}`,\n `Meter.Root: \\`value\\` is ${given}, which is not a finite number; it is rendered as \\`min\\`.`,\n );\n given = min;\n }\n if (isDegenerate(min, max)) {\n warnOnce(\n `Meter.Root:degenerate:${min}:${max}`,\n `Meter.Root: \\`max\\` (${max}) must be greater than \\`min\\` (${min}); the percentage is ` +\n \"rendered as 0.\",\n );\n }\n\n const clamped = clamp(given, min, max);\n const bounds = resolveMeterBounds(min, max, low, high, optimum);\n const formattedValue = formatRangeValue(clamped, min, max, format, locale);\n const base: MeterState = {\n value: clamped,\n min,\n max,\n ...bounds,\n percentage: percentage(clamped, min, max),\n formattedValue,\n valueText: formattedValue,\n region: meterRegion(clamped, bounds.low, bounds.high, bounds.optimum),\n };\n const valueText =\n getAriaValueText === undefined ? formattedValue : (getAriaValueText(clamped, base) ?? null);\n const state: MeterState = valueText === base.valueText ? base : { ...base, valueText };\n\n const variables = {\n \"--meter-value\": `${state.percentage}%`,\n \"--meter-low\": `${percentage(bounds.low, min, max)}%`,\n \"--meter-high\": `${percentage(bounds.high, min, max)}%`,\n \"--meter-optimum\": `${percentage(bounds.optimum, min, max)}%`,\n };\n\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: \"meter\",\n \"aria-valuemin\": min,\n \"aria-valuemax\": max,\n \"aria-valuenow\": clamped,\n \"aria-valuetext\": valueText ?? undefined,\n \"aria-labelledby\": `${id}-label`,\n \"data-region\": state.region,\n };\n\n const element = renderElement<ComponentPropsWithRef<\"div\">, MeterState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The custom properties lose to the consumer's own entries (design 3.3).\n style: (s) => ({ ...(variables as CSSProperties), ...resolveStateValue(style, s) }),\n children,\n props: rest,\n libraryProps,\n // Passed through to the element, never read during render.\n // oxlint-disable-next-line react/refs\n ref: mergeRenderRef(ref, render),\n });\n\n return <MeterContext value={{ id, state }}>{element}</MeterContext>;\n}\n\nMeterRoot.displayName = \"MeterRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"meter-root.mjs","names":[],"sources":["../../src/meter/meter-root.tsx"],"sourcesContent":["// No \"use client\": `Meter.Root` uses only `useId`, arithmetic and `Intl`, and renders the client\n// context's provider (conventions 7.1's second exception). Rendered by a Server Component it runs\n// once, on the server (design/components/progress.md 8.1). It must not import from any\n// \"use client\" module except its context (checked by src/__tests__/directives.test.ts).\nimport { useId } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { warnOnce } from \"../internal/dev-warn.js\";\nimport { clamp, formatRangeValue, isDegenerate, percentage } from \"../internal/range-value.js\";\nimport { mergeRenderRef, renderElement, resolveStateValue } from \"../internal/render-element.js\";\nimport type { DataAttributes } from \"../internal/render-element.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { MeterContext } from \"./meter-context.js\";\nimport { meterRegion, resolveMeterBounds } from \"./meter-region.js\";\nimport type { MeterRegion } from \"./meter-region.js\";\n\nexport type { MeterRegion } from \"./meter-region.js\";\n\n/** The state every Meter part receives. */\nexport interface MeterState {\n /** Clamped to `[min, max]`. */\n readonly value: number;\n /** The `min` prop. */\n readonly min: number;\n /** The `max` prop. */\n readonly max: number;\n /** After HTML's defaults and clamping. */\n readonly low: number;\n /** After HTML's defaults and clamping. */\n readonly high: number;\n /** After HTML's defaults and clamping. */\n readonly optimum: number;\n /** A number 0–100. */\n readonly percentage: number;\n /** The `Intl.NumberFormat` text of the value (or of the fraction, for the percent style). */\n readonly formattedValue: string;\n /** What `aria-valuetext` carries: `getAriaValueText`'s result, else `formattedValue`. */\n readonly valueText: string | null;\n /**\n * Which region of the range the value is in, as the platform computes it; rendered as\n * `data-region` on every part.\n */\n readonly region: MeterRegion;\n}\n\n/**\n * Props of `Meter.Root`.\n *\n * @see https://ui.funstack.work/components/meter\n */\nexport interface MeterRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"role\"\n | \"aria-valuemin\"\n | \"aria-valuemax\"\n | \"aria-valuenow\"\n | \"aria-valuetext\"\n | \"defaultValue\"\n | \"defaultChecked\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Required: a meter always has a value. Clamped to `[min, max]`. */\n value: number;\n /**\n * Lower bound of the range.\n *\n * @defaultValue `0`\n */\n min?: number;\n /**\n * Upper bound of the range.\n *\n * @defaultValue `100`\n */\n max?: number;\n /**\n * Upper bound of the \"low\" part of the range.\n *\n * @defaultValue `min`\n */\n low?: number;\n /**\n * Lower bound of the \"high\" part of the range.\n *\n * @defaultValue `max`\n */\n high?: number;\n /**\n * The best value. Decides which part of the range is `optimum`.\n *\n * @defaultValue the midpoint, `(min + max) / 2`\n */\n optimum?: number;\n /**\n * `Intl.NumberFormat` options for `aria-valuetext` and `Meter.Value`. A `percent` style formats\n * the fraction of the range; any other style formats the value. Serialisable: a Server\n * Component may pass it.\n *\n * @defaultValue `{ style: \"percent\" }`\n */\n format?: Intl.NumberFormatOptions;\n /**\n * BCP 47 tag, or a preference list of tags, for `Intl.NumberFormat`. Pass it when a client\n * tree is server-rendered.\n *\n * @defaultValue the runtime's locale\n */\n locale?: string | readonly string[];\n /**\n * The `aria-valuetext` to render instead of `formattedValue`. Called with the clamped value\n * and the state as it would be without this prop. Return `null` to render no\n * `aria-valuetext`.\n */\n getAriaValueText?: (value: number, state: MeterState) => string | null | undefined;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MeterState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MeterState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MeterState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MeterState>;\n}\n\n/**\n * `Meter.Root`: a `div[role=meter]` with the ARIA values and `aria-valuetext` always,\n * `data-region`, and `--meter-value` / `--meter-low` / `--meter-high` / `--meter-optimum` (the\n * percentages) in `style`, where the consumer's entries win. Owned keys: `role`,\n * `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext`, `aria-labelledby`\n * (token-merged: the consumer's tokens, then `Meter.Label`'s id, always), `data-region`.\n *\n * @see https://ui.funstack.work/components/meter\n */\nexport function MeterRoot({\n value,\n min = 0,\n max = 100,\n low,\n high,\n optimum,\n format,\n locale,\n getAriaValueText,\n className,\n style,\n children,\n render,\n ref,\n ...rest\n}: MeterRootProps) {\n const id = useId();\n\n let given = value;\n if (!Number.isFinite(given)) {\n warnOnce(\n `Meter.Root:non-finite:${given}`,\n `Meter.Root: \\`value\\` is ${given}, which is not a finite number; it is rendered as \\`min\\`.`,\n );\n given = min;\n }\n if (isDegenerate(min, max)) {\n warnOnce(\n `Meter.Root:degenerate:${min}:${max}`,\n `Meter.Root: \\`max\\` (${max}) must be greater than \\`min\\` (${min}); the percentage is ` +\n \"rendered as 0.\",\n );\n }\n\n const clamped = clamp(given, min, max);\n const bounds = resolveMeterBounds(min, max, low, high, optimum);\n const formattedValue = formatRangeValue(clamped, min, max, format, locale);\n const base: MeterState = {\n value: clamped,\n min,\n max,\n ...bounds,\n percentage: percentage(clamped, min, max),\n formattedValue,\n valueText: formattedValue,\n region: meterRegion(clamped, bounds.low, bounds.high, bounds.optimum),\n };\n const valueText =\n getAriaValueText === undefined ? formattedValue : (getAriaValueText(clamped, base) ?? null);\n const state: MeterState = valueText === base.valueText ? base : { ...base, valueText };\n\n const variables = {\n \"--meter-value\": `${state.percentage}%`,\n \"--meter-low\": `${percentage(bounds.low, min, max)}%`,\n \"--meter-high\": `${percentage(bounds.high, min, max)}%`,\n \"--meter-optimum\": `${percentage(bounds.optimum, min, max)}%`,\n };\n\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: \"meter\",\n \"aria-valuemin\": min,\n \"aria-valuemax\": max,\n \"aria-valuenow\": clamped,\n \"aria-valuetext\": valueText ?? undefined,\n \"aria-labelledby\": `${id}-label`,\n \"data-region\": state.region,\n };\n\n const element = renderElement<ComponentPropsWithRef<\"div\">, MeterState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The custom properties lose to the consumer's own entries (design 3.3).\n style: (s) => ({ ...(variables as CSSProperties), ...resolveStateValue(style, s) }),\n children,\n props: rest,\n libraryProps,\n // Passed through to the element, never read during render.\n // oxlint-disable-next-line react/refs\n ref: mergeRenderRef(ref, render),\n });\n\n return <MeterContext value={{ id, state }}>{element}</MeterContext>;\n}\n\nMeterRoot.displayName = \"MeterRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAsIA,SAAgB,UAAU,EACxB,OACA,MAAM,GACN,MAAM,KACN,KACA,MACA,SACA,QACA,QACA,kBACA,WACA,OACA,UACA,QACA,KACA,GAAG,QACc;CACjB,MAAM,KAAK,MAAM;CAEjB,IAAI,QAAQ;CACZ,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG;EAC3B,SACE,yBAAyB,SACzB,4BAA4B,MAAM,2DACpC;EACA,QAAQ;CACV;CACA,IAAI,aAAa,KAAK,GAAG,GACvB,SACE,yBAAyB,IAAI,GAAG,OAChC,wBAAwB,IAAI,kCAAkC,IAAI,oCAEpE;CAGF,MAAM,UAAU,MAAM,OAAO,KAAK,GAAG;CACrC,MAAM,SAAS,mBAAmB,KAAK,KAAK,KAAK,MAAM,OAAO;CAC9D,MAAM,iBAAiB,iBAAiB,SAAS,KAAK,KAAK,QAAQ,MAAM;CACzE,MAAM,OAAmB;EACvB,OAAO;EACP;EACA;EACA,GAAG;EACH,YAAY,WAAW,SAAS,KAAK,GAAG;EACxC;EACA,WAAW;EACX,QAAQ,YAAY,SAAS,OAAO,KAAK,OAAO,MAAM,OAAO,OAAO;CACtE;CACA,MAAM,YACJ,qBAAqB,KAAA,IAAY,iBAAkB,iBAAiB,SAAS,IAAI,KAAK;CACxF,MAAM,QAAoB,cAAc,KAAK,YAAY,OAAO;EAAE,GAAG;EAAM;CAAU;CAErF,MAAM,YAAY;EAChB,iBAAiB,GAAG,MAAM,WAAW;EACrC,eAAe,GAAG,WAAW,OAAO,KAAK,KAAK,GAAG,EAAE;EACnD,gBAAgB,GAAG,WAAW,OAAO,MAAM,KAAK,GAAG,EAAE;EACrD,mBAAmB,GAAG,WAAW,OAAO,SAAS,KAAK,GAAG,EAAE;CAC7D;CAEA,MAAM,eAAuE;EAC3E,MAAM;EACN,iBAAiB;EACjB,iBAAiB;EACjB,iBAAiB;EACjB,kBAAkB,aAAa,KAAA;EAC/B,mBAAmB,GAAG,GAAG;EACzB,eAAe,MAAM;CACvB;CAEA,MAAM,UAAU,cAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,QAAQ,OAAO;GAAE,GAAI;GAA6B,GAAG,kBAAkB,OAAO,CAAC;EAAE;EACjF;EACA,OAAO;EACP;EAGA,KAAK,eAAe,KAAK,MAAM;CACjC,CAAC;CAED,OAAO,oBAAC,cAAD;EAAc,OAAO;GAAE;GAAI;EAAM;EAAI,UAAA;CAAsB,CAAA;AACpE;AAEA,UAAU,cAAc"}
|
|
@@ -4,10 +4,10 @@ import { useLatest } from "../internal/use-latest.mjs";
|
|
|
4
4
|
import { toSet } from "../internal/value-set.mjs";
|
|
5
5
|
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
6
6
|
import { popoverDetails, usePopoverRoot } from "../internal/overlay/use-overlay-root.mjs";
|
|
7
|
+
import { toggleFromTrigger } from "../internal/overlay/use-popover-trigger.mjs";
|
|
7
8
|
import { FieldContext } from "../internal/form/field-context.mjs";
|
|
8
9
|
import { resolveFieldDefaults, useFieldValueChange } from "../internal/form/use-field-control.mjs";
|
|
9
10
|
import { useFormReset, useResetTarget } from "../internal/form/use-form-reset.mjs";
|
|
10
|
-
import { toggleFromTrigger } from "../internal/overlay/use-popover-trigger.mjs";
|
|
11
11
|
import { createTypeaheadBuffer } from "../internal/typeahead.mjs";
|
|
12
12
|
import { optionLabel, useOptionRegistry } from "../internal/use-option-registry.mjs";
|
|
13
13
|
import { HiddenValues } from "../internal/form/hidden-values.mjs";
|
|
@@ -4,9 +4,9 @@ import { useRender } from "../internal/use-render.mjs";
|
|
|
4
4
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
5
5
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
6
6
|
import { registerTrigger } from "../internal/overlay/trigger-ref.mjs";
|
|
7
|
+
import { RESERVED_INVOKER_KEYS } from "../internal/overlay/use-popover-trigger.mjs";
|
|
7
8
|
import { useFieldControl } from "../internal/form/use-field-control.mjs";
|
|
8
9
|
import { supportsUserInvalid } from "../internal/form/validity.mjs";
|
|
9
|
-
import { RESERVED_INVOKER_KEYS } from "../internal/overlay/use-popover-trigger.mjs";
|
|
10
10
|
import { optionId } from "../internal/use-option-registry.mjs";
|
|
11
11
|
import { useMultiSelectContext } from "./multi-select-context.mjs";
|
|
12
12
|
import { collectInvalid } from "../internal/form/focus-first-invalid.mjs";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "../internal/platform-attributes.mjs";
|
|
2
|
+
import { NavigationMenuItem, NavigationMenuItemProps, NavigationMenuItemState, NavigationMenuOpenChangeDetails } from "./navigation-menu-item.mjs";
|
|
3
|
+
import { NavigationMenuLink, NavigationMenuLinkProps, NavigationMenuLinkState } from "./navigation-menu-link.mjs";
|
|
4
|
+
import { NavigationMenuList, NavigationMenuListProps, NavigationMenuListState } from "./navigation-menu-list.mjs";
|
|
5
|
+
import { NavigationMenuAlign, NavigationMenuPopup, NavigationMenuPopupProps, NavigationMenuPopupState, NavigationMenuSide } from "./navigation-menu-popup.mjs";
|
|
6
|
+
import { NavigationMenuRoot, NavigationMenuRootProps, NavigationMenuRootState } from "./navigation-menu-root.mjs";
|
|
7
|
+
import { NavigationMenuTrigger, NavigationMenuTriggerProps, NavigationMenuTriggerState } from "./navigation-menu-trigger.mjs";
|
|
8
|
+
//#region src/navigation-menu/index.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A site's main navigation, the APG disclosure pattern (no menu roles, Tab through everything):
|
|
11
|
+
* `Root` (`nav`) > `List` (`ul[role=list]`) > `Item` (`li`, the owner of one flyout) >
|
|
12
|
+
* `Trigger` (`button[popovertarget]`) + `Popup` (`div[popover=auto]`, right after the Trigger),
|
|
13
|
+
* and `Link` (`a`). JS-free when an Item has none of `open` / `defaultOpen` /
|
|
14
|
+
* `openChangeAction` / `onOpenChange`: the browser toggles the panel, keeps one open at a time,
|
|
15
|
+
* closes it on Escape and a press outside. After hydration the library adds two closes: focus
|
|
16
|
+
* leaving the Item, and a followed Link inside the panel. In library mode opening and the closes a
|
|
17
|
+
* part asks for are requests (pending Trigger, content from committed state); dismissals are
|
|
18
|
+
* facts for `onOpenChange(false)`.
|
|
19
|
+
*
|
|
20
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
21
|
+
*/
|
|
22
|
+
export declare const NavigationMenu: {
|
|
23
|
+
readonly Root: typeof NavigationMenuRoot;
|
|
24
|
+
readonly List: typeof NavigationMenuList;
|
|
25
|
+
readonly Item: typeof NavigationMenuItem;
|
|
26
|
+
readonly Trigger: typeof NavigationMenuTrigger;
|
|
27
|
+
readonly Popup: typeof NavigationMenuPopup;
|
|
28
|
+
readonly Link: typeof NavigationMenuLink;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export type { NavigationMenuAlign, NavigationMenuItemProps, NavigationMenuItemState, NavigationMenuLinkProps, NavigationMenuLinkState, NavigationMenuListProps, NavigationMenuListState, NavigationMenuOpenChangeDetails, NavigationMenuPopupProps, NavigationMenuPopupState, NavigationMenuRootProps, NavigationMenuRootState, NavigationMenuSide, NavigationMenuTriggerProps, NavigationMenuTriggerState };
|
|
32
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/navigation-menu/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;qBAuBa;WACX,aAAI;WACJ,aAAI;WACJ,aAAI;WACJ,gBAAO;WACP,cAAK;WACL,aAAI"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NavigationMenuItem } from "./navigation-menu-item.mjs";
|
|
2
|
+
import { NavigationMenuLink } from "./navigation-menu-link.mjs";
|
|
3
|
+
import { NavigationMenuList } from "./navigation-menu-list.mjs";
|
|
4
|
+
import { NavigationMenuPopup } from "./navigation-menu-popup.mjs";
|
|
5
|
+
import { NavigationMenuRoot } from "./navigation-menu-root.mjs";
|
|
6
|
+
import { NavigationMenuTrigger } from "./navigation-menu-trigger.mjs";
|
|
7
|
+
//#region src/navigation-menu/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* A site's main navigation, the APG disclosure pattern (no menu roles, Tab through everything):
|
|
10
|
+
* `Root` (`nav`) > `List` (`ul[role=list]`) > `Item` (`li`, the owner of one flyout) >
|
|
11
|
+
* `Trigger` (`button[popovertarget]`) + `Popup` (`div[popover=auto]`, right after the Trigger),
|
|
12
|
+
* and `Link` (`a`). JS-free when an Item has none of `open` / `defaultOpen` /
|
|
13
|
+
* `openChangeAction` / `onOpenChange`: the browser toggles the panel, keeps one open at a time,
|
|
14
|
+
* closes it on Escape and a press outside. After hydration the library adds two closes: focus
|
|
15
|
+
* leaving the Item, and a followed Link inside the panel. In library mode opening and the closes a
|
|
16
|
+
* part asks for are requests (pending Trigger, content from committed state); dismissals are
|
|
17
|
+
* facts for `onOpenChange(false)`.
|
|
18
|
+
*
|
|
19
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
20
|
+
*/
|
|
21
|
+
const NavigationMenu = {
|
|
22
|
+
Root: NavigationMenuRoot,
|
|
23
|
+
List: NavigationMenuList,
|
|
24
|
+
Item: NavigationMenuItem,
|
|
25
|
+
Trigger: NavigationMenuTrigger,
|
|
26
|
+
Popup: NavigationMenuPopup,
|
|
27
|
+
Link: NavigationMenuLink
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { NavigationMenu };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/navigation-menu/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { NavigationMenuItem } from \"./navigation-menu-item.js\";\nimport { NavigationMenuLink } from \"./navigation-menu-link.js\";\nimport { NavigationMenuList } from \"./navigation-menu-list.js\";\nimport { NavigationMenuPopup } from \"./navigation-menu-popup.js\";\nimport { NavigationMenuRoot } from \"./navigation-menu-root.js\";\nimport { NavigationMenuTrigger } from \"./navigation-menu-trigger.js\";\n\n/**\n * A site's main navigation, the APG disclosure pattern (no menu roles, Tab through everything):\n * `Root` (`nav`) > `List` (`ul[role=list]`) > `Item` (`li`, the owner of one flyout) >\n * `Trigger` (`button[popovertarget]`) + `Popup` (`div[popover=auto]`, right after the Trigger),\n * and `Link` (`a`). JS-free when an Item has none of `open` / `defaultOpen` /\n * `openChangeAction` / `onOpenChange`: the browser toggles the panel, keeps one open at a time,\n * closes it on Escape and a press outside. After hydration the library adds two closes: focus\n * leaving the Item, and a followed Link inside the panel. In library mode opening and the closes a\n * part asks for are requests (pending Trigger, content from committed state); dismissals are\n * facts for `onOpenChange(false)`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport const NavigationMenu = {\n Root: NavigationMenuRoot,\n List: NavigationMenuList,\n Item: NavigationMenuItem,\n Trigger: NavigationMenuTrigger,\n Popup: NavigationMenuPopup,\n Link: NavigationMenuLink,\n} as const;\n\nexport type { NavigationMenuRootProps, NavigationMenuRootState } from \"./navigation-menu-root.js\";\nexport type { NavigationMenuListProps, NavigationMenuListState } from \"./navigation-menu-list.js\";\nexport type {\n NavigationMenuItemProps,\n NavigationMenuItemState,\n NavigationMenuOpenChangeDetails,\n} from \"./navigation-menu-item.js\";\nexport type {\n NavigationMenuTriggerProps,\n NavigationMenuTriggerState,\n} from \"./navigation-menu-trigger.js\";\nexport type {\n NavigationMenuPopupProps,\n NavigationMenuPopupState,\n NavigationMenuSide,\n NavigationMenuAlign,\n} from \"./navigation-menu-popup.js\";\nexport type { NavigationMenuLinkProps, NavigationMenuLinkState } from \"./navigation-menu-link.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,iBAAiB;CAC5B,MAAM;CACN,MAAM;CACN,MAAM;CACN,SAAS;CACT,OAAO;CACP,MAAM;AACR"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, use } from "react";
|
|
3
|
+
//#region src/navigation-menu/navigation-menu-context.ts
|
|
4
|
+
/** The open state of one flyout, owned by `NavigationMenu.Item` (navigation-menu.md 1). */
|
|
5
|
+
const NavigationMenuItemContext = createContext(null);
|
|
6
|
+
function useNavigationMenuItemContext(part) {
|
|
7
|
+
const context = use(NavigationMenuItemContext);
|
|
8
|
+
if (context === null) throw new Error(`${part} must be rendered inside a NavigationMenu.Item.`);
|
|
9
|
+
return context;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Set by `NavigationMenu.Popup` around its children: the Item whose panel a `NavigationMenu.Link`
|
|
13
|
+
* closes when followed (navigation-menu.md 4). `null` outside a Popup (a top-level link).
|
|
14
|
+
*/
|
|
15
|
+
const NavigationMenuPopupContext = createContext(null);
|
|
16
|
+
//#endregion
|
|
17
|
+
export { NavigationMenuItemContext, NavigationMenuPopupContext, useNavigationMenuItemContext };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=navigation-menu-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-context.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\n\n/** The open state of one flyout, owned by `NavigationMenu.Item` (navigation-menu.md 1). */\nexport const NavigationMenuItemContext = createContext<PopoverRootValue | null>(null);\n\nexport function useNavigationMenuItemContext(part: string): PopoverRootValue {\n const context = use(NavigationMenuItemContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a NavigationMenu.Item.`);\n }\n return context;\n}\n\n/**\n * Set by `NavigationMenu.Popup` around its children: the Item whose panel a `NavigationMenu.Link`\n * closes when followed (navigation-menu.md 4). `null` outside a Popup (a top-level link).\n */\nexport const NavigationMenuPopupContext = createContext<PopoverRootValue | null>(null);\n"],"mappings":";;;;AAKA,MAAa,4BAA4B,cAAuC,IAAI;AAEpF,SAAgB,6BAA6B,MAAgC;CAC3E,MAAM,UAAU,IAAI,yBAAyB;CAC7C,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,gDAAgD;CAE1E,OAAO;AACT;;;;;AAMA,MAAa,6BAA6B,cAAuC,IAAI"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ActionDetails, ChangeAction, ChangeReason, RenderProp, StateValue, UrgentChangeHandler } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/navigation-menu/navigation-menu-item.d.ts
|
|
4
|
+
/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */
|
|
5
|
+
export interface NavigationMenuOpenChangeDetails extends ActionDetails {
|
|
6
|
+
/**
|
|
7
|
+
* `"activate"`: the Trigger, a followed `NavigationMenu.Link`, a foreign invoker.
|
|
8
|
+
* `"dismiss"`: Escape, a press outside, another panel opening, focus leaving the Item, script.
|
|
9
|
+
* `"platform"`: the panel was found open on mount (opened before hydration); `event` is
|
|
10
|
+
* `undefined`.
|
|
11
|
+
*/
|
|
12
|
+
readonly reason: ChangeReason;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* State of `NavigationMenu.Item`, passed to the function forms of `className`, `style`,
|
|
16
|
+
* `children` and `render`.
|
|
17
|
+
*/
|
|
18
|
+
export interface NavigationMenuItemState {
|
|
19
|
+
/** Optimistic open state (library mode); `false` in JS-free mode. */
|
|
20
|
+
readonly open: boolean;
|
|
21
|
+
/** An `openChangeAction` dispatched through this Item is in flight (library mode only). */
|
|
22
|
+
readonly pending: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Props of `NavigationMenu.Item`.
|
|
26
|
+
*
|
|
27
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
28
|
+
*/
|
|
29
|
+
export interface NavigationMenuItemProps extends Omit<ComponentPropsWithRef<"li">, "className" | "style" | "children"> {
|
|
30
|
+
/**
|
|
31
|
+
* Controlled open state of this Item's panel. `undefined` means uncontrolled (and, with
|
|
32
|
+
* `defaultOpen`, `openChangeAction` and `onOpenChange` also absent, JS-free mode). A controlled
|
|
33
|
+
* Item needs `onOpenChange` too: the browser closes the panel without asking.
|
|
34
|
+
*/
|
|
35
|
+
open?: boolean;
|
|
36
|
+
/** Initial open state in uncontrolled library mode. Opens after hydration, never in the HTML. */
|
|
37
|
+
defaultOpen?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Requests only: the Trigger's toggle and a followed Link's close. Awaited: the panel opens
|
|
40
|
+
* when it resolves and the content has rendered, and closes when a close resolves. May be a
|
|
41
|
+
* Server Function. Rejections reach the nearest Error Boundary above the Item.
|
|
42
|
+
*/
|
|
43
|
+
openChangeAction?: ChangeAction<boolean, NavigationMenuOpenChangeDetails>;
|
|
44
|
+
/**
|
|
45
|
+
* Facts only: the panel was dismissed (Escape, a press outside, another panel opening, focus
|
|
46
|
+
* leaving the Item, script). Always `false`, called synchronously, outside any Transition, and
|
|
47
|
+
* not awaited. Controlled: set your state directly here (`onOpenChange={setOpen}`).
|
|
48
|
+
*/
|
|
49
|
+
onOpenChange?: UrgentChangeHandler<boolean, NavigationMenuOpenChangeDetails>;
|
|
50
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
51
|
+
className?: StateValue<string | undefined, NavigationMenuItemState>;
|
|
52
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
53
|
+
style?: StateValue<CSSProperties | undefined, NavigationMenuItemState>;
|
|
54
|
+
/** A Trigger and its Popup, or a Link. The function form receives the optimistic state. */
|
|
55
|
+
children?: StateValue<ReactNode, NavigationMenuItemState>;
|
|
56
|
+
/** Replace the default `<li>` (element form) or take over rendering (function form). */
|
|
57
|
+
render?: RenderProp<ComponentPropsWithRef<"li">, NavigationMenuItemState>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* One top-level entry, an `<li>`, and the owner of one flyout: the id the Trigger and Popup share
|
|
61
|
+
* and the open state, with Popover's two modes (design 2). Without `open`, `defaultOpen`,
|
|
62
|
+
* `openChangeAction` and `onOpenChange` the Item runs in **JS-free mode**: the browser toggles
|
|
63
|
+
* the panel. With any of them it runs in **library mode**: opening and the closes a part asks for
|
|
64
|
+
* (Trigger, a followed Link) are requests through `openChangeAction`; dismissals are facts for
|
|
65
|
+
* `onOpenChange`.
|
|
66
|
+
*
|
|
67
|
+
* Focus leaving the Item (to an element outside it) closes its panel (design 3.2): a shown panel
|
|
68
|
+
* is hidden at once (a `"dismiss"` fact), an open still pending is superseded by a `"dismiss"`
|
|
69
|
+
* request. The `focusout` listener is attached through the ref, so `onBlur` stays the
|
|
70
|
+
* consumer's. An Item with only a Link in it is a plain `<li>`.
|
|
71
|
+
*
|
|
72
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
73
|
+
*/
|
|
74
|
+
export declare function NavigationMenuItem({ open, defaultOpen, openChangeAction, onOpenChange, className, style, children, render, ...rest }: NavigationMenuItemProps): import("react").JSX.Element;
|
|
75
|
+
export declare namespace NavigationMenuItem {
|
|
76
|
+
var displayName: string;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//# sourceMappingURL=navigation-menu-item.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-item.d.mts","names":[],"sources":["../../src/navigation-menu/navigation-menu-item.tsx"],"mappings":";;;;iBAiBiB,wCAAwC;;;;;;;WAO9C,QAAQ;;;;;;iBAOF;;WAEN;;WAEA;;;;;;;iBAQM,gCAAgC,KAC/C;;;;;;EAQA;;EAEA;;;;;;EAMA,mBAAmB,sBAAsB;;;;;;EAMzC,eAAe,6BAA6B;;EAE5C,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,6BAA6B;;;;;;;;;;;;;;;;;wBAkBnC,qBACd,MACA,aACA,kBACA,cACA,WACA,OACA,UACA,WACG,QACF,0CAAuB,IAAA;yBAVV"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
4
|
+
import { popoverDetails, usePopoverRoot } from "../internal/overlay/use-overlay-root.mjs";
|
|
5
|
+
import { NavigationMenuItemContext } from "./navigation-menu-context.mjs";
|
|
6
|
+
import { useCallback } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
//#region src/navigation-menu/navigation-menu-item.tsx
|
|
9
|
+
/**
|
|
10
|
+
* One top-level entry, an `<li>`, and the owner of one flyout: the id the Trigger and Popup share
|
|
11
|
+
* and the open state, with Popover's two modes (design 2). Without `open`, `defaultOpen`,
|
|
12
|
+
* `openChangeAction` and `onOpenChange` the Item runs in **JS-free mode**: the browser toggles
|
|
13
|
+
* the panel. With any of them it runs in **library mode**: opening and the closes a part asks for
|
|
14
|
+
* (Trigger, a followed Link) are requests through `openChangeAction`; dismissals are facts for
|
|
15
|
+
* `onOpenChange`.
|
|
16
|
+
*
|
|
17
|
+
* Focus leaving the Item (to an element outside it) closes its panel (design 3.2): a shown panel
|
|
18
|
+
* is hidden at once (a `"dismiss"` fact), an open still pending is superseded by a `"dismiss"`
|
|
19
|
+
* request. The `focusout` listener is attached through the ref, so `onBlur` stays the
|
|
20
|
+
* consumer's. An Item with only a Link in it is a plain `<li>`.
|
|
21
|
+
*
|
|
22
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
23
|
+
*/
|
|
24
|
+
function NavigationMenuItem({ open, defaultOpen, openChangeAction, onOpenChange, className, style, children, render, ...rest }) {
|
|
25
|
+
const context = usePopoverRoot({
|
|
26
|
+
component: "navigation-menu",
|
|
27
|
+
part: "NavigationMenu.Item",
|
|
28
|
+
open,
|
|
29
|
+
defaultOpen,
|
|
30
|
+
openChangeAction,
|
|
31
|
+
onOpenChange,
|
|
32
|
+
details: popoverDetails
|
|
33
|
+
});
|
|
34
|
+
const { mode, popupRef, intended, requestClose, recordCloseIntent } = context;
|
|
35
|
+
const ref = useCallback((element) => {
|
|
36
|
+
const onFocusOut = (event) => {
|
|
37
|
+
const next = event.relatedTarget;
|
|
38
|
+
if (!(next instanceof Node) || element.contains(next)) return;
|
|
39
|
+
const popup = popupRef.current;
|
|
40
|
+
if (popup !== null && isPopoverOpen(popup)) {
|
|
41
|
+
if (mode === "library") recordCloseIntent({
|
|
42
|
+
reason: "dismiss",
|
|
43
|
+
event
|
|
44
|
+
});
|
|
45
|
+
popup.hidePopover();
|
|
46
|
+
} else if (mode === "library" && intended()) requestClose(event, "dismiss");
|
|
47
|
+
};
|
|
48
|
+
element.addEventListener("focusout", onFocusOut);
|
|
49
|
+
return () => element.removeEventListener("focusout", onFocusOut);
|
|
50
|
+
}, [
|
|
51
|
+
mode,
|
|
52
|
+
popupRef,
|
|
53
|
+
intended,
|
|
54
|
+
requestClose,
|
|
55
|
+
recordCloseIntent
|
|
56
|
+
]);
|
|
57
|
+
const state = {
|
|
58
|
+
open: context.optimistic,
|
|
59
|
+
pending: context.pending
|
|
60
|
+
};
|
|
61
|
+
const element = useRender({
|
|
62
|
+
defaultElement: "li",
|
|
63
|
+
render,
|
|
64
|
+
state,
|
|
65
|
+
className,
|
|
66
|
+
style,
|
|
67
|
+
children,
|
|
68
|
+
props: rest,
|
|
69
|
+
ref
|
|
70
|
+
});
|
|
71
|
+
return /* @__PURE__ */ jsx(NavigationMenuItemContext, {
|
|
72
|
+
value: context,
|
|
73
|
+
children: element
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
NavigationMenuItem.displayName = "NavigationMenuItem";
|
|
77
|
+
//#endregion
|
|
78
|
+
export { NavigationMenuItem };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=navigation-menu-item.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-item.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-item.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { popoverDetails, usePopoverRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { NavigationMenuItemContext } from \"./navigation-menu-context.js\";\n\n/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */\nexport interface NavigationMenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the Trigger, a followed `NavigationMenu.Link`, a foreign invoker.\n * `\"dismiss\"`: Escape, a press outside, another panel opening, focus leaving the Item, script.\n * `\"platform\"`: the panel was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * State of `NavigationMenu.Item`, passed to the function forms of `className`, `style`,\n * `children` and `render`.\n */\nexport interface NavigationMenuItemState {\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly open: boolean;\n /** An `openChangeAction` dispatched through this Item is in flight (library mode only). */\n readonly pending: boolean;\n}\n\n/**\n * Props of `NavigationMenu.Item`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport interface NavigationMenuItemProps extends Omit<\n ComponentPropsWithRef<\"li\">,\n \"className\" | \"style\" | \"children\"\n> {\n /**\n * Controlled open state of this Item's panel. `undefined` means uncontrolled (and, with\n * `defaultOpen`, `openChangeAction` and `onOpenChange` also absent, JS-free mode). A controlled\n * Item needs `onOpenChange` too: the browser closes the panel without asking.\n */\n open?: boolean;\n /** Initial open state in uncontrolled library mode. Opens after hydration, never in the HTML. */\n defaultOpen?: boolean;\n /**\n * Requests only: the Trigger's toggle and a followed Link's close. Awaited: the panel opens\n * when it resolves and the content has rendered, and closes when a close resolves. May be a\n * Server Function. Rejections reach the nearest Error Boundary above the Item.\n */\n openChangeAction?: ChangeAction<boolean, NavigationMenuOpenChangeDetails>;\n /**\n * Facts only: the panel was dismissed (Escape, a press outside, another panel opening, focus\n * leaving the Item, script). Always `false`, called synchronously, outside any Transition, and\n * not awaited. Controlled: set your state directly here (`onOpenChange={setOpen}`).\n */\n onOpenChange?: UrgentChangeHandler<boolean, NavigationMenuOpenChangeDetails>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NavigationMenuItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NavigationMenuItemState>;\n /** A Trigger and its Popup, or a Link. The function form receives the optimistic state. */\n children?: StateValue<ReactNode, NavigationMenuItemState>;\n /** Replace the default `<li>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"li\">, NavigationMenuItemState>;\n}\n\n/**\n * One top-level entry, an `<li>`, and the owner of one flyout: the id the Trigger and Popup share\n * and the open state, with Popover's two modes (design 2). Without `open`, `defaultOpen`,\n * `openChangeAction` and `onOpenChange` the Item runs in **JS-free mode**: the browser toggles\n * the panel. With any of them it runs in **library mode**: opening and the closes a part asks for\n * (Trigger, a followed Link) are requests through `openChangeAction`; dismissals are facts for\n * `onOpenChange`.\n *\n * Focus leaving the Item (to an element outside it) closes its panel (design 3.2): a shown panel\n * is hidden at once (a `\"dismiss\"` fact), an open still pending is superseded by a `\"dismiss\"`\n * request. The `focusout` listener is attached through the ref, so `onBlur` stays the\n * consumer's. An Item with only a Link in it is a plain `<li>`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport function NavigationMenuItem({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n className,\n style,\n children,\n render,\n ...rest\n}: NavigationMenuItemProps) {\n const context = usePopoverRoot<NavigationMenuOpenChangeDetails>({\n component: \"navigation-menu\",\n part: \"NavigationMenu.Item\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: popoverDetails,\n });\n const { mode, popupRef, intended, requestClose, recordCloseIntent } = context;\n\n // The focus-leave close (design 3.2, Menu's Tab rule on the `li`). A null `relatedTarget`\n // (window blur, a removed element) closes nothing.\n const ref = useCallback(\n (element: HTMLElement) => {\n const onFocusOut = (event: FocusEvent) => {\n const next = event.relatedTarget;\n if (!(next instanceof Node) || element.contains(next)) return;\n const popup = popupRef.current;\n if (popup !== null && isPopoverOpen(popup)) {\n // A fact in library mode, named by this event; a DOM-level hide in JS-free mode.\n if (mode === \"library\") recordCloseIntent({ reason: \"dismiss\", event });\n popup.hidePopover();\n } else if (mode === \"library\" && intended()) {\n requestClose(event, \"dismiss\");\n }\n };\n element.addEventListener(\"focusout\", onFocusOut);\n return () => element.removeEventListener(\"focusout\", onFocusOut);\n },\n [mode, popupRef, intended, requestClose, recordCloseIntent],\n );\n\n const state: NavigationMenuItemState = { open: context.optimistic, pending: context.pending };\n\n const element = useRender<ComponentPropsWithRef<\"li\">, NavigationMenuItemState>({\n defaultElement: \"li\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n ref,\n });\n\n return <NavigationMenuItemContext value={context}>{element}</NavigationMenuItemContext>;\n}\n\nNavigationMenuItem.displayName = \"NavigationMenuItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,mBAAmB,EACjC,MACA,aACA,kBACA,cACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,UAAU,eAAgD;EAC9D,WAAW;EACX,MAAM;EACN;EACA;EACA;EACA;EACA,SAAS;CACX,CAAC;CACD,MAAM,EAAE,MAAM,UAAU,UAAU,cAAc,sBAAsB;CAItE,MAAM,MAAM,aACT,YAAyB;EACxB,MAAM,cAAc,UAAsB;GACxC,MAAM,OAAO,MAAM;GACnB,IAAI,EAAE,gBAAgB,SAAS,QAAQ,SAAS,IAAI,GAAG;GACvD,MAAM,QAAQ,SAAS;GACvB,IAAI,UAAU,QAAQ,cAAc,KAAK,GAAG;IAE1C,IAAI,SAAS,WAAW,kBAAkB;KAAE,QAAQ;KAAW;IAAM,CAAC;IACtE,MAAM,YAAY;GACpB,OAAO,IAAI,SAAS,aAAa,SAAS,GACxC,aAAa,OAAO,SAAS;EAEjC;EACA,QAAQ,iBAAiB,YAAY,UAAU;EAC/C,aAAa,QAAQ,oBAAoB,YAAY,UAAU;CACjE,GACA;EAAC;EAAM;EAAU;EAAU;EAAc;CAAiB,CAC5D;CAEA,MAAM,QAAiC;EAAE,MAAM,QAAQ;EAAY,SAAS,QAAQ;CAAQ;CAE5F,MAAM,UAAU,UAAgE;EAC9E,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;CAED,OAAO,oBAAC,2BAAD;EAA2B,OAAO;EAAU,UAAA;CAAmC,CAAA;AACxF;AAEA,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/navigation-menu/navigation-menu-link.d.ts
|
|
4
|
+
/** `NavigationMenu.Link` has no state. */
|
|
5
|
+
export type NavigationMenuLinkState = Record<string, never>;
|
|
6
|
+
/**
|
|
7
|
+
* Props of `NavigationMenu.Link`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
10
|
+
*/
|
|
11
|
+
export interface NavigationMenuLinkProps extends Omit<ComponentPropsWithRef<"a">, "className" | "style" | "children"> {
|
|
12
|
+
/**
|
|
13
|
+
* Inside a Popup: following the link (a primary-button click with no modifier key) closes the
|
|
14
|
+
* panel. `false` keeps it open (a link that changes something inside the panel). Ignored
|
|
15
|
+
* outside a Popup.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue `true`
|
|
18
|
+
*/
|
|
19
|
+
closeOnActivate?: boolean;
|
|
20
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
21
|
+
className?: StateValue<string | undefined, NavigationMenuLinkState>;
|
|
22
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
23
|
+
style?: StateValue<CSSProperties | undefined, NavigationMenuLinkState>;
|
|
24
|
+
/** Content, or a function of the part's state. */
|
|
25
|
+
children?: StateValue<ReactNode, NavigationMenuLinkState>;
|
|
26
|
+
/** Replace the default `<a>`: a router's link component (`render={<Link to="/" />}`). */
|
|
27
|
+
render?: RenderProp<ComponentPropsWithRef<"a">, NavigationMenuLinkState>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A link: an `<a>` with every anchor prop passed through; the current page is marked with the
|
|
31
|
+
* native `aria-current="page"`. Inside a `NavigationMenu.Popup`, following it closes the panel
|
|
32
|
+
* (design 4): with a client-side router the `nav` stays mounted and a click inside a popover is
|
|
33
|
+
* no light dismiss. In library mode the close is a request (`openChangeAction(false, { reason:
|
|
34
|
+
* "activate" })`, a transition like a router's navigation); in JS-free mode `hidePopover()`. A
|
|
35
|
+
* modified click (new tab, new window, download) leaves the panel open. Outside a Popup it does
|
|
36
|
+
* nothing beyond rendering the `<a>`.
|
|
37
|
+
*
|
|
38
|
+
* The close is attached with `addEventListener` through the ref, so `onClick` is not owned and
|
|
39
|
+
* a consumer's or a router link's own click handling runs untouched. No owned keys.
|
|
40
|
+
*
|
|
41
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
42
|
+
*/
|
|
43
|
+
export declare function NavigationMenuLink({ closeOnActivate, className, style, children, render, ...rest }: NavigationMenuLinkProps): ReactNode;
|
|
44
|
+
export declare namespace NavigationMenuLink {
|
|
45
|
+
var displayName: string;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//# sourceMappingURL=navigation-menu-link.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-link.d.mts","names":[],"sources":["../../src/navigation-menu/navigation-menu-link.tsx"],"mappings":";;;;YAWY,0BAA0B;;;;;;iBASrB,gCAAgC,KAC/C;;;;;;;;EAUA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,4BAA4B;;;;;;;;;;;;;;;;wBAgClC,qBACd,iBACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBAPV"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
+
import { useLatest } from "../internal/use-latest.mjs";
|
|
4
|
+
import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
|
|
5
|
+
import { NavigationMenuPopupContext } from "./navigation-menu-context.mjs";
|
|
6
|
+
import { use, useCallback } from "react";
|
|
7
|
+
//#region src/navigation-menu/navigation-menu-link.tsx
|
|
8
|
+
const EMPTY = {};
|
|
9
|
+
/** The click that navigates this page: primary button, no modifier (design 4). */
|
|
10
|
+
function followsInPlace(event) {
|
|
11
|
+
return event.button === 0 && !event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey;
|
|
12
|
+
}
|
|
13
|
+
/** Closes the panel `item` owns: a request in library mode, `hidePopover()` in JS-free mode. */
|
|
14
|
+
function closePanel(item, event) {
|
|
15
|
+
if (item.mode === "library") {
|
|
16
|
+
item.requestClose(event, "activate");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const popup = item.popupRef.current;
|
|
20
|
+
if (popup !== null && isPopoverOpen(popup)) popup.hidePopover();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A link: an `<a>` with every anchor prop passed through; the current page is marked with the
|
|
24
|
+
* native `aria-current="page"`. Inside a `NavigationMenu.Popup`, following it closes the panel
|
|
25
|
+
* (design 4): with a client-side router the `nav` stays mounted and a click inside a popover is
|
|
26
|
+
* no light dismiss. In library mode the close is a request (`openChangeAction(false, { reason:
|
|
27
|
+
* "activate" })`, a transition like a router's navigation); in JS-free mode `hidePopover()`. A
|
|
28
|
+
* modified click (new tab, new window, download) leaves the panel open. Outside a Popup it does
|
|
29
|
+
* nothing beyond rendering the `<a>`.
|
|
30
|
+
*
|
|
31
|
+
* The close is attached with `addEventListener` through the ref, so `onClick` is not owned and
|
|
32
|
+
* a consumer's or a router link's own click handling runs untouched. No owned keys.
|
|
33
|
+
*
|
|
34
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
35
|
+
*/
|
|
36
|
+
function NavigationMenuLink({ closeOnActivate = true, className, style, children, render, ...rest }) {
|
|
37
|
+
const item = use(NavigationMenuPopupContext);
|
|
38
|
+
const latest = useLatest({
|
|
39
|
+
item,
|
|
40
|
+
closeOnActivate
|
|
41
|
+
});
|
|
42
|
+
const ref = useCallback((element) => {
|
|
43
|
+
const onClick = (event) => {
|
|
44
|
+
const { item, closeOnActivate } = latest.current;
|
|
45
|
+
if (item === null || !closeOnActivate || !followsInPlace(event)) return;
|
|
46
|
+
closePanel(item, event);
|
|
47
|
+
};
|
|
48
|
+
element.addEventListener("click", onClick);
|
|
49
|
+
return () => element.removeEventListener("click", onClick);
|
|
50
|
+
}, [latest]);
|
|
51
|
+
return useRender({
|
|
52
|
+
defaultElement: "a",
|
|
53
|
+
render,
|
|
54
|
+
state: EMPTY,
|
|
55
|
+
className,
|
|
56
|
+
style,
|
|
57
|
+
children,
|
|
58
|
+
props: rest,
|
|
59
|
+
ref
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
NavigationMenuLink.displayName = "NavigationMenuLink";
|
|
63
|
+
//#endregion
|
|
64
|
+
export { NavigationMenuLink };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=navigation-menu-link.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-link.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-link.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { NavigationMenuPopupContext } from \"./navigation-menu-context.js\";\n\n/** `NavigationMenu.Link` has no state. */\nexport type NavigationMenuLinkState = Record<string, never>;\n\nconst EMPTY: Record<string, never> = {};\n\n/**\n * Props of `NavigationMenu.Link`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport interface NavigationMenuLinkProps extends Omit<\n ComponentPropsWithRef<\"a\">,\n \"className\" | \"style\" | \"children\"\n> {\n /**\n * Inside a Popup: following the link (a primary-button click with no modifier key) closes the\n * panel. `false` keeps it open (a link that changes something inside the panel). Ignored\n * outside a Popup.\n *\n * @defaultValue `true`\n */\n closeOnActivate?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NavigationMenuLinkState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NavigationMenuLinkState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, NavigationMenuLinkState>;\n /** Replace the default `<a>`: a router's link component (`render={<Link to=\"/\" />}`). */\n render?: RenderProp<ComponentPropsWithRef<\"a\">, NavigationMenuLinkState>;\n}\n\n/** The click that navigates this page: primary button, no modifier (design 4). */\nfunction followsInPlace(event: MouseEvent): boolean {\n return event.button === 0 && !event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey;\n}\n\n/** Closes the panel `item` owns: a request in library mode, `hidePopover()` in JS-free mode. */\nfunction closePanel(item: PopoverRootValue, event: MouseEvent): void {\n if (item.mode === \"library\") {\n item.requestClose(event, \"activate\");\n return;\n }\n const popup = item.popupRef.current;\n if (popup !== null && isPopoverOpen(popup)) popup.hidePopover();\n}\n\n/**\n * A link: an `<a>` with every anchor prop passed through; the current page is marked with the\n * native `aria-current=\"page\"`. Inside a `NavigationMenu.Popup`, following it closes the panel\n * (design 4): with a client-side router the `nav` stays mounted and a click inside a popover is\n * no light dismiss. In library mode the close is a request (`openChangeAction(false, { reason:\n * \"activate\" })`, a transition like a router's navigation); in JS-free mode `hidePopover()`. A\n * modified click (new tab, new window, download) leaves the panel open. Outside a Popup it does\n * nothing beyond rendering the `<a>`.\n *\n * The close is attached with `addEventListener` through the ref, so `onClick` is not owned and\n * a consumer's or a router link's own click handling runs untouched. No owned keys.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport function NavigationMenuLink({\n closeOnActivate = true,\n className,\n style,\n children,\n render,\n ...rest\n}: NavigationMenuLinkProps) {\n const item = use(NavigationMenuPopupContext);\n // Read at the click: the latest committed props and Item.\n const latest = useLatest({ item, closeOnActivate });\n const ref = useCallback(\n (element: HTMLElement) => {\n const onClick = (event: MouseEvent) => {\n const { item, closeOnActivate } = latest.current;\n if (item === null || !closeOnActivate || !followsInPlace(event)) return;\n closePanel(item, event);\n };\n element.addEventListener(\"click\", onClick);\n return () => element.removeEventListener(\"click\", onClick);\n },\n [latest],\n );\n\n return useRender<ComponentPropsWithRef<\"a\">, NavigationMenuLinkState>({\n defaultElement: \"a\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: rest,\n ref,\n });\n}\n\nNavigationMenuLink.displayName = \"NavigationMenuLink\";\n"],"mappings":";;;;;;;AAaA,MAAM,QAA+B,CAAC;;AA8BtC,SAAS,eAAe,OAA4B;CAClD,OAAO,MAAM,WAAW,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,WAAW,CAAC,MAAM,YAAY,CAAC,MAAM;AAC7F;;AAGA,SAAS,WAAW,MAAwB,OAAyB;CACnE,IAAI,KAAK,SAAS,WAAW;EAC3B,KAAK,aAAa,OAAO,UAAU;EACnC;CACF;CACA,MAAM,QAAQ,KAAK,SAAS;CAC5B,IAAI,UAAU,QAAQ,cAAc,KAAK,GAAG,MAAM,YAAY;AAChE;;;;;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,EACjC,kBAAkB,MAClB,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,IAAI,0BAA0B;CAE3C,MAAM,SAAS,UAAU;EAAE;EAAM;CAAgB,CAAC;CAClD,MAAM,MAAM,aACT,YAAyB;EACxB,MAAM,WAAW,UAAsB;GACrC,MAAM,EAAE,MAAM,oBAAoB,OAAO;GACzC,IAAI,SAAS,QAAQ,CAAC,mBAAmB,CAAC,eAAe,KAAK,GAAG;GACjE,WAAW,MAAM,KAAK;EACxB;EACA,QAAQ,iBAAiB,SAAS,OAAO;EACzC,aAAa,QAAQ,oBAAoB,SAAS,OAAO;CAC3D,GACA,CAAC,MAAM,CACT;CAEA,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/navigation-menu/navigation-menu-list.d.ts
|
|
4
|
+
/** `NavigationMenu.List` has no state. */
|
|
5
|
+
export type NavigationMenuListState = Record<string, never>;
|
|
6
|
+
/**
|
|
7
|
+
* Props of `NavigationMenu.List`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
10
|
+
*/
|
|
11
|
+
export interface NavigationMenuListProps extends Omit<ComponentPropsWithRef<"ul">, "className" | "style" | "children"> {
|
|
12
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
13
|
+
className?: StateValue<string | undefined, NavigationMenuListState>;
|
|
14
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
15
|
+
style?: StateValue<CSSProperties | undefined, NavigationMenuListState>;
|
|
16
|
+
/** Content: `NavigationMenu.Item`s. */
|
|
17
|
+
children?: StateValue<ReactNode, NavigationMenuListState>;
|
|
18
|
+
/** Replace the default `<ul>` (element form) or take over rendering (function form). */
|
|
19
|
+
render?: RenderProp<ComponentPropsWithRef<"ul">, NavigationMenuListState>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The top-level entries: a `<ul role="list">`. The explicit role keeps the list semantics that
|
|
23
|
+
* Safari drops under `list-style: none` (design 1); it is a default the consumer may override.
|
|
24
|
+
* Directive-free, so a Server Component may render it.
|
|
25
|
+
*
|
|
26
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
27
|
+
*/
|
|
28
|
+
export declare function NavigationMenuList({ className, style, children, render, ref, ...rest }: NavigationMenuListProps): ReactNode;
|
|
29
|
+
export declare namespace NavigationMenuList {
|
|
30
|
+
var displayName: string;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//# sourceMappingURL=navigation-menu-list.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-list.d.mts","names":[],"sources":["../../src/navigation-menu/navigation-menu-list.tsx"],"mappings":";;;;YAQY,0BAA0B;;;;;;iBASrB,gCAAgC,KAC/C;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,6BAA6B;;;;;;;;;wBAUnC,qBACd,WACA,OACA,UACA,QACA,QACG,QACF,0BAAuB;yBAPV"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { mergeRenderRef, renderElement } from "../internal/render-element.mjs";
|
|
2
|
+
//#region src/navigation-menu/navigation-menu-list.tsx
|
|
3
|
+
const EMPTY = {};
|
|
4
|
+
/**
|
|
5
|
+
* The top-level entries: a `<ul role="list">`. The explicit role keeps the list semantics that
|
|
6
|
+
* Safari drops under `list-style: none` (design 1); it is a default the consumer may override.
|
|
7
|
+
* Directive-free, so a Server Component may render it.
|
|
8
|
+
*
|
|
9
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
10
|
+
*/
|
|
11
|
+
function NavigationMenuList({ className, style, children, render, ref, ...rest }) {
|
|
12
|
+
return renderElement({
|
|
13
|
+
defaultElement: "ul",
|
|
14
|
+
render,
|
|
15
|
+
state: EMPTY,
|
|
16
|
+
className,
|
|
17
|
+
style,
|
|
18
|
+
children,
|
|
19
|
+
props: {
|
|
20
|
+
role: "list",
|
|
21
|
+
...rest
|
|
22
|
+
},
|
|
23
|
+
ref: mergeRenderRef(ref, render)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
NavigationMenuList.displayName = "NavigationMenuList";
|
|
27
|
+
//#endregion
|
|
28
|
+
export { NavigationMenuList };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=navigation-menu-list.mjs.map
|