@kirana-ui/solid 0.1.1 → 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 (193) hide show
  1. package/dom/accordion.js +9 -6
  2. package/dom/agent.js +3 -0
  3. package/dom/autosize.js +1 -1
  4. package/dom/avatar.js +3 -3
  5. package/dom/button.js +1 -1
  6. package/dom/calendar.js +12 -8
  7. package/dom/carousel.js +6 -6
  8. package/dom/checkbox.js +3 -3
  9. package/dom/collapsible.js +3 -3
  10. package/dom/combobox.js +19 -11
  11. package/dom/command.js +8 -8
  12. package/dom/date-field.js +7 -3
  13. package/dom/date-picker.js +2 -2
  14. package/dom/dialog.js +5 -2
  15. package/dom/field.js +3 -3
  16. package/dom/fieldset.js +2 -2
  17. package/dom/form.js +1 -1
  18. package/dom/hover-popup.js +3 -3
  19. package/dom/input.js +1 -1
  20. package/dom/label.js +1 -1
  21. package/dom/listbox.js +5 -5
  22. package/dom/menu.js +11 -11
  23. package/dom/menubar.js +1 -1
  24. package/dom/message-scroller.js +4 -4
  25. package/dom/navigation-menu.js +18 -21
  26. package/dom/number-field.js +3 -3
  27. package/dom/otp.js +4 -4
  28. package/dom/pagination.js +3 -3
  29. package/dom/popover.js +20 -7
  30. package/dom/qr-code.js +3 -3
  31. package/dom/radio-group.js +4 -4
  32. package/dom/resizable.js +3 -3
  33. package/dom/runtime.js +23 -7
  34. package/dom/scroll-area.js +5 -5
  35. package/dom/select.js +25 -13
  36. package/dom/separator.js +1 -1
  37. package/dom/slider.js +10 -7
  38. package/dom/switch.js +3 -3
  39. package/dom/tabs.js +5 -5
  40. package/dom/testing.js +3 -0
  41. package/dom/toast.js +57 -20
  42. package/dom/toggle-group.js +1 -1
  43. package/dom/toggle.js +1 -1
  44. package/dom/toolbar.js +4 -4
  45. package/dom/value-bar.js +3 -3
  46. package/llms.txt +1588 -224
  47. package/package.json +18 -2
  48. package/server/accordion.js +9 -6
  49. package/server/agent.js +3 -0
  50. package/server/autosize.js +1 -1
  51. package/server/avatar.js +3 -3
  52. package/server/button.js +1 -1
  53. package/server/calendar.js +12 -8
  54. package/server/carousel.js +6 -6
  55. package/server/checkbox.js +3 -3
  56. package/server/collapsible.js +3 -3
  57. package/server/combobox.js +19 -11
  58. package/server/command.js +8 -8
  59. package/server/date-field.js +7 -3
  60. package/server/date-picker.js +2 -2
  61. package/server/dialog.js +5 -2
  62. package/server/field.js +3 -3
  63. package/server/fieldset.js +2 -2
  64. package/server/form.js +1 -1
  65. package/server/hover-popup.js +3 -3
  66. package/server/input.js +1 -1
  67. package/server/label.js +1 -1
  68. package/server/listbox.js +5 -5
  69. package/server/menu.js +11 -11
  70. package/server/menubar.js +1 -1
  71. package/server/message-scroller.js +4 -4
  72. package/server/navigation-menu.js +18 -15
  73. package/server/number-field.js +3 -3
  74. package/server/otp.js +4 -4
  75. package/server/pagination.js +3 -3
  76. package/server/popover.js +20 -7
  77. package/server/qr-code.js +3 -3
  78. package/server/radio-group.js +4 -4
  79. package/server/resizable.js +3 -3
  80. package/server/runtime.js +23 -7
  81. package/server/scroll-area.js +5 -5
  82. package/server/select.js +25 -13
  83. package/server/separator.js +1 -1
  84. package/server/slider.js +10 -7
  85. package/server/switch.js +3 -3
  86. package/server/tabs.js +5 -5
  87. package/server/testing.js +3 -0
  88. package/server/toast.js +57 -20
  89. package/server/toggle-group.js +1 -1
  90. package/server/toggle.js +1 -1
  91. package/server/toolbar.js +4 -4
  92. package/server/value-bar.js +3 -3
  93. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  94. package/src/accordion.jsx +10 -7
  95. package/src/agent.js +3 -0
  96. package/src/autosize.jsx +1 -1
  97. package/src/avatar.jsx +3 -3
  98. package/src/button.jsx +1 -1
  99. package/src/calendar.jsx +12 -8
  100. package/src/carousel.jsx +6 -6
  101. package/src/checkbox.jsx +3 -3
  102. package/src/collapsible.jsx +3 -3
  103. package/src/combobox.jsx +20 -12
  104. package/src/command.jsx +8 -8
  105. package/src/date-field.jsx +7 -3
  106. package/src/date-picker.jsx +2 -2
  107. package/src/dialog.jsx +8 -2
  108. package/src/field.jsx +3 -3
  109. package/src/fieldset.jsx +2 -2
  110. package/src/form.jsx +1 -1
  111. package/src/hover-popup.jsx +3 -3
  112. package/src/input.jsx +1 -1
  113. package/src/label.jsx +1 -1
  114. package/src/listbox.jsx +6 -6
  115. package/src/menu.jsx +11 -11
  116. package/src/menubar.jsx +1 -1
  117. package/src/message-scroller.jsx +4 -4
  118. package/src/navigation-menu.jsx +14 -13
  119. package/src/number-field.jsx +3 -3
  120. package/src/otp.jsx +4 -4
  121. package/src/pagination.jsx +3 -3
  122. package/src/popover.jsx +20 -4
  123. package/src/qr-code.jsx +3 -3
  124. package/src/radio-group.jsx +5 -5
  125. package/src/resizable.jsx +3 -3
  126. package/src/runtime.jsx +21 -7
  127. package/src/scroll-area.jsx +5 -5
  128. package/src/select.jsx +28 -14
  129. package/src/separator.jsx +1 -1
  130. package/src/slider.jsx +11 -8
  131. package/src/switch.jsx +3 -3
  132. package/src/tabs.jsx +6 -6
  133. package/src/testing.js +3 -0
  134. package/src/toast.jsx +38 -10
  135. package/src/toggle-group.jsx +2 -2
  136. package/src/toggle.jsx +1 -1
  137. package/src/toolbar.jsx +4 -4
  138. package/src/value-bar.jsx +3 -3
  139. package/types/accordion.d.ts +21 -19
  140. package/types/agent.d.ts +1 -0
  141. package/types/alert-dialog.d.ts +1 -0
  142. package/types/autocomplete.d.ts +1 -0
  143. package/types/autosize.d.ts +4 -1
  144. package/types/avatar.d.ts +12 -5
  145. package/types/button.d.ts +4 -2
  146. package/types/calendar.d.ts +35 -18
  147. package/types/carousel.d.ts +18 -10
  148. package/types/checkbox.d.ts +9 -6
  149. package/types/collapsible.d.ts +11 -7
  150. package/types/combobox.d.ts +61 -62
  151. package/types/command.d.ts +27 -17
  152. package/types/context-menu.d.ts +1 -0
  153. package/types/date-field.d.ts +20 -9
  154. package/types/date-picker.d.ts +25 -34
  155. package/types/dialog.d.ts +42 -31
  156. package/types/direction.d.ts +1 -0
  157. package/types/drawer.d.ts +1 -0
  158. package/types/field.d.ts +19 -11
  159. package/types/fieldset.d.ts +8 -3
  160. package/types/form.d.ts +5 -2
  161. package/types/hover-card.d.ts +16 -10
  162. package/types/hover-popup.d.ts +23 -13
  163. package/types/index.d.ts +12 -1
  164. package/types/input.d.ts +4 -3
  165. package/types/label.d.ts +4 -1
  166. package/types/listbox.d.ts +18 -20
  167. package/types/menu.d.ts +56 -42
  168. package/types/menubar.d.ts +6 -4
  169. package/types/message-scroller.d.ts +12 -6
  170. package/types/meter.d.ts +16 -7
  171. package/types/navigation-menu.d.ts +35 -29
  172. package/types/number-field.d.ts +13 -6
  173. package/types/otp.d.ts +17 -10
  174. package/types/pagination.d.ts +18 -10
  175. package/types/popover.d.ts +37 -12
  176. package/types/progress.d.ts +16 -7
  177. package/types/qr-code.d.ts +10 -4
  178. package/types/radio-group.d.ts +15 -17
  179. package/types/resizable.d.ts +12 -7
  180. package/types/runtime.d.ts +36 -12
  181. package/types/scroll-area.d.ts +17 -9
  182. package/types/select.d.ts +55 -46
  183. package/types/separator.d.ts +5 -3
  184. package/types/slider.d.ts +25 -13
  185. package/types/switch.d.ts +7 -4
  186. package/types/tabs.d.ts +20 -16
  187. package/types/testing.d.ts +1 -0
  188. package/types/toast.d.ts +40 -16
  189. package/types/toggle-group.d.ts +6 -11
  190. package/types/toggle.d.ts +4 -3
  191. package/types/toolbar.d.ts +19 -14
  192. package/types/tooltip.d.ts +16 -10
  193. package/types/value-bar.d.ts +21 -10
