Skip to content

Commit 7a97bf4

Browse files
committed
feat: customizing navigation defaults
1 parent 017c338 commit 7a97bf4

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ class Buttons extends BaseBlockCategory
379379
}
380380
```
381381

382+
default category type is 'all' it can be changed to class of the Category or the value, default can be changed like this:
383+
```php
384+
<?php
385+
386+
PageBuilder::make('website_content')
387+
->selectBlockAction(function ( SelectBlockAction $action) {
388+
return $action->selectField(function (RadioButtonImage $field) {
389+
return $field->defaultCategory(Navigations::class);
390+
});
391+
});
392+
```
393+
382394

383395
### Showing thumbnail preview for a block
384396

resources/views/forms/radio-button-image.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
$options = $getOptions();
77
$idSanitized = str_replace(['-', '.'], '_', $id);
88
$hasNoCategories = count($options) === 1;
9-
$firstCategory = array_key_first($options);
9+
$defaultCategory = $getDefaultCategory();
1010
$formattedOptions = $getFormattedOptions();
1111
@endphp
12-
<div x-data="{ activeTab: @js($firstCategory), options: @js($formattedOptions) }" class="">
12+
<div x-data="{ activeTab: @js($defaultCategory), options: @js($formattedOptions) }" class="">
1313
@if (!$hasNoCategories)
1414
<x-filament::tabs contained="true">
1515
@foreach ($options as $category => $_)

src/Components/Forms/Actions/SelectBlockAction.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ class SelectBlockAction extends Action
1717
use CanRenderWithThumbnails;
1818
use FormatsBlockCategories;
1919

20-
public ?Closure $modifySelectionFieldUsing = null;
20+
protected ?Closure $modifySelectionFieldUsing = null;
2121

2222
public static function getDefaultName(): ?string
2323
{
2424
return 'select-page-builder-block';
2525
}
2626

27+
public function selectField(Closure $modifySelectionFieldUsing): static
28+
{
29+
$this->modifySelectionFieldUsing = $modifySelectionFieldUsing;
30+
31+
return $this;
32+
}
33+
2734
protected function setUp(): void
2835
{
2936
parent::setUp();
@@ -68,7 +75,7 @@ protected function setUp(): void
6875
$field = $this->evaluate($this->modifySelectionFieldUsing, [
6976
'field' => $field,
7077
'component' => $component,
71-
]);
78+
]) ?? $field;
7279
}
7380

7481
return $form->schema([

src/Components/Forms/PageBuilder.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getReorderAction(): Action
7373
if ($this->modifyReorderActionUsing) {
7474
$action = $this->evaluate($this->modifyReorderActionUsing, [
7575
'action' => $action,
76-
]);
76+
]) ?? $action;
7777
}
7878

7979
return $action;
@@ -87,7 +87,7 @@ public function getCreateAction(): Action
8787
if ($this->modifyCreateActionUsing) {
8888
$action = $this->evaluate($this->modifyCreateActionUsing, [
8989
'action' => $action,
90-
]);
90+
]) ?? $action;
9191
}
9292

9393
return $action;
@@ -104,7 +104,7 @@ public function getSelectBlockAction(): Action
104104
if ($this->modifySelectBlockActionUsing) {
105105
$action = $this->evaluate($this->modifySelectBlockActionUsing, [
106106
'action' => $action,
107-
]);
107+
]) ?? $action;
108108
}
109109

110110
return $action;
@@ -118,7 +118,7 @@ public function getEditAction(): Action
118118
if ($this->modifyEditActionUsing) {
119119
$action = $this->evaluate($this->modifyEditActionUsing, [
120120
'action' => $action,
121-
]);
121+
]) ?? $action;
122122
}
123123

124124
return $action;
@@ -132,7 +132,7 @@ public function getDeleteAction(): Action
132132
if ($this->modifyDeleteActionUsing) {
133133
$action = $this->evaluate($this->modifyDeleteActionUsing, [
134134
'action' => $action,
135-
]);
135+
]) ?? $action;
136136
}
137137

138138
return $action;
@@ -290,6 +290,14 @@ public function createAction(
290290
return $this;
291291
}
292292

293+
public function selectBlockAction(
294+
Closure $modifySelectBlockActionUsing,
295+
) {
296+
$this->modifySelectBlockActionUsing = $modifySelectBlockActionUsing;
297+
298+
return $this;
299+
}
300+
293301
public function reorderAction(
294302
Closure $modifyReorderActionUsing,
295303
) {

src/Components/Forms/RadioButtonImage.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class RadioButtonImage extends Field
2525

2626
public ComponentAttributeBag | Closure | null $allTabAttributes = null;
2727

28+
protected string $defaultCategory = 'all';
29+
2830
/**
2931
* Returns the thumbnail for the given block type.
3032
*
@@ -46,6 +48,18 @@ public function allTabAttributes(
4648
return $this;
4749
}
4850

51+
public function defaultCategory(string $category): static
52+
{
53+
$this->defaultCategory = $category;
54+
55+
return $this;
56+
}
57+
58+
public function getDefaultCategory(): string
59+
{
60+
return $this->defaultCategory;
61+
}
62+
4963
public function getAllTabAttributes(): ComponentAttributeBag
5064
{
5165
return $this->evaluate($this->allTabAttributes) ?? new ComponentAttributeBag;

0 commit comments

Comments
 (0)