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,35 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { twoStateButtonProps } from "../../core/button.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.jsx";
5
+ import { useAccordionItemContext } from "../item/AccordionItemContext.js";
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 function AccordionTrigger(props) {
11
+ const item = useAccordionItemContext();
12
+ // The consumer's `id`, else the generated one, which the Panel, created
13
+ // after the Trigger, names. Kept out of the merge, where a wrapper's
14
+ // `id={undefined}` would remove it ("`undefined` is a value", PLAN.md
15
+ // section 8).
16
+ const generatedId = item.triggerId;
17
+ const id = () => props.id ?? generatedId();
18
+ item.triggerId = id;
19
+ const ownProps = merge(item.attributes, twoStateButtonProps({
20
+ get value() {
21
+ return item.open();
22
+ },
23
+ get disabled() {
24
+ return item.disabled();
25
+ },
26
+ setValue: item.setOpen,
27
+ }, "aria-expanded", "Accordion.Trigger"), {
28
+ get id() {
29
+ return id();
30
+ },
31
+ "aria-controls": item.panelId,
32
+ });
33
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
34
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
35
+ }
@@ -0,0 +1 @@
1
+ export * as Checkbox from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Checkbox from "./index.parts.js";
@@ -0,0 +1,2 @@
1
+ export { CheckboxRoot as Root } from "./root/CheckboxRoot.tsx";
2
+ export { CheckboxIndicator as Indicator } from "./indicator/CheckboxIndicator.tsx";
@@ -0,0 +1,2 @@
1
+ export { CheckboxRoot as Root } from "./root/CheckboxRoot.jsx";
2
+ export { CheckboxIndicator as Indicator } from "./indicator/CheckboxIndicator.jsx";
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface CheckboxIndicatorProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The check mark: a `<span>` with the Root's `data-*` attributes, always
8
+ * rendered, so that CSS shows it by state. Place it inside `Checkbox.Root`.
9
+ */
10
+ export declare function CheckboxIndicator(props: CheckboxIndicatorProps): JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useCheckboxRootContext } from "../root/CheckboxRootContext.js";
5
+ /**
6
+ * The check mark: a `<span>` with the Root's `data-*` attributes, always
7
+ * rendered, so that CSS shows it by state. Place it inside `Checkbox.Root`.
8
+ */
9
+ export function CheckboxIndicator(props) {
10
+ const elementProps = mergeElementProps(useCheckboxRootContext(), omit(props, "render"));
11
+ return renderElement(props, elementProps, (p) => <span {...p}/>);
12
+ }
@@ -0,0 +1,37 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface CheckboxRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** Whether the checkbox is checked, when controlled. */
5
+ checked?: boolean;
6
+ /** Whether the checkbox starts checked, when uncontrolled. */
7
+ defaultChecked?: boolean;
8
+ /**
9
+ * Called with the new value when the user checks or unchecks the
10
+ * checkbox, or its form is reset. When controlled, the checkbox changes
11
+ * only if `checked` does.
12
+ */
13
+ onCheckedChange?: (checked: boolean) => void;
14
+ /**
15
+ * Whether the checkbox is partly checked, such as the parent of a group
16
+ * whose children are only some checked. A click still asks for the
17
+ * opposite of `checked`.
18
+ */
19
+ indeterminate?: boolean;
20
+ /** Submitted with the form, as the hidden input's `name`. */
21
+ name?: string;
22
+ /** Submitted with the form while the checkbox is checked. The browser's default is `"on"`. */
23
+ value?: string;
24
+ /** Whether the checkbox ignores the user. It cannot be focused either. */
25
+ disabled?: boolean;
26
+ /** Whether the checkbox can be focused but not checked or unchecked. */
27
+ readOnly?: boolean;
28
+ /** Whether the form can be submitted only while the checkbox is checked. */
29
+ required?: boolean;
30
+ /** The `id` of the form the checkbox belongs to, when it is not inside it. */
31
+ form?: string;
32
+ render?: RenderProp;
33
+ }
34
+ /**
35
+ * The checkbox itself: a `<button role="checkbox">`.
36
+ */
37
+ export declare function CheckboxRoot(props: CheckboxRootProps): JSX.Element;
@@ -0,0 +1,135 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { merge, omit, onFlush, onSettled, untrack } from "solid-js";
3
+ import { warnUnlessButton } from "../../core/button.js";
4
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
5
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
6
+ import { renderElement } from "../../core/renderElement.jsx";
7
+ import { CheckboxRootContext } from "./CheckboxRootContext.js";
8
+ /**
9
+ * The checkbox itself: a `<button role="checkbox">`.
10
+ */
11
+ export function CheckboxRoot(props) {
12
+ const [checked, setChecked] = createControllableSignal({
13
+ get value() {
14
+ return props.checked;
15
+ },
16
+ get defaultValue() {
17
+ return props.defaultChecked ?? false;
18
+ },
19
+ onChange: (value) => props.onCheckedChange?.(value),
20
+ });
21
+ const stateAttributes = {
22
+ get "data-checked"() {
23
+ return !props.indeterminate && checked() ? "" : undefined;
24
+ },
25
+ get "data-unchecked"() {
26
+ return !props.indeterminate && !checked() ? "" : undefined;
27
+ },
28
+ get "data-indeterminate"() {
29
+ return props.indeterminate ? "" : undefined;
30
+ },
31
+ get "data-disabled"() {
32
+ return props.disabled ? "" : undefined;
33
+ },
34
+ get "data-readonly"() {
35
+ return props.readOnly ? "" : undefined;
36
+ },
37
+ get "data-required"() {
38
+ return props.required ? "" : undefined;
39
+ },
40
+ };
41
+ const buttonProps = {
42
+ role: "checkbox",
43
+ type: "button",
44
+ get disabled() {
45
+ return props.disabled;
46
+ },
47
+ // Solid 2.0 removes an attribute set to false, so spell the value out.
48
+ get "aria-checked"() {
49
+ if (props.indeterminate)
50
+ return "mixed";
51
+ return checked() ? "true" : "false";
52
+ },
53
+ get "aria-readonly"() {
54
+ return props.readOnly ? "true" : undefined;
55
+ },
56
+ get "aria-required"() {
57
+ return props.required ? "true" : undefined;
58
+ },
59
+ // The change goes through the hidden input, so that the form sees the
60
+ // native `input` and `change` events a checkbox fires.
61
+ onClick: () => input?.click(),
62
+ // A button clicks on Enter, a checkbox does not: the pattern names only
63
+ // Space. Canceling the key down keeps the browser from clicking.
64
+ onKeyDown: (event) => {
65
+ if (event.key === "Enter")
66
+ event.preventDefault();
67
+ },
68
+ ref: (element) => {
69
+ button = element;
70
+ // Production builds drop the check with `isDev`.
71
+ if (isDev)
72
+ warnUnlessButton(element, "Checkbox.Root");
73
+ },
74
+ };
75
+ let button;
76
+ let input;
77
+ // Puts the input back to the checkbox's value, once that has settled.
78
+ // The `checked` binding writes the DOM only when the value changes, so it
79
+ // does not undo a change of the input that the checkbox did not take.
80
+ const syncInput = () => {
81
+ if (input)
82
+ input.checked = untrack(checked);
83
+ };
84
+ const onInputChange = () => {
85
+ if (!input)
86
+ return;
87
+ setChecked(input.checked);
88
+ // The browser has already changed the input, so the form's own
89
+ // listeners, which run after this one, see the new value. The two
90
+ // differ afterwards only when a controlled checkbox's consumer declined
91
+ // the change.
92
+ onFlush(syncInput);
93
+ };
94
+ const onInputClick = (event) => {
95
+ // The click the button sends the input is an implementation detail:
96
+ // ancestors already received the user's click.
97
+ event.stopPropagation();
98
+ // Canceling the click keeps the checkbox as it was and fires no
99
+ // `input` or `change` event, whoever clicked it.
100
+ if (props.readOnly)
101
+ event.preventDefault();
102
+ };
103
+ // A form reset puts a checkbox back to its default, and so it does this
104
+ // one: through the setter, so that a controlled checkbox asks.
105
+ onSettled(() => {
106
+ const form = input?.form;
107
+ if (!form)
108
+ return;
109
+ const onReset = () => {
110
+ setChecked(props.defaultChecked ?? false);
111
+ // The browser resets the input after this event, to its `checked`
112
+ // attribute, which the binding does not set. `onFlush` runs after
113
+ // that, as the event has finished by then.
114
+ onFlush(syncInput);
115
+ };
116
+ form.addEventListener("reset", onReset);
117
+ return () => form.removeEventListener("reset", onReset);
118
+ });
119
+ const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "checked", "defaultChecked", "onCheckedChange", "indeterminate", "name", "value", "disabled", "readOnly", "required", "form"));
120
+ return (<CheckboxRootContext value={stateAttributes}>
121
+ {renderElement(props, elementProps, (p) => (<button {...p}/>))}
122
+ <input type="checkbox" aria-hidden="true" tabindex={-1} style={visuallyHidden} name={props.name} value={props.value} disabled={props.disabled} required={props.required} form={props.form} checked={checked()} onChange={onInputChange}
123
+ // The browser focuses an invalid input when it blocks a submission.
124
+ // The user knows the checkbox, not the hidden input.
125
+ onFocus={() => button?.focus()} ref={(element) => {
126
+ input = element;
127
+ // Solid delegates click handlers to the document, so this one is
128
+ // a native listener, to act before the click bubbles.
129
+ element.addEventListener("click", onInputClick);
130
+ }}/>
131
+ </CheckboxRootContext>);
132
+ }
133
+ // Hidden from sight but not from the form. Not `display: none`, so the
134
+ // browser can still anchor a validation message to it.
135
+ const visuallyHidden = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The checkbox's state as `data-*` attributes, each `""` when it applies and
3
+ * absent otherwise. Exactly one of `data-checked`, `data-unchecked` and
4
+ * `data-indeterminate` applies at a time. Root and Indicator both spread the
5
+ * same object, so its getters are read where each element uses them.
6
+ */
7
+ export type CheckboxStateAttributes = {
8
+ readonly "data-checked": "" | undefined;
9
+ readonly "data-unchecked": "" | undefined;
10
+ readonly "data-indeterminate": "" | undefined;
11
+ readonly "data-disabled": "" | undefined;
12
+ readonly "data-readonly": "" | undefined;
13
+ readonly "data-required": "" | undefined;
14
+ };
15
+ export declare const CheckboxRootContext: import("solid-js").Context<CheckboxStateAttributes | null>;
16
+ export declare function useCheckboxRootContext(): CheckboxStateAttributes;
@@ -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 CheckboxRootContext = createContext(null);
6
+ export function useCheckboxRootContext() {
7
+ const context = useContext(CheckboxRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] Checkbox parts must be placed within <Checkbox.Root>.");
11
+ }
12
+ return context;
13
+ }
@@ -0,0 +1 @@
1
+ export * as Collapsible from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as Collapsible from "./index.parts.js";
@@ -0,0 +1,3 @@
1
+ export { CollapsibleRoot as Root } from "./root/CollapsibleRoot.tsx";
2
+ export { CollapsibleTrigger as Trigger } from "./trigger/CollapsibleTrigger.tsx";
3
+ export { CollapsiblePanel as Panel } from "./panel/CollapsiblePanel.tsx";
@@ -0,0 +1,3 @@
1
+ export { CollapsibleRoot as Root } from "./root/CollapsibleRoot.jsx";
2
+ export { CollapsibleTrigger as Trigger } from "./trigger/CollapsibleTrigger.jsx";
3
+ export { CollapsiblePanel as Panel } from "./panel/CollapsiblePanel.jsx";
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface CollapsiblePanelProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "id"> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The content the Trigger shows and hides: a `<div>`, `hidden` while
8
+ * closed. Place it inside `Collapsible.Root`.
9
+ */
10
+ export declare function CollapsiblePanel(props: CollapsiblePanelProps): JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useCollapsibleRootContext } from "../root/CollapsibleRootContext.js";
5
+ /**
6
+ * The content the Trigger shows and hides: a `<div>`, `hidden` while
7
+ * closed. Place it inside `Collapsible.Root`.
8
+ */
9
+ export function CollapsiblePanel(props) {
10
+ const root = useCollapsibleRootContext();
11
+ const ownProps = merge(root.attributes, {
12
+ id: root.panelId,
13
+ get hidden() {
14
+ return !root.open();
15
+ },
16
+ });
17
+ const elementProps = mergeElementProps(ownProps,
18
+ // An `id` from untyped code would break the Trigger's `aria-controls`,
19
+ // so it is dropped too.
20
+ omit(props, "render", "id"));
21
+ return renderElement(props, elementProps, (p) => <div {...p}/>);
22
+ }
@@ -0,0 +1,21 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface CollapsibleRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** Whether the Panel is shown, when controlled. */
5
+ open?: boolean;
6
+ /** Whether the Panel is shown at first, when uncontrolled. */
7
+ defaultOpen?: boolean;
8
+ /**
9
+ * Called with the new value when the user shows or hides the Panel. When
10
+ * controlled, the Panel changes only if `open` does.
11
+ */
12
+ onOpenChange?: (open: boolean) => void;
13
+ /** Whether the Trigger ignores the user. It cannot be focused either. */
14
+ disabled?: boolean;
15
+ render?: RenderProp;
16
+ }
17
+ /**
18
+ * A section of content that a button shows and hides: a `<div>` around
19
+ * `Collapsible.Trigger` and `Collapsible.Panel`.
20
+ */
21
+ export declare function CollapsibleRoot(props: CollapsibleRootProps): JSX.Element;
@@ -0,0 +1,42 @@
1
+ import { createUniqueId, 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 { CollapsibleRootContext } from "./CollapsibleRootContext.js";
6
+ /**
7
+ * A section of content that a button shows and hides: a `<div>` around
8
+ * `Collapsible.Trigger` and `Collapsible.Panel`.
9
+ */
10
+ export function CollapsibleRoot(props) {
11
+ const [open, setOpen] = createControllableSignal({
12
+ get value() {
13
+ return props.open;
14
+ },
15
+ get defaultValue() {
16
+ return props.defaultOpen ?? false;
17
+ },
18
+ onChange: (value) => props.onOpenChange?.(value),
19
+ });
20
+ const attributes = {
21
+ get "data-open"() {
22
+ return open() ? "" : undefined;
23
+ },
24
+ get "data-closed"() {
25
+ return open() ? undefined : "";
26
+ },
27
+ get "data-disabled"() {
28
+ return props.disabled ? "" : undefined;
29
+ },
30
+ };
31
+ const context = {
32
+ open,
33
+ setOpen,
34
+ disabled: () => props.disabled,
35
+ panelId: createUniqueId(),
36
+ attributes,
37
+ };
38
+ const elementProps = mergeElementProps(attributes, omit(props, "render", "open", "defaultOpen", "onOpenChange", "disabled"));
39
+ return (<CollapsibleRootContext value={context}>
40
+ {renderElement(props, elementProps, (p) => (<div {...p}/>))}
41
+ </CollapsibleRootContext>);
42
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The collapsible's state as `data-*` attributes, each `""` when it applies
3
+ * and absent otherwise: one of `data-open` and `data-closed`, and
4
+ * `data-disabled`. Every part merges the same object, so its getters are
5
+ * read where each element uses them.
6
+ */
7
+ export type CollapsibleStateAttributes = {
8
+ readonly "data-open": "" | undefined;
9
+ readonly "data-closed": "" | undefined;
10
+ readonly "data-disabled": "" | undefined;
11
+ };
12
+ /** What the Root shares with its parts. */
13
+ export interface CollapsibleRootContextValue {
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. */
19
+ disabled(): boolean | undefined;
20
+ /** The Panel's `id`, which the Trigger names in `aria-controls`. */
21
+ readonly panelId: string;
22
+ /** The `data-*` attributes every part carries. */
23
+ readonly attributes: CollapsibleStateAttributes;
24
+ }
25
+ export declare const CollapsibleRootContext: import("solid-js").Context<CollapsibleRootContextValue | null>;
26
+ export declare function useCollapsibleRootContext(): CollapsibleRootContextValue;
@@ -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 CollapsibleRootContext = createContext(null);
6
+ export function useCollapsibleRootContext() {
7
+ const context = useContext(CollapsibleRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] Collapsible parts must be placed within <Collapsible.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 CollapsibleTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that shows and hides the Panel: a `<button aria-expanded>`.
8
+ * Place it inside `Collapsible.Root`.
9
+ */
10
+ export declare function CollapsibleTrigger(props: CollapsibleTriggerProps): JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { merge, omit } from "solid-js";
2
+ import { twoStateButtonProps } from "../../core/button.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { renderElement } from "../../core/renderElement.jsx";
5
+ import { useCollapsibleRootContext } from "../root/CollapsibleRootContext.js";
6
+ /**
7
+ * The button that shows and hides the Panel: a `<button aria-expanded>`.
8
+ * Place it inside `Collapsible.Root`.
9
+ */
10
+ export function CollapsibleTrigger(props) {
11
+ const root = useCollapsibleRootContext();
12
+ const ownProps = merge(root.attributes, twoStateButtonProps({
13
+ get value() {
14
+ return root.open();
15
+ },
16
+ get disabled() {
17
+ return root.disabled();
18
+ },
19
+ setValue: root.setOpen,
20
+ }, "aria-expanded", "Collapsible.Trigger"), { "aria-controls": root.panelId });
21
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
22
+ return renderElement(props, elementProps, (p) => <button {...p}/>);
23
+ }
@@ -0,0 +1,35 @@
1
+ /** The reader's choice: a fixed look, or whatever the system prefers. */
2
+ export type ColorScheme = "light" | "dark" | "system";
3
+ /** The look on screen: a scheme with `system` replaced by the preference. */
4
+ export type ResolvedColorScheme = "light" | "dark";
5
+ export interface ColorSchemeOptions {
6
+ /**
7
+ * The `localStorage` key, or the cookie name, the choice is saved under.
8
+ * Default `"color-scheme"`.
9
+ */
10
+ storageKey?: string;
11
+ /**
12
+ * Where the resolved scheme goes on `<html>`: a `data-*` attribute set to
13
+ * `light` or `dark` (default `"data-color-scheme"`), or `"class"` for a `light`
14
+ * or `dark` class.
15
+ */
16
+ attribute?: "class" | `data-${string}`;
17
+ }
18
+ export declare const defaultStorageKey = "color-scheme";
19
+ /** The fixed schemes: every value that is saved, and every look. */
20
+ export declare const resolvedSchemes: readonly ResolvedColorScheme[];
21
+ export declare const defaultAttribute = "data-color-scheme";
22
+ /** The media query whose match means the system prefers dark. */
23
+ export declare const darkQuery = "(prefers-color-scheme: dark)";
24
+ /** `scheme` as it looks when the system prefers `system`. */
25
+ export declare function resolveColorScheme(scheme: ColorScheme, system: ResolvedColorScheme): ResolvedColorScheme;
26
+ /**
27
+ * The scheme a single cycling toggle moves to next, so that a click from
28
+ * `system` always changes the look: `system`, then the opposite of the
29
+ * system's look, then the system's look, then `system` again. Three schemes
30
+ * share two looks, so one click per round leaves the look as it is: the one
31
+ * back to `system`.
32
+ */
33
+ export declare function nextColorScheme(scheme: ColorScheme, system: ResolvedColorScheme): ColorScheme;
34
+ /** A stored value as a scheme; anything else, including none, is `system`. */
35
+ export declare function parseColorScheme(value: string | null | undefined): ColorScheme;
@@ -0,0 +1,30 @@
1
+ import { parsePreference } from "../core/preference/preference.js";
2
+ export const defaultStorageKey = "color-scheme";
3
+ /** The fixed schemes: every value that is saved, and every look. */
4
+ export const resolvedSchemes = [
5
+ "light",
6
+ "dark",
7
+ ];
8
+ export const defaultAttribute = "data-color-scheme";
9
+ /** The media query whose match means the system prefers dark. */
10
+ export const darkQuery = "(prefers-color-scheme: dark)";
11
+ /** `scheme` as it looks when the system prefers `system`. */
12
+ export function resolveColorScheme(scheme, system) {
13
+ return scheme === "system" ? system : scheme;
14
+ }
15
+ /**
16
+ * The scheme a single cycling toggle moves to next, so that a click from
17
+ * `system` always changes the look: `system`, then the opposite of the
18
+ * system's look, then the system's look, then `system` again. Three schemes
19
+ * share two looks, so one click per round leaves the look as it is: the one
20
+ * back to `system`.
21
+ */
22
+ export function nextColorScheme(scheme, system) {
23
+ if (scheme === "system")
24
+ return system === "dark" ? "light" : "dark";
25
+ return scheme === system ? "system" : system;
26
+ }
27
+ /** A stored value as a scheme; anything else, including none, is `system`. */
28
+ export function parseColorScheme(value) {
29
+ return parsePreference(value, resolvedSchemes, "system");
30
+ }
@@ -0,0 +1,8 @@
1
+ import type { PreferenceStorage } from "../core/preference/preference.ts";
2
+ import type { ColorSchemeOptions } from "./colorScheme.ts";
3
+ /**
4
+ * `colorSchemeScript` of each entry point, with the entry point's storage: the
5
+ * source of a script for the document head that applies the saved choice,
6
+ * or the system preference, before the page first paints.
7
+ */
8
+ export declare function colorSchemeScriptWithStorage(storage: PreferenceStorage, options?: ColorSchemeOptions): string;
@@ -0,0 +1,16 @@
1
+ import { scriptLiteral } from "../core/preference/preference.js";
2
+ import { preferenceScript } from "../core/preference/preferenceScript.js";
3
+ import { resolvedSchemes, darkQuery, defaultAttribute, defaultStorageKey, } from "./colorScheme.js";
4
+ /**
5
+ * `colorSchemeScript` of each entry point, with the entry point's storage: the
6
+ * source of a script for the document head that applies the saved choice,
7
+ * or the system preference, before the page first paints.
8
+ */
9
+ export function colorSchemeScriptWithStorage(storage, options = {}) {
10
+ return preferenceScript(storage, {
11
+ storageKey: options.storageKey ?? defaultStorageKey,
12
+ attribute: options.attribute ?? defaultAttribute,
13
+ values: resolvedSchemes,
14
+ fallback: `matchMedia(${scriptLiteral(darkQuery)}).matches?"dark":"light"`,
15
+ });
16
+ }
@@ -0,0 +1,39 @@
1
+ import type { ColorScheme, ColorSchemeOptions } from "../colorScheme.ts";
2
+ import type { ColorSchemeState } from "../createColorScheme.ts";
3
+ /**
4
+ * The reader's light, dark or system choice, saved in a cookie and applied
5
+ * to `<html>` (`ColorSchemeOptions.attribute`). Follows the system preference
6
+ * while the choice is `system`, and stays in step with the other instances
7
+ * in this tab, and with other tabs once they are shown again.
8
+ *
9
+ * Call it in a component. The cookie is read during the first render, on
10
+ * the server from the request (`getRequestEvent()`), so the server's HTML
11
+ * shows the choice and hydration agrees. Only `system` waits until the page
12
+ * has settled, since the server cannot see the system's preference. The
13
+ * page has to be rendered for each request: a prerendered page has no
14
+ * cookie to read. The head script from `colorSchemeScript`, with the same
15
+ * options, applies a `system` choice before the first paint.
16
+ */
17
+ export declare function createColorScheme(options?: ColorSchemeOptions): ColorSchemeState;
18
+ /**
19
+ * The source of a script for the document head that applies the choice
20
+ * saved in the cookie, or the system preference, before the page first
21
+ * paints. Pass the options given to `createColorScheme`. Render it inline,
22
+ * before any styles that depend on the scheme, even when the server renders
23
+ * the choice: it is what applies `system`.
24
+ *
25
+ * ```tsx
26
+ * <script innerHTML={colorSchemeScript()} />
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
+ export declare function colorSchemeScript(options?: ColorSchemeOptions): string;
34
+ /**
35
+ * The scheme saved in a `Cookie` request header, for a server that puts the
36
+ * attribute on its own `<html>`. Pass the options given to
37
+ * `createColorScheme`.
38
+ */
39
+ export declare function colorSchemeFromCookie(cookieHeader: string | null | undefined, options?: Pick<ColorSchemeOptions, "storageKey">): ColorScheme;