@@ -18,10 +18,10 @@ function Root(props) {
18
18
  onAtBottomChange: (atBottom, details) => local.onAtBottomChange?.(atBottom, details),
19
19
  }));
20
20
  return (<Context.Provider value={made}>
21
- <Part part={made.root} tag="div" {...rest}/>
21
+ <Part of={made.root} tag="div" {...rest}/>
22
22
  </Context.Provider>);
23
23
  }
24
- const Viewport = (props) => (<Part part={useScroller().viewport} tag="div" {...props}/>);
25
- const Content = (props) => (<Part part={useScroller().content} tag="div" {...props}/>);
26
- const Button = (props) => (<Part part={useScroller().button} tag="button" {...props}/>);
24
+ const Viewport = (props) => <Part of={useScroller().viewport} tag="div" {...props}/>;
25
+ const Content = (props) => <Part of={useScroller().content} tag="div" {...props}/>;
26
+ const Button = (props) => <Part of={useScroller().button} tag="button" {...props}/>;
27
27
  export const MessageScroller = { Root, Viewport, Content, Button };
@@ -30,7 +30,7 @@ function Root(props) {
30
30
  ]);
31
31
  const generated = createUniqueId();
32
32
  const direction = useContext(DirectionContext);
33
- const made = controller(within(createNavigationMenu, { direction }), () => ({
33
+ const made = controller(within((createNavigationMenu), { direction }), () => ({
34
34
  id: local.id ?? generated,
35
35
  value: local.value,
36
36
  defaultValue: local.defaultValue,
@@ -40,18 +40,19 @@ function Root(props) {
40
40
  onValueChange: (value, details) => local.onValueChange?.(value, details),
41
41
  }));
42
42
  return (<Context.Provider value={made}>
43
- <Part part={made.root} tag="nav" {...rest}/>
43
+ <Part of={made.root} tag="nav" {...rest}/>
44
44
  </Context.Provider>);
45
45
  }
46
- /** `value` tells this item from the others; an item that is only a link needs none. */
46
+ /** `value` tells this item from the others; an item that is given none makes its own. */
47
47
  function Item(props) {
48
- const value = untrack(() => props.value);
49
- if (value === undefined)
50
- return <li>{props.children}</li>;
51
- const item = useNavigation().item(value);
48
+ const [local, rest] = splitProps(props, ["value"]);
49
+ const made = useNavigation();
50
+ const generated = createUniqueId();
51
+ const value = untrack(() => local.value);
52
+ const item = made.item(value === undefined ? generated : value);
52
53
  onMount(() => onCleanup(item.mount()));
53
54
  return (<ItemContext.Provider value={item}>
54
- <li>{props.children}</li>
55
+ <Part of={made.itemPart} tag="li" {...rest}/>
55
56
  </ItemContext.Provider>);
56
57
  }
57
58
  /** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
@@ -61,7 +62,7 @@ function Content(props) {
61
62
  const viewport = fromSignal(useNavigation().viewportElement);
62
63
  return (<Show when={mounted() ? viewport() : undefined}>
63
64
  {(target) => (<Into target={target()}>
64
- <Part part={item.content} tag="div" {...props}/>
65
+ <Part of={item.content} tag="div" {...props}/>
65
66
  </Into>)}
66
67
  </Show>);
67
68
  }
@@ -69,15 +70,15 @@ function Link(props) {
69
70
  const [local, rest] = splitProps(props, ["active", "closeOnClick"]);
70
71
  const options = toSignal(() => ({ ...local }));
71
72
  const part = useNavigation().link(() => defined(options.get()));
72
- return <Part part={part} tag="a" {...rest}/>;
73
+ return <Part of={part} tag="a" {...rest}/>;
73
74
  }
74
75
  const Portal = (props) => (<BodyPortal mounted={useNavigation().mounted}>{props.children}</BodyPortal>);
75
76
  function Positioner(props) {
76
77
  const made = useNavigation();
77
- return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
78
+ return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
78
79
  }
79
- const part = (name, tag) => (props) => <Part part={useNavigation()[name]} tag={tag} {...props}/>;
80
- const itemPart = (name, tag) => (props) => (<Part part={useItem()[name]} tag={tag} {...props}/>);
80
+ const part = (name, tag) => (props) => <Part of={useNavigation()[name]} tag={tag} {...props}/>;
81
+ const itemPart = (name, tag) => (props) => <Part of={useItem()[name]} tag={tag} {...props}/>;
81
82
  export const NavigationMenu = {
82
83
  Root,
83
84
  List: part("list", "ul"),
@@ -57,15 +57,15 @@ function Root(props) {
57
57
  }));
58
58
  const named = fromSignal(made.named);
59
59
  return (<Context.Provider value={made}>
60
- <Part part={made.root} tag="div" {...rest}>
60
+ <Part of={made.root} tag="div" {...rest}>
61
61
  {local.children}
62
62
  <Show when={named()}>
63
- <Part part={made.hidden} tag="input"/>
63
+ <Part of={made.hidden} tag="input"/>
64
64
  </Show>
65
65
  </Part>
66
66
  </Context.Provider>);
67
67
  }
68
- const part = (name, tag) => (props) => <Part part={useNumberField()[name]} tag={tag} {...props}/>;
68
+ const part = (name, tag) => (props) => <Part of={useNumberField()[name]} tag={tag} {...props}/>;
69
69
  export const NumberField = {
70
70
  Root,
71
71
  Group: part("group", "div"),
package/src/otp.jsx CHANGED
@@ -36,7 +36,7 @@ function Root(props) {
36
36
  onComplete: (value) => local.onComplete?.(value),
37
37
  }));
38
38
  return (<Context.Provider value={made}>
39
- <Part part={made.root} tag="div" {...rest}/>
39
+ <Part of={made.root} tag="div" {...rest}/>
40
40
  </Context.Provider>);
41
41
  }
42
42
  /** One cell: it shows its character, then whatever it is given (a caret). */
@@ -45,7 +45,7 @@ function Slot(props) {
45
45
  const slot = useOtp().slot(untrack(() => local.index));
46
46
  const char = fromSignal(slot.char);
47
47
  return (<SlotContext.Provider value={slot}>
48
- <Part part={slot.part} tag="div" {...rest}>
48
+ <Part of={slot.part} tag="div" {...rest}>
49
49
  {char()}
50
50
  {local.children}
51
51
  </Part>
@@ -59,10 +59,10 @@ function Caret(props) {
59
59
  throw new Error("An Otp.Caret must be inside <Otp.Slot>");
60
60
  const shown = fromSignal(slot.caret);
61
61
  return (<Show when={shown()}>
62
- <Part part={made.caretPart} tag="div" {...props}/>
62
+ <Part of={made.caretPart} tag="div" {...props}/>
63
63
  </Show>);
64
64
  }
65
- const part = (name, tag) => (props) => (<Part part={useOtp()[name]} tag={tag} {...props}/>);
65
+ const part = (name, tag) => (props) => <Part of={useOtp()[name]} tag={tag} {...props}/>;
66
66
  export const Otp = {
67
67
  Root,
68
68
  Input: part("input", "input"),
@@ -33,7 +33,7 @@ function Root(props) {
33
33
  onPageChange: (page, details) => local.onPageChange?.(page, details),
34
34
  }));
35
35
  return (<Context.Provider value={made}>
36
- <Part part={made.root} tag="nav" {...rest}/>
36
+ <Part of={made.root} tag="nav" {...rest}/>
37
37
  </Context.Provider>);
38
38
  }
39
39
  /** Draws its child once for each piece of the row: a page, or the mark for pages left out. */
@@ -47,9 +47,9 @@ function Items(props) {
47
47
  function Item(props) {
48
48
  const [local, rest] = splitProps(props, ["page"]);
49
49
  const made = usePagination();
50
- return <Part part={made.item(local.page)} tag="button" {...rest}/>;
50
+ return <Part of={made.item(local.page)} tag="button" {...rest}/>;
51
51
  }
52
- const part = (name, tag) => (props) => (<Part part={usePagination()[name]} tag={tag} {...props}/>);
52
+ const part = (name, tag) => (props) => <Part of={usePagination()[name]} tag={tag} {...props}/>;
53
53
  export const Pagination = {
54
54
  Root,
55
55
  Items,
package/src/popover.jsx CHANGED
@@ -2,6 +2,10 @@ 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();
6
10
  /** For a component made of this one's parts: a date picker. */
7
11
  export { Context as PopoverContext };
@@ -22,7 +26,10 @@ function Root(props) {
22
26
  return <Context.Provider value={made}>{props.children}</Context.Provider>;
23
27
  }
24
28
  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. */
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
+ */
26
33
  export function positioned(props, positioning) {
27
34
  const [local, rest] = splitProps(props, [
28
35
  "side",
@@ -30,15 +37,24 @@ export function positioned(props, positioning) {
30
37
  "sideOffset",
31
38
  "alignOffset",
32
39
  "collisionPadding",
40
+ "anchor",
33
41
  ]);
34
- 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
+ });
35
51
  return rest;
36
52
  }
37
53
  function Positioner(props) {
38
54
  const made = usePopover();
39
- return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
55
+ return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
40
56
  }
41
- 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}/>;
42
58
  export const Popover = {
43
59
  Root,
44
60
  Portal,
package/src/qr-code.jsx CHANGED
@@ -17,9 +17,9 @@ function Root(props) {
17
17
  correction: local.correction,
18
18
  }));
19
19
  return (<Context.Provider value={made}>
20
- <Part part={made.root} tag="div" {...rest}/>
20
+ <Part of={made.root} tag="div" {...rest}/>
21
21
  </Context.Provider>);
22
22
  }
23
- const Frame = (props) => <Part part={useQrCode().frame} tag="svg" {...props}/>;
24
- const Pattern = (props) => (<Part part={useQrCode().pattern} tag="path" {...props}/>);
23
+ const Frame = (props) => <Part of={useQrCode().frame} tag="svg" {...props}/>;
24
+ const Pattern = (props) => <Part of={useQrCode().pattern} tag="path" {...props}/>;
25
25
  export const QrCode = { Root, Frame, Pattern };
@@ -26,7 +26,7 @@ function Root(props) {
26
26
  ]);
