Skip to content

Commit 0da8418

Browse files
committed
feat(CommandPalette): add new component * 4
1 parent f2e5c65 commit 0da8418

24 files changed

+623
-465
lines changed

.changeset/giant-drinks-love.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/serious-meals-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": minor
3+
---
4+
5+
Add CommandMenu component.

.cursor/rules/guidelines.mdc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
alwaysApply: true
33
---
44

5-
65
# Description
76

87
Package name: `@cube-dev/ui-kit`

src/components/actions/CommandPalette/CommandPalette.docs.mdx renamed to src/components/actions/CommandMenu/CommandMenu.docs.mdx

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Meta, Story, Controls } from '@storybook/blocks';
2-
import { CommandPalette } from './CommandPalette';
3-
import * as CommandPaletteStories from './CommandPalette.stories.tsx';
2+
import { CommandMenu } from './CommandMenu';
3+
import * as CommandMenuStories from './CommandMenu.stories';
44

5-
<Meta of={CommandPaletteStories} />
5+
<Meta of={CommandMenuStories} />
66

7-
# CommandPalette
7+
# CommandMenu
88

99
A searchable menu interface that combines the functionality of Menu and ListBox components. It provides a command-line-like experience for users to quickly find and execute actions through a searchable interface.
1010

@@ -20,17 +20,17 @@ A searchable menu interface that combines the functionality of Menu and ListBox
2020

2121
### Default Usage
2222

23-
<Story of={CommandPaletteStories.Default} />
23+
<Story of={CommandMenuStories.Default} />
2424

2525
## Props
2626

27-
<Controls of={CommandPaletteStories.Default} />
27+
<Controls of={CommandMenuStories.Default} />
2828

2929
## Styling
3030

3131
### Style Props
3232

33-
The CommandPalette component supports all standard style properties:
33+
The CommandMenu component supports all standard style properties:
3434

3535
- **Layout**: `width`, `height`, `padding`, `margin`
3636
- **Positioning**: `position`, `top`, `left`, `right`, `bottom`
@@ -41,7 +41,7 @@ The CommandPalette component supports all standard style properties:
4141

4242
### Sub-elements
4343

44-
The CommandPalette component has several sub-elements that can be styled:
44+
The CommandMenu component has several sub-elements that can be styled:
4545

4646
- `SearchWrapper` - Container for the search input area
4747
- `SearchInput` - The search input field specifically
@@ -56,7 +56,7 @@ Customizes the search input field specifically.
5656

5757
### Modifiers
5858

59-
The CommandPalette component supports the following modifiers:
59+
The CommandMenu component supports the following modifiers:
6060

6161
| Modifier | Type | Description |
6262
|----------|------|-------------|
@@ -66,7 +66,7 @@ The CommandPalette component supports the following modifiers:
6666

6767
### Keyboard Navigation
6868

69-
The CommandPalette component provides comprehensive keyboard support:
69+
The CommandMenu component provides comprehensive keyboard support:
7070

7171
- **Search Input Focus**: The search input is automatically focused when the palette opens
7272
- **Arrow Keys**: Navigate through filtered options while keeping search input focused
@@ -92,29 +92,29 @@ The CommandPalette component provides comprehensive keyboard support:
9292
### Basic Usage
9393

9494
```jsx
95-
<CommandPalette searchPlaceholder="Search commands...">
95+
<CommandMenu searchPlaceholder="Search commands...">
9696
<Menu.Item key="copy">Copy</Menu.Item>
9797
<Menu.Item key="paste">Paste</Menu.Item>
9898
<Menu.Item key="cut">Cut</Menu.Item>
99-
</CommandPalette>
99+
</CommandMenu>
100100
```
101101

102102
### With MenuTrigger
103103

104104
```jsx
105-
<CommandPalette.Trigger>
105+
<CommandMenu.Trigger>
106106
<Button>Open Commands</Button>
107-
<CommandPalette searchPlaceholder="Search commands...">
107+
<CommandMenu searchPlaceholder="Search commands...">
108108
<Menu.Item key="copy">Copy</Menu.Item>
109109
<Menu.Item key="paste">Paste</Menu.Item>
110-
</CommandPalette>
111-
</CommandPalette.Trigger>
110+
</CommandMenu>
111+
</CommandMenu.Trigger>
112112
```
113113

