-
Notifications
You must be signed in to change notification settings - Fork 554
/
DatePicker.php
129 lines (99 loc) · 2.71 KB
/
DatePicker.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace A17\Twill\Services\Forms\Fields;
use A17\Twill\Services\Forms\Fields\Traits\HasPlaceholder;
use A17\Twill\Services\Forms\Fields\Traits\IsTranslatable;
class DatePicker extends BaseFormField
{
use IsTranslatable;
use HasPlaceholder;
protected bool $withTime = true;
protected bool $allowInput = false;
protected bool $allowClear = false;
protected bool $timeOnly = false;
protected bool $time24Hr = false;
protected ?string $altFormat = null;
protected ?int $minuteIncrement = null;
protected ?int $hourIncrement = null;
public static function make(): static
{
return new self(
component: \A17\Twill\View\Components\Fields\DatePicker::class,
mandatoryProperties: ['name', 'label']
);
}
/**
* Hides the time picker.
*/
public function withoutTime(bool $withoutTime = true): static
{
$this->withTime = !$withoutTime;
return $this;
}
/**
* Allows manual input.
*/
public function allowInput(bool $allowInput = true): static
{
$this->allowInput = $allowInput;
return $this;
}
/**
* Allows to clear the input field.
*/
public function allowClear(bool $allowClear = true): static
{
$this->allowClear = $allowClear;
return $this;
}
/**
* Makes it a time picker only.
*/
public function timeOnly(bool $timeOnly = true): static
{
$this->withTime = true;
$this->timeOnly = $timeOnly;
$this->altFormat = $this->altFormat ?? (($this->time24Hr ?? false) ? 'H:i' : 'h:i K');
return $this;
}
/**
* If 24h format should be used.
*/
public function time24h(bool $time24h = true): static
{
$this->time24Hr = $time24h;
return $this;
}
/**
* If 24h format should be used.
* Added for docs and backwards compatibility
*/
public function time24hr(bool $time24hr = true): static
{
$this->time24Hr = $time24hr;
return $this;
}
/**
* Define a custom date format.
*/
public function altFormat(string $altFormat): static
{
$this->altFormat = $altFormat;
return $this;
}
/**
* Set how many hours are increment when using the + and - actions.
*/
public function hourIncrement(int $hourIncrement = 1): static
{
$this->hourIncrement = $hourIncrement;
return $this;
}
/**
* Set how many minutes are increment when using the + and - actions.
*/
public function minuteIncrement(int $minuteIncrement = 1): static
{
$this->minuteIncrement = $minuteIncrement;
return $this;
}
}