Skip to content

Commit 547f76b

Browse files
committed
feat(CommandPalette): add new component * 6
1 parent dd7cd9e commit 547f76b

File tree

3 files changed

+20
-126
lines changed

3 files changed

+20
-126
lines changed

src/components/actions/CommandMenu/CommandMenu.docs.mdx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -312,23 +312,6 @@ The CommandMenu supports enhanced search capabilities:
312312
- **Force mount**: Certain items can always be visible regardless of search filter
313313
- **Custom filtering**: Override the default search algorithm with custom logic
314314

315-
### Integration with Dialog System
316-
317-
```jsx
318-
import { useDialogContainer } from '../../../hooks';
319-
320-
const CommandMenuDialog = useDialogContainer(CommandMenu);
321-
322-
// Usage
323-
<CommandMenuDialog
324-
isOpen={isOpen}
325-
onClose={() => setIsOpen(false)}
326-
searchPlaceholder="Search commands..."
327-
>
328-
<Menu.Item key="action1">Action 1</Menu.Item>
329-
</CommandMenuDialog>
330-
```
331-
332315
## Best Practices
333316

334317
### Do's

src/components/actions/CommandMenu/CommandMenu.stories.tsx

Lines changed: 20 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
IconFileText,
1111
IconFolder,
1212
IconSearch,
13+
IconSelect,
1314
IconSettings,
1415
} from '@tabler/icons-react';
1516
import React, { useState } from 'react';
@@ -135,36 +136,42 @@ const basicCommands = [
135136
label: 'Copy',
136137
description: 'Copy selected text',
137138
hotkeys: 'Ctrl+C',
139+
icon: <IconCopy />,
138140
},
139141
{
140142
key: 'paste',
141143
label: 'Paste',
142144
description: 'Paste from clipboard',
143145
hotkeys: 'Ctrl+V',
146+
icon: <IconClipboard />,
144147
},
145148
{
146149
key: 'cut',
147150
label: 'Cut',
148151
description: 'Cut selected text',
149152
hotkeys: 'Ctrl+X',
153+
icon: <IconCut />,
150154
},
151155
{
152156
key: 'undo',
153157
label: 'Undo',
154158
description: 'Undo last action',
155159
hotkeys: 'Ctrl+Z',
160+
icon: <IconArrowBack />,
156161
},
157162
{
158163
key: 'redo',
159164
label: 'Redo',
160165
description: 'Redo last action',
161166
hotkeys: 'Ctrl+Y',
167+
icon: <IconArrowForward />,
162168
},
163169
{
164170
key: 'select-all',
165171
label: 'Select All',
166172
description: 'Select all text',
167173
hotkeys: 'Ctrl+A',
174+
icon: <IconSelect />,
168175
},
169176
];
170177

