default(fn (ToggleButtons $component): mixed => $component->isMultiple() ? [] : null); $this->afterStateHydrated(static function (ToggleButtons $component, $state): void { if (! $component->isMultiple()) { return; } if (is_array($state)) { return; } $component->state([]); }); } public function grouped(): static { return $this->view(static::GROUPED_VIEW); } public function boolean(?string $trueLabel = null, ?string $falseLabel = null): static { $this->options([ 1 => $trueLabel ?? __('filament-forms::components.toggle_buttons.boolean.true'), 0 => $falseLabel ?? __('filament-forms::components.toggle_buttons.boolean.false'), ]); $this->colors([ 1 => 'success', 0 => 'danger', ]); $this->icons([ 1 => FilamentIcon::resolve('forms::components.toggle-buttons.boolean.true') ?? 'heroicon-m-check', 0 => FilamentIcon::resolve('forms::components.toggle-buttons.boolean.false') ?? 'heroicon-m-x-mark', ]); return $this; } public function inline(bool | Closure $condition = true): static { $this->isInline = $condition; return $this; } public function isInline(): bool { return (bool) $this->evaluate($this->isInline); } public function hiddenButtonLabels(bool | Closure $condition = true): static { $this->areButtonLabelsHidden = $condition; return $this; } public function areButtonLabelsHidden(): bool { return (bool) $this->evaluate($this->areButtonLabelsHidden); } public function multiple(bool | Closure $condition = true): static { $this->isMultiple = $condition; return $this; } public function isMultiple(): bool { return (bool) $this->evaluate($this->isMultiple); } public function getDefaultState(): mixed { $state = parent::getDefaultState(); if (is_bool($state)) { return $state ? 1 : 0; } return $state; } }