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,50 @@
1
+ import { createMemo, createSignal } from "solid-js";
2
+ // src/core/rovingFocus.ts
3
+ var byPosition = (a, b) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
4
+ /**
5
+ * One tab stop among a group's items, with arrow keys between them (roving
6
+ * tabindex, PLAN.md section 8, "A group of items is one tab stop"): Toggle
7
+ * Group's items, Tabs' tabs. Pass the options as getters and functions, so
8
+ * they are read where they are used:
9
+ *
10
+ * ```ts
11
+ * const roving = createRovingFocus({
12
+ * get vertical() { return props.orientation === "vertical"; },
13
+ * focusable: (item) => !item.disabled(),
14
+ * preferred: (item) => item.element === active(),
15
+ * });
16
+ * ```
17
+ *
18
+ * Items register once mounted, so the order follows the document. The tab
19
+ * stop is the first `preferred` focusable item, else the first focusable
20
+ * one. Arrow keys move focus among the focusable items and wrap: Left and
21
+ * Right, mirrored right to left, or Up and Down when `vertical`, and Home
22
+ * and End. With a modifier held, the keys are left to the browser.
23
+ */
24
+ function createRovingFocus(options) {
25
+ const [items, setItems] = createSignal([]);
26
+ const focusable = () => items().filter(options.focusable).sort(byPosition);
27
+ const tabStop = createMemo(() => {
28
+ const list = focusable();
29
+ return (list.find(options.preferred) ?? list[0])?.element;
30
+ });
31
+ return {
32
+ register: (item) => {
33
+ setItems((list) => [...list, item]);
34
+ return () => setItems((list) => list.filter((other) => other !== item));
35
+ },
36
+ isTabStop: (element, fallback) => items().length ? !!element && tabStop() === element : fallback,
37
+ navigate: (event, from) => {
38
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
39
+ const list = focusable();
40
+ const count = list.length;
41
+ const index = list.findIndex((item) => item.element === from);
42
+ const [previous, next] = options.vertical ? ["ArrowUp", "ArrowDown"] : getComputedStyle(from).direction === "rtl" ? ["ArrowRight", "ArrowLeft"] : ["ArrowLeft", "ArrowRight"];
43
+ const target = event.key === previous ? index - 1 : event.key === next ? index + 1 : event.key === "Home" ? 0 : event.key === "End" ? count - 1 : void 0;
44
+ if (target === void 0 || !count) return;
45
+ event.preventDefault();
46
+ list[(target + count) % count].element.focus();
47
+ }
48
+ };
49
+ }
50
+ export { createRovingFocus };
@@ -0,0 +1,37 @@
1
+ import { twoStateButtonProps } from "./button.js";
2
+ import { merge } from "solid-js";
3
+ // src/core/toggleButton.ts
4
+ /**
5
+ * The own props of a part that is a toggle button, a native
6
+ * `<button type="button" aria-pressed>` (WAI-ARIA button pattern): Toggle's
7
+ * Root and Toggle Group's Item. `value` is whether it is pressed. Pass the
8
+ * state as getters, so it is read where the props are used:
9
+ *
10
+ * ```ts
11
+ * const own = toggleButtonProps(
12
+ * {
13
+ * get value() { return pressed(); },
14
+ * get disabled() { return props.disabled; },
15
+ * setValue: setPressed,
16
+ * },
17
+ * "Toggle.Root",
18
+ * );
19
+ * ```
20
+ *
21
+ * `part` names the part in the development warning of a `render` that is
22
+ * not a button.
23
+ */
24
+ function toggleButtonProps(state, part) {
25
+ return merge(twoStateButtonProps(state, "aria-pressed", part), {
26
+ get "data-pressed"() {
27
+ return state.value ? "" : void 0;
28
+ },
29
+ get "data-unpressed"() {
30
+ return state.value ? void 0 : "";
31
+ },
32
+ get "data-disabled"() {
33
+ return state.disabled ? "" : void 0;
34
+ }
35
+ });
36
+ }
37
+ export { toggleButtonProps };
@@ -0,0 +1,2 @@
1
+ import * as Meter from "./index.parts.js";
2
+ export { Meter };
@@ -0,0 +1,3 @@
1
+ import { MeterRoot } from "./root/MeterRoot.js";
2
+ import { MeterValue } from "./value/MeterValue.js";
3
+ export { MeterRoot as Root, MeterValue as Value };
@@ -0,0 +1,28 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { createRange } from "../../core/range.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { MeterRootContext } from "./MeterRootContext.js";
5
+ import { createComponent, spread, template } from "@solidjs/web";
6
+ import { omit } from "solid-js";
7
+ // src/meter/root/MeterRoot.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
9
+ /**
10
+ * The meter itself: a `<div role="meter">`.
11
+ */
12
+ function MeterRoot(props) {
13
+ const range = createRange(props, "meter", "--meter");
14
+ const elementProps = mergeElementProps(range.props, omit(props, "render", "value", "min", "max", "format", "locale"));
15
+ return createComponent(MeterRootContext, {
16
+ get value() {
17
+ return { valueText: range.valueText };
18
+ },
19
+ get children() {
20
+ return renderElement(props, elementProps, (p) => (() => {
21
+ var _el$ = _tmpl$();
22
+ spread(_el$, p, false);
23
+ return _el$;
24
+ })());
25
+ }
26
+ });
27
+ }
28
+ export { MeterRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/meter/root/MeterRootContext.ts
4
+ var MeterRootContext = createContext(null);
5
+ function useMeterRootContext() {
6
+ const context = useContext(MeterRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] Meter parts must be placed within <Meter.Root>.");
8
+ return context;
9
+ }
10
+ export { MeterRootContext, useMeterRootContext };
@@ -0,0 +1,24 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useMeterRootContext } from "../root/MeterRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { omit } from "solid-js";
6
+ // src/meter/value/MeterValue.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<span>`);
8
+ /**
9
+ * The value as text: a `<span>` with the Root's `aria-valuetext`, the
10
+ * consumer's or the value in the Root's `format` and `locale`. Place it
11
+ * inside `Meter.Root`.
12
+ */
13
+ function MeterValue(props) {
14
+ const context = useMeterRootContext();
15
+ const elementProps = mergeElementProps({ get children() {
16
+ return context.valueText();
17
+ } }, omit(props, "render"));
18
+ return renderElement(props, elementProps, (p) => (() => {
19
+ var _el$ = _tmpl$();
20
+ spread(_el$, p, false);
21
+ return _el$;
22
+ })());
23
+ }
24
+ export { MeterValue };
@@ -0,0 +1,2 @@
1
+ import * as Progress from "./index.parts.js";
2
+ export { Progress };
@@ -0,0 +1,4 @@
1
+ import { ProgressRoot } from "./root/ProgressRoot.js";
2
+ import { ProgressIndicator } from "./indicator/ProgressIndicator.js";
3
+ import { ProgressValue } from "./value/ProgressValue.js";
4
+ export { ProgressIndicator as Indicator, ProgressRoot as Root, ProgressValue as Value };
@@ -0,0 +1,21 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useProgressRootContext } from "../root/ProgressRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { omit } from "solid-js";
6
+ // src/progress/indicator/ProgressIndicator.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
8
+ /**
9
+ * The filled part of the bar: a `<div>` with the Root's `data-*` attributes.
10
+ * It draws nothing; size it with `--progress`, which it inherits from the
11
+ * Root. Place it inside `Progress.Root`.
12
+ */
13
+ function ProgressIndicator(props) {
14
+ const elementProps = mergeElementProps(useProgressRootContext().attributes, omit(props, "render"));
15
+ return renderElement(props, elementProps, (p) => (() => {
16
+ var _el$ = _tmpl$();
17
+ spread(_el$, p, false);
18
+ return _el$;
19
+ })());
20
+ }
21
+ export { ProgressIndicator };
@@ -0,0 +1,47 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { createRange } from "../../core/range.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { ProgressRootContext } from "./ProgressRootContext.js";
5
+ import { createComponent, spread, template } from "@solidjs/web";
6
+ import { merge, omit } from "solid-js";
7
+ // src/progress/root/ProgressRoot.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
9
+ /**
10
+ * The progress bar itself: a `<div role="progressbar">`.
11
+ */
12
+ function ProgressRoot(props) {
13
+ const range = createRange(props, "progressbar", "--progress");
14
+ const state = () => {
15
+ const fraction = range.fraction();
16
+ if (fraction === void 0) return "indeterminate";
17
+ return fraction === 1 ? "complete" : "progressing";
18
+ };
19
+ const attributes = {
20
+ get "data-indeterminate"() {
21
+ return state() === "indeterminate" ? "" : void 0;
22
+ },
23
+ get "data-progressing"() {
24
+ return state() === "progressing" ? "" : void 0;
25
+ },
26
+ get "data-complete"() {
27
+ return state() === "complete" ? "" : void 0;
28
+ }
29
+ };
30
+ const elementProps = mergeElementProps(merge(attributes, range.props), omit(props, "render", "value", "min", "max", "format", "locale"));
31
+ return createComponent(ProgressRootContext, {
32
+ get value() {
33
+ return {
34
+ attributes,
35
+ valueText: range.valueText
36
+ };
37
+ },
38
+ get children() {
39
+ return renderElement(props, elementProps, (p) => (() => {
40
+ var _el$ = _tmpl$();
41
+ spread(_el$, p, false);
42
+ return _el$;
43
+ })());
44
+ }
45
+ });
46
+ }
47
+ export { ProgressRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/progress/root/ProgressRootContext.ts
4
+ var ProgressRootContext = createContext(null);
5
+ function useProgressRootContext() {
6
+ const context = useContext(ProgressRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] Progress parts must be placed within <Progress.Root>.");
8
+ return context;
9
+ }
10
+ export { ProgressRootContext, useProgressRootContext };
@@ -0,0 +1,26 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { useProgressRootContext } from "../root/ProgressRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { merge, omit } from "solid-js";
6
+ // src/progress/value/ProgressValue.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<span>`);
8
+ /**
9
+ * The value as text: a `<span>` with the Root's `aria-valuetext`, the
10
+ * consumer's or the value in the Root's `format` and `locale`, and its
11
+ * `data-*` attributes. Empty while indeterminate, unless the consumer gave
12
+ * `aria-valuetext`. Place it inside `Progress.Root`.
13
+ */
14
+ function ProgressValue(props) {
15
+ const context = useProgressRootContext();
16
+ const ownProps = merge(context.attributes, { get children() {
17
+ return context.valueText();
18
+ } });
19
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
20
+ return renderElement(props, elementProps, (p) => (() => {
21
+ var _el$ = _tmpl$();
22
+ spread(_el$, p, false);
23
+ return _el$;
24
+ })());
25
+ }
26
+ export { ProgressValue };
@@ -0,0 +1,2 @@
1
+ import * as Separator from "./index.parts.js";
2
+ export { Separator };
@@ -0,0 +1 @@
1
+ export { SeparatorRoot as Root } from "./root/SeparatorRoot.js";
@@ -0,0 +1,31 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { spread, template } from "@solidjs/web";
4
+ import { omit } from "solid-js";
5
+ // src/separator/root/SeparatorRoot.tsx
6
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
7
+ /**
8
+ * A line between sections of content or groups of items: a
9
+ * `<div role="separator">`.
10
+ */
11
+ function SeparatorRoot(props) {
12
+ const vertical = () => props.orientation === "vertical";
13
+ const elementProps = mergeElementProps({
14
+ role: "separator",
15
+ get "aria-orientation"() {
16
+ return vertical() ? "vertical" : "horizontal";
17
+ },
18
+ get "data-horizontal"() {
19
+ return vertical() ? void 0 : "";
20
+ },
21
+ get "data-vertical"() {
22
+ return vertical() ? "" : void 0;
23
+ }
24
+ }, omit(props, "render", "orientation"));
25
+ return renderElement(props, elementProps, (p) => (() => {
26
+ var _el$ = _tmpl$();
27
+ spread(_el$, p, false);
28
+ return _el$;
29
+ })());
30
+ }
31
+ export { SeparatorRoot };
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface AccordionHeaderProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The heading of a section, which holds only its `Accordion.Trigger`: an
8
+ * `<h3>`. Render another level with `render={(props) => <h2 {...props} />}`.
9
+ * Place it inside `Accordion.Item`.
10
+ */
11
+ export declare function AccordionHeader(props: AccordionHeaderProps): JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useAccordionItemContext } from "../item/AccordionItemContext.js";
5
+ /**
6
+ * The heading of a section, which holds only its `Accordion.Trigger`: an
7
+ * `<h3>`. Render another level with `render={(props) => <h2 {...props} />}`.
8
+ * Place it inside `Accordion.Item`.
9
+ */
10
+ export function AccordionHeader(props) {
11
+ const item = useAccordionItemContext();
12
+ const elementProps = mergeElementProps(item.attributes, omit(props, "render"));
13
+ return renderElement(props, elementProps, (p) => <h3 {...p}/>);
14
+ }
@@ -0,0 +1 @@
1
+ export * as Accordion from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Accordion from "./index.parts.js";
@@ -0,0 +1,5 @@
1
+ export { AccordionRoot as Root } from "./root/AccordionRoot.tsx";
2
+ export { AccordionItem as Item } from "./item/AccordionItem.tsx";
3
+ export { AccordionHeader as Header } from "./header/AccordionHeader.tsx";
4
+ export { AccordionTrigger as Trigger } from "./trigger/AccordionTrigger.tsx";
5
+ export { AccordionPanel as Panel } from "./panel/AccordionPanel.tsx";
@@ -0,0 +1,5 @@
1
+ export { AccordionRoot as Root } from "./root/AccordionRoot.jsx";
2
+ export { AccordionItem as Item } from "./item/AccordionItem.jsx";
3
+ export { AccordionHeader as Header } from "./header/AccordionHeader.jsx";
4
+ export { AccordionTrigger as Trigger } from "./trigger/AccordionTrigger.jsx";
5
+ export { AccordionPanel as Panel } from "./panel/AccordionPanel.jsx";
@@ -0,0 +1,17 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface AccordionItemProps 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
+ /** Whether the Trigger ignores the user. It cannot be focused either. */
10
+ disabled?: boolean;
11
+ render?: RenderProp;
12
+ }
13
+ /**
14
+ * One section of the accordion: a `<div>` around `Accordion.Header` and
15
+ * `Accordion.Panel`. Place it inside `Accordion.Root`.
16
+ */
17
+ export declare function AccordionItem(props: AccordionItemProps): JSX.Element;
@@ -0,0 +1,42 @@
1
+ import { createUniqueId, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useAccordionRootContext } from "../root/AccordionRootContext.js";
5
+ import { AccordionItemContext } from "./AccordionItemContext.js";
6
+ /**
7
+ * One section of the accordion: a `<div>` around `Accordion.Header` and
8
+ * `Accordion.Panel`. Place it inside `Accordion.Root`.
9
+ */
10
+ export function AccordionItem(props) {
11
+ const root = useAccordionRootContext();
12
+ const panelId = createUniqueId();
13
+ const generatedTriggerId = createUniqueId();
14
+ // Without a value, the Panel's id serves as one: unique, and one
15
+ // `createUniqueId` fewer than a value of its own.
16
+ const value = () => props.value ?? panelId;
17
+ const open = () => root.open(value());
18
+ const disabled = () => !!(root.disabled() || props.disabled);
19
+ const attributes = {
20
+ get "data-open"() {
21
+ return open() ? "" : undefined;
22
+ },
23
+ get "data-closed"() {
24
+ return open() ? undefined : "";
25
+ },
26
+ get "data-disabled"() {
27
+ return disabled() ? "" : undefined;
28
+ },
29
+ };
30
+ const context = {
31
+ open,
32
+ setOpen: (next) => root.setOpen(value(), next),
33
+ disabled,
34
+ panelId,
35
+ triggerId: () => generatedTriggerId,
36
+ attributes,
37
+ };
38
+ const elementProps = mergeElementProps(attributes, omit(props, "render", "value", "disabled"));
39
+ return (<AccordionItemContext value={context}>
40
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
41
+ </AccordionItemContext>);
42
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * An Item's state as `data-*` attributes, each `""` when it applies and
3
+ * absent otherwise: one of `data-open` and `data-closed`, and
4
+ * `data-disabled`. Every part of the Item merges the same object, so its
5
+ * getters are read where each element uses them.
6
+ */
7
+ export type AccordionItemStateAttributes = {
8
+ readonly "data-open": "" | undefined;
9
+ readonly "data-closed": "" | undefined;
10
+ readonly "data-disabled": "" | undefined;
11
+ };
12
+ /** What an Item shares with its Header, Trigger and Panel. */
13
+ export interface AccordionItemContextValue {
14
+ /** Whether the Panel is shown. */
15
+ open(): boolean;
16
+ /** Asks to show or hide the Panel. */
17
+ setOpen(open: boolean): void;
18
+ /** Whether the Trigger ignores the user, by the Root's or the Item's. */
19
+ disabled(): boolean;
20
+ /** The Panel's `id`, which the Trigger names in `aria-controls`. */
21
+ readonly panelId: string;
22
+ /**
23
+ * The Trigger's `id`, which the Panel names in `aria-labelledby`: the
24
+ * generated one, until the Trigger, created before the Panel, replaces
25
+ * this with one that reads the consumer's `id` first. `false`, the
26
+ * consumer's way to remove an attribute, removes both.
27
+ */
28
+ triggerId: () => string | false;
29
+ /** The `data-*` attributes every part of the Item carries. */
30
+ readonly attributes: AccordionItemStateAttributes;
31
+ }
32
+ export declare const AccordionItemContext: import("solid-js").Context<AccordionItemContextValue | null>;
33
+ export declare function useAccordionItemContext(): AccordionItemContextValue;
@@ -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 AccordionItemContext = createContext(null);
5
+ export function useAccordionItemContext() {
6
+ const context = useContext(AccordionItemContext);
7
+ // Production builds drop the check, and its message, with `isDev`.
8
+ if (isDev && !context) {
9
+ throw new Error("[menhir] Accordion parts must be placed within <Accordion.Item>.");
10
+ }
11
+ return context;
12
+ }
@@ -0,0 +1,11 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface AccordionPanelProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "id"> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The content its section's Trigger shows and hides: a
8
+ * `<div role="region">` named by the Trigger, `hidden` while closed. Place
9
+ * it inside `Accordion.Item`, after `Accordion.Header`.
10
+ */
11
+ export declare function AccordionPanel(props: AccordionPanelProps): JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useAccordionItemContext } from "../item/AccordionItemContext.js";
5
+ /**
6
+ * The content its section's Trigger shows and hides: a
7
+ * `<div role="region">` named by the Trigger, `hidden` while closed. Place
8
+ * it inside `Accordion.Item`, after `Accordion.Header`.
9
+ */
10
+ export function AccordionPanel(props) {
11
+ const item = useAccordionItemContext();
12
+ const ownProps = merge(item.attributes, {
13
+ id: item.panelId,
14
+ role: "region",
15
+ get "aria-labelledby"() {
16
+ return item.triggerId();
17
+ },
18
+ get hidden() {
19
+ return !item.open();
20
+ },
21
+ });
22
+ const elementProps = mergeElementProps(ownProps,
23
+ // An `id` from untyped code would break the Trigger's `aria-controls`,
24
+ // so it is dropped too.
25
+ omit(props, "render", "id"));
26
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
27
+ }
@@ -0,0 +1,26 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface AccordionRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** The values of the open Items, when controlled. */
5
+ value?: string[];
6
+ /** The values of the Items open at first, when uncontrolled. */
7
+ defaultValue?: string[];
8
+ /**
9
+ * Called with the new values when the user opens or closes an Item. When
10
+ * controlled, the accordion changes only if `value` does.
11
+ */
12
+ onValueChange?: (value: string[]) => void;
13
+ /**
14
+ * Whether several Items can be open at once. Otherwise opening an Item
15
+ * closes the one open before.
16
+ */
17
+ multiple?: boolean;
18
+ /** Whether every Trigger ignores the user. They cannot be focused either. */
19
+ disabled?: boolean;
20
+ render?: RenderProp;
21
+ }
22
+ /**
23
+ * A stack of sections, each shown and hidden by its heading's button: a
24
+ * `<div>` around `Accordion.Item`s.
25
+ */
26
+ export declare function AccordionRoot(props: AccordionRootProps): JSX.Element;
@@ -0,0 +1,37 @@
1
+ import { omit } from "solid-js";
2
+ import { createListValue } from "../../core/listValue.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.jsx";
5
+ import { AccordionRootContext } from "./AccordionRootContext.js";
6
+ /**
7
+ * A stack of sections, each shown and hidden by its heading's button: a
8
+ * `<div>` around `Accordion.Item`s.
9
+ */
10
+ export function AccordionRoot(props) {
11
+ const open = createListValue({
12
+ get value() {
13
+ return props.value;
14
+ },
15
+ get defaultValue() {
16
+ return props.defaultValue;
17
+ },
18
+ get multiple() {
19
+ return props.multiple;
20
+ },
21
+ onChange: (value) => props.onValueChange?.(value),
22
+ });
23
+ const context = {
24
+ open: open.has,
25
+ setOpen: open.set,
26
+ disabled: () => props.disabled,
27
+ };
28
+ const ownProps = {
29
+ get "data-disabled"() {
30
+ return props.disabled ? "" : undefined;
31
+ },
32
+ };
33
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "multiple", "disabled"));
34
+ return (<AccordionRootContext value={context}>
35
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
36
+ </AccordionRootContext>);
37
+ }
@@ -0,0 +1,11 @@
1
+ /** What the Root shares with its Items. */
2
+ export interface AccordionRootContextValue {
3
+ /** Whether the Item with this value is open. */
4
+ open(value: string): boolean;
5
+ /** Asks to open or close the Item with this value. */
6
+ setOpen(value: string, open: boolean): void;
7
+ /** Whether every Trigger ignores the user. */
8
+ disabled(): boolean | undefined;
9
+ }
10
+ export declare const AccordionRootContext: import("solid-js").Context<AccordionRootContextValue | null>;
11
+ export declare function useAccordionRootContext(): AccordionRootContextValue;
@@ -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 AccordionRootContext = createContext(null);
6
+ export function useAccordionRootContext() {
7
+ const context = useContext(AccordionRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] Accordion.Item must be placed within <Accordion.Root>.");
11
+ }
12
+ return context;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface AccordionTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that shows and hides its section's Panel: a
8
+ * `<button aria-expanded>`. Place it inside `Accordion.Header`.
9
+ */
10
+ export declare function AccordionTrigger(props: AccordionTriggerProps): JSX.Element;