Command
Fast, composable, command menu for Angular.
import { Component } from '@angular/core';
import { BrnCommandImports } from '@spartan-ng/brain/command';
import { HlmCommandImports } from '@spartan-ng/ui-command-helm';
import { HlmIconDirective } from '@spartan-ng/ui-icon-helm';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
import { provideIcons } from '@ng-icons/core';
import {
lucideCalendar,
lucideWallet,
lucideSmile,
lucideCog,
lucideSearch,
lucideUser,
lucidePlus,
} from '@ng-icons/lucide';
@Component({
selector: 'spartan-command-preview',
standalone: true,
imports: [BrnCommandImports, HlmCommandImports, HlmIconDirective, HlmButtonDirective],
providers: [
provideIcons({ lucideSearch, lucideCalendar, lucideSmile, lucidePlus, lucideUser, lucideWallet, lucideCog }),
],
template: `
<hlm-command>
<hlm-command-search>
<ng-icon hlm name="lucideSearch" class="inline-flex" />
<input
type="text"
hlm-command-search-input
placeholder="Type a command or search..."
/>
</hlm-command-search>
<hlm-command-list>
<hlm-command-group>
<hlm-command-group-label>Suggestions</hlm-command-group-label>
<button hlm-command-item value="Calendar">
<ng-icon hlm name="lucideCalendar" hlmCommandIcon />
Calendar
</button>
<button hlm-command-item value="Search Emoji">
<ng-icon hlm name="lucideSmile" hlmCommandIcon />
Search Emoji
</button>
<button hlm-command-item value="Calculator">
<ng-icon hlm name="lucidePlus" hlmCommandIcon />
Calculator
</button>
</hlm-command-group>
<hlm-command-separator />
<hlm-command-group>
<hlm-command-group-label>Settings</hlm-command-group-label>
<button hlm-command-item value="Profile">
<ng-icon hlm name="lucideUser" hlmCommandIcon />
Profile
<hlm-command-shortcut>⌘P</hlm-command-shortcut>
</button>
<button hlm-command-item value="Billing">
<ng-icon hlm name="lucideWallet" hlmCommandIcon />
Billing
<hlm-command-shortcut>⌘B</hlm-command-shortcut>
</button>
<button hlm-command-item value="Settings">
<ng-icon hlm name="lucideCog" hlmCommandIcon />
Settings
<hlm-command-shortcut>⌘S</hlm-command-shortcut>
</button>
</hlm-command-group>
</hlm-command-list>
<!-- Empty state -->
<div *brnCommandEmpty hlmCommandEmpty>No results found.</div>
</hlm-command>
`,
})
export class CommandPreviewComponent {}
Installation
npx nx g @spartan-ng/cli:ui command
ng g @spartan-ng/cli:ui command
Usage
import { BrnCommandImports } from '@spartan-ng/brain/command';
import { HlmCommandImports } from '@spartan-ng/ui-command-helm';
<hlm-command>
<hlm-command-search>
<ng-icon hlm name="lucideSearch" />
<input
type="text"
hlm-command-search-input
placeholder="Type a command or search..."
/>
</hlm-command-search>
<hlm-command-list>
<hlm-command-group>
<hlm-command-group-label>Suggestions</hlm-command-group-label>
<button hlm-command-item value="Calendar">
<ng-icon hlm name="lucideCalendar" hlmCommandIcon />
Calendar
</button>
</hlm-command-group>
<hlm-command-separator />
<hlm-command-group>
<hlm-command-group-label>Settings</hlm-command-group-label>
<button hlm-command-item value="Profile">
<ng-icon hlm name="lucideUser" hlmCommandIcon />
Profile
<hlm-command-shortcut>⌘P</hlm-command-shortcut>
</button>
</hlm-command-group>
</hlm-command-list>
<!-- Empty state -->
<div *brnCommandEmpty hlmCommandEmpty>No results found.</div>
</hlm-command>
Examples
Dialog
Press ⌘ + K
Last command: none
Combobox
You can use the brn-command
component as a combobox. See the Combobox page for more information.