-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.php
79 lines (71 loc) · 2.6 KB
/
Input.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
if (!enum_exists(InputType::class)) {
enum InputType: string {
case Text = 'text';
case Number = 'number';
case Password = 'password';
case Date = 'date';
case Month = 'month';
case Tel = 'tel';
case Email = 'email';
case Search = 'search';
}
}
assert(is_string($validacion));
assert(is_string($name));
assert(is_string($placeholder));
$min = isset($min) ? (int) $min : null;
$max = isset($max) ? (int) $max : null;
$minlength = isset($minlength) ? (string) $minlength : null;
$maxlength = isset($maxlength) ? (string) $maxlength : null;
$value = isset($value) ? (string) $value : null;
$pattern = isset($pattern) ? (string) $pattern : null;
$required = isset($required) ? (bool) $required : true;
$readonly = isset($readonly) ? (bool) $readonly : false;
$disabled = isset($disabled) ? (bool) $disabled : false;
$class = isset($class) ? (string) $class : null;
$list = isset($list) ? (string) $list : null;
$onchange = isset($onchange) ? (string) $onchange : null;
$onblur = isset($onblur) ? (string) $onblur : null;
$onkeydown = isset($onkeydown) ? (string) $onkeydown : null;
$onkeyup = isset($onkeyup) ? (string) $onkeyup : null;
$type = (isset($type) and is_string($type))
? InputType::from($type)
: InputType::Text;
$id = uniqid('input-password-');
?>
<label
class="input-group input-group--with-validation <?= $disabled ? 'input-group--disabled' : '' ?> <?= $required ? 'input-group--required' : 'input-group--optional' ?> <?= $class ?>"
data-validate="<?= $validacion ?>">
<input
list="<?= $list ?>"
<?= $readonly ? 'readonly' : '' ?>
<?= $disabled ? 'disabled' : '' ?>
type="<?= $type->value ?>"
<?= $required ? 'required' : '' ?>
class="input-group__input"
name="<?= $name ?>"
placeholder="<?= $placeholder ?>"
value="<?= $value ?>"
onchange="<?= $onchange ?>"
onblur="<?= $onblur ?>"
onkeydown="<?= $onkeydown ?>"
onkeyup="<?= $onkeyup ?>"
<?= $min !== null ? "min='$min'" : '' ?>
<?= $max ? "max='$max'" : '' ?>
<?= $minlength ? "minlength='$minlength'" : '' ?>
<?= $maxlength ? "maxlength='$maxlength'" : '' ?>
<?= $pattern ? "pattern='$pattern'" : '' ?>
title='<?= $validacion ?>'
/>
<span class="input-group__focus"></span>
<span class="input-group__label"><?= $placeholder ?></span>
</label>
<?php if ($type === InputType::Password): ?>
<div class="form-check px-4 mb-4 mostrar-clave" style="user-select: none">
<input class="form-check-input" type="checkbox" id="<?= $id ?>">
<label for="<?= $id ?>" style="display: inline-block">
Mostrar contraseña
</label>
</div>
<?php endif ?>