Newer
Older

Yassine Doghri
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace App\View\Components\Forms;
use ViewComponents\Component;
/**
* Form Checkbox Switch
*
* Abstracts form_label to stylize it as a switch toggle
*/
class Toggler extends Component
{
/**
* @var array<string, string>
*/
protected array $attributes = [
'id' => '',
'name' => '',
'value' => '',
'class' => '',
];
protected string $label = '';
protected string $hint = '';
protected bool $checked = false;
public function render(): string
{
$wrapperClass = $this->attributes['class'];
unset($this->attributes['class']);
$this->attributes['class'] = 'form-switch';
$checkbox = form_checkbox($this->attributes, $this->attributes['value'], $this->checked);
$hint = $this->hint !== '' ? hint_tooltip(lang('Podcast.form.lock_hint'), 'ml-1') : '';
return <<<CODE_SAMPLE
<label class="relative inline-flex items-center {$wrapperClass}">
{$checkbox}
<span class="form-switch-slider"></span>
<span class="ml-2">{$this->label}{$hint}</span>
</label>
CODE_SAMPLE;
}
}