menhir 0.1.10 → 0.1.12

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/checkbox/root/CheckboxRoot.js +10 -61
  3. package/dist/checkbox-group/index.js +2 -0
  4. package/dist/checkbox-group/index.parts.js +5 -0
  5. package/dist/checkbox-group/item/CheckboxGroupItem.js +40 -0
  6. package/dist/checkbox-group/parent/CheckboxGroupParent.js +55 -0
  7. package/dist/checkbox-group/root/CheckboxGroupRoot.js +89 -0
  8. package/dist/checkbox-group/root/CheckboxGroupRootContext.js +10 -0
  9. package/dist/core/hiddenInput.js +94 -0
  10. package/dist/core/rovingFocus.js +1 -1
  11. package/dist/radio/index.js +2 -0
  12. package/dist/radio/index.parts.js +4 -0
  13. package/dist/radio/indicator/RadioIndicator.js +20 -0
  14. package/dist/radio/item/RadioItem.js +94 -0
  15. package/dist/radio/item/RadioItemContext.js +10 -0
  16. package/dist/radio/root/RadioRoot.js +96 -0
  17. package/dist/radio/root/RadioRootContext.js +10 -0
  18. package/dist/source/checkbox/root/CheckboxRoot.jsx +5 -57
  19. package/dist/source/checkbox-group/index.d.ts +1 -0
  20. package/dist/source/checkbox-group/index.js +1 -0
  21. package/dist/source/checkbox-group/index.parts.d.ts +4 -0
  22. package/dist/source/checkbox-group/index.parts.js +4 -0
  23. package/dist/source/checkbox-group/item/CheckboxGroupItem.d.ts +10 -0
  24. package/dist/source/checkbox-group/item/CheckboxGroupItem.jsx +47 -0
  25. package/dist/source/checkbox-group/parent/CheckboxGroupParent.d.ts +17 -0
  26. package/dist/source/checkbox-group/parent/CheckboxGroupParent.jsx +72 -0
  27. package/dist/source/checkbox-group/root/CheckboxGroupRoot.d.ts +28 -0
  28. package/dist/source/checkbox-group/root/CheckboxGroupRoot.jsx +75 -0
  29. package/dist/source/checkbox-group/root/CheckboxGroupRootContext.d.ts +20 -0
  30. package/dist/source/checkbox-group/root/CheckboxGroupRootContext.js +13 -0
  31. package/dist/source/core/hiddenInput.d.ts +46 -0
  32. package/dist/source/core/hiddenInput.jsx +93 -0
  33. package/dist/source/core/rovingFocus.d.ts +1 -1
  34. package/dist/source/core/rovingFocus.js +1 -1
  35. package/dist/source/radio/index.d.ts +1 -0
  36. package/dist/source/radio/index.js +1 -0
  37. package/dist/source/radio/index.parts.d.ts +3 -0
  38. package/dist/source/radio/index.parts.js +3 -0
  39. package/dist/source/radio/indicator/RadioIndicator.d.ts +10 -0
  40. package/dist/source/radio/indicator/RadioIndicator.jsx +12 -0
  41. package/dist/source/radio/item/RadioItem.d.ts +14 -0
  42. package/dist/source/radio/item/RadioItem.jsx +96 -0
  43. package/dist/source/radio/item/RadioItemContext.d.ts +12 -0
  44. package/dist/source/radio/item/RadioItemContext.js +12 -0
  45. package/dist/source/radio/root/RadioRoot.d.ts +28 -0
  46. package/dist/source/radio/root/RadioRoot.jsx +112 -0
  47. package/dist/source/radio/root/RadioRootContext.d.ts +40 -0
  48. package/dist/source/radio/root/RadioRootContext.js +13 -0
  49. package/dist/source/switch/root/SwitchRoot.jsx +5 -57
  50. package/dist/switch/root/SwitchRoot.js +10 -61
  51. package/package.json +11 -1