114114
### With Sections and Keywords
115115

116116
```jsx
117-
<CommandPalette searchPlaceholder="Search commands...">
117+
<CommandMenu searchPlaceholder="Search commands...">
118118
<Menu.Section title="Edit">
119119
<Menu.Item key="copy" keywords={["duplicate", "clone"]}>
120120
Copy
@@ -128,28 +128,28 @@ The CommandPalette component provides comprehensive keyboard support:
128128
Zoom In
129129
</Menu.Item>
130130
</Menu.Section>
131-
</CommandPalette>
131+
</CommandMenu>
132132
```
133133

134134
### Controlled Search
135135

136136
```jsx
137137
const [searchValue, setSearchValue] = useState('');
138138

139-
<CommandPalette
139+
<CommandMenu
140140
searchValue={searchValue}
141141
onSearchChange={setSearchValue}
142142
searchPlaceholder="Type to search..."
143143
>
144144
<Menu.Item key="action1">Action 1</Menu.Item>
145145
<Menu.Item key="action2">Action 2</Menu.Item>
146-
</CommandPalette>
146+
</CommandMenu>
147147
```
148148

149149
### With Loading State
150150

151151
```jsx
152-
<CommandPalette
152+
<CommandMenu
153153
isLoading={isLoading}
154154
searchPlaceholder="Search commands..."
155155
>
@@ -158,13 +158,13 @@ const [searchValue, setSearchValue] = useState('');
158158
{command.name}
159159
</Menu.Item>
160160
))}
161-
</CommandPalette>
161+
</CommandMenu>
162162
```
163163

164164
### Custom Filtering
165165

166166
```jsx
167-
<CommandPalette
167+
<CommandMenu
168168
filter={(textValue, inputValue) => {
169169
// Custom fuzzy search logic
170170
return textValue.toLowerCase().includes(inputValue.toLowerCase());
@@ -173,26 +173,26 @@ const [searchValue, setSearchValue] = useState('');
173173
>
174174
<Menu.Item key="action1">Action 1</Menu.Item>
175175
<Menu.Item key="action2">Action 2</Menu.Item>
176-
</CommandPalette>
176+
</CommandMenu>
177177
```
178178

179179
### Force Mount Items
180180

181181
```jsx
182-
<CommandPalette searchPlaceholder="Search commands...">
182+
<CommandMenu searchPlaceholder="Search commands...">
183183
<Menu.Item key="help" forceMount>
184184
Help (always visible)
185185
</Menu.Item>
186186
<Menu.Item key="copy">Copy</Menu.Item>
187187
<Menu.Item key="paste">Paste</Menu.Item>
188-
</CommandPalette>
188+
</CommandMenu>
189189
```
190190

191191
## Advanced Features
192192

193193
### Enhanced Search
194194

195-
The CommandPalette supports enhanced search capabilities:
195+
The CommandMenu supports enhanced search capabilities:
196196

197197
- **Keywords**: Items can include additional keywords for better discoverability
198198
- **Custom values**: Items can have custom search values separate from display text
@@ -204,16 +204,16 @@ The CommandPalette supports enhanced search capabilities:
204204
```jsx
205205
import { useDialogContainer } from '../../../hooks';
206206

207-
const CommandPaletteDialog = useDialogContainer(CommandPalette);
207+
const CommandMenuDialog = useDialogContainer(CommandMenu);
208208

209209
// Usage
210-
<CommandPaletteDialog
210+
<CommandMenuDialog
211211
isOpen={isOpen}
212212
onClose={() => setIsOpen(false)}
213213
searchPlaceholder="Search commands..."
214214
>
215215
<Menu.Item key="action1">Action 1</Menu.Item>
216-
</CommandPaletteDialog>
216+
</CommandMenuDialog>
217217
```
218218

219219
## Best Practices

src/components/actions/CommandPalette/CommandPalette.spec.md renamed to src/components/actions/CommandMenu/CommandMenu.spec.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# CommandPalette Component Specification
1+
# CommandMenu Component Specification
22

33
## Overview
44

