@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
@@ -0,0 +1,140 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { within } from "@kirana-ui/core";
4
+ import { createCalendar } from "@kirana-ui/core/calendar";
5
+ import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
6
+ import { DirectionContext } from "./direction-context.js";
7
+ import { Part, controller, fromSignal } from "./runtime.js";
8
+ const Context = createContext();
9
+ /** For a component made of this one's parts: a date picker. */
10
+ export { Context as CalendarContext };
11
+ function useCalendar() {
12
+ const made = useContext(Context);
13
+ if (!made) throw new Error("A Calendar part must be inside <Calendar.Root>");
14
+ return made;
15
+ }
16
+ function Root(props) {
17
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "mode", "defaultFocusedValue", "onMonthChange", "locale", "calendarSystem", "min", "max", "isDateUnavailable", "disabled", "readOnly", "fixedWeeks", "id"]);
18
+ const generated = createUniqueId();
19
+ const direction = useContext(DirectionContext);
20
+ const made = controller(within(createCalendar, {
21
+ direction
22
+ }), () => ({
23
+ id: local.id ?? generated,
24
+ value: local.value,
25
+ defaultValue: local.defaultValue,
26
+ mode: local.mode,
27
+ defaultFocusedValue: local.defaultFocusedValue,
28
+ locale: local.locale,
29
+ calendarSystem: local.calendarSystem,
30
+ min: local.min,
31
+ max: local.max,
32
+ isDateUnavailable: local.isDateUnavailable,
33
+ disabled: local.disabled,
34
+ readOnly: local.readOnly,
35
+ fixedWeeks: local.fixedWeeks,
36
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
37
+ onMonthChange: month => local.onMonthChange?.(month)
38
+ }));
39
+ return _$createComponent(Context.Provider, {
40
+ value: made,
41
+ get children() {
42
+ return _$createComponent(Part, _$mergeProps({
43
+ get part() {
44
+ return made.root;
45
+ },
46
+ tag: "div"
47
+ }, rest));
48
+ }
49
+ });
50
+ }
51
+ /** Names the month shown, unless it is given something else to say. */
52
+ function Heading(props) {
53
+ const made = useCalendar();
54
+ const title = fromSignal(made.title);
55
+ return _$createComponent(Part, _$mergeProps({
56
+ get part() {
57
+ return made.heading;
58
+ },
59
+ tag: "div"
60
+ }, props, {
61
+ get children() {
62
+ return props.children ?? title();
63
+ }
64
+ }));
65
+ }
66
+ const Previous = props => _$createComponent(Part, _$mergeProps({
67
+ get part() {
68
+ return useCalendar().previous;
69
+ },
70
+ tag: "button"
71
+ }, props));
72
+ const Next = props => _$createComponent(Part, _$mergeProps({
73
+ get part() {
74
+ return useCalendar().next;
75
+ },
76
+ tag: "button"
77
+ }, props));
78
+ const Grid = props => _$createComponent(Part, _$mergeProps({
79
+ get part() {
80
+ return useCalendar().grid;
81
+ },
82
+ tag: "table"
83
+ }, props));
84
+ /** Draws its child once for each day of the week, in the locale's order. */
85
+ function Weekdays(props) {
86
+ const weekdays = fromSignal(useCalendar().weekdays);
87
+ return _$createComponent(For, {
88
+ get each() {
89
+ return weekdays();
90
+ },
91
+ children: weekday => props.children(weekday)
92
+ });
93
+ }
94
+ /** Draws its child once for each week of the month shown. */
95
+ function Weeks(props) {
96
+ const weeks = fromSignal(useCalendar().weeks);
97
+ return _$createComponent(For, {
98
+ get each() {
99
+ return weeks();
100
+ },
101
+ children: week => props.children(week)
102
+ });
103
+ }
104
+ function HeadCell(props) {
105
+ const [local, rest] = splitProps(props, ["weekday"]);
106
+ const part = useCalendar().headCell(local.weekday);
107
+ return _$createComponent(Part, _$mergeProps({
108
+ part: part,
109
+ tag: "th"
110
+ }, rest));
111
+ }
112
+ function Cell(props) {
113
+ const [local, rest] = splitProps(props, ["date"]);
114
+ // A cell is its day for as long as it is in the page.
115
+ const part = useCalendar().cell(local.date);
116
+ return _$createComponent(Part, _$mergeProps({
117
+ part: part,
118
+ tag: "td"
119
+ }, rest));
120
+ }
121
+ function Day(props) {
122
+ const [local, rest] = splitProps(props, ["date"]);
123
+ const part = useCalendar().day(local.date);
124
+ return _$createComponent(Part, _$mergeProps({
125
+ part: part,
126
+ tag: "button"
127
+ }, rest));
128
+ }
129
+ export const Calendar = {
130
+ Root,
131
+ Heading,
132
+ Previous,
133
+ Next,
134
+ Grid,
135
+ Weekdays,
136
+ HeadCell,
137
+ Weeks,
138
+ Cell,
139
+ Day
140
+ };
@@ -0,0 +1,83 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { within } from "@kirana-ui/core";
4
+ import { createCarousel } from "@kirana-ui/core/carousel";
5
+ import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
6
+ import { DirectionContext } from "./direction-context.js";
7
+ import { Part, controller } from "./runtime.js";
8
+ const Context = createContext();
9
+ function useCarousel() {
10
+ const made = useContext(Context);
11
+ if (!made) throw new Error("A Carousel part must be inside <Carousel.Root>");
12
+ return made;
13
+ }
14
+ function Root(props) {
15
+ const [local, rest] = splitProps(props, ["index", "defaultIndex", "onIndexChange", "orientation", "loop", "id"]);
16
+ const generated = createUniqueId();
17
+ const direction = useContext(DirectionContext);
18
+ const made = controller(within(createCarousel, {
19
+ direction
20
+ }), () => ({
21
+ id: local.id ?? generated,
22
+ index: local.index,
23
+ defaultIndex: local.defaultIndex,
24
+ orientation: local.orientation,
25
+ loop: local.loop,
26
+ onIndexChange: (index, details) => local.onIndexChange?.(index, details)
27
+ }));
28
+ return _$createComponent(Context.Provider, {
29
+ value: made,
30
+ get children() {
31
+ return _$createComponent(Part, _$mergeProps({
32
+ get part() {
33
+ return made.root;
34
+ },
35
+ tag: "div"
36
+ }, rest));
37
+ }
38
+ });
39
+ }
40
+ const Viewport = props => _$createComponent(Part, _$mergeProps({
41
+ get part() {
42
+ return useCarousel().viewport;
43
+ },
44
+ tag: "div"
45
+ }, props));
46
+ function Item(props) {
47
+ const [local, rest] = splitProps(props, ["index"]);
48
+ // A slide is its place for as long as it is in the page.
49
+ const part = useCarousel().item(local.index);
50
+ return _$createComponent(Part, _$mergeProps({
51
+ part: part,
52
+ tag: "div"
53
+ }, rest));
54
+ }
55
+ const Previous = props => _$createComponent(Part, _$mergeProps({
56
+ get part() {
57
+ return useCarousel().previous;
58
+ },
59
+ tag: "button"
60
+ }, props));
61
+ const Next = props => _$createComponent(Part, _$mergeProps({
62
+ get part() {
63
+ return useCarousel().next;
64
+ },
65
+ tag: "button"
66
+ }, props));
67
+ function Indicator(props) {
68
+ const [local, rest] = splitProps(props, ["index"]);
69
+ // A button is its slide for as long as it is in the page.
70
+ const part = useCarousel().indicator(local.index);
71
+ return _$createComponent(Part, _$mergeProps({
72
+ part: part,
73
+ tag: "button"
74
+ }, rest));
75
+ }
76
+ export const Carousel = {
77
+ Root,
78
+ Viewport,
79
+ Item,
80
+ Previous,
81
+ Next,
82
+ Indicator
83
+ };
@@ -0,0 +1,77 @@
1
+ import { memo as _$memo } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createComponent as _$createComponent } from "solid-js/web";
4
+ import { within } from "@kirana-ui/core";
5
+ import { createCheckbox } from "@kirana-ui/core/checkbox";
6
+ import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
7
+ import { FieldContext } from "./field-context.js";
8
+ import { Part, controller, fromSignal } from "./runtime.js";
9
+ const Context = createContext();
10
+ function useCheckbox() {
11
+ const made = useContext(Context);
12
+ if (!made) throw new Error("A Checkbox part must be inside <Checkbox.Root>");
13
+ return made;
14
+ }
15
+ function Root(props) {
16
+ const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "indeterminate", "disabled", "readOnly", "required", "name", "form", "value", "id", "children"]);
17
+ const generated = createUniqueId();
18
+ const field = useContext(FieldContext);
19
+ const made = controller(within(createCheckbox, {
20
+ field
21
+ }), () => ({
22
+ id: local.id ?? generated,
23
+ checked: local.checked,
24
+ defaultChecked: local.defaultChecked,
25
+ indeterminate: local.indeterminate,
26
+ disabled: local.disabled,
27
+ readOnly: local.readOnly,
28
+ required: local.required,
29
+ name: local.name,
30
+ form: local.form,
31
+ value: local.value,
32
+ onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
33
+ }));
34
+ return _$createComponent(Context.Provider, {
35
+ value: made,
36
+ get children() {
37
+ return _$createComponent(Part, _$mergeProps({
38
+ get part() {
39
+ return made.root;
40
+ },
41
+ tag: "span"
42
+ }, rest, {
43
+ get children() {
44
+ return [local.children, _$createComponent(Part, {
45
+ get part() {
46
+ return made.input;
47
+ },
48
+ tag: "input"
49
+ })];
50
+ }
51
+ }));
52
+ }
53
+ });
54
+ }
55
+ /** `keepMounted` keeps the mark in the page while the box is unchecked. */
56
+ function Indicator(props) {
57
+ const [local, rest] = splitProps(props, ["keepMounted"]);
58
+ const made = useCheckbox();
59
+ const mounted = fromSignal(made.indicatorMounted);
60
+ return _$createComponent(Show, {
61
+ get when() {
62
+ return mounted() || local.keepMounted;
63
+ },
64
+ get children() {
65
+ return _$createComponent(Part, _$mergeProps({
66
+ get part() {
67
+ return made.indicator;
68
+ },
69
+ tag: "span"
70
+ }, rest));
71
+ }
72
+ });
73
+ }
74
+ export const Checkbox = {
75
+ Root,
76
+ Indicator
77
+ };
@@ -0,0 +1,64 @@
1
+ import { memo as _$memo } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { mergeProps as _$mergeProps } from "solid-js/web";
4
+ import { createCollapsible } from "@kirana-ui/core/collapsible";
5
+ import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
6
+ import { Part, controller, fromSignal } from "./runtime.js";
7
+ const Context = createContext();
8
+ function useCollapsible() {
9
+ const made = useContext(Context);
10
+ if (!made) throw new Error("A Collapsible part must be inside <Collapsible.Root>");
11
+ return made;
12
+ }
13
+ function Root(props) {
14
+ const [local, rest] = splitProps(props, ["open", "defaultOpen", "onOpenChange", "disabled", "id"]);
15
+ const generated = createUniqueId();
16
+ const made = controller(createCollapsible, () => ({
17
+ id: local.id ?? generated,
18
+ open: local.open,
19
+ defaultOpen: local.defaultOpen,
20
+ disabled: local.disabled,
21
+ onOpenChange: (open, details) => local.onOpenChange?.(open, details)
22
+ }));
23
+ return _$createComponent(Context.Provider, {
24
+ value: made,
25
+ get children() {
26
+ return _$createComponent(Part, _$mergeProps({
27
+ get part() {
28
+ return made.root;
29
+ },
30
+ tag: "div"
31
+ }, rest));
32
+ }
33
+ });
34
+ }
35
+ const Trigger = props => _$createComponent(Part, _$mergeProps({
36
+ get part() {
37
+ return useCollapsible().trigger;
38
+ },
39
+ tag: "button"
40
+ }, props));
41
+ /** `keepMounted` keeps the closed panel in the page, `hidden`. */
42
+ function Panel(props) {
43
+ const [local, rest] = splitProps(props, ["keepMounted"]);
44
+ const made = useCollapsible();
45
+ const mounted = fromSignal(made.mounted);
46
+ return _$createComponent(Show, {
47
+ get when() {
48
+ return mounted() || local.keepMounted;
49
+ },
50
+ get children() {
51
+ return _$createComponent(Part, _$mergeProps({
52
+ get part() {
53
+ return made.panel;
54
+ },
55
+ tag: "div"
56
+ }, rest));
57
+ }
58
+ });
59
+ }
60
+ export const Collapsible = {
61
+ Root,
62
+ Trigger,
63
+ Panel
64
+ };
@@ -0,0 +1,281 @@
1
+ import { memo as _$memo } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createComponent as _$createComponent } from "solid-js/web";
4
+ import { within } from "@kirana-ui/core";
5
+ import { createAutocomplete } from "@kirana-ui/core/autocomplete";
6
+ import { createCombobox } from "@kirana-ui/core/combobox";
7
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
8
+ import { FieldContext } from "./field-context.js";
9
+ import { positioned } from "./popover.js";
10
+ import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.js";
11
+ const Context = createContext();
12
+ const ItemContext = createContext();
13
+ function useCombobox() {
14
+ const made = useContext(Context);
15
+ if (!made) throw new Error("A Combobox part must be inside <Combobox.Root>");
16
+ return made;
17
+ }
18
+ function Root(props) {
19
+ const generated = createUniqueId();
20
+ const field = useContext(FieldContext);
21
+ const made = controller(within(createCombobox, {
22
+ field
23
+ }), () => ({
24
+ id: props.id ?? generated,
25
+ value: props.value,
26
+ defaultValue: props.defaultValue,
27
+ inputValue: props.inputValue,
28
+ defaultInputValue: props.defaultInputValue,
29
+ open: props.open,
30
+ defaultOpen: props.defaultOpen,
31
+ disabled: props.disabled,
32
+ required: props.required,
33
+ multiple: props.multiple,
34
+ values: props.values,
35
+ defaultValues: props.defaultValues,
36
+ onValuesChange: (values, details) => props.onValuesChange?.(values, details),
37
+ inline: props.inline,
38
+ virtualized: props.virtualized,
39
+ name: props.name,
40
+ form: props.form,
41
+ items: props.items,
42
+ filter: props.filter,
43
+ onValueChange: (value, details) => props.onValueChange?.(value, details),
44
+ onInputValueChange: (value, details) => props.onInputValueChange?.(value, details),
45
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details)
46
+ }));
47
+ const named = fromSignal(made.named);
48
+ return _$createComponent(Context.Provider, {
49
+ value: made,
50
+ get children() {
51
+ return [props.children, _$createComponent(Show, {
52
+ get when() {
53
+ return named();
54
+ },
55
+ get children() {
56
+ return _$createComponent(Part, {
57
+ get part() {
58
+ return made.hidden;
59
+ },
60
+ tag: "input"
61
+ });
62
+ }
63
+ })];
64
+ }
65
+ });
66
+ }
67
+ const Portal = props => _$createComponent(BodyPortal, {
68
+ get mounted() {
69
+ return useCombobox().mounted;
70
+ },
71
+ get children() {
72
+ return props.children;
73
+ }
74
+ });
75
+ function Positioner(props) {
76
+ const made = useCombobox();
77
+ return _$createComponent(Part, _$mergeProps({
78
+ get part() {
79
+ return made.positioner;
80
+ },
81
+ tag: "div"
82
+ }, () => positioned(props, made.positioning)));
83
+ }
84
+ /** `label` is what is filtered and what the input shows; the item's text when left out. */
85
+ function Item(props) {
86
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "id", "index"]);
87
+ // An item is its value for as long as it is in the page.
88
+ const value = untrack(() => local.value);
89
+ const generated = createUniqueId();
90
+ const options = toSignal(() => ({
91
+ disabled: local.disabled,
92
+ label: local.label,
93
+ index: local.index,
94
+ id: local.id ?? generated
95
+ }));
96
+ const part = useCombobox().item(value, () => options.get(), useContext(GroupContext));
97
+ return _$createComponent(ItemContext.Provider, {
98
+ value: value,
99
+ get children() {
100
+ return _$createComponent(Part, _$mergeProps({
101
+ part: part,
102
+ tag: "div"
103
+ }, rest));
104
+ }
105
+ });
106
+ }
107
+ function ItemIndicator(props) {
108
+ const [local, rest] = splitProps(props, ["keepMounted"]);
109
+ const made = useCombobox();
110
+ const value = useContext(ItemContext);
111
+ const selected = fromSignal(made.selected(value));
112
+ return _$createComponent(Show, {
113
+ get when() {
114
+ return selected() || local.keepMounted;
115
+ },
116
+ get children() {
117
+ return _$createComponent(Part, _$mergeProps({
118
+ get part() {
119
+ return made.itemIndicator(value);
120
+ },
121
+ tag: "span"
122
+ }, rest));
123
+ }
124
+ });
125
+ }
126
+ /** A button that empties the input and the value. Drawn while there is something to clear. */
127
+ function Clear(props) {
128
+ const [local, rest] = splitProps(props, ["keepMounted"]);
129
+ const made = useCombobox();
130
+ const clearable = fromSignal(made.clearable);
131
+ return _$createComponent(Show, {
132
+ get when() {
133
+ return clearable() || local.keepMounted;
134
+ },
135
+ get children() {
136
+ return _$createComponent(Part, _$mergeProps({
137
+ get part() {
138
+ return made.clear;
139
+ },
140
+ tag: "button"
141
+ }, rest));
142
+ }
143
+ });
144
+ }
145
+ const ChipContext = createContext();
146
+ /** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
147
+ function Chip(props) {
148
+ const [local, rest] = splitProps(props, ["value"]);
149
+ // A chip is its value for as long as it is in the page.
150
+ const value = untrack(() => local.value);
151
+ return _$createComponent(ChipContext.Provider, {
152
+ value: value,
153
+ get children() {
154
+ return _$createComponent(Part, _$mergeProps({
155
+ get part() {
156
+ return useCombobox().chip(value);
157
+ },
158
+ tag: "span"
159
+ }, rest));
160
+ }
161
+ });
162
+ }
163
+ const ChipRemove = props => _$createComponent(Part, _$mergeProps({
164
+ get part() {
165
+ return useCombobox().chipRemove(useContext(ChipContext));
166
+ },
167
+ tag: "button"
168
+ }, props));
169
+ /** Drawn while no item is shown for what was typed. */
170
+ function Empty(props) {
171
+ const made = useCombobox();
172
+ const empty = fromSignal(made.empty);
173
+ return _$createComponent(Show, {
174
+ get when() {
175
+ return empty();
176
+ },
177
+ get children() {
178
+ return _$createComponent(Part, _$mergeProps({
179
+ get part() {
180
+ return made.emptyPart;
181
+ },
182
+ tag: "div"
183
+ }, props));
184
+ }
185
+ });
186
+ }
187
+ const GroupContext = createContext();
188
+ /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
189
+ function Group(props) {
190
+ const [local, rest] = splitProps(props, ["id"]);
191
+ const generated = createUniqueId();
192
+ const group = useCombobox().group(untrack(() => local.id) ?? generated);
193
+ return _$createComponent(GroupContext.Provider, {
194
+ value: group,
195
+ get children() {
196
+ return _$createComponent(Part, _$mergeProps({
197
+ get part() {
198
+ return group.root;
199
+ },
200
+ tag: "div"
201
+ }, rest));
202
+ }
203
+ });
204
+ }
205
+ /** Names the group it is in. With no group around it, it is plain text. */
206
+ const GroupLabel = props => _$createComponent(Part, _$mergeProps({
207
+ get part() {
208
+ return useContext(GroupContext)?.label ?? useCombobox().groupLabel;
209
+ },
210
+ tag: "div"
211
+ }, props));
212
+ const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
213
+ get part() {
214
+ return useCombobox()[name];
215
+ },
216
+ tag: tag
217
+ }, props));
218
+ /** A combobox whose text is the value: the list only suggests. */
219
+ function AutocompleteRoot(props) {
220
+ const generated = createUniqueId();
221
+ const field = useContext(FieldContext);
222
+ const made = controller(within(createAutocomplete, {
223
+ field
224
+ }), () => ({
225
+ id: props.id ?? generated,
226
+ value: props.value,
227
+ defaultValue: props.defaultValue,
228
+ open: props.open,
229
+ defaultOpen: props.defaultOpen,
230
+ mode: props.mode,
231
+ filter: props.filter,
232
+ openOnInputClick: props.openOnInputClick,
233
+ disabled: props.disabled,
234
+ required: props.required,
235
+ name: props.name,
236
+ form: props.form,
237
+ virtualized: props.virtualized,
238
+ onValueChange: (value, details) => props.onValueChange?.(value, details),
239
+ onOpenChange: (open, details) => props.onOpenChange?.(open, details)
240
+ }));
241
+ return _$createComponent(Context.Provider, {
242
+ value: made,
243
+ get children() {
244
+ return props.children;
245
+ }
246
+ });
247
+ }
248
+ export const Combobox = {
249
+ Root,
250
+ Input: part("input", "input"),
251
+ Trigger: part("trigger", "button"),
252
+ Clear,
253
+ /** With `multiple`: what holds the chips and the input. */
254
+ Chips: part("chips", "div"),
255
+ Chip,
256
+ ChipRemove,
257
+ Portal,
258
+ Positioner,
259
+ Popup: part("popup", "div"),
260
+ Group,
261
+ GroupLabel,
262
+ /** A line between groups. */
263
+ Separator: part("separator", "div"),
264
+ Item,
265
+ ItemIndicator,
266
+ Empty
267
+ };
268
+ export const Autocomplete = {
269
+ Root: AutocompleteRoot,
270
+ Input: Combobox.Input,
271
+ Trigger: Combobox.Trigger,
272
+ Clear: Combobox.Clear,
273
+ Portal: Combobox.Portal,
274
+ Positioner: Combobox.Positioner,
275
+ Popup: Combobox.Popup,
276
+ Group: Combobox.Group,
277
+ GroupLabel: Combobox.GroupLabel,
278
+ Separator: Combobox.Separator,
279
+ Item: Combobox.Item,
280
+ Empty: Combobox.Empty
281
+ };