tweaks & docs

This commit is contained in:
Dan Harrin
2024-12-02 14:53:02 +00:00
parent 2ea9de5ff2
commit 7cf83ce360
4 changed files with 30 additions and 79 deletions
+1 -1
View File
@@ -681,7 +681,7 @@ class Builder extends Field implements CanConcealComponents, HasExtraItemActions
$component->partiallyRender();
})
->iconButton()
->icon('heroicon-s-cog-6-tooth')
->icon('heroicon-m-cog-6-tooth')
->size(ActionSize::Small)
->visible(fn (Builder $component): bool => (! $component->isDisabled()) && $component->hasBlockPreviews());
@@ -662,14 +662,17 @@ public function hasCombinedRelationManagerTabsWithContent(): bool
}
```
### Setting an icon for the form tab
### Customizing the content tab
On the Edit or View page class, override the `getContentTabIcon()` method:
On the Edit or View page class, override the `getContentTabComponent()` method, and use any [Tab](../../schemas/layout/tabs) customization methods:
```php
public function getContentTabIcon(): ?string
use Filament\Schemas\Components\Tabs\Tab;
public function getContentTabComponent(): Tab
{
return 'heroicon-m-cog';
return Tab::make('Settings')
->icon('heroicon-m-cog');
}
```
@@ -686,91 +689,39 @@ public function getContentTabPosition(): ?ContentTabPosition
}
```
## Adding badges to relation manager tabs
## Customizing relation manager tabs
You can add a badge to a relation manager tab by setting the `$badge` property:
```php
protected static ?string $badge = 'new';
```
Alternatively, you can override the `getBadge()` method:
To customize the tab for a relation manager, override the `getTabComponent()` method, and use any [Tab](../../schemas/layout/tabs) customization methods:
```php
use Filament\Schemas\Components\Tabs\Tab;
use Illuminate\Database\Eloquent\Model;
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
public static function getTabComponent(Model $ownerRecord, string $pageClass): Tab
{
return static::$badge;
return Tab::make('Blog posts')
->badge($ownerRecord->posts()->count())
->badgeColor('info')
->badgeTooltip('The number of posts in this category')
->icon('heroicon-m-document-text');
}
```
Or, if you are using a [relation group](#grouping-relation-managers), you can use the `badge()` method:
If you are using a [relation group](#grouping-relation-managers), you can use the `tab()` method:
```php
use Filament\Resources\RelationManagers\RelationGroup;
RelationGroup::make('Contacts', [
// ...
])->badge('new');
```
### Changing the color of relation manager tab badges
If a badge value is defined, it will display using the primary color by default. To style the badge contextually, set the `$badgeColor` to be a [registered color](../../styling/colors):
```php
protected static ?string $badgeColor = 'danger';
```
Alternatively, you can override the `getBadgeColor()` method:
```php
use Filament\Schemas\Components\Tabs\Tab;
use Illuminate\Database\Eloquent\Model;
public static function getBadgeColor(Model $ownerRecord, string $pageClass): ?string
{
return 'danger';
}
```
Or, if you are using a [relation group](#grouping-relation-managers), you can use the `badgeColor()` method:
```php
use Filament\Resources\RelationManagers\RelationGroup;
RelationGroup::make('Contacts', [
// ...
])->badgeColor('danger');
```
### Adding a tooltip to relation manager tab badges
If a badge value is defined, you can add a tooltip to it by setting the `$badgeTooltip` property:
```php
protected static ?string $badgeTooltip = 'There are new posts';
```
Alternatively, you can override the `getBadgeTooltip()` method:
```php
use Illuminate\Database\Eloquent\Model;
public static function getBadgeTooltip(Model $ownerRecord, string $pageClass): ?string
{
return 'There are new posts';
}
```
Or, if you are using a [relation group](#grouping-relation-managers), you can use the `badgeTooltip()` method:
```php
use Filament\Resources\RelationManagers\RelationGroup;
RelationGroup::make('Contacts', [
// ...
])->badgeTooltip('There are new posts');
])
->tab(fn (Model $ownerRecord): Tab => Tab::make('Blog posts')
->badge($ownerRecord->posts()->count())
->badgeColor('info')
->badgeTooltip('The number of posts in this category')
->icon('heroicon-m-document-text'));
```
## Sharing a resource's form and table with a relation manager
@@ -74,8 +74,7 @@ trait HasRelationManagers
public function getContentTabComponent(): Tab
{
return Tab::make($this->getContentTabLabel())
->icon($this->getContentTabIcon())
->schema($this->getContentComponents());
->icon($this->getContentTabIcon());
}
public function getContentTabLabel(): ?string
@@ -128,7 +127,8 @@ trait HasRelationManagers
$tabKey = strval($tabKey);
if (blank($tabKey) && $hasCombinedRelationManagerTabsWithContent) {
return $this->getContentTabComponent();
return $this->getContentTabComponent()
->schema($this->getContentComponents());
}
if ($manager instanceof RelationGroup) {
@@ -69,7 +69,7 @@ class RuleBuilder extends Builder
])
->addAction(fn (Action $action) => $action
->label(__('filament-tables::filters/query-builder.actions.add_rule_group.label'))
->icon('heroicon-s-plus'))
->icon('heroicon-m-plus'))
->labelBetweenItems(__('filament-tables::filters/query-builder.item_separators.or'))
->collapsible()
->expandAllAction(fn (Action $action) => $action->hidden())
@@ -112,7 +112,7 @@ class RuleBuilder extends Builder
})
->addAction(fn (Action $action) => $action
->label(__('filament-tables::filters/query-builder.actions.add_rule.label'))
->icon('heroicon-s-plus'))
->icon('heroicon-m-plus'))
->addBetweenAction(fn (Action $action) => $action->hidden())
->label(__('filament-tables::filters/query-builder.form.rules.label'))
->hiddenLabel()