@kirana-ui/react 0.1.1 → 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 (161) hide show
  1. package/llms.txt +1601 -223
  2. package/package.json +14 -2
  3. package/skills/kirana-ui-primitives/SKILL.md +142 -0
  4. package/src/accordion.d.ts +26 -15
  5. package/src/accordion.js +11 -10
  6. package/src/accordion.js.map +1 -1
  7. package/src/agent.d.ts +1 -0
  8. package/src/agent.js +1 -0
  9. package/src/alert-dialog.d.ts +3 -2
  10. package/src/autocomplete.d.ts +3 -2
  11. package/src/autosize.d.ts +5 -2
  12. package/src/autosize.js +2 -2
  13. package/src/autosize.js.map +1 -1
  14. package/src/avatar.d.ts +12 -8
  15. package/src/avatar.js +18 -9
  16. package/src/avatar.js.map +1 -1
  17. package/src/button.d.ts +4 -2
  18. package/src/button.js +3 -3
  19. package/src/button.js.map +1 -1
  20. package/src/calendar.d.ts +49 -28
  21. package/src/calendar.js +7 -3
  22. package/src/calendar.js.map +1 -1
  23. package/src/carousel.d.ts +25 -15
  24. package/src/carousel.js +3 -3
  25. package/src/carousel.js.map +1 -1
  26. package/src/checkbox.d.ts +10 -7
  27. package/src/checkbox.js +18 -12
  28. package/src/checkbox.js.map +1 -1
  29. package/src/collapsible.d.ts +12 -8
  30. package/src/collapsible.js +8 -7
  31. package/src/collapsible.js.map +1 -1
  32. package/src/combobox.d.ts +88 -60
  33. package/src/combobox.js +44 -31
  34. package/src/combobox.js.map +1 -1
  35. package/src/command.d.ts +30 -21
  36. package/src/command.js +14 -7
  37. package/src/command.js.map +1 -1
  38. package/src/context-menu.d.ts +3 -2
  39. package/src/date-field.d.ts +25 -13
  40. package/src/date-field.js +7 -3
  41. package/src/date-field.js.map +1 -1
  42. package/src/date-picker.d.ts +31 -40
  43. package/src/date-picker.js +3 -3
  44. package/src/date-picker.js.map +1 -1
  45. package/src/dialog.d.ts +45 -35
  46. package/src/dialog.js +12 -8
  47. package/src/dialog.js.map +1 -1
  48. package/src/direction.d.ts +1 -0
  49. package/src/direction.js.map +1 -1
  50. package/src/drawer.d.ts +3 -2
  51. package/src/element.d.ts +12 -0
  52. package/src/element.js +20 -0
  53. package/src/element.js.map +1 -0
  54. package/src/field.d.ts +24 -16
  55. package/src/field.js +9 -7
  56. package/src/field.js.map +1 -1
  57. package/src/fieldset.d.ts +10 -5
  58. package/src/fieldset.js +4 -5
  59. package/src/fieldset.js.map +1 -1
  60. package/src/form.d.ts +5 -2
  61. package/src/form.js +6 -6
  62. package/src/form.js.map +1 -1
  63. package/src/hover-card.d.ts +16 -10
  64. package/src/hover-card.js +1 -1
  65. package/src/hover-card.js.map +1 -1
  66. package/src/hover-popup.d.ts +24 -14
  67. package/src/hover-popup.js +5 -13
  68. package/src/hover-popup.js.map +1 -1
  69. package/src/index.d.ts +13 -3
  70. package/src/input.d.ts +4 -2
  71. package/src/input.js +3 -3
  72. package/src/input.js.map +1 -1
  73. package/src/label.d.ts +4 -1
  74. package/src/label.js +3 -3
  75. package/src/label.js.map +1 -1
  76. package/src/listbox.d.ts +23 -15
  77. package/src/listbox.js +4 -5
  78. package/src/listbox.js.map +1 -1
  79. package/src/menu.d.ts +83 -65
  80. package/src/menu.js +10 -18
  81. package/src/menu.js.map +1 -1
  82. package/src/menubar.d.ts +5 -3
  83. package/src/menubar.js +3 -3
  84. package/src/menubar.js.map +1 -1
  85. package/src/message-scroller.d.ts +15 -9
  86. package/src/message-scroller.js +3 -3
  87. package/src/message-scroller.js.map +1 -1
  88. package/src/meter.d.ts +18 -9
  89. package/src/meter.js +1 -1
  90. package/src/meter.js.map +1 -1
  91. package/src/navigation-menu.d.ts +50 -40
  92. package/src/navigation-menu.js +15 -24
  93. package/src/navigation-menu.js.map +1 -1
  94. package/src/number-field.d.ts +19 -12
  95. package/src/number-field.js +6 -10
  96. package/src/number-field.js.map +1 -1
  97. package/src/otp.d.ts +24 -15
  98. package/src/otp.js +7 -13
  99. package/src/otp.js.map +1 -1
  100. package/src/pagination.d.ts +26 -16
  101. package/src/pagination.js +3 -3
  102. package/src/pagination.js.map +1 -1
  103. package/src/popover.d.ts +30 -21
  104. package/src/popover.js +9 -13
  105. package/src/popover.js.map +1 -1
  106. package/src/progress.d.ts +18 -9
  107. package/src/progress.js +1 -1
  108. package/src/progress.js.map +1 -1
  109. package/src/qr-code.d.ts +12 -7
  110. package/src/qr-code.js +3 -3
  111. package/src/qr-code.js.map +1 -1
  112. package/src/radio-group.d.ts +17 -11
  113. package/src/radio-group.js +16 -19
  114. package/src/radio-group.js.map +1 -1
  115. package/src/resizable.d.ts +13 -8
  116. package/src/resizable.js +3 -3
  117. package/src/resizable.js.map +1 -1
  118. package/src/runtime.d.ts +89 -15
  119. package/src/runtime.js +112 -19
  120. package/src/runtime.js.map +1 -1
  121. package/src/scroll-area.d.ts +26 -15
  122. package/src/scroll-area.js +9 -6
  123. package/src/scroll-area.js.map +1 -1
  124. package/src/select.d.ts +65 -45
  125. package/src/select.js +40 -35
  126. package/src/select.js.map +1 -1
  127. package/src/separator.d.ts +4 -2
  128. package/src/separator.js +3 -3
  129. package/src/separator.js.map +1 -1
  130. package/src/slider.d.ts +35 -20
  131. package/src/slider.js +17 -18
  132. package/src/slider.js.map +1 -1
  133. package/src/switch.d.ts +10 -6
  134. package/src/switch.js +11 -9
  135. package/src/switch.js.map +1 -1
  136. package/src/tabs.d.ts +22 -14
  137. package/src/tabs.js +5 -6
  138. package/src/tabs.js.map +1 -1
  139. package/src/testing.d.ts +1 -0
  140. package/src/testing.js +1 -0
  141. package/src/toast.d.ts +59 -23
  142. package/src/toast.js +59 -13
  143. package/src/toast.js.map +1 -1
  144. package/src/toggle-group.d.ts +5 -2
  145. package/src/toggle-group.js +3 -3
  146. package/src/toggle-group.js.map +1 -1
  147. package/src/toggle.d.ts +4 -2
  148. package/src/toggle.js +3 -3
  149. package/src/toggle.js.map +1 -1
  150. package/src/toolbar.d.ts +26 -11
  151. package/src/toolbar.js +23 -13
  152. package/src/toolbar.js.map +1 -1
  153. package/src/tooltip.d.ts +16 -10
  154. package/src/tooltip.js +1 -1
  155. package/src/tooltip.js.map +1 -1
  156. package/src/use-render.d.ts +38 -0
  157. package/src/use-render.js +50 -0
  158. package/src/use-render.js.map +1 -0
  159. package/src/value-bar.d.ts +19 -11
  160. package/src/value-bar.js +8 -5
  161. package/src/value-bar.js.map +1 -1
