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
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected array $attributes = [
|
2024-12-17 15:06:08 +00:00
|
|
|
'rows' => '6',
|
2021-08-19 14:00:14 +00:00
|
|
|
'class' => 'textarea',
|
|
|
|
];
|
|
|
|
|
2022-01-23 16:53:23 +00:00
|
|
|
protected string $content = '';
|
|
|
|
|
2024-12-17 15:06:08 +00:00
|
|
|
protected string $lang = '';
|
|
|
|
|
2022-01-23 16:53:23 +00:00
|
|
|
public function setContent(string $value): void
|
|
|
|
{
|
|
|
|
$this->content = htmlspecialchars_decode($value);
|
|
|
|
}
|
|
|
|
|
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';
|
2022-01-23 16:53:23 +00:00
|
|
|
$textarea = form_textarea($this->attributes, $this->content);
|
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
|
|
|
}
|
|
|
|
}
|