Prime Components
Prime components adalah content di dalam schema: baris teks, icon, atau gambar. Komponen ini tidak memiliki value, tidak memiliki field name, dan tidak mempersist apa pun. Gunakan Prime component ketika form perlu menyampaikan informasi. Menggunakan disabled field hanya untuk menampilkan kalimat akan menambahkan nama field dan validation rule pada sesuatu yang sebenarnya bukan input.
Contoh minimal
use Illuminate\Database\Eloquent\Model;
use PandaPanel\Forms\Components\TextInput;
use PandaPanel\Forms\FormSchema;
use PandaPanel\Forms\Prime\Text;
public static function form(FormSchema $schema): FormSchema
{
return $schema->schema([
Text::make(static fn (?Model $record): string => $record === null
? 'This account will be created immediately.'
: 'Editing '.$record->getAttribute('name')),
TextInput::make('name')->required(),
]);
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
Ada tiga Prime component, semuanya berada di namespace PandaPanel\Forms\Prime.
Text
use Illuminate\Database\Eloquent\Model;
use PandaPanel\Forms\Prime\Text;
use PandaPanel\Tables\Enums\BadgeColor;
Text::make('Changes take effect immediately.')
->color(BadgeColor::Warning)
->icon('triangle-alert')
->small();
Text::make(static fn (?Model $record): string => 'Last saved '.($record?->updated_at?->diffForHumans() ?? 'never'));2
3
4
5
6
7
8
9
10
| Method | Signature | Default |
|---|---|---|
make() | static make(string|Closure(?Model): string $content): self | |
color() | color(BadgeColor $color): self | null |
icon() | icon(string $icon): self | null |
small() | small(bool $small = true): self | false |
Content dapat di-resolve berdasarkan record sehingga teks dapat menjelaskan sesuatu tentang record yang sedang diedit. Closure berjalan di server; hanya hasil string-nya yang melintasi wire.
Icon
use PandaPanel\Forms\Prime\Icon;
use PandaPanel\Tables\Enums\BadgeColor;
Icon::make('shield-check')
->color(BadgeColor::Success)
->label('This account uses two-factor authentication');2
3
4
5
6
| Method | Signature | Default |
|---|---|---|
make() | static make(string $icon): self | |
color() | color(BadgeColor $color): self | null |
label() | label(string $label): self | null |
Nama icon adalah registry key seperti icon lainnya di Panel. Schema tidak dapat meminta browser merender icon yang tidak pernah masuk build. label() menjadi accessible name dan juga dirender di samping icon. Icon tanpa label tidak memberikan informasi tekstual apa pun kepada pembaca atau assistive technology.
Image
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use PandaPanel\Forms\Prime\Image;
Image::make(static fn (?Model $record): ?string => $record === null
? null
: Storage::disk('public')->url((string) $record->getAttribute('avatar')))
->alt('Current avatar')
->width(96)
->rounded();2
3
4
5
6
7
8
9
10
| Method | Signature | Default |
|---|---|---|
make() | static make(string|Closure(?Model): ?string $url): self | |
alt() | alt(string $alt): self | '' |
width() | width(int $pixels): self | null, minimum 1 |
rounded() | rounded(bool $rounded = true): self | false |
URL dibuat di server, termasuk ketika berasal dari Closure yang membaca record. Browser tidak membangun URL dari identifier sendiri. URL yang menghasilkan empty string atau non-string diserialisasi sebagai null, sehingga frontend tidak merender apa pun daripada menampilkan broken image.
BadgeColor
PandaPanel\Tables\Enums\BadgeColor digunakan kembali agar framework tidak memiliki dua vocabulary warna berbeda. Status menggunakan color yang sama di mana pun tampil: Neutral, Success, Warning, Danger, Info. Ini merupakan closed set karena frontend memetakan setiap case ke literal Tailwind class.
Data yang dikirim ke frontend
| Class | component | Keys |
|---|---|---|
Text | prime-text | content, color, icon, small |
Icon | prime-icon | icon, color, label |
Image | prime-image | url, alt, width, rounded |
Ketiganya mengimplementasikan fields(): array sebagai []. Itulah yang membuatnya benar-benar content: tidak menambahkan validation, tidak ikut hydration, dan tidak ikut write.
Text::make('Hello')->fields(); // []
Icon::make('check')->fields(); // []
Image::make('/logo.png')->fields(); // []2
3
Lokasi Prime component dapat ditempatkan
Prime component dapat diletakkan di mana pun FormComponent dapat berada: top-level schema, Section, Grid, Tab, Step, Callout, atau CustomComponent.
use PandaPanel\Forms\Components\TextInput;
use PandaPanel\Forms\Layouts\Section;
use PandaPanel\Forms\Prime\Text;
Section::make('Billing')->schema([
Text::make('Invoices are sent on the first of the month.')->small(),
TextInput::make('billing_email')->email(),
]);2
3
4
5
6
7
8
Record yang digunakan untuk me-resolve content adalah record yang dipakai container ketika diserialisasi. Karena itu Prime component di dalam Relationship menerima related record, bukan owner record.
Prime components dibanding Callout
Keduanya dapat menampilkan informasi, tetapi tujuan masing-masing berbeda:
| Komponen | Digunakan untuk |
|---|---|
Prime\Text | Satu kalimat yang mengikuti flow form |
Callout | Catatan dengan frame, tone, heading, dan opsional field yang berkaitan dengannya |
EmptyState | Bagian yang tidak memiliki content dan menjelaskan alasannya |
Callout dan EmptyState adalah layout. Lihat Form layouts.
Catatan
- Prime component tidak memiliki
columnSpan(). Span dimiliki field. Prime component mengikuti posisi flow yang diberikan layout. - Prime component tidak dapat di-hide berdasarkan Page menggunakan
hiddenOn(). Jika perlu conditional content, bangun komponen tersebut secara kondisional atau masukkan ke container yang dibangun secara kondisional. - Closure berjalan pada setiap serialization, termasuk setiap schema rebuild dari endpoint
form-state. Jaga logic-nya tetap murah. - Di dalam item schema Repeater, record bernilai
null. Repeater item adalah plain map, bukan Eloquent model. Prime component yang bergantung pada record akan menggunakan branchnull. - Nama icon yang tidak ada di registry tidak merender apa pun. Pada development browser console memberikan warning. Jalankan
php artisan panel:iconssetelah mendeklarasikan icon baru. - Content di-escape sebagai text. Prime component bukan mekanisme untuk merender arbitrary HTML. Untuk formatted stored content, gunakan value Rich Editor lalu render sendiri di Page application.