@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/field.jsx ADDED
@@ -0,0 +1,64 @@
1
+ import { createField } from "@kirana-ui/core/field";
2
+ import { Show, createUniqueId, onCleanup, onMount, splitProps, useContext } from "solid-js";
3
+ import { FieldContext } from "./field-context.js";
4
+ import { FieldsetContext } from "./fieldset.jsx";
5
+ import { FormContext } from "./form.jsx";
6
+ import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
7
+ function useField() {
8
+ const made = useContext(FieldContext);
9
+ if (!made)
10
+ throw new Error("A Field part must be inside <Field.Root>");
11
+ return made;
12
+ }
13
+ function Root(props) {
14
+ const [local, rest] = splitProps(props, [
15
+ "name",
16
+ "disabled",
17
+ "invalid",
18
+ "validate",
19
+ "validationMode",
20
+ "validationDebounceTime",
21
+ "id",
22
+ ]);
23
+ const generated = createUniqueId();
24
+ const around = { form: useContext(FormContext), fieldset: useContext(FieldsetContext) };
25
+ const made = controller((source) => createField(source, around), () => ({
26
+ ...local,
27
+ id: local.id ?? generated,
28
+ validate: (value) => local.validate?.(value) ?? null,
29
+ }));
30
+ return (<FieldContext.Provider value={made}>
31
+ <Part part={made.root} tag="div" {...rest}/>
32
+ </FieldContext.Provider>);
33
+ }
34
+ /**
35
+ * What is wrong, or its children in its place. In the page while it applies. `match` is one of
36
+ * the browser's findings (`"valueMissing"`) to show for only that, or `true` to show always.
37
+ */
38
+ function FieldError(props) {
39
+ const [local, rest] = splitProps(props, ["match", "children"]);
40
+ const options = toSignal(() => ({ match: local.match }));
41
+ const error = useField().error(() => options.get().match);
42
+ onMount(() => onCleanup(error.mount()));
43
+ const mounted = fromSignal(error.mounted);
44
+ const text = fromSignal(error.text);
45
+ return (<Show when={mounted()}>
46
+ <Part part={error.part} tag="div" {...rest}>
47
+ {local.children ?? text()}
48
+ </Part>
49
+ </Show>);
50
+ }
51
+ /** Draws nothing itself: its child, a function, is given the field's validity. */
52
+ function Validity(props) {
53
+ return props.children(fromSignal(useField().validity));
54
+ }
55
+ const part = (key, tag) => (props) => (<Part part={useField()[key]} tag={tag} {...props}/>);
56
+ export const Field = {
57
+ Root,
58
+ Label: part("label", "label"),
59
+ /** An `<input>`; `as="textarea"` or `as="select"` for another. */
60
+ Control: part("control", "input"),
61
+ Description: part("description", "p"),
62
+ Error: FieldError,
63
+ Validity,
64
+ };
@@ -0,0 +1,24 @@
1
+ import { createFieldset } from "@kirana-ui/core/fieldset";
2
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
3
+ import { Part, controller } from "./runtime.jsx";
4
+ /** The fieldset a field is in, if it is in one. */
5
+ export const FieldsetContext = createContext();
6
+ function useFieldset() {
7
+ const made = useContext(FieldsetContext);
8
+ if (!made)
9
+ throw new Error("A Fieldset part must be inside <Fieldset.Root>");
10
+ return made;
11
+ }
12
+ function Root(props) {
13
+ const [local, rest] = splitProps(props, ["disabled", "id"]);
14
+ const generated = createUniqueId();
15
+ const made = controller(createFieldset, () => ({
16
+ id: local.id ?? generated,
17
+ disabled: local.disabled,
18
+ }));
19
+ return (<FieldsetContext.Provider value={made}>
20
+ <Part part={made.root} tag="fieldset" {...rest}/>
21
+ </FieldsetContext.Provider>);
22
+ }
23
+ const Legend = (props) => (<Part part={useFieldset().legend} tag="div" {...props}/>);
24
+ export const Fieldset = { Root, Legend };
package/src/form.jsx ADDED
@@ -0,0 +1,26 @@
1
+ import { createForm } from "@kirana-ui/core/form";
2
+ import { createContext, splitProps } from "solid-js";
3
+ import { Part, controller } from "./runtime.jsx";
4
+ /** The form a field is in, if it is in one. */
5
+ export const FormContext = createContext();
6
+ /** A `<form>` whose fields say what is wrong; `onFormSubmit` takes the values once all are valid. */
7
+ export function Form(props) {
8
+ const [local, rest] = splitProps(props, [
9
+ "errors",
10
+ "onClearErrors",
11
+ "onFormSubmit",
12
+ "validationMode",
13
+ ]);
14
+ const made = controller(createForm, () => ({
15
+ errors: local.errors,
16
+ validationMode: local.validationMode,
17
+ // Only when the caller takes the values: without it the form submits as a form does.
18
+ onFormSubmit: local.onFormSubmit
19
+ ? (values, details) => local.onFormSubmit?.(values, details)
20
+ : undefined,
21
+ onClearErrors: (errors) => local.onClearErrors?.(errors),
22
+ }));
23
+ return (<FormContext.Provider value={made}>
24
+ <Part part={made.root} tag="form" {...rest}/>
25
+ </FormContext.Provider>);
26
+ }
@@ -0,0 +1,3 @@
1
+ import { createHoverCard } from "@kirana-ui/core/hover-card";
2
+ import { hoverPopup } from "./hover-popup.jsx";
3
+ export const HoverCard = hoverPopup("HoverCard", createHoverCard, "a");
@@ -0,0 +1,48 @@
1
+ import { defined } from "@kirana-ui/core";
2
+ import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
3
+ import { positioned } from "./popover.jsx";
4
+ import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
5
+ /** The parts of a popup the pointer opens: a tooltip's, a hover card's. */
6
+ export function hoverPopup(name, create, triggerTag) {
7
+ const Context = createContext();
8
+ function use() {
9
+ const made = useContext(Context);
10
+ if (!made)
11
+ throw new Error(`A ${name} part must be inside <${name}.Root>`);
12
+ return made;
13
+ }
14
+ function Root(props) {
15
+ const generated = createUniqueId();
16
+ const made = controller(create, () => ({
17
+ id: props.id ?? generated,
18
+ open: props.open,
19
+ defaultOpen: props.defaultOpen,
20
+ delay: props.delay,
21
+ closeDelay: props.closeDelay,
22
+ disabled: props.disabled,
23
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
24
+ }));
25
+ return <Context.Provider value={made}>{props.children}</Context.Provider>;
26
+ }
27
+ const Portal = (props) => (<BodyPortal mounted={use().mounted}>{props.children}</BodyPortal>);
28
+ function Positioner(props) {
29
+ const made = use();
30
+ return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
31
+ }
32
+ const part = (key, tag) => (props) => (<Part part={use()[key]} tag={tag} {...props}/>);
33
+ /** `delay` and `closeDelay` here come before the root's. */
34
+ function Trigger(props) {
35
+ const [local, rest] = splitProps(props, ["delay", "closeDelay"]);
36
+ const made = use();
37
+ createComputed(() => made.timing.set(defined({ ...local })));
38
+ return <Part part={made.trigger} tag={triggerTag} {...rest}/>;
39
+ }
40
+ return {
41
+ Root,
42
+ Portal,
43
+ Positioner,
44
+ Trigger,
45
+ Popup: part("popup", "div"),
46
+ Arrow: part("arrow", "div"),
47
+ };
48
+ }
package/src/index.js ADDED
@@ -0,0 +1,47 @@
1
+ export { Accordion } from "./accordion.jsx";
2
+ export { Checkbox } from "./checkbox.jsx";
3
+ export { Collapsible } from "./collapsible.jsx";
4
+ export { AlertDialog, Dialog, Drawer } from "./dialog.jsx";
5
+ export { MessageScroller } from "./message-scroller.jsx";
6
+ export { HoverCard } from "./hover-card.jsx";
7
+ export { Combobox } from "./combobox.jsx";
8
+ export { Listbox } from "./listbox.jsx";
9
+ export { ContextMenu, Menu } from "./menu.jsx";
10
+ export { Menubar } from "./menubar.jsx";
11
+ export { NavigationMenu } from "./navigation-menu.jsx";
12
+ export { Otp } from "./otp.jsx";
13
+ export { DateField } from "./date-field.jsx";
14
+ export { Input } from "./input.jsx";
15
+ export { Label } from "./label.jsx";
16
+ export { Command } from "./command.jsx";
17
+ export { NumberField } from "./number-field.jsx";
18
+ export { Autocomplete } from "./autocomplete.jsx";
19
+ export { Pagination } from "./pagination.jsx";
20
+ export { DatePicker } from "./date-picker.jsx";
21
+ export { Calendar } from "./calendar.jsx";
22
+ export { QrCode } from "./qr-code.jsx";
23
+ export { Autosize } from "./autosize.jsx";
24
+ export { Carousel } from "./carousel.jsx";
25
+ export { Toast, createToaster } from "./toast.jsx";
26
+ export { Resizable } from "./resizable.jsx";
27
+ export { Popover } from "./popover.jsx";
28
+ export { RadioGroup } from "./radio-group.jsx";
29
+ export { Select } from "./select.jsx";
30
+ export { Switch } from "./switch.jsx";
31
+ export { Tabs } from "./tabs.jsx";
32
+ export { Tooltip } from "./tooltip.jsx";
33
+ export { Avatar } from "./avatar.jsx";
34
+ export { Button } from "./button.jsx";
35
+ export { Meter } from "./meter.jsx";
36
+ export { Progress } from "./progress.jsx";
37
+ export { Separator } from "./separator.jsx";
38
+ export { Toggle } from "./toggle.jsx";
39
+ export { ToggleGroup } from "./toggle-group.jsx";
40
+ export { Toolbar } from "./toolbar.jsx";
41
+ export { ScrollArea } from "./scroll-area.jsx";
42
+ export { Slider } from "./slider.jsx";
43
+ export { Field } from "./field.jsx";
44
+ export { Fieldset } from "./fieldset.jsx";
45
+ export { Form } from "./form.jsx";
46
+ export { DirectionProvider, useDirection } from "./direction.jsx";
47
+ export { PortalProvider } from "./runtime.jsx";
package/src/input.jsx ADDED
@@ -0,0 +1,17 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createInput } from "@kirana-ui/core/input";
3
+ import { splitProps, useContext } from "solid-js";
4
+ import { FieldContext } from "./field-context.js";
5
+ import { Part, controller } from "./runtime.jsx";
6
+ /**
7
+ * An `<input>`; `as="textarea"` for a text area. It takes what an `<input>` takes, and inside
8
+ * a `<Field.Root>` it is the field's control.
9
+ */
10
+ export function Input(props) {
11
+ const [local, rest] = splitProps(props, ["disabled", "onValueChange"]);
12
+ const made = controller(within(createInput, { field: useContext(FieldContext) }), () => ({
13
+ disabled: local.disabled,
14
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
15
+ }));
16
+ return <Part part={made.input} tag="input" {...rest}/>;
17
+ }
package/src/label.jsx ADDED
@@ -0,0 +1,9 @@
1
+ import { createLabel } from "@kirana-ui/core/label";
2
+ import { useContext } from "solid-js";
3
+ import { FieldContext } from "./field-context.js";
4
+ import { Part } from "./runtime.jsx";
5
+ /** A `<label>`. Inside a `<Field.Root>` it is the field's label. */
6
+ export function Label(props) {
7
+ const made = createLabel({ field: useContext(FieldContext) });
8
+ return <Part part={made.label} tag="label" {...props}/>;
9
+ }
@@ -0,0 +1,81 @@
1
+ import { defined } from "@kirana-ui/core";
2
+ import { createListbox } from "@kirana-ui/core/listbox";
3
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
4
+ import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
5
+ const Context = createContext();
6
+ const ItemContext = createContext();
7
+ const GroupContext = createContext();
8
+ function useListbox() {
9
+ const made = useContext(Context);
10
+ if (!made)
11
+ throw new Error("A Listbox part must be inside <Listbox.Root>");
12
+ return made;
13
+ }
14
+ function Root(props) {
15
+ const [local, rest] = splitProps(props, [
16
+ "value",
17
+ "defaultValue",
18
+ "onValueChange",
19
+ "multiple",
20
+ "disabled",
21
+ "loop",
22
+ "name",
23
+ "form",
24
+ "virtualized",
25
+ "id",
26
+ ]);
27
+ const generated = createUniqueId();
28
+ const made = controller(createListbox, () => ({
29
+ id: local.id ?? generated,
30
+ value: local.value,
31
+ defaultValue: local.defaultValue,
32
+ multiple: local.multiple,
33
+ disabled: local.disabled,
34
+ loop: local.loop,
35
+ name: local.name,
36
+ form: local.form,
37
+ virtualized: local.virtualized,
38
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
39
+ }));
40
+ return (<Context.Provider value={made}>
41
+ <Part part={made.root} tag="div" {...rest}/>
42
+ </Context.Provider>);
43
+ }
44
+ function Item(props) {
45
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "index"]);
46
+ // An item is its value for as long as it is in the page.
47
+ const value = untrack(() => local.value);
48
+ const options = toSignal(() => ({
49
+ disabled: local.disabled,
50
+ label: local.label,
51
+ index: local.index,
52
+ }));
53
+ const part = useListbox().item(value, () => defined(options.get()));
54
+ return (<ItemContext.Provider value={value}>
55
+ <Part part={part} tag="div" {...rest}/>
56
+ </ItemContext.Provider>);
57
+ }
58
+ function ItemIndicator(props) {
59
+ const [local, rest] = splitProps(props, ["keepMounted"]);
60
+ const made = useListbox();
61
+ const value = useContext(ItemContext);
62
+ const selected = fromSignal(made.selected(value));
63
+ return (<Show when={selected() || local.keepMounted}>
64
+ <Part part={made.indicator(value)} tag="span" {...rest}/>
65
+ </Show>);
66
+ }
67
+ function Group(props) {
68
+ const [local, rest] = splitProps(props, ["id"]);
69
+ const generated = createUniqueId();
70
+ const group = useListbox().group(untrack(() => local.id) ?? generated);
71
+ return (<GroupContext.Provider value={group}>
72
+ <Part part={group.root} tag="div" {...rest}/>
73
+ </GroupContext.Provider>);
74
+ }
75
+ function GroupLabel(props) {
76
+ const group = useContext(GroupContext);
77
+ if (!group)
78
+ throw new Error("A Listbox.GroupLabel must be inside <Listbox.Group>");
79
+ return <Part part={group.label} tag="div" {...props}/>;
80
+ }
81
+ export const Listbox = { Root, Item, ItemIndicator, Group, GroupLabel };
package/src/menu.jsx ADDED
@@ -0,0 +1,164 @@
1
+ import { defined, within } from "@kirana-ui/core";
2
+ import { createMenu } from "@kirana-ui/core/menu";
3
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { MenubarContext } from "./menubar-context.js";
6
+ import { positioned } from "./popover.jsx";
7
+ import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
8
+ const Context = createContext();
9
+ const GroupContext = createContext(null);
10
+ const CheckboxContext = createContext();
11
+ const RadioGroupContext = createContext();
12
+ const RadioItemContext = createContext();
13
+ function useMenu() {
14
+ const made = useContext(Context);
15
+ if (!made)
16
+ throw new Error("A Menu part must be inside <Menu.Root>");
17
+ return made;
18
+ }
19
+ function inside(found, parent) {
20
+ if (!found)
21
+ throw new Error(`A Menu part must be inside <Menu.${parent}>`);
22
+ return found;
23
+ }
24
+ function make(props, kind) {
25
+ const generated = createUniqueId();
26
+ const direction = useContext(DirectionContext);
27
+ const parent = kind === "submenu" ? useMenu() : undefined;
28
+ const menubar = kind === "menu" ? (useContext(MenubarContext) ?? undefined) : undefined;
29
+ const around = { parent, direction, menubar, context: kind === "context" };
30
+ const made = controller(within(createMenu, around), () => ({
31
+ id: props.id ?? generated,
32
+ open: props.open,
33
+ defaultOpen: props.defaultOpen,
34
+ disabled: props.disabled,
35
+ loop: props.loop,
36
+ modal: props.modal,
37
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
38
+ }));
39
+ return (<Context.Provider value={made}>
40
+ {/* A group around a submenu is not a group of the submenu's own items; nor is a menu
41
+ written inside a bar's menu one of the bar's. */}
42
+ <MenubarContext.Provider value={null}>
43
+ <GroupContext.Provider value={null}>{props.children}</GroupContext.Provider>
44
+ </MenubarContext.Provider>
45
+ </Context.Provider>);
46
+ }
47
+ const Root = (props) => make(props, "menu");
48
+ /** A menu for an area of the page, opened at the pointer. Its trigger is the area. */
49
+ const ContextRoot = (props) => make(props, "context");
50
+ /** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */
51
+ const SubmenuRoot = (props) => make(props, "submenu");
52
+ const Portal = (props) => (<BodyPortal mounted={useMenu().mounted}>{props.children}</BodyPortal>);
53
+ function Positioner(props) {
54
+ const made = useMenu();
55
+ return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
56
+ }
57
+ const ITEM = ["disabled", "label", "closeOnClick"];
58
+ function Item(props) {
59
+ const [local, rest] = splitProps(props, ITEM);
60
+ const options = toSignal(() => ({ ...local }));
61
+ const part = useMenu().item(() => defined(options.get()));
62
+ return <Part part={part} tag="div" {...rest}/>;
63
+ }
64
+ /** An item that is a link: `href` and the rest go to its `<a>`. */
65
+ function LinkItem(props) {
66
+ const [local, rest] = splitProps(props, ITEM);
67
+ const options = toSignal(() => ({ ...local }));
68
+ const part = useMenu().item(() => defined(options.get()));
69
+ return <Part part={part} tag="a" {...rest}/>;
70
+ }
71
+ function Group(props) {
72
+ const [local, rest] = splitProps(props, ["id"]);
73
+ const generated = createUniqueId();
74
+ const group = useMenu().group(untrack(() => local.id) ?? generated);
75
+ return (<GroupContext.Provider value={group}>
76
+ <Part part={group.root} tag="div" {...rest}/>
77
+ </GroupContext.Provider>);
78
+ }
79
+ /** Names the group it is in. With no group around it, it is plain text. */
80
+ const GroupLabel = (props) => (<Part part={useContext(GroupContext)?.label ?? useMenu().label} tag="div" {...props}/>);
81
+ function CheckboxItem(props) {
82
+ const [local, rest] = splitProps(props, [...ITEM, "checked", "defaultChecked", "onCheckedChange"]);
83
+ const item = controller(useMenu().checkboxItem, () => ({
84
+ checked: local.checked,
85
+ defaultChecked: local.defaultChecked,
86
+ disabled: local.disabled,
87
+ label: local.label,
88
+ closeOnClick: local.closeOnClick,
89
+ onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
90
+ }));
91
+ return (<CheckboxContext.Provider value={item}>
92
+ <Part part={item.part} tag="div" {...rest}/>
93
+ </CheckboxContext.Provider>);
94
+ }
95
+ function CheckboxItemIndicator(props) {
96
+ const [local, rest] = splitProps(props, ["keepMounted"]);
97
+ const item = inside(useContext(CheckboxContext), "CheckboxItem");
98
+ const checked = fromSignal(item.checked);
99
+ return (<Show when={checked() || local.keepMounted}>
100
+ <Part part={item.indicator} tag="span" {...rest}/>
101
+ </Show>);
102
+ }
103
+ function RadioGroup(props) {
104
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "disabled"]);
105
+ const group = controller((useMenu().radioGroup), () => ({
106
+ value: local.value,
107
+ defaultValue: local.defaultValue,
108
+ disabled: local.disabled,
109
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
110
+ }));
111
+ return (<RadioGroupContext.Provider value={group}>
112
+ <Part part={group.root} tag="div" {...rest}/>
113
+ </RadioGroupContext.Provider>);
114
+ }
115
+ function RadioItem(props) {
116
+ const [local, rest] = splitProps(props, [...ITEM, "value"]);
117
+ // An item is its value for as long as it is in the page.
118
+ const value = untrack(() => local.value);
119
+ const options = toSignal(() => ({
120
+ disabled: local.disabled,
121
+ label: local.label,
122
+ closeOnClick: local.closeOnClick,
123
+ }));
124
+ const part = inside(useContext(RadioGroupContext), "RadioGroup").item(value, () => defined(options.get()));
125
+ return (<RadioItemContext.Provider value={value}>
126
+ <Part part={part} tag="div" {...rest}/>
127
+ </RadioItemContext.Provider>);
128
+ }
129
+ function RadioItemIndicator(props) {
130
+ const [local, rest] = splitProps(props, ["keepMounted"]);
131
+ const group = inside(useContext(RadioGroupContext), "RadioGroup");
132
+ const value = useContext(RadioItemContext);
133
+ const checked = fromSignal(group.checked(value));
134
+ return (<Show when={checked() || local.keepMounted}>
135
+ <Part part={group.indicator(value)} tag="span" {...rest}/>
136
+ </Show>);
137
+ }
138
+ const part = (name, tag) => (props) => <Part part={useMenu()[name]} tag={tag} {...props}/>;
139
+ export const Menu = {
140
+ Root,
141
+ Portal,
142
+ Positioner,
143
+ Trigger: part("trigger", "button"),
144
+ Popup: part("popup", "div"),
145
+ Arrow: part("arrow", "div"),
146
+ Item,
147
+ LinkItem,
148
+ Group,
149
+ GroupLabel,
150
+ Separator: part("separator", "div"),
151
+ CheckboxItem,
152
+ CheckboxItemIndicator,
153
+ RadioGroup,
154
+ RadioItem,
155
+ RadioItemIndicator,
156
+ SubmenuRoot,
157
+ SubmenuTrigger: part("trigger", "div"),
158
+ };
159
+ export const ContextMenu = {
160
+ ...Menu,
161
+ Root: ContextRoot,
162
+ /** The area a secondary press, or a long press on a touch screen, opens the menu in. */
163
+ Trigger: part("area", "div"),
164
+ };
@@ -0,0 +1,3 @@
1
+ import { createContext } from "solid-js";
2
+ /** The bar a menu is one of the menus of, if it is in one. */
3
+ export const MenubarContext = createContext(null);
@@ -0,0 +1,21 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createMenubar } from "@kirana-ui/core/menubar";
3
+ import { createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { MenubarContext } from "./menubar-context.js";
6
+ import { Part, controller } from "./runtime.jsx";
7
+ /** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */
8
+ export function Menubar(props) {
9
+ const [local, rest] = splitProps(props, ["loop", "disabled", "orientation", "id"]);
10
+ const generated = createUniqueId();
11
+ const direction = useContext(DirectionContext);
12
+ const made = controller(within(createMenubar, { direction }), () => ({
13
+ id: local.id ?? generated,
14
+ loop: local.loop,
15
+ disabled: local.disabled,
16
+ orientation: local.orientation,
17
+ }));
18
+ return (<MenubarContext.Provider value={made}>
19
+ <Part part={made.root} tag="div" {...rest}/>
20
+ </MenubarContext.Provider>);
21
+ }
@@ -0,0 +1,27 @@
1
+ import { createMessageScroller } from "@kirana-ui/core/message-scroller";
2
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
3
+ import { Part, controller } from "./runtime.jsx";
4
+ const Context = createContext();
5
+ function useScroller() {
6
+ const made = useContext(Context);
7
+ if (!made)
8
+ throw new Error("A MessageScroller part must be inside <MessageScroller.Root>");
9
+ return made;
10
+ }
11
+ function Root(props) {
12
+ const [local, rest] = splitProps(props, ["initial", "threshold", "onAtBottomChange", "id"]);
13
+ const generated = createUniqueId();
14
+ const made = controller(createMessageScroller, () => ({
15
+ id: local.id ?? generated,
16
+ initial: local.initial,
17
+ threshold: local.threshold,
18
+ onAtBottomChange: (atBottom, details) => local.onAtBottomChange?.(atBottom, details),
19
+ }));
20
+ return (<Context.Provider value={made}>
21
+ <Part part={made.root} tag="div" {...rest}/>
22
+ </Context.Provider>);
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}/>);
27
+ export const MessageScroller = { Root, Viewport, Content, Button };
package/src/meter.jsx ADDED
@@ -0,0 +1,3 @@
1
+ import { createMeter } from "@kirana-ui/core/meter";
2
+ import { valueBar } from "./value-bar.jsx";
3
+ export const Meter = valueBar("Meter", (props) => createMeter(props));
@@ -0,0 +1,95 @@
1
+ import { defined, within } from "@kirana-ui/core";
2
+ import { createNavigationMenu } from "@kirana-ui/core/navigation-menu";
3
+ import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { positioned } from "./popover.jsx";
6
+ import { Into, Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
7
+ const Context = createContext();
8
+ const ItemContext = createContext();
9
+ function useNavigation() {
10
+ const made = useContext(Context);
11
+ if (!made)
12
+ throw new Error("A NavigationMenu part must be inside <NavigationMenu.Root>");
13
+ return made;
14
+ }
15
+ function useItem() {
16
+ const item = useContext(ItemContext);
17
+ if (!item)
18
+ throw new Error("A NavigationMenu part must be inside <NavigationMenu.Item>");
19
+ return item;
20
+ }
21
+ function Root(props) {
22
+ const [local, rest] = splitProps(props, [
23
+ "value",
24
+ "defaultValue",
25
+ "onValueChange",
26
+ "delay",
27
+ "closeDelay",
28
+ "orientation",
29
+ "id",
30
+ ]);
31
+ const generated = createUniqueId();
32
+ const direction = useContext(DirectionContext);
33
+ const made = controller(within(createNavigationMenu, { direction }), () => ({
34
+ id: local.id ?? generated,
35
+ value: local.value,
36
+ defaultValue: local.defaultValue,
37
+ delay: local.delay,
38
+ closeDelay: local.closeDelay,
39
+ orientation: local.orientation,
40
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
41
+ }));
42
+ return (<Context.Provider value={made}>
43
+ <Part part={made.root} tag="nav" {...rest}/>
44
+ </Context.Provider>);
45
+ }
46
+ /** `value` tells this item from the others; an item that is only a link needs none. */
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);
52
+ onMount(() => onCleanup(item.mount()));
53
+ return (<ItemContext.Provider value={item}>
54
+ <li>{props.children}</li>
55
+ </ItemContext.Provider>);
56
+ }
57
+ /** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
58
+ function Content(props) {
59
+ const item = useItem();
60
+ const mounted = fromSignal(item.mounted);
61
+ const viewport = fromSignal(useNavigation().viewportElement);
62
+ return (<Show when={mounted() ? viewport() : undefined}>
63
+ {(target) => (<Into target={target()}>
64
+ <Part part={item.content} tag="div" {...props}/>
65
+ </Into>)}
66
+ </Show>);
67
+ }
68
+ function Link(props) {
69
+ const [local, rest] = splitProps(props, ["active", "closeOnClick"]);
70
+ const options = toSignal(() => ({ ...local }));
71
+ const part = useNavigation().link(() => defined(options.get()));
72
+ return <Part part={part} tag="a" {...rest}/>;
73
+ }
74
+ const Portal = (props) => (<BodyPortal mounted={useNavigation().mounted}>{props.children}</BodyPortal>);
75
+ function Positioner(props) {
76
+ const made = useNavigation();
77
+ return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
78
+ }
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}/>);
81
+ export const NavigationMenu = {
82
+ Root,
83
+ List: part("list", "ul"),
84
+ Item,
85
+ Trigger: itemPart("trigger", "button"),
86
+ Icon: itemPart("icon", "span"),
87
+ Content,
88
+ Link,
89
+ Portal,
90
+ Positioner,
91
+ Popup: part("popup", "div"),
92
+ Viewport: part("viewport", "div"),
93
+ Arrow: part("arrow", "div"),
94
+ Backdrop: part("backdrop", "div"),
95
+ };