menhir 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,7 +62,7 @@ For everything else, go to the docs:
62
62
 
63
63
  Early 0.x versions: the API may change between minor versions. The form components come next; the plan and roadmap are in the [repository](https://github.com/j13n/menhir). Built so far:
64
64
 
65
- - Components: Accordion, Alert Dialog, Autocomplete, Checkbox, Collapsible, Combobox, Context Menu, Dialog, Field, Form, Input, Menu, Menubar, Meter, Navigation Menu, Popover, Progress, Select, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
65
+ - Components: Accordion, Alert Dialog, Autocomplete, Checkbox, Checkbox Group, Collapsible, Combobox, Context Menu, Dialog, Field, Form, Input, Menu, Menubar, Meter, Navigation Menu, Popover, Progress, Select, Separator, Switch, Tabs, Toggle, Toggle Group and Tooltip.
66
66
  - Utilities: color scheme and theme, each with local-storage and cookie storage.
67
67
 
68
68
  ## Licence
@@ -0,0 +1,2 @@
1
+ import * as CheckboxGroup from "./index.parts.js";
2
+ export { CheckboxGroup };
@@ -0,0 +1,5 @@
1
+ import { CheckboxGroupRoot } from "./root/CheckboxGroupRoot.js";
2
+ import { CheckboxGroupItem } from "./item/CheckboxGroupItem.js";
3
+ import { CheckboxGroupParent } from "./parent/CheckboxGroupParent.js";
4
+ import { CheckboxIndicator } from "../checkbox/indicator/CheckboxIndicator.js";
5
+ export { CheckboxIndicator as Indicator, CheckboxGroupItem as Item, CheckboxGroupParent as Parent, CheckboxGroupRoot as Root };
@@ -0,0 +1,40 @@
1
+ import { CheckboxRoot } from "../../checkbox/root/CheckboxRoot.js";
2
+ import { useCheckboxGroupRootContext } from "../root/CheckboxGroupRootContext.js";
3
+ import { createComponent } from "@solidjs/web";
4
+ import { createMemo, merge, omit } from "solid-js";
5
+ // src/checkbox-group/item/CheckboxGroupItem.tsx
6
+ /**
7
+ * One box of the group: a `Checkbox.Root`, checked while the group's value
8
+ * has its `value`. Place it inside `CheckboxGroup.Root`.
9
+ */
10
+ function CheckboxGroupItem(props) {
11
+ const group = useCheckboxGroupRootContext();
12
+ const checked = createMemo(() => group.value().includes(props.value));
13
+ const checkboxProps = merge(omit(props, "value", "disabled"), {
14
+ get checked() {
15
+ return checked();
16
+ },
17
+ get defaultChecked() {
18
+ return checked();
19
+ },
20
+ onCheckedChange: (included) => {
21
+ const next = group.requested().filter((item) => item !== props.value);
22
+ if (included) next.push(props.value);
23
+ group.setValue(next);
24
+ },
25
+ get name() {
26
+ return group.name();
27
+ },
28
+ get value() {
29
+ return props.value;
30
+ },
31
+ get form() {
32
+ return group.form();
33
+ },
34
+ get disabled() {
35
+ return group.disabled() || props.disabled;
36
+ }
37
+ });
38
+ return createComponent(CheckboxRoot, checkboxProps);
39
+ }
40
+ export { CheckboxGroupItem };
@@ -0,0 +1,55 @@
1
+ import { CheckboxRoot } from "../../checkbox/root/CheckboxRoot.js";
2
+ import { useCheckboxGroupRootContext } from "../root/CheckboxGroupRootContext.js";
3
+ import { createComponent } from "@solidjs/web";
4
+ import { createMemo, merge, omit } from "solid-js";
5
+ // src/checkbox-group/parent/CheckboxGroupParent.tsx
6
+ /**
7
+ * A checkbox over the group's boxes: a `Checkbox.Root`, checked while every
8
+ * box of `values` is, mixed while some are. A click on a mixed parent checks
9
+ * all, on a checked one unchecks all, and on an unchecked one brings back
10
+ * the boxes checked when it was last mixed, or checks all. It submits
11
+ * nothing. Place it inside `CheckboxGroup.Root`.
12
+ */
13
+ function CheckboxGroupParent(props) {
14
+ const group = useCheckboxGroupRootContext();
15
+ let set;
16
+ const boxes = createMemo((previous) => {
17
+ const list = group.value();
18
+ const checked = props.values.filter((item) => list.includes(item));
19
+ return {
20
+ checked,
21
+ remembered: previous && list === set ? previous.remembered : checked
22
+ };
23
+ });
24
+ const allChecked = createMemo(() => props.values.length > 0 && boxes().checked.length === props.values.length);
25
+ const someChecked = createMemo(() => boxes().checked.length > 0);
26
+ const checkboxProps = merge(omit(props, "values", "disabled"), {
27
+ get checked() {
28
+ return allChecked();
29
+ },
30
+ get defaultChecked() {
31
+ return allChecked();
32
+ },
33
+ get indeterminate() {
34
+ return someChecked() && !allChecked();
35
+ },
36
+ onCheckedChange: (checked) => {
37
+ const values = props.values;
38
+ const current = group.requested();
39
+ const others = current.filter((item) => !values.includes(item));
40
+ const { remembered } = boxes();
41
+ let next = others;
42
+ if (checked) next = values.some((item) => current.includes(item)) || remembered.length === 0 ? [...current, ...values.filter((item) => !current.includes(item))] : [...others, ...remembered];
43
+ set = next;
44
+ group.setValue(next);
45
+ },
46
+ get form() {
47
+ return group.form();
48
+ },
49
+ get disabled() {
50
+ return group.disabled() || props.disabled;
51
+ }
52
+ });
53
+ return createComponent(CheckboxRoot, checkboxProps);
54
+ }
55
+ export { CheckboxGroupParent };
@@ -0,0 +1,89 @@
1
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { CheckboxGroupRootContext } from "./CheckboxGroupRootContext.js";
5
+ import { createComponent, effect, memo, ref, setAttribute, spread, template } from "@solidjs/web";
6
+ import { createUniqueId, omit, onSettled } from "solid-js";
7
+ // src/checkbox-group/root/CheckboxGroupRoot.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<input type=radio 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>`);
9
+ var _tmpl$2 = /* @__PURE__ */ template(`<fieldset>`);
10
+ /**
11
+ * The group: a `<fieldset>` around `CheckboxGroup.Item`s, named by a
12
+ * `<legend>`, that holds the values of the checked boxes.
13
+ */
14
+ function CheckboxGroupRoot(props) {
15
+ const [value, setValue, requested] = 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
+ const context = {
25
+ value,
26
+ requested,
27
+ setValue: (next) => setValue(next),
28
+ name: () => props.name,
29
+ form: () => props.form,
30
+ disabled: () => props.disabled
31
+ };
32
+ const validityName = createUniqueId();
33
+ let root;
34
+ let input;
35
+ onSettled(() => {
36
+ const form = input?.form;
37
+ if (!form) return;
38
+ const onReset = () => setValue(props.defaultValue ?? []);
39
+ form.addEventListener("reset", onReset);
40
+ return () => form.removeEventListener("reset", onReset);
41
+ });
42
+ const elementProps = mergeElementProps({
43
+ get disabled() {
44
+ return props.disabled;
45
+ },
46
+ get "data-disabled"() {
47
+ return props.disabled ? "" : void 0;
48
+ },
49
+ get "data-required"() {
50
+ return props.required ? "" : void 0;
51
+ },
52
+ ref: (element) => {
53
+ root = element;
54
+ }
55
+ }, omit(props, "render", "value", "defaultValue", "onValueChange", "name", "disabled", "required", "form"));
56
+ return createComponent(CheckboxGroupRootContext, {
57
+ value: context,
58
+ get children() {
59
+ return [memo(() => {
60
+ return renderElement(props, elementProps, (p) => (() => {
61
+ var _el$2 = _tmpl$2();
62
+ spread(_el$2, p, false);
63
+ return _el$2;
64
+ })());
65
+ }), (() => {
66
+ var _el$ = _tmpl$();
67
+ _el$.addEventListener("focus", () => root?.querySelector("[role=checkbox]:enabled")?.focus());
68
+ setAttribute(_el$, "name", validityName);
69
+ var _ref$ = input;
70
+ typeof _ref$ === "function" || Array.isArray(_ref$) ? ref(() => {
71
+ return _ref$;
72
+ }, _el$) : input = _el$;
73
+ effect(() => {
74
+ return {
75
+ e: props.disabled,
76
+ t: props.required && value().length === 0,
77
+ a: props.form
78
+ };
79
+ }, ({ e, t, a }, _p$) => {
80
+ e !== _p$?.e && setAttribute(_el$, "disabled", e);
81
+ t !== _p$?.t && setAttribute(_el$, "required", t);
82
+ a !== _p$?.a && setAttribute(_el$, "form", a);
83
+ });
84
+ return _el$;
85
+ })()];
86
+ }
87
+ });
88
+ }
89
+ export { CheckboxGroupRoot };
@@ -0,0 +1,10 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createContext, useContext } from "solid-js";
3
+ // src/checkbox-group/root/CheckboxGroupRootContext.ts
4
+ var CheckboxGroupRootContext = createContext(null);
5
+ function useCheckboxGroupRootContext() {
6
+ const context = useContext(CheckboxGroupRootContext);
7
+ if (isDev && !context) throw new Error("[menhir] CheckboxGroup parts must be placed within <CheckboxGroup.Root>.");
8
+ return context;
9
+ }
10
+ export { CheckboxGroupRootContext, useCheckboxGroupRootContext };
@@ -0,0 +1 @@
1
+ export * as CheckboxGroup from "./index.parts.ts";
@@ -0,0 +1 @@
1
+ export * as CheckboxGroup from "./index.parts.js";
@@ -0,0 +1,4 @@
1
+ export { CheckboxGroupRoot as Root } from "./root/CheckboxGroupRoot.tsx";
2
+ export { CheckboxGroupItem as Item } from "./item/CheckboxGroupItem.tsx";
3
+ export { CheckboxGroupParent as Parent } from "./parent/CheckboxGroupParent.tsx";
4
+ export { CheckboxIndicator as Indicator } from "../checkbox/indicator/CheckboxIndicator.tsx";
@@ -0,0 +1,4 @@
1
+ export { CheckboxGroupRoot as Root } from "./root/CheckboxGroupRoot.jsx";
2
+ export { CheckboxGroupItem as Item } from "./item/CheckboxGroupItem.jsx";
3
+ export { CheckboxGroupParent as Parent } from "./parent/CheckboxGroupParent.jsx";
4
+ export { CheckboxIndicator as Indicator } from "../checkbox/indicator/CheckboxIndicator.jsx";
@@ -0,0 +1,10 @@
1
+ import type { CheckboxRootProps } from "../../checkbox/root/CheckboxRoot.tsx";
2
+ export interface CheckboxGroupItemProps extends Omit<CheckboxRootProps, "checked" | "defaultChecked" | "onCheckedChange" | "indeterminate" | "name" | "value" | "required" | "form"> {
3
+ /** Identifies the box in the group's value, and is submitted while it is checked. */
4
+ value: string;
5
+ }
6
+ /**
7
+ * One box of the group: a `Checkbox.Root`, checked while the group's value
8
+ * has its `value`. Place it inside `CheckboxGroup.Root`.
9
+ */
10
+ export declare function CheckboxGroupItem(props: CheckboxGroupItemProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { createMemo, merge, omit } from "solid-js";
2
+ import { CheckboxRoot } from "../../checkbox/root/CheckboxRoot.jsx";
3
+ import { useCheckboxGroupRootContext } from "../root/CheckboxGroupRootContext.js";
4
+ /**
5
+ * One box of the group: a `Checkbox.Root`, checked while the group's value
6
+ * has its `value`. Place it inside `CheckboxGroup.Root`.
7
+ */
8
+ export function CheckboxGroupItem(props) {
9
+ const group = useCheckboxGroupRootContext();
10
+ // A memo, so that a change to the list that leaves this box as it was
11
+ // does not run the box's bindings again: a hidden input the user changed
12
+ // in the same turn, not yet in the list, would be written back over.
13
+ const checked = createMemo(() => group.value().includes(props.value));
14
+ const own = {
15
+ get checked() {
16
+ return checked();
17
+ },
18
+ // The group puts the list back on a form reset, once. Checkbox's own
19
+ // reset asks for `defaultChecked`, so passing the box's state makes it
20
+ // ask for nothing, and put its hidden input back to that state.
21
+ get defaultChecked() {
22
+ return checked();
23
+ },
24
+ onCheckedChange: (included) => {
25
+ // Reads lag writes, so a second change before the flush builds on
26
+ // the first, not on what `value` still reads.
27
+ const next = group.requested().filter((item) => item !== props.value);
28
+ if (included)
29
+ next.push(props.value);
30
+ group.setValue(next);
31
+ },
32
+ get name() {
33
+ return group.name();
34
+ },
35
+ get value() {
36
+ return props.value;
37
+ },
38
+ get form() {
39
+ return group.form();
40
+ },
41
+ get disabled() {
42
+ return group.disabled() || props.disabled;
43
+ },
44
+ };
45
+ const checkboxProps = merge(omit(props, "value", "disabled"), own);
46
+ return <CheckboxRoot {...checkboxProps}/>;
47
+ }
@@ -0,0 +1,17 @@
1
+ import type { CheckboxRootProps } from "../../checkbox/root/CheckboxRoot.tsx";
2
+ export interface CheckboxGroupParentProps extends Omit<CheckboxRootProps, "checked" | "defaultChecked" | "onCheckedChange" | "indeterminate" | "name" | "value" | "required" | "form"> {
3
+ /**
4
+ * The values of the boxes the parent checks and unchecks, usually every
5
+ * Item's. It is checked while the group's value has all of them, mixed
6
+ * while it has some.
7
+ */
8
+ values: string[];
9
+ }
10
+ /**
11
+ * A checkbox over the group's boxes: a `Checkbox.Root`, checked while every
12
+ * box of `values` is, mixed while some are. A click on a mixed parent checks
13
+ * all, on a checked one unchecks all, and on an unchecked one brings back
14
+ * the boxes checked when it was last mixed, or checks all. It submits
15
+ * nothing. Place it inside `CheckboxGroup.Root`.
16
+ */
17
+ export declare function CheckboxGroupParent(props: CheckboxGroupParentProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,72 @@
1
+ import { createMemo, merge, omit } from "solid-js";
2
+ import { CheckboxRoot } from "../../checkbox/root/CheckboxRoot.jsx";
3
+ import { useCheckboxGroupRootContext } from "../root/CheckboxGroupRootContext.js";
4
+ /**
5
+ * A checkbox over the group's boxes: a `Checkbox.Root`, checked while every
6
+ * box of `values` is, mixed while some are. A click on a mixed parent checks
7
+ * all, on a checked one unchecks all, and on an unchecked one brings back
8
+ * the boxes checked when it was last mixed, or checks all. It submits
9
+ * nothing. Place it inside `CheckboxGroup.Root`.
10
+ */
11
+ export function CheckboxGroupParent(props) {
12
+ const group = useCheckboxGroupRootContext();
13
+ // The list the parent set last, by reference: a list it did not set is
14
+ // a change the user made, through a box or a reset.
15
+ let set;
16
+ // The boxes of `values` that are checked, and the combination a click on
17
+ // the unchecked parent brings back: the one the user made last, which a
18
+ // change by the parent leaves as it was, as the WAI-ARIA mixed-state
19
+ // example does. Read by the bindings below, so it sees every change.
20
+ const boxes = createMemo((previous) => {
21
+ const list = group.value();
22
+ const checked = props.values.filter((item) => list.includes(item));
23
+ return {
24
+ checked,
25
+ remembered: previous && list === set ? previous.remembered : checked,
26
+ };
27
+ });
28
+ // Memos, so that a change to the list that leaves the parent as it was
29
+ // does not run its bindings again (CheckboxGroupItem).
30
+ const allChecked = createMemo(() => props.values.length > 0 && boxes().checked.length === props.values.length);
31
+ const someChecked = createMemo(() => boxes().checked.length > 0);
32
+ const own = {
33
+ get checked() {
34
+ return allChecked();
35
+ },
36
+ // The group puts the list back on a form reset, so Checkbox's own reset
37
+ // must ask for nothing (CheckboxGroupItem).
38
+ get defaultChecked() {
39
+ return allChecked();
40
+ },
41
+ get indeterminate() {
42
+ return someChecked() && !allChecked();
43
+ },
44
+ // Checkbox asks for the opposite of `checked`: `false` from a checked
45
+ // parent, `true` from a mixed or an unchecked one.
46
+ onCheckedChange: (checked) => {
47
+ const values = props.values;
48
+ const current = group.requested();
49
+ const others = current.filter((item) => !values.includes(item));
50
+ const { remembered } = boxes();
51
+ let next = others;
52
+ if (checked) {
53
+ // Mixed, or unchecked with nothing to bring back: check all.
54
+ next =
55
+ values.some((item) => current.includes(item)) ||
56
+ remembered.length === 0
57
+ ? [...current, ...values.filter((item) => !current.includes(item))]
58
+ : [...others, ...remembered];
59
+ }
60
+ set = next;
61
+ group.setValue(next);
62
+ },
63
+ get form() {
64
+ return group.form();
65
+ },
66
+ get disabled() {
67
+ return group.disabled() || props.disabled;
68
+ },
69
+ };
70
+ const checkboxProps = merge(omit(props, "values", "disabled"), own);
71
+ return <CheckboxRoot {...checkboxProps}/>;
72
+ }
@@ -0,0 +1,28 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface CheckboxGroupRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** The values of the checked boxes, when controlled. `[]` for none. */
5
+ value?: string[];
6
+ /** The values of the boxes checked at first, when uncontrolled. */
7
+ defaultValue?: string[];
8
+ /**
9
+ * Called with the new list when the user checks or unchecks a box, or
10
+ * the form is reset. When controlled, the group changes only if `value`
11
+ * does.
12
+ */
13
+ onValueChange?: (value: string[]) => void;
14
+ /** The name each checked box is submitted under, one entry per box. */
15
+ name?: string;
16
+ /** Whether every box ignores the user. The fieldset is disabled too. */
17
+ disabled?: boolean;
18
+ /** Whether the form can be submitted only while a box is checked. */
19
+ required?: boolean;
20
+ /** The `id` of the form the boxes belong to, when they are not inside it. */
21
+ form?: string;
22
+ render?: RenderProp;
23
+ }
24
+ /**
25
+ * The group: a `<fieldset>` around `CheckboxGroup.Item`s, named by a
26
+ * `<legend>`, that holds the values of the checked boxes.
27
+ */
28
+ export declare function CheckboxGroupRoot(props: CheckboxGroupRootProps): JSX.Element;
@@ -0,0 +1,75 @@
1
+ import { createUniqueId, omit, onSettled } 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 { CheckboxGroupRootContext } from "./CheckboxGroupRootContext.js";
6
+ /**
7
+ * The group: a `<fieldset>` around `CheckboxGroup.Item`s, named by a
8
+ * `<legend>`, that holds the values of the checked boxes.
9
+ */
10
+ export function CheckboxGroupRoot(props) {
11
+ const [value, setValue, requested] = createControllableSignal({
12
+ get value() {
13
+ return props.value;
14
+ },
15
+ get defaultValue() {
16
+ return props.defaultValue ?? [];
17
+ },
18
+ onChange: (value) => props.onValueChange?.(value),
19
+ });
20
+ const context = {
21
+ value,
22
+ requested,
23
+ setValue: (next) => setValue(next),
24
+ name: () => props.name,
25
+ form: () => props.form,
26
+ disabled: () => props.disabled,
27
+ };
28
+ // The hidden radio's name, which the server render and hydration agree on.
29
+ const validityName = createUniqueId();
30
+ let root;
31
+ let input;
32
+ // A form reset puts the list back to its default, once, through the
33
+ // setter, so that a controlled group asks once. Each Item's Checkbox asks
34
+ // for nothing itself (CheckboxGroupItem).
35
+ onSettled(() => {
36
+ const form = input?.form;
37
+ if (!form)
38
+ return;
39
+ const onReset = () => setValue(props.defaultValue ?? []);
40
+ form.addEventListener("reset", onReset);
41
+ return () => form.removeEventListener("reset", onReset);
42
+ });
43
+ const ownProps = {
44
+ get disabled() {
45
+ return props.disabled;
46
+ },
47
+ get "data-disabled"() {
48
+ return props.disabled ? "" : undefined;
49
+ },
50
+ get "data-required"() {
51
+ return props.required ? "" : undefined;
52
+ },
53
+ ref: (element) => {
54
+ root = element;
55
+ },
56
+ };
57
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "name", "disabled", "required", "form"));
58
+ return (<CheckboxGroupRootContext value={context}>
59
+ {renderElement(props, elementProps, (p) => (<fieldset {...p}/>))}
60
+ {/* "At least one" has no constraint of its own. An unchecked radio
61
+ that is required while the list is empty blocks a submission, and
62
+ the browser's message for it asks to select an option. Browsers
63
+ find a radio missing only with a name, unique so that no other
64
+ group's radio joins its radio group; unchecked, it submits nothing.
65
+ Its `required` follows the list, not its checkedness, which a form
66
+ reset would change behind the binding's back. */}
67
+ <input type="radio" name={validityName} aria-hidden="true" tabindex={-1} style={visuallyHidden} disabled={props.disabled} required={props.required && value().length === 0} form={props.form}
68
+ // The browser focuses an invalid input when it blocks a submission.
69
+ // The user knows the boxes, not the hidden input.
70
+ onFocus={() => root?.querySelector("[role=checkbox]:enabled")?.focus()} ref={input}/>
71
+ </CheckboxGroupRootContext>);
72
+ }
73
+ // Hidden from sight but not from the form. Not `display: none`, so the
74
+ // browser can still anchor a validation message to it.
75
+ 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,20 @@
1
+ /** What the group shares with its Items and its Parent. */
2
+ export interface CheckboxGroupRootContextValue {
3
+ /** The values of the checked boxes. */
4
+ value(): string[];
5
+ /**
6
+ * The list set last in this turn, or `value`, untracked: for a change
7
+ * that builds on one made earlier in the same turn.
8
+ */
9
+ requested(): string[];
10
+ /** Asks to set the whole list. */
11
+ setValue(next: string[]): void;
12
+ /** The `name` each Item submits under. */
13
+ name(): string | undefined;
14
+ /** The `id` of the form the Items belong to, when they are not inside it. */
15
+ form(): string | undefined;
16
+ /** Whether the whole group is disabled. */
17
+ disabled(): boolean | undefined;
18
+ }
19
+ export declare const CheckboxGroupRootContext: import("solid-js").Context<CheckboxGroupRootContextValue | null>;
20
+ export declare function useCheckboxGroupRootContext(): CheckboxGroupRootContextValue;
@@ -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 CheckboxGroupRootContext = createContext(null);
6
+ export function useCheckboxGroupRootContext() {
7
+ const context = useContext(CheckboxGroupRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] CheckboxGroup parts must be placed within <CheckboxGroup.Root>.");
11
+ }
12
+ return context;
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "menhir",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Unstyled, accessible UI primitives for SolidJS 2.0, with small and measurable bundles",
5
5
  "keywords": [
6
6
  "solid",
@@ -44,6 +44,11 @@
44
44
  "solid": "./dist/source/checkbox/index.js",
45
45
  "import": "./dist/checkbox/index.js"
46
46
  },
47
+ "./checkbox-group": {
48
+ "types": "./dist/source/checkbox-group/index.d.ts",
49
+ "solid": "./dist/source/checkbox-group/index.js",
50
+ "import": "./dist/checkbox-group/index.js"
51
+ },
47
52
  "./collapsible": {
48
53
  "types": "./dist/source/collapsible/index.d.ts",
49
54
  "solid": "./dist/source/collapsible/index.js",