menhir 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/LICENSE +0 -28
  2. package/README.md +44 -1
  3. package/dist/accordion/header/AccordionHeader.js +22 -0
  4. package/dist/accordion/index.js +2 -0
  5. package/dist/accordion/index.parts.js +6 -0
  6. package/dist/accordion/item/AccordionItem.js +51 -0
  7. package/dist/accordion/item/AccordionItemContext.js +10 -0
  8. package/dist/accordion/panel/AccordionPanel.js +32 -0
  9. package/dist/accordion/root/AccordionRoot.js +45 -0
  10. package/dist/accordion/root/AccordionRootContext.js +10 -0
  11. package/dist/accordion/trigger/AccordionTrigger.js +39 -0
  12. package/dist/checkbox/index.js +2 -0
  13. package/dist/checkbox/index.parts.js +3 -0
  14. package/dist/checkbox/indicator/CheckboxIndicator.js +20 -0
  15. package/dist/checkbox/root/CheckboxRoot.js +136 -0
  16. package/dist/checkbox/root/CheckboxRootContext.js +10 -0
  17. package/dist/collapsible/index.js +2 -0
  18. package/dist/collapsible/index.parts.js +4 -0
  19. package/dist/collapsible/panel/CollapsiblePanel.js +27 -0
  20. package/dist/collapsible/root/CollapsibleRoot.js +53 -0
  21. package/dist/collapsible/root/CollapsibleRootContext.js +10 -0
  22. package/dist/collapsible/trigger/CollapsibleTrigger.js +31 -0
  23. package/dist/color-scheme/colorScheme.js +28 -0
  24. package/dist/color-scheme/colorSchemeScript.js +18 -0
  25. package/dist/color-scheme/cookie/cookie.js +50 -0
  26. package/dist/color-scheme/cookie/index.js +3 -0
  27. package/dist/color-scheme/createColorScheme.js +41 -0
  28. package/dist/color-scheme/local-storage/index.js +3 -0
  29. package/dist/color-scheme/local-storage/localStorage.js +38 -0
  30. package/dist/core/button.js +56 -0
  31. package/dist/core/createControllableSignal.js +50 -0
  32. package/dist/core/listValue.js +49 -0
  33. package/dist/core/mergeElementProps.js +67 -0
  34. package/dist/core/preference/cookiePreference.js +44 -0
  35. package/dist/core/preference/createPreference.js +60 -0
  36. package/dist/core/preference/localStoragePreference.js +28 -0
  37. package/dist/core/preference/preference.js +21 -0
  38. package/dist/core/preference/preferenceScript.js +12 -0
  39. package/dist/core/range.js +53 -0
  40. package/dist/core/renderElement.js +14 -0
  41. package/dist/core/rovingFocus.js +50 -0
  42. package/dist/core/toggleButton.js +37 -0
  43. package/dist/meter/index.js +2 -0
  44. package/dist/meter/index.parts.js +3 -0
  45. package/dist/meter/root/MeterRoot.js +28 -0
  46. package/dist/meter/root/MeterRootContext.js +10 -0
  47. package/dist/meter/value/MeterValue.js +24 -0
  48. package/dist/progress/index.js +2 -0
  49. package/dist/progress/index.parts.js +4 -0
  50. package/dist/progress/indicator/ProgressIndicator.js +21 -0
  51. package/dist/progress/root/ProgressRoot.js +47 -0
  52. package/dist/progress/root/ProgressRootContext.js +10 -0
  53. package/dist/progress/value/ProgressValue.js +26 -0
  54. package/dist/separator/index.js +2 -0
  55. package/dist/separator/index.parts.js +1 -0
  56. package/dist/separator/root/SeparatorRoot.js +31 -0
  57. package/dist/source/accordion/header/AccordionHeader.d.ts +11 -0
  58. package/dist/source/accordion/header/AccordionHeader.jsx +14 -0
  59. package/dist/source/accordion/index.d.ts +1 -0
  60. package/dist/source/accordion/index.js +1 -0
  61. package/dist/source/accordion/index.parts.d.ts +5 -0
  62. package/dist/source/accordion/index.parts.js +5 -0
  63. package/dist/source/accordion/item/AccordionItem.d.ts +17 -0
  64. package/dist/source/accordion/item/AccordionItem.jsx +42 -0
  65. package/dist/source/accordion/item/AccordionItemContext.d.ts +33 -0
  66. package/dist/source/accordion/item/AccordionItemContext.js +12 -0
  67. package/dist/source/accordion/panel/AccordionPanel.d.ts +11 -0
  68. package/dist/source/accordion/panel/AccordionPanel.jsx +27 -0
  69. package/dist/source/accordion/root/AccordionRoot.d.ts +26 -0
  70. package/dist/source/accordion/root/AccordionRoot.jsx +37 -0
  71. package/dist/source/accordion/root/AccordionRootContext.d.ts +11 -0
  72. package/dist/source/accordion/root/AccordionRootContext.js +13 -0
  73. package/dist/source/accordion/trigger/AccordionTrigger.d.ts +10 -0
  74. package/dist/source/accordion/trigger/AccordionTrigger.jsx +35 -0
  75. package/dist/source/checkbox/index.d.ts +1 -0
  76. package/dist/source/checkbox/index.js +1 -0
  77. package/dist/source/checkbox/index.parts.d.ts +2 -0
  78. package/dist/source/checkbox/index.parts.js +2 -0
  79. package/dist/source/checkbox/indicator/CheckboxIndicator.d.ts +10 -0
  80. package/dist/source/checkbox/indicator/CheckboxIndicator.jsx +12 -0
  81. package/dist/source/checkbox/root/CheckboxRoot.d.ts +37 -0
  82. package/dist/source/checkbox/root/CheckboxRoot.jsx +135 -0
  83. package/dist/source/checkbox/root/CheckboxRootContext.d.ts +16 -0
  84. package/dist/source/checkbox/root/CheckboxRootContext.js +13 -0
  85. package/dist/source/collapsible/index.d.ts +1 -0
  86. package/dist/source/collapsible/index.js +1 -0
  87. package/dist/source/collapsible/index.parts.d.ts +3 -0
  88. package/dist/source/collapsible/index.parts.js +3 -0
  89. package/dist/source/collapsible/panel/CollapsiblePanel.d.ts +10 -0
  90. package/dist/source/collapsible/panel/CollapsiblePanel.jsx +22 -0
  91. package/dist/source/collapsible/root/CollapsibleRoot.d.ts +21 -0
  92. package/dist/source/collapsible/root/CollapsibleRoot.jsx +42 -0
  93. package/dist/source/collapsible/root/CollapsibleRootContext.d.ts +26 -0
  94. package/dist/source/collapsible/root/CollapsibleRootContext.js +13 -0
  95. package/dist/source/collapsible/trigger/CollapsibleTrigger.d.ts +10 -0
  96. package/dist/source/collapsible/trigger/CollapsibleTrigger.jsx +23 -0
  97. package/dist/source/color-scheme/colorScheme.d.ts +35 -0
  98. package/dist/source/color-scheme/colorScheme.js +30 -0
  99. package/dist/source/color-scheme/colorSchemeScript.d.ts +8 -0
  100. package/dist/source/color-scheme/colorSchemeScript.js +16 -0
  101. package/dist/source/color-scheme/cookie/cookie.d.ts +39 -0
  102. package/dist/source/color-scheme/cookie/cookie.js +48 -0
  103. package/dist/source/color-scheme/cookie/index.d.ts +4 -0
  104. package/dist/source/color-scheme/cookie/index.js +2 -0
  105. package/dist/source/color-scheme/createColorScheme.d.ts +26 -0
  106. package/dist/source/color-scheme/createColorScheme.js +44 -0
  107. package/dist/source/color-scheme/local-storage/index.d.ts +4 -0
  108. package/dist/source/color-scheme/local-storage/index.js +2 -0
  109. package/dist/source/color-scheme/local-storage/localStorage.d.ts +30 -0
  110. package/dist/source/color-scheme/local-storage/localStorage.js +36 -0
  111. package/dist/source/core/button.d.ts +53 -0
  112. package/dist/source/core/button.js +61 -0
  113. package/dist/source/core/createControllableSignal.d.ts +27 -0
  114. package/dist/source/core/createControllableSignal.js +74 -0
  115. package/dist/source/core/index.d.ts +1 -0
  116. package/dist/source/core/index.js +1 -0
  117. package/dist/source/core/listValue.d.ts +32 -0
  118. package/dist/source/core/listValue.js +51 -0
  119. package/dist/source/core/mergeElementProps.d.ts +19 -0
  120. package/dist/source/core/mergeElementProps.js +91 -0
  121. package/dist/source/core/preference/cookiePreference.d.ts +10 -0
  122. package/dist/source/core/preference/cookiePreference.js +57 -0
  123. package/dist/source/core/preference/createPreference.d.ts +44 -0
  124. package/dist/source/core/preference/createPreference.js +60 -0
  125. package/dist/source/core/preference/localStoragePreference.d.ts +3 -0
  126. package/dist/source/core/preference/localStoragePreference.js +36 -0
  127. package/dist/source/core/preference/preference.d.ts +40 -0
  128. package/dist/source/core/preference/preference.js +22 -0
  129. package/dist/source/core/preference/preferenceScript.d.ts +17 -0
  130. package/dist/source/core/preference/preferenceScript.js +13 -0
  131. package/dist/source/core/range.d.ts +52 -0
  132. package/dist/source/core/range.js +60 -0
  133. package/dist/source/core/renderElement.d.ts +25 -0
  134. package/dist/source/core/renderElement.jsx +11 -0
  135. package/dist/source/core/rovingFocus.d.ts +42 -0
  136. package/dist/source/core/rovingFocus.js +71 -0
  137. package/dist/source/core/toggleButton.d.ts +22 -0
  138. package/dist/source/core/toggleButton.js +35 -0
  139. package/dist/source/meter/index.d.ts +1 -0
  140. package/dist/source/meter/index.js +1 -0
  141. package/dist/source/meter/index.parts.d.ts +2 -0
  142. package/dist/source/meter/index.parts.js +2 -0
  143. package/dist/source/meter/root/MeterRoot.d.ts +27 -0
  144. package/dist/source/meter/root/MeterRoot.jsx +15 -0
  145. package/dist/source/meter/root/MeterRootContext.d.ts +9 -0
  146. package/dist/source/meter/root/MeterRootContext.js +13 -0
  147. package/dist/source/meter/value/MeterValue.d.ts +11 -0
  148. package/dist/source/meter/value/MeterValue.jsx +19 -0
  149. package/dist/source/progress/index.d.ts +1 -0
  150. package/dist/source/progress/index.js +1 -0
  151. package/dist/source/progress/index.parts.d.ts +3 -0
  152. package/dist/source/progress/index.parts.js +3 -0
  153. package/dist/source/progress/indicator/ProgressIndicator.d.ts +11 -0
  154. package/dist/source/progress/indicator/ProgressIndicator.jsx +13 -0
  155. package/dist/source/progress/root/ProgressRoot.d.ts +30 -0
  156. package/dist/source/progress/root/ProgressRoot.jsx +32 -0
  157. package/dist/source/progress/root/ProgressRootContext.d.ts +20 -0
  158. package/dist/source/progress/root/ProgressRootContext.js +13 -0
  159. package/dist/source/progress/value/ProgressValue.d.ts +12 -0
  160. package/dist/source/progress/value/ProgressValue.jsx +20 -0
  161. package/dist/source/separator/index.d.ts +1 -0
  162. package/dist/source/separator/index.js +1 -0
  163. package/dist/source/separator/index.parts.d.ts +1 -0
  164. package/dist/source/separator/index.parts.js +1 -0
  165. package/dist/source/separator/root/SeparatorRoot.d.ts +12 -0
  166. package/dist/source/separator/root/SeparatorRoot.jsx +26 -0
  167. package/dist/source/switch/index.d.ts +1 -0
  168. package/dist/source/switch/index.js +1 -0
  169. package/dist/source/switch/index.parts.d.ts +2 -0
  170. package/dist/source/switch/index.parts.js +2 -0
  171. package/dist/source/switch/root/SwitchRoot.d.ts +31 -0
  172. package/dist/source/switch/root/SwitchRoot.jsx +124 -0
  173. package/dist/source/switch/root/SwitchRootContext.d.ts +14 -0
  174. package/dist/source/switch/root/SwitchRootContext.js +13 -0
  175. package/dist/source/switch/thumb/SwitchThumb.d.ts +10 -0
  176. package/dist/source/switch/thumb/SwitchThumb.jsx +12 -0
  177. package/dist/source/tabs/index.d.ts +1 -0
  178. package/dist/source/tabs/index.js +1 -0
  179. package/dist/source/tabs/index.parts.d.ts +4 -0
  180. package/dist/source/tabs/index.parts.js +4 -0
  181. package/dist/source/tabs/list/TabsList.d.ts +11 -0
  182. package/dist/source/tabs/list/TabsList.jsx +27 -0
  183. package/dist/source/tabs/panel/TabsPanel.d.ts +12 -0
  184. package/dist/source/tabs/panel/TabsPanel.jsx +38 -0
  185. package/dist/source/tabs/root/TabsRoot.d.ts +30 -0
  186. package/dist/source/tabs/root/TabsRoot.jsx +74 -0
  187. package/dist/source/tabs/root/TabsRootContext.d.ts +47 -0
  188. package/dist/source/tabs/root/TabsRootContext.js +13 -0
  189. package/dist/source/tabs/tab/TabsTab.d.ts +20 -0
  190. package/dist/source/tabs/tab/TabsTab.jsx +77 -0
  191. package/dist/source/theme/cookie/cookie.d.ts +34 -0
  192. package/dist/source/theme/cookie/cookie.js +42 -0
  193. package/dist/source/theme/cookie/index.d.ts +2 -0
  194. package/dist/source/theme/cookie/index.js +1 -0
  195. package/dist/source/theme/local-storage/index.d.ts +2 -0
  196. package/dist/source/theme/local-storage/index.js +1 -0
  197. package/dist/source/theme/local-storage/localStorage.d.ts +28 -0
  198. package/dist/source/theme/local-storage/localStorage.js +34 -0
  199. package/dist/source/theme/theme.d.ts +46 -0
  200. package/dist/source/theme/theme.js +57 -0
  201. package/dist/source/toggle/index.d.ts +1 -0
  202. package/dist/source/toggle/index.js +1 -0
  203. package/dist/source/toggle/index.parts.d.ts +1 -0
  204. package/dist/source/toggle/index.parts.js +1 -0
  205. package/dist/source/toggle/root/ToggleRoot.d.ts +20 -0
  206. package/dist/source/toggle/root/ToggleRoot.jsx +30 -0
  207. package/dist/source/toggle-group/index.d.ts +1 -0
  208. package/dist/source/toggle-group/index.js +1 -0
  209. package/dist/source/toggle-group/index.parts.d.ts +2 -0
  210. package/dist/source/toggle-group/index.parts.js +2 -0
  211. package/dist/source/toggle-group/item/ToggleGroupItem.d.ts +14 -0
  212. package/dist/source/toggle-group/item/ToggleGroupItem.jsx +39 -0
  213. package/dist/source/toggle-group/root/ToggleGroupRoot.d.ts +28 -0
  214. package/dist/source/toggle-group/root/ToggleGroupRoot.jsx +68 -0
  215. package/dist/source/toggle-group/root/ToggleGroupRootContext.d.ts +25 -0
  216. package/dist/source/toggle-group/root/ToggleGroupRootContext.js +13 -0
  217. package/dist/switch/index.js +2 -0
  218. package/dist/switch/index.parts.js +3 -0
  219. package/dist/switch/root/SwitchRoot.js +129 -0
  220. package/dist/switch/root/SwitchRootContext.js +10 -0
  221. package/dist/switch/thumb/SwitchThumb.js +20 -0
  222. package/dist/tabs/index.js +2 -0
  223. package/dist/tabs/index.parts.js +5 -0
  224. package/dist/tabs/list/TabsList.js +33 -0
  225. package/dist/tabs/panel/TabsPanel.js +40 -0
  226. package/dist/tabs/root/TabsRoot.js +74 -0
  227. package/dist/tabs/root/TabsRootContext.js +10 -0
  228. package/dist/tabs/tab/TabsTab.js +74 -0
  229. package/dist/theme/cookie/cookie.js +44 -0
  230. package/dist/theme/cookie/index.js +1 -0
  231. package/dist/theme/local-storage/index.js +1 -0
  232. package/dist/theme/local-storage/localStorage.js +36 -0
  233. package/dist/theme/theme.js +52 -0
  234. package/dist/toggle/index.js +2 -0
  235. package/dist/toggle/index.parts.js +1 -0
  236. package/dist/toggle/root/ToggleRoot.js +38 -0
  237. package/dist/toggle-group/index.js +2 -0
  238. package/dist/toggle-group/index.parts.js +3 -0
  239. package/dist/toggle-group/item/ToggleGroupItem.js +48 -0
  240. package/dist/toggle-group/root/ToggleGroupRoot.js +71 -0
  241. package/dist/toggle-group/root/ToggleGroupRootContext.js +10 -0
  242. package/package.json +99 -6
