Skip to content

Commit c576594

Browse files
committed
Refactor CodeEditor component: Add methods for custom styles, themes, and minimum height configuration
1 parent 3b900fc commit c576594

3 files changed

Lines changed: 114 additions & 4 deletions

File tree

resources/views/filament/forms/components/code-editor.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
x-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-code-editor', 'solution-forest/inspirecms') }}"
3939
>
4040
<div wire:ignore class="w-full code-editor-textarea-wrapper" x-ref="codeEditor"
41-
style="height:{{ $getMinHeight() }}px;overflow: hidden; {{ $getCustomStyle() }}">
41+
style="height:{{ $getMinHeight() }};overflow: hidden; {{ $getCustomStyle() }}">
4242
</div>
4343
</div>
4444
</div>

src/Filament/Forms/Components/CodeEditor.php

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,117 @@
22

33
namespace SolutionForest\InspireCms\Filament\Forms\Components;
44

5-
class CodeEditor extends \Dotswan\FilamentCodeEditor\Fields\CodeEditor
5+
use Closure;
6+
use Filament\Forms\Components\Field;
7+
8+
class CodeEditor extends Field
69
{
710
protected string $view = 'inspirecms::filament.forms.components.code-editor';
11+
12+
protected int | string | Closure | null $minHeight = 420;
13+
protected string | Closure | null $customStyle = null;
14+
protected string | Closure | null $darkModeTheme = null;
15+
protected string | Closure | null $lightModeTheme = null;
16+
protected bool | Closure $isReadOnly = false;
17+
protected bool | Closure $showCopyButton = false;
18+
19+
public function customStyle(string | null $customStyle): static
20+
{
21+
$this->customStyle = $customStyle;
22+
23+
return $this;
24+
}
25+
26+
public function minHeight(int | string | Closure | null $minHeight = 768): static
27+
{
28+
$this->minHeight = $minHeight;
29+
30+
return $this;
31+
}
32+
33+
public function lightModeTheme(?string $lightModeTheme): static
34+
{
35+
$this->lightModeTheme = $lightModeTheme;
36+
37+
return $this;
38+
}
39+
40+
public function darkModeTheme(?string $darkModeTheme): static
41+
{
42+
$this->darkModeTheme = $darkModeTheme;
43+
44+
return $this;
45+
}
46+
47+
public function isReadOnly(bool | Closure $isReadOnly = false): static
48+
{
49+
$this->isReadOnly = $isReadOnly;
50+
51+
return $this;
52+
}
53+
54+
public function showCopyButton(bool | Closure $showCopyButton = true): static
55+
{
56+
$this->showCopyButton = $showCopyButton;
57+
58+
return $this;
59+
}
60+
61+
/**
62+
* @return bool
63+
*/
64+
public function getIsReadOnly(): bool
65+
{
66+
return boolval($this->evaluate($this->isReadOnly));
67+
}
68+
69+
/**
70+
* @return ?string
71+
*/
72+
public function getMinHeight()
73+
{
74+
$height = $this->evaluate($this->minHeight);
75+
76+
if (is_numeric($height)) {
77+
return (int) $height . 'px';
78+
}
79+
80+
if (is_string($height)) {
81+
return $height;
82+
}
83+
84+
return null;
85+
}
86+
87+
/**
88+
* @return string
89+
*/
90+
public function getShowCopyButton()
91+
{
92+
return $this->evaluate($this->showCopyButton ? "true" : "false");
93+
}
94+
95+
/**
96+
* @return ?string
97+
*/
98+
public function getCustomStyle()
99+
{
100+
return $this->evaluate($this->customStyle);
101+
}
102+
103+
/**
104+
* @return ?string
105+
*/
106+
public function getDarkModeTheme()
107+
{
108+
return $this->evaluate($this->darkModeTheme);
109+
}
110+
111+
/**
112+
* @return ?string
113+
*/
114+
public function getLightModeTheme()
115+
{
116+
return $this->evaluate($this->lightModeTheme);
117+
}
8118
}

src/Filament/Resources/Helpers/TemplateResourceHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public static function getThemeFormComponent()
3838
public static function getContentFormComponent($name = 'content')
3939
{
4040
return \SolutionForest\InspireCms\Filament\Forms\Components\CodeEditor::make($name)
41-
// ->darkModeTheme('gruvbox-dark')
4241
->darkModeTheme('basic-dark')
43-
->lightModeTheme('basic-light');
42+
->lightModeTheme('basic-light')
43+
->minHeight('48rem');
4444
}
4545

4646
/** @return Forms\Components\Field|Forms\Components\Component */

0 commit comments

Comments
 (0)