Skip to content

Commit

Permalink
Merge branch '4.x' into tiptap-rich-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Feb 7, 2025
2 parents bd1249f + b61e3d3 commit 2e50e7d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/forms/docs/02-fields/18-toggle-buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ If you are using an enum for the options, you can use the [`HasIcon` interface](

<AutoScreenshot name="forms/fields/toggle-buttons/icons" alt="Toggle buttons with icons" version="4.x" />

If you want to display only icons, you can use `hiddenButtonLabels()` to hide the option labels.

## Boolean options

If you want a simple boolean toggle button group, with "Yes" and "No" options, you can use the `boolean()` method:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$isDisabled = $isDisabled();
$isMultiple = $isMultiple();
$statePath = $getStatePath();
$areButtonLabelsHidden = $areButtonLabelsHidden();
@endphp

<x-dynamic-component
Expand Down Expand Up @@ -52,6 +53,7 @@
:for="$inputId"
grouped
:icon="$getIcon($value)"
:label-sr-only="$areButtonLabelsHidden"
tag="label"
>
{{ $label }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$isInline = $isInline();
$isMultiple = $isMultiple();
$statePath = $getStatePath();
$areButtonLabelsHidden = $areButtonLabelsHidden();
@endphp

<x-dynamic-component
Expand Down Expand Up @@ -65,6 +66,7 @@
:disabled="$shouldOptionBeDisabled"
:for="$inputId"
:icon="$getIcon($value)"
:label-sr-only="$areButtonLabelsHidden"
tag="label"
>
{{ $label }}
Expand Down
14 changes: 14 additions & 0 deletions packages/forms/src/Components/ToggleButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ToggleButtons extends Field implements Contracts\CanDisableOptions

protected bool | Closure $isInline = false;

protected bool | Closure $areButtonLabelsHidden = false;

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -88,6 +90,18 @@ 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;
Expand Down
4 changes: 3 additions & 1 deletion packages/panels/src/Resources/Pages/EditRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ protected function fillFormWithDataAndCallHooks(Model $record, array $extraData
*/
public function refreshFormData(array $attributes): void
{
$this->data = [
$data = [
...$this->data,
...Arr::only($this->getRecord()->attributesToArray(), $attributes),
];

$this->form->fill($data);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/panels/src/Resources/Pages/ViewRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ protected function fillFormWithDataAndCallHooks(Model $record, array $extraData
*/
public function refreshFormData(array $attributes): void
{
$this->data = [
$data = [
...$this->data,
...Arr::only($this->getRecord()->attributesToArray(), $attributes),
];

$this->form->fill($data);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/panels/src/global_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
use Filament\FilamentManager;

if (! function_exists('filament')) {
/**
* @return ($plugin is null ? FilamentManager : Plugin)
*/
function filament(?string $plugin = null): FilamentManager | Plugin
{
/** @var FilamentManager $filament */
Expand Down

0 comments on commit 2e50e7d

Please sign in to comment.