@kirana-ui/solid 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dom/accordion.js +9 -6
  2. package/dom/agent.js +3 -0
  3. package/dom/autocomplete.js +2 -0
  4. package/dom/autosize.js +19 -0
  5. package/dom/avatar.js +3 -3
  6. package/dom/button.js +1 -1
  7. package/dom/calendar.js +145 -0
  8. package/dom/carousel.js +83 -0
  9. package/dom/checkbox.js +5 -4
  10. package/dom/collapsible.js +3 -3
  11. package/dom/combobox.js +289 -0
  12. package/dom/command.js +129 -0
  13. package/dom/context-menu.js +2 -0
  14. package/dom/date-field.js +90 -0
  15. package/dom/date-picker.js +103 -0
  16. package/dom/dialog.js +32 -1
  17. package/dom/drawer.js +2 -0
  18. package/dom/field.js +3 -3
  19. package/dom/fieldset.js +2 -2
  20. package/dom/form.js +1 -1
  21. package/dom/hover-popup.js +19 -4
  22. package/dom/index.js +26 -1
  23. package/dom/input.js +26 -0
  24. package/dom/label.js +18 -0
  25. package/dom/listbox.js +114 -0
  26. package/dom/menu.js +261 -0
  27. package/dom/menubar-context.js +3 -0
  28. package/dom/menubar.js +33 -0
  29. package/dom/message-scroller.js +56 -0
  30. package/dom/navigation-menu.js +147 -0
  31. package/dom/number-field.js +82 -0
  32. package/dom/otp.js +95 -0
  33. package/dom/pagination.js +74 -0
  34. package/dom/popover.js +22 -7
  35. package/dom/qr-code.js +48 -0
  36. package/dom/radio-group.js +6 -5
  37. package/dom/resizable.js +65 -0
  38. package/dom/runtime.js +59 -9
  39. package/dom/scroll-area.js +99 -0
  40. package/dom/select.js +91 -15
  41. package/dom/separator.js +1 -1
  42. package/dom/slider.js +11 -8
  43. package/dom/switch.js +5 -4
  44. package/dom/tabs.js +5 -5
  45. package/dom/testing.js +3 -0
  46. package/dom/toast.js +150 -0
  47. package/dom/toggle-group.js +37 -0
  48. package/dom/toggle.js +12 -4
  49. package/dom/toolbar-context.js +5 -0
  50. package/dom/toolbar.js +71 -0
  51. package/dom/value-bar.js +3 -3
  52. package/llms.txt +3202 -0
  53. package/package.json +236 -2
  54. package/server/accordion.js +9 -6
  55. package/server/agent.js +3 -0
  56. package/server/autocomplete.js +2 -0
  57. package/server/autosize.js +19 -0
  58. package/server/avatar.js +3 -3
  59. package/server/button.js +1 -1
  60. package/server/calendar.js +144 -0
  61. package/server/carousel.js +83 -0
  62. package/server/checkbox.js +5 -4
  63. package/server/collapsible.js +3 -3
  64. package/server/combobox.js +289 -0
  65. package/server/command.js +129 -0
  66. package/server/context-menu.js +2 -0
  67. package/server/date-field.js +90 -0
  68. package/server/date-picker.js +103 -0
  69. package/server/dialog.js +32 -1
  70. package/server/drawer.js +2 -0
  71. package/server/field.js +3 -3
  72. package/server/fieldset.js +2 -2
  73. package/server/form.js +1 -1
  74. package/server/hover-popup.js +19 -4
  75. package/server/index.js +26 -1
  76. package/server/input.js +26 -0
  77. package/server/label.js +18 -0
  78. package/server/listbox.js +114 -0
  79. package/server/menu.js +261 -0
  80. package/server/menubar-context.js +3 -0
  81. package/server/menubar.js +33 -0
  82. package/server/message-scroller.js +56 -0
  83. package/server/navigation-menu.js +147 -0
  84. package/server/number-field.js +81 -0
  85. package/server/otp.js +94 -0
  86. package/server/pagination.js +74 -0
  87. package/server/popover.js +22 -7
  88. package/server/qr-code.js +48 -0
  89. package/server/radio-group.js +6 -5
  90. package/server/resizable.js +65 -0
  91. package/server/runtime.js +58 -8
  92. package/server/scroll-area.js +99 -0
  93. package/server/select.js +91 -15
  94. package/server/separator.js +1 -1
  95. package/server/slider.js +11 -8
  96. package/server/switch.js +5 -4
  97. package/server/tabs.js +5 -5
  98. package/server/testing.js +3 -0
  99. package/server/toast.js +150 -0
  100. package/server/toggle-group.js +37 -0
  101. package/server/toggle.js +12 -4
  102. package/server/toolbar-context.js +5 -0
  103. package/server/toolbar.js +71 -0
  104. package/server/value-bar.js +3 -3
  105. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  106. package/src/accordion.jsx +10 -7
  107. package/src/agent.js +3 -0
  108. package/src/autocomplete.jsx +2 -0
  109. package/src/autosize.jsx +8 -0
  110. package/src/avatar.jsx +3 -3
  111. package/src/button.jsx +1 -1
  112. package/src/calendar.jsx +108 -0
  113. package/src/carousel.jsx +51 -0
  114. package/src/checkbox.jsx +5 -3
  115. package/src/collapsible.jsx +3 -3
  116. package/src/combobox.jsx +187 -0
  117. package/src/command.jsx +81 -0
  118. package/src/context-menu.js +2 -0
  119. package/src/date-field.jsx +71 -0
  120. package/src/date-picker.jsx +72 -0
  121. package/src/dialog.jsx +27 -1
  122. package/src/drawer.js +2 -0
  123. package/src/field.jsx +3 -3
  124. package/src/fieldset.jsx +2 -2
  125. package/src/form.jsx +1 -1
  126. package/src/hover-popup.jsx +12 -4
  127. package/src/index.js +26 -1
  128. package/src/input.jsx +17 -0
  129. package/src/label.jsx +9 -0
  130. package/src/listbox.jsx +81 -0
  131. package/src/menu.jsx +164 -0
  132. package/src/menubar-context.js +3 -0
  133. package/src/menubar.jsx +21 -0
  134. package/src/message-scroller.jsx +27 -0
  135. package/src/navigation-menu.jsx +96 -0
  136. package/src/number-field.jsx +75 -0
  137. package/src/otp.jsx +73 -0
  138. package/src/pagination.jsx +60 -0
  139. package/src/popover.jsx +22 -4
  140. package/src/qr-code.jsx +25 -0
  141. package/src/radio-group.jsx +7 -5
  142. package/src/resizable.jsx +46 -0
  143. package/src/runtime.jsx +54 -9
  144. package/src/scroll-area.jsx +53 -0
  145. package/src/select.jsx +72 -14
  146. package/src/separator.jsx +1 -1
  147. package/src/slider.jsx +13 -8
  148. package/src/switch.jsx +5 -3
  149. package/src/tabs.jsx +6 -6
  150. package/src/testing.js +3 -0
  151. package/src/toast.jsx +86 -0
  152. package/src/toggle-group.jsx +32 -0
  153. package/src/toggle.jsx +9 -3
  154. package/src/toolbar-context.js +5 -0
  155. package/src/toolbar.jsx +43 -0
  156. package/src/value-bar.jsx +3 -3
  157. package/types/accordion.d.ts +21 -19
  158. package/types/agent.d.ts +1 -0
  159. package/types/alert-dialog.d.ts +1 -0
  160. package/types/autocomplete.d.ts +2 -0
  161. package/types/autosize.d.ts +11 -0
  162. package/types/avatar.d.ts +12 -5
  163. package/types/button.d.ts +4 -2
  164. package/types/calendar.d.ts +57 -0
  165. package/types/carousel.d.ts +34 -0
  166. package/types/checkbox.d.ts +10 -6
  167. package/types/collapsible.d.ts +11 -7
  168. package/types/combobox.d.ts +105 -0
  169. package/types/command.d.ts +55 -0
  170. package/types/context-menu.d.ts +2 -0
  171. package/types/date-field.d.ts +34 -0
  172. package/types/date-picker.d.ts +40 -0
  173. package/types/dialog.d.ts +52 -20
  174. package/types/direction.d.ts +1 -0
  175. package/types/drawer.d.ts +2 -0
  176. package/types/field.d.ts +19 -11
  177. package/types/fieldset.d.ts +8 -3
  178. package/types/form.d.ts +5 -2
  179. package/types/hover-card.d.ts +16 -7
  180. package/types/hover-popup.d.ts +23 -10
  181. package/types/index.d.ts +39 -2
  182. package/types/input.d.ts +13 -0
  183. package/types/label.d.ts +7 -0
  184. package/types/listbox.d.ts +36 -0
  185. package/types/menu.d.ts +105 -0
  186. package/types/menubar-context.d.ts +3 -0
  187. package/types/menubar.d.ts +12 -0
  188. package/types/message-scroller.d.ts +22 -0
  189. package/types/meter.d.ts +16 -7
  190. package/types/navigation-menu.d.ts +50 -0
  191. package/types/number-field.d.ts +22 -0
  192. package/types/otp.d.ts +39 -0
  193. package/types/pagination.d.ts +31 -0
  194. package/types/popover.d.ts +41 -13
  195. package/types/progress.d.ts +16 -7
  196. package/types/qr-code.d.ts +20 -0
  197. package/types/radio-group.d.ts +15 -16
  198. package/types/resizable.d.ts +29 -0
  199. package/types/runtime.d.ts +53 -11
  200. package/types/scroll-area.d.ts +28 -0
  201. package/types/select.d.ts +66 -33
  202. package/types/separator.d.ts +5 -3
  203. package/types/slider.d.ts +25 -13
  204. package/types/switch.d.ts +8 -4
  205. package/types/tabs.d.ts +20 -16
  206. package/types/testing.d.ts +1 -0
  207. package/types/toast.d.ts +57 -0
  208. package/types/toggle-group.d.ts +9 -0
  209. package/types/toggle.d.ts +6 -3
  210. package/types/toolbar-context.d.ts +6 -0
  211. package/types/toolbar.d.ts +28 -0
  212. package/types/tooltip.d.ts +16 -7
  213. package/types/value-bar.d.ts +21 -10