package/src/combobox.d.ts CHANGED
@@ -1,91 +1,119 @@
1
- import { PartComponentProps } from "./runtime.js";
2
- import { PositionOptions } from "@kirana-ui/core";
1
+ import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
3
3
  import { ReactElement, ReactNode } from "react";
4
4
  import { AutocompleteProps } from "@kirana-ui/core/autocomplete";
5
5
  import { ComboboxProps } from "@kirana-ui/core/combobox";
6
- export type RootProps<Value> = Omit<ComboboxProps<Value>, "id"> & {
6
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
7
+ type Parts = Vocabulary["combobox"];
8
+ /** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */
9
+ export type RootProps<Value = unknown> = Omit<ComboboxProps<Value>, "id"> & {
7
10
  id?: string;
8
11
  children?: ReactNode;
9
12
  };
10
- declare function Root<Value>({ children, ...props }: RootProps<Value>): ReactElement;
11
- declare const Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
12
- declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
13
- declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
14
- declare function Portal({ children }: {
15
- children?: ReactNode;
16
- }): ReactElement | null;
17
- export type PositionerProps = PartComponentProps & Partial<PositionOptions>;
18
- declare function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
- /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
20
- declare function Group({ id, ...props }: PartComponentProps & {
13
+ declare function Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement;
14
+ export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
15
+ export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>>;
16
+ export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
17
+ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
18
+ declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
19
+ declare const Trigger: (props: TriggerProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
20
+ declare const Popup: (props: PopupProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
21
+ /**
22
+ * The items' own box inside the popup, when the popup holds more than items (an input): it
23
+ * is then the listbox.
24
+ */
25
+ declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
26
+ declare function Portal({ children }: PortalProps): ReactElement | null;
27
+ export type PositionerProps = PartComponentProps<"div", StateOf<Parts["positioner"]>, PositionerOptions>;
28
+ declare function Positioner(props: PositionerProps): ReactElement;
29
+ export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
21
30
  id?: string;
22
- }): ReactElement;
31
+ }>;
32
+ /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
33
+ declare function Group({ id, ...props }: GroupProps): ReactElement;
34
+ export type GroupLabelProps = PartComponentProps<"div", StateOf<Parts["groupLabel"]>>;
23
35
  /** A group's name. Outside a group it is plain text, and names nothing. */
24
- declare function GroupLabel(props: PartComponentProps): ReactElement;
36
+ declare function GroupLabel(props: GroupLabelProps): ReactElement;
37
+ export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
25
38
  /** A line between groups. */
26
- declare const Separator: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
27
- export interface ItemProps extends PartComponentProps {
39
+ declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
40
+ export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
41
+ /** What the combobox's value is while this item is chosen. */
28
42
  value: unknown;
43
+ /** Disables this item: it cannot be chosen, and the arrows pass over it. */
29
44
  disabled?: boolean;
30
45
  /** What is filtered and what the input shows; the item's text when left out. */
31
46
  label?: string;
32
47
  id?: string;
33
48
  /** Its place among all the rows, in a virtualized list. */
34
49
  index?: number;
35
- }
50
+ }>;
36
51
  declare function Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement;
37
- export interface ItemIndicatorProps extends PartComponentProps {
52
+ export type ItemIndicatorProps = PartComponentProps<"span", StateOf<Parts["itemIndicator"]>, {
53
+ /** Keeps the mark in the page while its item is not chosen. */
38
54
  keepMounted?: boolean;
39
- }
40
- declare function ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps): import("react").JSX.Element | null;
55
+ }>;
56
+ /** In the page while its item is a chosen one. */
57
+ declare function ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null;
58
+ export type ClearProps = PartComponentProps<"button", StateOf<Parts["clear"]>, {
59
+ /** Keeps the button in the page while there is nothing to clear. */
60
+ keepMounted?: boolean;
61
+ }>;
41
62
  /** A button that empties the input and the value. Drawn while there is something to clear. */
42
- declare function Clear({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null;
63
+ declare function Clear({ keepMounted, ...props }: ClearProps): ReactElement | null;
64
+ export type ChipsProps = PartComponentProps<"div", StateOf<Parts["chips"]>>;
43
65
  /** With `multiple`: what holds the chips and the input. */
44
- declare const Chips: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
45
- /** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
46
- declare function Chip({ value, ...props }: PartComponentProps & {
66
+ declare const Chips: (props: ChipsProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
67
+ export type ChipProps = PartComponentProps<"span", StateOf<Parts["chip"]>, {
68
+ /** The chosen value this chip stands for. */
47
69
  value: unknown;
48
- }): ReactElement;
49
- declare function ChipRemove(props: PartComponentProps): ReactElement;
70
+ }>;
71
+ /** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
72
+ declare function Chip({ value, ...props }: ChipProps): ReactElement;
73
+ export type ChipRemoveProps = PartComponentProps<"button", StateOf<Parts["chipRemove"]>>;
74
+ declare function ChipRemove(props: ChipRemoveProps): ReactElement;
75
+ export type EmptyProps = PartComponentProps<"div", StateOf<Parts["empty"]>>;
50
76
  /** Drawn while no item is shown for what was typed. */
51
- declare function Empty(props: PartComponentProps): ReactElement | null;
77
+ declare function Empty(props: EmptyProps): ReactElement | null;
52
78
  export type AutocompleteRootProps = Omit<AutocompleteProps, "id"> & {
53
79
  id?: string;
54
80
  children?: ReactNode;
55
81
  };
