menhir 0.1.5 → 0.1.7

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 (117) hide show
  1. package/README.md +2 -2
  2. package/dist/autocomplete/index.js +3 -0
  3. package/dist/autocomplete/index.parts.js +11 -0
  4. package/dist/autocomplete/input/AutocompleteInput.js +45 -0
  5. package/dist/autocomplete/item/AutocompleteItem.js +29 -0
  6. package/dist/autocomplete/root/AutocompleteContext.js +39 -0
  7. package/dist/autocomplete/root/AutocompleteRoot.js +22 -0
  8. package/dist/combobox/clear/ComboboxClear.js +39 -0
  9. package/dist/combobox/filter/includesText.js +24 -0
  10. package/dist/combobox/group/ComboboxGroup.js +32 -0
  11. package/dist/combobox/group/ComboboxGroupContext.js +10 -0
  12. package/dist/combobox/group-label/ComboboxGroupLabel.js +26 -0
  13. package/dist/combobox/index.js +3 -0
  14. package/dist/combobox/index.parts.js +12 -0
  15. package/dist/combobox/input/ComboboxInput.js +78 -0
  16. package/dist/combobox/input/createComboboxInput.js +112 -0
  17. package/dist/combobox/item/ComboboxItem.js +54 -0
  18. package/dist/combobox/item/ComboboxItemContext.js +10 -0
  19. package/dist/combobox/item/createComboboxItem.js +62 -0
  20. package/dist/combobox/item-indicator/ComboboxItemIndicator.js +22 -0
  21. package/dist/combobox/list/ComboboxList.js +26 -0
  22. package/dist/combobox/popup/ComboboxPopup.js +78 -0
  23. package/dist/combobox/root/ComboboxContext.js +161 -0
  24. package/dist/combobox/root/ComboboxRoot.js +21 -0
  25. package/dist/combobox/status/ComboboxStatus.js +31 -0
  26. package/dist/combobox/trigger/ComboboxTrigger.js +47 -0
  27. package/dist/select/group/SelectGroup.js +32 -0
  28. package/dist/select/group/SelectGroupContext.js +10 -0
  29. package/dist/select/group-label/SelectGroupLabel.js +26 -0
  30. package/dist/select/index.js +2 -0
  31. package/dist/select/index.parts.js +9 -0
  32. package/dist/select/item/SelectItem.js +97 -0
  33. package/dist/select/item/SelectItemContext.js +10 -0
  34. package/dist/select/item-indicator/SelectItemIndicator.js +22 -0
  35. package/dist/select/popup/SelectPopup.js +92 -0
  36. package/dist/select/root/SelectContext.js +99 -0
  37. package/dist/select/root/SelectRoot.js +21 -0
  38. package/dist/select/trigger/SelectTrigger.js +163 -0
  39. package/dist/select/value/SelectValue.js +32 -0
  40. package/dist/source/autocomplete/index.d.ts +2 -0
  41. package/dist/source/autocomplete/index.js +4 -0
  42. package/dist/source/autocomplete/index.parts.d.ts +10 -0
  43. package/dist/source/autocomplete/index.parts.js +12 -0
  44. package/dist/source/autocomplete/input/AutocompleteInput.d.ts +18 -0
  45. package/dist/source/autocomplete/input/AutocompleteInput.jsx +37 -0
  46. package/dist/source/autocomplete/item/AutocompleteItem.d.ts +20 -0
  47. package/dist/source/autocomplete/item/AutocompleteItem.jsx +25 -0
  48. package/dist/source/autocomplete/root/AutocompleteContext.d.ts +59 -0
  49. package/dist/source/autocomplete/root/AutocompleteContext.js +33 -0
  50. package/dist/source/autocomplete/root/AutocompleteRoot.d.ts +13 -0
  51. package/dist/source/autocomplete/root/AutocompleteRoot.jsx +15 -0
  52. package/dist/source/combobox/clear/ComboboxClear.d.ts +12 -0
  53. package/dist/source/combobox/clear/ComboboxClear.jsx +36 -0
  54. package/dist/source/combobox/filter/includesText.d.ts +12 -0
  55. package/dist/source/combobox/filter/includesText.js +26 -0
  56. package/dist/source/combobox/group/ComboboxGroup.d.ts +10 -0
  57. package/dist/source/combobox/group/ComboboxGroup.jsx +23 -0
  58. package/dist/source/combobox/group/ComboboxGroupContext.d.ts +10 -0
  59. package/dist/source/combobox/group/ComboboxGroupContext.js +12 -0
  60. package/dist/source/combobox/group-label/ComboboxGroupLabel.d.ts +10 -0
  61. package/dist/source/combobox/group-label/ComboboxGroupLabel.jsx +24 -0
  62. package/dist/source/combobox/index.d.ts +2 -0
  63. package/dist/source/combobox/index.js +4 -0
  64. package/dist/source/combobox/index.parts.d.ts +11 -0
  65. package/dist/source/combobox/index.parts.js +11 -0
  66. package/dist/source/combobox/input/ComboboxInput.d.ts +19 -0
  67. package/dist/source/combobox/input/ComboboxInput.jsx +52 -0
  68. package/dist/source/combobox/input/createComboboxInput.d.ts +30 -0
  69. package/dist/source/combobox/input/createComboboxInput.js +140 -0
  70. package/dist/source/combobox/item/ComboboxItem.d.ts +25 -0
  71. package/dist/source/combobox/item/ComboboxItem.jsx +50 -0
  72. package/dist/source/combobox/item/ComboboxItemContext.d.ts +11 -0
  73. package/dist/source/combobox/item/ComboboxItemContext.js +12 -0
  74. package/dist/source/combobox/item/createComboboxItem.d.ts +21 -0
  75. package/dist/source/combobox/item/createComboboxItem.js +61 -0
  76. package/dist/source/combobox/item-indicator/ComboboxItemIndicator.d.ts +11 -0
  77. package/dist/source/combobox/item-indicator/ComboboxItemIndicator.jsx +16 -0
  78. package/dist/source/combobox/list/ComboboxList.d.ts +12 -0
  79. package/dist/source/combobox/list/ComboboxList.jsx +17 -0
  80. package/dist/source/combobox/popup/ComboboxPopup.d.ts +34 -0
  81. package/dist/source/combobox/popup/ComboboxPopup.jsx +76 -0
  82. package/dist/source/combobox/root/ComboboxContext.d.ts +179 -0
  83. package/dist/source/combobox/root/ComboboxContext.js +186 -0
  84. package/dist/source/combobox/root/ComboboxRoot.d.ts +13 -0
  85. package/dist/source/combobox/root/ComboboxRoot.jsx +13 -0
  86. package/dist/source/combobox/status/ComboboxStatus.d.ts +19 -0
  87. package/dist/source/combobox/status/ComboboxStatus.jsx +27 -0
  88. package/dist/source/combobox/trigger/ComboboxTrigger.d.ts +13 -0
  89. package/dist/source/combobox/trigger/ComboboxTrigger.jsx +40 -0
  90. package/dist/source/floating/dismissal/reason.d.ts +7 -2
  91. package/dist/source/select/group/SelectGroup.d.ts +10 -0
  92. package/dist/source/select/group/SelectGroup.jsx +23 -0
  93. package/dist/source/select/group/SelectGroupContext.d.ts +10 -0
  94. package/dist/source/select/group/SelectGroupContext.js +12 -0
  95. package/dist/source/select/group-label/SelectGroupLabel.d.ts +10 -0
  96. package/dist/source/select/group-label/SelectGroupLabel.jsx +24 -0
  97. package/dist/source/select/index.d.ts +1 -0
  98. package/dist/source/select/index.js +1 -0
  99. package/dist/source/select/index.parts.d.ts +8 -0
  100. package/dist/source/select/index.parts.js +8 -0
  101. package/dist/source/select/item/SelectItem.d.ts +24 -0
  102. package/dist/source/select/item/SelectItem.jsx +92 -0
  103. package/dist/source/select/item/SelectItemContext.d.ts +11 -0
  104. package/dist/source/select/item/SelectItemContext.js +12 -0
  105. package/dist/source/select/item-indicator/SelectItemIndicator.d.ts +11 -0
  106. package/dist/source/select/item-indicator/SelectItemIndicator.jsx +16 -0
  107. package/dist/source/select/popup/SelectPopup.d.ts +32 -0
  108. package/dist/source/select/popup/SelectPopup.jsx +97 -0
  109. package/dist/source/select/root/SelectContext.d.ts +106 -0
  110. package/dist/source/select/root/SelectContext.js +119 -0
  111. package/dist/source/select/root/SelectRoot.d.ts +13 -0
  112. package/dist/source/select/root/SelectRoot.jsx +11 -0
  113. package/dist/source/select/trigger/SelectTrigger.d.ts +15 -0
  114. package/dist/source/select/trigger/SelectTrigger.jsx +181 -0
  115. package/dist/source/select/value/SelectValue.d.ts +20 -0
  116. package/dist/source/select/value/SelectValue.jsx +27 -0
  117. package/package.json +16 -1
