PHP code example of syriable / filament-choice-fields

1. Go to this page and download the library: Download syriable/filament-choice-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

syriable / filament-choice-fields example snippets


use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxList;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxStackedCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\CheckboxTable;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioList;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioStackedCard;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioTable;

CheckboxList::make('delivery_type')
    ->searchable()
    ->bulkToggleable()
    ->options([
        'standard' => 'Standard Delivery',
        'express' => 'Express Delivery',
        'overnight' => 'Overnight Delivery',
        'same_day' => 'Same Day Delivery',
    ])
    ->descriptions([
        'standard' => 'Delivery within 5-7 business days',
        'express' => 'Delivery within 2-3 business days',
        'overnight' => 'Next day delivery available',
        'same_day' => 'Delivery on the same day',
    ])
    ->extras([
        'standard' => '$5.00 flat rate',
        'express' => '$10.00 flat rate',
        'overnight' => '$20.00 flat rate',
        'same_day' => '$25.00 flat rate',
    ]);

CheckboxCard::make('delivery_type')
    ->searchable()
    ->bulkToggleable()
    ->options([
        'standard' => 'Standard Delivery',
        'express' => 'Express Delivery',
        'overnight' => 'Overnight Delivery',
    ])
    ->descriptions([
        'standard' => 'Delivery within 5-7 business days',
        'express' => 'Delivery within 2-3 business days',
        'overnight' => 'Next day delivery available',
    ])
    ->extras([
        'standard' => '$5.00 flat rate',
        'express' => '$10.00 flat rate',
        'overnight' => '$20.00 flat rate',
    ]);

CheckboxStackedCard::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->searchable()
    ->bulkToggleable();

CheckboxTable::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->searchable()
    ->bulkToggleable();

RadioList::make('delivery_type')
    ->options(DeliveryTypeEnum::class);

RadioCard::make('plan')
    ->options([
        'hobby' => 'Hobby',
        'pro' => 'Pro',
    ])
    ->descriptions([
        'hobby' => 'For side projects',
        'pro' => 'For teams',
    ])
    ->extras([
        'hobby' => '$9/mo',
        'pro' => '$29/mo',
    ]);

RadioStackedCard::make('delivery_type')
    ->options(DeliveryTypeEnum::class);

RadioTable::make('delivery_type')
    ->options(DeliveryTypeEnum::class);

use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\SingleCheckboxCard;

SingleCheckboxCard::make('terms')
    ->label('Accept terms & conditions')
    ->description('You agree to our privacy policy and terms of service')
    ->icon('heroicon-o-shield-check');

SingleCheckboxCard::make('newsletter')
    ->label('Subscribe to the newsletter')
    ->description('Get product updates once a month')
    ->selectedDescription('You will receive our next issue')
    ->badge('Recommended')
    ->badgeColor('success')
    ->color(\Filament\Support\Colors\Color::Emerald)
    ->hiddenInputs();

use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\SingleCheckboxList;

SingleCheckboxList::make('terms')
    ->label('Accept terms & conditions')
    ->description('You agree to our privacy policy and terms of service')
    ->icon('heroicon-o-shield-check');

CheckboxList::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->searchable()
    ->searchPrompt('Search delivery types...')
    ->noSearchResultsMessage('No delivery types found.');

CheckboxList::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->bulkToggleable();

CheckboxList::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->disableOptionWhen(fn (string $value): bool => $value === 'premium');



declare(strict_types=1);

namespace App\Enums;

use Filament\Support\Contracts\HasDescription;
use Filament\Support\Contracts\HasLabel;

enum DeliveryTypeEnum: string implements HasDescription, HasLabel
{
    case Standard = 'standard';
    case Express = 'express';
    case Overnight = 'overnight';
    case SameDay = 'same_day';

    public function getLabel(): string
    {
        return match ($this) {
            self::Standard => __('Standard Delivery'),
            self::Express => __('Express Delivery'),
            self::Overnight => __('Overnight Delivery'),
            self::SameDay => __('Same Day Delivery'),
        };
    }

    public function getDescription(): string
    {
        return match ($this) {
            self::Standard => __('Delivery within 5-7 business days'),
            self::Express => __('Delivery within 2-3 business days'),
            self::Overnight => __('Next day delivery available'),
            self::SameDay => __('Delivery on the same day'),
        };
    }
}

use App\Enums\DeliveryTypeEnum;
use Filament\Schemas\Schema;
use Syriable\Filament\Plugins\Translations\ChoiceFields\Filament\Forms\Components\RadioStackedCard;

public static function configure(Schema $schema): Schema
{
    return $schema
        ->columns(1)
        ->components([
            RadioStackedCard::make('delivery_type')
                ->options(DeliveryTypeEnum::class),
        ]);
}

use Filament\Support\Colors\Color;

CheckboxCard::make('plan')
    ->options(Plan::class)
    ->color(Color::Rose);

RadioList::make('language')
    ->options($languages)
    ->descriptions([
        'en' => 'Click to select this language',
    ])
    ->selectedDescriptions([
        'en' => 'Selected as the browser language',
    ]);

use Filament\Support\Enums\IconPosition;

CheckboxList::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->icons([
        'standard' => 'heroicon-o-sparkles',
        'express' => 'heroicon-o-bolt',
        'overnight' => 'heroicon-o-moon',
        'same_day' => 'heroicon-o-clock',
    ])
    ->iconPosition(IconPosition::After);

CheckboxList::make('language')
    ->options($languages)
    ->optionHasIcon(fn (string $value): string => "flag-language-{$value}");

CheckboxList::make('language')
    ->options($languages)
    ->optionHasBadge(fn (string $value): string => $value);

CheckboxList::make('language')
    ->options($languages)
    ->optionHasBadge(fn (string $value): array => [
        'code' => $value,
        'used' => fn () => Locale::query()->where('code', $value)->exists()
            ? __('Already added')
            : null,
    ])
    ->optionBadgeColor(fn (string $value): array => [
        'used' => 'danger',
    ]);

CheckboxList::make('language')
    ->options($languages)
    ->searchable()
    ->maxHeight('20rem');

CheckboxCard::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->hiddenInputs();

RadioCard::make('delivery_type')
    ->options(DeliveryTypeEnum::class)
    ->hiddenInputIcon('heroicon-o-chevron-double-down')
    ->hiddenInputs();

use Illuminate\Support\HtmlString;

CheckboxCard::make('plan')
    ->options([
        'basic' => 'Basic',
        'pro' => 'Pro',
        'team' => 'Team',
    ])
    ->extras([
        // Escaped automatically.
        'basic' => 'Free',
        // Rendered as raw HTML because it is Htmlable.
        'pro' => str('<span class="font-bold text-primary-600">$29/mo</span>')->toHtmlString(),
        // Closures are evaluated per option.
        'team' => fn (): HtmlString => new HtmlString('<b>$99/mo</b>'),
    ]);
css
@source '../../../../vendor/syriable/filament-choice-fields/resources/**/*.blade.php';