27
27
  const generated = createUniqueId();
28
28
  const field = useContext(FieldContext);
29
- const made = controller(within(createRadioGroup, { field, direction: useContext(DirectionContext) }), () => ({
29
+ const made = controller(within((createRadioGroup), { field, direction: useContext(DirectionContext) }), () => ({
30
30
  id: local.id ?? generated,
31
31
  value: local.value,
32
32
  defaultValue: local.defaultValue,
@@ -38,7 +38,7 @@ function Root(props) {
38
38
  onValueChange: (value, details) => local.onValueChange?.(value, details),
39
39
  }));
40
40
  return (<Context.Provider value={made}>
41
- <Part part={made.root} tag="div" {...rest}/>
41
+ <Part of={made.root} tag="div" {...rest}/>
42
42
  </Context.Provider>);
43
43
  }
44
44
  function Item(props) {
@@ -49,9 +49,9 @@ function Item(props) {
49
49
  const read = () => defined(options.get());
50
50
  const group = useRadioGroup();
51
51
  return (<ItemContext.Provider value={value}>
52
- <Part part={group.item(value, read)} tag="span" {...rest}>
52
+ <Part of={group.item(value, read)} tag="span" {...rest}>
53
53
  {local.children}
54
- <Part part={group.itemInput(value, read)} tag="input"/>
54
+ <Part of={group.itemInput(value, read)} tag="input"/>
55
55
  </Part>
56
56
  </ItemContext.Provider>);
57
57
  }
@@ -62,7 +62,7 @@ function Indicator(props) {
62
62
  onMount(() => onCleanup(indicator.mount()));
63
63
  const mounted = fromSignal(indicator.mounted);
64
64
  return (<Show when={mounted() || local.keepMounted}>
65
- <Part part={indicator.part} tag="span" {...rest}/>
65
+ <Part of={indicator.part} tag="span" {...rest}/>
66
66
  </Show>);
67
67
  }
68
68
  export const RadioGroup = { Root, Item, Indicator };
package/src/resizable.jsx CHANGED
@@ -28,19 +28,19 @@ function Group(props) {
28
28
  onSizesChange: (sizes, details) => local.onSizesChange?.(sizes, details),
29
29
  }));
30
30
  return (<Context.Provider value={made}>
31
- <Part part={made.group} tag="div" {...rest}/>
31
+ <Part of={made.group} tag="div" {...rest}/>
32
32
  </Context.Provider>);
33
33
  }
34
34
  function Panel(props) {
35
35
  const [local, rest] = splitProps(props, ["defaultSize", "minSize", "maxSize"]);
36
36
  const options = toSignal(() => ({ ...local }));
37
37
  const part = useResizable().panel(() => defined(options.get()));
38
- return <Part part={part} tag="div" {...rest}/>;
38
+ return <Part of={part} tag="div" {...rest}/>;
39
39
  }
40
40
  function Handle(props) {
41
41
  const [local, rest] = splitProps(props, ["disabled"]);
42
42
  const options = toSignal(() => ({ disabled: local.disabled }));
43
43
  const part = useResizable().handle(() => defined(options.get()));
44
- return <Part part={part} tag="div" {...rest}/>;
44
+ return <Part of={part} tag="div" {...rest}/>;
45
45
  }
46
46
  export const Resizable = { Group, Panel, Handle };
package/src/runtime.jsx CHANGED
@@ -1,4 +1,4 @@
1
- import { mergeProps, sameProps, signal } from "@kirana-ui/core";
1
+ import { mergeProps, sameProps, signal, stateOf } from "@kirana-ui/core";
2
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. */
@@ -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,10 +78,17 @@ 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
  }