@@ -0,0 +1,108 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createCalendar } from "@kirana-ui/core/calendar";
3
+ import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { Part, controller, fromSignal } from "./runtime.jsx";
6
+ /**
7
+ * The calendar its parts are inside. Exported for a component that is made of one (a date picker
8
+ * provides its own to the calendar's parts).
9
+ */
10
+ const Context = createContext();
11
+ /** For a component made of this one's parts: a date picker. */
12
+ export { Context as CalendarContext };
13
+ function useCalendar() {
14
+ const made = useContext(Context);
15
+ if (!made)
16
+ throw new Error("A Calendar part must be inside <Calendar.Root>");
17
+ return made;
18
+ }
19
+ function Root(props) {
20
+ const [local, rest] = splitProps(props, [
21
+ "value",
22
+ "defaultValue",
23
+ "onValueChange",
24
+ "mode",
25
+ "defaultFocusedValue",
26
+ "onMonthChange",
27
+ "locale",
28
+ "calendarSystem",
29
+ "min",
30
+ "max",
31
+ "isDateUnavailable",
32
+ "disabled",
33
+ "readOnly",
34
+ "fixedWeeks",
35
+ "id",
36
+ ]);
37
+ const generated = createUniqueId();
38
+ const direction = useContext(DirectionContext);
39
+ const made = controller(within(createCalendar, { direction }), () => ({
40
+ id: local.id ?? generated,
41
+ value: local.value,
42
+ defaultValue: local.defaultValue,
43
+ mode: local.mode,
44
+ defaultFocusedValue: local.defaultFocusedValue,
45
+ locale: local.locale,
46
+ calendarSystem: local.calendarSystem,
47
+ min: local.min,
48
+ max: local.max,
49
+ isDateUnavailable: local.isDateUnavailable,
50
+ disabled: local.disabled,
51
+ readOnly: local.readOnly,
52
+ fixedWeeks: local.fixedWeeks,
53
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
54
+ onMonthChange: (month) => local.onMonthChange?.(month),
55
+ }));
56
+ return (<Context.Provider value={made}>
57
+ <Part of={made.root} tag="div" {...rest}/>
58
+ </Context.Provider>);
59
+ }
60
+ /** Names the month shown, unless it is given something else to say. */
61
+ function Heading(props) {
62
+ const made = useCalendar();
63
+ const title = fromSignal(made.title);
64
+ return (<Part of={made.heading} tag="div" {...props}>
65
+ {props.children ?? title()}
66
+ </Part>);
67
+ }
68
+ const Previous = (props) => (<Part of={useCalendar().previous} tag="button" {...props}/>);
69
+ const Next = (props) => <Part of={useCalendar().next} tag="button" {...props}/>;
70
+ const Grid = (props) => <Part of={useCalendar().grid} tag="table" {...props}/>;
71
+ /** Draws its child once for each day of the week, in the locale's order. */
72
+ function Weekdays(props) {
73
+ const weekdays = fromSignal(useCalendar().weekdays);
74
+ return <For each={weekdays()}>{(weekday) => props.children(weekday)}</For>;
75
+ }
76
+ /** Draws its child once for each week of the month shown. */
77
+ function Weeks(props) {
78
+ const weeks = fromSignal(useCalendar().weeks);
79
+ return <For each={weeks()}>{(week) => props.children(week)}</For>;
80
+ }
81
+ function HeadCell(props) {
82
+ const [local, rest] = splitProps(props, ["weekday"]);
83
+ const part = useCalendar().headCell(local.weekday);
84
+ return <Part of={part} tag="th" {...rest}/>;
85
+ }
86
+ function Cell(props) {
87
+ const [local, rest] = splitProps(props, ["date"]);
88
+ // A cell is its day for as long as it is in the page.
89
+ const part = useCalendar().cell(local.date);
90
+ return <Part of={part} tag="td" {...rest}/>;
91
+ }
92
+ function Day(props) {
93
+ const [local, rest] = splitProps(props, ["date"]);
94
+ const part = useCalendar().day(local.date);
95
+ return <Part of={part} tag="button" {...rest}/>;
96
+ }
97
+ export const Calendar = {
98
+ Root,
99
+ Heading,
100
+ Previous,
101
+ Next,
102
+ Grid,
103
+ Weekdays,
104
+ HeadCell,
105
+ Weeks,
106
+ Cell,
107
+ Day,
108
+ };
@@ -0,0 +1,51 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createCarousel } from "@kirana-ui/core/carousel";
3
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { Part, controller } from "./runtime.jsx";
6
+ const Context = createContext();
7
+ function useCarousel() {
8
+ const made = useContext(Context);
9
+ if (!made)
10
+ throw new Error("A Carousel part must be inside <Carousel.Root>");
11
+ return made;
12
+ }
13
+ function Root(props) {
14
+ const [local, rest] = splitProps(props, [
15
+ "index",
16
+ "defaultIndex",
17
+ "onIndexChange",
18
+ "orientation",
19
+ "loop",
20
+ "id",
21
+ ]);
22
+ const generated = createUniqueId();
23
+ const direction = useContext(DirectionContext);
24
+ const made = controller(within(createCarousel, { direction }), () => ({
25
+ id: local.id ?? generated,
26
+ index: local.index,
27
+ defaultIndex: local.defaultIndex,
28
+ orientation: local.orientation,
29
+ loop: local.loop,
30
+ onIndexChange: (index, details) => local.onIndexChange?.(index, details),
31
+ }));
32
+ return (<Context.Provider value={made}>
33
+ <Part of={made.root} tag="div" {...rest}/>
34
+ </Context.Provider>);
35
+ }
36
+ const Viewport = (props) => <Part of={useCarousel().viewport} tag="div" {...props}/>;
37
+ function Item(props) {
38
+ const [local, rest] = splitProps(props, ["index"]);
39
+ // A slide is its place for as long as it is in the page.
40
+ const part = useCarousel().item(local.index);
41
+ return <Part of={part} tag="div" {...rest}/>;
42
+ }
43
+ const Previous = (props) => (<Part of={useCarousel().previous} tag="button" {...props}/>);
44
+ const Next = (props) => <Part of={useCarousel().next} tag="button" {...props}/>;
45
+ function Indicator(props) {
46
+ const [local, rest] = splitProps(props, ["index"]);
47
+ // A button is its slide for as long as it is in the page.
48
+ const part = useCarousel().indicator(local.index);
49
+ return <Part of={part} tag="button" {...rest}/>;
50
+ }
51
+ export const Carousel = { Root, Viewport, Item, Previous, Next, Indicator };
package/src/checkbox.jsx CHANGED
@@ -20,6 +20,7 @@ function Root(props) {
20
20
  "readOnly",
21
21
  "required",
22
22
  "name",
23
+ "form",
23
24
  "value",
24
25
  "id",
25
26
  "children",
@@ -35,13 +36,14 @@ function Root(props) {
35
36
  readOnly: local.readOnly,
36
37
  required: local.required,
37
38
  name: local.name,
39
+ form: local.form,
38
40
  value: local.value,
39
41
  onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
40
42
  }));