@@ -0,0 +1,96 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createMemo, merge, omit, onSettled, untrack } from "solid-js";
3
+ import { warnUnlessButton } from "../../core/button.js";
4
+ import { createHiddenInput } from "../../core/hiddenInput.jsx";
5
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
6
+ import { renderElement } from "../../core/renderElement.jsx";
7
+ import { useRadioRootContext } from "../root/RadioRootContext.js";
8
+ import { RadioItemContext } from "./RadioItemContext.js";
9
+ /**
10
+ * One radio of the group: a `<button role="radio">`, checked while the
11
+ * group's value is its `value`. Place it inside `Radio.Root`.
12
+ */
13
+ export function RadioItem(props) {
14
+ const group = useRadioRootContext();
15
+ // A memo, so that a change of the value that leaves this radio as it was
16
+ // does not run its bindings again.
17
+ const checked = createMemo(() => group.value() === props.value);
18
+ const disabled = () => !!(group.disabled() || props.disabled);
19
+ let element;
20
+ const stateAttributes = {
21
+ get "data-checked"() {
22
+ return checked() ? "" : undefined;
23
+ },
24
+ get "data-unchecked"() {
25
+ return checked() ? undefined : "";
26
+ },
27
+ get "data-disabled"() {
28
+ return disabled() ? "" : undefined;
29
+ },
30
+ };
31
+ const inputProps = {
32
+ get name() {
33
+ return group.name();
34
+ },
35
+ get value() {
36
+ return props.value;
37
+ },
38
+ get disabled() {
39
+ return disabled();
40
+ },
41
+ get required() {
42
+ return group.required();
43
+ },
44
+ get form() {
45
+ return group.form();
46
+ },
47
+ };
48
+ // The input's change only ever checks it: the user cannot uncheck a radio.
49
+ const input = createHiddenInput("radio", inputProps, checked, () => group.select(props.value), () => element, group.reset);
50
+ // Read once: the tab stop of the server HTML, and of the first render.
51
+ const first = group.claimTabStop(untrack(checked), untrack(disabled));
52
+ const buttonProps = {
53
+ role: "radio",
54
+ type: "button",
55
+ get disabled() {
56
+ return disabled();
57
+ },
58
+ // Solid 2.0 removes an attribute set to false, so spell the value out.
59
+ get "aria-checked"() {
60
+ return checked() ? "true" : "false";
61
+ },
62
+ get tabindex() {
63
+ return group.isTabStop(element, first) ? 0 : -1;
64
+ },
65
+ // The change goes through the hidden input, so that the form sees the
66
+ // native `input` and `change` events a radio fires.
67
+ onClick: () => input.click(),
68
+ onKeyDown: (event) => {
69
+ // A button clicks on Enter, a radio does not: the pattern names only
70
+ // Space. Canceling the key down keeps the browser from clicking.
71
+ if (event.key === "Enter")
72
+ event.preventDefault();
73
+ else
74
+ group.navigate(event, element);
75
+ },
76
+ // An arrow key checks the radio it moves to; Tab and a click focus it
77
+ // without checking it, though a click checks it then.
78
+ onFocus: () => {
79
+ if (group.moving())
80
+ input.click();
81
+ },
82
+ ref: (el) => {
83
+ element = el;
84
+ // Production builds drop the check with `isDev`.
85
+ if (isDev)
86
+ warnUnlessButton(el, "Radio.Item");
87
+ },
88
+ };
89
+ // Mounted, so its place in the document is known.
90
+ onSettled(() => group.register({ element: element, input, disabled, checked }));
91
+ const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "value", "disabled"));
92
+ return (<RadioItemContext value={stateAttributes}>
93
+ {renderElement(props, elementProps, (p) => (<button {...p}/>))}
94
+ {input}
95
+ </RadioItemContext>);
96
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The radio's state as `data-*` attributes, each `""` when it applies and
3
+ * absent otherwise. Item and Indicator both spread the same object, so its
4
+ * getters are read where each element uses them.
5
+ */
6
+ export type RadioStateAttributes = {
7
+ readonly "data-checked": "" | undefined;
8
+ readonly "data-unchecked": "" | undefined;
9
+ readonly "data-disabled": "" | undefined;
10
+ };
11
+ export declare const RadioItemContext: import("solid-js").Context<RadioStateAttributes | null>;
12
+ export declare function useRadioItemContext(): RadioStateAttributes;
@@ -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 RadioItemContext = createContext(null);
5
+ export function useRadioItemContext() {
6
+ const context = useContext(RadioItemContext);
7
+ // Production builds drop the check, and its message, with `isDev`.
8
+ if (isDev && !context) {
9
+ throw new Error("[menhir] Radio.Indicator must be placed within <Radio.Item>.");
10
+ }
11
+ return context;
12
+ }
@@ -0,0 +1,28 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface RadioRootProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ /** The checked radio's value, when controlled. `null` for none. */
5
+ value?: string | null;
6
+ /** The radio checked at first, when uncontrolled. */
7
+ defaultValue?: string | null;
8
+ /**
9
+ * Called with the new value when the user checks a radio, or with
10
+ * `defaultValue` when the form is reset. When controlled, the group
11
+ * changes only if `value` does.
12
+ */
13
+ onValueChange?: (value: string | null) => void;
14
+ /** The name the checked radio's value is submitted under. */
15
+ name?: string;
16
+ /** Whether every radio ignores the user. The fieldset is disabled too. */
17
+ disabled?: boolean;
18
+ /** Whether the form can be submitted only while a radio is checked. */
19
+ required?: boolean;
20
+ /** The `id` of the form the radios belong to, when they are not inside it. */
21
+ form?: string;
22
+ render?: RenderProp;
23
+ }
24
+ /**
25
+ * The group: a `<fieldset role="radiogroup">` around `Radio.Item`s, named
26
+ * by a `<legend>`, that holds the checked radio's value.
27
+ */
28
+ export declare function RadioRoot(props: RadioRootProps): JSX.Element;
@@ -0,0 +1,112 @@
1
+ import { createUniqueId, omit, onFlush, untrack } from "solid-js";
2
+ import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
4
+ import { createRovingFocus } from "../../core/rovingFocus.js";
5
+ import { renderElement } from "../../core/renderElement.jsx";
6
+ import { RadioRootContext } from "./RadioRootContext.js";
7
+ /**
8
+ * The group: a `<fieldset role="radiogroup">` around `Radio.Item`s, named
9
+ * by a `<legend>`, that holds the checked radio's value.
10
+ */
11
+ export function RadioRoot(props) {
12
+ const [value, setValue] = createControllableSignal({
13
+ get value() {
14
+ return props.value;
15
+ },
16
+ get defaultValue() {
17
+ return props.defaultValue ?? null;
18
+ },
19
+ onChange: (value) => props.onValueChange?.(value),
20
+ });
21
+ // The pattern moves on every arrow key, whatever the layout. Roving focus
22
+ // reads one axis, so `navigate` sets it from each key: Up and Down as a
23
+ // vertical group's, Left and Right as a horizontal one's, which roving
24
+ // focus mirrors right to left.
25
+ let vertical = false;
26
+ // Whether focus is moving by an arrow key, so the Item it reaches checks.
27
+ let moving = false;
28
+ // Whether an Item has claimed the tab stop of the server HTML.
29
+ let claimed = false;
30
+ const items = new Set();
31
+ const roving = createRovingFocus({
32
+ get vertical() {
33
+ return vertical;
34
+ },
35
+ focusable: (item) => !item.disabled(),
36
+ preferred: (item) => item.checked(),
37
+ });
38
+ // After a declined change. The browser checked the clicked radio's input
39
+ // and unchecked the checked one's, which no binding changed: this checks
40
+ // it again, once the value has settled. The clicked one unchecks itself.
41
+ const restore = () => {
42
+ for (const item of items)
43
+ if (untrack(item.checked))
44
+ item.input.checked = true;
45
+ };
46
+ // The hidden inputs' name, which the server render and hydration agree
47
+ // on. Browsers find a radio missing only with a name, so a group with no
48
+ // `name` of its own gives them this one while none is checked, when they
49
+ // submit nothing; once one is checked, they have none again.
50
+ const validityName = createUniqueId();
51
+ const empty = () => value() === null;
52
+ const context = {
53
+ value,
54
+ select: (next) => {
55
+ setValue(next);
56
+ onFlush(restore);
57
+ },
58
+ // Each Item's hidden input asks on a form reset. A set equal to the one
59
+ // before it in the turn does nothing, so a controlled group asks once.
60
+ reset: () => setValue(props.defaultValue ?? null),
61
+ name: () => props.name ?? (empty() ? validityName : undefined),
62
+ form: () => props.form,
63
+ disabled: () => props.disabled,
64
+ // Only while none is checked: once one is, the group is not missing,
65
+ // and an unnamed, unchecked, required radio would be missing on its own
66
+ // by the HTML standard. It follows the value, not the inputs'
67
+ // checkedness, which a form reset changes behind the bindings' back.
68
+ required: () => props.required && empty(),
69
+ register: (item) => {
70
+ items.add(item);
71
+ const unregister = roving.register(item);
72
+ return () => {
73
+ items.delete(item);
74
+ unregister();
75
+ };
76
+ },
77
+ isTabStop: roving.isTabStop,
78
+ // Before any Item has registered, as on the server, the checked Item
79
+ // has the tab stop, or the first enabled one while none is checked.
80
+ claimTabStop: (checked, disabled) => !disabled &&
81
+ (checked || (untrack(value) === null && !claimed && (claimed = true))),
82
+ navigate: (event, from) => {
83
+ // The pattern names no Home or End, and native radios have none.
84
+ if (!event.key.startsWith("Arrow"))
85
+ return;
86
+ vertical = event.key === "ArrowUp" || event.key === "ArrowDown";
87
+ moving = true;
88
+ roving.navigate(event, from);
89
+ moving = false;
90
+ },
91
+ moving: () => moving,
92
+ };
93
+ const ownProps = {
94
+ role: "radiogroup",
95
+ get disabled() {
96
+ return props.disabled;
97
+ },
98
+ get "aria-required"() {
99
+ return props.required ? "true" : undefined;
100
+ },
101
+ get "data-disabled"() {
102
+ return props.disabled ? "" : undefined;
103
+ },
104
+ get "data-required"() {
105
+ return props.required ? "" : undefined;
106
+ },
107
+ };
108
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "value", "defaultValue", "onValueChange", "name", "disabled", "required", "form"));
109
+ return (<RadioRootContext value={context}>
110
+ {renderElement(props, elementProps, (p) => (<fieldset {...p}/>))}
111
+ </RadioRootContext>);
112
+ }
@@ -0,0 +1,40 @@
1
+ import type { RovingItem } from "../../core/rovingFocus.ts";
2
+ /** A mounted Item, as the group knows it. */
3
+ export interface RadioItemEntry extends RovingItem {
4
+ /** The Item's hidden input, which the group checks again after a declined change. */
5
+ readonly input: HTMLInputElement;
6
+ disabled(): boolean;
7
+ checked(): boolean;
8
+ }
9
+ /** What the group shares with its Items. */
10
+ export interface RadioRootContextValue {
11
+ /** The checked Item's value, `null` while none is checked. */
12
+ value(): string | null;
13
+ /** Asks to check the Item with this value. */
14
+ select(value: string): void;
15
+ /** Asks for `defaultValue`, on a form reset. Asked once however many Items ask. */
16
+ reset(): void;
17
+ /** The `name` each Item's hidden input takes. */
18
+ name(): string | undefined;
19
+ /** The `id` of the form the Items belong to, when they are not inside it. */
20
+ form(): string | undefined;
21
+ /** Whether the whole group is disabled. */
22
+ disabled(): boolean | undefined;
23
+ /** Whether each Item's hidden input is `required`: while none is checked in a required group. */
24
+ required(): boolean | undefined;
25
+ /** Adds a mounted Item; returns what removes it. */
26
+ register(item: RadioItemEntry): () => void;
27
+ /** Whether this Item has the tab stop; `fallback` until Items register. */
28
+ isTabStop(element: HTMLElement | undefined, fallback: boolean): boolean;
29
+ /**
30
+ * Whether an Item, created checked or not and enabled or not, has the tab
31
+ * stop of the server HTML and of the first render.
32
+ */
33
+ claimTabStop(checked: boolean, disabled: boolean): boolean;
34
+ /** Moves focus, and checks, for an arrow key pressed on an Item. */
35
+ navigate(event: KeyboardEvent, from: HTMLElement): void;
36
+ /** Whether focus is moving by an arrow key, so the Item it reaches checks. */
37
+ moving(): boolean;
38
+ }
39
+ export declare const RadioRootContext: import("solid-js").Context<RadioRootContextValue | null>;
40
+ export declare function useRadioRootContext(): RadioRootContextValue;
@@ -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 RadioRootContext = createContext(null);
6
+ export function useRadioRootContext() {
7
+ const context = useContext(RadioRootContext);
8
+ // Production builds drop the check, and its message, with `isDev`.
9
+ if (isDev && !context) {
10
+ throw new Error("[menhir] Radio.Item must be placed within <Radio.Root>.");
11
+ }
12
+ return context;
13
+ }
@@ -1,7 +1,8 @@
1
1
  import { isDev } from "@solidjs/web";
