Biji UI

Command

A searchable command palette for navigating and executing actions via keyboard or mouse.

New File
Open File
Save File
Cut
Copy
Paste (disabled)

Installation

biji-ui = { version = "0.5.0", features = ["command"] }

Usage

use leptos::prelude::*;
use biji_ui::components::command;

#[component]
pub fn MyCommand() -> impl IntoView {
    view! {
        <command::Root class="overflow-hidden w-full max-w-sm rounded-lg border shadow-md border-border">
            <command::Input
                placeholder="Search..."
                class="py-2 px-3 w-full text-sm border-b outline-none border-border bg-background"
            />
            <command::List class="overflow-y-auto p-1 max-h-64">
                <command::Empty>
                    <div class="py-6 text-sm text-center text-muted-foreground">
                        "No results found."
                    </div>
                </command::Empty>
                <command::Group label="Actions" label_class="px-2 py-1 text-xs font-semibold text-muted-foreground">
                    <command::Item
                        value="new-file"
                        class="flex items-center py-1.5 px-2 text-sm rounded-sm cursor-pointer outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50 data-[disabled]:pointer-events-none"
                        on_select={Callback::new(|val| leptos::logging::log!("selected: {val}"))}
                    >
                        "New File"
                    </command::Item>
                    <command::Item
                        value="new-folder"
                        class="flex items-center py-1.5 px-2 text-sm rounded-sm cursor-pointer outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground"
                    >
                        "New Folder"
                    </command::Item>
                </command::Group>
            </command::List>
        </command::Root>
    }
}

Text Highlighting

Use command::HighlightedText inside an item to automatically highlight the portion of the label that matches the current search query.

Accordion
Alert Dialog
Calendar
Checkbox
Collapsible
Dialog
Popover
Select
Tabs
Tooltip
use leptos::prelude::*;
use biji_ui::components::command;

#[component]
pub fn MyHighlightedCommand() -> impl IntoView {
    view! {
        <command::Root class="overflow-hidden w-full max-w-sm rounded-lg border shadow-md border-border">
            <command::Input
                placeholder="Search..."
                class="py-2 px-3 w-full text-sm border-b outline-none border-border bg-background"
            />
            <command::List class="overflow-y-auto p-1 max-h-64">
                <command::Empty>
                    <div class="py-6 text-sm text-center text-muted-foreground">
                        "No results found."
                    </div>
                </command::Empty>
                <command::Item
                    value="accordion"
                    class="flex items-center py-1.5 px-2 text-sm rounded-sm cursor-pointer outline-none data-[highlighted]:bg-accent"
                >
                    <command::HighlightedText
                        label="Accordion"
                        highlight_class="bg-yellow-200/80 dark:bg-yellow-500/30 rounded"
                    />
                </command::Item>
                <command::Item
                    value="dialog"
                    class="flex items-center py-1.5 px-2 text-sm rounded-sm cursor-pointer outline-none data-[highlighted]:bg-accent"
                >
                    <command::HighlightedText
                        label="Dialog"
                        highlight_class="bg-yellow-200/80 dark:bg-yellow-500/30 rounded"
                    />
                </command::Item>
            </command::List>
        </command::Root>
    }
}

API Reference

Root

NameTypeDefaultDescription
classString""CSS class applied to the root wrapper element.

Input

NameTypeDefaultDescription
classString""CSS class applied to the search input element.
placeholderString""Placeholder text shown when the input is empty.

List

NameTypeDefaultDescription
classString""CSS class applied to the list container element.

Group

NameTypeDefaultDescription
classString""CSS class applied to the group container element.
labelOption<String>NoneOptional heading text rendered above the group items.
label_classString""CSS class applied to the group label element.

Item

NameTypeDefaultDescription
valueString Unique string value identifying this item. Also used as the default label for filtering.
labelOption<String>NoneOverride the text used for filtering. Defaults to value when not provided.
classString""CSS class applied to the item element.
disabledboolfalseWhen true, the item is excluded from navigation and cannot be selected.
on_selectOption<Callback<String>>NoneCallback fired with the item's value when it is selected via click or Enter.

HighlightedText

NameTypeDefaultDescription
labelString The full text string to display. The matched portion is wrapped in a highlighted span.
highlight_classString""CSS class applied to the span wrapping the matched substring.

Data Attributes

AttributeDescription
data-highlightedPresent on Item when it is the currently focused/highlighted item.
data-disabledPresent on Item when the item is disabled.

Keyboard Navigation

KeyDescription
ArrowDownMoves focus to the next visible item, wrapping to the first.
ArrowUpMoves focus to the previous visible item, wrapping to the last.
HomeMoves focus to the first visible item.
EndMoves focus to the last visible item.
EnterSelects the focused item and fires on_select.