41
43
  return (<Context.Provider value={made}>
42
- <Part part={made.root} tag="span" {...rest}>
44
+ <Part of={made.root} tag="span" {...rest}>
43
45
  {local.children}
44
- <Part part={made.input} tag="input"/>
46
+ <Part of={made.input} tag="input"/>
45
47
  </Part>
46
48
  </Context.Provider>);
47
49
  }
@@ -51,7 +53,7 @@ function Indicator(props) {
51
53
  const made = useCheckbox();
52
54
  const mounted = fromSignal(made.indicatorMounted);
53
55
  return (<Show when={mounted() || local.keepMounted}>
54
- <Part part={made.indicator} tag="span" {...rest}/>
56
+ <Part of={made.indicator} tag="span" {...rest}/>
55
57
  </Show>);
56
58
  }
57
59
  export const Checkbox = { Root, Indicator };
@@ -19,17 +19,17 @@ function Root(props) {
19
19
  onOpenChange: (open, details) => local.onOpenChange?.(open, details),
20
20
  }));
21
21
  return (<Context.Provider value={made}>
22
- <Part part={made.root} tag="div" {...rest}/>
22
+ <Part of={made.root} tag="div" {...rest}/>
23
23
  </Context.Provider>);
24
24
  }
25
- const Trigger = (props) => (<Part part={useCollapsible().trigger} tag="button" {...props}/>);
25
+ const Trigger = (props) => (<Part of={useCollapsible().trigger} tag="button" {...props}/>);
26
26
  /** `keepMounted` keeps the closed panel in the page, `hidden`. */