80
94
  /**
@@ -15,7 +15,7 @@ function Root(props) {
15
15
  const direction = useContext(DirectionContext);
16
16
  const made = controller(within(createScrollArea, { direction }), () => ({}));
17
17
  return (<Context.Provider value={made}>
18
- <Part part={made.root} tag="div" {...props}/>
18
+ <Part of={made.root} tag="div" {...props}/>
19
19
  </Context.Provider>);
20
20
  }
21
21
  /** `orientation` is which way it scrolls (`vertical` by default). */
@@ -25,7 +25,7 @@ function Scrollbar(props) {
25
25
  const shown = fromSignal(bar.shown);
26
26
  return (<ScrollbarContext.Provider value={bar}>
27
27
  <Show when={shown() || local.keepMounted}>
28
- <Part part={bar.part} tag="div" {...rest}/>
28
+ <Part of={bar.part} tag="div" {...rest}/>
29
29
  </Show>
30
30
  </ScrollbarContext.Provider>);
31
31
  }
@@ -33,16 +33,16 @@ function Thumb(props) {
33
33
  const bar = useContext(ScrollbarContext);
34
34
  if (!bar)
35
35
  throw new Error("A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>");
36
- return <Part part={bar.thumb} tag="div" {...props}/>;
36
+ return <Part of={bar.thumb} tag="div" {...props}/>;
37
37
  }
