Skip to content

Commit

Permalink
Merge pull request #221 from awcodes/grid-layouts
Browse files Browse the repository at this point in the history
Grid layouts
  • Loading branch information
awcodes authored Nov 27, 2023
2 parents a82915c + d47934b commit c881a32
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 60 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,28 @@ TiptapEditor::make('content')
'floating_menu_tools' => ['media', 'grid-builder', 'details', 'table', 'oembed', 'code-block']
```

## Grid layouts

When using the `grid` tool, you can customize the available layouts in the dropdown by passing them to the `gridLayouts()` method:

```php
TiptapEditor::make('content')
->gridLayouts([
'two-columns',
'three-columns',
'four-columns',
'five-columns',
'fixed-two-columns',
'fixed-three-columns',
'fixed-four-columns',
'fixed-five-columns',
'asymmetric-left-thirds',
'asymmetric-right-thirds',
'asymmetric-left-fourths',
'asymmetric-right-fourths',
]);
```

## Custom Blocks

> **Note**
Expand Down
152 changes: 93 additions & 59 deletions resources/views/components/tools/grid.blade.php
Original file line number Diff line number Diff line change
@@ -1,74 +1,108 @@
@props([
'editor' => null,
])

@php
$layouts = $editor->getGridLayouts();
@endphp

<x-filament-tiptap-editor::dropdown-button
label="{{ __('filament-tiptap-editor::editor.grid.label') }}"
active="grid"
icon="grid"
>
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.two_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('two-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.two_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

@if (in_array('three-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 3 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.three_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

@if (in_array('four-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 4 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.four_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 3 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.three_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('five-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 5 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.five_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 4 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.four_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 5 }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.five_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('fixed-two-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'fixed' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.fixed_two_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'fixed' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.fixed_two_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('fixed-three-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 3, type: 'fixed' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.fixed_three_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 3, type: 'fixed' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.fixed_three_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 4, type: 'fixed' }).run()">
{{ __('filament-tiptap-editor::editor.grid.fixed_four_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 5, type: 'fixed' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.fixed_five_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('fixed-four-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 4, type: 'fixed' }).run()">
{{ __('filament-tiptap-editor::editor.grid.fixed_four_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-left-thirds' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_left_thirds') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('fixed-five-columns', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 5, type: 'fixed' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.fixed_five_columns') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-right-thirds' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_right_thirds') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('asymmetric-left-thirds', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-left-thirds' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_left_thirds') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-left-fourths' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_left_fourths') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('asymmetric-right-thirds', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-right-thirds' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_right_thirds') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-right-fourths' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_right_fourths') }}
</x-filament-tiptap-editor::dropdown-button-item>
@if (in_array('asymmetric-left-fourths', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-left-fourths' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_left_fourths') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif

@if (in_array('asymmetric-right-fourths', $layouts))
<x-filament-tiptap-editor::dropdown-button-item
action="editor().chain().focus().insertGrid({ cols: 2, type: 'asymetric-right-fourths' }).run()"
>
{{ __('filament-tiptap-editor::editor.grid.asymmetric_right_fourths') }}
</x-filament-tiptap-editor::dropdown-button-item>
@endif
</x-filament-tiptap-editor::dropdown-button>
2 changes: 1 addition & 1 deletion resources/views/tiptap-editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class="relative z-0 tiptap-wrapper rounded-md bg-white dark:bg-gray-900 focus-wi
<x-filament-tiptap-editor::tools.blocks :blocks="$blocks" :state-path="$statePath" />
@endif
@else
<x-dynamic-component component="filament-tiptap-editor::tools.{{ $tool }}" :state-path="$statePath" />
<x-dynamic-component component="filament-tiptap-editor::tools.{{ $tool }}" :state-path="$statePath" :editor="$field" />
@endif
@endforeach
</div>
Expand Down
27 changes: 27 additions & 0 deletions src/TiptapEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ class TiptapEditor extends Field

protected bool $shouldCollapseBlocksPanel = false;

protected array $gridLayouts = [
'two-columns',
'three-columns',
'four-columns',
'five-columns',
'fixed-two-columns',
'fixed-three-columns',
'fixed-four-columns',
'fixed-five-columns',
'asymmetric-left-thirds',
'asymmetric-right-thirds',
'asymmetric-left-fourths',
'asymmetric-right-fourths',
];

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -400,4 +415,16 @@ public function shouldCollapseBlocksPanel(): bool
{
return $this->shouldCollapseBlocksPanel;
}

public function gridLayouts(array $layouts): static
{
$this->gridLayouts = $layouts;

return $this;
}

public function getGridLayouts(): array
{
return $this->gridLayouts;
}
}

0 comments on commit c881a32

Please sign in to comment.