Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an extraTabs function to the field #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static function form(Form $form): Form
->required()
->maxLength(255),
])
->extraTabs([ // Optional
Tab::make('More things')->schema([
TextInput::make('more_things')
->required()
->maxLength(255),
]),
])
->translatableFields([
TextInput::make("title")
->label('Title')
Expand Down
26 changes: 26 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ TranslatableEntry::make([
], \App\CustomLocaleCollection::class);
```

### Adding extra tabs

You can add extra tabs by using the `->extraTabs()` method, this expects a Closure, array or `null`.
Passing an array here with Tabs will add them next to the general tab, this can be useful for separating your General tab in case it becomes too long.

```php
use Codedor\TranslatableTabs\Forms\TranslatableTabs;
use Filament\Forms\Components\Tabs\Tab;

public static function form(Form $form): Form
{
return $form->schema([
TranslatableTabs::make('Translations')
->defaultFields(...)
->extraTabs([
Tab::make('More options')->schema([
Text::make('Extra option')
->required(),
]),
])
->translatableFields(...)
->columnSpan(['lg' => 2]),
]);
}
```

### Showing a different icon

You can show a different icon by using the `icon()` method, this expects a Closure, string or `false`.
Expand Down
13 changes: 13 additions & 0 deletions src/Forms/TranslatableTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TranslatableTabs extends Component

public array|Closure $defaultFields = [];

public null|array|Closure $extraTabs = null;

public Closure $translatableFields;

public array|Closure $locales = [];
Expand Down Expand Up @@ -75,6 +77,13 @@ public function defaultFields(array|Closure $defaultFields): static
return $this;
}

public function extraTabs(null|array|Closure $extraTabs): static
{
$this->extraTabs = $extraTabs;

return $this;
}

public function translatableFields(Closure $translatableFields): static
{
$this->translatableFields = $translatableFields;
Expand Down Expand Up @@ -122,6 +131,10 @@ public function getChildComponents(): array
->schema($this->evaluate($this->defaultFields)),
];

if (! is_null($this->extraTabs)) {
$tabs = array_merge($tabs, $this->evaluate($this->extraTabs));
}

foreach ($this->evaluate($this->locales) as $locale) {
$tabs[] = Tab::make($locale)
->schema($this->evaluate($this->translatableFields, [
Expand Down