38
38
  function Corner(props) {
39
39
  const { corner } = useScrollArea();
40
40
  const shown = fromSignal(corner.shown);
41
41
  return (<Show when={shown()}>
42
- <Part part={corner.part} tag="div" {...props}/>
42
+ <Part of={corner.part} tag="div" {...props}/>
43
43
  </Show>);
44
44
  }
45
- const part = (name) => (props) => (<Part part={useScrollArea()[name]} tag="div" {...props}/>);
45
+ const part = (name) => (props) => <Part of={useScrollArea()[name]} tag="div" {...props}/>;
46
46
  export const ScrollArea = {
47
47
  Root,
48
48
  Viewport: part("viewport"),
package/src/select.jsx CHANGED
@@ -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,
@@ -26,15 +26,19 @@ function Root(props) {
26
26
  name: props.name,
27
27
  form: props.form,
28
28
  items: props.items,
29
+ multiple: props.multiple,
30
+ values: props.values,
31
+ defaultValues: props.defaultValues,
29
32
  virtualized: props.virtualized,
30
33
  onValueChange: (value, details) => props.onValueChange?.(value, details),
34
+ onValuesChange: (values, details) => props.onValuesChange?.(values, details),
31
35
  onOpenChange: (open, details) => props.onOpenChange?.(open, details),
32
36
  }));