5-
The CommandPalette component is a searchable menu interface that combines the functionality of Menu and ListBox components. It provides a command-line-like experience for users to quickly find and execute actions through a searchable interface.
5+
The CommandMenu component is a searchable menu interface that combines the functionality of Menu and ListBox components. It provides a command-line-like experience for users to quickly find and execute actions through a searchable interface.
66

77
## Component Features
88

@@ -18,7 +18,7 @@ The CommandPalette component is a searchable menu interface that combines the fu
1818
- **Enhanced search**: Keywords-based matching and custom value support
1919

2020
### Key Behaviors
21-
- When CommandPalette gains focus, the search input is automatically focused
21+
- When CommandMenu gains focus, the search input is automatically focused
2222
- Arrow keys navigate through filtered options while search input retains focus
2323
- Enter key selects the currently highlighted option
2424
- Escape key clears search or closes the palette
@@ -32,33 +32,33 @@ The CommandPalette component is a searchable menu interface that combines the fu
3232
## Required Files
3333

3434
### Core Component Files
35-
1. **CommandPalette.tsx** - Main component implementation
35+
1. **CommandMenu.tsx** - Main component implementation
3636
2. **styled.tsx** - Styled components using tasty
37-
3. **index.ts** - Export barrel (includes CommandPalette.Trigger alias)
37+
3. **index.ts** - Export barrel (includes CommandMenu.Trigger alias)
3838

3939
### Documentation & Testing
40-
4. **CommandPalette.docs.mdx** - Component documentation
41-
5. **CommandPalette.stories.tsx** - Storybook stories
42-
6. **CommandPalette.test.tsx** - Unit tests (10-15 comprehensive tests)
40+
4. **CommandMenu.docs.mdx** - Component documentation
41+
5. **CommandMenu.stories.tsx** - Storybook stories
42+
6. **CommandMenu.test.tsx** - Unit tests (10-15 comprehensive tests)
4343

4444
### Integration Files
4545
7. **Update src/components/actions/index.ts** - Export new components
4646
8. **Update src/index.ts** - Export new components
4747

4848
## Implementation Approach
4949

50-
The CommandPalette will **reuse the existing Menu component** and add search functionality on top. This approach ensures we inherit all Menu features (sections, descriptions, tooltips, hotkeys) while adding search-specific capabilities. The implementation will follow the React Aria command palette example pattern, wrapping Menu with search input and filtering logic.
50+
The CommandMenu will **reuse the existing Menu component** and add search functionality on top. This approach ensures we inherit all Menu features (sections, descriptions, tooltips, hotkeys) while adding search-specific capabilities. The implementation will follow the React Aria command palette example pattern, wrapping Menu with search input and filtering logic.
5151

5252
### Key Technical Insights
5353

54-
1. **Reuse Menu component**: CommandPalette will wrap the existing Menu component to inherit all features (sections, descriptions, tooltips, hotkeys)
54+
1. **Reuse Menu component**: CommandMenu will wrap the existing Menu component to inherit all features (sections, descriptions, tooltips, hotkeys)
5555
2. **Filter-based search**: Use React Stately's `filter` prop (like ListBox) to implement search functionality
5656
3. **Virtual focus pattern**: Follow ListBox's search pattern - search input stays focused while arrow keys navigate menu items
57-
4. **Reuse existing patterns**: Use `useDialogContainer(CommandPalette)` for programmatic usage - no need for a separate hook
57+
4. **Reuse existing patterns**: Use `useDialogContainer(CommandMenu)` for programmatic usage - no need for a separate hook
5858

5959
## Implementation Plan
6060

61-
### Phase 1: Core Component Structure (CommandPalette.tsx)
61+
### Phase 1: Core Component Structure (CommandMenu.tsx)
6262
1. **Setup component interface**
6363
- Extend Menu props with search-specific additions
6464
- Add `searchPlaceholder`, `emptyLabel`, `filter` props
@@ -92,9 +92,9 @@ The CommandPalette will **reuse the existing Menu component** and add search fun
9292
- Empty state when no results
9393

