Skip to content

List

ui list

Components

UiList

Display a list of items. The items will be automatically filtered based on the command bar search panel value.

Example

import { UiListItem, UiList, UiIcons } from '@altdot/extension';
const items: UiListItem[] = [
{
group: 'fruit',
title: 'Apple',
value: 'apple',
icon: <UiList.Icon icon={UiIcons.Wand} />
},
{
group: 'fruit',
title: 'Banana',
value: 'banana',
icon: <UiList.Icon icon={UiIcons.Wand} />
},
{
group: 'vegetable',
title: 'Carrot',
value: 'carrot',
icon: <UiList.Icon icon={UiIcons.Wand} />
},
{
group: 'vegetable',
title: 'Eggplant',
value: 'eggplant',
icon: <UiList.Icon icon={UiIcons.Wand} />
},
];
export default function Command() {
return (
<UiList items={items} />
);
}

Props

NameTypeDescription
itemsUiListItem[]The list items
search?stringItems search filter
selectedItem?stringItems search filter
shouldFilter?booleanWhether to filter the items
noDataSlot?React.ReactNodeElement to show when no items match the filter
disabledItemSelection?booleanDisable the item selection
onItemSelected?((value: string) => void)Fired when an item is selected
onSearchChanged?((value: string) => void)Fired when the search is changed
renderItem?((detail: UiListRenderItemDetail[], index: number) => React.ReactNode)Custom list item renderer
renderGroupHeader?((label: string, index: number) => React.ReactNode)Custom group header renderer

UiList.Item

Ui list item component.

Example

<UiList
items={items}
renderItem={({ item, ref, selected }) => (
<UiList.Item
{...item}
selected={selected}
ref={ref}
icon={<UiList.Icon icon={UiIcons.Wand} />}
/>
)}
/>

Props

NameTypeDescription
valuestringThe list item’s unique value
selected?booleanWhether the item is selected
title?string | React.ReactNodeThe list item’s title that will be displayed
actions?UiListItemAction[]The list item’s actions
subtitle?(string | React.ReactNode)Subtitle that will be displayed next to the title
icon`?(stringReact.ReactNode)`
description?(string | React.ReactNode)Shortcut description about the item
alias?(string | React.ReactNode)The list item’s alias
keywords?string[]Additional keywords for the item. It will be used when filtering the list items.
onSelected?(() => void)Will be fired when the item is selected
suffix?(string | React.ReactNode)The item’s suffix. Will be displayed on the item’s right side.

UiList.Icon

Icon wrapper for the ui list item.

Example

<UiList
items={items}
renderItem={({ item, ref, selected }) => (
<UiList.Item
{...item}
selected={selected}
ref={ref}
icon={<UiList.Icon icon={UiIcons.Wand} />}
/>
)}
/>

Props

NameTypeDescription
icon`stringReact.Element`

Types

UiListItem

The list item data.

interface UiListItem<T = any> {
value: string;
title: string;
metadata?: T;
alias?: string;
group?: string;
subtitle?: string;
keywords?: string[];
description?: string;
searchOnly?: boolean;
icon?: React.ReactNode;
onSelected?: () => void;
actions?: UiListItemAction[];
suffix?: string | React.ReactNode;
}
PropertyTypeDescription
valuestringThe list item’s unique value
titlestringThe list item’s title that will be displayed
actions?UiListItemAction[]The list item’s actions
subtitle?stringSubtitle that will be displayed next to the title
icon?React.ReactNodeThe list item’s icon that will be displayed
description?stringShortcut description about the item
metadata?anyThe list item’s metadata
alias?stringThe list item’s alias
keywords?string[]Additional keywords for the item. It will be used when filtering the list items.
searchOnly?booleanWhether the item will only be shown when filtering the items
onSelected?(() => void)Will be fired when the item is selected
suffix?(string | React.ReactNode)The item’s suffix. Will be displayed on the item’s right side.

UiListItemActionBase

Contains information about the list item.

interface UiListItemActionBase {
title: string;
value: string;
disabled?: boolean;
icon: React.ReactNode;
shortcut?: KeyboardShortcut;
color?: 'default' | 'primary' | 'destructive';
}
PropertyTypeDescription
valuestringThe action’s unique value
titlestringThe action’s title
icon?React.ReactNodeThe action’s icon
disabled?booleanWhether the item is disabled
color?('default' | 'primary' | 'destructive')The action’s color
shortcut?KeyboardShortcutThe action’s keyboard shortcut

UiListItemActionButton

List item action button type.

interface UiListItemActionButton extends UiListItemActionBase {
type: 'button';
onAction: () => void;
}
PropertyTypeDescription
typebuttonItem action type
onAction() => voidWill be fired when the action is selected
UiListItemActionBase

UiListItemActionMenu

List item action button type.

interface UiListItemActionMenu extends UiListItemActionBase {
type: 'menu';
items: UiListItemActionButton[];
}
PropertyTypeDescription
typebuttonItem action type
itemsUiListItemActionButton[]The action menu items
UiListItemActionBase

UiListItemAction

The list item action.

type UiListItemAction = UiListItemActionMenu | UiListItemActionButton;

UiListRenderItemDetail

The item detail when passing a function in the renderItem prop.

interface UiListRenderItemDetail {
item: UiListItem;
selected: boolean;
ref: React.Ref<HTMLDivElement>;
props: Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> & {
onSelected?: () => void;
};
}
PropertyTypeDescription
itemUiListItemThe list item
selectedbooleanWhether the item is selected
refReact.Ref<HTMLDivElement>The item’s ref prop
propsOmit<React.HTMLAttributes<HTMLDivElement>, 'children'> & { onSelected?: () => void }The item’s props

KeyboardShorcut

Keyboard shortcut.

interface KeyboardShortcut {
key: string;
mod1: KeyboardShortcutModifier;
mod2?: KeyboardShortcutModifier;
}
PropertyTypeDescription
keystringThe keyboard shortcut key
mod1KeyboardShortcutModifierThe keyboard shortcut modifier key
mod2?KeyboardShortcutModifierThe keyboard shortcut modifier key

KeyboardShortcutModifier

Keyboard shortcut modifier.

type KeyboardShortcutModifier = 'mod' | 'altKey' | 'metaKey' | 'ctrlKey' | 'shiftKey';