| 1 |
<?php |
| 2 |
|
| 3 |
namespace SimpleAnalytics\Settings\Blocks\Fields; |
| 4 |
|
| 5 |
use SimpleAnalytics\Setting; |
| 6 |
use SimpleAnalytics\Settings\Concerns\HasDocs; |
| 7 |
use SimpleAnalytics\Settings\Concerns\HasPlaceholder; |
| 8 |
use SimpleAnalytics\UI\LabelComponent; |
| 9 |
|
| 10 |
class Input extends Field |
| 11 |
{ |
| 12 |
use HasDocs; |
| 13 |
use HasPlaceholder; |
| 14 |
|
| 15 |
/** |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $type = 'text'; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var bool |
| 22 |
*/ |
| 23 |
protected $autofocus = false; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var string|null |
| 27 |
*/ |
| 28 |
protected $placeholder; |
| 29 |
|
| 30 |
public function getValueSanitizer(): callable |
| 31 |
{ |
| 32 |
return 'sanitize_text_field'; |
| 33 |
} |
| 34 |
|
| 35 |
public function getValueType(): string |
| 36 |
{ |
| 37 |
return 'string'; |
| 38 |
} |
| 39 |
|
| 40 |
public function render(): void |
| 41 |
{ |
| 42 |
?> |
| 43 |
<?php |
| 44 |
(new LabelComponent($this->getLabel(), $this->docs, $this->getKey()))(); |
| 45 |
?> |
| 46 |
<input |
| 47 |
type="<?php |
| 48 |
echo esc_attr($this->type); |
| 49 |
?>" |
| 50 |
name="<?php |
| 51 |
echo esc_attr($this->getKey()); |
| 52 |
?>" |
| 53 |
id="<?php |
| 54 |
echo esc_attr($this->getKey()); |
| 55 |
?>" |
| 56 |
class="mt-2 block w-full rounded-md border-0 placeholder:text-gray-400 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 py-1.5 focus:ring-primary focus:ring-2 focus:ring-inset sm:max-w-md sm:text-sm sm:leading-6" |
| 57 |
placeholder="<?php |
| 58 |
echo esc_attr($this->placeholder); |
| 59 |
?>" |
| 60 |
<?php |
| 61 |
if ($this->autofocus) echo "autofocus"; |
| 62 |
?> |
| 63 |
value="<?php |
| 64 |
echo esc_attr(Setting::get($this->getKey())); |
| 65 |
?>" |
| 66 |
> |
| 67 |
<?php |
| 68 |
if ($this->description): ?> |
| 69 |
<p class="mt-2 text-sm text-gray-500"> |
| 70 |
<?php echo esc_html($this->description); ?> |
| 71 |
</p> |
| 72 |
<?php endif; |
| 73 |
} |
| 74 |
|
| 75 |
public function type(string $type): self |
| 76 |
{ |
| 77 |
$this->type = $type; |
| 78 |
|
| 79 |
return $this; |
| 80 |
} |
| 81 |
|
| 82 |
public function autofocus(): self |
| 83 |
{ |
| 84 |
$this->autofocus = true; |
| 85 |
|
| 86 |
return $this; |
| 87 |
} |
| 88 |
} |
| 89 |
|