@choice-ui/command 0.0.5 → 0.0.7

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.
package/dist/index.d.ts CHANGED
@@ -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;
@@ -54,6 +58,9 @@ interface CommandItemProps extends Omit<HTMLProps<HTMLDivElement>, "onSelect"> {
54
58
  interface CommandListProps extends ScrollAreaProps {
55
59
  children: React.ReactNode;
56
60
  className?: string;
61
+ classNames?: {
62
+ content?: string;
63
+ };
57
64
  label?: string;
58
65
  }
59
66
 
@@ -106,6 +113,11 @@ interface CommandProps extends Omit<react__default.HTMLAttributes<HTMLDivElement
106
113
  * Event handler called when the selected item of the menu changes.
107
114
  */
108
115
  onChange?: (value: string) => void;
116
+ /**
117
+ * Optionally set to `true` to enable selection mode.
118
+ * When enabled, items with `selected` prop will be scrolled into view on mount.
119
+ */
120
+ selection?: boolean;
109
121
  /**
110
122
  * Optionally set to `false` to turn off the automatic filtering and sorting.
111
123
  * If `false`, you must conditionally render valid items based on the search query yourself.
@@ -140,6 +152,7 @@ type Context = {
140
152
  labelId: string;
141
153
  listId: string;
142
154
  listInnerRef: react__default.MutableRefObject<HTMLDivElement | null>;
155
+ selection?: boolean;
143
156
  size?: "default" | "large";
144
157
  store: Store;
145
158
  value: (id: string, value?: string, keywords?: string[]) => void;
package/dist/index.js CHANGED
@@ -180,6 +180,7 @@ function createCommandContext(options) {
180
180
  propsRef,
181
181
  schedule,
182
182
  selectFirstItem,
183
+ selection,
183
184
  size,
184
185
  sort,
185
186
  state,
@@ -256,6 +257,7 @@ function createCommandContext(options) {
256
257
  inputId,
257
258
  labelId,
258
259
  listInnerRef,
260
+ selection,
259
261
  store,
260
262
  size,
261
263
  variant
@@ -333,7 +335,7 @@ var commandTv = tcv({
333
335
  variants: {
334
336
  variant: {
335
337
  default: {
336
- root: "bg-default-background text-default-foreground",
338
+ root: "text-default-foreground",
337
339
  divider: "bg-default-boundary"
338
340
  },
339
341
  dark: {
@@ -600,6 +602,7 @@ var Command = forwardRef((props, forwardedRef) => {
600
602
  onChange: onValueChange,
601
603
  filter,
602
604
  shouldFilter,
605
+ selection,
603
606
  loop,
604
607
  size = "default",
605
608
  variant = "default",
@@ -803,6 +806,7 @@ var Command = forwardRef((props, forwardedRef) => {
803
806
  propsRef,
804
807
  schedule,
805
808
  selectFirstItem,
809
+ selection,
806
810
  size,
807
811
  sort,
808
812
  state,
@@ -1053,6 +1057,7 @@ var CommandItem = memo(
1053
1057
  forceMount,
1054
1058
  keywords,
1055
1059
  onSelect,
1060
+ selected: selectedProp,
1056
1061
  value,
1057
1062
  children,
1058
1063
  prefixElement,
@@ -1087,6 +1092,11 @@ var CommandItem = memo(
1087
1092
  const stableKeywords = useMemo(() => keywords || [], [keywords]);
1088
1093
  const valueRef = useValue(id, ref, valueDeps, stableKeywords);
1089
1094
  const store = context.store;
1095
+ useEffect(() => {
1096
+ if (context.selection && selectedProp && valueRef.current) {
1097
+ store.setState("value", valueRef.current);
1098
+ }
1099
+ }, [selectedProp]);
1090
1100
  const selected = useCommandState(
1091
1101
  (state) => Boolean(state.value && state.value === valueRef?.current)
1092
1102
  );
@@ -1169,6 +1179,9 @@ var CommandList = forwardRef((props, forwardedRef) => {
1169
1179
  label = "Suggestions",
1170
1180
  hoverBoundary = "none",
1171
1181
  scrollbarMode = "padding-b",
1182
+ classNames = {
1183
+ content: ""
1184
+ },
1172
1185
  orientation,
1173
1186
  variant,
1174
1187
  type,
@@ -1215,6 +1228,7 @@ var CommandList = forwardRef((props, forwardedRef) => {
1215
1228
  },
1216
1229
  ...rest,
1217
1230
  className: tcx(tv.root({ className })),
1231
+ style: context.selection ? { scrollPaddingBlock: 8 } : void 0,
1218
1232
  role: "listbox",
1219
1233
  tabIndex: -1,
1220
1234
  "aria-activedescendant": selectedItemId,
@@ -1223,7 +1237,7 @@ var CommandList = forwardRef((props, forwardedRef) => {
1223
1237
  children: /* @__PURE__ */ jsx(
1224
1238
  ScrollArea.Content,
1225
1239
  {
1226
- className: tcx(tv.content()),
1240
+ className: tcx(tv.content(), classNames?.content),
1227
1241
  ref: (el) => {
1228
1242
  height.current = el;
1229
1243
  if (context.listInnerRef) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@choice-ui/command",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A command palette component for quick actions, search, and keyboard navigation",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "usehooks-ts": "^3.1.0",
23
23
  "@choice-ui/shared": "^0.0.1",
24
- "@choice-ui/text-field": "^0.0.7",
24
+ "@choice-ui/text-field": "^0.0.10",
25
25
  "@choice-ui/kbd": "^0.0.4",
26
26
  "@choice-ui/scroll-area": "^0.0.7",
27
27
  "@choice-ui/tabs": "^0.0.5"