@choice-ui/react 1.9.3 → 1.9.4

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.
@@ -246,6 +246,13 @@ const buttonTv = tcv({
246
246
  variant: "secondary",
247
247
  active: false,
248
248
  class: { button: "hover:bg-secondary-background" }
249
+ },
250
+ {
251
+ disabled: false,
252
+ loading: false,
253
+ variant: "secondary-destruct",
254
+ active: false,
255
+ class: { button: "hover:bg-danger-background/10" }
249
256
  }
250
257
  ],
251
258
  defaultVariants: {
@@ -43,6 +43,10 @@ interface CommandItemProps extends Omit<HTMLProps<HTMLDivElement>, "onSelect"> {
43
43
  keywords?: string[];
44
44
  onSelect?: (value: string) => void;
45
45
  prefixElement?: ReactNode;
46
+ /**
47
+ * When true, this item will be set as the selected item and scrolled into view.
48
+ */
49
+ selected?: boolean;
46
50
  shortcut?: {
47
51
  keys?: ReactNode;
48
52
  modifier?: KbdKey | KbdKey[] | undefined;
@@ -106,6 +110,11 @@ interface CommandProps extends Omit<react__default.HTMLAttributes<HTMLDivElement
106
110
  * Event handler called when the selected item of the menu changes.
107
111
  */
108
112
  onChange?: (value: string) => void;
113
+ /**
114
+ * Optionally set to `true` to enable selection mode.
115
+ * When enabled, items with `selected` prop will be scrolled into view on mount.
116
+ */
117
+ selection?: boolean;
109
118
  /**
110
119
  * Optionally set to `false` to turn off the automatic filtering and sorting.
111
120
  * If `false`, you must conditionally render valid items based on the search query yourself.
@@ -140,6 +149,7 @@ type Context = {
140
149
  labelId: string;
141
150
  listId: string;
142
151
  listInnerRef: react__default.MutableRefObject<HTMLDivElement | null>;
152
+ selection?: boolean;
143
153
  size?: "default" | "large";
144
154
  store: Store;
145
155
  value: (id: string, value?: string, keywords?: string[]) => void;
@@ -42,6 +42,7 @@ const Command = forwardRef((props, forwardedRef) => {
42
42
  onChange: onValueChange,
43
43
  filter,
44
44
  shouldFilter,
45
+ selection,
45
46
  loop,
46
47
  size = "default",
47
48
  variant = "default",
@@ -253,6 +254,7 @@ const Command = forwardRef((props, forwardedRef) => {
253
254
  propsRef,
254
255
  schedule,
255
256
  selectFirstItem,
257
+ selection,
256
258
  size,
257
259
  sort,
258
260
  state,
@@ -6,6 +6,10 @@ export interface CommandItemProps extends Omit<HTMLProps<HTMLDivElement>, "onSel
6
6
  keywords?: string[];
7
7
  onSelect?: (value: string) => void;
8
8
  prefixElement?: ReactNode;
9
+ /**
10
+ * When true, this item will be set as the selected item and scrolled into view.
11
+ */
12
+ selected?: boolean;
9
13
  shortcut?: {
10
14
  keys?: ReactNode;
11
15
  modifier?: KbdKey | KbdKey[] | undefined;
@@ -16,6 +16,7 @@ const CommandItem = memo(
16
16
  forceMount,
17
17
  keywords,
18
18
  onSelect,
19
+ selected: selectedProp,
19
20
  value,
20
21
  children,
21
22
  prefixElement,
@@ -50,6 +51,11 @@ const CommandItem = memo(
50
51
  const stableKeywords = useMemo(() => keywords || [], [keywords]);
51
52
  const valueRef = useValue(id, ref, valueDeps, stableKeywords);
52
53
  const store = context.store;
54
+ useEffect(() => {
55
+ if (context.selection && selectedProp && valueRef.current) {
56
+ store.setState("value", valueRef.current);
57
+ }
58
+ }, [selectedProp]);
53
59
  const selected = useCommandState(
54
60
  (state) => Boolean(state.value && state.value === (valueRef == null ? void 0 : valueRef.current))
55
61
  );
@@ -58,6 +58,7 @@ const CommandList = forwardRef((props, forwardedRef) => {
58
58
  },
59
59
  ...rest,
60
60
  className: tcx(tv.root({ className })),
61
+ style: context.selection ? { scrollPaddingBlock: 8 } : void 0,
61
62
  role: "listbox",
62
63
  tabIndex: -1,
63
64
  "aria-activedescendant": selectedItemId,
@@ -16,6 +16,7 @@ interface CreateCommandContextOptions {
16
16
  propsRef: React.MutableRefObject<CommandProps>;
17
17
  schedule: (id: string | number, cb: () => void) => void;
18
18
  selectFirstItem: () => void;
19
+ selection?: boolean;
19
20
  size?: "default" | "large";
20
21
  sort: () => void;
21
22
  state: React.MutableRefObject<State>;
@@ -13,6 +13,7 @@ function createCommandContext(options) {
13
13
  propsRef,
14
14
  schedule,
15
15
  selectFirstItem,
16
+ selection,
16
17
  size,
17
18
  sort,
18
19
  state,
@@ -93,6 +94,7 @@ function createCommandContext(options) {
93
94
  inputId,
94
95
  labelId,
95
96
  listInnerRef,
97
+ selection,
96
98
  store,
97
99
  size,
98
100
  variant
@@ -7,7 +7,7 @@ const commandTv = tcv({
7
7
  variants: {
8
8
  variant: {
9
9
  default: {
10
- root: "bg-default-background text-default-foreground",
10
+ root: "text-default-foreground",
11
11
  divider: "bg-default-boundary"
12
12
  },
13
13
  dark: {
@@ -27,6 +27,11 @@ export interface CommandProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
27
27
  * Event handler called when the selected item of the menu changes.
28
28
  */
29
29
  onChange?: (value: string) => void;
30
+ /**
31
+ * Optionally set to `true` to enable selection mode.
32
+ * When enabled, items with `selected` prop will be scrolled into view on mount.
33
+ */
34
+ selection?: boolean;
30
35
  /**
31
36
  * Optionally set to `false` to turn off the automatic filtering and sorting.
32
37
  * If `false`, you must conditionally render valid items based on the search query yourself.
@@ -61,6 +66,7 @@ export type Context = {
61
66
  labelId: string;
62
67
  listId: string;
63
68
  listInnerRef: React.MutableRefObject<HTMLDivElement | null>;
69
+ selection?: boolean;
64
70
  size?: "default" | "large";
65
71
  store: Store;
66
72
  value: (id: string, value?: string, keywords?: string[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@choice-ui/react",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "description": "A desktop-first React UI component library built for professional desktop applications with comprehensive documentation",
5
5
  "sideEffects": false,
6
6
  "type": "module",