33
37
  const named = fromSignal(made.named);
34
38
  return (<Context.Provider value={made}>
35
39
  {props.children}
36
40
  <Show when={named()}>
37
- <Part part={made.input} tag="input"/>
41
+ <Part of={made.input} tag="input"/>
38
42
  </Show>
39
43
  </Context.Provider>);
40
44
  }
@@ -47,15 +51,25 @@ function Positioner(props) {
47
51
  const made = useSelect();
48
52
  const [local, rest] = splitProps(props, ["alignItemWithTrigger"]);
49
53
  createComputed(() => made.alignItemWithTrigger.set(Boolean(local.alignItemWithTrigger)));
50
- return (<Part part={made.positioner} tag="div" {...positioned(rest, made.positioning)}/>);
54
+ return <Part of={made.positioner} tag="div" {...positioned(rest, made.positioning)}/>;
51
55
  }
52
- /** Shows the chosen value's label, or `placeholder` while nothing is chosen. */
53
56
  function Value(props) {
54
57
  const [local, rest] = splitProps(props, ["placeholder", "children"]);
55
58
  const made = useSelect();
56
- const label = fromSignal(made.label);
57
- return (<Part part={made.valuePart} tag="span" {...rest}>
58
- {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()}
59
73
  </Part>);
60
74
  }
