menhir 0.1.11 → 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 (33) hide show
  1. package/README.md +1 -1
  2. package/dist/checkbox/root/CheckboxRoot.js +10 -61
  3. package/dist/core/hiddenInput.js +94 -0
  4. package/dist/core/rovingFocus.js +1 -1
  5. package/dist/radio/index.js +2 -0
  6. package/dist/radio/index.parts.js +4 -0
  7. package/dist/radio/indicator/RadioIndicator.js +20 -0
  8. package/dist/radio/item/RadioItem.js +94 -0
  9. package/dist/radio/item/RadioItemContext.js +10 -0
  10. package/dist/radio/root/RadioRoot.js +96 -0
  11. package/dist/radio/root/RadioRootContext.js +10 -0
  12. package/dist/source/checkbox/root/CheckboxRoot.jsx +5 -57
  13. package/dist/source/core/hiddenInput.d.ts +46 -0
  14. package/dist/source/core/hiddenInput.jsx +93 -0
  15. package/dist/source/core/rovingFocus.d.ts +1 -1
  16. package/dist/source/core/rovingFocus.js +1 -1
  17. package/dist/source/radio/index.d.ts +1 -0
  18. package/dist/source/radio/index.js +1 -0
  19. package/dist/source/radio/index.parts.d.ts +3 -0
  20. package/dist/source/radio/index.parts.js +3 -0
  21. package/dist/source/radio/indicator/RadioIndicator.d.ts +10 -0
  22. package/dist/source/radio/indicator/RadioIndicator.jsx +12 -0
  23. package/dist/source/radio/item/RadioItem.d.ts +14 -0
  24. package/dist/source/radio/item/RadioItem.jsx +96 -0
  25. package/dist/source/radio/item/RadioItemContext.d.ts +12 -0
  26. package/dist/source/radio/item/RadioItemContext.js +12 -0
  27. package/dist/source/radio/root/RadioRoot.d.ts +28 -0
  28. package/dist/source/radio/root/RadioRoot.jsx +112 -0
  29. package/dist/source/radio/root/RadioRootContext.d.ts +40 -0
  30. package/dist/source/radio/root/RadioRootContext.js +13 -0
  31. package/dist/source/switch/root/SwitchRoot.jsx +5 -57
  32. package/dist/switch/root/SwitchRoot.js +10 -61
  33. package/package.json +6 -1
@@ -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.11",
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",
@@ -129,6 +129,11 @@
129
129
  "solid": "./dist/source/progress/index.js",
130
130
  "import": "./dist/progress/index.js"
131
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
+ },
132
137
  "./select": {
133
138
  "types": "./dist/source/select/index.d.ts",
134
139
  "solid": "./dist/source/select/index.js",