9494
### Phase 2: MenuTrigger Integration and Alias
95-
1. **Create CommandPalette.Trigger alias**
96-
- Export MenuTrigger as CommandPalette.Trigger in index.ts
97-
- Ensure CommandPalette works seamlessly with MenuTrigger
95+
1. **Create CommandMenu.Trigger alias**
96+
- Export MenuTrigger as CommandMenu.Trigger in index.ts
97+
- Ensure CommandMenu works seamlessly with MenuTrigger
9898
- Test compatibility with existing MenuTrigger features
9999

100100
2. **Update documentation**
@@ -104,7 +104,7 @@ The CommandPalette will **reuse the existing Menu component** and add search fun
104104

105105
### Phase 3: Styling (styled.tsx)
106106
1. **Create styled components using tasty**
107-
- CommandPaletteWrapper: Main container
107+
- CommandMenuWrapper: Main container
108108
- SearchSection: Search input area
109109
- LoadingSection: Loading indicator area
110110
- ContentSection: Options list area
@@ -117,7 +117,7 @@ The CommandPalette will **reuse the existing Menu component** and add search fun
117117
- Proper spacing and typography
118118
- Theme integration
119119

120-
### Phase 4: Documentation (CommandPalette.docs.mdx)
120+
### Phase 4: Documentation (CommandMenu.docs.mdx)
121121
1. **Follow documentation guidelines**
122122
- Component overview and when to use
123123
- Complete props documentation
@@ -128,19 +128,19 @@ The CommandPalette will **reuse the existing Menu component** and add search fun
128128
2. **Include comprehensive examples**
129129
- Basic usage
130130
- With header/footer
131-
- Programmatic usage with `useDialogContainer(CommandPalette)`
132-
- With MenuTrigger (using CommandPalette.Trigger alias)
131+
- Programmatic usage with `useDialogContainer(CommandMenu)`
132+
- With MenuTrigger (using CommandMenu.Trigger alias)
133133
- Custom filtering and keywords
134134
- Multiple selection
135135
- Loading states
136136
- Force mount items
137137

138-
### Phase 5: Stories (CommandPalette.stories.tsx)
138+
### Phase 5: Stories (CommandMenu.stories.tsx)
139139
1. **Create comprehensive stories**
140140
- Default usage
141141
- With header and footer
142-
- Programmatic usage with `useDialogContainer(CommandPalette)`
143-
- With MenuTrigger (CommandPalette.Trigger)
142+
- Programmatic usage with `useDialogContainer(CommandMenu)`
143+
- With MenuTrigger (CommandMenu.Trigger)
144144
- Custom filtering and keywords
145145
- Loading states
146146
- Empty states
@@ -152,7 +152,7 @@ The CommandPalette will **reuse the existing Menu component** and add search fun
152152
- Demonstrate keyboard navigation
153153
- Show filtering behavior
154154

155-
### Phase 6: Testing (CommandPalette.test.tsx)
155+
### Phase 6: Testing (CommandMenu.test.tsx)
156156
1. **Functional tests (10-15 tests)**
157157
- Basic rendering and props
158158
- Search functionality and filtering
@@ -181,7 +181,7 @@ The CommandPalette will **reuse the existing Menu component** and add search fun
181181

182182
### Props Interface
183183
```typescript
184-
interface CommandPaletteProps<T> extends CubeMenuProps<T> {
184+
interface CommandMenuProps<T> extends CubeMenuProps<T> {
185185
// Search-specific props
186186
searchPlaceholder?: string;
187187
searchValue?: string;
@@ -202,7 +202,7 @@ interface CommandPaletteProps<T> extends CubeMenuProps<T> {
202202
// - All React Aria menu props (isDisabled, disabledKeys, etc.)
203203
}
204204

205-
interface CommandPaletteItem {
205+
interface CommandMenuItem {
206206
// Standard item props
207207
id: string;
208208
textValue: string;
@@ -241,7 +241,7 @@ interface CommandPaletteItem {
241241
## Integration Points
242242

243243
### With Menu Component
244-
- **Direct reuse**: CommandPalette wraps Menu component completely
244+
- **Direct reuse**: CommandMenu wraps Menu component completely
245245
- **Inherit all features**: Sections, descriptions, tooltips, hotkeys, selection icons
246246
- **Consistent API**: All Menu props work the same way
247247
- **Styling compatibility**: All Menu styling props are supported

0 commit comments

Comments
 (0)