61
75
  /** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
@@ -70,17 +84,17 @@ function Item(props) {
70
84
  }));
71
85
  const part = useSelect().item(value, () => defined(options.get()));
72
86
  return (<ItemContext.Provider value={value}>
73
- <Part part={part} tag="div" {...rest}/>
87
+ <Part of={part} tag="div" {...rest}/>
74
88
  </ItemContext.Provider>);
75
89
  }
76
- 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}/>);
77
91
  function ItemIndicator(props) {
78
92
  const [local, rest] = splitProps(props, ["keepMounted"]);
79
93
  const made = useSelect();
80
94
  const value = useContext(ItemContext);
81
95
  const selected = fromSignal(made.selected(value));
82
96
  return (<Show when={selected() || local.keepMounted}>
83
- <Part part={made.itemIndicator(value)} tag="span" {...rest}/>
97
+ <Part of={made.itemIndicator(value)} tag="span" {...rest}/>
84
98
  </Show>);
85
99
  }
86
100
  const GroupContext = createContext();
@@ -90,22 +104,22 @@ function Group(props) {
90
104
  const generated = createUniqueId();
91
105
  const group = useSelect().group(untrack(() => local.id) ?? generated);
92
106
  return (<GroupContext.Provider value={group}>
93
- <Part part={group.root} tag="div" {...rest}/>
107
+ <Part of={group.root} tag="div" {...rest}/>
94
108
  </GroupContext.Provider>);
95
109
  }
96
110
  /** Names the group it is in. With no group around it, it is plain text. */
97
- const GroupLabel = (props) => (<Part part={useContext(GroupContext)?.label ?? useSelect().groupLabel} tag="div" {...props}/>);
111
+ const GroupLabel = (props) => (<Part of={useContext(GroupContext)?.label ?? useSelect().groupLabel} tag="div" {...props}/>);
98
112
  function scrollArrow(direction) {
99
113
  return (props) => {
100
114
  const arrow = useSelect().scrollArrow(direction);
101
115
  onMount(() => onCleanup(arrow.mount()));
102
116
  const mounted = fromSignal(arrow.mounted);
103
117
  return (<Show when={mounted()}>
104
- <Part part={arrow.part} tag="div" {...props}/>
118
+ <Part of={arrow.part} tag="div" {...props}/>
105
119
  </Show>);
106
120
  };
107
121
  }
108
- const part = (name, tag) => (props) => <Part part={useSelect()[name]} tag={tag} {...props}/>;
122
+ const part = (name, tag) => (props) => <Part of={useSelect()[name]} tag={tag} {...props}/>;
109
123
  export const Select = {
110
124
  Root,
111
125
  Portal,
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
  }
package/src/slider.jsx CHANGED
@@ -11,6 +11,7 @@ function useSlider() {
11
11
  throw new Error("A Slider part must be inside <Slider.Root>");
12
12
  return made;
13
13
  }
