CommandPalette
class CommandPalette extends BeartropyComponent
CommandPalette component.
A searchable command palette for navigation and actions.
Opens via Cmd+K / Ctrl+K or click trigger; renders a modal overlay
via x-teleport with Alpine.js keyboard navigation (arrow keys, tab, enter).
Supports loading items from a PHP array or a JSON file in storage/app. Items are cached per-user with permission/role filtering via Spatie Permissions.
Action types: route:name, url:path, absolute/relative URLs, dispatch:event, js:code.
Traits
Trait HasPresets.
Trait HasErrorBag.
Properties
| string|null | $size | Component size (md, lg, etc.) used for preset resolution. |
from BeartropyComponent |
| array | $bt_cp_data | ||
| string|null | $color | Component color. |
|
| array|null | $items | Items definition array. |
|
| string|null | $source | Legacy source path (unused). |
|
| string|null | $src | JSON source path in storage/app. |
|
| bool | $allowGuests | Allow guests to view items. |
Methods
Compute component presets based on context.
No description
No description
No description
No description
No description
No description
No description
No description
No description
Determine the error state for a specific field.
Analyze wire:model attributes to determine binding state.
Resolve the size preset for the component.
Create a new CommandPalette component instance.
Get the view / contents that represent the component.
Build cache key parts.
Resolve items from array or JSON file.
Read JSON file from storage.
Normalize items to ensure all keys exist.
Filter items by permissions (Spatie).
Remove 'permission' key before sending to client.
Details
in
HasPresets at line 21
array
getComponentPresets(string|null $componentName = null, ComponentAttributeBag|null $attributes = null)
Compute component presets based on context.
in
HasPresets at line 59
protected array
loadPresets(string $componentName)
No description
in
HasPresets at line 73
protected array
loadComponentDefaults(string $componentName)
No description
in
HasPresets at line 88
protected bool
detectHasVariants(array $colors)
No description
in
HasPresets at line 116
protected array
computeSupports(array $sizes, array $colorsArray, array $defaults, array $magicProps)
No description
in
HasPresets at line 137
protected array
resolveSize(array $supports, array $sizes, array $defaults, array $magicProps)
No description
in
HasPresets at line 174
protected array
resolveVariant(array $supports, array $colorsArray, array $componentPresets, array $defaults, array $magicProps, bool $hasVariants)
No description
in
HasPresets at line 223
protected array
resolveColor(array $supports, array $colorsArray, array $componentPresets, array $defaults, array $magicProps, string|null $variant, bool $hasVariants)
No description
in
HasPresets at line 293
protected array
resolveFill(array $supports, array $attributes, array $defaults)
No description
in
HasPresets at line 338
protected string
buildCacheKey(string $component, array $supports, string|null $size, string|null $variant, string|null $color, bool $shouldFill)
No description
in
HasPresets at line 349
protected void
syncInstanceProps(array $supports, string|null $size, string|null $variant, string|null $color)
No description
in
HasPresets at line 365
protected array
buildPresetNames(array $supports, string|null $size, string|null $variant, string|null $color, bool $shouldFill, string $sizeOrigin, string $variantOrigin, string $colorOrigin, string $fillOrigin)
No description
in
HasPresets at line 384
protected void
debugWarnings(array $supports, array $sizePreset, array $colorPreset, string $componentName, string|null $variant, string|null $color)
No description
in
HasErrorBag at line 24
array
getErrorState(ComponentAttributeBag|null $attributes = null, ViewErrorBag|MessageBag|null $errors = null, string|null $error = null)
Determine the error state for a specific field.
Checks both the session error bag and specific error attributes.
Looks up errors by wire:model value or name attribute.
in
BeartropyComponent at line 33
array
getWireModelState(ComponentAttributeBag|null $attributes = null)
Analyze wire:model attributes to determine binding state.
Detects if wire:model is present and if it uses dot notation (e.g., user.name).
in
BeartropyComponent at line 64
array
getSizePreset(string|null $componentName = null, array|ComponentAttributeBag|null $attributes = null, string $defaultSize = 'md')
Resolve the size preset for the component.
Checks:
- Explicit
$this->size. - Magic attributes (e.g.,
<x-button sm />). - Default size.
at line 58
__construct(string|null $color = null, array|null $items = null, string|null $source = null, string|null $src = null, bool $allowGuests = false)
Create a new CommandPalette component instance.
at line 74
View
render()
Get the view / contents that represent the component.
Calculates cache key based on user permissions and content version. Caches the resulting filtered items for performance.
at line 98
protected array
cacheKeyParts()
Build cache key parts.
- userKey: id + hash of roles/permissions (or "guest")
- version: file modification time (if src) or array hash (if items)
at line 133
protected array
resolveItems()
Resolve items from array or JSON file.
at line 155
protected array
readJsonFromStorage(string $path)
Read JSON file from storage.
at line 178
protected array
normalize(array $items)
Normalize items to ensure all keys exist.
at line 204
protected array
filterByPermissions(array $items)
Filter items by permissions (Spatie).
- Guest: if $allowGuests => all; otherwise only items without 'permission'/'roles'.
- Admin: all (if config admin_roles matches).
- User: checks 'permission' (can) and 'roles' (hasAnyRole).
at line 282
protected array
stripPermissions(array $items)
Remove 'permission' key before sending to client.