@kirana-ui/solid 0.1.0 → 0.2.0

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 (213) hide show
  1. package/dom/accordion.js +9 -6
  2. package/dom/agent.js +3 -0
  3. package/dom/autocomplete.js +2 -0
  4. package/dom/autosize.js +19 -0
  5. package/dom/avatar.js +3 -3
  6. package/dom/button.js +1 -1
  7. package/dom/calendar.js +145 -0
  8. package/dom/carousel.js +83 -0
  9. package/dom/checkbox.js +5 -4
  10. package/dom/collapsible.js +3 -3
  11. package/dom/combobox.js +289 -0
  12. package/dom/command.js +129 -0
  13. package/dom/context-menu.js +2 -0
  14. package/dom/date-field.js +90 -0
  15. package/dom/date-picker.js +103 -0
  16. package/dom/dialog.js +32 -1
  17. package/dom/drawer.js +2 -0
  18. package/dom/field.js +3 -3
  19. package/dom/fieldset.js +2 -2
  20. package/dom/form.js +1 -1
  21. package/dom/hover-popup.js +19 -4
  22. package/dom/index.js +26 -1
  23. package/dom/input.js +26 -0
  24. package/dom/label.js +18 -0
  25. package/dom/listbox.js +114 -0
  26. package/dom/menu.js +261 -0
  27. package/dom/menubar-context.js +3 -0
  28. package/dom/menubar.js +33 -0
  29. package/dom/message-scroller.js +56 -0
  30. package/dom/navigation-menu.js +147 -0
  31. package/dom/number-field.js +82 -0
  32. package/dom/otp.js +95 -0
  33. package/dom/pagination.js +74 -0
  34. package/dom/popover.js +22 -7
  35. package/dom/qr-code.js +48 -0
  36. package/dom/radio-group.js +6 -5
  37. package/dom/resizable.js +65 -0
  38. package/dom/runtime.js +59 -9
  39. package/dom/scroll-area.js +99 -0
  40. package/dom/select.js +91 -15
  41. package/dom/separator.js +1 -1
  42. package/dom/slider.js +11 -8
  43. package/dom/switch.js +5 -4
  44. package/dom/tabs.js +5 -5
  45. package/dom/testing.js +3 -0
  46. package/dom/toast.js +150 -0
  47. package/dom/toggle-group.js +37 -0
  48. package/dom/toggle.js +12 -4
  49. package/dom/toolbar-context.js +5 -0
  50. package/dom/toolbar.js +71 -0
  51. package/dom/value-bar.js +3 -3
  52. package/llms.txt +3202 -0
  53. package/package.json +236 -2
  54. package/server/accordion.js +9 -6
  55. package/server/agent.js +3 -0
  56. package/server/autocomplete.js +2 -0
  57. package/server/autosize.js +19 -0
  58. package/server/avatar.js +3 -3
  59. package/server/button.js +1 -1
  60. package/server/calendar.js +144 -0
  61. package/server/carousel.js +83 -0
  62. package/server/checkbox.js +5 -4
  63. package/server/collapsible.js +3 -3
  64. package/server/combobox.js +289 -0
  65. package/server/command.js +129 -0
  66. package/server/context-menu.js +2 -0
  67. package/server/date-field.js +90 -0
  68. package/server/date-picker.js +103 -0
  69. package/server/dialog.js +32 -1
  70. package/server/drawer.js +2 -0
  71. package/server/field.js +3 -3
  72. package/server/fieldset.js +2 -2
  73. package/server/form.js +1 -1
  74. package/server/hover-popup.js +19 -4
  75. package/server/index.js +26 -1
  76. package/server/input.js +26 -0
  77. package/server/label.js +18 -0
  78. package/server/listbox.js +114 -0
  79. package/server/menu.js +261 -0
  80. package/server/menubar-context.js +3 -0
  81. package/server/menubar.js +33 -0
  82. package/server/message-scroller.js +56 -0
  83. package/server/navigation-menu.js +147 -0
  84. package/server/number-field.js +81 -0
  85. package/server/otp.js +94 -0
  86. package/server/pagination.js +74 -0
  87. package/server/popover.js +22 -7
  88. package/server/qr-code.js +48 -0
  89. package/server/radio-group.js +6 -5
  90. package/server/resizable.js +65 -0
  91. package/server/runtime.js +58 -8
  92. package/server/scroll-area.js +99 -0
  93. package/server/select.js +91 -15
  94. package/server/separator.js +1 -1
  95. package/server/slider.js +11 -8
  96. package/server/switch.js +5 -4
  97. package/server/tabs.js +5 -5
  98. package/server/testing.js +3 -0
  99. package/server/toast.js +150 -0
  100. package/server/toggle-group.js +37 -0
  101. package/server/toggle.js +12 -4
  102. package/server/toolbar-context.js +5 -0
  103. package/server/toolbar.js +71 -0
  104. package/server/value-bar.js +3 -3
  105. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  106. package/src/accordion.jsx +10 -7
  107. package/src/agent.js +3 -0
  108. package/src/autocomplete.jsx +2 -0
  109. package/src/autosize.jsx +8 -0
  110. package/src/avatar.jsx +3 -3
  111. package/src/button.jsx +1 -1
  112. package/src/calendar.jsx +108 -0
  113. package/src/carousel.jsx +51 -0
  114. package/src/checkbox.jsx +5 -3
  115. package/src/collapsible.jsx +3 -3
  116. package/src/combobox.jsx +187 -0
  117. package/src/command.jsx +81 -0
  118. package/src/context-menu.js +2 -0
  119. package/src/date-field.jsx +71 -0
  120. package/src/date-picker.jsx +72 -0
  121. package/src/dialog.jsx +27 -1
  122. package/src/drawer.js +2 -0
  123. package/src/field.jsx +3 -3
  124. package/src/fieldset.jsx +2 -2
  125. package/src/form.jsx +1 -1
  126. package/src/hover-popup.jsx +12 -4
  127. package/src/index.js +26 -1
  128. package/src/input.jsx +17 -0
  129. package/src/label.jsx +9 -0
  130. package/src/listbox.jsx +81 -0
  131. package/src/menu.jsx +164 -0
  132. package/src/menubar-context.js +3 -0
  133. package/src/menubar.jsx +21 -0
  134. package/src/message-scroller.jsx +27 -0
  135. package/src/navigation-menu.jsx +96 -0
  136. package/src/number-field.jsx +75 -0
  137. package/src/otp.jsx +73 -0
  138. package/src/pagination.jsx +60 -0
  139. package/src/popover.jsx +22 -4
  140. package/src/qr-code.jsx +25 -0
  141. package/src/radio-group.jsx +7 -5
  142. package/src/resizable.jsx +46 -0
  143. package/src/runtime.jsx +54 -9
  144. package/src/scroll-area.jsx +53 -0
  145. package/src/select.jsx +72 -14
  146. package/src/separator.jsx +1 -1
  147. package/src/slider.jsx +13 -8
  148. package/src/switch.jsx +5 -3
  149. package/src/tabs.jsx +6 -6
  150. package/src/testing.js +3 -0
  151. package/src/toast.jsx +86 -0
  152. package/src/toggle-group.jsx +32 -0
  153. package/src/toggle.jsx +9 -3
  154. package/src/toolbar-context.js +5 -0
  155. package/src/toolbar.jsx +43 -0
  156. package/src/value-bar.jsx +3 -3
  157. package/types/accordion.d.ts +21 -19
  158. package/types/agent.d.ts +1 -0
  159. package/types/alert-dialog.d.ts +1 -0
  160. package/types/autocomplete.d.ts +2 -0
  161. package/types/autosize.d.ts +11 -0
  162. package/types/avatar.d.ts +12 -5
  163. package/types/button.d.ts +4 -2
  164. package/types/calendar.d.ts +57 -0
  165. package/types/carousel.d.ts +34 -0
  166. package/types/checkbox.d.ts +10 -6
  167. package/types/collapsible.d.ts +11 -7
  168. package/types/combobox.d.ts +105 -0
  169. package/types/command.d.ts +55 -0
  170. package/types/context-menu.d.ts +2 -0
  171. package/types/date-field.d.ts +34 -0
  172. package/types/date-picker.d.ts +40 -0
  173. package/types/dialog.d.ts +52 -20
  174. package/types/direction.d.ts +1 -0
  175. package/types/drawer.d.ts +2 -0
  176. package/types/field.d.ts +19 -11
  177. package/types/fieldset.d.ts +8 -3
  178. package/types/form.d.ts +5 -2
  179. package/types/hover-card.d.ts +16 -7
  180. package/types/hover-popup.d.ts +23 -10
  181. package/types/index.d.ts +39 -2
  182. package/types/input.d.ts +13 -0
  183. package/types/label.d.ts +7 -0
  184. package/types/listbox.d.ts +36 -0
  185. package/types/menu.d.ts +105 -0
  186. package/types/menubar-context.d.ts +3 -0
  187. package/types/menubar.d.ts +12 -0
  188. package/types/message-scroller.d.ts +22 -0
  189. package/types/meter.d.ts +16 -7
  190. package/types/navigation-menu.d.ts +50 -0
  191. package/types/number-field.d.ts +22 -0
  192. package/types/otp.d.ts +39 -0
  193. package/types/pagination.d.ts +31 -0
  194. package/types/popover.d.ts +41 -13
  195. package/types/progress.d.ts +16 -7
  196. package/types/qr-code.d.ts +20 -0
  197. package/types/radio-group.d.ts +15 -16
  198. package/types/resizable.d.ts +29 -0
  199. package/types/runtime.d.ts +53 -11
  200. package/types/scroll-area.d.ts +28 -0
  201. package/types/select.d.ts +66 -33
  202. package/types/separator.d.ts +5 -3
  203. package/types/slider.d.ts +25 -13
  204. package/types/switch.d.ts +8 -4
  205. package/types/tabs.d.ts +20 -16
  206. package/types/testing.d.ts +1 -0
  207. package/types/toast.d.ts +57 -0
  208. package/types/toggle-group.d.ts +9 -0
  209. package/types/toggle.d.ts +6 -3
  210. package/types/toolbar-context.d.ts +6 -0
  211. package/types/toolbar.d.ts +28 -0
  212. package/types/tooltip.d.ts +16 -7
  213. package/types/value-bar.d.ts +21 -10
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 of={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 of={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 of={made.caretPart} tag="div" {...props}/>
63
+ </Show>);
64
+ }
65
+ const part = (name, tag) => (props) => <Part of={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 of={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 of={made.item(local.page)} tag="button" {...rest}/>;
51
+ }
52
+ const part = (name, tag) => (props) => <Part of={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
+ };
package/src/popover.jsx CHANGED
@@ -2,7 +2,13 @@ import { defined } from "@kirana-ui/core";
2
2
  import { createPopover } from "@kirana-ui/core/popover";
3
3
  import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
4
  import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
5
+ /**
6
+ * The popover its parts are inside. Exported for a component that is made of one (a date picker
7
+ * provides its own to the popover's parts).
8
+ */
5
9
  const Context = createContext();
10
+ /** For a component made of this one's parts: a date picker. */
11
+ export { Context as PopoverContext };
6
12
  function usePopover() {
7
13
  const made = useContext(Context);
8
14
  if (!made)
@@ -20,7 +26,10 @@ function Root(props) {
20
26
  return <Context.Provider value={made}>{props.children}</Context.Provider>;
21
27
  }
22
28
  const Portal = (props) => (<BodyPortal mounted={usePopover().mounted}>{props.children}</BodyPortal>);
23
- /** A positioner's own props, written where its placement reads them, before its element attaches. */
29
+ /**
30
+ * A positioner's own props, written where its placement reads them, before its element
31
+ * attaches: the one place they are named. Gives back what is left, for the part's element.
32
+ */
24
33
  export function positioned(props, positioning) {
25
34
  const [local, rest] = splitProps(props, [
26
35
  "side",
@@ -28,15 +37,24 @@ export function positioned(props, positioning) {
28
37
  "sideOffset",
29
38
  "alignOffset",
30
39
  "collisionPadding",
40
+ "anchor",
31
41
  ]);
32
- createComputed(() => positioning.set(defined({ ...local })));
42
+ createComputed(() => {
43
+ const anchor = local.anchor;
44
+ positioning.set(defined({
45
+ ...local,
46
+ // A function is asked here, so a change of the signal it reads is followed; and given
47
+ // whole while it has nothing, to be asked again as the popup is placed.
48
+ anchor: typeof anchor === "function" ? (anchor() ?? anchor) : anchor,
49
+ }));
50
+ });
33
51
  return rest;
34
52
  }
35
53
  function Positioner(props) {
36
54
  const made = usePopover();
37
- return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
55
+ return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
38
56
  }
39
- const part = (name, tag) => (props) => <Part part={usePopover()[name]} tag={tag} {...props}/>;
57
+ const part = (name, tag) => (props) => <Part of={usePopover()[name]} tag={tag} {...props}/>;
40
58
  export const Popover = {
41
59
  Root,
42
60
  Portal,
@@ -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 of={made.root} tag="div" {...rest}/>
21
+ </Context.Provider>);
22
+ }
23
+ const Frame = (props) => <Part of={useQrCode().frame} tag="svg" {...props}/>;
24
+ const Pattern = (props) => <Part of={useQrCode().pattern} tag="path" {...props}/>;
25
+ export const QrCode = { Root, Frame, Pattern };
@@ -21,11 +21,12 @@ function Root(props) {
21
21
  "readOnly",
22
22
  "required",
23
23
  "name",
24
+ "form",
24
25
  "id",
25
26
  ]);
26
27
  const generated = createUniqueId();
27
28
  const field = useContext(FieldContext);
28
- const made = controller(within(createRadioGroup, { field, direction: useContext(DirectionContext) }), () => ({
29
+ const made = controller(within((createRadioGroup), { field, direction: useContext(DirectionContext) }), () => ({
29
30
  id: local.id ?? generated,
30
31
  value: local.value,
31
32
  defaultValue: local.defaultValue,
@@ -33,10 +34,11 @@ function Root(props) {
33
34
  readOnly: local.readOnly,
34
35
  required: local.required,
35
36
  name: local.name,
37
+ form: local.form,
36
38
  onValueChange: (value, details) => local.onValueChange?.(value, details),
37
39
  }));
38
40
  return (<Context.Provider value={made}>
39
- <Part part={made.root} tag="div" {...rest}/>
41
+ <Part of={made.root} tag="div" {...rest}/>
40
42
  </Context.Provider>);
41
43
  }
42
44
  function Item(props) {
@@ -47,9 +49,9 @@ function Item(props) {
47
49
  const read = () => defined(options.get());
48
50
  const group = useRadioGroup();
49
51
  return (<ItemContext.Provider value={value}>
50
- <Part part={group.item(value, read)} tag="span" {...rest}>
52
+ <Part of={group.item(value, read)} tag="span" {...rest}>
51
53
  {local.children}
52
- <Part part={group.itemInput(value, read)} tag="input"/>
54
+ <Part of={group.itemInput(value, read)} tag="input"/>
53
55
  </Part>
54
56
  </ItemContext.Provider>);
55
57
  }
@@ -60,7 +62,7 @@ function Indicator(props) {
60
62
  onMount(() => onCleanup(indicator.mount()));
61
63
  const mounted = fromSignal(indicator.mounted);
62
64
  return (<Show when={mounted() || local.keepMounted}>
63
- <Part part={indicator.part} tag="span" {...rest}/>
65
+ <Part of={indicator.part} tag="span" {...rest}/>
64
66
  </Show>);
65
67
  }
66
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 of={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 of={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 of={part} tag="div" {...rest}/>;
45
+ }
46
+ export const Resizable = { Group, Panel, Handle };
package/src/runtime.jsx CHANGED
@@ -1,5 +1,5 @@
1
- import { mergeProps, sameProps, signal } from "@kirana-ui/core";
2
- import { Show, createComputed, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, } from "solid-js";
1
+ import { mergeProps, sameProps, signal, stateOf } from "@kirana-ui/core";
2
+ import { Show, children, createComputed, createContext, createRenderEffect, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, useContext, } from "solid-js";
3
3
  import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
4
4
  /** A core signal as a Solid accessor: tracked by whatever calls it. */
5
5
  export function fromSignal(source) {
@@ -46,12 +46,15 @@ function toSolid(props) {
46
46
  return out;
47
47
  }
48
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.
49
+ * The element of a part (`of`), 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. What the part holds
51
+ * is its children here: with `as` they are the element's, and with `render` they are handed to
52
+ * the caller's function as the `children` of its props, so a control drawn as another element
53
+ * keeps the native input a form and a label reach.
51
54
  */
52
55
  export function Part(props) {
53
- const [local, caller] = splitProps(props, ["part", "tag", "as", "render", "children"]);
54
- const own = fromSignal(untrack(() => local.part).props);
56
+ const [local, caller] = splitProps(props, ["of", "tag", "as", "render", "children"]);
57
+ const own = fromSignal(untrack(() => local.of).props);
55
58
  // Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
56
59
  // the starting style) waits for the mount that follows. It belongs to this component, not to
57
60
  // the effect that spreads the props (which hands the ref over again, and is torn down, each time
@@ -62,8 +65,12 @@ export function Part(props) {
62
65
  if (element === attached)
63
66
  return;
64
67
  attached = element;
65
- const part = untrack(() => local.part);
68
+ const part = untrack(() => local.of);
66
69
  runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
70
+ // The caller's own `ref` (Solid hands a component a function, whatever was written).
71
+ const theirs = untrack(() => caller.ref);
72
+ if (typeof theirs === "function")
73
+ theirs(element);
67
74
  };
68
75
  const merged = createMemo(() => {
69
76
  const theirs = {};
@@ -71,17 +78,55 @@ export function Part(props) {
71
78
  theirs[key] = caller[key];
72
79
  return { ...mergeProps(theirs, toSolid(own())), ref: attach };
73
80
  });
81
+ const state = () => stateOf(own());
74
82
  return (<Show when={local.render} fallback={<Dynamic component={local.as ?? local.tag} {...merged()}>
75
83
  {local.children}
76
84
  </Dynamic>}>
77
- {(render) => render()(merged)}
85
+ {(render) => {
86
+ // Resolved once: a change of the part's props hands the same nodes over again, and
87
+ // the element keeps them.
88
+ const held = children(() => local.children);
89
+ const handed = createMemo(() => ({ ...merged(), children: held() }));
90
+ return render()(handed, state);
91
+ }}
78
92
  </Show>);
79
93
  }
94
+ /**
95
+ * Its children as children of `target`, an element drawn elsewhere: with no element of its own
96
+ * around them (Solid's `Portal` adds one), so the page is the same as on the other adapters.
97
+ */
98
+ export function Into(props) {
99
+ const resolved = children(() => props.children);
100
+ // Before any mount work of the children: their elements are in the page by then.
101
+ createRenderEffect(() => {
102
+ const target = props.target;
103
+ const nodes = resolved.toArray().filter((each) => each instanceof Node);
104
+ for (const node of nodes)
105
+ target.appendChild(node);
106
+ onCleanup(() => {
107
+ for (const node of nodes)
108
+ if (node.parentNode === target)
109
+ target.removeChild(node);
110
+ });
111
+ });
112
+ return null;
113
+ }
114
+ const PortalContainer = createContext();
115
+ /**
116
+ * Says where every popup inside it is drawn, the popups those open included: an element of
117
+ * the page (a shadow root's host, a full-screen element) in place of `<body>`.
118
+ */
119
+ export function PortalProvider(props) {
120
+ return (<PortalContainer.Provider value={() => props.container}>
121
+ {props.children}
122
+ </PortalContainer.Provider>);
123
+ }
80
124
  /** Its children in a container at the end of the page, while `mounted`. */
81
125
  export function Portal(props) {
82
126
  const shown = fromSignal(untrack(() => props.mounted));
127
+ const container = useContext(PortalContainer);
83
128
  return (<Show when={shown()}>
84
- <SolidPortal ref={(container) => container.setAttribute("data-kirana-portal", "")}>
129
+ <SolidPortal mount={container?.() ?? undefined} ref={(outlet) => outlet.setAttribute("data-kirana-portal", "")}>
85
130
  {props.children}
86
131
  </SolidPortal>
87
132
  </Show>);
@@ -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 of={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 of={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 of={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 of={corner.part} tag="div" {...props}/>
43
+ </Show>);
44
+ }
45
+ const part = (name) => (props) => <Part of={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
+ };
package/src/select.jsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defined, within } from "@kirana-ui/core";
2
2
  import { createSelect } from "@kirana-ui/core/select";
3
- import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
3
+ import { Show, createComputed, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
4
4
  import { positioned } from "./popover.jsx";
5
5
  import { FieldContext } from "./field-context.js";
6
6
  import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
@@ -15,7 +15,7 @@ function useSelect() {
15
15
  function Root(props) {
16
16
  const generated = createUniqueId();
17
17
  const field = useContext(FieldContext);
18
- const made = controller(within(createSelect, { field }), () => ({
18
+ const made = controller(within((createSelect), { field }), () => ({
19
19
  id: props.id ?? generated,
20
20
  value: props.value,
21
21
  defaultValue: props.defaultValue,
@@ -24,54 +24,102 @@ function Root(props) {
24
24
  disabled: props.disabled,
25
25
  required: props.required,
26
26
  name: props.name,
27
+ form: props.form,
27
28
  items: props.items,
29
+ multiple: props.multiple,
30
+ values: props.values,
31
+ defaultValues: props.defaultValues,
32
+ virtualized: props.virtualized,
28
33
  onValueChange: (value, details) => props.onValueChange?.(value, details),
34
+ onValuesChange: (values, details) => props.onValuesChange?.(values, details),
29
35
  onOpenChange: (open, details) => props.onOpenChange?.(open, details),
30
36
  }));
31
37
  const named = fromSignal(made.named);
32
38
  return (<Context.Provider value={made}>
33
39
  {props.children}
34
40
  <Show when={named()}>
35
- <Part part={made.input} tag="input"/>
41
+ <Part of={made.input} tag="input"/>
36
42
  </Show>
37
43
  </Context.Provider>);
38
44
  }
39
45
  const Portal = (props) => (<BodyPortal mounted={useSelect().mounted}>{props.children}</BodyPortal>);
46
+ /**
47
+ * `alignItemWithTrigger`: the list opens over its trigger, the chosen item's text on the
48
+ * trigger's own, where there is room and unless a finger opened it.
49
+ */
40
50
  function Positioner(props) {
41
51
  const made = useSelect();
42
- return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
52
+ const [local, rest] = splitProps(props, ["alignItemWithTrigger"]);
53
+ createComputed(() => made.alignItemWithTrigger.set(Boolean(local.alignItemWithTrigger)));
54
+ return <Part of={made.positioner} tag="div" {...positioned(rest, made.positioning)}/>;
43
55
  }
44
- /** Shows the chosen value's label, or `placeholder` while nothing is chosen. */
45
56
  function Value(props) {
46
57
  const [local, rest] = splitProps(props, ["placeholder", "children"]);
47
58
  const made = useSelect();
48
- const label = fromSignal(made.label);
49
- return (<Part part={made.valuePart} tag="span" {...rest}>
50
- {local.children ?? label() ?? local.placeholder}
59
+ const shown = fromSignal(made.shown);
60
+ const drawn = () => {
61
+ const given = local.children;
62
+ // A function that takes nothing is an element of Solid's own, drawn as it is.
63
+ if (typeof given !== "function" || given.length === 0) {
64
+ return given ?? shown().label ?? local.placeholder;
65
+ }
66
+ const draw = given;
67
+ return made.multiple
68
+ ? draw(() => shown().values, () => shown().labels)
69
+ : draw(() => shown().value, () => shown().label);
70
+ };
71
+ return (<Part of={made.valuePart} tag="span" {...rest}>
72
+ {drawn()}
51
73
  </Part>);
52
74
  }
53
75
  /** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
54
76
  function Item(props) {
55
- const [local, rest] = splitProps(props, ["value", "disabled", "label"]);
77
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "index"]);
56
78
  // An item is its value for as long as it is in the page.
57
79
  const value = untrack(() => local.value);
58
- const options = toSignal(() => ({ disabled: local.disabled, label: local.label }));
80
+ const options = toSignal(() => ({
81
+ disabled: local.disabled,
82
+ label: local.label,
83
+ index: local.index,
84
+ }));
59
85
  const part = useSelect().item(value, () => defined(options.get()));
60
86
  return (<ItemContext.Provider value={value}>
61
- <Part part={part} tag="div" {...rest}/>
87
+ <Part of={part} tag="div" {...rest}/>
62
88
  </ItemContext.Provider>);
63
89
  }
64
- const ItemText = (props) => (<Part part={useSelect().itemText(useContext(ItemContext))} tag="span" {...props}/>);
90
+ const ItemText = (props) => (<Part of={useSelect().itemText(useContext(ItemContext))} tag="span" {...props}/>);
65
91
  function ItemIndicator(props) {
66
92
  const [local, rest] = splitProps(props, ["keepMounted"]);
67
93
  const made = useSelect();
68
94
  const value = useContext(ItemContext);
69
95
  const selected = fromSignal(made.selected(value));
70
96
  return (<Show when={selected() || local.keepMounted}>
71
- <Part part={made.itemIndicator(value)} tag="span" {...rest}/>
97
+ <Part of={made.itemIndicator(value)} tag="span" {...rest}/>
72
98
  </Show>);
73
99
  }
74
- const part = (name, tag) => (props) => (<Part part={useSelect()[name]} tag={tag} {...props}/>);
100
+ const GroupContext = createContext();
101
+ /** Items that belong together, named by their `<Select.GroupLabel>`. */
102
+ function Group(props) {
103
+ const [local, rest] = splitProps(props, ["id"]);
104
+ const generated = createUniqueId();
105
+ const group = useSelect().group(untrack(() => local.id) ?? generated);
106
+ return (<GroupContext.Provider value={group}>
107
+ <Part of={group.root} tag="div" {...rest}/>
108
+ </GroupContext.Provider>);
109
+ }
110
+ /** Names the group it is in. With no group around it, it is plain text. */
111
+ const GroupLabel = (props) => (<Part of={useContext(GroupContext)?.label ?? useSelect().groupLabel} tag="div" {...props}/>);
112
+ function scrollArrow(direction) {
113
+ return (props) => {
114
+ const arrow = useSelect().scrollArrow(direction);
115
+ onMount(() => onCleanup(arrow.mount()));
116
+ const mounted = fromSignal(arrow.mounted);
117
+ return (<Show when={mounted()}>
118
+ <Part of={arrow.part} tag="div" {...props}/>
119
+ </Show>);
120
+ };
121
+ }
122
+ const part = (name, tag) => (props) => <Part of={useSelect()[name]} tag={tag} {...props}/>;
75
123
  export const Select = {
76
124
  Root,
77
125
  Portal,
@@ -82,4 +130,14 @@ export const Select = {
82
130
  ItemIndicator,
83
131
  Trigger: part("trigger", "button"),
84
132
  Popup: part("popup", "div"),
133
+ /** The items' own box inside the popup, when the popup also holds scroll arrows. */
134
+ List: part("list", "div"),
135
+ /** In the page while there is more of the list above: it scrolls it under a moving pointer. */
136
+ ScrollUpArrow: scrollArrow("up"),
137
+ /** In the page while there is more of the list below. */
138
+ ScrollDownArrow: scrollArrow("down"),
139
+ Group,
140
+ GroupLabel,
141
+ /** A line between groups. */
142
+ Separator: part("separator", "div"),
85
143
  };
package/src/separator.jsx CHANGED
@@ -4,5 +4,5 @@ import { Part, controller } from "./runtime.jsx";
4
4
  export function Separator(props) {
5
5
  const [local, rest] = splitProps(props, ["orientation"]);
6
6
  const made = controller(createSeparator, () => ({ orientation: local.orientation }));
7
- return <Part part={made.root} tag="div" {...rest}/>;
7
+ return <Part of={made.root} tag="div" {...rest}/>;
8
8
  }