@kirana-ui/solid 0.1.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 (159) hide show
  1. package/dom/autocomplete.js +2 -0
  2. package/dom/autosize.js +19 -0
  3. package/dom/calendar.js +141 -0
  4. package/dom/carousel.js +83 -0
  5. package/dom/checkbox.js +2 -1
  6. package/dom/combobox.js +281 -0
  7. package/dom/command.js +129 -0
  8. package/dom/context-menu.js +2 -0
  9. package/dom/date-field.js +86 -0
  10. package/dom/date-picker.js +103 -0
  11. package/dom/dialog.js +28 -0
  12. package/dom/drawer.js +2 -0
  13. package/dom/hover-popup.js +17 -2
  14. package/dom/index.js +26 -1
  15. package/dom/input.js +26 -0
  16. package/dom/label.js +18 -0
  17. package/dom/listbox.js +114 -0
  18. package/dom/menu.js +261 -0
  19. package/dom/menubar-context.js +3 -0
  20. package/dom/menubar.js +33 -0
  21. package/dom/message-scroller.js +56 -0
  22. package/dom/navigation-menu.js +150 -0
  23. package/dom/number-field.js +82 -0
  24. package/dom/otp.js +95 -0
  25. package/dom/pagination.js +74 -0
  26. package/dom/popover.js +2 -0
  27. package/dom/qr-code.js +48 -0
  28. package/dom/radio-group.js +2 -1
  29. package/dom/resizable.js +65 -0
  30. package/dom/runtime.js +36 -2
  31. package/dom/scroll-area.js +99 -0
  32. package/dom/select.js +69 -5
  33. package/dom/slider.js +1 -1
  34. package/dom/switch.js +2 -1
  35. package/dom/toast.js +113 -0
  36. package/dom/toggle-group.js +37 -0
  37. package/dom/toggle.js +11 -3
  38. package/dom/toolbar-context.js +5 -0
  39. package/dom/toolbar.js +71 -0
  40. package/llms.txt +1838 -0
  41. package/package.json +220 -2
  42. package/server/autocomplete.js +2 -0
  43. package/server/autosize.js +19 -0
  44. package/server/calendar.js +140 -0
  45. package/server/carousel.js +83 -0
  46. package/server/checkbox.js +2 -1
  47. package/server/combobox.js +281 -0
  48. package/server/command.js +129 -0
  49. package/server/context-menu.js +2 -0
  50. package/server/date-field.js +86 -0
  51. package/server/date-picker.js +103 -0
  52. package/server/dialog.js +28 -0
  53. package/server/drawer.js +2 -0
  54. package/server/hover-popup.js +17 -2
  55. package/server/index.js +26 -1
  56. package/server/input.js +26 -0
  57. package/server/label.js +18 -0
  58. package/server/listbox.js +114 -0
  59. package/server/menu.js +261 -0
  60. package/server/menubar-context.js +3 -0
  61. package/server/menubar.js +33 -0
  62. package/server/message-scroller.js +56 -0
  63. package/server/navigation-menu.js +144 -0
  64. package/server/number-field.js +81 -0
  65. package/server/otp.js +94 -0
  66. package/server/pagination.js +74 -0
  67. package/server/popover.js +2 -0
  68. package/server/qr-code.js +48 -0
  69. package/server/radio-group.js +2 -1
  70. package/server/resizable.js +65 -0
  71. package/server/runtime.js +35 -1
  72. package/server/scroll-area.js +99 -0
  73. package/server/select.js +69 -5
  74. package/server/slider.js +1 -1
  75. package/server/switch.js +2 -1
  76. package/server/toast.js +113 -0
  77. package/server/toggle-group.js +37 -0
  78. package/server/toggle.js +11 -3
  79. package/server/toolbar-context.js +5 -0
  80. package/server/toolbar.js +71 -0
  81. package/src/autocomplete.jsx +2 -0
  82. package/src/autosize.jsx +8 -0
  83. package/src/calendar.jsx +104 -0
  84. package/src/carousel.jsx +51 -0
  85. package/src/checkbox.jsx +2 -0
  86. package/src/combobox.jsx +179 -0
  87. package/src/command.jsx +81 -0
  88. package/src/context-menu.js +2 -0
  89. package/src/date-field.jsx +67 -0
  90. package/src/date-picker.jsx +72 -0
  91. package/src/dialog.jsx +20 -0
  92. package/src/drawer.js +2 -0
  93. package/src/hover-popup.jsx +10 -2
  94. package/src/index.js +26 -1
  95. package/src/input.jsx +17 -0
  96. package/src/label.jsx +9 -0
  97. package/src/listbox.jsx +81 -0
  98. package/src/menu.jsx +164 -0
  99. package/src/menubar-context.js +3 -0
  100. package/src/menubar.jsx +21 -0
  101. package/src/message-scroller.jsx +27 -0
  102. package/src/navigation-menu.jsx +95 -0
  103. package/src/number-field.jsx +75 -0
  104. package/src/otp.jsx +73 -0
  105. package/src/pagination.jsx +60 -0
  106. package/src/popover.jsx +2 -0
  107. package/src/qr-code.jsx +25 -0
  108. package/src/radio-group.jsx +2 -0
  109. package/src/resizable.jsx +46 -0
  110. package/src/runtime.jsx +33 -2
  111. package/src/scroll-area.jsx +53 -0
  112. package/src/select.jsx +49 -5
  113. package/src/slider.jsx +2 -0
  114. package/src/switch.jsx +2 -0
  115. package/src/toast.jsx +58 -0
  116. package/src/toggle-group.jsx +32 -0
  117. package/src/toggle.jsx +8 -2
  118. package/src/toolbar-context.js +5 -0
  119. package/src/toolbar.jsx +43 -0
  120. package/types/autocomplete.d.ts +1 -0
  121. package/types/autosize.d.ts +8 -0
  122. package/types/calendar.d.ts +40 -0
  123. package/types/carousel.d.ts +26 -0
  124. package/types/checkbox.d.ts +1 -0
  125. package/types/combobox.d.ts +106 -0
  126. package/types/command.d.ts +45 -0
  127. package/types/context-menu.d.ts +1 -0
  128. package/types/date-field.d.ts +23 -0
  129. package/types/date-picker.d.ts +49 -0
  130. package/types/dialog.d.ts +21 -0
  131. package/types/drawer.d.ts +1 -0
  132. package/types/hover-card.d.ts +4 -1
  133. package/types/hover-popup.d.ts +4 -1
  134. package/types/index.d.ts +27 -1
  135. package/types/input.d.ts +12 -0
  136. package/types/label.d.ts +4 -0
  137. package/types/listbox.d.ts +38 -0
  138. package/types/menu.d.ts +91 -0
  139. package/types/menubar-context.d.ts +3 -0
  140. package/types/menubar.d.ts +10 -0
  141. package/types/message-scroller.d.ts +16 -0
  142. package/types/navigation-menu.d.ts +44 -0
  143. package/types/number-field.d.ts +15 -0
  144. package/types/otp.d.ts +32 -0
  145. package/types/pagination.d.ts +23 -0
  146. package/types/popover.d.ts +4 -1
  147. package/types/qr-code.d.ts +14 -0
  148. package/types/radio-group.d.ts +1 -0
  149. package/types/resizable.d.ts +24 -0
  150. package/types/runtime.d.ts +18 -0
  151. package/types/scroll-area.d.ts +20 -0
  152. package/types/select.d.ts +25 -1
  153. package/types/switch.d.ts +1 -0
  154. package/types/toast.d.ts +33 -0
  155. package/types/toggle-group.d.ts +14 -0
  156. package/types/toggle.d.ts +2 -0
  157. package/types/toolbar-context.d.ts +6 -0
  158. package/types/toolbar.d.ts +23 -0
  159. package/types/tooltip.d.ts +4 -1