56
82
  /** A combobox whose text is the value: the list only suggests. */
57
83
  declare function AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement;
58
- export declare const Autocomplete: {
59
- Root: typeof AutocompleteRoot;
60
- Input: typeof Input;
61
- Trigger: typeof Trigger;
62
- Clear: typeof Clear;
63
- Portal: typeof Portal;
64
- Positioner: typeof Positioner;
65
- Popup: typeof Popup;
66
- Group: typeof Group;
67
- GroupLabel: typeof GroupLabel;
68
- Separator: typeof Separator;
69
- Item: typeof Item;
70
- Empty: typeof Empty;
71
- };
72
84
  export declare const Combobox: {
73
- Root: typeof Root;
74
- Input: typeof Input;
75
- Trigger: typeof Trigger;
76
- Clear: typeof Clear;
77
- Chips: typeof Chips;
78
- Chip: typeof Chip;
79
- ChipRemove: typeof ChipRemove;
80
- Portal: typeof Portal;
81
- Positioner: typeof Positioner;
82
- Popup: typeof Popup;
83
- Group: typeof Group;
84
- GroupLabel: typeof GroupLabel;
85
- Separator: typeof Separator;
86
- Item: typeof Item;
87
- ItemIndicator: typeof ItemIndicator;
88
- Empty: typeof Empty;
85
+ readonly Root: typeof Root;
86
+ readonly Input: typeof Input;
87
+ readonly Trigger: typeof Trigger;
88
+ readonly Clear: typeof Clear;
89
+ readonly Chips: typeof Chips;
90
+ readonly Chip: typeof Chip;
91
+ readonly ChipRemove: typeof ChipRemove;
92
+ readonly Portal: typeof Portal;
93
+ readonly Positioner: typeof Positioner;
94
+ readonly Popup: typeof Popup;
95
+ readonly List: typeof List;
96
+ readonly Group: typeof Group;
97
+ readonly GroupLabel: typeof GroupLabel;
98
+ readonly Separator: typeof Separator;
99
+ readonly Item: typeof Item;
100
+ readonly ItemIndicator: typeof ItemIndicator;
101
+ readonly Empty: typeof Empty;
102
+ };
103
+ export declare const Autocomplete: {
104
+ readonly Root: typeof AutocompleteRoot;
105
+ readonly Input: typeof Input;
106
+ readonly Trigger: typeof Trigger;
107
+ readonly Clear: typeof Clear;
108
+ readonly Portal: typeof Portal;
109
+ readonly Positioner: typeof Positioner;
110
+ readonly Popup: typeof Popup;
111
+ readonly List: typeof List;
112
+ readonly Group: typeof Group;
113
+ readonly GroupLabel: typeof GroupLabel;
114
+ readonly Separator: typeof Separator;
115
+ readonly Item: typeof Item;
116
+ readonly Empty: typeof Empty;
89
117
  };
90
- export {};
118
+ export type { PortalProps };
91
119
  //# sourceMappingURL=combobox.d.ts.map
package/src/combobox.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FieldContext } from "./field-context.js";
2
- import { Portal as Portal$1, useController, useOptions, useOwnText, usePart, useSignal } from "./runtime.js";
3
- import { defined, within } from "@kirana-ui/core";
2
+ import { PartElement, Portal as Portal$1, parts, useController, useOptions, useOwnText, usePart, usePositioning, useSignal } from "./runtime.js";
3
+ import { within } from "@kirana-ui/core";
4
4
  import { createContext, useContext, useId, useMemo } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  import { createAutocomplete } from "@kirana-ui/core/autocomplete";
@@ -26,19 +26,17 @@ const HiddenInput = () => usePart(useCombobox("Root").hidden, "input", {});
26
26
  const Input = (props) => usePart(useOwnText(useCombobox("Input").input), "input", props);
27
27
  const Trigger = (props) => usePart(useCombobox("Trigger").trigger, "button", props);
28
28
  const Popup = (props) => usePart(useCombobox("Popup").popup, "div", props);
29
+ /**
30
+ * The items' own box inside the popup, when the popup holds more than items (an input): it
31
+ * is then the listbox.
32
+ */
33
+ const List = (props) => usePart(useCombobox("List").list, "div", props);
29
34
  function Portal({ children }) {
30
35
  return useSignal(useCombobox("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
31
36
  }
32
- function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }) {
37
+ function Positioner(props) {
33
38
  const controller = useCombobox("Positioner");
34
- controller.positioning.set(defined({
35
- side,
36
- align,
37
- sideOffset,
38
- alignOffset,
39
- collisionPadding
40
- }));
41
- return usePart(controller.positioner, "div", props);
39
+ return usePart(controller.positioner, "div", usePositioning(controller.positioning, props));
42
40
  }
43
41
  const GroupContext = createContext(null);
44
42
  /** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
@@ -83,17 +81,26 @@ function Item({ value, disabled, label, id, index, ...props }) {
83
81
  children: usePart(part, "div", props)
84
82
  });
85
83
  }
86
- function ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }) {
87
- if (!useSignal(useCombobox("ItemIndicator").selected(useContext(ItemContext))) && !keepMounted) return null;
88
- return /* @__PURE__ */ jsx("span", {
89
- "aria-hidden": "true",
90
- ...rest
91
- });
84
+ /** In the page while its item is a chosen one. */
85
+ function ItemIndicator({ keepMounted, ...props }) {
86
+ const controller = useCombobox("ItemIndicator");
87
+ const value = useContext(ItemContext);
88
+ const selected = useSignal(controller.selected(value));
89
+ const part = useMemo(() => controller.itemIndicator(value), [controller, value]);
90
+ return selected || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
91
+ of: part,
92
+ tag: "span",
93
+ ...props
94
+ }) : null;
92
95
  }
93
- const ClearElement = (props) => usePart(useCombobox("Clear").clear, "button", props);
94
96
  /** A button that empties the input and the value. Drawn while there is something to clear. */
95
97
  function Clear({ keepMounted, ...props }) {
96
- return useSignal(useCombobox("Clear").clearable) || keepMounted ? /* @__PURE__ */ jsx(ClearElement, { ...props }) : null;
98
+ const controller = useCombobox("Clear");
99
+ return useSignal(controller.clearable) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
100
+ of: controller.clear,
101
+ tag: "button",
102
+ ...props
103
+ }) : null;
97
104
  }
98
105
  /** With `multiple`: what holds the chips and the input. */
99
106
  const Chips = (props) => usePart(useCombobox("Chips").chips, "div", props);
