Debian Codegraph @

node/@patternfly/patternfly/docs/components/DatePicker/examples/DatePicker.md

raw
1 ---
2 id: 'Date picker'
3 section: components
4 subsection: date-and-time
5 cssPrefix: pf-v6-c-date-picker
6 ---import './DatePicker.css'
7
8 ## Examples
9
10 ### Basic
11
12 ```html
13 <div class="pf-v6-c-date-picker">
14 <div class="pf-v6-c-date-picker__input">
15 <div class="pf-v6-c-input-group">
16 <div class="pf-v6-c-input-group__item pf-m-fill">
17 <span class="pf-v6-c-form-control">
18 <input
19 type="text"
20 value="2020-03-05"
21 id="basic-input"
22 name="basic-input"
23 aria-label="Date picker"
24 />
25 </span>
26 </div>
27 <div class="pf-v6-c-input-group__item">
28 <button
29 class="pf-v6-c-button pf-m-control"
30 type="button"
31 aria-label="Toggle date picker"
32 >
33 <span class="pf-v6-c-button__icon">
34 <svg
35 class="pf-v6-svg"
36 fill="currentColor"
37 viewBox="0 0 448 512"
38 aria-hidden="true"
39 role="img"
40 width="1em"
41 height="1em"
42 >
43 <path
44 d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"
45 />
46 </svg>
47 </span>
48 </button>
49 </div>
50 </div>
51 </div>
52 </div>
53
54 ```
55
56 ### Helper text
57
58 ```html
59 <div class="pf-v6-c-date-picker">
60 <div class="pf-v6-c-date-picker__input">
61 <div class="pf-v6-c-input-group">
62 <div class="pf-v6-c-input-group__item pf-m-fill">
63 <span class="pf-v6-c-form-control">
64 <input
65 type="text"
66 value="2020-03-05"
67 id="helper-text-input"
68 name="helper-text-input"
69 aria-label="Date picker"
70 />
71 </span>
72 </div>
73 <div class="pf-v6-c-input-group__item">
74 <button
75 class="pf-v6-c-button pf-m-control"
76 type="button"
77 aria-label="Toggle date picker"
78 >
79 <span class="pf-v6-c-button__icon">
80 <svg
81 class="pf-v6-svg"
82 fill="currentColor"
83 viewBox="0 0 448 512"
84 aria-hidden="true"
85 role="img"
86 width="1em"
87 height="1em"
88 >
89 <path
90 d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"
91 />
92 </svg>
93 </span>
94 </button>
95 </div>
96 </div>
97 </div>
98 <div class="pf-v6-c-date-picker__helper-text">
99 <div class="pf-v6-c-helper-text">
100 <div class="pf-v6-c-helper-text__item">
101 <span class="pf-v6-c-helper-text__item-text">Select a date</span>
102 </div>
103 </div>
104 </div>
105 </div>
106
107 ```
108
109 ### Invalid
110
111 ```html
112 <div class="pf-v6-c-date-picker">
113 <div class="pf-v6-c-date-picker__input">
114 <div class="pf-v6-c-input-group">
115 <div class="pf-v6-c-input-group__item pf-m-fill">
116 <span class="pf-v6-c-form-control pf-m-error">
117 <input
118 aria-invalid="true"
119 type="text"
120 value="2020-03-05"
121 id="invalid-input"
122 name="invalid-input"
123 aria-label="Date picker"
124 />
125 <span class="pf-v6-c-form-control__utilities">
126 <span class="pf-v6-c-form-control__icon pf-m-status">
127 <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
128 </span>
129 </span>
130 </span>
131 </div>
132 <div class="pf-v6-c-input-group__item">
133 <button
134 class="pf-v6-c-button pf-m-control"
135 type="button"
136 aria-label="Toggle date picker"
137 >
138 <span class="pf-v6-c-button__icon">
139 <svg
140 class="pf-v6-svg"
141 fill="currentColor"
142 viewBox="0 0 448 512"
143 aria-hidden="true"
144 role="img"
145 width="1em"
146 height="1em"
147 >
148 <path
149 d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"
150 />
151 </svg>
152 </span>
153 </button>
154 </div>
155 </div>
156 </div>
157 <div class="pf-v6-c-date-picker__helper-text">
158 <div class="pf-v6-c-helper-text">
159 <div class="pf-v6-c-helper-text__item pf-m-error">
160 <span class="pf-v6-c-helper-text__item-icon">
161 <i class="fas fa-fw fa-exclamation-circle" aria-hidden="true"></i>
162 </span>
163 <span class="pf-v6-c-helper-text__item-text">
164 <span class="pf-v6-screen-reader">Error:</span>
165 Invalid date
166 </span>
167 </div>
168 </div>
169 </div>
170 </div>
171
172 ```
173
174 ### Expanded
175
176 ```html
177 <div class="pf-v6-c-date-picker">
178 <div class="pf-v6-c-date-picker__input">
179 <div class="pf-v6-c-input-group">
180 <div class="pf-v6-c-input-group__item pf-m-fill">
181 <span class="pf-v6-c-form-control">
182 <input
183 type="text"
184 value="2020-03-05"
185 id="expanded-input"
186 name="expanded-input"
187 aria-label="Date picker"
188 />
189 </span>
190 </div>
191 <div class="pf-v6-c-input-group__item">
192 <button
193 class="pf-v6-c-button pf-m-control"
194 type="button"
195 aria-label="Toggle date picker"
196 >
197 <span class="pf-v6-c-button__icon">
198 <svg
199 class="pf-v6-svg"
200 fill="currentColor"
201 viewBox="0 0 448 512"
202 aria-hidden="true"
203 role="img"
204 width="1em"
205 height="1em"
206 >
207 <path
208 d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"
209 />
210 </svg>
211 </span>
212 </button>
213 </div>
214 </div>
215 </div>
216 <div class="pf-v6-c-date-picker__calendar">Calendar</div>
217 </div>
218
219 ```
220
221 ### Custom width input
222
223 ```html
224 <div
225 class="pf-v6-c-date-picker"
226 style="--pf-v6-c-date-picker__input--c-form-control--Width: 220px;"
227 >
228 <div class="pf-v6-c-date-picker__input">
229 <div class="pf-v6-c-input-group">
230 <div class="pf-v6-c-input-group__item pf-m-fill">
231 <span class="pf-v6-c-form-control">
232 <input
233 type="text"
234 value="November 20, 2020"
235 id="custom-width-input-input"
236 name="custom-width-input-input"
237 aria-label="Date picker"
238 />
239 </span>
240 </div>
241 <div class="pf-v6-c-input-group__item">
242 <button
243 class="pf-v6-c-button pf-m-control"
244 type="button"
245 aria-label="Toggle date picker"
246 >
247 <span class="pf-v6-c-button__icon">
248 <svg
249 class="pf-v6-svg"
250 fill="currentColor"
251 viewBox="0 0 448 512"
252 aria-hidden="true"
253 role="img"
254 width="1em"
255 height="1em"
256 >
257 <path
258 d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"
259 />
260 </svg>
261 </span>
262 </button>
263 </div>
264 </div>
265 </div>
266 </div>
267
268 ```
269
270 ### Custom width input based on number of characters
271
272 ```html
273 <div
274 class="pf-v6-c-date-picker"
275 style="--pf-v6-c-date-picker__input--c-form-control--width-chars: 18;"
276 >
277 <div class="pf-v6-c-date-picker__input">
278 <div class="pf-v6-c-input-group">
279 <div class="pf-v6-c-input-group__item pf-m-fill">
280 <span class="pf-v6-c-form-control">
281 <input
282 type="text"
283 value="November 20, 2020"
284 id="custom-width-input-based-on-number-of-characters-input"
285 name="custom-width-input-based-on-number-of-characters-input"
286 aria-label="Date picker"
287 />
288 </span>
289 </div>
290 <div class="pf-v6-c-input-group__item">
291 <button
292 class="pf-v6-c-button pf-m-control"
293 type="button"
294 aria-label="Toggle date picker"
295 >
296 <span class="pf-v6-c-button__icon">
297 <svg
298 class="pf-v6-svg"
299 fill="currentColor"
300 viewBox="0 0 448 512"
301 aria-hidden="true"
302 role="img"
303 width="1em"
304 height="1em"
305 >
306 <path
307 d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"
308 />
309 </svg>
310 </span>
311 </button>
312 </div>
313 </div>
314 </div>
315 </div>
316
317 ```
318
319 ## Documentation
320
321 ### Usage
322
323 | Class | Applied to | Outcome |
324 | -- | -- | -- |
325 | `.pf-v6-c-date-picker` | `<div>` | Initiates the date picker component. **Required** |
326 | `.pf-v6-c-date-picker__input` | `<div>` | Initiates the date picker input container. **Required** |
327 | `.pf-v6-c-date-picker__helper-text` | `<div>` | Initiates the date picker helper text. |
328 | `.pf-v6-c-date-picker__calendar` | `<div>` | Initiates an optional date picker calendar container. **Note:** Required in the react date picker component. |
329 | `.pf-m-top` | `.pf-v6-c-date-picker` | Modifies to display the calendar above the date picker. |
330 | `.pf-m-align-right` | `.pf-v6-c-date-picker__calendar` | Modifies the calendar to align the calendar to the right edge of the date picker. |
331 | `.pf-m-static` | `.pf-v6-c-date-picker__calendar` | Modifies the calendar to be statically positioned to support custom positioning. |