@@ -0,0 +1,14 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface ToggleGroupItemProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** Identifies the item in the group's value. */
5
+ value: string;
6
+ /** Whether the item ignores the user. It cannot be focused either. */
7
+ disabled?: boolean;
8
+ render?: RenderProp;
9
+ }
10
+ /**
11
+ * One toggle button of the group: a `<button aria-pressed>`. Place it
12
+ * inside `ToggleGroup.Root`.
13
+ */
14
+ export declare function ToggleGroupItem(props: ToggleGroupItemProps): JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { merge, omit, onSettled, untrack } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { toggleButtonProps } from "../../core/toggleButton.js";
5
+ import { useToggleGroupRootContext } from "../root/ToggleGroupRootContext.js";
6
+ /**
7
+ * One toggle button of the group: a `<button aria-pressed>`. Place it
8
+ * inside `ToggleGroup.Root`.
9
+ */
10
+ export function ToggleGroupItem(props) {
11
+ const group = useToggleGroupRootContext();
12
+ let element;
13
+ const own = toggleButtonProps({
14
+ get value() {
15
+ return group.pressed(props.value);
16
+ },
17
+ get disabled() {
18
+ return !!(group.disabled() || props.disabled);
19
+ },
20
+ setValue: (pressed) => group.press(props.value, pressed),
21
+ }, "ToggleGroup.Item");
22
+ // Read once: the tab stop of the server HTML, and of the first render.
23
+ const first = group.claimTabStop(untrack(() => own.disabled));
24
+ const itemProps = merge(own, {
25
+ get tabindex() {
26
+ return group.isTabStop(element, first) ? 0 : -1;
27
+ },
28
+ onFocus: () => group.setActive(element),
29
+ onKeyDown: (event) => group.navigate(event, element),
30
+ ref: (el) => {
31
+ element = el;
32
+ own.ref(el);
33
+ },
34
+ });
35
+ // Mounted, so its place in the document is known.
36
+ onSettled(() => group.register({ element: element, disabled: () => own.disabled }));
37
+ const elementProps = mergeElementProps(itemProps, omit(props, "render", "value", "disabled"));
38
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
39
+ }
@@ -0,0 +1,28 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface ToggleGroupRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** The values of the pressed items, when controlled. */
5
+ value?: string[];
6
+ /** The values of the items pressed at first, when uncontrolled. */
7
+ defaultValue?: string[];
8
+ /**
9
+ * Called with the new values when the user presses or releases an item.
10
+ * When controlled, the group changes only if `value` does.
11
+ */
12
+ onValueChange?: (value: string[]) => void;
13
+ /**
14
+ * Whether several items can be pressed at once. Otherwise pressing an
15
+ * item releases the one pressed before.
16
+ */
17
+ multiple?: boolean;
18
+ /** Whether every item ignores the user. They cannot be focused either. */
19
+ disabled?: boolean;
20
+ /** Whether the items are laid out side by side, or stacked. */
21
+ orientation?: "horizontal" | "vertical";
22
+ render?: RenderProp;
23
+ }
24
+ /**
25
+ * A set of toggle buttons that share one value: a `<div role="group">`
26
+ * around `ToggleGroup.Item`s, with one tab stop among them.
27
+ */
28
+ export declare function ToggleGroupRoot(props: ToggleGroupRootProps): JSX.Element;
@@ -0,0 +1,68 @@
1
+ import { createSignal, omit } from "solid-js";
2
+ import { createListValue } from "../../core/listValue.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { createRovingFocus } from "../../core/rovingFocus.js";
5
+ import { renderElement } from "../../core/renderElement.jsx";
6
+ import { ToggleGroupRootContext } from "./ToggleGroupRootContext.js";
7
+ /**
8
+ * A set of toggle buttons that share one value: a `<div role="group">`
9
+ * around `ToggleGroup.Item`s, with one tab stop among them.
10
+ */
11
+ export function ToggleGroupRoot(props) {
12
+ const pressed = createListValue({
13
+ get value() {
14
+ return props.value;
15
+ },
16
+ get defaultValue() {
17
+ return props.defaultValue;
18
+ },
19
+ get multiple() {
20
+ return props.multiple;
21
+ },
22
+ onChange: (value) => props.onValueChange?.(value),
23
+ });
24
+ const vertical = () => props.orientation === "vertical";
25
+ // The item that last had focus has the tab stop, else the first enabled
26
+ // one.
27
+ const [active, setActive] = createSignal();
28
+ const roving = createRovingFocus({
29
+ get vertical() {
30
+ return vertical();
31
+ },
32
+ focusable: (item) => !item.disabled(),
33
+ preferred: (item) => item.element === active(),
34
+ });
35
+ // Whether an item has claimed the tab stop of the server HTML.
36
+ let claimed = false;
37
+ const context = {
38
+ ...roving,
39
+ pressed: pressed.has,
40
+ press: pressed.set,
41
+ disabled: () => props.disabled,
42
+ // Before any item has registered, as on the server, the first enabled
43
+ // item created has the tab stop, so the server HTML has one too.
44
+ claimTabStop: (disabled) => !disabled && !claimed && (claimed = true),
45
+ setActive: (element) => setActive(element),
46
+ };
47
+ const ownProps = {
48
+ role: "group",
49
+ // The group role takes no orientation; a toolbar does, horizontal unless
50
+ // it says otherwise.
51
+ get "aria-orientation"() {
52
+ return props.role === "toolbar" && vertical() ? "vertical" : undefined;
53
+ },
54
+ get "data-horizontal"() {
55
+ return vertical() ? undefined : "";
56
+ },
57
+ get "data-vertical"() {
58
+ return vertical() ? "" : undefined;
59
+ },
60
+ get "data-disabled"() {
61
+ return props.disabled ? "" : undefined;
62
+ },
63
+ };
64
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "multiple", "disabled", "orientation"));
65
+ return (<ToggleGroupRootContext value={context}>
66
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
67
+ </ToggleGroupRootContext>);
68
+ }
@@ -0,0 +1,25 @@
1
+ import type { RovingFocus } from "../../core/rovingFocus.ts";
2
+ /** An item as the group knows it, for focus order and the tab stop. */
3
+ export interface ToggleGroupItemEntry {
4
+ readonly element: HTMLElement;
5
+ readonly disabled: () => boolean;
6
+ }
7
+ /** What the group shares with its items, with their roving focus. */
8
+ export interface ToggleGroupRootContextValue extends RovingFocus<ToggleGroupItemEntry> {
9
+ /** Whether the item with this value is pressed. */
10
+ pressed(value: string): boolean;
11
+ /** Asks to press or release the item with this value. */
12
+ press(value: string, pressed: boolean): void;
13
+ /** Whether the whole group is disabled. */
14
+ disabled(): boolean | undefined;
15
+ /**
16
+ * Whether the item being created is the group's first enabled item, which
17
+ * has the tab stop before any item has registered, as on the server.
18
+ * Called once per item, in its body.
19
+ */
20
+ claimTabStop(disabled: boolean): boolean;
21
+ /** Records the item that received focus, which takes the tab stop. */
22
+ setActive(element: HTMLElement): void;
23
+ }
24
+ export declare const ToggleGroupRootContext: import("solid-js").Context<ToggleGroupRootContextValue | null>;
25
+ export declare function useToggleGroupRootContext(): ToggleGroupRootContextValue;
@@ -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 ToggleGroupRootContext = createContext(null);
6
+ export function useToggleGroupRootContext() {
7
+ const context = useContext(ToggleGroupRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] ToggleGroup parts must be placed within <ToggleGroup.Root>.");
11
+ }
12
+ return context;
13
+ }
@@ -0,0 +1,2 @@
1
+ import * as Switch from "./index.parts.js";
2
+ export { Switch };
@@ -0,0 +1,3 @@
1
+ import { SwitchRoot } from "./root/SwitchRoot.js";
2
+ import { SwitchThumb } from "./thumb/SwitchThumb.js";
3
+ export { SwitchRoot as Root, SwitchThumb as Thumb };
@@ -0,0 +1,129 @@
1
+ import { warnUnlessButton } from "../../core/button.js";
2
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.js";
5
+ import { SwitchRootContext } from "./SwitchRootContext.js";
6
+ import { createComponent, effect, heldRead, isDev, memo, ref, setAttribute, setProperty, spread, template } from "@solidjs/web";
7
+ import { merge, omit, onFlush, onSettled, untrack } from "solid-js";
8
+ // src/switch/root/SwitchRoot.tsx
9
+ var _tmpl$ = /* @__PURE__ */ template(`<input type=checkbox aria-hidden=true tabindex=-1 style=position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none>`);
10
+ var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
11
+ /**
12
+ * The switch itself: a `<button role="switch">`.
13
+ */
14
+ function SwitchRoot(props) {
15
+ const [checked, setChecked] = createControllableSignal({
16
+ get value() {
17
+ return props.checked;
18
+ },
19
+ get defaultValue() {
20
+ return props.defaultChecked ?? false;
21
+ },
22
+ onChange: (value) => props.onCheckedChange?.(value)
23
+ });
24
+ const stateAttributes = {
25
+ get "data-checked"() {
26
+ return checked() ? "" : void 0;
27
+ },
28
+ get "data-unchecked"() {
29
+ return checked() ? void 0 : "";
30
+ },
31
+ get "data-disabled"() {
32
+ return props.disabled ? "" : void 0;
33
+ },
34
+ get "data-readonly"() {
35
+ return props.readOnly ? "" : void 0;
36
+ },
37
+ get "data-required"() {
38
+ return props.required ? "" : void 0;
39
+ }
40
+ };
41
+ const buttonProps = {
42
+ role: "switch",
43
+ type: "button",
44
+ get disabled() {
45
+ return props.disabled;
46
+ },
47
+ get "aria-checked"() {
48
+ return checked() ? "true" : "false";
49
+ },
50
+ get "aria-readonly"() {
51
+ return props.readOnly ? "true" : void 0;
52
+ },
53
+ get "aria-required"() {
54
+ return props.required ? "true" : void 0;
55
+ },
56
+ onClick: () => input?.click(),
57
+ ref: (element) => {
58
+ button = element;
59
+ if (isDev) warnUnlessButton(element, "Switch.Root");
60
+ }
61
+ };
62
+ let button;
63
+ let input;
64
+ const syncInput = () => {
65
+ if (input) input.checked = untrack(checked);
66
+ };
67
+ const onInputChange = () => {
68
+ if (!input) return;
69
+ setChecked(input.checked);
70
+ onFlush(syncInput);
71
+ };
72
+ const onInputClick = (event) => {
73
+ event.stopPropagation();
74
+ if (props.readOnly) event.preventDefault();
75
+ };
76
+ onSettled(() => {
77
+ const form = input?.form;
78
+ if (!form) return;
79
+ const onReset = () => {
80
+ setChecked(props.defaultChecked ?? false);
81
+ onFlush(syncInput);
82
+ };
83
+ form.addEventListener("reset", onReset);
84
+ return () => form.removeEventListener("reset", onReset);
85
+ });
86
+ const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "checked", "defaultChecked", "onCheckedChange", "name", "value", "disabled", "readOnly", "required", "form"));
87
+ return createComponent(SwitchRootContext, {
88
+ value: stateAttributes,
89
+ get children() {
90
+ return [memo(() => {
91
+ return renderElement(props, elementProps, (p) => (() => {
92
+ var _el$2 = _tmpl$2();
93
+ spread(_el$2, p, false);
94
+ return _el$2;
95
+ })());
96
+ }), (() => {
97
+ var _el$ = _tmpl$();
98
+ _el$.addEventListener("focus", () => button?.focus());
99
+ _el$.addEventListener("change", onInputChange);
100
+ ref(() => {
101
+ return (element) => {
102
+ input = element;
103
+ element.addEventListener("click", onInputClick);
104
+ };
105
+ }, _el$);
106
+ effect(() => {
107
+ return {
108
+ e: props.name,
109
+ t: props.value,
110
+ a: props.disabled,
111
+ o: props.required,
112
+ i: props.form,
113
+ n: checked(),
114
+ s: heldRead()
115
+ };
116
+ }, ({ e, t, a, o, i, n, s }, _p$) => {
117
+ e !== _p$?.e && setAttribute(_el$, "name", e);
118
+ (t !== _p$?.t || !s) && setProperty(_el$, "value", t);
119
+ a !== _p$?.a && setAttribute(_el$, "disabled", a);
120
+ o !== _p$?.o && setAttribute(_el$, "required", o);
121
+ i !== _p$?.i && setAttribute(_el$, "form", i);
122
+ (n !== _p$?.n || !s) && (_el$.checked = n);
123
+ });
124
+ return _el$;
125
+ })()];
126
+ }
127
+ });
128
+ }
129
+ export { SwitchRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/switch/root/SwitchRootContext.ts
4
+ var SwitchRootContext = createContext(null);
5
+ function useSwitchRootContext() {
6
+ const context = useContext(SwitchRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] Switch parts must be placed within <Switch.Root>.");
8
+ return context;
9
+ }
10
+ export { SwitchRootContext, useSwitchRootContext };
@@ -0,0 +1,20 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useSwitchRootContext } from "../root/SwitchRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { omit } from "solid-js";
6
+ // src/switch/thumb/SwitchThumb.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<span>`);
8
+ /**
9
+ * The part of the switch that slides between off and on: a `<span>` with
10
+ * the Root's `data-*` attributes. Place it inside `Switch.Root`.
11
+ */
12
+ function SwitchThumb(props) {
13
+ const elementProps = mergeElementProps(useSwitchRootContext(), omit(props, "render"));
14
+ return renderElement(props, elementProps, (p) => (() => {
15
+ var _el$ = _tmpl$();
16
+ spread(_el$, p, false);
17
+ return _el$;
18
+ })());
19
+ }
20
+ export { SwitchThumb };
@@ -0,0 +1,2 @@
1
+ import * as Tabs from "./index.parts.js";
2
+ export { Tabs };
@@ -0,0 +1,5 @@
1
+ import { TabsRoot } from "./root/TabsRoot.js";
2
+ import { TabsList } from "./list/TabsList.js";
3
+ import { TabsTab } from "./tab/TabsTab.js";
4
+ import { TabsPanel } from "./panel/TabsPanel.js";
5
+ export { TabsList as List, TabsPanel as Panel, TabsRoot as Root, TabsTab as Tab };
@@ -0,0 +1,33 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useTabsRootContext } from "../root/TabsRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { omit } from "solid-js";
6
+ // src/tabs/list/TabsList.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
8
+ /**
9
+ * The list of tabs: a `<div role="tablist">` around `Tabs.Tab`s, with one
10
+ * tab stop among them. Name it with `aria-label` or `aria-labelledby`.
11
+ * Place it inside `Tabs.Root`.
12
+ */
13
+ function TabsList(props) {
14
+ const root = useTabsRootContext();
15
+ const elementProps = mergeElementProps({
16
+ role: "tablist",
17
+ get "aria-orientation"() {
18
+ return root.vertical() ? "vertical" : void 0;
19
+ },
20
+ get "data-horizontal"() {
21
+ return root.vertical() ? void 0 : "";
22
+ },
23
+ get "data-vertical"() {
24
+ return root.vertical() ? "" : void 0;
25
+ }
26
+ }, omit(props, "render"));
27
+ return renderElement(props, elementProps, (p) => (() => {
28
+ var _el$ = _tmpl$();
29
+ spread(_el$, p, false);
30
+ return _el$;
31
+ })());
32
+ }
33
+ export { TabsList };
@@ -0,0 +1,40 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useTabsRootContext } from "../root/TabsRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { omit } from "solid-js";
6
+ // src/tabs/panel/TabsPanel.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
8
+ /**
9
+ * The content its tab shows: a `<div role="tabpanel">` named by the tab,
10
+ * `hidden` unless the tab is selected. Place it inside `Tabs.Root`.
11
+ */
12
+ function TabsPanel(props) {
13
+ const root = useTabsRootContext();
14
+ const selected = () => root.selected(props.value);
15
+ const elementProps = mergeElementProps({
16
+ role: "tabpanel",
17
+ get id() {
18
+ return root.panelId(props.value);
19
+ },
20
+ get "aria-labelledby"() {
21
+ return root.tabId(props.value);
22
+ },
23
+ tabindex: 0,
24
+ get hidden() {
25
+ return !selected();
26
+ },
27
+ get "data-selected"() {
28
+ return selected() ? "" : void 0;
29
+ },
30
+ get "data-unselected"() {
31
+ return selected() ? void 0 : "";
32
+ }
33
+ }, omit(props, "render", "value", "id"));
34
+ return renderElement(props, elementProps, (p) => (() => {
35
+ var _el$ = _tmpl$();
36
+ spread(_el$, p, false);
37
+ return _el$;
38
+ })());
39
+ }
40
+ export { TabsPanel };
@@ -0,0 +1,74 @@
1
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { createRovingFocus } from "../../core/rovingFocus.js";
5
+ import { TabsRootContext } from "./TabsRootContext.js";
6
+ import { createComponent, spread, template } from "@solidjs/web";
7
+ import { createSignal, createUniqueId, omit } from "solid-js";
8
+ // src/tabs/root/TabsRoot.tsx
9
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
10
+ /**
11
+ * Layered sections of content, one shown at a time: a `<div>` around a
12
+ * `Tabs.List` of `Tabs.Tab`s and their `Tabs.Panel`s.
13
+ */
14
+ function TabsRoot(props) {
15
+ const [value, setValue] = createControllableSignal({
16
+ get value() {
17
+ return props.value;
18
+ },
19
+ get defaultValue() {
20
+ return props.defaultValue;
21
+ },
22
+ onChange: (value) => props.onValueChange?.(value)
23
+ });
24
+ let first;
25
+ const selected = () => {
26
+ const current = value();
27
+ return current === void 0 ? first : current;
28
+ };
29
+ const vertical = () => props.orientation === "vertical";
30
+ const id = createUniqueId();
31
+ const [focused, setFocused] = createSignal();
32
+ const context = {
33
+ ...createRovingFocus({
34
+ get vertical() {
35
+ return vertical();
36
+ },
37
+ focusable: () => true,
38
+ preferred: (tab) => focused() ? tab.element === focused() : selected() === tab.value()
39
+ }),
40
+ selected: (tab) => selected() === tab,
41
+ select: (tab) => {
42
+ if (selected() !== tab) setValue(tab);
43
+ },
44
+ claimFirst: (tab, disabled) => {
45
+ if (!disabled) first ??= tab;
46
+ },
47
+ vertical,
48
+ automatic: () => props.activation !== "manual",
49
+ generatedTabId: (tab) => `${id}-tab-${tab}`,
50
+ tabId: (tab) => context.tabIds[tab]?.() ?? context.generatedTabId(tab),
51
+ tabIds: {},
52
+ panelId: (tab) => `${id}-panel-${tab}`,
53
+ setFocused: (element) => setFocused(element)
54
+ };
55
+ const elementProps = mergeElementProps({
56
+ get "data-horizontal"() {
57
+ return vertical() ? void 0 : "";
58
+ },
59
+ get "data-vertical"() {
60
+ return vertical() ? "" : void 0;
61
+ }
62
+ }, omit(props, "render", "value", "defaultValue", "onValueChange", "orientation", "activation"));
63
+ return createComponent(TabsRootContext, {
64
+ value: context,
65
+ get children() {
66
+ return renderElement(props, elementProps, (p) => (() => {
67
+ var _el$ = _tmpl$();
68
+ spread(_el$, p, false);
69
+ return _el$;
70
+ })());
71
+ }
72
+ });
73
+ }
74
+ export { TabsRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/tabs/root/TabsRootContext.ts
4
+ var TabsRootContext = createContext(null);
5
+ function useTabsRootContext() {
6
+ const context = useContext(TabsRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] Tabs parts must be placed within <Tabs.Root>.");
8
+ return context;
9
+ }
10
+ export { TabsRootContext, useTabsRootContext };
@@ -0,0 +1,74 @@
1
+ import { warnUnlessButton } from "../../core/button.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { useTabsRootContext } from "../root/TabsRootContext.js";
5
+ import { isDev, spread, template } from "@solidjs/web";
6
+ import { omit, onSettled, untrack } from "solid-js";
7
+ // src/tabs/tab/TabsTab.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<button>`);
9
+ /**
10
+ * One tab, which shows its `Tabs.Panel` when selected: a
11
+ * `<button role="tab" aria-selected>`. Place it inside `Tabs.List`.
12
+ */
13
+ function TabsTab(props) {
14
+ const root = useTabsRootContext();
15
+ let element;
16
+ const selected = () => root.selected(props.value);
17
+ const select = () => {
18
+ if (!props.disabled) root.select(props.value);
19
+ };
20
+ const value = untrack(() => props.value);
21
+ root.claimFirst(value, untrack(() => !!props.disabled));
22
+ const id = () => props.id ?? root.generatedTabId(props.value);
23
+ root.tabIds[value] = id;
24
+ const ownProps = {
25
+ type: "button",
26
+ role: "tab",
27
+ get id() {
28
+ return id();
29
+ },
30
+ get "aria-selected"() {
31
+ return selected() ? "true" : "false";
32
+ },
33
+ get "aria-controls"() {
34
+ return root.panelId(props.value);
35
+ },
36
+ get "aria-disabled"() {
37
+ return props.disabled ? "true" : void 0;
38
+ },
39
+ get tabindex() {
40
+ return root.isTabStop(element, selected()) ? 0 : -1;
41
+ },
42
+ get "data-selected"() {
43
+ return selected() ? "" : void 0;
44
+ },
45
+ get "data-unselected"() {
46
+ return selected() ? void 0 : "";
47
+ },
48
+ get "data-disabled"() {
49
+ return props.disabled ? "" : void 0;
50
+ },
51
+ onClick: select,
52
+ onFocus: () => {
53
+ root.setFocused(element);
54
+ if (root.automatic()) select();
55
+ },
56
+ onBlur: () => root.setFocused(void 0),
57
+ onKeyDown: (event) => root.navigate(event, element),
58
+ ref: (el) => {
59
+ element = el;
60
+ if (isDev) warnUnlessButton(el, "Tabs.Tab");
61
+ }
62
+ };
63
+ onSettled(() => root.register({
64
+ element,
65
+ value: () => props.value
66
+ }));
67
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "disabled", "id"));
68
+ return renderElement(props, elementProps, (p) => (() => {
69
+ var _el$ = _tmpl$();
70
+ spread(_el$, p, false);
71
+ return _el$;
72
+ })());
73
+ }
74
+ export { TabsTab };
@@ -0,0 +1,44 @@
1
+ import { cookiePreference, cookieValue } from "../../core/preference/cookiePreference.js";
2
+ import { createThemeWithStorage, parseTheme, themeScriptWithStorage } from "../theme.js";
3
+ // src/theme/cookie/cookie.ts
4
+ var storage = cookiePreference;
5
+ /**
6
+ * The reader's choice of theme, saved in a cookie and applied to
7
+ * `<html>` (`ThemeOptions.attribute`). Stays in step with the other
8
+ * instances in this tab, and with other tabs once they are shown again.
9
+ *
10
+ * Call it in a component. The cookie is read during the first render, on
11
+ * the server from the request (`getRequestEvent()`), so the server's HTML
12
+ * shows the theme and hydration agrees. The page has to be rendered for
13
+ * each request: a prerendered page has no cookie to read.
14
+ */
15
+ function createTheme(options) {
16
+ return createThemeWithStorage(storage, options);
17
+ }
18
+ /**
19
+ * The source of a script for the document head that applies the theme
20
+ * saved in the cookie, or the default, before the page first paints. Pass
21
+ * the options given to `createTheme`. Render it inline, before any styles
22
+ * that depend on the theme. With the theme rendered on the server, it only
23
+ * applies what the server rendered, and can be left out.
24
+ *
25
+ * ```tsx
26
+ * <script innerHTML={themeScript(options)} />
27
+ * ```
28
+ *
29
+ * Under a Content Security Policy without `'unsafe-inline'`, put the
30
+ * policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
31
+ * SHA-256 hash of the returned source.
32
+ */
33
+ function themeScript(options) {
34
+ return themeScriptWithStorage(storage, options);
35
+ }
36
+ /**
37
+ * The theme saved in a `Cookie` request header, or the default, for a
38
+ * server that puts the attribute on its own `<html>`. Pass the options
39
+ * given to `createTheme`.
40
+ */
41
+ function themeFromCookie(cookieHeader, options) {
42
+ return parseTheme(cookieValue(cookieHeader, options.storageKey ?? "theme"), options);
43
+ }
44
+ export { createTheme, themeFromCookie, themeScript };
@@ -0,0 +1 @@
1
+ export { createTheme, themeFromCookie, themeScript } from "./cookie.js";
@@ -0,0 +1 @@
1
+ export { createTheme, themeScript } from "./localStorage.js";