@@ -113,10 +120,14 @@ function ChipRemove(props) {
113
120
  const part = useMemo(() => controller.chipRemove(value), [controller, value]);
114
121
  return usePart(part, "button", props);
115
122
  }
116
- const EmptyElement = (props) => usePart(useCombobox("Empty").emptyPart, "div", props);
117
123
  /** Drawn while no item is shown for what was typed. */
118
124
  function Empty(props) {
119
- return useSignal(useCombobox("Empty").empty) ? /* @__PURE__ */ jsx(EmptyElement, { ...props }) : null;
125
+ const controller = useCombobox("Empty");
126
+ return useSignal(controller.empty) ? /* @__PURE__ */ jsx(PartElement, {
127
+ of: controller.emptyPart,
128
+ tag: "div",
129
+ ...props
130
+ }) : null;
120
131
  }
121
132
  /** A combobox whose text is the value: the list only suggests. */
122
133
  function AutocompleteRoot({ children, ...props }) {
@@ -127,38 +138,40 @@ function AutocompleteRoot({ children, ...props }) {
127
138
  children
128
139
  });
129
140
  }
130
- const Autocomplete = {
131
- Root: AutocompleteRoot,
141
+ const Combobox = /* @__PURE__ */ parts("Combobox", {
142
+ Root,
132
143
  Input,
133
144
  Trigger,
134
145
  Clear,
146
+ Chips,
147
+ Chip,
148
+ ChipRemove,
135
149
  Portal,
136
150
  Positioner,
137
151
  Popup,
152
+ List,
138
153
  Group,
139
154
  GroupLabel,
140
155
  Separator,
141
156
  Item,
157
+ ItemIndicator,
142
158
  Empty
143
- };
144
- const Combobox = {
145
- Root,
159
+ });
160
+ const Autocomplete = /* @__PURE__ */ parts("Autocomplete", {
161
+ Root: AutocompleteRoot,
146
162
  Input,
147
163
  Trigger,
148
164
  Clear,
149
- Chips,
150
- Chip,
151
- ChipRemove,
152
165
  Portal,
153
166
  Positioner,
154
167
  Popup,
168
+ List,
155
169
  Group,
156
170
  GroupLabel,
157
171
  Separator,
158
172
  Item,
159
- ItemIndicator,
160
173
  Empty
161
- };
174
+ });
162
175
  export { Autocomplete, Combobox };
163
176
 