2
- import { merge, omit, onFlush, onSettled, untrack } from "solid-js";
2
+ import { merge, omit } from "solid-js";
3
3
  import { warnUnlessButton } from "../../core/button.js";
4
4
  import { createControllableSignal } from "../../core/createControllableSignal.js";
5
+ import { createHiddenInput } from "../../core/hiddenInput.jsx";
5
6
  import { mergeElementProps } from "../../core/mergeElementProps.js";
6
7
  import { renderElement } from "../../core/renderElement.jsx";
7
8
  import { SwitchRootContext } from "./SwitchRootContext.js";
@@ -53,7 +54,7 @@ export function SwitchRoot(props) {
53
54
  },
54
55
  // The change goes through the hidden input, so that the form sees the
55
56
  // native `input` and `change` events a checkbox fires.
56
- onClick: () => input?.click(),
57
+ onClick: () => input.click(),
57
58
  ref: (element) => {
58
59
  button = element;
59
60
  // Production builds drop the check with `isDev`.
@@ -62,63 +63,10 @@ export function SwitchRoot(props) {
62
63
  },
63
64
  };
64
65
  let button;
65
- let input;
66
- // Puts the input back to the switch's value, once that has settled. The
67
- // `checked` binding writes the DOM only when the value changes, so it
68
- // does not undo a change of the input that the switch did not take.
69
- const syncInput = () => {
70
- if (input)
71
- input.checked = untrack(checked);
72
- };
73
- const onInputChange = () => {
74
- if (!input)
75
- return;
76
- setChecked(input.checked);
77
- // The browser has already changed the input, so the form's own
78
- // listeners, which run after this one, see the new value. The two
79
- // differ afterwards only when a controlled switch's consumer declined
80
- // the change.
81
- onFlush(syncInput);
82
- };
83
- const onInputClick = (event) => {
84
- // The click the button sends the input is an implementation detail:
85
- // ancestors already received the user's click.
86
- event.stopPropagation();
87
- // Canceling the click keeps the checkbox as it was and fires no
88
- // `input` or `change` event, whoever clicked it.
89
- if (props.readOnly)
90
- event.preventDefault();
91
- };
92
- // A form reset puts a checkbox back to its default, and so it does the
93
- // switch: through the setter, so that a controlled switch asks.
94
- onSettled(() => {
95
- const form = input?.form;
96
- if (!form)
97
- return;
98
- const onReset = () => {
99
- setChecked(props.defaultChecked ?? false);
100
- // The browser resets the input after this event, to its `checked`
101
- // attribute, which the binding does not set. `onFlush` runs after
102
- // that, as the event has finished by then.
103
- onFlush(syncInput);
104
- };
105
- form.addEventListener("reset", onReset);
106
- return () => form.removeEventListener("reset", onReset);
107
- });
66
+ const input = createHiddenInput("checkbox", props, checked, setChecked, () => button, () => setChecked(props.defaultChecked ?? false));
108
67
  const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "checked", "defaultChecked", "onCheckedChange", "name", "value", "disabled", "readOnly", "required", "form"));
