| 1 |
<?php |
| 2 |
|
| 3 |
namespace SimpleAnalytics\Settings\Blocks\Fields; |
| 4 |
|
| 5 |
use SimpleAnalytics\Setting; |
| 6 |
use SimpleAnalytics\Settings\Concerns\HasDocs; |
| 7 |
use SimpleAnalytics\UI\LabelComponent; |
| 8 |
|
| 9 |
class Checkbox extends Field |
| 10 |
{ |
| 11 |
use HasDocs; |
| 12 |
|
| 13 |
/** |
| 14 |
* @var bool |
| 15 |
*/ |
| 16 |
protected $default = false; |
| 17 |
|
| 18 |
public function getValueSanitizer(): callable |
| 19 |
{ |
| 20 |
return 'absint'; |
| 21 |
} |
| 22 |
|
| 23 |
public function getValueType(): string |
| 24 |
{ |
| 25 |
return 'integer'; |
| 26 |
} |
| 27 |
|
| 28 |
public function default(bool $value): self |
| 29 |
{ |
| 30 |
$this->default = $value; |
| 31 |
|
| 32 |
return $this; |
| 33 |
} |
| 34 |
|
| 35 |
public function render(): void |
| 36 |
{ |
| 37 |
?> |
| 38 |
<div class="relative flex gap-x-3"> |
| 39 |
<div class="flex h-6 items-center"> |
| 40 |
<input |
| 41 |
id="<?php |
| 42 |
echo esc_attr($this->getKey()); |
| 43 |
?>" |
| 44 |
name="<?php |
| 45 |
echo esc_attr($this->getKey()); |
| 46 |
?>" |
| 47 |
type="checkbox" |
| 48 |
value="1" |
| 49 |
class="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" |
| 50 |
<?php |
| 51 |
if (Setting::boolean($this->getKey(), $this->default) === true) echo 'checked'; |
| 52 |
?> |
| 53 |
> |
| 54 |
</div> |
| 55 |
<div class="text-sm leading-6"> |
| 56 |
<?php |
| 57 |
(new LabelComponent($this->getLabel(), $this->docs, $this->getKey()))(); |
| 58 |
?> |
| 59 |
|
| 60 |
<?php |
| 61 |
if ($this->description): ?> |
| 62 |
<p class="text-gray-500"> |
| 63 |
<?php echo esc_html($this->description); ?> |
| 64 |
</p> |
| 65 |
<?php endif; |
| 66 |
?> |
| 67 |
</div> |
| 68 |
</div> |
| 69 |
<?php |
| 70 |
} |
| 71 |
} |
| 72 |
|