2021-08-19 14:00:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
namespace App\Views\Components\Forms;
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
use Override;
|
|
|
|
|
2024-12-17 15:06:08 +00:00
|
|
|
class CodeEditor extends FormComponent
|
2021-08-19 14:00:14 +00:00
|
|
|
{
|
2024-12-17 15:06:08 +00:00
|
|
|
protected array $props = ['content', 'lang'];
|
2024-05-09 17:55:41 +00:00
|
|
|
|
2021-08-19 14:00:14 +00:00
|
|
|
protected array $attributes = [
|
2024-12-17 15:06:08 +00:00
|
|
|
'rows' => '6',
|
2024-12-23 15:35:47 +00:00
|
|
|
'class' => 'bg-elevated w-full rounded-lg border-3 border-contrast focus:border-contrast focus-within:ring-accent transition',
|
2021-08-19 14:00:14 +00:00
|
|
|
];
|
|
|
|
|
2024-12-17 15:06:08 +00:00
|
|
|
protected string $lang = '';
|
|
|
|
|
2024-12-19 12:33:57 +00:00
|
|
|
public function setValue(string $value): void
|
2022-01-23 16:53:23 +00:00
|
|
|
{
|
2024-12-19 12:33:57 +00:00
|
|
|
$this->value = htmlspecialchars_decode($value);
|
2022-01-23 16:53:23 +00:00
|
|
|
}
|
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2021-08-19 14:00:14 +00:00
|
|
|
public function render(): string
|
|
|
|
{
|
2021-08-27 10:58:22 +00:00
|
|
|
$this->attributes['slot'] = 'textarea';
|
2024-12-19 12:33:57 +00:00
|
|
|
$textarea = form_textarea($this->attributes, $this->getValue());
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2021-08-27 10:58:22 +00:00
|
|
|
return <<<HTML
|
2024-12-17 15:06:08 +00:00
|
|
|
<code-editor lang="{$this->lang}">{$textarea}</code-editor>
|
2021-08-27 10:58:22 +00:00
|
|
|
HTML;
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
}
|