@@ -0,0 +1,11 @@
1
+ import { createSelect, SelectContext } from "./SelectContext.js";
2
+ /**
3
+ * A value selected from a list that a button opens: holds the value and
4
+ * whether the list is open, and shares them with `Select.Trigger`,
5
+ * `Select.Value`, `Select.Popup` and the items inside it. Its form props
6
+ * go on the hidden input the Trigger renders. Renders no element of its
7
+ * own.
8
+ */
9
+ export function SelectRoot(props) {
10
+ return (<SelectContext value={createSelect(props)}>{props.children}</SelectContext>);
11
+ }
@@ -0,0 +1,15 @@
1
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface SelectTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
4
+ render?: RenderProp;
5
+ }
6
+ /**
7
+ * The button that shows the value and opens the list: a `<button
8
+ * type="button" role="combobox" aria-haspopup="listbox">` with
9
+ * `aria-expanded`, naming the Popup in `popovertarget` and `aria-controls`
10
+ * and the active item in `aria-activedescendant`. It keeps focus while the
11
+ * list is open and takes every key. A visually hidden `<input>` follows
12
+ * it, the form's view of the value. Name it with a `<label>`. Place it
13
+ * inside `Select.Root`, right before `Select.Popup`.
14
+ */
15
+ export declare function SelectTrigger(props: SelectTriggerProps): JSX.Element;
@@ -0,0 +1,181 @@
1
+ import { isDev } from "@solidjs/web";
2
+ import { createUniqueId, merge, omit, onFlush, onSettled, untrack, } from "solid-js";
3
+ import { warnUnlessButton } from "../../core/button.js";
4
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
5
+ import { renderElement } from "../../core/renderElement.jsx";
6
+ import { useSelectContext } from "../root/SelectContext.js";
7
+ /**
8
+ * The button that shows the value and opens the list: a `<button
9
+ * type="button" role="combobox" aria-haspopup="listbox">` with
10
+ * `aria-expanded`, naming the Popup in `popovertarget` and `aria-controls`
11
+ * and the active item in `aria-activedescendant`. It keeps focus while the
12
+ * list is open and takes every key. A visually hidden `<input>` follows
13
+ * it, the form's view of the value. Name it with a `<label>`. Place it
14
+ * inside `Select.Root`, right before `Select.Popup`.
15
+ */
16
+ export function SelectTrigger(props) {
17
+ const select = useSelectContext();
18
+ const { list } = select;
19
+ const generated = createUniqueId();
20
+ // The consumer's `id`, else the generated one, which labels the Popup
21
+ // rendered after it. Kept out of the merge, where a wrapper's
22
+ // `id={undefined}` would remove it ("`undefined` is a value", PLAN.md
23
+ // section 8).
24
+ const id = () => props.id ?? generated;
25
+ select.triggerId = id;
26
+ let input;
27
+ const press = (event) => ({ reason: "trigger-press", event });
28
+ // Opens the list on its first or last item, or, with no `edge`, on the
29
+ // selected item, else the first. While closed, the move waits for the
30
+ // list to open (list navigation).
31
+ const openList = (event, edge) => {
32
+ select.setOpen(true, press(event));
33
+ const items = list.items();
34
+ if (edge)
35
+ list.move(edge === "last" ? items[items.length - 1] : items[0]);
36
+ };
37
+ // Selects the active item, unless it is disabled, and closes the list.
38
+ const selectActive = (event, reason) => {
39
+ if (select.select(select.active()) || reason === "focus-out")
40
+ select.setOpen(false, { reason, event });
41
+ };
42
+ const ownProps = merge(select.attributes, {
43
+ type: "button",
44
+ role: "combobox",
45
+ get id() {
46
+ return id();
47
+ },
48
+ get disabled() {
49
+ return select.props.disabled;
50
+ },
51
+ // So that the browser counts a press on the Trigger as one on the
52
+ // popover, which light dismiss leaves open (`src/popover/README.md`).
53
+ popovertarget: select.popupId,
54
+ "aria-haspopup": "listbox",
55
+ get "aria-expanded"() {
56
+ return select.open() ? "true" : "false";
57
+ },
58
+ "aria-controls": select.popupId,
59
+ // Only while open, as an item's `data-active`.
60
+ get "aria-activedescendant"() {
61
+ return select.open() ? select.active()?.id : undefined;
62
+ },
63
+ get "aria-required"() {
64
+ return select.props.required ? "true" : undefined;
65
+ },
66
+ onClick: (event) => {
67
+ // The state shows and hides the popover, in the flush that places
68
+ // it: the browser's own toggle would show it a task before.
69
+ event.preventDefault();
70
+ select.setOpen(!select.open(), press(event));
71
+ },
72
+ onKeyDown: (event) => {
73
+ const isOpen = select.open();
74
+ // A typed character opens a closed Select on its match, and the
75
+ // string goes on (PLAN.md section 8, "Typeahead").
76
+ if (select.typeahead.onKeyDown(event)) {
77
+ if (!isOpen)
78
+ select.setOpen(true, press(event));
79
+ return;
80
+ }
81
+ const { key, altKey } = event;
82
+ if (event.ctrlKey || event.metaKey)
83
+ return;
84
+ if (key === "Tab") {
85
+ // Focus moves on by itself.
86
+ if (isOpen)
87
+ selectActive(event, "focus-out");
88
+ return;
89
+ }
90
+ if (event.shiftKey)
91
+ return;
92
+ const enterOrSpace = key === "Enter" || key === " ";
93
+ if (!isOpen) {
94
+ if (enterOrSpace || key === "ArrowDown")
95
+ openList(event);
96
+ else if (altKey)
97
+ return;
98
+ else if (key === "ArrowUp" || key === "Home")
99
+ openList(event, "first");
100
+ else if (key === "End")
101
+ openList(event, "last");
102
+ else
103
+ return;
104
+ }
105
+ else if (enterOrSpace || (altKey && key === "ArrowUp")) {
106
+ selectActive(event, "item-press");
107
+ }
108
+ else {
109
+ // The keys move on from the item the list opened on.
110
+ const active = select.active();
111
+ if (!list.active())
112
+ list.move(active);
113
+ if (key === "PageDown" || key === "PageUp") {
114
+ const items = list.items();
115
+ const index = items.indexOf(active) + (key === "PageUp" ? -10 : 10);
116
+ list.move(items[Math.min(Math.max(index, 0), items.length - 1)]);
117
+ }
118
+ else if (!list.onKeyDown(event))
119
+ return;
120
+ }
121
+ // Enter and Space would click the button, and toggle the list again.
122
+ event.preventDefault();
123
+ },
124
+ ref: (element) => {
125
+ select.trigger = element;
126
+ // Production builds drop the check with `isDev`.
127
+ if (isDev)
128
+ warnUnlessButton(element, "Select.Trigger");
129
+ },
130
+ });
131
+ // Puts the input back to the Select's value, once that has settled: a
132
+ // controlled Select's consumer may have declined the change.
133
+ const syncInput = () => {
134
+ if (input)
135
+ input.value = untrack(select.value) ?? "";
136
+ };
137
+ // A selection, which the Select makes through the input, and a value the
138
+ // browser fills in. The browser's is an item's `value`, or its label.
139
+ const onInputChange = () => {
140
+ const filled = input.value;
141
+ const items = list.items();
142
+ const label = filled.toLowerCase();
143
+ const item = items.find((item) => item.value === filled) ??
144
+ items.find((item) => (item.text ?? item.element.textContent ?? "").trim().toLowerCase() ===
145
+ label);
146
+ if (item)
147
+ select.setValue(item.value);
148
+ else if (!filled)
149
+ select.setValue(null);
150
+ onFlush(syncInput);
151
+ };
152
+ // A form reset puts a control back to its default, and so it does the
153
+ // Select: through the setter, so that a controlled Select asks.
154
+ onSettled(() => {
155
+ const form = input?.form;
156
+ if (!form)
157
+ return;
158
+ const onReset = () => {
159
+ select.setValue(select.props.defaultValue ?? null);
160
+ // The browser resets the input after this event, to its `value`
161
+ // attribute; `onFlush` runs after that.
162
+ onFlush(syncInput);
163
+ };
164
+ form.addEventListener("reset", onReset);
165
+ return () => form.removeEventListener("reset", onReset);
166
+ });
167
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
168
+ return (<>
169
+ {renderElement(props, elementProps, (p) => (<button {...p}/>))}
170
+ <input aria-hidden="true" tabindex={-1} style={visuallyHidden} name={select.props.name} form={select.props.form} required={select.props.required} disabled={select.props.disabled} autocomplete={select.props.autocomplete} value={select.value() ?? ""} onChange={onInputChange}
171
+ // The browser focuses an invalid input when it blocks a submission.
172
+ // The user knows the Trigger, not the hidden input.
173
+ onFocus={() => select.trigger?.focus()} ref={(element) => {
174
+ input = element;
175
+ select.input = element;
176
+ }}/>
177
+ </>);
178
+ }
179
+ // Hidden from sight but not from the form. Not `display: none`, so the
180
+ // browser can still anchor a validation message to it.
181
+ 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
+ import type { JSX } from "@solidjs/web";
2
+ import type { RenderProp } from "../../core/renderElement.tsx";
3
+ export interface SelectValueProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "children"> {
4
+ /** What it shows while no item is selected. */
5
+ placeholder?: JSX.Element;
6
+ /**
7
+ * The label of a value, for a Select whose labels differ from its
8
+ * values: the server HTML cannot read a label from the items, which are
9
+ * rendered after it. Without it, the selected item's `label` or text
10
+ * content once the items have mounted, and the value itself before.
11
+ */
12
+ children?: (value: string) => JSX.Element;
13
+ render?: RenderProp;
14
+ }
15
+ /**
16
+ * The selected item's label: a `<span>`, with the `placeholder` and
17
+ * `data-placeholder` while no item is selected. Place it inside
18
+ * `Select.Trigger`.
19
+ */
20
+ export declare function SelectValue(props: SelectValueProps): JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { omit } from "solid-js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.jsx";
4
+ import { useSelectContext } from "../root/SelectContext.js";
5
+ /**
6
+ * The selected item's label: a `<span>`, with the `placeholder` and
7
+ * `data-placeholder` while no item is selected. Place it inside
8
+ * `Select.Trigger`.
9
+ */
10
+ export function SelectValue(props) {
11
+ const select = useSelectContext();
12
+ const elementProps = mergeElementProps({
13
+ get "data-placeholder"() {
14
+ return select.value() === null ? "" : undefined;
15
+ },
16
+ get children() {
17
+ const value = select.value();
18
+ if (value === null)
19
+ return props.placeholder;
20
+ if (props.children)
21
+ return props.children(value);
22
+ // An item's text is always given: its `label`, else its content.
23
+ return select.selectedItem()?.text.trim() ?? value;
24
+ },
25
+ }, omit(props, "render", "placeholder", "children"));
26
+ return renderElement(props, elementProps, (p) => <span {...p}/>);
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "menhir",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Unstyled, accessible UI primitives for SolidJS 2.0, with small and measurable bundles",
5
5
  "keywords": [
6
6
  "solid",
@@ -34,6 +34,11 @@
34
34
  "solid": "./dist/source/alert-dialog/index.js",
35
35
  "import": "./dist/alert-dialog/index.js"
36
36
  },
37
+ "./autocomplete": {
38
+ "types": "./dist/source/autocomplete/index.d.ts",
39
+ "solid": "./dist/source/autocomplete/index.js",
40
+ "import": "./dist/autocomplete/index.js"
41
+ },
37
42
  "./checkbox": {
38
43
  "types": "./dist/source/checkbox/index.d.ts",
39
44
  "solid": "./dist/source/checkbox/index.js",
@@ -54,6 +59,11 @@
54
59
  "solid": "./dist/source/color-scheme/local-storage/index.js",
55
60
  "import": "./dist/color-scheme/local-storage/index.js"
56
61
  },
62
+ "./combobox": {
63
+ "types": "./dist/source/combobox/index.d.ts",
64
+ "solid": "./dist/source/combobox/index.js",
65
+ "import": "./dist/combobox/index.js"
66
+ },
57
67
  "./context-menu": {
58
68
  "types": "./dist/source/context-menu/index.d.ts",
59
69
  "solid": "./dist/source/context-menu/index.js",
@@ -94,6 +104,11 @@
94
104
  "solid": "./dist/source/progress/index.js",
95
105
  "import": "./dist/progress/index.js"
96
106
  },
107
+ "./select": {
108
+ "types": "./dist/source/select/index.d.ts",
109
+ "solid": "./dist/source/select/index.js",
110
+ "import": "./dist/select/index.js"
111
+ },
97
112
  "./separator": {
98
113
  "types": "./dist/source/separator/index.d.ts",
99
114
  "solid": "./dist/source/separator/index.js",