Skip to content

Commit d78096e

Browse files
committed
docs: add categories to readme
1 parent 8db6f9b commit d78096e

File tree

3 files changed

+133
-32
lines changed

3 files changed

+133
-32
lines changed

README.md

Lines changed: 133 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
- [Previewing in real time with iframe](#previewing-in-real-time-with-iframe)
1616
- [Formatting page builder data for preview](#formatting-page-builder-data-for-preview)
1717
- [Formatting block label](#formatting-block-label)
18+
- [grouping blocks](#grouping-blocks)
19+
- [Block categories](#block-categories)
1820
- [Showing thumbnail preview for a block](#showing-thumbnail-preview-for-a-block)
1921
- [disabling block in select block](#disabling-block-in-select-block)
20-
- [grouping blocks](#grouping-blocks)
2122
- [iframe resizing](#iframe-resizing)
2223
- [Parameter injection](#parameter-injection)
2324
- [Rendering page builder items on infolist](#rendering-page-builder-items-on-infolist)
@@ -267,6 +268,118 @@ class Description extends BaseBlock
267268
}
268269
```
269270

271+
272+
### grouping blocks
273+
274+
many times you will have too many blocks and will have the need to group them, this can be done by declaring
275+
`getCategory` method on BaseBlock class like so:
276+
277+
```php
278+
class Description extends BaseBlock
279+
{
280+
public static function getCategory(): string
281+
{
282+
return 'About';
283+
}
284+
}
285+
```
286+
287+
or you can use category class instead of just name to group them easier, you can create category class by running command:
288+
289+
```bash
290+
php artisan page-builder-plugin:make-block-category
291+
```
292+
293+
this will create a category class in `app/Filament/{id of admin panel}/BlockCategories` directory, you can then use this class to group blocks like this:
294+
295+
```php
296+
<?php
297+
298+
namespace App\Filament\Admin\BlockCategories;
299+
300+
use Redberry\PageBuilderPlugin\Abstracts\BaseBlockCategory;
301+
302+
class Buttons extends BaseBlockCategory
303+
{
304+
public static function getCategoryName(): string
305+
{
306+
return 'Buttons';
307+
}
308+
}
309+
```
310+
311+
this classes come more in play when using thumbnail mode of select block, you can read more about it in [Showing thumbnail preview for a block](#showing-thumbnail-preview-for-a-block) section.
312+
313+
result look will like this:
314+
![block grouping demo](./assets/block-grouping-demo.png)
315+
316+
### Block categories
317+
318+
blocks can be categorized visually by adding `getCategory` function on a block class, return value of `getCategory` can be either normal string or class that extends `BaseBlockCategory` class, this class can be created by running command:
319+
320+
```bash
321+
php artisan page-builder-plugin:make-block-category
322+
```
323+
324+
this will create a category class in `app/Filament/{id of admin panel}/BlockCategories` directory, you can then use this class to group blocks like this:
325+
326+
```php
327+
<?php
328+
329+
class Description extends BaseBlock
330+
{
331+
public static function getCategory(): string
332+
{
333+
return TextFields::class;
334+
}
335+
}
336+
```
337+
338+
benefit of using category class is that there is lower chance of a typo on top of this category classes allow more customization when using [thumbnail previews](#showing-thumbnail-preview-for-a-block) for blocks by allowing you to add icons and customized other attributes for a filter tab.
339+
340+
you can customize category icon by adding `getCategoryIcon` method to the category class like this:
341+
342+
```php
343+
<?php
344+
345+
namespace App\Filament\Admin\BlockCategories;
346+
347+
use Redberry\PageBuilderPlugin\Abstracts\BaseBlockCategory;
348+
349+
class Buttons extends BaseBlockCategory
350+
{
351+
// ...
352+
353+
public static function getCategoryIcon(): string
354+
{
355+
return 'heroicon-o-hand-raised';
356+
}
357+
}
358+
```
359+
360+
and you can customize other tab attributes by overriding `getCategoryAttributes` method like this:
361+
362+
```php
363+
<?php
364+
365+
namespace App\Filament\Admin\BlockCategories;
366+
367+
use Redberry\PageBuilderPlugin\Abstracts\BaseBlockCategory;
368+
369+
class Buttons extends BaseBlockCategory
370+
{
371+
// ...
372+
373+
public static function getCategoryAttributes(): ComponentAttributeBag
374+
{
375+
return new ComponentAttributeBag([
376+
'class' => 'bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200',
377+
]);
378+
}
379+
}
380+
```
381+
382+
270383
### Showing thumbnail preview for a block
271384

272385
if you want to show thumbnail preview of a block using an image it can be done by declaring `getThumbnail` method on a block class and calling `renderWithThumbnails` method on the page builder field like this:
@@ -292,7 +405,13 @@ $form->schema([
292405
```
293406

294407
which will render components like this:
295-
![thumbnails preview](./assets/thumbnails.png)
408+
![thumbnails preview](./assets/thumbnails-without-category.png)
409+
410+
if you are using categories for blocks it will look like this:
411+
412+
![thumbnails preview with category](./assets/thumbnails.png)
413+
414+
you can customized tabs by using [Block categories](#block-categories).
296415

297416
### disabling block in select block
298417
if you want to disable block without removing it from the page builder you can do so by declaring `getIsSelectionDisabled` method on a block class like this:
@@ -309,24 +428,6 @@ class Description extends BaseBlock
309428
}
310429
```
311430

312-
### grouping blocks
313-
314-
many times you will have too many blocks and will have the need to group them, this can be done by declaring
315-
`getCategory` method on BaseBlock class like so:
316-
317-
```php
318-
class Description extends BaseBlock
319-
{
320-
public static function getCategory(): string
321-
{
322-
return 'About';
323-
}
324-
}
325-
```
326-
327-
result look will like this:
328-
![block grouping demo](./assets/block-grouping-demo.png)
329-
330431
### iframe resizing
331432

332433
iframe height can not be adjusted based on content of iframe because of CORS issues, because of this there are two ways to size iframe height to not cause components to hide.
@@ -473,13 +574,13 @@ this will render preview of items selected in `PageBuilder` field and it will up
473574

474575
only component which has actions is `PageBuilder`, all of this actions have their own modifier functions and are moved to the own class, so you can easily customize them, here is the list of actions, functions to modify them and their classes:
475576

476-
| Action name | Class | Modifier function |
477-
|-------------|--------------------------------|-------------------|
478-
| Create | `CreatePageBuilderBlockAction` | `createAction` |
479-
| Edit | `EditPageBuilderBlockAction` | `editAction` |
480-
| Delete | `DeletePageBuilderBlockAction` | `deleteAction` |
481-
| Reorder | `ReorderPageBuilderBlockAction`| `reorderAction` |
482-
| Select block| `SelectBlockAction` | `selectBlockAction` |
577+
| Action name | Class | Modifier function |
578+
| ------------ | ------------------------------- | ------------------- |
579+
| Create | `CreatePageBuilderBlockAction` | `createAction` |
580+
| Edit | `EditPageBuilderBlockAction` | `editAction` |
581+
| Delete | `DeletePageBuilderBlockAction` | `deleteAction` |
582+
| Reorder | `ReorderPageBuilderBlockAction` | `reorderAction` |
583+
| Select block | `SelectBlockAction` | `selectBlockAction` |
483584

484585
#### Customizing buttons for actions
485586
one strange thing about this package is how buttons are customized, because of how filamentphp actions are structured each button render comes with lot baggage to say so, multiple views, many checks and etc. while this is not too much of a problem if you are using couple of actions but due to nature of components for building a page there will be need for many many actions, 3 actions per component, its hard to quanitify exactly how much performance disadvantage this causes but in large project we first used this package in it became a massive problem to a point where removing those actions increase paged speeding 2-3 times, same numbers are replicable in this package on smaller scale as well, for example page which was rendering 65 components took around 500ms on local machine with using normal actions and no additional logic on their part while using simple buttons took around 150ms on average because of this drastic performance deference we decided to opt into using simple button rather than action. most buttons are rendered like this:
@@ -504,11 +605,11 @@ as you can see we are using filament button to render our buttons, this gives us
504605
this buttons can also be easily change, even the component view itself using modifier functions provided on `PageBuilder` component, this functions are injected with: `$action` `$item` `$index` and `$attributes` which can be injected via passing a closure to the modifier function,
505606
this is a list of modifier functions and their corresponding actions:
506607

507-
| Action name | Modifier function |
508-
|-------------|-------------------------|
509-
| Delete | `deleteActionButton` |
510-
| Edit | `editActionButton` |
511-
| Reorder | `reorderActionButton` |
608+
| Action name | Modifier function |
609+
| ----------- | --------------------- |
610+
| Delete | `deleteActionButton` |
611+
| Edit | `editActionButton` |
612+
| Reorder | `reorderActionButton` |
512613

513614
here is example on how to use this modifier functions:
514615

73.5 KB
Loading

assets/thumbnails.png

47.7 KB
Loading

0 commit comments

Comments
 (0)