@@ -291,6 +298,7 @@ export const Default: StoryFn<CubeCommandMenuProps<any>> = (args) => (
291298
key={command.key}
292299
description={command.description}
293300
hotkeys={command.hotkeys}
301+
icon={command.icon}
294302
>
295303
{command.label}
296304
</CommandMenu.Item>
@@ -349,6 +357,7 @@ export const WithMenuTrigger: StoryFn<CubeCommandMenuProps<any>> = (args) => (
349357
key={command.key}
350358
description={command.description}
351359
hotkeys={command.hotkeys}
360+
icon={command.icon}
352361
>
353362
{command.label}
354363
</CommandMenu.Item>
@@ -411,6 +420,7 @@ export const ControlledSearch: StoryFn<CubeCommandMenuProps<any>> = (args) => {
411420
key={command.key}
412421
description={command.description}
413422
hotkeys={command.hotkeys}
423+
icon={command.icon}
414424
>
415425
{command.label}
416426
</CommandMenu.Item>
@@ -432,6 +442,7 @@ export const LoadingState: StoryFn<CubeCommandMenuProps<any>> = (args) => (
432442
key={command.key}
433443
description={command.description}
434444
hotkeys={command.hotkeys}
445+
icon={command.icon}
435446
>
436447
{command.label}
437448
</CommandMenu.Item>
@@ -469,6 +480,7 @@ export const CustomFilter: StoryFn<CubeCommandMenuProps<any>> = (args) => (
469480
key={command.key}
470481
description={command.description}
471482
hotkeys={command.hotkeys}
483+
icon={command.icon}
472484
>
473485
{command.label}
474486
</CommandMenu.Item>
@@ -516,6 +528,7 @@ export const ForceMountItems: StoryFn<CubeCommandMenuProps<any>> = (args) => (
516528
key={command.key}
517529
description={command.description}
518530
hotkeys={command.hotkeys}
531+
icon={command.icon}
519532
>
520533
{command.label}
521534
</CommandMenu.Item>
@@ -560,6 +573,7 @@ export const MultipleSelection: StoryFn<CubeCommandMenuProps<any>> = (args) => {
560573
key={command.key}
561574
description={command.description}
562575
hotkeys={command.hotkeys}
576+
icon={command.icon}
563577
>
564578
{command.label}
565579
</CommandMenu.Item>
@@ -595,6 +609,7 @@ export const SingleSelection: StoryFn<CubeCommandMenuProps<any>> = (args) => {
595609
key={command.key}
596610
description={command.description}
597611
hotkeys={command.hotkeys}
612+
icon={command.icon}
598613
>
599614
{command.label}
600615
</CommandMenu.Item>
@@ -627,6 +642,7 @@ export const CustomStyling: StoryFn<CubeCommandMenuProps<any>> = (args) => (
627642
key={command.key}
628643
description={command.description}
629644
hotkeys={command.hotkeys}
645+
icon={command.icon}
630646
>
631647
{command.label}
632648
</CommandMenu.Item>
@@ -688,6 +704,7 @@ export const HotkeyTesting: StoryFn<CubeCommandMenuProps<any>> = (args) => {
688704
key={command.key}
689705
description={command.description}
690706
hotkeys={command.hotkeys}
707+
icon={command.icon}
691708
>
692709
{command.label}
693710
</CommandMenu.Item>
@@ -709,6 +726,7 @@ export const MediumSize: StoryFn<CubeCommandMenuProps<any>> = (args) => (
709726
key={command.key}
710727
description={command.description}
711728
hotkeys={command.hotkeys}
729+
icon={command.icon}
712730
>
713731
{command.label}
714732
</CommandMenu.Item>
@@ -731,6 +749,7 @@ export const WithDialog: StoryFn<CubeCommandMenuProps<any>> = (args) => (
731749
key={command.key}
732750
description={command.description}
733751
hotkeys={command.hotkeys}
752+
icon={command.icon}
734753
>
735754
{command.label}
736755
</CommandMenu.Item>
@@ -781,6 +800,7 @@ function CommandMenuDialogContent({
781800
key={command.key}
782801
description={command.description}
783802
hotkeys={command.hotkeys}
803+
icon={command.icon}
784804
>
785805
{command.label}
786806
</CommandMenu.Item>
@@ -825,106 +845,3 @@ WithDialogContainer.play = async ({ canvasElement }) => {
825845
canvas.getByPlaceholderText('Search commands...');
826846
});
827847
};
828-
829-
export const WithIcons: StoryFn<CubeCommandMenuProps<any>> = (args) => (
830-
<CommandMenu {...args}>
831-
<Menu.Section title="File Operations">
832-
<CommandMenu.Item
833-
key="new-file"
834-
icon={<IconFile />}
835-
description="Create a new file"
836-
hotkeys="Ctrl+N"
837-
>
838-
New File
839-
</CommandMenu.Item>
840-
<CommandMenu.Item
841-
key="open-file"
842-
icon={<IconFolder />}
843-
description="Open an existing file"
844-
hotkeys="Ctrl+O"
845-
>
846-
Open File
847-
</CommandMenu.Item>
848-
<CommandMenu.Item
849-
key="save-file"
850-
icon={<IconDeviceFloppy />}
851-
description="Save current file"
852-
hotkeys="Ctrl+S"
853-
>
854-
Save File
855-
</CommandMenu.Item>
856-
</Menu.Section>
857-
858-
<Menu.Section title="Edit Operations">
859-
<CommandMenu.Item
860-
key="copy"
861-
icon={<IconCopy />}
862-
description="Copy selected text"
863-
hotkeys="Ctrl+C"
864-
keywords={['duplicate', 'clone']}
865-
>
866-
Copy
867-
</CommandMenu.Item>
868-
<CommandMenu.Item
869-
key="paste"
870-
icon={<IconClipboard />}
871-
description="Paste from clipboard"
872-
hotkeys="Ctrl+V"
873-
keywords={['insert']}
874-
>
875-
Paste
876-
</CommandMenu.Item>
877-
<CommandMenu.Item
878-
key="cut"
879-
icon={<IconCut />}
880-
description="Cut selected text"
881-
hotkeys="Ctrl+X"
882-
>
883-
Cut
884-
</CommandMenu.Item>
885-
<CommandMenu.Item
886-
key="undo"
887-
icon={<IconArrowBack />}
888-
description="Undo last action"
889-
hotkeys="Ctrl+Z"
890-
>
891-
Undo
892-
</CommandMenu.Item>
893-
<CommandMenu.Item
894-
key="redo"
895-
icon={<IconArrowForward />}
896-
description="Redo last action"
897-
hotkeys="Ctrl+Y"
898-
>
899-
Redo
900-
</CommandMenu.Item>
901-
</Menu.Section>
902-
903-
<Menu.Section title="Tools">
904-
<CommandMenu.Item
905-
key="search"
906-
icon={<IconSearch />}
907-
description="Search in files"
908-
hotkeys="Ctrl+F"
909-
>
910-
Search
911-
</CommandMenu.Item>
912-
<CommandMenu.Item
913-
key="settings"
914-
icon={<IconSettings />}
915-
description="Open settings"
916-
hotkeys="Ctrl+."
917-
>
918-
Settings
919-
</CommandMenu.Item>
920-
<CommandMenu.Item key="documents" description="View all documents">
921-
Documents
922-
</CommandMenu.Item>
923-
</Menu.Section>
924-
</CommandMenu>
925-
);
926-
927-
WithIcons.args = {
928-
searchPlaceholder: 'Search commands with icons...',
929-
autoFocus: true,
930-
};

src/components/actions/CommandMenu/CommandMenu.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export interface CommandMenuItem {
4646

4747
// Enhanced search features
4848
keywords?: string[];
49-
value?: string;
5049
forceMount?: boolean;
5150

5251
// Standard Menu item props inherited
@@ -186,11 +185,6 @@ function CommandMenuBase<T extends object>(
186185
);
187186
}
188187

189-
// Check custom value if available
190-
if (item?.value && typeof item.value === 'string') {
191-
return textFilterFn(item.value, inputValue);
192-
}
193-
194188
return false;
195189
},
196190
[textFilterFn, shouldFilter],

0 commit comments

Comments
 (0)