109
68
  return (<SwitchRootContext value={stateAttributes}>
110
69
  {renderElement(props, elementProps, (p) => (<button {...p}/>))}
111
- <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}
112
- // The browser focuses an invalid input when it blocks a submission.
113
- // The user knows the switch, not the hidden input.
114
- onFocus={() => button?.focus()} ref={(element) => {
115
- input = element;
116
- // Solid delegates click handlers to the document, so this one is
117
- // a native listener, to act before the click bubbles.
118
- element.addEventListener("click", onInputClick);
119
- }}/>
70
+ {input}
120
71
  </SwitchRootContext>);
121
72
  }
122
- // Hidden from sight but not from the form. Not `display: none`, so the
123
- // browser can still anchor a validation message to it.
124
- 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";
@@ -1,13 +1,13 @@
1
1
  import { warnUnlessButton } from "../../core/button.js";
2
2
  import { createControllableSignal } from "../../core/createControllableSignal.js";
3
+ import { createHiddenInput } from "../../core/hiddenInput.js";
3
4
  import { mergeElementProps } from "../../core/mergeElementProps.js";
4
5
  import { renderElement } from "../../core/renderElement.js";
5
6
  import { SwitchRootContext } from "./SwitchRootContext.js";
6
- import { createComponent, effect, heldRead, isDev, memo, ref, setAttribute, setProperty, spread, template } from "@solidjs/web";
7
- import { merge, omit, onFlush, onSettled, untrack } from "solid-js";
7
+ import { createComponent, isDev, memo, spread, template } from "@solidjs/web";
8
+ import { merge, omit } from "solid-js";
8
9
  // src/switch/root/SwitchRoot.tsx
