Skip to content

Commit

Permalink
Merge branch '3.x' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed May 16, 2024
2 parents 8343a99 + e8190c9 commit 8859516
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/forms/docs/03-fields/01-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ TextInput::make('categories')
->extraInputAttributes(['width' => 200])
```

You can also pass extra HTML attributes to the field wrapper which surrounds the label, entry, and any other text:

```php
use Filament\Forms\Components\TextInput;

TextInput::make('categories')
->extraFieldWrapperAttributes(['class' => 'components-locked'])
```

## Disabling a field

You may disable a field to prevent it from being edited by the user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@
$hasError = filled($statePath) && ($errors->has($statePath) || ($hasNestedRecursiveValidationRules && $errors->has("{$statePath}.*")));
@endphp

<div data-field-wrapper {{ $attributes->class(['fi-fo-field-wrp']) }}>
<div
data-field-wrapper
{{
$attributes
->merge($field?->getExtraFieldWrapperAttributes() ?? [])
->class(['fi-fo-field-wrp'])
}}
>
@if ($label && $labelSrOnly)
<label for="{{ $id }}" class="sr-only">
{{ $label }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Filament\Forms\Components\Concerns;

use Closure;
use Illuminate\View\ComponentAttributeBag;

trait HasExtraFieldWrapperAttributes
{
/**
* @var array<array<mixed> | Closure>
*/
protected array $extraFieldWrapperAttributes = [];

/**
* @param array<mixed> | Closure $attributes
*/
public function extraFieldWrapperAttributes(array | Closure $attributes, bool $merge = false): static
{
if ($merge) {
$this->extraFieldWrapperAttributes[] = $attributes;
} else {
$this->extraFieldWrapperAttributes = [$attributes];
}

return $this;
}

/**
* @return array<mixed>
*/
public function getExtraFieldWrapperAttributes(): array
{
$temporaryAttributeBag = new ComponentAttributeBag();

foreach ($this->extraFieldWrapperAttributes as $extraFieldWrapperAttributes) {
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraFieldWrapperAttributes));
}

return $temporaryAttributeBag->getAttributes();
}

public function getExtraFieldWrapperAttributesBag(): ComponentAttributeBag
{
return new ComponentAttributeBag($this->getExtraFieldWrapperAttributes());
}
}
9 changes: 9 additions & 0 deletions packages/infolists/docs/03-entries/01-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ TextEntry::make('slug')

These get merged onto the outer `<div>` element of each entry in that entry.

You can also pass extra HTML attributes to the entry wrapper which surrounds the label, entry, and any other text:

```php
use Filament\Infolists\Components\TextEntry;

TextEntry::make('slug')
->extraFieldWrapperAttributes(['class' => 'entry-locked'])
```

## Global settings

If you wish to change the default behaviour of all entries globally, then you can call the static `configureUsing()` method inside a service provider's `boot()` method, to which you pass a Closure to modify the entries using. For example, if you wish to make all `TextEntry` components [`words(10)`](text#limiting-word-count), you can do it like so:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@
);
@endphp

<div {{ $attributes->class(['fi-in-entry-wrp']) }}>
<div
{{
$attributes
->merge($entry?->getExtraEntryWrapperAttributes() ?? [])
->class(['fi-in-entry-wrp'])
}}
>
@if ($label && $labelSrOnly)
<dt class="sr-only">
{{ $label }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Filament\Infolists\Components\Concerns;

use Closure;
use Illuminate\View\ComponentAttributeBag;

trait HasExtraEntryWrapperAttributes
{
/**
* @var array<array<mixed> | Closure>
*/
protected array $extraEntryWrapperAttributes = [];

/**
* @param array<mixed> | Closure $attributes
*/
public function extraEntryWrapperAttributes(array | Closure $attributes, bool $merge = false): static
{
if ($merge) {
$this->extraEntryWrapperAttributes[] = $attributes;
} else {
$this->extraEntryWrapperAttributes = [$attributes];
}

return $this;
}

/**
* @return array<mixed>
*/
public function getExtraEntryWrapperAttributes(): array
{
$temporaryAttributeBag = new ComponentAttributeBag();

foreach ($this->extraEntryWrapperAttributes as $extraEntryWrapperAttributes) {
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraEntryWrapperAttributes));
}

return $temporaryAttributeBag->getAttributes();
}

public function getExtraEntryWrapperAttributesBag(): ComponentAttributeBag
{
return new ComponentAttributeBag($this->getExtraEntryWrapperAttributes());
}
}

0 comments on commit 8859516

Please sign in to comment.