@@ -0,0 +1,2 @@
1
+ // An autocomplete is a combobox whose text is the value: its parts are a combobox's.
2
+ export { Autocomplete } from "./combobox.js";
@@ -0,0 +1,19 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createAutosize } from "@kirana-ui/core/autosize";
4
+ import { Part, controller } from "./runtime.js";
5
+ /** A `<textarea>` as tall as its text. It takes what a `<textarea>` takes. */
6
+ function Textarea(props) {
7
+ const made = controller(createAutosize, () => ({
8
+ value: props.value
9
+ }));
10
+ return _$createComponent(Part, _$mergeProps({
11
+ get part() {
12
+ return made.textarea;
13
+ },
14
+ tag: "textarea"
15
+ }, props));
16
+ }
17
+ export const Autosize = {
18
+ Textarea
19
+ };
@@ -0,0 +1,141 @@
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 { within } from "@kirana-ui/core";
5
+ import { createCalendar } from "@kirana-ui/core/calendar";
6
+ import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
7
+ import { DirectionContext } from "./direction-context.js";
8
+ import { Part, controller, fromSignal } from "./runtime.js";
9
+ const Context = createContext();
10
+ /** For a component made of this one's parts: a date picker. */
11
+ export { Context as CalendarContext };
12
+ function useCalendar() {
13
+ const made = useContext(Context);
14
+ if (!made) throw new Error("A Calendar part must be inside <Calendar.Root>");
15
+ return made;
16
+ }
17
+ function Root(props) {
18
+ const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "mode", "defaultFocusedValue", "onMonthChange", "locale", "calendarSystem", "min", "max", "isDateUnavailable", "disabled", "readOnly", "fixedWeeks", "id"]);
19
+ const generated = createUniqueId();
20
+ const direction = useContext(DirectionContext);
21
+ const made = controller(within(createCalendar, {
22
+ direction
23
+ }), () => ({
24
+ id: local.id ?? generated,
25
+ value: local.value,
26
+ defaultValue: local.defaultValue,
27
+ mode: local.mode,
28
+ defaultFocusedValue: local.defaultFocusedValue,
29
+ locale: local.locale,
30
+ calendarSystem: local.calendarSystem,
31
+ min: local.min,
32
+ max: local.max,
33
+ isDateUnavailable: local.isDateUnavailable,
34
+ disabled: local.disabled,
35
+ readOnly: local.readOnly,
36
+ fixedWeeks: local.fixedWeeks,
37
+ onValueChange: (value, details) => local.onValueChange?.(value, details),
38
+ onMonthChange: month => local.onMonthChange?.(month)
39
+ }));
40
+ return _$createComponent(Context.Provider, {
41
+ value: made,
42
+ get children() {
43
+ return _$createComponent(Part, _$mergeProps({
44
+ get part() {
45
+ return made.root;
46
+ },
47
+ tag: "div"
48
+ }, rest));
49
+ }
50
+ });
51
+ }
52
+ /** Names the month shown, unless it is given something else to say. */
53
+ function Heading(props) {
54
+ const made = useCalendar();
55
+ const title = fromSignal(made.title);
56
+ return _$createComponent(Part, _$mergeProps({
57
+ get part() {
58
+ return made.heading;
59
+ },
60
+ tag: "div"
61
+ }, props, {
62
+ get children() {
63
+ return props.children ?? title();
64
+ }
65
+ }));
66
+ }
67
+ const Previous = props => _$createComponent(Part, _$mergeProps({
68
+ get part() {
69
+ return useCalendar().previous;
70
+ },
71
+ tag: "button"
72
+ }, props));
73
+ const Next = props => _$createComponent(Part, _$mergeProps({
74
+ get part() {
75
+ return useCalendar().next;
76
+ },
77
+ tag: "button"
78
+ }, props));
79
+ const Grid = props => _$createComponent(Part, _$mergeProps({
80
+ get part() {
81
+ return useCalendar().grid;
82
+ },
83
+ tag: "table"
84
+ }, props));
85
+ /** Draws its child once for each day of the week, in the locale's order. */
86
+ function Weekdays(props) {
87
+ const weekdays = fromSignal(useCalendar().weekdays);
88
+ return _$createComponent(For, {
89
+ get each() {
90
+ return weekdays();
91
+ },
92
+ children: weekday => props.children(weekday)
93
+ });
94
+ }
95
+ /** Draws its child once for each week of the month shown. */
96
+ function Weeks(props) {
97
+ const weeks = fromSignal(useCalendar().weeks);
98
+ return _$createComponent(For, {
99
+ get each() {
100
+ return weeks();
101
+ },
102
+ children: week => props.children(week)
103
+ });
104
+ }
105
+ function HeadCell(props) {
106
+ const [local, rest] = splitProps(props, ["weekday"]);
107
+ const part = useCalendar().headCell(local.weekday);
108
+ return _$createComponent(Part, _$mergeProps({
109
+ part: part,
110
+ tag: "th"
111
+ }, rest));
112
+ }
113
+ function Cell(props) {
114
+ const [local, rest] = splitProps(props, ["date"]);
115
+ // A cell is its day for as long as it is in the page.
116
+ const part = useCalendar().cell(local.date);
117
+ return _$createComponent(Part, _$mergeProps({
118
+ part: part,
119
+ tag: "td"
120
+ }, rest));
121
+ }
122
+ function Day(props) {
123
+ const [local, rest] = splitProps(props, ["date"]);
124
+ const part = useCalendar().day(local.date);
125
+ return _$createComponent(Part, _$mergeProps({
126
+ part: part,
127
+ tag: "button"
128
+ }, rest));
129
+ }
130
+ export const Calendar = {
131
+ Root,
132
+ Heading,
133
+ Previous,
134
+ Next,
135
+ Grid,
136
+ Weekdays,
137
+ HeadCell,
138
+ Weeks,
139
+ Cell,
140
+ Day
141
+ };
@@ -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
+ };
package/dom/checkbox.js CHANGED
@@ -13,7 +13,7 @@ function useCheckbox() {
13
13
  return made;
14
14
  }