164
177
  //# sourceMappingURL=combobox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { PositionOptions } from \"@kirana-ui/core\"\nimport { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\nimport type { Combobox as Controller, ComboboxGroup, ComboboxProps } from \"@kirana-ui/core/combobox\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useCombobox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`)\n return controller\n}\n\nexport type RootProps<Value> = Omit<ComboboxProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<ComboboxProps<Value>, Controller<Value>>(\n within(createCombobox<Value>, { field }),\n props\n ) as unknown as Controller\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: PartComponentProps) =>\n usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: PartComponentProps) =>\n usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PartComponentProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\n\nfunction Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps & Partial<PositionOptions>\n\nfunction Positioner({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n ...props\n}: PositionerProps) {\n const controller = useCombobox(\"Positioner\")\n controller.positioning.set(defined({ side, align, sideOffset, alignOffset, collisionPadding }))\n return usePart(controller.positioner, \"div\", props)\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: PartComponentProps & { id?: string }): ReactElement {\n const controller = useCombobox(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: PartComponentProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\n/** A line between groups. */\nconst Separator = (props: PartComponentProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport interface ItemProps extends PartComponentProps {\n value: unknown\n disabled?: boolean\n /** What is filtered and what the input shows; the item's text when left out. */\n label?: string\n id?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n}\n\nfunction Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement {\n const controller = useCombobox(\"Item\")\n const group = useContext(GroupContext) ?? undefined\n const generated = useId()\n const options = useOptions({ disabled, label, index, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport interface ItemIndicatorProps extends PartComponentProps {\n keepMounted?: boolean\n}\n\nfunction ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps) {\n const selected = useSignal(useCombobox(\"ItemIndicator\").selected(useContext(ItemContext)))\n if (!selected && !keepMounted) return null\n return <span aria-hidden=\"true\" {...(rest as object)} />\n}\n\nconst ClearElement = (props: PartComponentProps) =>\n usePart(useCombobox(\"Clear\").clear, \"button\", props)\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const clearable = useSignal(useCombobox(\"Clear\").clearable)\n return clearable || keepMounted ? <ClearElement {...props} /> : null\n}\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: PartComponentProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: PartComponentProps & { value: unknown }): ReactElement {\n const controller = useCombobox(\"Chip\")\n const part = useMemo(() => controller.chip(value), [controller, value])\n return <ChipContext.Provider value={value}>{usePart(part, \"span\", props)}</ChipContext.Provider>\n}\n\nfunction ChipRemove(props: PartComponentProps): ReactElement {\n const controller = useCombobox(\"ChipRemove\")\n const value = useContext(ChipContext)\n const part = useMemo(() => controller.chipRemove(value), [controller, value])\n return usePart(part, \"button\", props)\n}\n\nconst EmptyElement = (props: PartComponentProps) =>\n usePart(useCombobox(\"Empty\").emptyPart, \"div\", props)\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: PartComponentProps): ReactElement | null {\n const empty = useSignal(useCombobox(\"Empty\").empty)\n return empty ? <EmptyElement {...props} /> : null\n}\n\nexport type AutocompleteRootProps = Omit<AutocompleteProps, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\n/** A combobox whose text is the value: the list only suggests. */\nfunction AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<AutocompleteProps, Controller>(\n within(createAutocomplete, { field }),\n props\n )\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nexport const Autocomplete = {\n Root: AutocompleteRoot,\n Input,\n Trigger,\n Clear,\n Portal,\n Positioner,\n Popup,\n Group,\n GroupLabel,\n Separator,\n Item,\n Empty,\n}\n\nexport const Combobox = {\n Root,\n Input,\n Trigger,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Positioner,\n Popup,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT;AAOA,SAAS,KAAY,EAAE,UAAU,GAAG,SAAyC;CAC3E,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cACjB,OAAO,gBAAuB,EAAE,MAAM,CAAC,GACvC,KACF;CACA,MAAM,QAAQ,UAAU,WAAW,KAAK;CACxC,OACE,qBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAzB,UAAA,CACG,UACA,QAAQ,oBAAC,aAAD,CAAc,CAAA,IAAI,IACX;;AAEtB;AAEA,MAAM,oBAAoB,QAAQ,YAAY,MAAM,CAAC,CAAC,QAAQ,SAAS,CAAC,CAAC;AACzE,MAAM,SAAS,UACb,QAAQ,WA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;CACpC,MAAM,OAAO,cAAc,WAAW,WAAW,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CAC5E,OAAO,QAAQ,MAAM,UAAU,KAAK;AACtC;AAEA,MAAM,gBAAgB,UACpB,QAAQ,YAAY,OAAO,CAAC,CAAC,WAAW,OAAO,KAAK;;AAGtD,SAAS,MAAM,OAAgD;CAE7D,OADc,UAAU,YAAY,OAAO,CAAC,CAAC,KAClC,IAAI,oBAAC,cAAD,EAAc,GAAI,MAAQ,CAAA,IAAI;AAC/C;;AAQA,SAAS,iBAAiB,EAAE,UAAU,GAAG,SAA8C;CACrF,MAAM,QAAQ,WAAW,YAAY,KAAK,KAAA;CAC1C,MAAM,aAAa,cACjB,OAAO,oBAAoB,EAAE,MAAM,CAAC,GACpC,KACF;CACA,OAAO,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa;CAA2B,CAAA;AAC1E;AAEA,MAAa,eAAe;CAC1B,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"combobox.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/combobox.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createAutocomplete } from \"@kirana-ui/core/autocomplete\"\nimport type { AutocompleteProps } from \"@kirana-ui/core/autocomplete\"\nimport { createCombobox } from \"@kirana-ui/core/combobox\"\nimport type { Combobox as Controller, ComboboxGroup, ComboboxProps } from \"@kirana-ui/core/combobox\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { FieldContext } from \"./field-context.ts\"\nimport {\n Portal as BodyPortal,\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n usePositioning,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps, PortalProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps }\n\ntype Parts = Vocabulary[\"combobox\"]\n\nconst Context = createContext<Controller | null>(null)\nconst ItemContext = createContext<unknown>(undefined)\n\nfunction useCombobox(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Combobox.${part}> must be inside <Combobox.Root>`)\n return controller\n}\n\n/** `Value` is what tells an item from the others: the type of `value`, and of `values`' entries. */\nexport type RootProps<Value = unknown> = Omit<ComboboxProps<Value>, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\nfunction Root<Value = unknown>({ children, ...props }: RootProps<Value>): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller: Controller = useController<ComboboxProps<Value>, Controller<Value>>(\n within(createCombobox<Value>, { field }),\n props\n )\n const named = useSignal(controller.named)\n return (\n <Context.Provider value={controller}>\n {children}\n {named ? <HiddenInput /> : null}\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst HiddenInput = () => usePart(useCombobox(\"Root\").hidden, \"input\", {})\nconst Input = (props: InputProps) => usePart(useOwnText(useCombobox(\"Input\").input), \"input\", props)\nconst Trigger = (props: TriggerProps) => usePart(useCombobox(\"Trigger\").trigger, \"button\", props)\nconst Popup = (props: PopupProps) => usePart(useCombobox(\"Popup\").popup, \"div\", props)\n/**\n * The items' own box inside the popup, when the popup holds more than items (an input): it\n * is then the listbox.\n */\nconst List = (props: ListProps) => usePart(useCombobox(\"List\").list, \"div\", props)\n\nfunction Portal({ children }: PortalProps): ReactElement | null {\n const mounted = useSignal(useCombobox(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\n\nfunction Positioner(props: PositionerProps): ReactElement {\n const controller = useCombobox(\"Positioner\")\n return usePart(controller.positioner, \"div\", usePositioning(controller.positioning, props))\n}\n\nconst GroupContext = createContext<ComboboxGroup | null>(null)\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCombobox(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupLabelProps = PartComponentProps<\"div\", StateOf<Parts[\"groupLabel\"]>>\n\n/** A group's name. Outside a group it is plain text, and names nothing. */\nfunction GroupLabel(props: GroupLabelProps): ReactElement {\n const lone = useCombobox(\"GroupLabel\").groupLabel\n return usePart(useContext(GroupContext)?.label ?? lone, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\n/** A line between groups. */\nconst Separator = (props: SeparatorProps) =>\n usePart(useCombobox(\"Separator\").separator, \"div\", props)\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What the combobox's value is while this item is chosen. */\n value: unknown\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered and what the input shows; the item's text when left out. */\n label?: string\n id?: string\n /** Its place among all the rows, in a virtualized list. */\n index?: number\n }\n>\n\nfunction Item({ value, disabled, label, id, index, ...props }: ItemProps): ReactElement {\n const controller = useCombobox(\"Item\")\n const group = useContext(GroupContext) ?? undefined\n const generated = useId()\n const options = useOptions({ disabled, label, index, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return <ItemContext.Provider value={value}>{usePart(part, \"div\", props)}</ItemContext.Provider>\n}\n\nexport type ItemIndicatorProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"itemIndicator\"]>,\n {\n /** Keeps the mark in the page while its item is not chosen. */\n keepMounted?: boolean\n }\n>\n\n/** In the page while its item is a chosen one. */\nfunction ItemIndicator({ keepMounted, ...props }: ItemIndicatorProps): ReactElement | null {\n const controller = useCombobox(\"ItemIndicator\")\n const value = useContext(ItemContext)\n const selected = useSignal(controller.selected(value))\n const part = useMemo(() => controller.itemIndicator(value), [controller, value])\n return selected || keepMounted ? <PartElement of={part} tag=\"span\" {...props} /> : null\n}\n\nexport type ClearProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"clear\"]>,\n {\n /** Keeps the button in the page while there is nothing to clear. */\n keepMounted?: boolean\n }\n>\n\n/** A button that empties the input and the value. Drawn while there is something to clear. */\nfunction Clear({ keepMounted, ...props }: ClearProps): ReactElement | null {\n const controller = useCombobox(\"Clear\")\n const clearable = useSignal(controller.clearable)\n return clearable || keepMounted ? (\n <PartElement of={controller.clear} tag=\"button\" {...props} />\n ) : null\n}\n\nexport type ChipsProps = PartComponentProps<\"div\", StateOf<Parts[\"chips\"]>>\n\n/** With `multiple`: what holds the chips and the input. */\nconst Chips = (props: ChipsProps) => usePart(useCombobox(\"Chips\").chips, \"div\", props)\n\nconst ChipContext = createContext<unknown>(undefined)\n\nexport type ChipProps = PartComponentProps<\n \"span\",\n StateOf<Parts[\"chip\"]>,\n {\n /** The chosen value this chip stands for. */\n value: unknown\n }\n>\n\n/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */\nfunction Chip({ value, ...props }: ChipProps): ReactElement {\n const controller = useCombobox(\"Chip\")\n const part = useMemo(() => controller.chip(value), [controller, value])\n return <ChipContext.Provider value={value}>{usePart(part, \"span\", props)}</ChipContext.Provider>\n}\n\nexport type ChipRemoveProps = PartComponentProps<\"button\", StateOf<Parts[\"chipRemove\"]>>\n\nfunction ChipRemove(props: ChipRemoveProps): ReactElement {\n const controller = useCombobox(\"ChipRemove\")\n const value = useContext(ChipContext)\n const part = useMemo(() => controller.chipRemove(value), [controller, value])\n return usePart(part, \"button\", props)\n}\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCombobox(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type AutocompleteRootProps = Omit<AutocompleteProps, \"id\"> & {\n id?: string\n children?: ReactNode\n}\n\n/** A combobox whose text is the value: the list only suggests. */\nfunction AutocompleteRoot({ children, ...props }: AutocompleteRootProps): ReactElement {\n const field = useContext(FieldContext) ?? undefined\n const controller = useController<AutocompleteProps, Controller>(\n within(createAutocomplete, { field }),\n props\n )\n return <Context.Provider value={controller}>{children}</Context.Provider>\n}\n\nexport const Combobox = /* @__PURE__ */ parts(\"Combobox\", {\n Root,\n Input,\n Trigger,\n Clear,\n Chips,\n Chip,\n ChipRemove,\n Portal,\n Positioner,\n Popup,\n List,\n Group,\n GroupLabel,\n Separator,\n Item,\n ItemIndicator,\n Empty,\n})\n\nexport const Autocomplete = /* @__PURE__ */ parts(\"Autocomplete\", {\n Root: AutocompleteRoot,\n Input,\n Trigger,\n Clear,\n Portal,\n Positioner,\n Popup,\n List,\n Group,\n GroupLabel,\n Separator,\n Item,\n Empty,\n})\n"],"mappings":";;;;;;;;AA4BA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,cAAc,cAAuB,KAAA,CAAS;AAEpD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,aAAa,KAAK,iCAAiC;CACpF,OAAO;AACT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}
