انتقل إلى المحتوى
الأدلة
التنقل
التنبيهات
الطبقات العائمة
التخطيط
عرض البيانات
النماذج
.md

التنقل

command

لوحة أوامر مبنية على عنصر dialog الأصلي: تُفتح بـ Cmd/Ctrl+K، وتصفّي العناصر المجمّعة أثناء الكتابة، وتنتقل إلى الروابط أو تطلق حدث command-select.

اقتراحات
التقويم
البحث عن رمز تعبيري
الآلة الحاسبة
الإعدادات
الملف الشخصي ⌘P
الفوترة ⌘B
الإعدادات ⌘S
الصفحات
المكونات

اضغط ⌘K أو انقر على الزر.

التثبيت

php artisan ui:add command

الاستخدام

@php
    $commands = [
        'Pages' => [
            ['label' => 'Profile', 'href' => '/profile', 'shortcut' => '⌘P'],
            ['label' => 'Billing', 'href' => '/billing'],
        ],
        'Actions' => [
            ['label' => 'New invoice', 'value' => 'new-invoice'],
            ['label' => 'Log out', 'value' => 'logout'],
        ],
    ];
@endphp

<x-ui.command :groups="$commands" />

{{-- Your own trigger, a different shortcut (empty disables it) --}}
<x-ui.command :groups="$commands" shortcut="j">
    <x-slot:trigger>
        <x-ui.button variant="outline">Open palette</x-ui.button>
    </x-slot:trigger>
</x-ui.command>

<script>
    // Items with a value dispatch command-select; it bubbles to window.
    window.addEventListener('command-select', (event) => {
        const { value, label } = event.detail;
        if (value === 'new-invoice') location.href = '/invoices/create';
    });
</script>

{{-- Livewire: listen with Alpine and call the component,
     e.g. x-on:command-select.window="$wire.run($event.detail.value)"
     on any element, or in a script block:
     window.addEventListener('command-select', e => $wire.run(e.detail.value)) --}}

مرّر :groups بالشكل ['Heading' => [['label' => ..., 'href' => ...], ['label' => ..., 'value' => ...]]]؛ العناصر ذات href تنتقل إلى الرابط، والعناصر ذات value تطلق حدث command-select متصاعدًا (التفاصيل { value, label }) يصل إلى window. تربط shortcut (الافتراضي k، اتركها فارغة للتعطيل) الاختصار Cmd/Ctrl+حرف، ويستبدل المنفذ الاختياري trigger زر البحث الافتراضي، وتحدد placeholder وsearch-placeholder وempty وlabel النصوص.

الخصائص

كل خاصية مع قيمتها الافتراضية. مرّر أيًّا منها كسمة، واستخدم : لربط قيمة PHP.

@props([
    'groups' => [],
    'shortcut' => 'k',
    'placeholder' => 'Search...',
    'searchPlaceholder' => 'Type a command or search...',
    'empty' => 'No results found.',
    'label' => 'Command palette',
])