menhir 0.1.3 → 0.1.4

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.
Files changed (62) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +8 -1
  3. package/dist/core/createControllableSignal.js +11 -2
  4. package/dist/core/listValue.js +2 -7
  5. package/dist/floating/dismissal/escape.js +2 -1
  6. package/dist/floating/list-navigation/activeDescendant.js +29 -0
  7. package/dist/floating/list-navigation/listNavigation.js +108 -0
  8. package/dist/floating/list-navigation/roving.js +27 -0
  9. package/dist/floating/typeahead/match.js +24 -0
  10. package/dist/floating/typeahead/typeahead.js +56 -0
  11. package/dist/navigation-menu/index.js +2 -0
  12. package/dist/navigation-menu/index.parts.js +6 -0
  13. package/dist/navigation-menu/item/NavigationMenuItem.js +83 -0
  14. package/dist/navigation-menu/item/NavigationMenuItemContext.js +10 -0
  15. package/dist/navigation-menu/link/NavigationMenuLink.js +26 -0
  16. package/dist/navigation-menu/panel/NavigationMenuPanel.js +31 -0
  17. package/dist/navigation-menu/root/NavigationMenuRoot.js +100 -0
  18. package/dist/navigation-menu/root/NavigationMenuRootContext.js +10 -0
  19. package/dist/navigation-menu/trigger/NavigationMenuTrigger.js +36 -0
  20. package/dist/source/core/createControllableSignal.d.ts +9 -1
  21. package/dist/source/core/createControllableSignal.js +7 -2
  22. package/dist/source/core/listValue.js +4 -10
  23. package/dist/source/floating/dismissal/escape.d.ts +2 -1
  24. package/dist/source/floating/dismissal/escape.js +2 -1
  25. package/dist/source/floating/dismissal/reason.d.ts +5 -1
  26. package/dist/source/floating/list-navigation/activeDescendant.d.ts +30 -0
  27. package/dist/source/floating/list-navigation/activeDescendant.js +24 -0
  28. package/dist/source/floating/list-navigation/listNavigation.d.ts +68 -0
  29. package/dist/source/floating/list-navigation/listNavigation.js +148 -0
  30. package/dist/source/floating/list-navigation/roving.d.ts +23 -0
  31. package/dist/source/floating/list-navigation/roving.js +25 -0
  32. package/dist/source/floating/typeahead/match.d.ts +14 -0
  33. package/dist/source/floating/typeahead/match.js +32 -0
  34. package/dist/source/floating/typeahead/typeahead.d.ts +41 -0
  35. package/dist/source/floating/typeahead/typeahead.js +81 -0
  36. package/dist/source/navigation-menu/index.d.ts +1 -0
  37. package/dist/source/navigation-menu/index.js +1 -0
  38. package/dist/source/navigation-menu/index.parts.d.ts +5 -0
  39. package/dist/source/navigation-menu/index.parts.js +5 -0
  40. package/dist/source/navigation-menu/item/NavigationMenuItem.d.ts +16 -0
  41. package/dist/source/navigation-menu/item/NavigationMenuItem.jsx +85 -0
  42. package/dist/source/navigation-menu/item/NavigationMenuItemContext.d.ts +27 -0
  43. package/dist/source/navigation-menu/item/NavigationMenuItemContext.js +12 -0
  44. package/dist/source/navigation-menu/link/NavigationMenuLink.d.ts +12 -0
  45. package/dist/source/navigation-menu/link/NavigationMenuLink.jsx +18 -0
  46. package/dist/source/navigation-menu/panel/NavigationMenuPanel.d.ts +11 -0
  47. package/dist/source/navigation-menu/panel/NavigationMenuPanel.jsx +26 -0
  48. package/dist/source/navigation-menu/root/NavigationMenuRoot.d.ts +37 -0
  49. package/dist/source/navigation-menu/root/NavigationMenuRoot.jsx +103 -0
  50. package/dist/source/navigation-menu/root/NavigationMenuRootContext.d.ts +33 -0
  51. package/dist/source/navigation-menu/root/NavigationMenuRootContext.js +13 -0
  52. package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.d.ts +12 -0
  53. package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.jsx +32 -0
  54. package/package.json +8 -2
  55. package/skills/menhir-styling/SKILL.md +35 -0
  56. package/skills/menhir-styling/looks/shadcn/LICENSE +24 -0
  57. package/skills/menhir-styling/looks/shadcn/LOOK.md +106 -0
  58. package/skills/menhir-styling/looks/shadcn/dialog.md +63 -0
  59. package/skills/menhir-styling/looks/shadcn/popover.md +39 -0
  60. package/skills/menhir-styling/looks/shadcn/switch.md +26 -0
  61. package/skills/menhir-styling/looks/shadcn/tabs.md +62 -0
  62. package/skills/menhir-styling/looks/shadcn/tokens.css +80 -0
