Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
331
vendor/filament/forms/docs/18-toggle-buttons.md
vendored
Normal file
331
vendor/filament/forms/docs/18-toggle-buttons.md
vendored
Normal file
|
|
@ -0,0 +1,331 @@
|
|||
---
|
||||
title: Toggle buttons
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import UtilityInjection from "@components/UtilityInjection.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
The toggle buttons input provides a group of buttons for selecting a single value, or multiple values, from a list of predefined options:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'scheduled' => 'Scheduled',
|
||||
'published' => 'Published'
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static array, the `options()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/simple" alt="Toggle buttons" version="5.x" />
|
||||
|
||||
## Changing the color of option buttons
|
||||
|
||||
You can change the [color](../styling/colors) of the option buttons using the `colors()` method. Each key in the array should correspond to an option value:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'scheduled' => 'Scheduled',
|
||||
'published' => 'Published'
|
||||
])
|
||||
->colors([
|
||||
'draft' => 'info',
|
||||
'scheduled' => 'warning',
|
||||
'published' => 'success',
|
||||
])
|
||||
```
|
||||
|
||||
If you are using an enum for the options, you can use the [`HasColor` interface](../advanced/enums#enum-colors) to define colors instead.
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static array, the `colors()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/colors" alt="Toggle buttons with different colors" version="5.x" />
|
||||
|
||||
## Adding icons to option buttons
|
||||
|
||||
You can add [icon](../styling/icons) to the option buttons using the `icons()` method. Each key in the array should correspond to an option value, and the value may be any valid [icon](../styling/icons):
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
ToggleButtons::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'scheduled' => 'Scheduled',
|
||||
'published' => 'Published'
|
||||
])
|
||||
->icons([
|
||||
'draft' => Heroicon::OutlinedPencil,
|
||||
'scheduled' => Heroicon::OutlinedClock,
|
||||
'published' => Heroicon::OutlinedCheckCircle,
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static array, the `icons()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
If you are using an enum for the options, you can use the [`HasIcon` interface](../advanced/enums#enum-icons) to define icons instead.
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/icons" alt="Toggle buttons with icons" version="5.x" />
|
||||
|
||||
If you want to display only icons, you can use `hiddenButtonLabels()` to hide the option labels.
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/hidden-labels" alt="Toggle buttons with hidden labels" version="5.x" />
|
||||
|
||||
## Adding tooltips to option buttons
|
||||
|
||||
You can add different tooltips to each option button using the `tooltips()` method.
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'scheduled' => 'Scheduled',
|
||||
'published' => 'Published',
|
||||
])
|
||||
->tooltips([
|
||||
'draft' => 'Set as a draft before publishing.',
|
||||
'scheduled' => 'Schedule publishing on a specific date.',
|
||||
'published' => 'Publish now',
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static array, the `tooltips()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/tooltips" alt="Toggle buttons with tooltips" version="5.x" />
|
||||
|
||||
## Boolean options
|
||||
|
||||
If you want a simple boolean toggle button group, with "Yes" and "No" options, you can use the `boolean()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean()
|
||||
```
|
||||
|
||||
The options will have [colors](#changing-the-color-of-option-buttons) and [icons](#adding-icons-to-option-buttons) set up automatically, but you can override these with `colors()` or `icons()`.
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/boolean" alt="Boolean toggle buttons" version="5.x" />
|
||||
|
||||
To customize the "Yes" label, you can use the `trueLabel` argument on the `boolean()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean(trueLabel: 'Absolutely!')
|
||||
```
|
||||
|
||||
To customize the "No" label, you can use the `falseLabel` argument on the `boolean()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean(falseLabel: 'Not at all!')
|
||||
```
|
||||
|
||||
## Positioning the options inline with each other
|
||||
|
||||
You may wish to display the buttons `inline()` with each other:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean()
|
||||
->inline()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/inline" alt="Inline toggle buttons" version="5.x" />
|
||||
|
||||
Optionally, you may pass a boolean value to control if the buttons should be inline or not:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean()
|
||||
->inline(FeatureFlag::active())
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static value, the `inline()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Grouping option buttons
|
||||
|
||||
You may wish to group option buttons together so they are more compact, using the `grouped()` method. This also makes them appear horizontally inline with each other:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean()
|
||||
->grouped()
|
||||
```
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/grouped" alt="Grouped toggle buttons" version="5.x" />
|
||||
|
||||
Optionally, you may pass a boolean value to control if the buttons should be grouped or not:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('feedback')
|
||||
->label('Like this post?')
|
||||
->boolean()
|
||||
->grouped(FeatureFlag::active())
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static value, the `grouped()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Selecting multiple buttons
|
||||
|
||||
The `multiple()` method on the `ToggleButtons` component allows you to select multiple values from the list of options:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('technologies')
|
||||
->multiple()
|
||||
->options([
|
||||
'tailwind' => 'Tailwind CSS',
|
||||
'alpine' => 'Alpine.js',
|
||||
'laravel' => 'Laravel',
|
||||
'livewire' => 'Laravel Livewire',
|
||||
])
|
||||
```
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/multiple" alt="Multiple toggle buttons selected" version="5.x" />
|
||||
|
||||
These options are returned in JSON format. If you're saving them using Eloquent, you should be sure to add an `array` [cast](https://laravel.com/docs/eloquent-mutators#array-and-json-casting) to the model property:
|
||||
|
||||
```php
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class App extends Model
|
||||
{
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'technologies' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Optionally, you may pass a boolean value to control if the buttons should allow multiple selections or not:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('technologies')
|
||||
->multiple(FeatureFlag::active())
|
||||
->options([
|
||||
'tailwind' => 'Tailwind CSS',
|
||||
'alpine' => 'Alpine.js',
|
||||
'laravel' => 'Laravel',
|
||||
'livewire' => 'Laravel Livewire',
|
||||
])
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static value, the `multiple()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
## Splitting options into columns
|
||||
|
||||
You may split options into columns by using the `columns()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('technologies')
|
||||
->options([
|
||||
// ...
|
||||
])
|
||||
->columns(2)
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static value, the `columns()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/columns" alt="Toggle buttons with 2 columns" version="5.x" />
|
||||
|
||||
This method accepts the same options as the `columns()` method of the [grid](../schemas/layouts#grid-system). This allows you to responsively customize the number of columns at various breakpoints.
|
||||
|
||||
### Setting the grid direction
|
||||
|
||||
By default, when you arrange buttons into columns, they will be listed in order vertically. If you'd like to list them horizontally, you may use the `gridDirection(GridDirection::Row)` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Support\Enums\GridDirection;
|
||||
|
||||
ToggleButtons::make('technologies')
|
||||
->options([
|
||||
// ...
|
||||
])
|
||||
->columns(2)
|
||||
->gridDirection(GridDirection::Row)
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x">As well as allowing a static value, the `gridDirection()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/rows" alt="Toggle buttons with 2 rows" version="5.x" />
|
||||
|
||||
## Disabling specific options
|
||||
|
||||
You can disable specific options using the `disableOptionWhen()` method. It accepts a closure, in which you can check if the option with a specific `$value` should be disabled:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'scheduled' => 'Scheduled',
|
||||
'published' => 'Published',
|
||||
])
|
||||
->disableOptionWhen(fn (string $value): bool => $value === 'published')
|
||||
```
|
||||
|
||||
<UtilityInjection set="formFields" version="5.x" extras="Option value;;mixed;;$value;;The value of the option to disable.||Option label;;string | Illuminate\Contracts\Support\Htmlable;;$label;;The label of the option to disable.">You can inject various utilities into the function as parameters.</UtilityInjection>
|
||||
|
||||
<AutoScreenshot name="forms/fields/toggle-buttons/disabled-option" alt="Toggle buttons with disabled option" version="5.x" />
|
||||
|
||||
If you want to retrieve the options that have not been disabled, e.g. for validation purposes, you can do so using `getEnabledOptions()`:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
|
||||
ToggleButtons::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'scheduled' => 'Scheduled',
|
||||
'published' => 'Published',
|
||||
])
|
||||
->disableOptionWhen(fn (string $value): bool => $value === 'published')
|
||||
->in(fn (ToggleButtons $component): array => array_keys($component->getEnabledOptions()))
|
||||
```
|
||||
|
||||
For more information about the `in()` function, please see the [Validation documentation](validation#in).
|
||||
Loading…
Add table
Add a link
Reference in a new issue