@kirana-ui/solid 0.0.0 → 0.1.1

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 (233) hide show
  1. package/LICENSE +1 -1
  2. package/dom/accordion.js +106 -0
  3. package/dom/alert-dialog.js +2 -0
  4. package/dom/autocomplete.js +2 -0
  5. package/dom/autosize.js +19 -0
  6. package/dom/avatar.js +68 -0
  7. package/dom/button.js +18 -0
  8. package/dom/calendar.js +141 -0
  9. package/dom/carousel.js +83 -0
  10. package/dom/checkbox.js +77 -0
  11. package/dom/collapsible.js +64 -0
  12. package/dom/combobox.js +281 -0
  13. package/dom/command.js +129 -0
  14. package/dom/context-menu.js +2 -0
  15. package/dom/date-field.js +86 -0
  16. package/dom/date-picker.js +103 -0
  17. package/dom/dialog.js +101 -0
  18. package/dom/direction-context.js +3 -0
  19. package/dom/direction.js +27 -0
  20. package/dom/drawer.js +2 -0
  21. package/dom/field-context.js +3 -0
  22. package/dom/field.js +88 -0
  23. package/dom/fieldset.js +41 -0
  24. package/dom/form.js +29 -0
  25. package/dom/hover-card.js +3 -0
  26. package/dom/hover-popup.js +78 -0
  27. package/dom/index.js +47 -0
  28. package/dom/input.js +26 -0
  29. package/dom/label.js +18 -0
  30. package/dom/listbox.js +114 -0
  31. package/dom/menu.js +261 -0
  32. package/dom/menubar-context.js +3 -0
  33. package/dom/menubar.js +33 -0
  34. package/dom/message-scroller.js +56 -0
  35. package/dom/meter.js +3 -0
  36. package/dom/navigation-menu.js +150 -0
  37. package/dom/number-field.js +82 -0
  38. package/dom/otp.js +95 -0
  39. package/dom/pagination.js +74 -0
  40. package/dom/popover.js +70 -0
  41. package/dom/progress.js +3 -0
  42. package/dom/qr-code.js +48 -0
  43. package/dom/radio-group.js +101 -0
  44. package/dom/resizable.js +65 -0
  45. package/dom/runtime.js +133 -0
  46. package/dom/scroll-area.js +99 -0
  47. package/dom/select.js +213 -0
  48. package/dom/separator.js +17 -0
  49. package/dom/slider.js +93 -0
  50. package/dom/switch.js +63 -0
  51. package/dom/tabs.js +97 -0
  52. package/dom/toast.js +113 -0
  53. package/dom/toggle-group.js +37 -0
  54. package/dom/toggle.js +28 -0
  55. package/dom/toolbar-context.js +5 -0
  56. package/dom/toolbar.js +71 -0
  57. package/dom/tooltip.js +3 -0
  58. package/dom/value-bar.js +62 -0
  59. package/llms.txt +1838 -0
  60. package/package.json +437 -6
  61. package/server/accordion.js +106 -0
  62. package/server/alert-dialog.js +2 -0
  63. package/server/autocomplete.js +2 -0
  64. package/server/autosize.js +19 -0
  65. package/server/avatar.js +68 -0
  66. package/server/button.js +18 -0
  67. package/server/calendar.js +140 -0
  68. package/server/carousel.js +83 -0
  69. package/server/checkbox.js +77 -0
  70. package/server/collapsible.js +64 -0
  71. package/server/combobox.js +281 -0
  72. package/server/command.js +129 -0
  73. package/server/context-menu.js +2 -0
  74. package/server/date-field.js +86 -0
  75. package/server/date-picker.js +103 -0
  76. package/server/dialog.js +101 -0
  77. package/server/direction-context.js +3 -0
  78. package/server/direction.js +27 -0
  79. package/server/drawer.js +2 -0
  80. package/server/field-context.js +3 -0
  81. package/server/field.js +87 -0
  82. package/server/fieldset.js +41 -0
  83. package/server/form.js +29 -0
  84. package/server/hover-card.js +3 -0
  85. package/server/hover-popup.js +78 -0
  86. package/server/index.js +47 -0
  87. package/server/input.js +26 -0
  88. package/server/label.js +18 -0
  89. package/server/listbox.js +114 -0
  90. package/server/menu.js +261 -0
  91. package/server/menubar-context.js +3 -0
  92. package/server/menubar.js +33 -0
  93. package/server/message-scroller.js +56 -0
  94. package/server/meter.js +3 -0
  95. package/server/navigation-menu.js +144 -0
  96. package/server/number-field.js +81 -0
  97. package/server/otp.js +94 -0
  98. package/server/pagination.js +74 -0
  99. package/server/popover.js +70 -0
  100. package/server/progress.js +3 -0
  101. package/server/qr-code.js +48 -0
  102. package/server/radio-group.js +101 -0
  103. package/server/resizable.js +65 -0
  104. package/server/runtime.js +132 -0
  105. package/server/scroll-area.js +99 -0
  106. package/server/select.js +213 -0
  107. package/server/separator.js +17 -0
  108. package/server/slider.js +92 -0
  109. package/server/switch.js +62 -0
  110. package/server/tabs.js +97 -0
  111. package/server/toast.js +113 -0
  112. package/server/toggle-group.js +37 -0
  113. package/server/toggle.js +28 -0
  114. package/server/toolbar-context.js +5 -0
  115. package/server/toolbar.js +71 -0
  116. package/server/tooltip.js +3 -0
  117. package/server/value-bar.js +61 -0
  118. package/src/accordion.jsx +68 -0
  119. package/src/alert-dialog.js +2 -0
  120. package/src/autocomplete.jsx +2 -0
  121. package/src/autosize.jsx +8 -0
  122. package/src/avatar.jsx +35 -0
  123. package/src/button.jsx +9 -0
  124. package/src/calendar.jsx +104 -0
  125. package/src/carousel.jsx +51 -0
  126. package/src/checkbox.jsx +59 -0
  127. package/src/collapsible.jsx +35 -0
  128. package/src/combobox.jsx +179 -0
  129. package/src/command.jsx +81 -0
  130. package/src/context-menu.js +2 -0
  131. package/src/date-field.jsx +67 -0
  132. package/src/date-picker.jsx +72 -0
  133. package/src/dialog.jsx +67 -0
  134. package/src/direction-context.js +3 -0
  135. package/src/direction.jsx +17 -0
  136. package/src/drawer.js +2 -0
  137. package/src/field-context.js +3 -0
  138. package/src/field.jsx +64 -0
  139. package/src/fieldset.jsx +24 -0
  140. package/src/form.jsx +26 -0
  141. package/src/hover-card.jsx +3 -0
  142. package/src/hover-popup.jsx +48 -0
  143. package/src/index.js +47 -0
  144. package/src/input.jsx +17 -0
  145. package/src/label.jsx +9 -0
  146. package/src/listbox.jsx +81 -0
  147. package/src/menu.jsx +164 -0
  148. package/src/menubar-context.js +3 -0
  149. package/src/menubar.jsx +21 -0
  150. package/src/message-scroller.jsx +27 -0
  151. package/src/meter.jsx +3 -0
  152. package/src/navigation-menu.jsx +95 -0
  153. package/src/number-field.jsx +75 -0
  154. package/src/otp.jsx +73 -0
  155. package/src/pagination.jsx +60 -0
  156. package/src/popover.jsx +51 -0
  157. package/src/progress.jsx +3 -0
  158. package/src/qr-code.jsx +25 -0
  159. package/src/radio-group.jsx +68 -0
  160. package/src/resizable.jsx +46 -0
  161. package/src/runtime.jsx +119 -0
  162. package/src/scroll-area.jsx +53 -0
  163. package/src/select.jsx +129 -0
  164. package/src/separator.jsx +8 -0
  165. package/src/slider.jsx +76 -0
  166. package/src/switch.jsx +49 -0
  167. package/src/tabs.jsx +58 -0
  168. package/src/toast.jsx +58 -0
  169. package/src/toggle-group.jsx +32 -0
  170. package/src/toggle.jsx +24 -0
  171. package/src/toolbar-context.js +5 -0
  172. package/src/toolbar.jsx +43 -0
  173. package/src/tooltip.jsx +3 -0
  174. package/src/value-bar.jsx +45 -0
  175. package/types/accordion.d.ts +30 -0
  176. package/types/alert-dialog.d.ts +1 -0
  177. package/types/autocomplete.d.ts +1 -0
  178. package/types/autosize.d.ts +8 -0
  179. package/types/avatar.d.ts +15 -0
  180. package/types/button.d.ts +9 -0
  181. package/types/calendar.d.ts +40 -0
  182. package/types/carousel.d.ts +26 -0
  183. package/types/checkbox.d.ts +26 -0
  184. package/types/collapsible.d.ts +21 -0
  185. package/types/combobox.d.ts +106 -0
  186. package/types/command.d.ts +45 -0
  187. package/types/context-menu.d.ts +1 -0
  188. package/types/date-field.d.ts +23 -0
  189. package/types/date-picker.d.ts +49 -0
  190. package/types/dialog.d.ts +61 -0
  191. package/types/direction-context.d.ts +3 -0
  192. package/types/direction.d.ts +14 -0
  193. package/types/drawer.d.ts +1 -0
  194. package/types/field-context.d.ts +3 -0
  195. package/types/field.d.ts +28 -0
  196. package/types/fieldset.d.ts +14 -0
  197. package/types/form.d.ts +7 -0
  198. package/types/hover-card.d.ts +13 -0
  199. package/types/hover-popup.d.ts +29 -0
  200. package/types/index.d.ts +50 -0
  201. package/types/input.d.ts +12 -0
  202. package/types/label.d.ts +4 -0
  203. package/types/listbox.d.ts +38 -0
  204. package/types/menu.d.ts +91 -0
  205. package/types/menubar-context.d.ts +3 -0
  206. package/types/menubar.d.ts +10 -0
  207. package/types/message-scroller.d.ts +16 -0
  208. package/types/meter.d.ts +9 -0
  209. package/types/navigation-menu.d.ts +44 -0
  210. package/types/number-field.d.ts +15 -0
  211. package/types/otp.d.ts +32 -0
  212. package/types/pagination.d.ts +23 -0
  213. package/types/popover.d.ts +31 -0
  214. package/types/progress.d.ts +9 -0
  215. package/types/qr-code.d.ts +14 -0
  216. package/types/radio-group.d.ts +29 -0
  217. package/types/resizable.d.ts +24 -0
  218. package/types/runtime.d.ts +49 -0
  219. package/types/scroll-area.d.ts +20 -0
  220. package/types/select.d.ts +74 -0
  221. package/types/separator.d.ts +6 -0
  222. package/types/slider.d.ts +24 -0
  223. package/types/switch.d.ts +21 -0
  224. package/types/tabs.d.ts +32 -0
  225. package/types/toast.d.ts +33 -0
  226. package/types/toggle-group.d.ts +14 -0
  227. package/types/toggle.d.ts +12 -0
  228. package/types/toolbar-context.d.ts +6 -0
  229. package/types/toolbar.d.ts +23 -0
  230. package/types/tooltip.d.ts +13 -0
  231. package/types/value-bar.d.ts +17 -0
  232. package/README.md +0 -7
  233. package/index.js +0 -5
