Skip to content

Commit

Permalink
removed flex class from preview's body because it's a mistake 🙄, and …
Browse files Browse the repository at this point in the history
…instead replaced it with a function to give the user full control over the body's attributes. 😁
  • Loading branch information
abdelhamiderrahmouni committed Apr 20, 2024
1 parent 30ff5be commit 3a74de1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/views/filament-monaco-editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
wrapPreview(value){
return `<head>{{ $getPreviewHeadEndContent() }}</head>` +
`&lt;body class='flex'&gt;` +
`&lt;body {{ $getPreviewBodyAttributes() }}&gt;` +
`{{ $getPreviewBodyStartContent() }}` +
`${value}` +
`{{ $getPreviewBodyEndContent() }}` +
Expand Down
15 changes: 15 additions & 0 deletions src/MonacoEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MonacoEditor extends Field

public string | Closure $previewHeadEndContent = '';

public array | Closure $previewBodyAttributes = ["class" => ""];

public string | Closure $previewBodyStartContent = '';

public string | Closure $previewBodyEndContent = '';
Expand Down Expand Up @@ -183,6 +185,13 @@ public function previewHeadEndContent(string | Closure $content = ''): static
return $this;
}

public function previewBodyAttributes(array | Closure $attributes = ["class" => ""]): static
{
$this->previewBodyAttributes = $attributes;

return $this;
}

public function previewBodyStartContent(string | Closure $content = ''): static
{
$this->previewBodyStartContent = $content;
Expand Down Expand Up @@ -274,6 +283,12 @@ public function getPreviewHeadEndContent()
return $this->evaluate($this->previewHeadEndContent);
}

public function getPreviewBodyAttributes()
{
$attributes = $this->evaluate($this->previewBodyAttributes);
return implode(' ', array_map(fn ($key, $value) => "$key=&quot;$value&quot;", array_keys($attributes), $attributes));
}

public function getPreviewBodyStartContent()
{
return $this->evaluate($this->previewBodyStartContent);
Expand Down

0 comments on commit 3a74de1

Please sign in to comment.