9
- var _tmpl$ = /* @__PURE__ */ template(`<input type=checkbox aria-hidden=true tabindex=-1 style=position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none>`);
10
- var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
10
+ var _tmpl$ = /* @__PURE__ */ template(`<button>`);
11
11
  /**
12
12
  * The switch itself: a `<button role="switch">`.
13
13
  */
@@ -53,76 +53,25 @@ function SwitchRoot(props) {
53
53
  get "aria-required"() {
54
54
  return props.required ? "true" : void 0;
55
55
  },
56
- onClick: () => input?.click(),
56
+ onClick: () => input.click(),
57
57
  ref: (element) => {
58
58
  button = element;
59
59
  if (isDev) warnUnlessButton(element, "Switch.Root");
60
60
  }
61
61
  };
62
62
  let button;
63
- let input;
64
- const syncInput = () => {
65
- if (input) input.checked = untrack(checked);
66
- };
67
- const onInputChange = () => {
68
- if (!input) return;
69
- setChecked(input.checked);
70
- onFlush(syncInput);
71
- };
72
- const onInputClick = (event) => {
73
- event.stopPropagation();
74
- if (props.readOnly) event.preventDefault();
75
- };
76
- onSettled(() => {
77
- const form = input?.form;
78
- if (!form) return;
79
- const onReset = () => {
80
- setChecked(props.defaultChecked ?? false);
81
- onFlush(syncInput);
82
- };
83
- form.addEventListener("reset", onReset);
84
- return () => form.removeEventListener("reset", onReset);
85
- });
63
+ const input = createHiddenInput("checkbox", props, checked, setChecked, () => button, () => setChecked(props.defaultChecked ?? false));
86
64
  const elementProps = mergeElementProps(merge(stateAttributes, buttonProps), omit(props, "render", "checked", "defaultChecked", "onCheckedChange", "name", "value", "disabled", "readOnly", "required", "form"));