15
15
  function Root(props) {
16
- const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "indeterminate", "disabled", "readOnly", "required", "name", "value", "id", "children"]);
16
+ const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "indeterminate", "disabled", "readOnly", "required", "name", "form", "value", "id", "children"]);
17
17
  const generated = createUniqueId();
18
18
  const field = useContext(FieldContext);
19
19
  const made = controller(within(createCheckbox, {
@@ -27,6 +27,7 @@ function Root(props) {
27
27
  readOnly: local.readOnly,
28
28
  required: local.required,
29
29
  name: local.name,
30
+ form: local.form,
30
31
  value: local.value,
31
32
  onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
32
33
  }));
@@ -0,0 +1,281 @@
1
+ import { mergeProps as _$mergeProps } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { memo as _$memo } 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 [_$memo(() => 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
+ };
package/dom/command.js ADDED
@@ -0,0 +1,129 @@
1
+ import { createComponent as _$createComponent } from "solid-js/web";
2
+ import { mergeProps as _$mergeProps } from "solid-js/web";
3
+ import { createCommand } from "@kirana-ui/core/command";
4
+ import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
5
+ import { Part, controller, fromSignal, toSignal } from "./runtime.js";
6
+ const Context = createContext();
7
+ const GroupContext = createContext();
8
+ function useCommand() {
9
+ const made = useContext(Context);
10
+ if (!made) throw new Error("A Command part must be inside <Command.Root>");
11
+ return made;
12
+ }
13
+ function Root(props) {
14
+ const [local, rest] = splitProps(props, ["inputValue", "defaultInputValue", "onInputValueChange", "onSelect", "filter", "loop", "disabled", "id"]);
15
+ const generated = createUniqueId();
16
+ const made = controller(createCommand, () => ({
17
+ id: local.id ?? generated,
18
+ inputValue: local.inputValue,
19
+ defaultInputValue: local.defaultInputValue,
20
+ filter: local.filter,
21
+ loop: local.loop,
22
+ disabled: local.disabled,
23
+ onInputValueChange: (value, details) => local.onInputValueChange?.(value, details),
24
+ onSelect: (value, details) => local.onSelect?.(value, details)
25
+ }));
26
+ return _$createComponent(Context.Provider, {
27
+ value: made,
28
+ get children() {
29
+ return _$createComponent(Part, _$mergeProps({
30
+ get part() {
31
+ return made.root;
32
+ },
33
+ tag: "div"
34
+ }, rest));
35
+ }
36
+ });
37
+ }
38
+ const Input = props => _$createComponent(Part, _$mergeProps({
39
+ get part() {
40
+ return useCommand().input;
41
+ },
42
+ tag: "input"
43
+ }, props));
44
+ const List = props => _$createComponent(Part, _$mergeProps({
45
+ get part() {
46
+ return useCommand().list;
47
+ },
48
+ tag: "div"
49
+ }, props));
50
+ /** Drawn while no item is shown for what was typed. */
51
+ function Empty(props) {
52
+ const made = useCommand();
53
+ const empty = fromSignal(made.empty);
54
+ return _$createComponent(Show, {
55
+ get when() {
56
+ return empty();
57
+ },
58
+ get children() {
59
+ return _$createComponent(Part, _$mergeProps({
60
+ get part() {
61
+ return made.emptyPart;
62
+ },
63
+ tag: "div"
64
+ }, props));
65
+ }
66
+ });
67
+ }
68
+ /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
69
+ function Group(props) {
70
+ const [local, rest] = splitProps(props, ["id"]);
71
+ const generated = createUniqueId();
72
+ const group = useCommand().group(untrack(() => local.id) ?? generated);
73
+ return _$createComponent(GroupContext.Provider, {
74
+ value: group,
75
+ get children() {
76
+ return _$createComponent(Part, _$mergeProps({
77
+ get part() {
78
+ return group.part;
79
+ },
80
+ tag: "div"
81
+ }, rest));
82
+ }
83
+ });
84
+ }
85
+ function GroupHeading(props) {
86
+ const part = useContext(GroupContext)?.heading ?? useCommand().heading;
87
+ return _$createComponent(Part, _$mergeProps({
88
+ part: part,
89
+ tag: "div"
90
+ }, props));
91
+ }
92
+ /** `label` is what is filtered, the item's text when left out; `keywords` are other words for it. */
93
+ function Item(props) {
94
+ const [local, rest] = splitProps(props, ["value", "disabled", "label", "keywords", "id"]);
95
+ const generated = createUniqueId();
96
+ const options = toSignal(() => ({
97
+ disabled: local.disabled,
98
+ label: local.label,
99
+ keywords: local.keywords,
100
+ id: local.id ?? generated
101
+ }));
102
+ const part = useCommand().item(untrack(() => local.value), () => options.get(), useContext(GroupContext));
103
+ return _$createComponent(Part, _$mergeProps({
104
+ part: part,
105
+ tag: "div"
106
+ }, rest));
107
+ }
108
+ /** A line between groups: gone while something is typed, unless `alwaysRender`. */
109
+ function Separator(props) {
110
+ const [local, rest] = splitProps(props, ["alwaysRender"]);
111
+ const options = toSignal(() => ({
112
+ alwaysRender: local.alwaysRender
113
+ }));
114
+ const part = useCommand().separator(() => options.get().alwaysRender);
115
+ return _$createComponent(Part, _$mergeProps({
116
+ part: part,
117
+ tag: "div"
118
+ }, rest));
119
+ }
120
+ export const Command = {
121
+ Root,
122
+ Input,
123
+ List,
124
+ Empty,
125
+ Group,
126
+ GroupHeading,
127
+ Item,
128
+ Separator
129
+ };
@@ -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.js";