package/dom/select.js ADDED
@@ -0,0 +1,213 @@
1
+ import { mergeProps as _$mergeProps } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { memo as _$memo } from "solid-js/web";
4
+ import { defined, within } from "@kirana-ui/core";
5
+ import { createSelect } from "@kirana-ui/core/select";
6
+ import { Show, createComputed, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
7
+ import { positioned } from "./popover.js";
8
+ import { FieldContext } from "./field-context.js";
9
+ import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.js";
10
+ const Context = createContext();
11
+ const ItemContext = createContext();
12
+ function useSelect() {
13
+ const made = useContext(Context);
14
+ if (!made) throw new Error("A Select part must be inside <Select.Root>");
15
+ return made;
16
+ }
17
+ function Root(props) {
18
+ const generated = createUniqueId();
19
+ const field = useContext(FieldContext);
20
+ const made = controller(within(createSelect, {
21
+ field
22
+ }), () => ({
23
+ id: props.id ?? generated,
24
+ value: props.value,
25
+ defaultValue: props.defaultValue,
26
+ open: props.open,
27
+ defaultOpen: props.defaultOpen,
28
+ disabled: props.disabled,
29
+ required: props.required,
30
+ name: props.name,
31
+ form: props.form,
32
+ items: props.items,
33
+ virtualized: props.virtualized,
34
+ onValueChange: (value, details) => props.onValueChange?.(value, details),
35
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details)
36
+ }));
37
+ const named = fromSignal(made.named);
38
+ return _$createComponent(Context.Provider, {
39
+ value: made,
40
+ get children() {
41
+ return [_$memo(() => props.children), _$createComponent(Show, {
42
+ get when() {
43
+ return named();
44
+ },
45
+ get children() {
46
+ return _$createComponent(Part, {
47
+ get part() {
48
+ return made.input;
49
+ },
50
+ tag: "input"
51
+ });
52
+ }
53
+ })];
54
+ }
55
+ });
56
+ }
57
+ const Portal = props => _$createComponent(BodyPortal, {
58
+ get mounted() {
59
+ return useSelect().mounted;
60
+ },
61
+ get children() {
62
+ return props.children;
63
+ }
64
+ });
65
+ /**
66
+ * `alignItemWithTrigger`: the list opens over its trigger, the chosen item's text on the
67
+ * trigger's own, where there is room and unless a finger opened it.
68
+ */
69
+ function Positioner(props) {
70
+ const made = useSelect();
71
+ const [local, rest] = splitProps(props, ["alignItemWithTrigger"]);
72
+ createComputed(() => made.alignItemWithTrigger.set(Boolean(local.alignItemWithTrigger)));
73
+ return _$createComponent(Part, _$mergeProps({
74
+ get part() {
75
+ return made.positioner;
76
+ },
77
+ tag: "div"
78
+ }, () => positioned(rest, made.positioning)));
79
+ }
80
+ /** Shows the chosen value's label, or `placeholder` while nothing is chosen. */
81
+ function Value(props) {
82
+ const [local, rest] = splitProps(props, ["placeholder", "children"]);
83
+ const made = useSelect();
84
+ const label = fromSignal(made.label);
85
+ return _$createComponent(Part, _$mergeProps({
86
+ get part() {
87
+ return made.valuePart;
88
+ },
89
+ tag: "span"
90
+ }, rest, {
91
+ get children() {
92
+ return local.children ?? label() ?? local.placeholder;
93
+ }
94
+ }));
95
+ }
96
+ /** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
97
+ function Item(props) {
98
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "index"]);
99
+ // An item is its value for as long as it is in the page.
100
+ const value = untrack(() => local.value);
101
+ const options = toSignal(() => ({
102
+ disabled: local.disabled,
103
+ label: local.label,
104
+ index: local.index
105
+ }));
106
+ const part = useSelect().item(value, () => defined(options.get()));
107
+ return _$createComponent(ItemContext.Provider, {
108
+ value: value,
109
+ get children() {
110
+ return _$createComponent(Part, _$mergeProps({
111
+ part: part,
112
+ tag: "div"
113
+ }, rest));
114
+ }
115
+ });
116
+ }
117
+ const ItemText = props => _$createComponent(Part, _$mergeProps({
118
+ get part() {
119
+ return useSelect().itemText(useContext(ItemContext));
120
+ },
121
+ tag: "span"
122
+ }, props));
123
+ function ItemIndicator(props) {
124
+ const [local, rest] = splitProps(props, ["keepMounted"]);
125
+ const made = useSelect();
126
+ const value = useContext(ItemContext);
127
+ const selected = fromSignal(made.selected(value));
128
+ return _$createComponent(Show, {
129
+ get when() {
130
+ return selected() || local.keepMounted;
131
+ },
132
+ get children() {
133
+ return _$createComponent(Part, _$mergeProps({
134
+ get part() {
135
+ return made.itemIndicator(value);
136
+ },
137
+ tag: "span"
138
+ }, rest));
139
+ }
140
+ });
141
+ }
142
+ const GroupContext = createContext();
143
+ /** Items that belong together, named by their `<Select.GroupLabel>`. */
144
+ function Group(props) {
145
+ const [local, rest] = splitProps(props, ["id"]);
146
+ const generated = createUniqueId();
147
+ const group = useSelect().group(untrack(() => local.id) ?? generated);
148
+ return _$createComponent(GroupContext.Provider, {
149
+ value: group,
150
+ get children() {
151
+ return _$createComponent(Part, _$mergeProps({
152
+ get part() {
153
+ return group.root;
154
+ },
155
+ tag: "div"
156
+ }, rest));
157
+ }
158
+ });
159
+ }
160
+ /** Names the group it is in. With no group around it, it is plain text. */
161
+ const GroupLabel = props => _$createComponent(Part, _$mergeProps({
162
+ get part() {
163
+ return useContext(GroupContext)?.label ?? useSelect().groupLabel;
164
+ },
165
+ tag: "div"
166
+ }, props));
167
+ function scrollArrow(direction) {
168
+ return props => {
169
+ const arrow = useSelect().scrollArrow(direction);
170
+ onMount(() => onCleanup(arrow.mount()));
171
+ const mounted = fromSignal(arrow.mounted);
172
+ return _$createComponent(Show, {
173
+ get when() {
174
+ return mounted();
175
+ },
176
+ get children() {
177
+ return _$createComponent(Part, _$mergeProps({
178
+ get part() {
179
+ return arrow.part;
180
+ },
181
+ tag: "div"
182
+ }, props));
183
+ }
184
+ });
185
+ };
186
+ }
187
+ const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
188
+ get part() {
189
+ return useSelect()[name];
190
+ },
191
+ tag: tag
192
+ }, props));
193
+ export const Select = {
194
+ Root,
195
+ Portal,
196
+ Positioner,
197
+ Value,
198
+ Item,
199
+ ItemText,
200
+ ItemIndicator,
201
+ Trigger: part("trigger", "button"),
202
+ Popup: part("popup", "div"),
203
+ /** The items' own box inside the popup, when the popup also holds scroll arrows. */
204
+ List: part("list", "div"),
205
+ /** In the page while there is more of the list above: it scrolls it under a moving pointer. */
206
+ ScrollUpArrow: scrollArrow("up"),
207
+ /** In the page while there is more of the list below. */
208
+ ScrollDownArrow: scrollArrow("down"),
209
+ Group,
210
+ GroupLabel,
211
+ /** A line between groups. */
212
+ Separator: part("separator", "div")
213
+ };
@@ -0,0 +1,17 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createSeparator } from "@kirana-ui/core/separator";
4
+ import { splitProps } from "solid-js";
5
+ import { Part, controller } from "./runtime.js";
6
+ export function Separator(props) {
7
+ const [local, rest] = splitProps(props, ["orientation"]);
8
+ const made = controller(createSeparator, () => ({
9
+ orientation: local.orientation
10
+ }));
11
+ return _$createComponent(Part, _$mergeProps({
12
+ get part() {
13
+ return made.root;
14
+ },
15
+ tag: "div"
16
+ }, rest));
17
+ }
package/dom/slider.js ADDED
@@ -0,0 +1,93 @@
1
+ import { memo as _$memo } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { mergeProps as _$mergeProps } from "solid-js/web";
4
+ import { within } from "@kirana-ui/core";
5
+ import { createSlider } from "@kirana-ui/core/slider";
6
+ import { createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
7
+ import { DirectionContext } from "./direction-context.js";
8
+ import { FieldContext } from "./field-context.js";
9
+ import { Part, controller, fromSignal } from "./runtime.js";
10
+ const Context = createContext();
11
+ function useSlider() {
12
+ const made = useContext(Context);
13
+ if (!made) throw new Error("A Slider part must be inside <Slider.Root>");
14
+ return made;
15
+ }
16
+ function Root(props) {
17
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "largeStep", "minStepsBetweenValues", "thumbAlignment", "orientation", "disabled", "name", "form", "format", "locale", "getAriaValueText", "id"]);
18
+ const generated = createUniqueId();
19
+ const field = useContext(FieldContext);
20
+ const made = controller(within(createSlider, {
21
+ field,
22
+ direction: useContext(DirectionContext)
23
+ }), () => ({
24
+ ...local,
25
+ id: local.id ?? generated,
26
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
27
+ onValueCommitted: (value, details) => local.onValueCommitted?.(value, details)
28
+ }));
29
+ return _$createComponent(Context.Provider, {
30
+ value: made,
31
+ get children() {
32
+ return _$createComponent(Part, _$mergeProps({
33
+ get part() {
34
+ return made.root;
35
+ },
36
+ tag: "div"
37
+ }, rest));
38
+ }
39
+ });
40
+ }
41
+ /** `index` is which value of a range the thumb is, from 0. */
42
+ function Thumb(props) {
43
+ const [local, rest] = splitProps(props, ["index", "children"]);
44
+ // A thumb is its index for as long as it is in the page.
45
+ const index = untrack(() => local.index ?? 0);
46
+ const slider = useSlider();
47
+ return _$createComponent(Part, _$mergeProps({
48
+ get part() {
49
+ return slider.thumb(index);
50
+ },
51
+ tag: "div"
52
+ }, rest, {
53
+ get children() {
54
+ return [_$memo(() => local.children), _$createComponent(Part, {
55
+ get part() {
56
+ return slider.thumbInput(index);
57
+ },
58
+ tag: "input"
59
+ })];
60
+ }
61
+ }));
62
+ }
63
+ /** The written value, or what its child, a function, makes of it and of the values. */
64
+ function Value(props) {
65
+ const [local, rest] = splitProps(props, ["children"]);
66
+ const made = useSlider();
67
+ const text = fromSignal(made.text);
68
+ const values = fromSignal(made.values);
69
+ return _$createComponent(Part, _$mergeProps({
70
+ get part() {
71
+ return made.value;
72
+ },
73
+ tag: "output"
74
+ }, rest, {
75
+ get children() {
76
+ return _$memo(() => !!local.children)() ? local.children(text, values) : text();
77
+ }
78
+ }));
79
+ }
80
+ const part = key => props => _$createComponent(Part, _$mergeProps({
81
+ get part() {
82
+ return useSlider()[key];
83
+ },
84
+ tag: "div"
85
+ }, props));
86
+ export const Slider = {
87
+ Root,
88
+ Value,
89
+ Control: part("control"),
90
+ Track: part("track"),
91
+ Indicator: part("indicator"),
92
+ Thumb
93
+ };
package/dom/switch.js ADDED
@@ -0,0 +1,63 @@
1
+ import { mergeProps as _$mergeProps } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { memo as _$memo } from "solid-js/web";
4
+ import { within } from "@kirana-ui/core";
5
+ import { createSwitch } from "@kirana-ui/core/switch";
6
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
7
+ import { FieldContext } from "./field-context.js";
8
+ import { Part, controller } from "./runtime.js";
9
+ const Context = createContext();
10
+ function useSwitch() {
11
+ const made = useContext(Context);
12
+ if (!made) throw new Error("A Switch part must be inside <Switch.Root>");
13
+ return made;
14
+ }
15
+ function Root(props) {
16
+ const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "disabled", "readOnly", "required", "name", "form", "value", "id", "children"]);
17
+ const generated = createUniqueId();
18
+ const field = useContext(FieldContext);
19
+ const made = controller(within(createSwitch, {
20
+ field
21
+ }), () => ({
22
+ id: local.id ?? generated,
23
+ checked: local.checked,
24
+ defaultChecked: local.defaultChecked,
25
+ disabled: local.disabled,
26
+ readOnly: local.readOnly,
27
+ required: local.required,
28
+ name: local.name,
29
+ form: local.form,
30
+ value: local.value,
31
+ onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
32
+ }));
33
+ return _$createComponent(Context.Provider, {
34
+ value: made,
35
+ get children() {
36
+ return _$createComponent(Part, _$mergeProps({
37
+ get part() {
38
+ return made.root;
39
+ },
40
+ tag: "span"
41
+ }, rest, {
42
+ get children() {
43
+ return [_$memo(() => local.children), _$createComponent(Part, {
44
+ get part() {
45
+ return made.input;
46
+ },
47
+ tag: "input"
48
+ })];
49
+ }
50
+ }));
51
+ }
52
+ });
53
+ }
54
+ const Thumb = props => _$createComponent(Part, _$mergeProps({
55
+ get part() {
56
+ return useSwitch().thumb;
57
+ },
58
+ tag: "span"
59
+ }, props));
60
+ export const Switch = {
61
+ Root,
62
+ Thumb
63
+ };
package/dom/tabs.js ADDED
@@ -0,0 +1,97 @@
1
+ import { memo as _$memo } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { mergeProps as _$mergeProps } from "solid-js/web";
4
+ import { defined, within } from "@kirana-ui/core";
5
+ import { createTabs } from "@kirana-ui/core/tabs";
6
+ import { Show, createComputed, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
7
+ import { DirectionContext } from "./direction-context.js";
8
+ import { Part, controller, fromSignal, toSignal } from "./runtime.js";
9
+ const Context = createContext();
10
+ function useTabs() {
11
+ const made = useContext(Context);
12
+ if (!made) throw new Error("A Tabs part must be inside <Tabs.Root>");
13
+ return made;
14
+ }
15
+ function Root(props) {
16
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "orientation", "id"]);
17
+ const generated = createUniqueId();
18
+ const direction = useContext(DirectionContext);
19
+ const made = controller(within(createTabs, {
20
+ direction
21
+ }), () => ({
22
+ id: local.id ?? generated,
23
+ value: local.value,
24
+ defaultValue: local.defaultValue,
25
+ orientation: local.orientation,
26
+ onValueChange: (value, details) => local.onValueChange?.(value, details)
27
+ }));
28
+ return _$createComponent(Context.Provider, {
29
+ value: made,
30
+ get children() {
31
+ return _$createComponent(Part, _$mergeProps({
32
+ get part() {
33
+ return made.root;
34
+ },
35
+ tag: "div"
36
+ }, rest));
37
+ }
38
+ });
39
+ }
40
+ function List(props) {
41
+ const [local, rest] = splitProps(props, ["activateOnFocus", "loop"]);
42
+ const made = useTabs();
43
+ createComputed(() => made.listOptions.set(defined({
44
+ ...local
45
+ })));
46
+ return _$createComponent(Part, _$mergeProps({
47
+ get part() {
48
+ return made.list;
49
+ },
50
+ tag: "div"
51
+ }, rest));
52
+ }
53
+ function Tab(props) {
54
+ const [local, rest] = splitProps(props, ["value", "disabled"]);
55
+ const options = toSignal(() => ({
56
+ disabled: local.disabled
57
+ }));
58
+ // A tab is its value for as long as it is in the page.
59
+ const part = useTabs().tab(untrack(() => local.value), () => defined(options.get()));
60
+ return _$createComponent(Part, _$mergeProps({
61
+ part: part,
62
+ tag: "button"
63
+ }, rest));
64
+ }
65
+ const Indicator = props => _$createComponent(Part, _$mergeProps({
66
+ get part() {
67
+ return useTabs().indicator;
68
+ },
69
+ tag: "span"
70
+ }, props));
71
+ /** `keepMounted` keeps the panel in the page, `hidden`, while its tab is not the active one. */
72
+ function Panel(props) {
73
+ const [local, rest] = splitProps(props, ["value", "keepMounted"]);
74
+ const panel = useTabs().panel(untrack(() => local.value));
75
+ onMount(() => onCleanup(panel.mount()));
76
+ const mounted = fromSignal(panel.mounted);
77
+ return _$createComponent(Show, {
78
+ get when() {
79
+ return mounted() || local.keepMounted;
80
+ },
81
+ get children() {
82
+ return _$createComponent(Part, _$mergeProps({
83
+ get part() {
84
+ return panel.part;
85
+ },
86
+ tag: "div"
87
+ }, rest));
88
+ }
89
+ });
90
+ }
91
+ export const Tabs = {
92
+ Root,
93
+ List,
94
+ Tab,
95
+ Indicator,
96
+ Panel
97
+ };
package/dom/toast.js ADDED
@@ -0,0 +1,113 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createToast } from "@kirana-ui/core/toast";
4
+ import { For, createContext, createMemo, createUniqueId, splitProps, useContext } from "solid-js";
5
+ import { Part, controller, fromSignal } from "./runtime.js";
6
+ const Context = createContext();
7
+ const ToastContext = createContext();
8
+ function useToast() {
9
+ const made = useContext(Context);
10
+ if (!made) throw new Error("A Toast part must be inside <Toast.Viewport>");
11
+ return made;
12
+ }
13
+ function useParts() {
14
+ const parts = useContext(ToastContext);
15
+ if (!parts) throw new Error("A toast's part must be inside <Toast.Root>");
16
+ return parts;
17
+ }
18
+ /** Where a toaster's toasts are drawn. Always in the page: put it once, near the root. */
19
+ function Viewport(props) {
20
+ const [local, rest] = splitProps(props, ["toaster", "label", "hotkey", "swipeDirection", "id"]);
21
+ const generated = createUniqueId();
22
+ const made = controller(createToast, () => ({
23
+ id: local.id ?? generated,
24
+ toaster: local.toaster,
25
+ label: local.label,
26
+ hotkey: local.hotkey,
27
+ swipeDirection: local.swipeDirection
28
+ }));
29
+ return _$createComponent(Context.Provider, {
30
+ value: made,
31
+ get children() {
32
+ return _$createComponent(Part, _$mergeProps({
33
+ get part() {
34
+ return made.viewport;
35
+ },
36
+ tag: "div"
37
+ }, rest));
38
+ }
39
+ });
40
+ }
41
+ /**
42
+ * Draws its child once for each toast, the newest first. The child is given the toast as an
43
+ * accessor: one that changes is the same toast, drawn again where it stands.
44
+ */
45
+ function List(props) {
46
+ const toasts = fromSignal(useToast().toasts);
47
+ const ids = createMemo(() => toasts().map(each => each.id), undefined, {
48
+ equals: (a, b) => a.length === b.length && a.every((each, at) => each === b[at])
49
+ });
50
+ return _$createComponent(For, {
51
+ get each() {
52
+ return ids();
53
+ },
54
+ children: id => props.children(() => toasts().find(each => each.id === id))
55
+ });
56
+ }
57
+ function Root(props) {
58
+ const [local, rest] = splitProps(props, ["toast"]);
59
+ // A root is its toast for as long as it is in the page.
60
+ const parts = useToast().toast(local.toast.id);
61
+ return _$createComponent(ToastContext.Provider, {
62
+ value: parts,
63
+ get children() {
64
+ return _$createComponent(Part, _$mergeProps({
65
+ get part() {
66
+ return parts.root;
67
+ },
68
+ tag: "div"
69
+ }, rest));
70
+ }
71
+ });
72
+ }
73
+ const Content = props => _$createComponent(Part, _$mergeProps({
74
+ get part() {
75
+ return useParts().content;
76
+ },
77
+ tag: "div"
78
+ }, props));
79
+ const Title = props => _$createComponent(Part, _$mergeProps({
80
+ get part() {
81
+ return useParts().title;
82
+ },
83
+ tag: "div"
84
+ }, props));
85
+ const Description = props => _$createComponent(Part, _$mergeProps({
86
+ get part() {
87
+ return useParts().description;
88
+ },
89
+ tag: "div"
90
+ }, props));
91
+ const Close = props => _$createComponent(Part, _$mergeProps({
92
+ get part() {
93
+ return useParts().close;
94
+ },
95
+ tag: "button"
96
+ }, props));
97
+ const Action = props => _$createComponent(Part, _$mergeProps({
98
+ get part() {
99
+ return useParts().action;
100
+ },
101
+ tag: "button"
102
+ }, props));
103
+ export const Toast = {
104
+ Viewport,
105
+ List,
106
+ Root,
107
+ Content,
108
+ Title,
109
+ Description,
110
+ Close,
111
+ Action
112
+ };
113
+ export { createToaster } from "@kirana-ui/core/toast";
@@ -0,0 +1,37 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { within } from "@kirana-ui/core";
4
+ import { createToggleGroup } from "@kirana-ui/core/toggle-group";
5
+ import { splitProps, useContext } from "solid-js";
6
+ import { DirectionContext } from "./direction-context.js";
7
+ import { Part, controller } from "./runtime.js";
8
+ import { ToggleGroupContext, ToolbarContext } from "./toolbar-context.js";
9
+ /** Toggles that are one control. Each `<Toggle value>` inside it is one of its toggles. */
10
+ export function ToggleGroup(props) {
11
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "multiple", "disabled", "orientation", "loop"]);
12
+ const direction = useContext(DirectionContext);
13
+ const toolbar = useContext(ToolbarContext) ?? undefined;
14
+ const made = controller(within(createToggleGroup, {
15
+ direction,
16
+ toolbar
17
+ }), () => ({
18
+ value: local.value,
19
+ defaultValue: local.defaultValue,
20
+ multiple: local.multiple,
21
+ disabled: local.disabled,
22
+ orientation: local.orientation,
23
+ loop: local.loop,
24
+ onValueChange: (value, details) => local.onValueChange?.(value, details)
25
+ }));
26
+ return _$createComponent(ToggleGroupContext.Provider, {
27
+ value: made,
28
+ get children() {
29
+ return _$createComponent(Part, _$mergeProps({
30
+ get part() {
31
+ return made.root;
32
+ },
33
+ tag: "div"
34
+ }, rest));
35
+ }
36
+ });
37
+ }
package/dom/toggle.js ADDED
@@ -0,0 +1,28 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { within } from "@kirana-ui/core";
4
+ import { createToggle } from "@kirana-ui/core/toggle";
5
+ import { splitProps, useContext } from "solid-js";
6
+ import { Part, controller } from "./runtime.js";
7
+ import { ToggleGroupContext, ToolbarContext } from "./toolbar-context.js";
8
+ export function Toggle(props) {
9
+ const [local, rest] = splitProps(props, ["pressed", "defaultPressed", "onPressedChange", "disabled", "value"]);
10
+ const group = useContext(ToggleGroupContext) ?? undefined;
11
+ const toolbar = useContext(ToolbarContext) ?? undefined;
12
+ const made = controller(within(createToggle, {
13
+ group,
14
+ toolbar
15
+ }), () => ({
16
+ pressed: local.pressed,
17
+ defaultPressed: local.defaultPressed,
18
+ disabled: local.disabled,
19
+ value: local.value,
20
+ onPressedChange: (pressed, details) => local.onPressedChange?.(pressed, details)
21
+ }));
22
+ return _$createComponent(Part, _$mergeProps({
23
+ get part() {
24
+ return made.root;
25
+ },
26
+ tag: "button"
27
+ }, rest));
28
+ }
@@ -0,0 +1,5 @@
1
+ import { createContext } from "solid-js";
2
+ /** The toolbar a control is an item of, if it is in one. */
3
+ export const ToolbarContext = createContext(null);
4
+ /** The group a toggle is one of the toggles of, if it is in one. */
5
+ export const ToggleGroupContext = createContext(null);