|
2 | 2 |
|
3 | 3 | namespace SolutionForest\InspireCms\Filament\Forms\Components; |
4 | 4 |
|
5 | | -class CodeEditor extends \Dotswan\FilamentCodeEditor\Fields\CodeEditor |
| 5 | +use Closure; |
| 6 | +use Filament\Forms\Components\Field; |
| 7 | + |
| 8 | +class CodeEditor extends Field |
6 | 9 | { |
7 | 10 | 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 | + } |
8 | 118 | } |
0 commit comments