@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
@@ -0,0 +1,132 @@
1
+ import { mergeProps as _$mergeProps } from "solid-js/web";
2
+ import { memo as _$memo } from "solid-js/web";
3
+ import { createComponent as _$createComponent } from "solid-js/web";
4
+ import { mergeProps, sameProps, signal } from "@kirana-ui/core";
5
+ import { Show, children, createComputed, createContext, createRenderEffect, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, useContext } from "solid-js";
6
+ import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
7
+ /** A core signal as a Solid accessor: tracked by whatever calls it. */
8
+ export function fromSignal(source) {
9
+ const [read, write] = createSignal(source.peek(), {
10
+ equals: false
11
+ });
12
+ if (!isServer) onCleanup(source.subscribe(() => write(() => source.peek())));
13
+ return read;
14
+ }
15
+ /** A core signal that follows Solid state: the core hears a changed prop before anything renders. */
16
+ export function toSignal(read) {
17
+ const source = signal(untrack(read), sameProps);
18
+ createComputed(() => source.set(read()));
19
+ return source;
20
+ }
21
+ /** A component's controller, made once, following its props. */
22
+ export function controller(create, read) {
23
+ const made = create(toSignal(read));
24
+ onMount(() => onCleanup(made.mount()));
25
+ return made;
26
+ }
27
+ // HTML's boolean attributes, which Solid sets as properties: a part's `""` means "present".
28
+ const BOOLEAN = new Set(["hidden", "disabled", "inert", "required", "readonly", "multiple", "checked", "novalidate"]);
29
+ function toSolid(props) {
30
+ const out = {};
31
+ for (const key in props) {
32
+ const value = props[key];
33
+ // Solid's `onFocus` and `onBlur` do not bubble; the core's are the ones that do.
34
+ if (key === "onFocus") out.onFocusIn = value;else if (key === "onBlur") out.onFocusOut = value;else out[key] = BOOLEAN.has(key) ? value === "" || value === true : value;
35
+ }
36
+ return out;
37
+ }
38
+ /**
39
+ * A part's element (or the caller's, through `render`), with the caller's props merged under the
40
+ * part's and the part's DOM work attached once the element is in the page.
41
+ */
42
+ export function Part(props) {
43
+ const [local, caller] = splitProps(props, ["part", "tag", "as", "render", "children"]);
44
+ const own = fromSignal(untrack(() => local.part).props);
45
+ // Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
46
+ // the starting style) waits for the mount that follows. It belongs to this component, not to
47
+ // the effect that spreads the props (which hands the ref over again, and is torn down, each time
48
+ // they change): attached once per element, detached when the component goes.
49
+ const owner = getOwner();
50
+ let attached;
51
+ const attach = element => {
52
+ if (element === attached) return;
53
+ attached = element;
54
+ const part = untrack(() => local.part);
55
+ runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
56
+ };
57
+ const merged = createMemo(() => {
58
+ const theirs = {};
59
+ for (const key of Object.keys(caller)) theirs[key] = caller[key];
60
+ return {
61
+ ...mergeProps(theirs, toSolid(own())),
62
+ ref: attach
63
+ };
64
+ });
65
+ return _$createComponent(Show, {
66
+ get when() {
67
+ return local.render;
68
+ },
69
+ get fallback() {
70
+ return _$createComponent(Dynamic, _$mergeProps({
71
+ get component() {
72
+ return local.as ?? local.tag;
73
+ }
74
+ }, merged, {
75
+ get children() {
76
+ return local.children;
77
+ }
78
+ }));
79
+ },
80
+ children: render => render()(merged)
81
+ });
82
+ }
83
+ /**
84
+ * Its children as children of `target`, an element drawn elsewhere: with no element of its own
85
+ * around them (Solid's `Portal` adds one), so the page is the same as on the other adapters.
86
+ */
87
+ export function Into(props) {
88
+ const resolved = children(() => props.children);
89
+ // Before any mount work of the children: their elements are in the page by then.
90
+ createRenderEffect(() => {
91
+ const target = props.target;
92
+ const nodes = resolved.toArray().filter(each => each instanceof Node);
93
+ for (const node of nodes) target.appendChild(node);
94
+ onCleanup(() => {
95
+ for (const node of nodes) if (node.parentNode === target) target.removeChild(node);
96
+ });
97
+ });
98
+ return null;
99
+ }
100
+ const PortalContainer = createContext();
101
+ /**
102
+ * Says where every popup inside it is drawn, the popups those open included: an element of
103
+ * the page (a shadow root's host, a full-screen element) in place of `<body>`.
104
+ */
105
+ export function PortalProvider(props) {
106
+ return _$createComponent(PortalContainer.Provider, {
107
+ value: () => props.container,
108
+ get children() {
109
+ return props.children;
110
+ }
111
+ });
112
+ }
113
+ /** Its children in a container at the end of the page, while `mounted`. */
114
+ export function Portal(props) {
115
+ const shown = fromSignal(untrack(() => props.mounted));
116
+ const container = useContext(PortalContainer);
117
+ return _$createComponent(Show, {
118
+ get when() {
119
+ return shown();
120
+ },
121
+ get children() {
122
+ return _$createComponent(SolidPortal, {
123
+ get mount() {
124
+ return container?.() ?? undefined;
125
+ },
126
+ get children() {
127
+ return props.children;
128
+ }
129
+ });
130
+ }
131
+ });
132
+ }
@@ -0,0 +1,99 @@
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 { createScrollArea } from "@kirana-ui/core/scroll-area";
6
+ import { Show, createContext, splitProps, untrack, useContext } from "solid-js";
7
+ import { DirectionContext } from "./direction-context.js";
8
+ import { Part, controller, fromSignal } from "./runtime.js";
9
+ const Context = createContext();
10
+ const ScrollbarContext = createContext();
11
+ function useScrollArea() {
12
+ const made = useContext(Context);
13
+ if (!made) throw new Error("A ScrollArea part must be inside <ScrollArea.Root>");
14
+ return made;
15
+ }
16
+ function Root(props) {
17
+ const direction = useContext(DirectionContext);
18
+ const made = controller(within(createScrollArea, {
19
+ direction
20
+ }), () => ({}));
21
+ return _$createComponent(Context.Provider, {
22
+ value: made,
23
+ get children() {
24
+ return _$createComponent(Part, _$mergeProps({
25
+ get part() {
26
+ return made.root;
27
+ },
28
+ tag: "div"
29
+ }, props));
30
+ }
31
+ });
32
+ }
33
+ /** `orientation` is which way it scrolls (`vertical` by default). */
34
+ function Scrollbar(props) {
35
+ const [local, rest] = splitProps(props, ["orientation", "keepMounted"]);
36
+ const bar = useScrollArea().scrollbar(untrack(() => local.orientation) ?? "vertical");
37
+ const shown = fromSignal(bar.shown);
38
+ return _$createComponent(ScrollbarContext.Provider, {
39
+ value: bar,
40
+ get children() {
41
+ return _$createComponent(Show, {
42
+ get when() {
43
+ return shown() || local.keepMounted;
44
+ },
45
+ get children() {
46
+ return _$createComponent(Part, _$mergeProps({
47
+ get part() {
48
+ return bar.part;
49
+ },
50
+ tag: "div"
51
+ }, rest));
52
+ }
53
+ });
54
+ }
55
+ });
56
+ }
57
+ function Thumb(props) {
58
+ const bar = useContext(ScrollbarContext);
59
+ if (!bar) throw new Error("A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>");
60
+ return _$createComponent(Part, _$mergeProps({
61
+ get part() {
62
+ return bar.thumb;
63
+ },
64
+ tag: "div"
65
+ }, props));
66
+ }
67
+ function Corner(props) {
68
+ const {
69
+ corner
70
+ } = useScrollArea();
71
+ const shown = fromSignal(corner.shown);
72
+ return _$createComponent(Show, {
73
+ get when() {
74
+ return shown();
75
+ },
76
+ get children() {
77
+ return _$createComponent(Part, _$mergeProps({
78
+ get part() {
79
+ return corner.part;
80
+ },
81
+ tag: "div"
82
+ }, props));
83
+ }
84
+ });
85
+ }
86
+ const part = name => props => _$createComponent(Part, _$mergeProps({
87
+ get part() {
88
+ return useScrollArea()[name];
89
+ },
90
+ tag: "div"
91
+ }, props));
92
+ export const ScrollArea = {
93
+ Root,
94
+ Viewport: part("viewport"),
95
+ Content: part("content"),
96
+ Scrollbar,
97
+ Thumb,
98
+ Corner
99
+ };
@@ -0,0 +1,213 @@
1
+ import { memo as _$memo } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createComponent as _$createComponent } 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 [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
+ }
@@ -0,0 +1,92 @@
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 { createSlider } from "@kirana-ui/core/slider";
5
+ import { createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
6
+ import { DirectionContext } from "./direction-context.js";
7
+ import { FieldContext } from "./field-context.js";
8
+ import { Part, controller, fromSignal } from "./runtime.js";
9
+ const Context = createContext();
10
+ function useSlider() {
11
+ const made = useContext(Context);
12
+ if (!made) throw new Error("A Slider part must be inside <Slider.Root>");
13
+ return made;
14
+ }
15
+ function Root(props) {
16
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "largeStep", "minStepsBetweenValues", "thumbAlignment", "orientation", "disabled", "name", "form", "format", "locale", "getAriaValueText", "id"]);
17
+ const generated = createUniqueId();
18
+ const field = useContext(FieldContext);
19
+ const made = controller(within(createSlider, {
20
+ field,
21
+ direction: useContext(DirectionContext)
22
+ }), () => ({
23
+ ...local,
24
+ id: local.id ?? generated,
25
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
26
+ onValueCommitted: (value, details) => local.onValueCommitted?.(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
+ /** `index` is which value of a range the thumb is, from 0. */
41
+ function Thumb(props) {
42
+ const [local, rest] = splitProps(props, ["index", "children"]);
43
+ // A thumb is its index for as long as it is in the page.
44
+ const index = untrack(() => local.index ?? 0);
45
+ const slider = useSlider();
46
+ return _$createComponent(Part, _$mergeProps({
47
+ get part() {
48
+ return slider.thumb(index);
49
+ },
50
+ tag: "div"
51
+ }, rest, {
52
+ get children() {
53
+ return [local.children, _$createComponent(Part, {
54
+ get part() {
55
+ return slider.thumbInput(index);
56
+ },
57
+ tag: "input"
58
+ })];
59
+ }
60
+ }));
61
+ }
62
+ /** The written value, or what its child, a function, makes of it and of the values. */
63
+ function Value(props) {
64
+ const [local, rest] = splitProps(props, ["children"]);
65
+ const made = useSlider();
66
+ const text = fromSignal(made.text);
67
+ const values = fromSignal(made.values);
68
+ return _$createComponent(Part, _$mergeProps({
69
+ get part() {
70
+ return made.value;
71
+ },
72
+ tag: "output"
73
+ }, rest, {
74
+ get children() {
75
+ return local.children ? local.children(text, values) : text();
76
+ }
77
+ }));
78
+ }
79
+ const part = key => props => _$createComponent(Part, _$mergeProps({
80
+ get part() {
81
+ return useSlider()[key];
82
+ },
83
+ tag: "div"
84
+ }, props));
85
+ export const Slider = {
86
+ Root,
87
+ Value,
88
+ Control: part("control"),
89
+ Track: part("track"),
90
+ Indicator: part("indicator"),
91
+ Thumb
92
+ };
@@ -0,0 +1,62 @@
1
+ import { mergeProps as _$mergeProps } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { within } from "@kirana-ui/core";
4
+ import { createSwitch } from "@kirana-ui/core/switch";
5
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
6
+ import { FieldContext } from "./field-context.js";
7
+ import { Part, controller } from "./runtime.js";
8
+ const Context = createContext();
9
+ function useSwitch() {
10
+ const made = useContext(Context);
11
+ if (!made) throw new Error("A Switch part must be inside <Switch.Root>");
12
+ return made;
13
+ }
14
+ function Root(props) {
15
+ const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "disabled", "readOnly", "required", "name", "form", "value", "id", "children"]);
16
+ const generated = createUniqueId();
17
+ const field = useContext(FieldContext);
18
+ const made = controller(within(createSwitch, {
19
+ field
20
+ }), () => ({
21
+ id: local.id ?? generated,
22
+ checked: local.checked,
23
+ defaultChecked: local.defaultChecked,
24
+ disabled: local.disabled,
25
+ readOnly: local.readOnly,
26
+ required: local.required,
27
+ name: local.name,
28
+ form: local.form,
29
+ value: local.value,
30
+ onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
31
+ }));
32
+ return _$createComponent(Context.Provider, {
33
+ value: made,
34
+ get children() {
35
+ return _$createComponent(Part, _$mergeProps({
36
+ get part() {
37
+ return made.root;
38
+ },
39
+ tag: "span"
40
+ }, rest, {
41
+ get children() {
42
+ return [local.children, _$createComponent(Part, {
43
+ get part() {
44
+ return made.input;
45
+ },
46
+ tag: "input"
47
+ })];
48
+ }
49
+ }));
50
+ }
51
+ });
52
+ }
53
+ const Thumb = props => _$createComponent(Part, _$mergeProps({
54
+ get part() {
55
+ return useSwitch().thumb;
56
+ },
57
+ tag: "span"
58
+ }, props));
59
+ export const Switch = {
60
+ Root,
61
+ Thumb
62
+ };