27
27
  function Panel(props) {
28
28
  const [local, rest] = splitProps(props, ["keepMounted"]);
29
29
  const made = useCollapsible();
30
30
  const mounted = fromSignal(made.mounted);
31
31
  return (<Show when={mounted() || local.keepMounted}>
32
- <Part part={made.panel} tag="div" {...rest}/>
32
+ <Part of={made.panel} tag="div" {...rest}/>
33
33
  </Show>);
34
34
  }
35
35
  export const Collapsible = { Root, Trigger, Panel };
@@ -0,0 +1,187 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createAutocomplete } from "@kirana-ui/core/autocomplete";
3
+ import { createCombobox } from "@kirana-ui/core/combobox";
4
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
5
+ import { FieldContext } from "./field-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 ItemContext = createContext();
10
+ function useCombobox() {
11
+ const made = useContext(Context);
12
+ if (!made)
13
+ throw new Error("A Combobox part must be inside <Combobox.Root>");
14
+ return made;
15
+ }
16
+ function Root(props) {
17
+ const generated = createUniqueId();
18
+ const field = useContext(FieldContext);
19
+ const made = controller(within((createCombobox), { field }), () => ({
20
+ id: props.id ?? generated,
21
+ value: props.value,
22
+ defaultValue: props.defaultValue,
23
+ inputValue: props.inputValue,
24
+ defaultInputValue: props.defaultInputValue,
25
+ open: props.open,
26
+ defaultOpen: props.defaultOpen,
27
+ disabled: props.disabled,
28
+ required: props.required,
29
+ multiple: props.multiple,
30
+ values: props.values,
31
+ defaultValues: props.defaultValues,
32
+ onValuesChange: (values, details) => props.onValuesChange?.(values, details),
33
+ inline: props.inline,
34
+ virtualized: props.virtualized,
35
+ autoHighlight: props.autoHighlight,
36
+ name: props.name,
37
+ form: props.form,
38
+ items: props.items,
39
+ filter: props.filter,
40
+ onValueChange: (value, details) => props.onValueChange?.(value, details),
41
+ onInputValueChange: (value, details) => props.onInputValueChange?.(value, details),
42
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
43
+ }));
44
+ const named = fromSignal(made.named);
45
+ return (<Context.Provider value={made}>
46
+ {props.children}
47
+ <Show when={named()}>
48
+ <Part of={made.hidden} tag="input"/>
49
+ </Show>
50
+ </Context.Provider>);
51
+ }
52
+ const Portal = (props) => (<BodyPortal mounted={useCombobox().mounted}>{props.children}</BodyPortal>);
53
+ function Positioner(props) {
54
+ const made = useCombobox();
55
+ return <Part of={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
56
+ }
57
+ /** `label` is what is filtered and what the input shows; the item's text when left out. */
58
+ function Item(props) {
59
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "id", "index"]);
60
+ // An item is its value for as long as it is in the page.
61
+ const value = untrack(() => local.value);
62
+ const generated = createUniqueId();
63
+ const options = toSignal(() => ({
64
+ disabled: local.disabled,
65
+ label: local.label,
66
+ index: local.index,
67
+ id: local.id ?? generated,
68
+ }));
69
+ const part = useCombobox().item(value, () => options.get(), useContext(GroupContext));
70
+ return (<ItemContext.Provider value={value}>
71
+ <Part of={part} tag="div" {...rest}/>
72
+ </ItemContext.Provider>);
73
+ }
74
+ function ItemIndicator(props) {
75
+ const [local, rest] = splitProps(props, ["keepMounted"]);
76
+ const made = useCombobox();
77
+ const value = useContext(ItemContext);
78
+ const selected = fromSignal(made.selected(value));
79
+ return (<Show when={selected() || local.keepMounted}>
80
+ <Part of={made.itemIndicator(value)} tag="span" {...rest}/>
81
+ </Show>);
82
+ }
83
+ /** A button that empties the input and the value. Drawn while there is something to clear. */
84
+ function Clear(props) {
85
+ const [local, rest] = splitProps(props, ["keepMounted"]);
86
+ const made = useCombobox();
87
+ const clearable = fromSignal(made.clearable);
88
+ return (<Show when={clearable() || local.keepMounted}>
89
+ <Part of={made.clear} tag="button" {...rest}/>
90
+ </Show>);
91
+ }
92
+ const ChipContext = createContext();
93
+ /** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
94
+ function Chip(props) {
95
+ const [local, rest] = splitProps(props, ["value"]);
96
+ // A chip is its value for as long as it is in the page.
97
+ const value = untrack(() => local.value);
98
+ return (<ChipContext.Provider value={value}>
99
+ <Part of={useCombobox().chip(value)} tag="span" {...rest}/>
100
+ </ChipContext.Provider>);
101
+ }
102
+ const ChipRemove = (props) => (<Part of={useCombobox().chipRemove(useContext(ChipContext))} tag="button" {...props}/>);
103
+ /** Drawn while no item is shown for what was typed. */
104
+ function Empty(props) {
105
+ const made = useCombobox();
106
+ const empty = fromSignal(made.empty);
107
+ return (<Show when={empty()}>
108
+ <Part of={made.emptyPart} tag="div" {...props}/>
109
+ </Show>);
110
+ }
111
+ const GroupContext = createContext();
112
+ /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
113
+ function Group(props) {
114
+ const [local, rest] = splitProps(props, ["id"]);
115
+ const generated = createUniqueId();
116
+ const group = useCombobox().group(untrack(() => local.id) ?? generated);
117
+ return (<GroupContext.Provider value={group}>
118
+ <Part of={group.root} tag="div" {...rest}/>
119
+ </GroupContext.Provider>);
120
+ }
121
+ /** Names the group it is in. With no group around it, it is plain text. */
122
+ const GroupLabel = (props) => (<Part of={useContext(GroupContext)?.label ?? useCombobox().groupLabel} tag="div" {...props}/>);
123
+ const part = (name, tag) => (props) => <Part of={useCombobox()[name]} tag={tag} {...props}/>;
124
+ /** A combobox whose text is the value: the list only suggests. */
125
+ function AutocompleteRoot(props) {
126
+ const generated = createUniqueId();
127
+ const field = useContext(FieldContext);
128
+ const made = controller(within(createAutocomplete, { field }), () => ({
129
+ id: props.id ?? generated,
130
+ value: props.value,
131
+ defaultValue: props.defaultValue,
132
+ open: props.open,
133
+ defaultOpen: props.defaultOpen,
134
+ mode: props.mode,
135
+ filter: props.filter,
136
+ openOnInputClick: props.openOnInputClick,
137
+ disabled: props.disabled,
138
+ required: props.required,
139
+ name: props.name,
140
+ form: props.form,
141
+ virtualized: props.virtualized,
142
+ autoHighlight: props.autoHighlight,
143
+ onValueChange: (value, details) => props.onValueChange?.(value, details),
144
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
145
+ }));
146
+ return <Context.Provider value={made}>{props.children}</Context.Provider>;
147
+ }
148
+ export const Combobox = {
149
+ Root,
150
+ Input: part("input", "input"),
151
+ Trigger: part("trigger", "button"),
152
+ Clear,
153
+ /** With `multiple`: what holds the chips and the input. */
154
+ Chips: part("chips", "div"),
155
+ Chip,
156
+ ChipRemove,
157
+ Portal,
158
+ Positioner,
159
+ Popup: part("popup", "div"),
160
+ /**
161
+ * The items' own box inside the popup, when the popup holds more than items (an input): it
162
+ * is then the listbox.
163
+ */
164
+ List: part("list", "div"),
165
+ Group,
166
+ GroupLabel,
167
+ /** A line between groups. */
168
+ Separator: part("separator", "div"),
169
+ Item,
170
+ ItemIndicator,
171
+ Empty,
172
+ };
173
+ export const Autocomplete = {
174
+ Root: AutocompleteRoot,
175
+ Input: Combobox.Input,
176
+ Trigger: Combobox.Trigger,
177
+ Clear: Combobox.Clear,
178
+ Portal: Combobox.Portal,
179
+ Positioner: Combobox.Positioner,
180
+ Popup: Combobox.Popup,
181
+ List: Combobox.List,
182
+ Group: Combobox.Group,
183
+ GroupLabel: Combobox.GroupLabel,
184
+ Separator: Combobox.Separator,
185
+ Item: Combobox.Item,
186
+ Empty: Combobox.Empty,
187
+ };
@@ -0,0 +1,81 @@
1
+ import { createCommand } from "@kirana-ui/core/command";
2
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
3
+ import { Part, controller, fromSignal, toSignal } from "./runtime.jsx";
4
+ const Context = createContext();
5
+ const GroupContext = createContext();
6
+ function useCommand() {
7
+ const made = useContext(Context);
8
+ if (!made)
9
+ throw new Error("A Command part must be inside <Command.Root>");
10
+ return made;
11
+ }
12
+ function Root(props) {
13
+ const [local, rest] = splitProps(props, [
14
+ "inputValue",
15
+ "defaultInputValue",
16
+ "onInputValueChange",
17
+ "onSelect",
18
+ "filter",
19
+ "loop",
20
+ "disabled",
21
+ "id",
22
+ ]);
23
+ const generated = createUniqueId();
24
+ const made = controller(createCommand, () => ({
25
+ id: local.id ?? generated,
26
+ inputValue: local.inputValue,
27
+ defaultInputValue: local.defaultInputValue,
28
+ filter: local.filter,
29
+ loop: local.loop,
30
+ disabled: local.disabled,
31
+ onInputValueChange: (value, details) => local.onInputValueChange?.(value, details),
32
+ onSelect: (value, details) => local.onSelect?.(value, details),
33
+ }));
34
+ return (<Context.Provider value={made}>
35
+ <Part of={made.root} tag="div" {...rest}/>
36
+ </Context.Provider>);
37
+ }
38
+ const Input = (props) => <Part of={useCommand().input} tag="input" {...props}/>;
39
+ const List = (props) => <Part of={useCommand().list} tag="div" {...props}/>;
40
+ /** Drawn while no item is shown for what was typed. */
41
+ function Empty(props) {
42
+ const made = useCommand();
43
+ const empty = fromSignal(made.empty);
44
+ return (<Show when={empty()}>
45
+ <Part of={made.emptyPart} tag="div" {...props}/>
46
+ </Show>);
47
+ }
48
+ /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
49
+ function Group(props) {
50
+ const [local, rest] = splitProps(props, ["id"]);
51
+ const generated = createUniqueId();
52
+ const group = useCommand().group(untrack(() => local.id) ?? generated);
53
+ return (<GroupContext.Provider value={group}>
54
+ <Part of={group.part} tag="div" {...rest}/>
55
+ </GroupContext.Provider>);
56
+ }
57
+ function GroupHeading(props) {
58
+ const part = useContext(GroupContext)?.heading ?? useCommand().heading;
59
+ return <Part of={part} tag="div" {...props}/>;
60
+ }
61
+ /** `label` is what is filtered, the item's text when left out; `keywords` are other words for it. */
62
+ function Item(props) {
63
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "keywords", "id"]);
64
+ const generated = createUniqueId();
65
+ const options = toSignal(() => ({
66
+ disabled: local.disabled,
67
+ label: local.label,
68
+ keywords: local.keywords,
69
+ id: local.id ?? generated,
70
+ }));
71
+ const part = useCommand().item(untrack(() => local.value), () => options.get(), useContext(GroupContext));
72
+ return <Part of={part} tag="div" {...rest}/>;
73
+ }
74
+ /** A line between groups: gone while something is typed, unless `alwaysRender`. */
75
+ function Separator(props) {
76
+ const [local, rest] = splitProps(props, ["alwaysRender"]);
77
+ const options = toSignal(() => ({ alwaysRender: local.alwaysRender }));
78
+ const part = useCommand().separator(() => options.get().alwaysRender);
79
+ return <Part of={part} tag="div" {...rest}/>;
80
+ }
81
+ export const Command = { Root, Input, List, Empty, Group, GroupHeading, Item, Separator };
@@ -0,0 +1,2 @@
1
+ // A context menu's parts are a menu's, but for its root and its trigger: an area, not a button.
2
+ export { ContextMenu } from "./menu.jsx";
@@ -0,0 +1,71 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createDateField } from "@kirana-ui/core/date-field";
3
+ import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
4
+ import { DirectionContext } from "./direction-context.js";
5
+ import { Part, controller, fromSignal } from "./runtime.jsx";
6
+ /**
7
+ * The date field its parts are inside. Exported for a component that is made of one (a date picker
8
+ * provides its own to the date field's parts).
9
+ */
10
+ const Context = createContext();
11
+ /** For a component made of this one's parts: a date picker. */
12
+ export { Context as DateFieldContext };
13
+ function useDateField() {
14
+ const made = useContext(Context);
15
+ if (!made)
16
+ throw new Error("A DateField part must be inside <DateField.Root>");
17
+ return made;
18
+ }
19
+ function Root(props) {
20
+ const [local, rest] = splitProps(props, [
21
+ "value",
22
+ "defaultValue",
23
+ "onValueChange",
24
+ "locale",
25
+ "min",
26
+ "max",
27
+ "placeholders",
28
+ "disabled",
29
+ "readOnly",
30
+ "required",
31
+ "name",
32
+ "form",
33
+ "id",
34
+ ]);
35
+ const generated = createUniqueId();
36
+ const direction = useContext(DirectionContext);
37
+ const made = controller(within(createDateField, { direction }), () => ({
38
+ id: local.id ?? generated,
39
+ value: local.value,
40
+ defaultValue: local.defaultValue,
41
+ locale: local.locale,
42
+ min: local.min,
43
+ max: local.max,
44
+ placeholders: local.placeholders,
45
+ disabled: local.disabled,
46
+ readOnly: local.readOnly,
47
+ required: local.required,
48
+ name: local.name,
49
+ form: local.form,
50
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
51
+ }));
52
+ return (<Context.Provider value={made}>
53
+ <Part of={made.root} tag="div" {...rest}/>
54
+ </Context.Provider>);
55
+ }
56
+ /** Draws its child once for each piece of the date, in the locale's order. */
57
+ function Segments(props) {
58
+ const segments = fromSignal(useDateField().segments);
59
+ return <For each={segments()}>{(segment) => props.children(segment)}</For>;
60
+ }
61
+ /** One piece: a part that is typed, or what stands between two. It writes its own text. */
62
+ function Segment(props) {
63
+ const [local, rest] = splitProps(props, ["segment"]);
64
+ const made = useDateField().segment(local.segment);
65
+ const shown = fromSignal(made.text);
66
+ return (<Part of={made.part} tag="span" {...rest}>
67
+ {shown()}
68
+ </Part>);
69
+ }
70
+ const Input = (props) => <Part of={useDateField().input} tag="input" {...props}/>;
71
+ export const DateField = { Root, Segments, Segment, Input };
@@ -0,0 +1,72 @@
1
+ import { within } from "@kirana-ui/core";
2
+ import { createDatePicker } from "@kirana-ui/core/date-picker";
3
+ import { createContext, createUniqueId, useContext } from "solid-js";
4
+ import { Calendar, CalendarContext } from "./calendar.jsx";
5
+ import { DateField, DateFieldContext } from "./date-field.jsx";
6
+ import { DirectionContext } from "./direction-context.js";
7
+ import { Popover, PopoverContext } from "./popover.jsx";
8
+ import { Part, controller } from "./runtime.jsx";
9
+ const Context = createContext();
10
+ function useDatePicker() {
11
+ const made = useContext(Context);
12
+ if (!made)
13
+ throw new Error("A DatePicker part must be inside <DatePicker.Root>");
14
+ return made;
15
+ }
16
+ /** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
17
+ function Root(props) {
18
+ const generated = createUniqueId();
19
+ const made = controller(within(createDatePicker, { direction: useContext(DirectionContext) }), () => ({
20
+ id: props.id ?? generated,
21
+ value: props.value,
22
+ defaultValue: props.defaultValue,
23
+ open: props.open,
24
+ defaultOpen: props.defaultOpen,
25
+ locale: props.locale,
26
+ min: props.min,
27
+ max: props.max,
28
+ isDateUnavailable: props.isDateUnavailable,
29
+ calendarSystem: props.calendarSystem,
30
+ fixedWeeks: props.fixedWeeks,
31
+ placeholders: props.placeholders,
32
+ disabled: props.disabled,
33
+ readOnly: props.readOnly,
34
+ required: props.required,
35
+ name: props.name,
36
+ form: props.form,
37
+ onValueChange: (value, details) => props.onValueChange?.(value, details),
38
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
39
+ }));
40
+ return (<Context.Provider value={made}>
41
+ <DateFieldContext.Provider value={made.field}>
42
+ <PopoverContext.Provider value={made.popover}>
43
+ <CalendarContext.Provider value={made.calendar}>
44
+ {props.children}
45
+ </CalendarContext.Provider>
46
+ </PopoverContext.Provider>
47
+ </DateFieldContext.Provider>
48
+ </Context.Provider>);
49
+ }
50
+ export const DatePicker = {
51
+ Root,
52
+ /** The typed date: what holds its segments and its hidden input. */
53
+ Field: (props) => <Part of={useDatePicker().field.root} tag="div" {...props}/>,
54
+ Segments: DateField.Segments,
55
+ Segment: DateField.Segment,
56
+ Input: DateField.Input,
57
+ Trigger: Popover.Trigger,
58
+ Portal: Popover.Portal,
59
+ Positioner: Popover.Positioner,
60
+ Popup: Popover.Popup,
61
+ /** The calendar: what holds its heading, its buttons and its grid. */
62
+ Calendar: (props) => (<Part of={useDatePicker().calendar.root} tag="div" {...props}/>),
63
+ Heading: Calendar.Heading,
64
+ Previous: Calendar.Previous,
65
+ Next: Calendar.Next,
66
+ Grid: Calendar.Grid,
67
+ Weekdays: Calendar.Weekdays,
68
+ HeadCell: Calendar.HeadCell,
69
+ Weeks: Calendar.Weeks,
70
+ Cell: Calendar.Cell,
71
+ Day: Calendar.Day,
72
+ };
package/src/dialog.jsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
2
2
  import { createDialog } from "@kirana-ui/core/dialog";
