This commit is contained in:
Zep Fietje
2023-10-29 14:34:21 +01:00
parent 00e398fc98
commit 901a99f1ad
7 changed files with 11 additions and 24 deletions
+1 -1
View File
@@ -709,7 +709,7 @@ class TablesDemo extends Component implements HasForms, HasTable
return $this->filtersTable($table)
->filters([
Filter::make('dummy')
->indicators(fn () => [
->indicateUsing(fn () => [
Indicator::make('Posted by administrator')
->removeField('one'),
Indicator::make('Less than 1 year old')
+4 -4
View File
@@ -314,11 +314,11 @@ Filter::make('is_admin')
->indicator('Administrators')
```
If you are using a [custom filter form](#custom-filter-forms), you should use [`indicators()`](#custom-active-indicators) to display an active indicator.
If you are using a [custom filter form](#custom-filter-forms), you should use [`indicateUsing()`](#custom-active-indicators) to display an active indicator.
### Custom active indicators
Not all indicators are simple, so you may need to use `indicators()` to customize which indicators should be shown at any time.
Not all indicators are simple, so you may need to use `indicateUsing()` to customize which indicators should be shown at any time.
For example, if you have a custom date filter, you may create a custom indicator that formats the selected date:
@@ -329,7 +329,7 @@ use Filament\Tables\Filters\Filter;
Filter::make('created_at')
->form([DatePicker::make('date')])
// ...
->indicators(function (array $data): ?string {
->indicateUsing(function (array $data): ?string {
if (! $data['date']) {
return null;
}
@@ -353,7 +353,7 @@ Filter::make('created_at')
DatePicker::make('until'),
])
// ...
->indicators(function (array $data): array {
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['from'] ?? null) {
@@ -12,11 +12,6 @@ trait HasIndicators
protected Indicator | string | Closure | null $indicator = null;
/**
* @var array<Indicator> | Closure
*/
protected array | Closure $indicators = [];
public function indicator(Indicator | string | Closure | null $indicator): static
{
$this->indicator = $indicator;
@@ -24,23 +19,15 @@ trait HasIndicators
return $this;
}
/**
* @param array<Indicator> | Closure $indicators
*/
public function indicators(array | Closure $indicators): static
public function indicateUsing(?Closure $indicators): static
{
$this->indicators = $indicators;
return $this;
}
public function indicateUsing(?Closure $callback): static
{
return $this->indicators($callback);
}
/**
* @return array<Indicator> | array<string>
* @return array<Indicator>
*/
public function getIndicators(): array
{
+1 -1
View File
@@ -14,7 +14,7 @@ class Filter extends BaseFilter
{
parent::setUp();
$this->indicators(function (array $state): array {
$this->indicateUsing(function (array $state): array {
if (! ($state['isActive'] ?? false)) {
return [];
}
+1 -1
View File
@@ -39,7 +39,7 @@ class SelectFilter extends BaseFilter
__('filament-tables::table.filters.select.placeholder'),
);
$this->indicators(function (SelectFilter $filter, array $state): array {
$this->indicateUsing(function (SelectFilter $filter, array $state): array {
if ($filter->isMultiple()) {
if (blank($state['values'] ?? null)) {
return [];
@@ -22,7 +22,7 @@ class TernaryFilter extends SelectFilter
$this->boolean();
$this->indicators(function (TernaryFilter $filter, array $state): array {
$this->indicateUsing(function (TernaryFilter $filter, array $state): array {
if (blank($state['value'] ?? null)) {
return [];
}
@@ -34,7 +34,7 @@ class TrashedFilter extends TernaryFilter
SoftDeletingScope::class,
]));
$this->indicators(function (array $state): array {
$this->indicateUsing(function (array $state): array {
if ($state['value'] ?? null) {
return [Indicator::make($this->getTrueLabel())];
}