@funstack/ui 0.1.0-alpha.20 → 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/alert-dialog/alert-dialog-root.mjs +2 -1
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -1
- package/dist/avatar/avatar-context.mjs +24 -0
- package/dist/avatar/avatar-context.mjs.map +1 -0
- package/dist/avatar/avatar-fallback.d.mts +32 -0
- package/dist/avatar/avatar-fallback.d.mts.map +1 -0
- package/dist/avatar/avatar-fallback.mjs +31 -0
- package/dist/avatar/avatar-fallback.mjs.map +1 -0
- package/dist/avatar/avatar-image.d.mts +37 -0
- package/dist/avatar/avatar-image.d.mts.map +1 -0
- package/dist/avatar/avatar-image.mjs +91 -0
- package/dist/avatar/avatar-image.mjs.map +1 -0
- package/dist/avatar/avatar-root.d.mts +48 -0
- package/dist/avatar/avatar-root.d.mts.map +1 -0
- package/dist/avatar/avatar-root.mjs +81 -0
- package/dist/avatar/avatar-root.mjs.map +1 -0
- package/dist/avatar/index.d.mts +24 -0
- package/dist/avatar/index.d.mts.map +1 -0
- package/dist/avatar/index.mjs +24 -0
- package/dist/avatar/index.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +14 -3
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs +7 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +1 -0
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +20 -2
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.mjs +6 -4
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/docs/components/avatar.md +354 -0
- package/dist/docs/components/drawer.md +622 -0
- 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 +508 -0
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/radio-group.md +1 -1
- package/dist/docs/components/scroll-area.md +294 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/concepts/direction-and-locales.md +106 -0
- package/dist/docs/index.md +8 -1
- package/dist/docs/roadmap.md +13 -0
- package/dist/drawer/drawer-close.d.mts +26 -0
- package/dist/drawer/drawer-close.d.mts.map +1 -0
- package/dist/drawer/drawer-close.mjs +19 -0
- package/dist/drawer/drawer-close.mjs.map +1 -0
- package/dist/drawer/drawer-description.d.mts +23 -0
- package/dist/drawer/drawer-description.d.mts.map +1 -0
- package/dist/drawer/drawer-description.mjs +18 -0
- package/dist/drawer/drawer-description.mjs.map +1 -0
- package/dist/drawer/drawer-form.d.mts +24 -0
- package/dist/drawer/drawer-form.d.mts.map +1 -0
- package/dist/drawer/drawer-form.mjs +19 -0
- package/dist/drawer/drawer-form.mjs.map +1 -0
- package/dist/drawer/drawer-popup.d.mts +77 -0
- package/dist/drawer/drawer-popup.d.mts.map +1 -0
- package/dist/drawer/drawer-popup.mjs +124 -0
- package/dist/drawer/drawer-popup.mjs.map +1 -0
- package/dist/drawer/drawer-root.d.mts +31 -0
- package/dist/drawer/drawer-root.d.mts.map +1 -0
- package/dist/drawer/drawer-root.mjs +23 -0
- package/dist/drawer/drawer-root.mjs.map +1 -0
- package/dist/drawer/drawer-swipe.d.mts +5 -0
- package/dist/drawer/drawer-swipe.d.mts.map +1 -0
- package/dist/drawer/drawer-swipe.mjs +193 -0
- package/dist/drawer/drawer-swipe.mjs.map +1 -0
- package/dist/drawer/drawer-title.d.mts +23 -0
- package/dist/drawer/drawer-title.d.mts.map +1 -0
- package/dist/drawer/drawer-title.mjs +18 -0
- package/dist/drawer/drawer-title.mjs.map +1 -0
- package/dist/drawer/drawer-trigger.d.mts +23 -0
- package/dist/drawer/drawer-trigger.d.mts.map +1 -0
- package/dist/drawer/drawer-trigger.mjs +18 -0
- package/dist/drawer/drawer-trigger.mjs.map +1 -0
- package/dist/drawer/index.d.mts +34 -0
- package/dist/drawer/index.d.mts.map +1 -0
- package/dist/drawer/index.mjs +33 -0
- package/dist/drawer/index.mjs.map +1 -0
- package/dist/index.d.mts +29 -2
- package/dist/index.mjs +6 -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/internal/swipe-arithmetic.mjs +75 -0
- package/dist/internal/swipe-arithmetic.mjs.map +1 -0
- package/dist/internal/swipe.mjs +169 -0
- package/dist/internal/swipe.mjs.map +1 -0
- package/dist/menu/menu-context-trigger.mjs +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +34 -7
- 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/index.d.mts +23 -0
- package/dist/otp-field/index.d.mts.map +1 -0
- package/dist/otp-field/index.mjs +23 -0
- package/dist/otp-field/index.mjs.map +1 -0
- package/dist/otp-field/otp-field-context.mjs +13 -0
- package/dist/otp-field/otp-field-context.mjs.map +1 -0
- package/dist/otp-field/otp-field-filter.d.mts +5 -0
- package/dist/otp-field/otp-field-filter.d.mts.map +1 -0
- package/dist/otp-field/otp-field-filter.mjs +135 -0
- package/dist/otp-field/otp-field-filter.mjs.map +1 -0
- package/dist/otp-field/otp-field-input.d.mts +41 -0
- package/dist/otp-field/otp-field-input.d.mts.map +1 -0
- package/dist/otp-field/otp-field-input.mjs +177 -0
- package/dist/otp-field/otp-field-input.mjs.map +1 -0
- package/dist/otp-field/otp-field-root.d.mts +152 -0
- package/dist/otp-field/otp-field-root.d.mts.map +1 -0
- package/dist/otp-field/otp-field-root.mjs +400 -0
- package/dist/otp-field/otp-field-root.mjs.map +1 -0
- package/dist/otp-field/otp-field-slot.d.mts +52 -0
- package/dist/otp-field/otp-field-slot.d.mts.map +1 -0
- package/dist/otp-field/otp-field-slot.mjs +67 -0
- package/dist/otp-field/otp-field-slot.mjs.map +1 -0
- 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 +7 -1
- package/skills/funstack-ui-knowledge/SKILL.md +8 -1
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-list.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-list.tsx"],"sourcesContent":["// No \"use client\": `NavigationMenu.List` reads no context and calls no hook, so a Server\n// Component may render it (design/components/navigation-menu.md 8). It must not import from any\n// \"use client\" module (checked by src/__tests__/directives.test.ts).\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { mergeRenderRef, renderElement } from \"../internal/render-element.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\n\n/** `NavigationMenu.List` has no state. */\nexport type NavigationMenuListState = Record<string, never>;\n\nconst EMPTY: Record<string, never> = {};\n\n/**\n * Props of `NavigationMenu.List`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport interface NavigationMenuListProps extends Omit<\n ComponentPropsWithRef<\"ul\">,\n \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NavigationMenuListState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NavigationMenuListState>;\n /** Content: `NavigationMenu.Item`s. */\n children?: StateValue<ReactNode, NavigationMenuListState>;\n /** Replace the default `<ul>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"ul\">, NavigationMenuListState>;\n}\n\n/**\n * The top-level entries: a `<ul role=\"list\">`. The explicit role keeps the list semantics that\n * Safari drops under `list-style: none` (design 1); it is a default the consumer may override.\n * Directive-free, so a Server Component may render it.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport function NavigationMenuList({\n className,\n style,\n children,\n render,\n ref,\n ...rest\n}: NavigationMenuListProps) {\n return renderElement<ComponentPropsWithRef<\"ul\">, NavigationMenuListState>({\n defaultElement: \"ul\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: { role: \"list\", ...rest },\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\nNavigationMenuList.displayName = \"NavigationMenuList\";\n"],"mappings":";;AAUA,MAAM,QAA+B,CAAC;;;;;;;;AA4BtC,SAAgB,mBAAmB,EACjC,WACA,OACA,UACA,QACA,KACA,GAAG,QACuB;CAC1B,OAAO,cAAoE;EACzE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;GAAE,MAAM;GAAQ,GAAG;EAAK;EAG/B,KAAK,eAAe,KAAK,MAAM;CACjC,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { AnchorAlign, AnchorSide } from "../internal/overlay/anchor-position.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
|
|
4
|
+
//#region src/navigation-menu/navigation-menu-popup.d.ts
|
|
5
|
+
/** `inline-start` / `inline-end` follow the panel's `direction` (conventions 13.1). */
|
|
6
|
+
export type NavigationMenuSide = AnchorSide;
|
|
7
|
+
/**
|
|
8
|
+
* Alignment of the panel along its side: inline-relative on a top / bottom side, the top /
|
|
9
|
+
* bottom edges on the others.
|
|
10
|
+
*/
|
|
11
|
+
export type NavigationMenuAlign = AnchorAlign;
|
|
12
|
+
/**
|
|
13
|
+
* State of `NavigationMenu.Popup`, passed to the function forms of `className`, `style`,
|
|
14
|
+
* `children` and `render`.
|
|
15
|
+
*/
|
|
16
|
+
export interface NavigationMenuPopupState {
|
|
17
|
+
/**
|
|
18
|
+
* Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the
|
|
19
|
+
* DOM truth.
|
|
20
|
+
*/
|
|
21
|
+
readonly open: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* While shown: the physical side the browser placed the panel on (after any fallback flip;
|
|
24
|
+
* conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`.
|
|
25
|
+
*/
|
|
26
|
+
readonly side: NavigationMenuSide | null;
|
|
27
|
+
/** While shown: the resolved alignment; otherwise the `align` prop. */
|
|
28
|
+
readonly align: NavigationMenuAlign;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Props of `NavigationMenu.Popup`.
|
|
32
|
+
*
|
|
33
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
34
|
+
*/
|
|
35
|
+
export interface NavigationMenuPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "onToggle" | "onBeforeToggle" | "className" | "style" | "children"> {
|
|
36
|
+
/**
|
|
37
|
+
* Placement relative to the Trigger through inline `position-area`, with
|
|
38
|
+
* `position-try-fallbacks` flipping it when it does not fit. `null` emits no inline positioning
|
|
39
|
+
* (and no `data-side` / `data-align`), so a stylesheet owns placement (a full-width panel).
|
|
40
|
+
*
|
|
41
|
+
* @defaultValue `"bottom"`
|
|
42
|
+
*/
|
|
43
|
+
side?: NavigationMenuSide | null;
|
|
44
|
+
/**
|
|
45
|
+
* Alignment along the side. On a top / bottom side `start` / `end` are inline-relative
|
|
46
|
+
* (mirrored under `direction: rtl`). Ignored when `side` is `null`.
|
|
47
|
+
*
|
|
48
|
+
* @defaultValue `"start"`
|
|
49
|
+
*/
|
|
50
|
+
align?: NavigationMenuAlign;
|
|
51
|
+
/**
|
|
52
|
+
* Library mode: what happens to the children while the panel is closed.
|
|
53
|
+
* - `false` (default): not rendered. Mounting them is part of the opening transition, so
|
|
54
|
+
* content that suspends holds the open (the Trigger is `data-pending`) until it is ready.
|
|
55
|
+
* - `true`: rendered inside `<Activity mode="hidden">`: DOM and state preserved, effects
|
|
56
|
+
* stopped. Not in the server HTML.
|
|
57
|
+
*
|
|
58
|
+
* Ignored in JS-free mode (always mounted, in the server HTML).
|
|
59
|
+
*
|
|
60
|
+
* @defaultValue `false`
|
|
61
|
+
*/
|
|
62
|
+
keepMounted?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Library mode only. Forwarded to the `<ViewTransition default>` around the popover element.
|
|
65
|
+
* Animates library-driven opens and closes (the Trigger, a followed Link, controlled changes);
|
|
66
|
+
* dismissals animate with CSS only. Ignored (dev warning) in JS-free mode.
|
|
67
|
+
*
|
|
68
|
+
* Static: setting or unsetting it remounts the element.
|
|
69
|
+
*/
|
|
70
|
+
transition?: ViewTransitionClass;
|
|
71
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
72
|
+
className?: StateValue<string | undefined, NavigationMenuPopupState>;
|
|
73
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
74
|
+
style?: StateValue<CSSProperties | undefined, NavigationMenuPopupState>;
|
|
75
|
+
/** The panel's links, or a function of the part's state. Library mode: may suspend. */
|
|
76
|
+
children?: StateValue<ReactNode, NavigationMenuPopupState>;
|
|
77
|
+
/** Replace the default `<div>` (element form) or take over rendering (function form). */
|
|
78
|
+
render?: RenderProp<ComponentPropsWithRef<"div">, NavigationMenuPopupState>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The panel: a `<div popover="auto">` with no role (the disclosure pattern), placed against the
|
|
82
|
+
* Trigger with CSS Anchor Positioning. Render it **immediately after** the Trigger in the same
|
|
83
|
+
* Item: every engine then puts the panel's links right after the Trigger in the Tab order
|
|
84
|
+
* (development warning otherwise). Sibling `auto` popovers close each other, so one panel is
|
|
85
|
+
* open at a time.
|
|
86
|
+
*
|
|
87
|
+
* JS-free mode: the children are always mounted (in the server HTML). Library mode: they render
|
|
88
|
+
* from committed state, so content that suspends holds the open with `data-pending` on the
|
|
89
|
+
* Trigger; `showPopover({ source: trigger })` runs in the commit that mounted them. Style it with
|
|
90
|
+
* `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
|
|
91
|
+
*
|
|
92
|
+
* Owned keys (conventions 1.2): `id`, `popover`, and `data-side` / `data-align` unless `side` is
|
|
93
|
+
* `null`.
|
|
94
|
+
*
|
|
95
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
96
|
+
*/
|
|
97
|
+
export declare function NavigationMenuPopup({ side: sideProp, align: alignProp, keepMounted, transition, className, style, children, render, ...rest }: NavigationMenuPopupProps): ReactNode;
|
|
98
|
+
export declare namespace NavigationMenuPopup {
|
|
99
|
+
var displayName: string;
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//# sourceMappingURL=navigation-menu-popup.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-popup.d.mts","names":[],"sources":["../../src/navigation-menu/navigation-menu-popup.tsx"],"mappings":";;;;;YAsBY,qBAAqB;;;;;YAKrB,sBAAsB;;;;;iBAMjB;;;;;WAKN;;;;;WAKA,MAAM;;WAEN,OAAO;;;;;;;iBAQD,iCAAiC,KAChD;;;;;;;;EAUA,OAAO;;;;;;;EAOP,QAAQ;;;;;;;;;;;;EAYR;;;;;;;;EAQA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;wBAuBpC,sBACd,MAAM,UACN,OAAO,WACP,aACA,YACA,WACA,OACA,UACA,WACG,QACF,2BAAwB;yBAVX"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
3
|
+
import { resolveStateValue } from "../internal/render-element.mjs";
|
|
4
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
5
|
+
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
6
|
+
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
7
|
+
import { useAnchoredPlacement } from "../internal/overlay/use-resolved-placement.mjs";
|
|
8
|
+
import { listenInvokerPresses } from "../internal/overlay/invokers.mjs";
|
|
9
|
+
import { useJsFreePropWarnings } from "../internal/overlay/overlay-popup.mjs";
|
|
10
|
+
import { usePopoverPopup } from "../internal/overlay/use-popover-popup.mjs";
|
|
11
|
+
import { NavigationMenuPopupContext, useNavigationMenuItemContext } from "./navigation-menu-context.mjs";
|
|
12
|
+
import { useEffect, useRef } from "react";
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
//#region src/navigation-menu/navigation-menu-popup.tsx
|
|
15
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
16
|
+
/** The panel is a `<div>` (design 1). */
|
|
17
|
+
const POPUP_ELEMENTS = ["DIV"];
|
|
18
|
+
/**
|
|
19
|
+
* The panel: a `<div popover="auto">` with no role (the disclosure pattern), placed against the
|
|
20
|
+
* Trigger with CSS Anchor Positioning. Render it **immediately after** the Trigger in the same
|
|
21
|
+
* Item: every engine then puts the panel's links right after the Trigger in the Tab order
|
|
22
|
+
* (development warning otherwise). Sibling `auto` popovers close each other, so one panel is
|
|
23
|
+
* open at a time.
|
|
24
|
+
*
|
|
25
|
+
* JS-free mode: the children are always mounted (in the server HTML). Library mode: they render
|
|
26
|
+
* from committed state, so content that suspends holds the open with `data-pending` on the
|
|
27
|
+
* Trigger; `showPopover({ source: trigger })` runs in the commit that mounted them. Style it with
|
|
28
|
+
* `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
|
|
29
|
+
*
|
|
30
|
+
* Owned keys (conventions 1.2): `id`, `popover`, and `data-side` / `data-align` unless `side` is
|
|
31
|
+
* `null`.
|
|
32
|
+
*
|
|
33
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
34
|
+
*/
|
|
35
|
+
function NavigationMenuPopup({ side: sideProp = "bottom", align: alignProp = "start", keepMounted, transition, className, style, children, render, ...rest }) {
|
|
36
|
+
const ctx = useNavigationMenuItemContext("NavigationMenu.Popup");
|
|
37
|
+
const isLibrary = ctx.mode === "library";
|
|
38
|
+
const { ids, popupRef, triggerRef } = ctx;
|
|
39
|
+
useJsFreePropWarnings("NavigationMenu.Popup", "panel", isLibrary, transition, keepMounted);
|
|
40
|
+
const { setElement, renderContent } = usePopoverPopup(ctx, {
|
|
41
|
+
part: "NavigationMenu.Popup",
|
|
42
|
+
keepMounted,
|
|
43
|
+
transition: isLibrary ? transition : void 0,
|
|
44
|
+
elements: POPUP_ELEMENTS,
|
|
45
|
+
whileShown: listenInvokerPresses
|
|
46
|
+
});
|
|
47
|
+
const checkSecond = useElementCheck(isDev && ((element) => popupRef.current !== null && popupRef.current !== element ? "NavigationMenu.Popup: a second NavigationMenu.Popup mounted in the same Item. An Item has one Trigger and one Popup; give each panel its own NavigationMenu.Item." : null));
|
|
48
|
+
const self = useRef(null);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!isDev) return;
|
|
51
|
+
const element = self.current;
|
|
52
|
+
const trigger = triggerRef.current;
|
|
53
|
+
if (element === null || trigger === null || element.previousElementSibling === trigger) return;
|
|
54
|
+
console.error("NavigationMenu.Popup: the Popup does not directly follow its NavigationMenu.Trigger. Render the Popup immediately after the Trigger: Safari puts a popover's content after its invoker in the Tab order only when the two are adjacent.");
|
|
55
|
+
}, [triggerRef]);
|
|
56
|
+
const placement = useAnchoredPlacement({
|
|
57
|
+
side: sideProp,
|
|
58
|
+
align: alignProp
|
|
59
|
+
});
|
|
60
|
+
const { side, align } = placement;
|
|
61
|
+
const ref = useMergedRefs(checkSecond, setElement, placement.ref, self);
|
|
62
|
+
const state = {
|
|
63
|
+
open: ctx.committed,
|
|
64
|
+
side,
|
|
65
|
+
align
|
|
66
|
+
};
|
|
67
|
+
const content = (s) => /* @__PURE__ */ jsx(NavigationMenuPopupContext, {
|
|
68
|
+
value: ctx,
|
|
69
|
+
children: renderContent(() => resolveStateValue(children, s))
|
|
70
|
+
});
|
|
71
|
+
const libraryProps = {
|
|
72
|
+
id: ids.popup,
|
|
73
|
+
popover: "auto",
|
|
74
|
+
...placement.dataAttributes
|
|
75
|
+
};
|
|
76
|
+
const element = useRender({
|
|
77
|
+
defaultElement: "div",
|
|
78
|
+
render,
|
|
79
|
+
state,
|
|
80
|
+
className,
|
|
81
|
+
style: placement.style(style),
|
|
82
|
+
children: content,
|
|
83
|
+
props: rest,
|
|
84
|
+
libraryProps,
|
|
85
|
+
ref
|
|
86
|
+
});
|
|
87
|
+
return useTransitionBoundary("NavigationMenu.Popup", isLibrary ? transition : void 0, element);
|
|
88
|
+
}
|
|
89
|
+
NavigationMenuPopup.displayName = "NavigationMenuPopup";
|
|
90
|
+
//#endregion
|
|
91
|
+
export { NavigationMenuPopup };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=navigation-menu-popup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-popup.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, ViewTransitionClass } from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/overlay/anchor-position.js\";\nimport { listenInvokerPresses } from \"../internal/overlay/invokers.js\";\nimport { useJsFreePropWarnings } from \"../internal/overlay/overlay-popup.js\";\nimport { usePopoverPopup } from \"../internal/overlay/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/overlay/use-resolved-placement.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n NavigationMenuPopupContext,\n useNavigationMenuItemContext,\n} from \"./navigation-menu-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the panel's `direction` (conventions 13.1). */\nexport type NavigationMenuSide = AnchorSide;\n/**\n * Alignment of the panel along its side: inline-relative on a top / bottom side, the top /\n * bottom edges on the others.\n */\nexport type NavigationMenuAlign = AnchorAlign;\n\n/**\n * State of `NavigationMenu.Popup`, passed to the function forms of `className`, `style`,\n * `children` and `render`.\n */\nexport interface NavigationMenuPopupState {\n /**\n * Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the\n * DOM truth.\n */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the panel on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`.\n */\n readonly side: NavigationMenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: NavigationMenuAlign;\n}\n\n/**\n * Props of `NavigationMenu.Popup`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport interface NavigationMenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"popover\" | \"onToggle\" | \"onBeforeToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Placement relative to the Trigger through inline `position-area`, with\n * `position-try-fallbacks` flipping it when it does not fit. `null` emits no inline positioning\n * (and no `data-side` / `data-align`), so a stylesheet owns placement (a full-width panel).\n *\n * @defaultValue `\"bottom\"`\n */\n side?: NavigationMenuSide | null;\n /**\n * Alignment along the side. On a top / bottom side `start` / `end` are inline-relative\n * (mirrored under `direction: rtl`). Ignored when `side` is `null`.\n *\n * @defaultValue `\"start\"`\n */\n align?: NavigationMenuAlign;\n /**\n * Library mode: what happens to the children while the panel is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open (the Trigger is `data-pending`) until it is ready.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted, in the server HTML).\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the popover element.\n * Animates library-driven opens and closes (the Trigger, a followed Link, controlled changes);\n * dismissals animate with CSS only. Ignored (dev warning) in JS-free mode.\n *\n * Static: setting or unsetting it remounts the element.\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NavigationMenuPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NavigationMenuPopupState>;\n /** The panel's links, or a function of the part's state. Library mode: may suspend. */\n children?: StateValue<ReactNode, NavigationMenuPopupState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, NavigationMenuPopupState>;\n}\n\n/** The panel is a `<div>` (design 1). */\nconst POPUP_ELEMENTS: readonly string[] = [\"DIV\"];\n\n/**\n * The panel: a `<div popover=\"auto\">` with no role (the disclosure pattern), placed against the\n * Trigger with CSS Anchor Positioning. Render it **immediately after** the Trigger in the same\n * Item: every engine then puts the panel's links right after the Trigger in the Tab order\n * (development warning otherwise). Sibling `auto` popovers close each other, so one panel is\n * open at a time.\n *\n * JS-free mode: the children are always mounted (in the server HTML). Library mode: they render\n * from committed state, so content that suspends holds the open with `data-pending` on the\n * Trigger; `showPopover({ source: trigger })` runs in the commit that mounted them. Style it with\n * `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, and `data-side` / `data-align` unless `side` is\n * `null`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport function NavigationMenuPopup({\n side: sideProp = \"bottom\",\n align: alignProp = \"start\",\n keepMounted,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: NavigationMenuPopupProps) {\n const ctx = useNavigationMenuItemContext(\"NavigationMenu.Popup\");\n const isLibrary = ctx.mode === \"library\";\n const { ids, popupRef, triggerRef } = ctx;\n\n useJsFreePropWarnings(\"NavigationMenu.Popup\", \"panel\", isLibrary, transition, keepMounted);\n\n const { setElement, renderContent } = usePopoverPopup(ctx, {\n part: \"NavigationMenu.Popup\",\n keepMounted,\n transition: isLibrary ? transition : undefined,\n elements: POPUP_ELEMENTS,\n // While shown, a primary press on any `popovertarget` / `commandfor` invoker of the panel\n // moves no focus: a foreign one outside the Item (the focus-leave close would otherwise hide\n // the panel before the invoker's own toggle), and the panel's own Trigger as well. The latter\n // is harmless and intended: focus is already inside the Item, and the hide returns it.\n whileShown: listenInvokerPresses,\n });\n\n // Development checks (design 7): one Popup per Item, directly after its Trigger. Runs before\n // `setElement`, which registers this element.\n const checkSecond = useElementCheck(\n isDev &&\n ((element) =>\n popupRef.current !== null && popupRef.current !== element\n ? \"NavigationMenu.Popup: a second NavigationMenu.Popup mounted in the same Item. An \" +\n \"Item has one Trigger and one Popup; give each panel its own NavigationMenu.Item.\"\n : null),\n );\n const self = useRef<HTMLElement | null>(null);\n useEffect(() => {\n if (!isDev) return;\n const element = self.current;\n const trigger = triggerRef.current;\n if (element === null || trigger === null || element.previousElementSibling === trigger) return;\n console.error(\n \"NavigationMenu.Popup: the Popup does not directly follow its NavigationMenu.Trigger. \" +\n \"Render the Popup immediately after the Trigger: Safari puts a popover's content after \" +\n \"its invoker in the Tab order only when the two are adjacent.\",\n );\n }, [triggerRef]);\n\n const placement = useAnchoredPlacement({ side: sideProp, align: alignProp });\n const { side, align } = placement;\n const ref = useMergedRefs<HTMLElement>(checkSecond, setElement, placement.ref, self);\n\n const state: NavigationMenuPopupState = { open: ctx.committed, side, align };\n\n const content = (s: NavigationMenuPopupState): ReactNode => (\n <NavigationMenuPopupContext value={ctx}>\n {renderContent(() => resolveStateValue(children, s))}\n </NavigationMenuPopupContext>\n );\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ids.popup,\n popover: \"auto\",\n // Not owned with `side={null}`: the stylesheet (or a render element) may set them.\n ...placement.dataAttributes,\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, NavigationMenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The consumer's style wins over the inline placement.\n style: placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"NavigationMenu.Popup\", isLibrary ? transition : undefined, element);\n}\n\nNavigationMenuPopup.displayName = \"NavigationMenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAoFvC,MAAM,iBAAoC,CAAC,KAAK;;;;;;;;;;;;;;;;;;AAmBhD,SAAgB,oBAAoB,EAClC,MAAM,WAAW,UACjB,OAAO,YAAY,SACnB,aACA,YACA,WACA,OACA,UACA,QACA,GAAG,QACwB;CAC3B,MAAM,MAAM,6BAA6B,sBAAsB;CAC/D,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,KAAK,UAAU,eAAe;CAEtC,sBAAsB,wBAAwB,SAAS,WAAW,YAAY,WAAW;CAEzF,MAAM,EAAE,YAAY,kBAAkB,gBAAgB,KAAK;EACzD,MAAM;EACN;EACA,YAAY,YAAY,aAAa,KAAA;EACrC,UAAU;EAKV,YAAY;CACd,CAAC;CAID,MAAM,cAAc,gBAClB,WACI,YACA,SAAS,YAAY,QAAQ,SAAS,YAAY,UAC9C,sKAEA,KACV;CACA,MAAM,OAAO,OAA2B,IAAI;CAC5C,gBAAgB;EACd,IAAI,CAAC,OAAO;EACZ,MAAM,UAAU,KAAK;EACrB,MAAM,UAAU,WAAW;EAC3B,IAAI,YAAY,QAAQ,YAAY,QAAQ,QAAQ,2BAA2B,SAAS;EACxF,QAAQ,MACN,yOAGF;CACF,GAAG,CAAC,UAAU,CAAC;CAEf,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAU,OAAO;CAAU,CAAC;CAC3E,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,MAAM,cAA2B,aAAa,YAAY,UAAU,KAAK,IAAI;CAEnF,MAAM,QAAkC;EAAE,MAAM,IAAI;EAAW;EAAM;CAAM;CAE3E,MAAM,WAAW,MACf,oBAAC,4BAAD;EAA4B,OAAO;EAChC,UAAA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC;CACzB,CAAA;CAG9B,MAAM,eAA8D;EAClE,IAAI,IAAI;EACR,SAAS;EAET,GAAG,UAAU;CACf;CAEA,MAAM,UAAU,UAAkE;EAChF,gBAAgB;EAChB;EACA;EACA;EAEA,OAAO,UAAU,MAAM,KAAK;EAC5B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,wBAAwB,YAAY,aAAa,KAAA,GAAW,OAAO;AAClG;AAEA,oBAAoB,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-root.d.ts
|
|
4
|
+
/** `NavigationMenu.Root` has no state. */
|
|
5
|
+
export type NavigationMenuRootState = Record<string, never>;
|
|
6
|
+
/**
|
|
7
|
+
* Props of `NavigationMenu.Root`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
10
|
+
*/
|
|
11
|
+
export interface NavigationMenuRootProps extends Omit<ComponentPropsWithRef<"nav">, "className" | "style" | "children"> {
|
|
12
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
13
|
+
className?: StateValue<string | undefined, NavigationMenuRootState>;
|
|
14
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
15
|
+
style?: StateValue<CSSProperties | undefined, NavigationMenuRootState>;
|
|
16
|
+
/** Content: a `NavigationMenu.List`. */
|
|
17
|
+
children?: StateValue<ReactNode, NavigationMenuRootState>;
|
|
18
|
+
/** Replace the default `<nav>` (element form) or take over rendering (function form). */
|
|
19
|
+
render?: RenderProp<ComponentPropsWithRef<"nav">, NavigationMenuRootState>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The navigation landmark: a `<nav>`. Structure only, with no state and no owned keys. Name it
|
|
23
|
+
* with `aria-label` (or `aria-labelledby`) when the page has more than one `nav`.
|
|
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 NavigationMenuRoot({ className, style, children, render, ref, ...rest }: NavigationMenuRootProps): ReactNode;
|
|
29
|
+
export declare namespace NavigationMenuRoot {
|
|
30
|
+
var displayName: string;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//# sourceMappingURL=navigation-menu-root.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-root.d.mts","names":[],"sources":["../../src/navigation-menu/navigation-menu-root.tsx"],"mappings":";;;;YAQY,0BAA0B;;;;;;iBASrB,gCAAgC,KAC/C;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;wBAUpC,qBACd,WACA,OACA,UACA,QACA,QACG,QACF,0BAAuB;yBAPV"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mergeRenderRef, renderElement } from "../internal/render-element.mjs";
|
|
2
|
+
//#region src/navigation-menu/navigation-menu-root.tsx
|
|
3
|
+
const EMPTY = {};
|
|
4
|
+
/**
|
|
5
|
+
* The navigation landmark: a `<nav>`. Structure only, with no state and no owned keys. Name it
|
|
6
|
+
* with `aria-label` (or `aria-labelledby`) when the page has more than one `nav`.
|
|
7
|
+
* Directive-free, so a Server Component may render it.
|
|
8
|
+
*
|
|
9
|
+
* @see https://ui.funstack.work/components/navigation-menu
|
|
10
|
+
*/
|
|
11
|
+
function NavigationMenuRoot({ className, style, children, render, ref, ...rest }) {
|
|
12
|
+
return renderElement({
|
|
13
|
+
defaultElement: "nav",
|
|
14
|
+
render,
|
|
15
|
+
state: EMPTY,
|
|
16
|
+
className,
|
|
17
|
+
style,
|
|
18
|
+
children,
|
|
19
|
+
props: rest,
|
|
20
|
+
ref: mergeRenderRef(ref, render)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
NavigationMenuRoot.displayName = "NavigationMenuRoot";
|
|
24
|
+
//#endregion
|
|
25
|
+
export { NavigationMenuRoot };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=navigation-menu-root.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-menu-root.mjs","names":[],"sources":["../../src/navigation-menu/navigation-menu-root.tsx"],"sourcesContent":["// No \"use client\": `NavigationMenu.Root` reads no context and calls no hook, so a Server\n// Component may render it and it runs once, on the server (design/components/navigation-menu.md\n// 8). It must not import from any \"use client\" module (checked by src/__tests__/directives.test.ts).\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { mergeRenderRef, renderElement } from \"../internal/render-element.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\n\n/** `NavigationMenu.Root` has no state. */\nexport type NavigationMenuRootState = Record<string, never>;\n\nconst EMPTY: Record<string, never> = {};\n\n/**\n * Props of `NavigationMenu.Root`.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport interface NavigationMenuRootProps extends Omit<\n ComponentPropsWithRef<\"nav\">,\n \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, NavigationMenuRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NavigationMenuRootState>;\n /** Content: a `NavigationMenu.List`. */\n children?: StateValue<ReactNode, NavigationMenuRootState>;\n /** Replace the default `<nav>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"nav\">, NavigationMenuRootState>;\n}\n\n/**\n * The navigation landmark: a `<nav>`. Structure only, with no state and no owned keys. Name it\n * with `aria-label` (or `aria-labelledby`) when the page has more than one `nav`.\n * Directive-free, so a Server Component may render it.\n *\n * @see https://ui.funstack.work/components/navigation-menu\n */\nexport function NavigationMenuRoot({\n className,\n style,\n children,\n render,\n ref,\n ...rest\n}: NavigationMenuRootProps) {\n return renderElement<ComponentPropsWithRef<\"nav\">, NavigationMenuRootState>({\n defaultElement: \"nav\",\n render,\n state: EMPTY,\n className,\n style,\n children,\n props: rest,\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\nNavigationMenuRoot.displayName = \"NavigationMenuRoot\";\n"],"mappings":";;AAUA,MAAM,QAA+B,CAAC;;;;;;;;AA4BtC,SAAgB,mBAAmB,EACjC,WACA,OACA,UACA,QACA,KACA,GAAG,QACuB;CAC1B,OAAO,cAAqE;EAC1E,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EAGP,KAAK,eAAe,KAAK,MAAM;CACjC,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|