menhir 0.1.3 → 0.1.5
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/LICENSE +6 -0
- package/README.md +9 -2
- package/dist/context-menu/index.js +2 -0
- package/dist/context-menu/index.parts.js +13 -0
- package/dist/context-menu/popup/ContextMenuPopup.js +30 -0
- package/dist/context-menu/root/ContextMenuContext.js +11 -0
- package/dist/context-menu/root/ContextMenuRoot.js +23 -0
- package/dist/context-menu/trigger/ContextMenuTrigger.js +47 -0
- package/dist/core/createControllableSignal.js +11 -2
- package/dist/core/listValue.js +2 -7
- package/dist/core/mergeElementProps.js +7 -1
- package/dist/floating/dismissal/escape.js +2 -1
- package/dist/floating/list-navigation/activeDescendant.js +29 -0
- package/dist/floating/list-navigation/listNavigation.js +108 -0
- package/dist/floating/list-navigation/roving.js +27 -0
- package/dist/floating/typeahead/match.js +24 -0
- package/dist/floating/typeahead/typeahead.js +56 -0
- package/dist/menu/checkbox-item/MenuCheckboxItem.js +28 -0
- package/dist/menu/group/MenuGroup.js +40 -0
- package/dist/menu/group/MenuGroupContext.js +10 -0
- package/dist/menu/group-label/MenuGroupLabel.js +27 -0
- package/dist/menu/index.js +2 -0
- package/dist/menu/index.parts.js +13 -0
- package/dist/menu/item/MenuItem.js +30 -0
- package/dist/menu/item/menuItemProps.js +77 -0
- package/dist/menu/item/renderCheckedItem.js +52 -0
- package/dist/menu/item-indicator/MenuItemIndicator.js +23 -0
- package/dist/menu/item-indicator/MenuItemIndicatorContext.js +10 -0
- package/dist/menu/popup/MenuPopup.js +123 -0
- package/dist/menu/radio-group/MenuRadioGroup.js +39 -0
- package/dist/menu/radio-item/MenuRadioItem.js +21 -0
- package/dist/menu/root/MenuContext.js +114 -0
- package/dist/menu/root/MenuRoot.js +19 -0
- package/dist/menu/submenu/MenuSubmenu.js +18 -0
- package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +114 -0
- package/dist/menu/trigger/MenuTrigger.js +67 -0
- package/dist/menubar/index.js +2 -0
- package/dist/menubar/index.parts.js +14 -0
- package/dist/menubar/menu/MenubarMenu.js +30 -0
- package/dist/menubar/root/MenubarContext.js +10 -0
- package/dist/menubar/root/MenubarRoot.js +68 -0
- package/dist/menubar/trigger/MenubarTrigger.js +73 -0
- package/dist/navigation-menu/index.js +2 -0
- package/dist/navigation-menu/index.parts.js +6 -0
- package/dist/navigation-menu/item/NavigationMenuItem.js +83 -0
- package/dist/navigation-menu/item/NavigationMenuItemContext.js +10 -0
- package/dist/navigation-menu/link/NavigationMenuLink.js +26 -0
- package/dist/navigation-menu/panel/NavigationMenuPanel.js +31 -0
- package/dist/navigation-menu/root/NavigationMenuRoot.js +100 -0
- package/dist/navigation-menu/root/NavigationMenuRootContext.js +10 -0
- package/dist/navigation-menu/trigger/NavigationMenuTrigger.js +36 -0
- package/dist/source/context-menu/index.d.ts +1 -0
- package/dist/source/context-menu/index.js +1 -0
- package/dist/source/context-menu/index.parts.d.ts +12 -0
- package/dist/source/context-menu/index.parts.js +13 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.d.ts +12 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.jsx +36 -0
- package/dist/source/context-menu/root/ContextMenuContext.d.ts +18 -0
- package/dist/source/context-menu/root/ContextMenuContext.js +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.d.ts +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.jsx +16 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.d.ts +15 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +46 -0
- package/dist/source/core/createControllableSignal.d.ts +9 -1
- package/dist/source/core/createControllableSignal.js +7 -2
- package/dist/source/core/listValue.js +4 -10
- package/dist/source/core/mergeElementProps.d.ts +8 -0
- package/dist/source/core/mergeElementProps.js +7 -1
- package/dist/source/floating/dismissal/escape.d.ts +2 -1
- package/dist/source/floating/dismissal/escape.js +2 -1
- package/dist/source/floating/dismissal/reason.d.ts +11 -2
- package/dist/source/floating/list-navigation/activeDescendant.d.ts +30 -0
- package/dist/source/floating/list-navigation/activeDescendant.js +24 -0
- package/dist/source/floating/list-navigation/listNavigation.d.ts +68 -0
- package/dist/source/floating/list-navigation/listNavigation.js +148 -0
- package/dist/source/floating/list-navigation/roving.d.ts +23 -0
- package/dist/source/floating/list-navigation/roving.js +25 -0
- package/dist/source/floating/typeahead/match.d.ts +14 -0
- package/dist/source/floating/typeahead/match.js +32 -0
- package/dist/source/floating/typeahead/typeahead.d.ts +41 -0
- package/dist/source/floating/typeahead/typeahead.js +81 -0
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.d.ts +20 -0
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.jsx +26 -0
- package/dist/source/menu/group/MenuGroup.d.ts +16 -0
- package/dist/source/menu/group/MenuGroup.jsx +31 -0
- package/dist/source/menu/group/MenuGroupContext.d.ts +10 -0
- package/dist/source/menu/group/MenuGroupContext.js +12 -0
- package/dist/source/menu/group-label/MenuGroupLabel.d.ts +11 -0
- package/dist/source/menu/group-label/MenuGroupLabel.jsx +25 -0
- package/dist/source/menu/index.d.ts +1 -0
- package/dist/source/menu/index.js +1 -0
- package/dist/source/menu/index.parts.d.ts +12 -0
- package/dist/source/menu/index.parts.js +12 -0
- package/dist/source/menu/item/MenuItem.d.ts +11 -0
- package/dist/source/menu/item/MenuItem.jsx +21 -0
- package/dist/source/menu/item/menuItemProps.d.ts +35 -0
- package/dist/source/menu/item/menuItemProps.js +78 -0
- package/dist/source/menu/item/renderCheckedItem.d.ts +22 -0
- package/dist/source/menu/item/renderCheckedItem.jsx +41 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.d.ts +12 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.jsx +17 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.d.ts +11 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.js +12 -0
- package/dist/source/menu/popup/MenuPopup.d.ts +41 -0
- package/dist/source/menu/popup/MenuPopup.jsx +156 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.d.ts +27 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.jsx +36 -0
- package/dist/source/menu/radio-item/MenuRadioItem.d.ts +14 -0
- package/dist/source/menu/radio-item/MenuRadioItem.jsx +19 -0
- package/dist/source/menu/root/MenuContext.d.ts +114 -0
- package/dist/source/menu/root/MenuContext.js +123 -0
- package/dist/source/menu/root/MenuRoot.d.ts +11 -0
- package/dist/source/menu/root/MenuRoot.jsx +9 -0
- package/dist/source/menu/submenu/MenuSubmenu.d.ts +22 -0
- package/dist/source/menu/submenu/MenuSubmenu.jsx +10 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.d.ts +14 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +121 -0
- package/dist/source/menu/trigger/MenuTrigger.d.ts +13 -0
- package/dist/source/menu/trigger/MenuTrigger.jsx +73 -0
- package/dist/source/menubar/index.d.ts +1 -0
- package/dist/source/menubar/index.js +1 -0
- package/dist/source/menubar/index.parts.d.ts +13 -0
- package/dist/source/menubar/index.parts.js +14 -0
- package/dist/source/menubar/menu/MenubarMenu.d.ts +11 -0
- package/dist/source/menubar/menu/MenubarMenu.jsx +24 -0
- package/dist/source/menubar/root/MenubarContext.d.ts +30 -0
- package/dist/source/menubar/root/MenubarContext.js +12 -0
- package/dist/source/menubar/root/MenubarRoot.d.ts +11 -0
- package/dist/source/menubar/root/MenubarRoot.jsx +77 -0
- package/dist/source/menubar/trigger/MenubarTrigger.d.ts +11 -0
- package/dist/source/menubar/trigger/MenubarTrigger.jsx +78 -0
- package/dist/source/navigation-menu/index.d.ts +1 -0
- package/dist/source/navigation-menu/index.js +1 -0
- package/dist/source/navigation-menu/index.parts.d.ts +5 -0
- package/dist/source/navigation-menu/index.parts.js +5 -0
- package/dist/source/navigation-menu/item/NavigationMenuItem.d.ts +16 -0
- package/dist/source/navigation-menu/item/NavigationMenuItem.jsx +85 -0
- package/dist/source/navigation-menu/item/NavigationMenuItemContext.d.ts +27 -0
- package/dist/source/navigation-menu/item/NavigationMenuItemContext.js +12 -0
- package/dist/source/navigation-menu/link/NavigationMenuLink.d.ts +12 -0
- package/dist/source/navigation-menu/link/NavigationMenuLink.jsx +18 -0
- package/dist/source/navigation-menu/panel/NavigationMenuPanel.d.ts +11 -0
- package/dist/source/navigation-menu/panel/NavigationMenuPanel.jsx +26 -0
- package/dist/source/navigation-menu/root/NavigationMenuRoot.d.ts +37 -0
- package/dist/source/navigation-menu/root/NavigationMenuRoot.jsx +103 -0
- package/dist/source/navigation-menu/root/NavigationMenuRootContext.d.ts +33 -0
- package/dist/source/navigation-menu/root/NavigationMenuRootContext.js +13 -0
- package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.d.ts +12 -0
- package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.jsx +32 -0
- package/package.json +23 -2
- package/skills/menhir-styling/SKILL.md +35 -0
- package/skills/menhir-styling/looks/shadcn/LICENSE +24 -0
- package/skills/menhir-styling/looks/shadcn/LOOK.md +106 -0
- package/skills/menhir-styling/looks/shadcn/dialog.md +63 -0
- package/skills/menhir-styling/looks/shadcn/popover.md +39 -0
- package/skills/menhir-styling/looks/shadcn/switch.md +26 -0
- package/skills/menhir-styling/looks/shadcn/tabs.md +62 -0
- package/skills/menhir-styling/looks/shadcn/tokens.css +80 -0
|
@@ -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
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Unstyled, accessible UI primitives for SolidJS 2.0, with small and measurable bundles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"solid",
|
|
@@ -54,16 +54,36 @@
|
|
|
54
54
|
"solid": "./dist/source/color-scheme/local-storage/index.js",
|
|
55
55
|
"import": "./dist/color-scheme/local-storage/index.js"
|
|
56
56
|
},
|
|
57
|
+
"./context-menu": {
|
|
58
|
+
"types": "./dist/source/context-menu/index.d.ts",
|
|
59
|
+
"solid": "./dist/source/context-menu/index.js",
|
|
60
|
+
"import": "./dist/context-menu/index.js"
|
|
61
|
+
},
|
|
57
62
|
"./dialog": {
|
|
58
63
|
"types": "./dist/source/dialog/index.d.ts",
|
|
59
64
|
"solid": "./dist/source/dialog/index.js",
|
|
60
65
|
"import": "./dist/dialog/index.js"
|
|
61
66
|
},
|
|
67
|
+
"./menu": {
|
|
68
|
+
"types": "./dist/source/menu/index.d.ts",
|
|
69
|
+
"solid": "./dist/source/menu/index.js",
|
|
70
|
+
"import": "./dist/menu/index.js"
|
|
71
|
+
},
|
|
72
|
+
"./menubar": {
|
|
73
|
+
"types": "./dist/source/menubar/index.d.ts",
|
|
74
|
+
"solid": "./dist/source/menubar/index.js",
|
|
75
|
+
"import": "./dist/menubar/index.js"
|
|
76
|
+
},
|
|
62
77
|
"./meter": {
|
|
63
78
|
"types": "./dist/source/meter/index.d.ts",
|
|
64
79
|
"solid": "./dist/source/meter/index.js",
|
|
65
80
|
"import": "./dist/meter/index.js"
|
|
66
81
|
},
|
|
82
|
+
"./navigation-menu": {
|
|
83
|
+
"types": "./dist/source/navigation-menu/index.d.ts",
|
|
84
|
+
"solid": "./dist/source/navigation-menu/index.js",
|
|
85
|
+
"import": "./dist/navigation-menu/index.js"
|
|
86
|
+
},
|
|
67
87
|
"./popover": {
|
|
68
88
|
"types": "./dist/source/popover/index.d.ts",
|
|
69
89
|
"solid": "./dist/source/popover/index.js",
|
|
@@ -117,7 +137,8 @@
|
|
|
117
137
|
"./package.json": "./package.json"
|
|
118
138
|
},
|
|
119
139
|
"files": [
|
|
120
|
-
"dist"
|
|
140
|
+
"dist",
|
|
141
|
+
"skills"
|
|
121
142
|
],
|
|
122
143
|
"imports": {
|
|
123
144
|
"#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.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<!-- Generated by website/styling-skill.ts from website/src/looks/shadcn/LOOK.md. Edit that file, then run `pnpm --filter website skill`. -->
|
|
2
|
+
|
|
3
|
+
# The shadcn look
|
|
4
|
+
|
|
5
|
+
The look of shadcn/ui's default theme (neutral, "new-york"), in Tailwind CSS v4. Its class strings follow shadcn/ui's components, rewritten for Menhir's parts and data attributes. The licence notice is in `LICENSE`, beside this file.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
Once per app. Check before adding: the app may already have it.
|
|
10
|
+
|
|
11
|
+
1. Copy `tokens.css` beside the app's main stylesheet and import it there, after Tailwind:
|
|
12
|
+
|
|
13
|
+
```css
|
|
14
|
+
@import "tailwindcss";
|
|
15
|
+
@import "./tokens.css";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. Put `data-look="shadcn"` on `<html>`, and `class="bg-background text-foreground"` on `<body>`. The tokens apply inside the element that has the attribute, so a page can also take the look in one part only.
|
|
19
|
+
3. Light and dark follow the CSS `color-scheme`: the tokens use `light-dark()`. The `dark:` classes in the examples need Tailwind's `dark` variant on the same condition. With Menhir's color-scheme utility, which sets `data-color-scheme` on `<html>`:
|
|
20
|
+
|
|
21
|
+
```css
|
|
22
|
+
@custom-variant dark (&:where([data-color-scheme="dark"], [data-color-scheme="dark"] *));
|
|
23
|
+
|
|
24
|
+
:root[data-color-scheme="dark"] {
|
|
25
|
+
color-scheme: dark;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Without the utility, `:root { color-scheme: light dark; }` follows the system, and the `dark` variant stays Tailwind's default, `prefers-color-scheme`. Use the first when the app already has the utility, and the second otherwise.
|
|
30
|
+
|
|
31
|
+
## Tokens
|
|
32
|
+
|
|
33
|
+
Use these through Tailwind classes (`bg-primary`, `text-muted-foreground`, `border-input`, `ring-ring/50`), never as raw colours. Two colours are not tokens, as in shadcn/ui, and are used only where their recipe says: black at 50% behind a dialog (`backdrop:bg-black/50`), and white text on `destructive` (`text-white`).
|
|
34
|
+
|
|
35
|
+
| Token | For |
|
|
36
|
+
| ----------------------------------- | ---------------------------------------------------------------------------------- |
|
|
37
|
+
| `background`, `foreground` | The page, and a surface that sits on it, such as a dialog |
|
|
38
|
+
| `card`, `card-foreground` | A raised box in the page, such as a tab panel |
|
|
39
|
+
| `popover`, `popover-foreground` | A positioned popup: popover, tooltip, menu |
|
|
40
|
+
| `primary`, `primary-foreground` | The main action, and the on state: a checked switch |
|
|
41
|
+
| `secondary`, `secondary-foreground` | A second action |
|
|
42
|
+
| `muted`, `muted-foreground` | A quiet background (a tab list), and secondary text |
|
|
43
|
+
| `accent`, `accent-foreground` | Hover on an outline or ghost control, a highlighted item |
|
|
44
|
+
| `destructive` | An action that deletes, and invalid fields |
|
|
45
|
+
| `border`, `input` | Borders: `border` for surfaces (the default), `input` for fields and the off state |
|
|
46
|
+
| `ring` | Focus: `ring-ring/50`, and the focused field's border |
|
|
47
|
+
|
|
48
|
+
Spacing and shadows are Tailwind's own scales (`p-6`, `gap-2`, `shadow-xs` to `shadow-lg`), which the look leaves as they are, as shadcn/ui does; the recipes say which step each part takes, so do not add spacing or shadow tokens.
|
|
49
|
+
|
|
50
|
+
Radii come from `--radius`: `rounded-md` (0.5rem) for controls, `rounded-lg` for a dialog and a tab list, `rounded-xl` for a card, `rounded-full` for a switch.
|
|
51
|
+
|
|
52
|
+
## Recipes
|
|
53
|
+
|
|
54
|
+
Every component in the look is built from these. Extend them for a component without a worked example.
|
|
55
|
+
|
|
56
|
+
- **Focus**: `outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50` on every focusable part, including a tab panel. Buttons aside, a part without a border of its own, such as a tab or an accordion's Trigger, also gets `border border-transparent`, for the focused border to colour.
|
|
57
|
+
- **Disabled**: `data-disabled:pointer-events-none data-disabled:opacity-50` on a part that has `data-disabled` (form controls, tabs, toggles, accordion items: see the component's page); `disabled:pointer-events-none disabled:opacity-50` on a plain button, such as a popup's Trigger or Close.
|
|
58
|
+
- **Controls** are `h-9` with `text-sm font-medium`. A small one is `h-8`.
|
|
59
|
+
- **Buttons**, all `inline-flex h-9 shrink-0 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-medium whitespace-nowrap transition-all motion-reduce:transition-none` plus the focus and disabled recipes. A popup's Trigger and a Cancel are outline, the main action is primary, and the button that carries out a deletion is destructive; a Trigger that only opens the confirmation stays outline:
|
|
60
|
+
- primary: `bg-primary text-primary-foreground hover:bg-primary/90`
|
|
61
|
+
- outline: `border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`
|
|
62
|
+
- secondary: `bg-secondary text-secondary-foreground hover:bg-secondary/80`
|
|
63
|
+
- ghost: `hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`
|
|
64
|
+
- destructive: `bg-destructive text-white hover:bg-destructive/90 dark:bg-destructive/60`
|
|
65
|
+
- **Fields**: `h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] motion-reduce:transition-none md:text-sm dark:bg-input/30 placeholder:text-muted-foreground`, plus focus.
|
|
66
|
+
- **On and off** (switch, checkbox): on is `data-checked:bg-primary` with `text-primary-foreground` inside; off is `data-unchecked:bg-input` or `border-input`. A checkbox's partly checked state, `data-indeterminate:`, takes the on classes.
|
|
67
|
+
- **Tracks** (switch): `inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all`, with the on and off classes and `dark:data-unchecked:bg-input/80`, plus the focus and disabled recipes. The thumb is `pointer-events-none block size-4 rounded-full bg-background ring-0 transition-transform data-checked:translate-x-[calc(100%-2px)] data-unchecked:translate-x-0 dark:data-checked:bg-primary-foreground dark:data-unchecked:bg-foreground`.
|
|
68
|
+
- **Boxes** (checkbox): `size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow dark:bg-input/30`; on, and the same for `data-indeterminate:`: `data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary` (the `dark:` one keeps `dark:bg-input/30` from covering the fill). Plus the focus and disabled recipes. The Indicator is `group flex items-center justify-center data-unchecked:hidden` and holds two icons, `size-3.5`: a check with `group-data-indeterminate:hidden` and a dash with `hidden group-data-indeterminate:block`.
|
|
69
|
+
- **Pressed** (toggle, toggle group item): `inline-flex h-9 min-w-9 items-center justify-center gap-2 rounded-md px-2 text-sm font-medium transition-[color,box-shadow] hover:bg-muted hover:text-muted-foreground data-pressed:bg-accent data-pressed:text-accent-foreground`, plus focus and disabled.
|
|
70
|
+
- **Selected** (tab): `data-selected:bg-background data-selected:text-foreground data-selected:shadow-sm`, and in dark `dark:data-selected:border-input dark:data-selected:bg-input/30 dark:data-selected:text-foreground`, on a `rounded-lg bg-muted p-[3px] text-muted-foreground` track. A tab that is not selected is `border border-transparent text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground`.
|
|
71
|
+
- **Disclosures** (accordion, collapsible): an accordion's Root is `w-full`, as wide as what holds it; its Item is `border-b last:border-b-0`, and its Header `m-0 flex`. The Trigger is `group flex flex-1 items-start justify-between gap-4 rounded-md border border-transparent px-2 py-4 text-left text-sm font-medium transition-all motion-reduce:transition-none hover:underline`, plus the focus and disabled recipes, and ends with the chevron down icon: `pointer-events-none size-4 shrink-0 translate-y-0.5 text-muted-foreground transition-transform duration-200 motion-reduce:transition-none group-data-open:rotate-180`. The Panel is `text-sm`, around an inner `<div class="px-2 pt-1 pb-4">`, which lines its text up with the Trigger's and keeps it clear of the Trigger's focus ring, as the Trigger's own padding does for its text: the Panel is hidden while closed, so it takes no `display` or spacing class, and it is not animated.
|
|
72
|
+
- **Icons** are inline SVG: `viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"`, `size-4` unless a recipe says otherwise. Paths: check `M4 12l5 5L20 6`, dash `M5 12h14`, close `M18 6 6 18M6 6l12 12`, chevron down `m6 9 6 6 6-6`. A button with only an icon gets its name from `<span class="sr-only">`.
|
|
73
|
+
- **Corner close** (the icon button in a dialog's corner): `absolute top-4 right-4 rounded-xs opacity-70 transition-opacity outline-none hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/50`.
|
|
74
|
+
- **Surfaces**: a dialog is `rounded-lg border bg-background p-6 shadow-lg` with `backdrop:bg-black/50`, a positioned popup `rounded-md border bg-popover p-4 text-popover-foreground shadow-md`, a card `rounded-xl border bg-card p-6 text-card-foreground shadow-sm`.
|
|
75
|
+
- **Text**: titles `font-semibold` (dialog, `text-lg leading-none`) or `font-medium` (popover); descriptions `text-sm text-muted-foreground`.
|
|
76
|
+
- **Motion**: popups fade and grow from 95%: `transition-[opacity,scale] data-closed:scale-95 data-closed:opacity-0 starting:data-open:scale-95 starting:data-open:opacity-0`, 150ms for a positioned popup and 200ms for a dialog. A dialog's backdrop fades with it: `backdrop:transition-opacity backdrop:duration-200 data-closed:backdrop:opacity-0 starting:data-open:backdrop:opacity-0`. Every `transition-*` gets `motion-reduce:transition-none`.
|
|
77
|
+
|
|
78
|
+
## From shadcn/ui's source
|
|
79
|
+
|
|
80
|
+
shadcn/ui's own components use other attribute, variable and part names. What each becomes in Menhir:
|
|
81
|
+
|
|
82
|
+
| shadcn/ui | Menhir |
|
|
83
|
+
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
84
|
+
| `data-[state=checked]`, `data-[state=unchecked]` | `data-checked:`, `data-unchecked:` |
|
|
85
|
+
| `data-[state=open]`, `data-[state=closed]` | `data-open:`, `data-closed:` |
|
|
86
|
+
| `data-[state=active]` on a tab | `data-selected:` |
|
|
87
|
+
| `data-[orientation=vertical]`, `data-[disabled]` | `data-vertical:`, `data-disabled:` |
|
|
88
|
+
| `animate-in fade-in-0 zoom-in-95` | a transition, with `starting:data-open:opacity-0 starting:data-open:scale-95` |
|
|
89
|
+
| `animate-out fade-out-0 zoom-out-95` | `data-closed:opacity-0 data-closed:scale-95`: Menhir keeps the popup shown until its transition ends |
|
|
90
|
+
| `DialogOverlay` with `bg-black/50` | `backdrop:bg-black/50` on the Dialog's Popup: the backdrop is the browser's `::backdrop` |
|
|
91
|
+
| `fixed top-[50%] left-[50%] translate-…` on `DialogContent` | `m-auto`: a modal `<dialog>` centres itself |
|
|
92
|
+
| `grid` or `flex` on `DialogContent` or `PopoverContent` | an inner `<div>`: a `display` class on the Popup overrides the browser's `display: none` and shows it while closed |
|
|
93
|
+
| `[&[data-state=open]>svg]:rotate-180` | `group` on the Trigger, `group-data-open:rotate-180` on the icon |
|
|
94
|
+
| `animate-accordion-down`, `animate-accordion-up` | nothing: a Panel is hidden while closed, and is not animated |
|
|
95
|
+
| `Portal`, `z-50` | nothing: popups are in the top layer |
|
|
96
|
+
| `--radix-popover-content-transform-origin` | `--transform-origin` |
|
|
97
|
+
| `--radix-popover-trigger-width` | `--anchor-width` |
|
|
98
|
+
| `asChild` | the part's `render` prop |
|
|
99
|
+
| `cn()`, `cva()` variants, `data-slot` | plain class strings |
|
|
100
|
+
|
|
101
|
+
## Worked examples
|
|
102
|
+
|
|
103
|
+
- [Dialog](dialog.md)
|
|
104
|
+
- [Popover](popover.md)
|
|
105
|
+
- [Switch](switch.md)
|
|
106
|
+
- [Tabs](tabs.md)
|