14
+ // Given neither `value` nor `defaultValue`, a slider has one thumb: its value is a number.
14
15
  function Root(props) {
15
16
  const [local, rest] = splitProps(props, [
16
17
  "value",
@@ -34,25 +35,27 @@ function Root(props) {
34
35
  ]);
35
36
  const generated = createUniqueId();
36
37
  const field = useContext(FieldContext);
37
- const made = controller(within(createSlider, { field, direction: useContext(DirectionContext) }), () => ({
38
+ const made = controller(within((createSlider), { field, direction: useContext(DirectionContext) }), () => ({
38
39
  ...local,
39
40
  id: local.id ?? generated,
40
41
  onValueChange: (value, details) => local.onValueChange?.(value, details),
41
42
  onValueCommitted: (value, details) => local.onValueCommitted?.(value, details),
42
43
  }));
43
44
  return (<Context.Provider value={made}>
44
- <Part part={made.root} tag="div" {...rest}/>
45
+ <Part of={made.root} tag="div" {...rest}/>
45
46
  </Context.Provider>);
46
47
  }
47
48
  /** `index` is which value of a range the thumb is, from 0. */
48
49
  function Thumb(props) {
49
50
  const [local, rest] = splitProps(props, ["index", "children"]);
50
- // A thumb is its index for as long as it is in the page.
51
- const index = untrack(() => local.index ?? 0);
51
+ // A thumb is its index for as long as it is in the page. Given none, it takes its place
52
+ // among the slider's thumbs, in the order they are written.
53
+ const generated = createUniqueId();
54
+ const index = untrack(() => local.index ?? generated);
52
55
  const slider = useSlider();
53
- return (<Part part={slider.thumb(index)} tag="div" {...rest}>
56
+ return (<Part of={slider.thumb(index)} tag="div" {...rest}>
54
57
  {local.children}
55
- <Part part={slider.thumbInput(index)} tag="input"/>
58
+ <Part of={slider.thumbInput(index)} tag="input"/>
56
59
  </Part>);
57
60
  }
58
61
  /** The written value, or what its child, a function, makes of it and of the values. */
@@ -61,11 +64,11 @@ function Value(props) {
61
64
  const made = useSlider();
62
65
  const text = fromSignal(made.text);
63
66
  const values = fromSignal(made.values);
64
- return (<Part part={made.value} tag="output" {...rest}>
67
+ return (<Part of={made.value} tag="output" {...rest}>
65
68
  {local.children ? local.children(text, values) : text()}
66
69
  </Part>);
67
70
  }
68
- const part = (key) => (props) => (<Part part={useSlider()[key]} tag="div" {...props}/>);
71
+ const part = (key) => (props) => <Part of={useSlider()[key]} tag="div" {...props}/>;
69
72
  export const Slider = {
70
73
  Root,
71
74
  Value,
package/src/switch.jsx CHANGED
@@ -39,11 +39,11 @@ function Root(props) {
39
39
  onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
40
40
  }));
41
41
  return (<Context.Provider value={made}>
42
- <Part part={made.root} tag="span" {...rest}>
42
+ <Part of={made.root} tag="span" {...rest}>
43
43
  {local.children}
44
- <Part part={made.input} tag="input"/>
44
+ <Part of={made.input} tag="input"/>
45
45
  </Part>
46
46
  </Context.Provider>);
47
47
  }
48
- const Thumb = (props) => <Part part={useSwitch().thumb} tag="span" {...props}/>;
48
+ const Thumb = (props) => <Part of={useSwitch().thumb} tag="span" {...props}/>;
49
49
  export const Switch = { Root, Thumb };
package/src/tabs.jsx CHANGED
@@ -20,7 +20,7 @@ function Root(props) {
20
20
  ]);
21
21
  const generated = createUniqueId();
22
22
  const direction = useContext(DirectionContext);
23
- const made = controller(within(createTabs, { direction }), () => ({
23
+ const made = controller(within((createTabs), { direction }), () => ({
24
24
  id: local.id ?? generated,
25
25
  value: local.value,
26
26
  defaultValue: local.defaultValue,
@@ -28,23 +28,23 @@ function Root(props) {
28
28
  onValueChange: (value, details) => local.onValueChange?.(value, details),
29
29
  }));
30
30
  return (<Context.Provider value={made}>
31
- <Part part={made.root} tag="div" {...rest}/>
31
+ <Part of={made.root} tag="div" {...rest}/>
32
32
  </Context.Provider>);
33
33
  }
34
34
  function List(props) {
35
35
  const [local, rest] = splitProps(props, ["activateOnFocus", "loop"]);
36
36
  const made = useTabs();
37
37
  createComputed(() => made.listOptions.set(defined({ ...local })));
38
- return <Part part={made.list} tag="div" {...rest}/>;
38
+ return <Part of={made.list} tag="div" {...rest}/>;
39
39
  }
40
40
  function Tab(props) {
41
41
  const [local, rest] = splitProps(props, ["value", "disabled"]);
42
42
  const options = toSignal(() => ({ disabled: local.disabled }));
43
43
  // A tab is its value for as long as it is in the page.
44
44
  const part = useTabs().tab(untrack(() => local.value), () => defined(options.get()));
45
- return <Part part={part} tag="button" {...rest}/>;
45
+ return <Part of={part} tag="button" {...rest}/>;
46
46
  }
47
- const Indicator = (props) => (<Part part={useTabs().indicator} tag="span" {...props}/>);
47
+ const Indicator = (props) => <Part of={useTabs().indicator} tag="span" {...props}/>;
48
48
  /** `keepMounted` keeps the panel in the page, `hidden`, while its tab is not the active one. */
49
49
  function Panel(props) {
50
50
  const [local, rest] = splitProps(props, ["value", "keepMounted"]);
@@ -52,7 +52,7 @@ function Panel(props) {
52
52
  onMount(() => onCleanup(panel.mount()));
53
53
  const mounted = fromSignal(panel.mounted);
54
54
  return (<Show when={mounted() || local.keepMounted}>
55
- <Part part={panel.part} tag="div" {...rest}/>
55
+ <Part of={panel.part} tag="div" {...rest}/>
56
56
  </Show>);
57
57
  }
58
58
  export const Tabs = { Root, List, Tab, Indicator, Panel };
package/src/testing.js ADDED
@@ -0,0 +1,3 @@
1
+ // The testing kit is the core's, and the same on every framework: it is an entry here too, so
2
+ // a test imports it from the one package the project installed.
3
+ export * from "@kirana-ui/core/testing";