@kirana-ui/solid 0.0.0 → 0.1.1

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