package/src/command.d.ts CHANGED
@@ -1,44 +1,53 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
2
3
  import { ReactElement } from "react";
3
4
  import { CommandProps } from "@kirana-ui/core/command";
4
- export type RootProps = Omit<CommandProps, "id"> & {
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["command"];
7
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<CommandProps, "id"> & {
5
8
  id?: string;
6
- } & PartComponentProps;
9
+ }>;
7
10
  declare function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, filter, loop, disabled, id, ...rest }: RootProps): ReactElement;
8
- declare const Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
9
- declare const List: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
11
+ export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
12
+ declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
13
+ export type ListProps = PartComponentProps<"div", StateOf<Parts["list"]>>;
14
+ declare const List: (props: ListProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
15
+ export type EmptyProps = PartComponentProps<"div", StateOf<Parts["empty"]>>;
10
16
  /** Drawn while no item is shown for what was typed. */
11
- declare function Empty(props: PartComponentProps): ReactElement | null;
12
- /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
13
- declare function Group({ id, ...props }: PartComponentProps & {
17
+ declare function Empty(props: EmptyProps): ReactElement | null;
18
+ export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, {
14
19
  id?: string;
15
- }): ReactElement;
16
- declare function GroupHeading(props: PartComponentProps): ReactElement;
17
- export interface ItemProps extends PartComponentProps {
20
+ }>;
21
+ /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
22
+ declare function Group({ id, ...props }: GroupProps): ReactElement;
23
+ export type GroupHeadingProps = PartComponentProps<"div", StateOf<Parts["groupHeading"]>>;
24
+ declare function GroupHeading(props: GroupHeadingProps): ReactElement;
25
+ export type ItemProps = PartComponentProps<"div", StateOf<Parts["item"]>, {
18
26
  /** What `onSelect` is told. */
19
27
  value: string;
28
+ /** Disables this item: it cannot be chosen, and the arrows pass over it. */
20
29
  disabled?: boolean;
21
30
  /** What is filtered; the item's text when left out. */
22
31
  label?: string;
23
32
  /** Other words the item answers to. */
24
33
  keywords?: readonly string[];
25
34
  id?: string;
26
- }
35
+ }>;
27
36
  declare function Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement;
28
- export interface SeparatorProps extends PartComponentProps {
37
+ export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>, {
29
38
  /** Stays while something is typed. */
30
39
  alwaysRender?: boolean;
31
- }
40
+ }>;
32
41
  declare function Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement;
33
42
  export declare const Command: {
34
- Root: typeof Root;
35
- Input: typeof Input;
36
- List: typeof List;
37
- Empty: typeof Empty;
38
- Group: typeof Group;
39
- GroupHeading: typeof GroupHeading;
40
- Item: typeof Item;
41
- Separator: typeof Separator;
43
+ readonly Root: typeof Root;
44
+ readonly Input: typeof Input;
45
+ readonly List: typeof List;
46
+ readonly Empty: typeof Empty;
47
+ readonly Group: typeof Group;
48
+ readonly GroupHeading: typeof GroupHeading;
49
+ readonly Item: typeof Item;
50
+ readonly Separator: typeof Separator;
42
51
  };
43
52
  export {};
44
53
  //# sourceMappingURL=command.d.ts.map
package/src/command.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useController, useOptions, useOwnText, usePart, useSignal } from "./runtime.js";
1
+ import { PartElement, parts, useController, useOptions, useOwnText, usePart, useSignal } from "./runtime.js";
2
2
  import { createContext, useContext, useId, useMemo } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { createCommand } from "@kirana-ui/core/command";
@@ -23,16 +23,23 @@ function Root({ inputValue, defaultInputValue, onInputValueChange, onSelect, fil
23
23
  });
24
24
  return /* @__PURE__ */ jsx(Context.Provider, {
25
25
  value: controller,
26
- children: /* @__PURE__ */ jsx(RootElement, { ...rest })
26
+ children: /* @__PURE__ */ jsx(PartElement, {
27
+ of: controller.root,
28
+ tag: "div",
29
+ ...rest
30
+ })
27
31
  });
28
32
  }
29
- const RootElement = (props) => usePart(useCommand("Root").root, "div", props);
30
33
  const Input = (props) => usePart(useOwnText(useCommand("Input").input), "input", props);
31
34
  const List = (props) => usePart(useCommand("List").list, "div", props);
32
- const EmptyElement = (props) => usePart(useCommand("Empty").emptyPart, "div", props);
33
35
  /** Drawn while no item is shown for what was typed. */
