From 7cf83ce360f6492a6ac830ab4e381fbfafd02e9c Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Mon, 2 Dec 2024 14:53:02 +0000 Subject: [PATCH] tweaks & docs --- packages/forms/src/Components/Builder.php | 2 +- .../docs/02-resources/07-relation-managers.md | 97 +++++-------------- .../Pages/Concerns/HasRelationManagers.php | 6 +- .../Forms/Components/RuleBuilder.php | 4 +- 4 files changed, 30 insertions(+), 79 deletions(-) diff --git a/packages/forms/src/Components/Builder.php b/packages/forms/src/Components/Builder.php index 9b46802137..a1cde2ac78 100644 --- a/packages/forms/src/Components/Builder.php +++ b/packages/forms/src/Components/Builder.php @@ -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()); diff --git a/packages/panels/docs/02-resources/07-relation-managers.md b/packages/panels/docs/02-resources/07-relation-managers.md index 4e3f1e4735..4459e526ad 100644 --- a/packages/panels/docs/02-resources/07-relation-managers.md +++ b/packages/panels/docs/02-resources/07-relation-managers.md @@ -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 diff --git a/packages/panels/src/Resources/Pages/Concerns/HasRelationManagers.php b/packages/panels/src/Resources/Pages/Concerns/HasRelationManagers.php index a7d31cb697..59cbdaaec8 100644 --- a/packages/panels/src/Resources/Pages/Concerns/HasRelationManagers.php +++ b/packages/panels/src/Resources/Pages/Concerns/HasRelationManagers.php @@ -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) { diff --git a/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php b/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php index b713c292a3..be929431f6 100644 --- a/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php +++ b/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php @@ -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()