@choice-ui/command 0.0.4 → 0.0.6
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 +10 -0
- package/dist/index.js +27 -4
- package/package.json +5 -5
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;
|
|
@@ -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;
|
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: "
|
|
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
|
);
|
|
@@ -1163,7 +1173,17 @@ var CommandItem = memo(
|
|
|
1163
1173
|
);
|
|
1164
1174
|
CommandItem.displayName = "CommandItem";
|
|
1165
1175
|
var CommandList = forwardRef((props, forwardedRef) => {
|
|
1166
|
-
const {
|
|
1176
|
+
const {
|
|
1177
|
+
children,
|
|
1178
|
+
className,
|
|
1179
|
+
label = "Suggestions",
|
|
1180
|
+
hoverBoundary = "none",
|
|
1181
|
+
scrollbarMode = "padding-b",
|
|
1182
|
+
orientation,
|
|
1183
|
+
variant,
|
|
1184
|
+
type,
|
|
1185
|
+
...rest
|
|
1186
|
+
} = props;
|
|
1167
1187
|
const ref = useRef(null);
|
|
1168
1188
|
const height = useRef(null);
|
|
1169
1189
|
const selectedItemId = useCommandState((state) => state.selectedItemId);
|
|
@@ -1190,9 +1210,11 @@ var CommandList = forwardRef((props, forwardedRef) => {
|
|
|
1190
1210
|
return /* @__PURE__ */ jsx(
|
|
1191
1211
|
ScrollArea,
|
|
1192
1212
|
{
|
|
1193
|
-
variant: context.variant,
|
|
1213
|
+
variant: variant ?? context.variant,
|
|
1194
1214
|
hoverBoundary,
|
|
1195
|
-
|
|
1215
|
+
scrollbarMode,
|
|
1216
|
+
orientation,
|
|
1217
|
+
type,
|
|
1196
1218
|
children: /* @__PURE__ */ jsx(
|
|
1197
1219
|
ScrollArea.Viewport,
|
|
1198
1220
|
{
|
|
@@ -1203,6 +1225,7 @@ var CommandList = forwardRef((props, forwardedRef) => {
|
|
|
1203
1225
|
},
|
|
1204
1226
|
...rest,
|
|
1205
1227
|
className: tcx(tv.root({ className })),
|
|
1228
|
+
style: context.selection ? { scrollPaddingBlock: 8 } : void 0,
|
|
1206
1229
|
role: "listbox",
|
|
1207
1230
|
tabIndex: -1,
|
|
1208
1231
|
"aria-activedescendant": selectedItemId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choice-ui/command",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A command palette component for quick actions, search, and keyboard navigation",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -21,10 +21,10 @@
|
|
|
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.
|
|
25
|
-
"@choice-ui/kbd": "^0.0.
|
|
26
|
-
"@choice-ui/scroll-area": "^0.0.
|
|
27
|
-
"@choice-ui/tabs": "^0.0.
|
|
24
|
+
"@choice-ui/text-field": "^0.0.10",
|
|
25
|
+
"@choice-ui/kbd": "^0.0.4",
|
|
26
|
+
"@choice-ui/scroll-area": "^0.0.7",
|
|
27
|
+
"@choice-ui/tabs": "^0.0.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/react": "^18.3.12",
|