@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,75 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createNumberField } from "@kirana-ui/core/number-field";
3
+ import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { FieldContext } from "./field-context.js";
5
+ import { Part, controller, fromSignal } from "./runtime.jsx";
6
+ const Context = createContext();
7
+ function useNumberField() {
8
+ const made = useContext(Context);
9
+ if (!made)
10
+ throw new Error("A NumberField part must be inside <NumberField.Root>");
11
+ return made;
12
+ }
13
+ function Root(props) {
14
+ const [local, rest] = splitProps(props, [
15
+ "value",
16
+ "defaultValue",
17
+ "onValueChange",
18
+ "onValueCommitted",
19
+ "min",
20
+ "max",
21
+ "step",
22
+ "smallStep",
23
+ "largeStep",
24
+ "snapOnStep",
25
+ "allowWheelScrub",
26
+ "format",
27
+ "locale",
28
+ "disabled",
29
+ "readOnly",
30
+ "required",
31
+ "name",
32
+ "form",
33
+ "id",
34
+ "children",
35
+ ]);
36
+ const generated = createUniqueId();
37
+ const made = controller(within(createNumberField, { field: useContext(FieldContext) }), () => ({
38
+ id: local.id ?? generated,
39
+ value: local.value,
40
+ defaultValue: local.defaultValue,
41
+ min: local.min,
42
+ max: local.max,
43
+ step: local.step,
44
+ smallStep: local.smallStep,
45
+ largeStep: local.largeStep,
46
+ snapOnStep: local.snapOnStep,
47
+ allowWheelScrub: local.allowWheelScrub,
48
+ format: local.format,
49
+ locale: local.locale,
50
+ disabled: local.disabled,
51
+ readOnly: local.readOnly,
52
+ required: local.required,
53
+ name: local.name,
54
+ form: local.form,
55
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
56
+ onValueCommitted: (value, details) => local.onValueCommitted?.(value, details),
57
+ }));
58
+ const named = fromSignal(made.named);
59
+ return (<Context.Provider value={made}>
60
+ <Part part={made.root} tag="div" {...rest}>
61
+ {local.children}
62
+ <Show when={named()}>
63
+ <Part part={made.hidden} tag="input"/>
64
+ </Show>
65
+ </Part>
66
+ </Context.Provider>);
67
+ }
68
+ const part = (name, tag) => (props) => <Part part={useNumberField()[name]} tag={tag} {...props}/>;
69
+ export const NumberField = {
70
+ Root,
71
+ Group: part("group", "div"),
72
+ Input: part("input", "input"),
73
+ Increment: part("increment", "button"),
74
+ Decrement: part("decrement", "button"),
75
+ };
package/src/otp.jsx ADDED
@@ -0,0 +1,73 @@
1
+ import { createOtp } from "@kirana-ui/core/otp";
2
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
3
+ import { Part, controller, fromSignal } from "./runtime.jsx";
4
+ const Context = createContext();
5
+ const SlotContext = createContext();
6
+ function useOtp() {
7
+ const made = useContext(Context);
8
+ if (!made)
9
+ throw new Error("An Otp part must be inside <Otp.Root>");
10
+ return made;
11
+ }
12
+ function Root(props) {
13
+ const [local, rest] = splitProps(props, [
14
+ "length",
15
+ "value",
16
+ "defaultValue",
17
+ "onValueChange",
18
+ "onComplete",
19
+ "mode",
20
+ "disabled",
21
+ "name",
22
+ "form",
23
+ "id",
24
+ ]);
25
+ const generated = createUniqueId();
26
+ const made = controller(createOtp, () => ({
27
+ id: local.id ?? generated,
28
+ length: local.length,
29
+ value: local.value,
30
+ defaultValue: local.defaultValue,
31
+ mode: local.mode,
32
+ disabled: local.disabled,
33
+ name: local.name,
34
+ form: local.form,
35
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
36
+ onComplete: (value) => local.onComplete?.(value),
37
+ }));
38
+ return (<Context.Provider value={made}>
39
+ <Part part={made.root} tag="div" {...rest}/>
40
+ </Context.Provider>);
41
+ }
42
+ /** One cell: it shows its character, then whatever it is given (a caret). */
43
+ function Slot(props) {
44
+ const [local, rest] = splitProps(props, ["index", "children"]);
45
+ const slot = useOtp().slot(untrack(() => local.index));
46
+ const char = fromSignal(slot.char);
47
+ return (<SlotContext.Provider value={slot}>
48
+ <Part part={slot.part} tag="div" {...rest}>
49
+ {char()}
50
+ {local.children}
51
+ </Part>
52
+ </SlotContext.Provider>);
53
+ }
54
+ /** Drawn in its cell while the cell is the active one and empty. */
55
+ function Caret(props) {
56
+ const made = useOtp();
57
+ const slot = useContext(SlotContext);
58
+ if (!slot)
59
+ throw new Error("An Otp.Caret must be inside <Otp.Slot>");
60
+ const shown = fromSignal(slot.caret);
61
+ return (<Show when={shown()}>
62
+ <Part part={made.caretPart} tag="div" {...props}/>
63
+ </Show>);
64
+ }
65
+ const part = (name, tag) => (props) => (<Part part={useOtp()[name]} tag={tag} {...props}/>);
66
+ export const Otp = {
67
+ Root,
68
+ Input: part("input", "input"),
69
+ Group: part("group", "div"),
70
+ Slot,
71
+ Separator: part("separator", "div"),
72
+ Caret,
73
+ };
@@ -0,0 +1,60 @@
1
+ import { createPagination } from "@kirana-ui/core/pagination";
2
+ import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
3
+ import { Part, controller, fromSignal } from "./runtime.jsx";
4
+ const Context = createContext();
5
+ function usePagination() {
6
+ const made = useContext(Context);
7
+ if (!made)
8
+ throw new Error("A Pagination part must be inside <Pagination.Root>");
9
+ return made;
10
+ }
11
+ function Root(props) {
12
+ const [local, rest] = splitProps(props, [
13
+ "page",
14
+ "defaultPage",
15
+ "onPageChange",
16
+ "count",
17
+ "pageSize",
18
+ "siblingCount",
19
+ "boundaryCount",
20
+ "disabled",
21
+ "id",
22
+ ]);
23
+ const generated = createUniqueId();
24
+ const made = controller(createPagination, () => ({
25
+ id: local.id ?? generated,
26
+ page: local.page,
27
+ defaultPage: local.defaultPage,
28
+ count: local.count,
29
+ pageSize: local.pageSize,
30
+ siblingCount: local.siblingCount,
31
+ boundaryCount: local.boundaryCount,
32
+ disabled: local.disabled,
33
+ onPageChange: (page, details) => local.onPageChange?.(page, details),
34
+ }));
35
+ return (<Context.Provider value={made}>
36
+ <Part part={made.root} tag="nav" {...rest}/>
37
+ </Context.Provider>);
38
+ }
39
+ /** Draws its child once for each piece of the row: a page, or the mark for pages left out. */
40
+ function Items(props) {
41
+ const entries = fromSignal(usePagination().entries);
42
+ // By key: a page that stays in the row keeps its element.
43
+ const keys = () => entries().map((each) => each.key);
44
+ const of = (key) => entries().find((each) => each.key === key);
45
+ return <For each={keys()}>{(key) => props.children(of(key))}</For>;
46
+ }
47
+ function Item(props) {
48
+ const [local, rest] = splitProps(props, ["page"]);
49
+ const made = usePagination();
50
+ return <Part part={made.item(local.page)} tag="button" {...rest}/>;
51
+ }
52
+ const part = (name, tag) => (props) => (<Part part={usePagination()[name]} tag={tag} {...props}/>);
53
+ export const Pagination = {
54
+ Root,
55
+ Items,
56
+ Item,
57
+ Ellipsis: part("ellipsis", "span"),
58
+ Previous: part("previous", "button"),
59
+ Next: part("next", "button"),
60
+ };
@@ -0,0 +1,51 @@
1
+ import { defined } from "@kirana-ui/core";
2
+ import { createPopover } from "@kirana-ui/core/popover";
3
+ import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
5
+ const Context = createContext();
6
+ /** For a component made of this one's parts: a date picker. */
7
+ export { Context as PopoverContext };
8
+ function usePopover() {
9
+ const made = useContext(Context);
10
+ if (!made)
11
+ throw new Error("A Popover part must be inside <Popover.Root>");
12
+ return made;
13
+ }
14
+ function Root(props) {
15
+ const generated = createUniqueId();
16
+ const made = controller(createPopover, () => ({
17
+ id: props.id ?? generated,
18
+ open: props.open,
19
+ defaultOpen: props.defaultOpen,
20
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
21
+ }));
22
+ return <Context.Provider value={made}>{props.children}</Context.Provider>;
23
+ }
24
+ const Portal = (props) => (<BodyPortal mounted={usePopover().mounted}>{props.children}</BodyPortal>);
25
+ /** A positioner's own props, written where its placement reads them, before its element attaches. */
26
+ export function positioned(props, positioning) {
27
+ const [local, rest] = splitProps(props, [
28
+ "side",
29
+ "align",
30
+ "sideOffset",
31
+ "alignOffset",
32
+ "collisionPadding",
33
+ ]);
34
+ createComputed(() => positioning.set(defined({ ...local })));
35
+ return rest;
36
+ }
37
+ function Positioner(props) {
38
+ const made = usePopover();
39
+ return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
40
+ }
41
+ const part = (name, tag) => (props) => <Part part={usePopover()[name]} tag={tag} {...props}/>;
42
+ export const Popover = {
43
+ Root,
44
+ Portal,
45
+ Positioner,
46
+ Trigger: part("trigger", "button"),
47
+ Popup: part("popup", "div"),
48
+ Title: part("title", "h2"),
49
+ Description: part("description", "p"),
50
+ Close: part("close", "button"),
51
+ };
@@ -0,0 +1,3 @@
1
+ import { createProgress } from "@kirana-ui/core/progress";
2
+ import { valueBar } from "./value-bar.jsx";
3
+ export const Progress = valueBar("Progress", createProgress);
@@ -0,0 +1,25 @@
1
+ import { createQrCode } from "@kirana-ui/core/qr-code";
2
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
3
+ import { Part, controller } from "./runtime.jsx";
4
+ const Context = createContext();
5
+ function useQrCode() {
6
+ const made = useContext(Context);
7
+ if (!made)
8
+ throw new Error("A QrCode part must be inside <QrCode.Root>");
9
+ return made;
10
+ }
11
+ function Root(props) {
12
+ const [local, rest] = splitProps(props, ["value", "correction", "id"]);
13
+ const generated = createUniqueId();
14
+ const made = controller(createQrCode, () => ({
15
+ id: local.id ?? generated,
16
+ value: local.value,
17
+ correction: local.correction,
18
+ }));
19
+ return (<Context.Provider value={made}>
20
+ <Part part={made.root} tag="div" {...rest}/>
21
+ </Context.Provider>);
22
+ }
23
+ const Frame = (props) => <Part part={useQrCode().frame} tag="svg" {...props}/>;
24
+ const Pattern = (props) => (<Part part={useQrCode().pattern} tag="path" {...props}/>);
25
+ export const QrCode = { Root, Frame, Pattern };
@@ -0,0 +1,68 @@
1
+ import { defined, within } from "@kirana-ui/core";
2
+ import { createRadioGroup } from "@kirana-ui/core/radio-group";
3
+ import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { FieldContext } from "./field-context.js";
6
+ import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
7
+ const Context = createContext();
8
+ const ItemContext = createContext();
9
+ function useRadioGroup() {
10
+ const made = useContext(Context);
11
+ if (!made)
12
+ throw new Error("A RadioGroup part must be inside <RadioGroup.Root>");
13
+ return made;
14
+ }
15
+ function Root(props) {
16
+ const [local, rest] = splitProps(props, [
17
+ "value",
18
+ "defaultValue",
19
+ "onValueChange",
20
+ "disabled",
21
+ "readOnly",
22
+ "required",
23
+ "name",
24
+ "form",
25
+ "id",
26
+ ]);
27
+ const generated = createUniqueId();
28
+ const field = useContext(FieldContext);
29
+ const made = controller(within(createRadioGroup, { field, direction: useContext(DirectionContext) }), () => ({
30
+ id: local.id ?? generated,
31
+ value: local.value,
32
+ defaultValue: local.defaultValue,
33
+ disabled: local.disabled,
34
+ readOnly: local.readOnly,
35
+ required: local.required,
36
+ name: local.name,
37
+ form: local.form,
38
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
39
+ }));
40
+ return (<Context.Provider value={made}>
41
+ <Part part={made.root} tag="div" {...rest}/>
42
+ </Context.Provider>);
43
+ }
44
+ function Item(props) {
45
+ const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
46
+ // An item is its value for as long as it is in the page.
47
+ const value = untrack(() => local.value);
48
+ const options = toSignal(() => ({ disabled: local.disabled }));
49
+ const read = () => defined(options.get());
50
+ const group = useRadioGroup();
51
+ return (<ItemContext.Provider value={value}>
52
+ <Part part={group.item(value, read)} tag="span" {...rest}>
53
+ {local.children}
54
+ <Part part={group.itemInput(value, read)} tag="input"/>
55
+ </Part>
56
+ </ItemContext.Provider>);
57
+ }
58
+ /** `keepMounted` keeps the mark in the page while its item is not the chosen one. */
59
+ function Indicator(props) {
60
+ const [local, rest] = splitProps(props, ["keepMounted"]);
61
+ const indicator = useRadioGroup().indicator(useContext(ItemContext));
62
+ onMount(() => onCleanup(indicator.mount()));
63
+ const mounted = fromSignal(indicator.mounted);
64
+ return (<Show when={mounted() || local.keepMounted}>
65
+ <Part part={indicator.part} tag="span" {...rest}/>
66
+ </Show>);
67
+ }
68
+ export const RadioGroup = { Root, Item, Indicator };
@@ -0,0 +1,46 @@
1
+ import { defined, within } from "@kirana-ui/core";
2
+ import { createResizable } from "@kirana-ui/core/resizable";
3
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { Part, controller, toSignal } from "./runtime.jsx";
6
+ const Context = createContext();
7
+ function useResizable() {
8
+ const made = useContext(Context);
9
+ if (!made)
10
+ throw new Error("A Resizable part must be inside <Resizable.Group>");
11
+ return made;
12
+ }
13
+ function Group(props) {
14
+ const [local, rest] = splitProps(props, [
15
+ "orientation",
16
+ "onSizesChange",
17
+ "keyboardStep",
18
+ "disabled",
19
+ "id",
20
+ ]);
21
+ const generated = createUniqueId();
22
+ const direction = useContext(DirectionContext);
23
+ const made = controller(within(createResizable, { direction }), () => ({
24
+ id: local.id ?? generated,
25
+ orientation: local.orientation,
26
+ keyboardStep: local.keyboardStep,
27
+ disabled: local.disabled,
28
+ onSizesChange: (sizes, details) => local.onSizesChange?.(sizes, details),
29
+ }));
30
+ return (<Context.Provider value={made}>
31
+ <Part part={made.group} tag="div" {...rest}/>
32
+ </Context.Provider>);
33
+ }
34
+ function Panel(props) {
35
+ const [local, rest] = splitProps(props, ["defaultSize", "minSize", "maxSize"]);
36
+ const options = toSignal(() => ({ ...local }));
37
+ const part = useResizable().panel(() => defined(options.get()));
38
+ return <Part part={part} tag="div" {...rest}/>;
39
+ }
40
+ function Handle(props) {
41
+ const [local, rest] = splitProps(props, ["disabled"]);
42
+ const options = toSignal(() => ({ disabled: local.disabled }));
43
+ const part = useResizable().handle(() => defined(options.get()));
44
+ return <Part part={part} tag="div" {...rest}/>;
45
+ }
46
+ export const Resizable = { Group, Panel, Handle };
@@ -0,0 +1,119 @@
1
+ import { mergeProps, sameProps, signal } from "@kirana-ui/core";
2
+ import { Show, children, createComputed, createContext, createRenderEffect, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, useContext, } from "solid-js";
3
+ import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
4
+ /** A core signal as a Solid accessor: tracked by whatever calls it. */
5
+ export function fromSignal(source) {
6
+ const [read, write] = createSignal(source.peek(), { equals: false });
7
+ if (!isServer)
8
+ onCleanup(source.subscribe(() => write(() => source.peek())));
9
+ return read;
10
+ }
11
+ /** A core signal that follows Solid state: the core hears a changed prop before anything renders. */
12
+ export function toSignal(read) {
13
+ const source = signal(untrack(read), sameProps);
14
+ createComputed(() => source.set(read()));
15
+ return source;
16
+ }
17
+ /** A component's controller, made once, following its props. */
18
+ export function controller(create, read) {
19
+ const made = create(toSignal(read));
20
+ onMount(() => onCleanup(made.mount()));
21
+ return made;
22
+ }
23
+ // HTML's boolean attributes, which Solid sets as properties: a part's `""` means "present".
24
+ const BOOLEAN = new Set([
25
+ "hidden",
26
+ "disabled",
27
+ "inert",
28
+ "required",
29
+ "readonly",
30
+ "multiple",
31
+ "checked",
32
+ "novalidate",
33
+ ]);
34
+ function toSolid(props) {
35
+ const out = {};
36
+ for (const key in props) {
37
+ const value = props[key];
38
+ // Solid's `onFocus` and `onBlur` do not bubble; the core's are the ones that do.
39
+ if (key === "onFocus")
40
+ out.onFocusIn = value;
41
+ else if (key === "onBlur")
42
+ out.onFocusOut = value;
43
+ else
44
+ out[key] = BOOLEAN.has(key) ? value === "" || value === true : value;
45
+ }
46
+ return out;
47
+ }
48
+ /**
49
+ * A part's element (or the caller's, through `render`), with the caller's props merged under the
50
+ * part's and the part's DOM work attached once the element is in the page.
51
+ */
52
+ export function Part(props) {
53
+ const [local, caller] = splitProps(props, ["part", "tag", "as", "render", "children"]);
54
+ const own = fromSignal(untrack(() => local.part).props);
55
+ // Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
56
+ // the starting style) waits for the mount that follows. It belongs to this component, not to
57
+ // the effect that spreads the props (which hands the ref over again, and is torn down, each time
58
+ // they change): attached once per element, detached when the component goes.
59
+ const owner = getOwner();
60
+ let attached;
61
+ const attach = (element) => {
62
+ if (element === attached)
63
+ return;
64
+ attached = element;
65
+ const part = untrack(() => local.part);
66
+ runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
67
+ };
68
+ const merged = createMemo(() => {
69
+ const theirs = {};
70
+ for (const key of Object.keys(caller))
71
+ theirs[key] = caller[key];
72
+ return { ...mergeProps(theirs, toSolid(own())), ref: attach };
73
+ });
74
+ return (<Show when={local.render} fallback={<Dynamic component={local.as ?? local.tag} {...merged()}>
75
+ {local.children}
76
+ </Dynamic>}>
77
+ {(render) => render()(merged)}
78
+ </Show>);
79
+ }
80
+ /**
81
+ * Its children as children of `target`, an element drawn elsewhere: with no element of its own
82
+ * around them (Solid's `Portal` adds one), so the page is the same as on the other adapters.
83
+ */
84
+ export function Into(props) {
85
+ const resolved = children(() => props.children);
86
+ // Before any mount work of the children: their elements are in the page by then.
87
+ createRenderEffect(() => {
88
+ const target = props.target;
89
+ const nodes = resolved.toArray().filter((each) => each instanceof Node);
90
+ for (const node of nodes)
91
+ target.appendChild(node);
92
+ onCleanup(() => {
93
+ for (const node of nodes)
94
+ if (node.parentNode === target)
95
+ 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 (<PortalContainer.Provider value={() => props.container}>
107
+ {props.children}
108
+ </PortalContainer.Provider>);
109
+ }
110
+ /** Its children in a container at the end of the page, while `mounted`. */
111
+ export function Portal(props) {
112
+ const shown = fromSignal(untrack(() => props.mounted));
113
+ const container = useContext(PortalContainer);
114
+ return (<Show when={shown()}>
115
+ <SolidPortal mount={container?.() ?? undefined} ref={(outlet) => outlet.setAttribute("data-kirana-portal", "")}>
116
+ {props.children}
117
+ </SolidPortal>
118
+ </Show>);
119
+ }
@@ -0,0 +1,53 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createScrollArea } from "@kirana-ui/core/scroll-area";
3
+ import { Show, createContext, splitProps, untrack, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { Part, controller, fromSignal } from "./runtime.jsx";
6
+ const Context = createContext();
7
+ const ScrollbarContext = createContext();
8
+ function useScrollArea() {
9
+ const made = useContext(Context);
10
+ if (!made)
11
+ throw new Error("A ScrollArea part must be inside <ScrollArea.Root>");
12
+ return made;
13
+ }
14
+ function Root(props) {
15
+ const direction = useContext(DirectionContext);
16
+ const made = controller(within(createScrollArea, { direction }), () => ({}));
17
+ return (<Context.Provider value={made}>
18
+ <Part part={made.root} tag="div" {...props}/>
19
+ </Context.Provider>);
20
+ }
21
+ /** `orientation` is which way it scrolls (`vertical` by default). */
22
+ function Scrollbar(props) {
23
+ const [local, rest] = splitProps(props, ["orientation", "keepMounted"]);
24
+ const bar = useScrollArea().scrollbar(untrack(() => local.orientation) ?? "vertical");
25
+ const shown = fromSignal(bar.shown);
26
+ return (<ScrollbarContext.Provider value={bar}>
27
+ <Show when={shown() || local.keepMounted}>
28
+ <Part part={bar.part} tag="div" {...rest}/>
29
+ </Show>
30
+ </ScrollbarContext.Provider>);
31
+ }
32
+ function Thumb(props) {
33
+ const bar = useContext(ScrollbarContext);
34
+ if (!bar)
35
+ throw new Error("A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>");
36
+ return <Part part={bar.thumb} tag="div" {...props}/>;
37
+ }
38
+ function Corner(props) {
39
+ const { corner } = useScrollArea();
40
+ const shown = fromSignal(corner.shown);
41
+ return (<Show when={shown()}>
42
+ <Part part={corner.part} tag="div" {...props}/>
43
+ </Show>);
44
+ }
45
+ const part = (name) => (props) => (<Part part={useScrollArea()[name]} tag="div" {...props}/>);
46
+ export const ScrollArea = {
47
+ Root,
48
+ Viewport: part("viewport"),
49
+ Content: part("content"),
50
+ Scrollbar,
51
+ Thumb,
52
+ Corner,
53
+ };