Dropdown
Example
import { Dropdown, IconButton } from '@i4o/catalystui'
import {
ExitIcon,
ExternalLinkIcon,
FileIcon,
GearIcon,
HamburgerMenuIcon,
InfoCircledIcon,
} from '@radix-ui/react-icons'
export default () => {
const dropdownItems = [
{
label: 'New',
icon: <FileIcon />,
submenu: [
{
label: 'File',
icon: <FileIcon />,
onClick: () => console.log('File'),
shortcut: 'Ctrl+N',
},
{
label: 'Folder',
icon: <FileIcon />,
onClick: () => console.log('Folder'),
shortcut: 'Ctrl+Shift+N',
},
],
type: 'submenu',
},
{
label: 'View Post',
icon: <ExternalLinkIcon />,
onClick: () => console.log('View Post'),
shortcut: 'Ctrl+Shift+V',
},
{
type: 'separator',
},
{
label: 'Settings',
icon: <GearIcon />,
onClick: () => console.log('Settings'),
shortcut: 'Ctrl+,',
},
{
type: 'separator',
},
{
label: 'About',
icon: <InfoCircledIcon />,
onClick: () => console.log('About'),
},
{
label: 'Exit',
icon: <ExitIcon />,
onClick: () => console.log('Logout'),
shortcut: 'Ctrl+Q',
},
]
return (
<Dropdown
align='start'
items={dropdownItems}
trigger={<IconButton icon={<HamburgerMenuIcon />} />}
/>
)
}
Props
Name | Type | Default | Description |
---|---|---|---|
align | 'start' | 'center' | 'end' | 'start' | The alignment of the dropdown menu. |
items | DropdownItem[] | [] | The items to display in the dropdown menu. |
trigger | ReactNode | null | The trigger element. |
DropdownItem
Name | Type | Default | Description |
---|---|---|---|
type | 'submenu' | 'separator' | 'item' | 'item' | Type of the dropdown menu item. |
label | string | ReactNode | '' | Label to display for the item. |
icon | ReactNode | - | Icon to display for the item. |
submenu | DropdownItem[] | [] | The items to display as the submenu for the item. |
link | string | - | URL to open on click when type is item . |
onSelect | () => void | - | Function to call when type is item . |
shortcut | string | - | Keyboard shortcut to display when type is item . Calling the onSelect function is not handled. User has to handle it on their own. |