87
65
  return createComponent(SwitchRootContext, {
88
66
  value: stateAttributes,
89
67
  get children() {
90
68
  return [memo(() => {
91
69
  return renderElement(props, elementProps, (p) => (() => {
92
- var _el$2 = _tmpl$2();
93
- spread(_el$2, p, false);
94
- return _el$2;
70
+ var _el$ = _tmpl$();
71
+ spread(_el$, p, false);
72
+ return _el$;
95
73
  })());
96
- }), (() => {
97
- var _el$ = _tmpl$();
98
- _el$.addEventListener("focus", () => button?.focus());
99
- _el$.addEventListener("change", onInputChange);
100
- ref(() => {
101
- return (element) => {
102
- input = element;
103
- element.addEventListener("click", onInputClick);
104
- };
105
- }, _el$);
106
- effect(() => {
107
- return {
108
- e: props.name,
109
- t: props.value,
110
- a: props.disabled,
111
- o: props.required,
112
- i: props.form,
113
- n: checked(),
114
- s: heldRead()
115
- };
116
- }, ({ e, t, a, o, i, n, s }, _p$) => {
117
- e !== _p$?.e && setAttribute(_el$, "name", e);
118
- (t !== _p$?.t || !s) && setProperty(_el$, "value", t);
119
- a !== _p$?.a && setAttribute(_el$, "disabled", a);
120
- o !== _p$?.o && setAttribute(_el$, "required", o);
121
- i !== _p$?.i && setAttribute(_el$, "form", i);
122
- (n !== _p$?.n || !s) && (_el$.checked = n);
123
- });
124
- return _el$;
125
- })()];
74
+ }), input];
126
75
  }
127
76
  });
128
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "menhir",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
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",
@@ -124,6 +129,11 @@
124
129
  "solid": "./dist/source/progress/index.js",
125
130
  "import": "./dist/progress/index.js"
126
131
  },
132
+ "./radio": {
133
+ "types": "./dist/source/radio/index.d.ts",
134
+ "solid": "./dist/source/radio/index.js",
135
+ "import": "./dist/radio/index.js"
136
+ },
127
137
  "./select": {
128
138
  "types": "./dist/source/select/index.d.ts",
129
139
  "solid": "./dist/source/select/index.js",