@@ -0,0 +1,5 @@
1
+ export { NavigationMenuRoot as Root } from "./root/NavigationMenuRoot.tsx";
2
+ export { NavigationMenuItem as Item } from "./item/NavigationMenuItem.tsx";
3
+ export { NavigationMenuTrigger as Trigger } from "./trigger/NavigationMenuTrigger.tsx";
4
+ export { NavigationMenuPanel as Panel } from "./panel/NavigationMenuPanel.tsx";
5
+ export { NavigationMenuLink as Link } from "./link/NavigationMenuLink.tsx";
@@ -0,0 +1,5 @@
1
+ export { NavigationMenuRoot as Root } from "./root/NavigationMenuRoot.jsx";
2
+ export { NavigationMenuItem as Item } from "./item/NavigationMenuItem.jsx";
3
+ export { NavigationMenuTrigger as Trigger } from "./trigger/NavigationMenuTrigger.jsx";
4
+ export { NavigationMenuPanel as Panel } from "./panel/NavigationMenuPanel.jsx";
5
+ export { NavigationMenuLink as Link } from "./link/NavigationMenuLink.jsx";
@@ -0,0 +1,16 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface NavigationMenuItemProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /**
5
+ * Identifies the Item in the Root's value. Without one, the Item uses a
6
+ * generated value, which no other code knows.
7
+ */
8
+ value?: string;
9
+ render?: RenderProp;
10
+ }
11
+ /**
12
+ * One entry of the bar: an `<li>` around a `NavigationMenu.Trigger` and its
13
+ * `NavigationMenu.Panel`. Place it inside `NavigationMenu.Root`, in the
14
+ * `<ul>` of the bar.
15
+ */
16
+ export declare function NavigationMenuItem(props: NavigationMenuItemProps): JSX.Element;
@@ -0,0 +1,85 @@
1
+ import { createUniqueId, merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { createEscape } from "../../floating/dismissal/escape.js";
5
+ import { createHover } from "../../floating/hover/hover.js";
6
+ import { useNavigationMenuRootContext } from "../root/NavigationMenuRootContext.js";
7
+ import { NavigationMenuItemContext } from "./NavigationMenuItemContext.js";
8
+ /**
9
+ * One entry of the bar: an `<li>` around a `NavigationMenu.Trigger` and its
10
+ * `NavigationMenu.Panel`. Place it inside `NavigationMenu.Root`, in the
11
+ * `<ul>` of the bar.
12
+ */
13
+ export function NavigationMenuItem(props) {
14
+ const root = useNavigationMenuRootContext("Item");
15
+ const panelId = createUniqueId();
16
+ // Without a value, the Panel's id serves as one, as on an Accordion Item.
17
+ const value = () => props.value ?? panelId;
18
+ const open = () => root.value() === value();
19
+ const attributes = {
20
+ get "data-open"() {
21
+ return open() ? "" : undefined;
22
+ },
23
+ get "data-closed"() {
24
+ return open() ? undefined : "";
25
+ },
26
+ };
27
+ const context = {
28
+ open,
29
+ toggle: (event) => root.toggle(value(), event),
30
+ panelId,
31
+ trigger: undefined,
32
+ panel: undefined,
33
+ attributes,
34
+ };
35
+ let element;
36
+ createHover({
37
+ get trigger() {
38
+ return context.trigger;
39
+ },
40
+ get popup() {
41
+ return context.panel;
42
+ },
43
+ get open() {
44
+ return open();
45
+ },
46
+ // Read as the pointer enters: 0 while another Item is open (README,
47
+ // "Moving along the bar").
48
+ get delay() {
49
+ return root.hoverDelay();
50
+ },
51
+ get closeDelay() {
52
+ return root.closeDelay();
53
+ },
54
+ // A Panel that holds focus stays open when the pointer leaves: closing
55
+ // it would drop focus to the page. One a press opened stays open too
56
+ // (`hoverClose`).
57
+ onOpenChange: (next, details) => {
58
+ if (next)
59
+ root.hoverOpen(value(), details);
60
+ else if (!context.panel?.contains(document.activeElement))
61
+ root.hoverClose(value(), details);
62
+ },
63
+ });
64
+ createEscape({
65
+ get open() {
66
+ return open();
67
+ },
68
+ onDismiss: (details) => {
69
+ // As the example does: focus inside the Item goes back to its
70
+ // Trigger, which stays in the page; focus elsewhere stays there.
71
+ if (element?.contains(document.activeElement))
72
+ context.trigger?.focus();
73
+ root.close(details);
74
+ },
75
+ });
76
+ const ownProps = merge(attributes, {
77
+ ref: (el) => {
78
+ element = el;
79
+ },
80
+ });
81
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value"));
82
+ return (<NavigationMenuItemContext value={context}>
83
+ {renderElement(props, elementProps, (p) => (<li {...p}/>))}
84
+ </NavigationMenuItemContext>);
85
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * An Item's state as `data-*` attributes, each `""` when it applies and
3
+ * absent otherwise: one of `data-open` and `data-closed`. Every part of the
4
+ * Item merges the same object, so its getters are read where each element
5
+ * uses them.
6
+ */
7
+ export type NavigationMenuItemStateAttributes = {
8
+ readonly "data-open": "" | undefined;
9
+ readonly "data-closed": "" | undefined;
10
+ };
11
+ /** What an Item shares with its Trigger and Panel. */
12
+ export interface NavigationMenuItemContextValue {
13
+ /** Whether the Panel is shown. */
14
+ open(): boolean;
15
+ /** Asks to open or close the Panel by a press on the Trigger. */
16
+ toggle(event: MouseEvent): void;
17
+ /** The Panel's `id`, which the Trigger names in `aria-controls`. */
18
+ readonly panelId: string;
19
+ /** The Trigger's element, once rendered. */
20
+ trigger: HTMLElement | undefined;
21
+ /** The Panel's element, once rendered. */
22
+ panel: HTMLElement | undefined;
23
+ /** The `data-*` attributes every part of the Item carries. */
24
+ readonly attributes: NavigationMenuItemStateAttributes;
25
+ }
26
+ export declare const NavigationMenuItemContext: import("solid-js").Context<NavigationMenuItemContextValue | null>;
27
+ export declare function useNavigationMenuItemContext(): NavigationMenuItemContextValue;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ // `null` outside an Item, so that the part can name what is missing.
4
+ export const NavigationMenuItemContext = createContext(null);
5
+ export function useNavigationMenuItemContext() {
6
+ const context = useContext(NavigationMenuItemContext);
7
+ // Production builds drop the check, and its message, with `isDev`.
8
+ if (isDev && !context) {
9
+ throw new Error("[menhir] NavigationMenu.Trigger and NavigationMenu.Panel must be placed within <NavigationMenu.Item>.");
10
+ }
11
+ return context;
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface NavigationMenuLinkProps extends JSX.HTMLAttributes<HTMLElement>, Pick<JSX.AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "target" | "rel" | "download" | "hreflang" | "ping" | "referrerpolicy" | "type"> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * A link of the navigation: an `<a>` that closes the open Panel when it is
8
+ * activated, by pointer or by Enter, so a router's page change leaves no
9
+ * menu open. Pass `href`, and `aria-current="page"` on the current page's
10
+ * link. Place it anywhere inside `NavigationMenu.Root`.
11
+ */
12
+ export declare function NavigationMenuLink(props: NavigationMenuLinkProps): JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useNavigationMenuRootContext } from "../root/NavigationMenuRootContext.js";
5
+ /**
6
+ * A link of the navigation: an `<a>` that closes the open Panel when it is
7
+ * activated, by pointer or by Enter, so a router's page change leaves no
8
+ * menu open. Pass `href`, and `aria-current="page"` on the current page's
9
+ * link. Place it anywhere inside `NavigationMenu.Root`.
10
+ */
11
+ export function NavigationMenuLink(props) {
12
+ const root = useNavigationMenuRootContext("Link");
13
+ const ownProps = {
14
+ onClick: (event) => root.close({ reason: "link-press", event }),
15
+ };
16
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
17
+ return renderElement(props, elementProps, (p) => <a {...p}/>);
18
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface NavigationMenuPanelProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "id"> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The links its Item's Trigger shows and hides: a `<div>` in the page's
8
+ * flow, `hidden` while closed, which your CSS places under the Item. Place
9
+ * it inside `NavigationMenu.Item`, after `NavigationMenu.Trigger`.
10
+ */
11
+ export declare function NavigationMenuPanel(props: NavigationMenuPanelProps): JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useNavigationMenuItemContext } from "../item/NavigationMenuItemContext.js";
5
+ /**
6
+ * The links its Item's Trigger shows and hides: a `<div>` in the page's
7
+ * flow, `hidden` while closed, which your CSS places under the Item. Place
8
+ * it inside `NavigationMenu.Item`, after `NavigationMenu.Trigger`.
9
+ */
10
+ export function NavigationMenuPanel(props) {
11
+ const item = useNavigationMenuItemContext();
12
+ const ownProps = merge(item.attributes, {
13
+ id: item.panelId,
14
+ get hidden() {
15
+ return !item.open();
16
+ },
17
+ ref: (element) => {
18
+ item.panel = element;
19
+ },
20
+ });
21
+ const elementProps = mergeElementProps(ownProps,
22
+ // An `id` from untyped code would break the Trigger's `aria-controls`,
23
+ // so it is dropped too.
24
+ omit(props, "render", "id"));
25
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
26
+ }
@@ -0,0 +1,37 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
4
+ export interface NavigationMenuRootProps extends JSX.HTMLAttributes<HTMLElement> {
5
+ /** The open Item's value, `null` when none is open, when controlled. */
6
+ value?: string | null;
7
+ /** The value of the Item open at first, when uncontrolled. */
8
+ defaultValue?: string | null;
9
+ /**
10
+ * Called with the new value, and why, when the user opens or closes an
11
+ * Item. When controlled, the menu changes only if `value` does.
12
+ */
13
+ onValueChange?: (value: string | null, details: OpenChangeDetails) => void;
14
+ /**
15
+ * How long the pointer rests on a Trigger before its Panel opens, in
16
+ * milliseconds. Default 300. While an Item is open, or within `timeout`
17
+ * of the last close, the next opens at once.
18
+ */
19
+ delay?: number;
20
+ /**
21
+ * How long after the pointer has left a Trigger and its Panel the Panel
22
+ * closes, in milliseconds. Default 200.
23
+ */
24
+ closeDelay?: number;
25
+ /**
26
+ * How long after the last close hovering a Trigger still opens its Panel
27
+ * at once, in milliseconds. Default 400.
28
+ */
29
+ timeout?: number;
30
+ render?: RenderProp;
31
+ }
32
+ /**
33
+ * A site's navigation: a `<nav>` that holds which `NavigationMenu.Item` is
34
+ * open, one at a time. Focus moving out of it, and a press outside it,
35
+ * close the open Item.
36
+ */
37
+ export declare function NavigationMenuRoot(props: NavigationMenuRootProps): JSX.Element;
@@ -0,0 +1,103 @@
1
+ import { createEffect, omit } from "solid-js";
2
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.jsx";
5
+ import { NavigationMenuRootContext } from "./NavigationMenuRootContext.js";
6
+ /**
7
+ * A site's navigation: a `<nav>` that holds which `NavigationMenu.Item` is
8
+ * open, one at a time. Focus moving out of it, and a press outside it,
9
+ * close the open Item.
10
+ */
11
+ export function NavigationMenuRoot(props) {
12
+ // `requested` counts a change asked for earlier in the same turn, which
13
+ // `value` shows only after the flush: two pointer events of one move may
14
+ // ask twice.
15
+ const [value, setValue, requested] = createControllableSignal({
16
+ get value() {
17
+ return props.value;
18
+ },
19
+ get defaultValue() {
20
+ return props.defaultValue ?? null;
21
+ },
22
+ onChange: (next, details) => props.onValueChange?.(next, details),
23
+ });
24
+ // The Item a press opened, whose Panel hover does not close (README,
25
+ // "Decisions").
26
+ let pressedItem = null;
27
+ // When an Item last closed, for `timeout`.
28
+ let closedAt = -Infinity;
29
+ const set = (next, details) => {
30
+ if (next === null && requested() !== null)
31
+ closedAt = Date.now();
32
+ pressedItem = null;
33
+ setValue(next, details);
34
+ };
35
+ const close = (details) => set(null, details);
36
+ let nav;
37
+ const inside = (target) => !!target && !!nav?.contains(target);
38
+ // Whether a primary press started outside and has not ended in a `click`
39
+ // or been cancelled yet. Focus that such a press moves out of the `<nav>`
40
+ // is left to the press, so it closes on release as `outside-press`.
41
+ let pressOutside = false;
42
+ // A press outside closes on release, the `click` of a press that also
43
+ // started outside, so a text selection dragged out of a Panel, a
44
+ // secondary button and a key's `click` close nothing (README).
45
+ createEffect(() => value() !== null, (open) => {
46
+ if (!open)
47
+ return;
48
+ const down = (event) => {
49
+ pressOutside = event.button === 0 && !inside(event.target);
50
+ };
51
+ const cancel = () => {
52
+ pressOutside = false;
53
+ };
54
+ const click = (event) => {
55
+ if (pressOutside && !inside(event.target))
56
+ close({ reason: "outside-press", event });
57
+ pressOutside = false;
58
+ };
59
+ document.addEventListener("pointerdown", down, true);
60
+ document.addEventListener("pointercancel", cancel, true);
61
+ document.addEventListener("click", click, true);
62
+ return () => {
63
+ cancel();
64
+ document.removeEventListener("pointerdown", down, true);
65
+ document.removeEventListener("pointercancel", cancel, true);
66
+ document.removeEventListener("click", click, true);
67
+ };
68
+ });
69
+ const context = {
70
+ value,
71
+ toggle: (item, event) => {
72
+ const next = requested() === item ? null : item;
73
+ set(next, { reason: "trigger-press", event });
74
+ pressedItem = next;
75
+ },
76
+ hoverOpen: set,
77
+ hoverClose: (item, details) => {
78
+ if (requested() === item && pressedItem !== item)
79
+ close(details);
80
+ },
81
+ close,
82
+ hoverDelay: () => requested() !== null || Date.now() - closedAt < (props.timeout ?? 400)
83
+ ? 0
84
+ : (props.delay ?? 300),
85
+ closeDelay: () => props.closeDelay ?? 200,
86
+ };
87
+ const ownProps = {
88
+ // Focus moving to an element outside closes; focus lost to nothing,
89
+ // such as the window's, does not, and focus that a press outside moves
90
+ // closes on its release (README, "Decisions").
91
+ onFocusOut: (event) => {
92
+ if (event.relatedTarget && !inside(event.relatedTarget) && !pressOutside)
93
+ close({ reason: "focus-out", event });
94
+ },
95
+ ref: (element) => {
96
+ nav = element;
97
+ },
98
+ };
99
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "delay", "closeDelay", "timeout"));
100
+ return (<NavigationMenuRootContext value={context}>
101
+ {renderElement(props, elementProps, (p) => (<nav {...p}/>))}
102
+ </NavigationMenuRootContext>);
103
+ }
@@ -0,0 +1,33 @@
1
+ import type { OpenChangeDetails } from "../../floating/dismissal/reason.ts";
2
+ /** What the Root shares with its Items and Links. */
3
+ export interface NavigationMenuRootContextValue {
4
+ /** The open Item's value, `null` when none is open. */
5
+ value(): string | null;
6
+ /**
7
+ * A press on the Item's Trigger: opens it, to stay open when the pointer
8
+ * leaves, or closes it if it is open, counting a change asked for earlier
9
+ * in the same turn.
10
+ */
11
+ toggle(item: string, event: MouseEvent): void;
12
+ /** Hover asking to open the Item, closing any other. */
13
+ hoverOpen(item: string, details: OpenChangeDetails): void;
14
+ /**
15
+ * Hover asking to close the Item, which closes it only if it is the one
16
+ * open, counting a change asked for earlier in the same turn, and a press
17
+ * did not open it: hover's close of the Item the pointer left must not
18
+ * undo the opening of the next.
19
+ */
20
+ hoverClose(item: string, details: OpenChangeDetails): void;
21
+ /** Asks to close whichever Item is open, saying why. */
22
+ close(details: OpenChangeDetails): void;
23
+ /**
24
+ * How long the pointer rests on a Trigger it has just entered before its
25
+ * Panel opens: 0 while an Item is open or within `timeout` of the last
26
+ * close, else the Root's `delay`.
27
+ */
28
+ hoverDelay(): number;
29
+ /** The Root's `closeDelay`. */
30
+ closeDelay(): number;
31
+ }
32
+ export declare const NavigationMenuRootContext: import("solid-js").Context<NavigationMenuRootContextValue | null>;
33
+ export declare function useNavigationMenuRootContext(part: string): NavigationMenuRootContextValue;
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from "solid-js";
2
+ import { isDev } from "@solidjs/web";
3
+ // `null` outside a Root, so that the part can name what is missing. Solid's
4
+ // own error for a context with no provider and no default does not.
5
+ export const NavigationMenuRootContext = createContext(null);
6
+ export function useNavigationMenuRootContext(part) {
7
+ const context = useContext(NavigationMenuRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error(`[menhir] NavigationMenu.${part} must be placed within <NavigationMenu.Root>.`);
11
+ }
12
+ return context;
13
+ }
@@ -0,0 +1,12 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface NavigationMenuTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that shows and hides its Item's Panel: a
8
+ * `<button type="button" aria-expanded>`. A press toggles the Panel, and
9
+ * the pointer resting on it opens it. Place it inside
10
+ * `NavigationMenu.Item`, before `NavigationMenu.Panel`.
11
+ */
12
+ export declare function NavigationMenuTrigger(props: NavigationMenuTriggerProps): JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { merge, omit } from "solid-js";
3
+ import { warnUnlessButton } from "../../core/button.js";
4
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
5
+ import { renderElement } from "../../core/renderElement.jsx";
6
+ import { useNavigationMenuItemContext } from "../item/NavigationMenuItemContext.js";
7
+ /**
8
+ * The button that shows and hides its Item's Panel: a
9
+ * `<button type="button" aria-expanded>`. A press toggles the Panel, and
10
+ * the pointer resting on it opens it. Place it inside
11
+ * `NavigationMenu.Item`, before `NavigationMenu.Panel`.
12
+ */
13
+ export function NavigationMenuTrigger(props) {
14
+ const item = useNavigationMenuItemContext();
15
+ const ownProps = merge(item.attributes, {
16
+ type: "button",
17
+ // Solid 2.0 removes an attribute set to false, so spell the value out.
18
+ get "aria-expanded"() {
19
+ return item.open() ? "true" : "false";
20
+ },
21
+ "aria-controls": item.panelId,
22
+ onClick: (event) => item.toggle(event),
23
+ ref: (element) => {
24
+ item.trigger = element;
25
+ // Production builds drop the check with `isDev`.
26
+ if (isDev)
27
+ warnUnlessButton(element, "NavigationMenu.Trigger");
28
+ },
29
+ });
30
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
31
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "menhir",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Unstyled, accessible UI primitives for SolidJS 2.0, with small and measurable bundles",
5
5
  "keywords": [
6
6
  "solid",
@@ -64,6 +64,11 @@
64
64
  "solid": "./dist/source/meter/index.js",
65
65
  "import": "./dist/meter/index.js"
66
66
  },
67
+ "./navigation-menu": {
68
+ "types": "./dist/source/navigation-menu/index.d.ts",
69
+ "solid": "./dist/source/navigation-menu/index.js",
70
+ "import": "./dist/navigation-menu/index.js"
71
+ },
67
72
  "./popover": {
68
73
  "types": "./dist/source/popover/index.d.ts",
69
74
  "solid": "./dist/source/popover/index.js",
@@ -117,7 +122,8 @@
117
122
  "./package.json": "./package.json"
118
123
  },
119
124
  "files": [
120
- "dist"
125
+ "dist",
126
+ "skills"
121
127
  ],
122
128
  "imports": {
123
129
  "#test-utils": "./test/index.ts"
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: menhir-styling
3
+ description: Style Menhir components (the `menhir` package for SolidJS) in one consistent look, such as the shadcn look, or a look the user describes or shows. Use when adding styles to a Menhir component, or giving an app's Menhir components a look.
4
+ ---
5
+
6
+ # Styling Menhir components
7
+
8
+ Menhir's components are unstyled: each part exposes its state as data attributes for CSS to select. A **look** is a complete visual style for them: tokens (colours and radii), recipes for every kind of part, and worked examples built from both. Every component styled in a look uses that look's tokens and recipes, so components styled weeks apart still match.
9
+
10
+ ## Looks
11
+
12
+ | Look | Styling | Worked examples |
13
+ | ------------------------------ | --------------- | ----------------------------- |
14
+ | [shadcn](looks/shadcn/LOOK.md) | Tailwind CSS v4 | Switch, Dialog, Tabs, Popover |
15
+
16
+ Each look's `LOOK.md` has its setup, what each token is for, its recipes, and the list of worked examples. When the app is styled with the other technology, translate the look's classes into it, token for token.
17
+
18
+ ## Steps
19
+
20
+ 1. **Choose the look.** The one the user names, or the one the app already has: look for `data-look` and a look's `tokens.css` in the app. For a look the user describes or shows (a screenshot, a site, an existing design system), write its tokens first: copy the closest look's `tokens.css`, keep the token names, change the values. That look's recipes and worked examples then carry over. Done when the app has one tokens file for the look.
21
+ 2. **Set up the look**, once per app, as its `LOOK.md` says. A look's tokens apply only inside its `data-look` attribute, and switch between light and dark with the CSS `color-scheme`, which the app sets from Menhir's color-scheme utility (`menhir/color-scheme/local-storage` or `/cookie`) or from the system. Done when the tokens apply where the components render, in light and dark.
22
+ 3. **Style each component.** Read its parts and data attributes first, from its Markdown page, `https://menhir-ui.com/docs/components/<name>.md` (all of them are listed in `https://menhir-ui.com/llms.txt`); the types in `node_modules/menhir/dist/source/<name>/` are the installed version's. When the look has a worked example of it, start from that and change only the content. Otherwise build it from the look's recipes, taking their classes as written, and its nearest worked example: a control from Switch, a popup from Popover or Dialog, a composite from Tabs. Where no recipe covers a part, say so in your reply, with the classes you chose. Done when every part the app renders has its classes, every colour and radius comes from a token, and sizes, spacing and shadows come from the look's recipes.
23
+ 4. **Check it in the browser.** For each component: its states (on and off, selected, disabled), open and close animations, keyboard focus on every interactive part, text contrast against its background, and the same again in the dark color scheme. Done when each one looks like the look's worked examples in both color schemes.
24
+
25
+ ## Menhir's contract
26
+
27
+ What holds for every component, and so is on no single component's page. A component's parts, props and data attributes are on its Markdown page only: read them there.
28
+
29
+ - **State is in data attributes**, present or absent, such as `data-checked` and `data-unchecked`; the component's page lists each part's. In Tailwind: `data-checked:bg-primary`.
30
+ - **Focus** is `:focus-visible` (`focus-visible:` in Tailwind). There is no focus attribute.
31
+ - **`class` and `style` merge** with the part's own. A part's `render` prop renders it through the app's own component.
32
+ - **Popups are in the top layer**: a Dialog's Popup is a modal `<dialog>`, a Popover's Popup is a `popover` element. They need no portal and no `z-index`. The browser hides them while closed with `display: none`, so a `display` class (`flex`, `grid`) goes on an inner wrapper, never on the Popup.
33
+ - **A Dialog's backdrop** is the browser's `::backdrop` (`backdrop:` in Tailwind), and `m-auto` centres the dialog.
34
+ - **Animation**: entry from `@starting-style` on `[data-open]` (`starting:data-open:`), exit to the `[data-closed]` styles: Menhir keeps a closing popup shown until its transition or animation ends. Guard motion with `prefers-reduced-motion` (`motion-reduce:transition-none`).
35
+ - **A positioned popup** (Popover, Tooltip) grows from its trigger: `origin-(--transform-origin)`. Its page lists its side and alignment attributes and its other CSS variables.
@@ -0,0 +1,24 @@
1
+ The shadcn look reproduces class strings and token values from shadcn/ui
2
+ (https://github.com/shadcn-ui/ui), under its licence:
3
+
4
+ MIT License
5
+
6
+ Copyright (c) 2023 shadcn
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.