34
36
  function Empty(props) {
35
- return useSignal(useCommand("Empty").empty) ? /* @__PURE__ */ jsx(EmptyElement, { ...props }) : null;
37
+ const controller = useCommand("Empty");
38
+ return useSignal(controller.empty) ? /* @__PURE__ */ jsx(PartElement, {
39
+ of: controller.emptyPart,
40
+ tag: "div",
41
+ ...props
42
+ }) : null;
36
43
  }
37
44
  /** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
38
45
  function Group({ id, ...props }) {
@@ -73,7 +80,7 @@ function Separator({ alwaysRender, ...props }) {
73
80
  const part = useMemo(() => controller.separator(() => options.get().alwaysRender), [controller, options]);
74
81
  return usePart(part, "div", props);
75
82
  }
76
- const Command = {
83
+ const Command = /* @__PURE__ */ parts("Command", {
77
84
  Root,
78
85
  Input,
79
86
  List,
@@ -82,7 +89,7 @@ const Command = {
82
89
  GroupHeading,
83
90
  Item,
84
91
  Separator
85
- };
92
+ });
86
93
  export { Command };
87
94
 
88
95
  //# sourceMappingURL=command.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { useController, useOptions, useOwnText, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<CommandGroup | undefined>(undefined)\n\nfunction useCommand(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<CommandProps, \"id\"> & { id?: string } & PartComponentProps\n\nfunction Root({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n disabled,\n id,\n ...rest\n}: RootProps): ReactElement {\n const controller = useController<CommandProps, Controller>(createCommand, {\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n disabled,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <RootElement {...rest} />\n </Context.Provider>\n )\n}\n\nconst RootElement = (props: PartComponentProps) => usePart(useCommand(\"Root\").root, \"div\", props)\nconst Input = (props: PartComponentProps) =>\n usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nconst List = (props: PartComponentProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nconst EmptyElement = (props: PartComponentProps) =>\n usePart(useCommand(\"Empty\").emptyPart, \"div\", props)\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: PartComponentProps): ReactElement | null {\n const empty = useSignal(useCommand(\"Empty\").empty)\n return empty ? <EmptyElement {...props} /> : null\n}\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: PartComponentProps & { id?: string }): ReactElement {\n const controller = useCommand(\"Group\")\n const generated = useId()\n const name = id ?? generated\n const group = useMemo(() => controller.group(name), [controller, name])\n return (\n <GroupContext.Provider value={group}>{usePart(group.part, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nfunction GroupHeading(props: PartComponentProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport interface ItemProps extends PartComponentProps {\n /** What `onSelect` is told. */\n value: string\n disabled?: boolean\n /** What is filtered; the item's text when left out. */\n label?: string\n /** Other words the item answers to. */\n keywords?: readonly string[]\n id?: string\n}\n\nfunction Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement {\n const controller = useCommand(\"Item\")\n const group = useContext(GroupContext)\n const generated = useId()\n const options = useOptions({ disabled, label, keywords, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return usePart(part, \"div\", props)\n}\n\nexport interface SeparatorProps extends PartComponentProps {\n /** Stays while something is typed. */\n alwaysRender?: boolean\n}\n\nfunction Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement {\n const controller = useCommand(\"Separator\")\n const options = useOptions({ alwaysRender })\n const part = useMemo(\n () => controller.separator(() => options.get().alwaysRender),\n [controller, options]\n )\n return usePart(part, \"div\", props)\n}\n\nexport const Command = { Root, Input, List, Empty, Group, GroupHeading, Item, Separator }\n"],"mappings":";;;;;AAQA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,eAAe,cAAwC,KAAA,CAAS;AAEtE,SAAS,WAAW,MAA0B;CAC5C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,YAAY,KAAK,gCAAgC;CAClF,OAAO;AACT;AAIA,SAAS,KAAK,EACZ,YACA,mBACA,oBACA,UACA,QACA,MACA,UACA,IACA,GAAG,QACuB;CAC1B,MAAM,aAAa,cAAwC,eAAe;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD,EAAa,GAAI,KAAO,CAAA;CACR,CAAA;AAEtB;AAEA,MAAM,eAAe,UAA8B,QAAQ,WAAW,MAAM,CAAC,CAAC,MAAM,OAAO,KAAK;AAChG,MAAM,SAAS,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,aAAa,WAAW,WAAW;CACzC,MAAM,UAAU,WAAW,EAAE,aAAa,CAAC;CAC3C,MAAM,OAAO,cACL,WAAW,gBAAgB,QAAQ,IAAI,CAAC,CAAC,YAAY,GAC3D,CAAC,YAAY,OAAO,CACtB;CACA,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAEA,MAAa,UAAU;CAAE;CAAM;CAAO;CAAM;CAAO;CAAO;CAAc;CAAM;AAAU"}