3
+ import { createDrawer } from "@kirana-ui/core/drawer";
3
4
  import { createContext, createUniqueId, useContext } from "solid-js";
4
5
  import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
5
6
  const Context = createContext();
@@ -22,7 +23,7 @@ function Root(props) {
22
23
  return <Context.Provider value={made}>{props.children}</Context.Provider>;
23
24
  }
24
25
  const Portal = (props) => (<BodyPortal mounted={useDialog().mounted}>{props.children}</BodyPortal>);
25
- const part = (name, tag) => (props) => <Part part={useDialog()[name]} tag={tag} {...props}/>;
26
+ const part = (name, tag) => (props) => <Part of={useDialog()[name]} tag={tag} {...props}/>;
26
27
  function AlertRoot(props) {
27
28
  const generated = createUniqueId();
28
29
  const made = controller(createAlertDialog, () => ({
@@ -45,3 +46,28 @@ export const Dialog = {
45
46
  };
46
47
  /** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
47
48
  export const AlertDialog = { ...Dialog, Root: AlertRoot };
49
+ function DrawerRoot(props) {
50
+ const generated = createUniqueId();
51
+ const made = controller(createDrawer, () => ({
52
+ id: props.id ?? generated,
53
+ open: props.open,
54
+ defaultOpen: props.defaultOpen,
55
+ modal: props.modal,
56
+ dismissible: props.dismissible,
57
+ swipeDirection: props.swipeDirection,
58
+ snapPoints: props.snapPoints,
59
+ snapPoint: props.snapPoint,
60
+ defaultSnapPoint: props.defaultSnapPoint,
61
+ onSnapPointChange: (snapPoint, details) => props.onSnapPointChange?.(snapPoint, details),
62
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details),
63
+ }));
64
+ return <Context.Provider value={made}>{props.children}</Context.Provider>;
65
+ }
66
+ /** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */
67
+ export const Drawer = {
68
+ ...Dialog,
69
+ Root: DrawerRoot,
70
+ // The same components: only what `render` reads of their state is a drawer's.
71
+ Backdrop: Dialog.Backdrop,
72
+ Popup: Dialog.Popup,
73
+ };
package/src/drawer.js ADDED
@@ -0,0 +1,2 @@
1
+ // A drawer is a dialog that is dragged: its parts are a dialog's.
2
+ export { Drawer } from "./dialog.jsx";