1
+ {"version":3,"file":"command.js","names":[],"sources":["../../../../packages/react/src/command.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createCommand } from \"@kirana-ui/core/command\"\nimport type { CommandGroup, CommandProps, Command as Controller } from \"@kirana-ui/core/command\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport {\n PartElement,\n parts,\n useController,\n useOptions,\n useOwnText,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"command\"]\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<CommandGroup | undefined>(undefined)\n\nfunction useCommand(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Command.${part}> must be inside <Command.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<CommandProps, \"id\"> & { id?: string }\n>\n\nfunction Root({\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n disabled,\n id,\n ...rest\n}: RootProps): ReactElement {\n const controller = useController<CommandProps, Controller>(createCommand, {\n inputValue,\n defaultInputValue,\n onInputValueChange,\n onSelect,\n filter,\n loop,\n disabled,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>>\n\nconst Input = (props: InputProps) => usePart(useOwnText(useCommand(\"Input\").input), \"input\", props)\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>>\n\nconst List = (props: ListProps) => usePart(useCommand(\"List\").list, \"div\", props)\n\nexport type EmptyProps = PartComponentProps<\"div\", StateOf<Parts[\"empty\"]>>\n\n/** Drawn while no item is shown for what was typed. */\nfunction Empty(props: EmptyProps): ReactElement | null {\n const controller = useCommand(\"Empty\")\n const empty = useSignal(controller.empty)\n return empty ? <PartElement of={controller.emptyPart} tag=\"div\" {...props} /> : null\n}\n\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, { id?: string }>\n\n/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */\nfunction Group({ id, ...props }: GroupProps): ReactElement {\n const controller = useCommand(\"Group\")\n const generated = useId()\n const name = id ?? generated\n const group = useMemo(() => controller.group(name), [controller, name])\n return (\n <GroupContext.Provider value={group}>{usePart(group.part, \"div\", props)}</GroupContext.Provider>\n )\n}\n\nexport type GroupHeadingProps = PartComponentProps<\"div\", StateOf<Parts[\"groupHeading\"]>>\n\nfunction GroupHeading(props: GroupHeadingProps): ReactElement {\n const lone = useCommand(\"GroupHeading\").heading\n return usePart(useContext(GroupContext)?.heading ?? lone, \"div\", props)\n}\n\nexport type ItemProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"item\"]>,\n {\n /** What `onSelect` is told. */\n value: string\n /** Disables this item: it cannot be chosen, and the arrows pass over it. */\n disabled?: boolean\n /** What is filtered; the item's text when left out. */\n label?: string\n /** Other words the item answers to. */\n keywords?: readonly string[]\n id?: string\n }\n>\n\nfunction Item({ value, disabled, label, keywords, id, ...props }: ItemProps): ReactElement {\n const controller = useCommand(\"Item\")\n const group = useContext(GroupContext)\n const generated = useId()\n const options = useOptions({ disabled, label, keywords, id: id ?? generated })\n const part = useMemo(\n () => controller.item(value, () => options.get(), group),\n [controller, value, options, group]\n )\n return usePart(part, \"div\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"separator\"]>,\n {\n /** Stays while something is typed. */\n alwaysRender?: boolean\n }\n>\n\nfunction Separator({ alwaysRender, ...props }: SeparatorProps): ReactElement {\n const controller = useCommand(\"Separator\")\n const options = useOptions({ alwaysRender })\n const part = useMemo(\n () => controller.separator(() => options.get().alwaysRender),\n [controller, options]\n )\n return usePart(part, \"div\", props)\n}\n\nexport const Command = /* @__PURE__ */ parts(\"Command\", {\n Root,\n Input,\n List,\n Empty,\n Group,\n GroupHeading,\n Item,\n Separator,\n})\n"],"mappings":";;;;;AAoBA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,eAAe,cAAwC,KAAA,CAAS;AAEtE,SAAS,WAAW,MAA0B;CAC5C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,YAAY,KAAK,gCAAgC;CAClF,OAAO;AACT;AAQA,SAAS,KAAK,EACZ,YACA,mBACA,oBACA,UACA,QACA,MACA,UACA,IACA,GAAG,QACuB;CAC1B,MAAM,aAAa,cAAwC,eAAe;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CACvC,CAAA;AAEtB;AAIA,MAAM,SAAS,UAAsB,QAAQ,WAAW,WAAW,OAAO,CAAC,CAAC,KAAK,GAAG,SAAS,KAAK;AAGlG,MAAM,QAAQ,UAAqB,QAAQ,WAAW,MAAM,CAAC,CAAC,MAAM,OAAO,KAAK;;AAKhF,SAAS,MAAM,OAAwC;CACrD,MAAM,aAAa,WAAW,OAAO;CAErC,OADc,UAAU,WAAW,KACxB,IAAI,oBAAC,aAAD;EAAa,IAAI,WAAW;EAAW,KAAI;EAAM,GAAI;C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u.js";
2
- export { ContextMenu };
1
+ import { PortalProps } from "./runtime.js";
2
+ import { ArrowProps, CheckboxItemIndicatorProps, CheckboxItemProps, ContextMenu, ContextTriggerProps, GroupLabelProps, GroupProps, ItemProps, LinkItemProps, PopupProps, PositionerProps, RadioGroupProps, RadioItemIndicatorProps, RadioItemProps, RootProps, SeparatorProps, SubmenuRootProps, SubmenuTriggerProps } from "./menu.js";
3
+ export { type ArrowProps, type CheckboxItemIndicatorProps, type CheckboxItemProps, ContextMenu, type GroupLabelProps, type GroupProps, type ItemProps, type LinkItemProps, type PopupProps, type PortalProps, type PositionerProps, type RadioGroupProps, type RadioItemIndicatorProps, type RadioItemProps, type RootProps, type SeparatorProps, type SubmenuRootProps, type SubmenuTriggerProps, type ContextTriggerProps as TriggerProps };
@@ -1,25 +1,37 @@
1
1
  import { PartComponentProps } from "./runtime.js";
2
+ import { StateOf } from "@kirana-ui/core";
2
3
  import { ReactElement, ReactNode } from "react";
3
4
  import { DateField as DateField$1, DateFieldProps, DateFieldSegment } from "@kirana-ui/core/date-field";
5
+ import { Vocabulary } from "@kirana-ui/core/vocabulary";
6
+ type Parts = Vocabulary["dateField"];
7
+ /**
8
+ * The date field its parts are inside. Exported for a component that is made of one (a date picker
9
+ * provides its own to the date field's parts).
10
+ */
4
11
  declare const Context: import("react").Context<DateField$1 | null>;
5
- export type RootProps = Omit<DateFieldProps, "id"> & {
12
+ export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, Omit<DateFieldProps, "id"> & {
6
13
  id?: string;
7
- } & PartComponentProps;
14
+ }>;
8
15
  declare function Root({ value, defaultValue, onValueChange, locale, min, max, placeholders, disabled, readOnly, required, name, form, id, ...rest }: RootProps): ReactElement;
9
- /** Draws its child once for each piece of the date, in the locale's order. */
10
- declare function Segments({ children }: {
16
+ export interface SegmentsProps {
17
+ /** Draws one piece of the date, once for each: a part that is typed, or what stands between two. */
11
18
  children: (segment: DateFieldSegment) => ReactNode;
12
- }): import("react").JSX.Element;
13
- /** One piece: a part that is typed, or what stands between two. It writes its own text. */
14
- declare function Segment({ segment, ...props }: PartComponentProps & {
19
+ }
20
+ /** Draws its child once for each piece of the date, in the locale's order. */
21
+ declare function Segments({ children }: SegmentsProps): import("react").JSX.Element;
22
+ export type SegmentProps = PartComponentProps<"span", StateOf<Parts["segment"]>, {
23
+ /** The piece it is: an entry `DateField.Segments` gave. */
15
24
  segment: DateFieldSegment;
16
- }): ReactElement;
17
- declare const Input: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
25
+ }>;
26
+ /** One piece: a part that is typed, or what stands between two. It writes its own text. */
27
+ declare function Segment({ segment, ...props }: SegmentProps): ReactElement;
28
+ export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>>;
29
+ declare const Input: (props: InputProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
18
30
  export declare const DateField: {
19
- Root: typeof Root;
20
- Segments: typeof Segments;
21
- Segment: typeof Segment;
22
- Input: typeof Input;
31
+ readonly Root: typeof Root;
32
+ readonly Segments: typeof Segments;
33
+ readonly Segment: typeof Segment;
34
+ readonly Input: typeof Input;
23
35
  };
24
36
  export { Context as DateFieldContext };
25
37
  //# sourceMappingURL=date-field.d.ts.map