@abraracs/better-shopify-wc-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +325 -0
- package/docs/avatar.md +481 -0
- package/docs/badge.md +266 -0
- package/docs/banner.md +350 -0
- package/docs/box.md +618 -0
- package/docs/button.md +604 -0
- package/docs/buttongroup.md +251 -0
- package/docs/checkbox.md +346 -0
- package/docs/chip.md +261 -0
- package/docs/choicelist.md +416 -0
- package/docs/clickable.md +703 -0
- package/docs/clickablechip.md +377 -0
- package/docs/colorfield.md +416 -0
- package/docs/colorpicker.md +152 -0
- package/docs/datefield.md +706 -0
- package/docs/datepicker.md +443 -0
- package/docs/divider.md +263 -0
- package/docs/dropzone.md +331 -0
- package/docs/emailfield.md +377 -0
- package/docs/grid.md +1246 -0
- package/docs/heading.md +201 -0
- package/docs/icon.md +295 -0
- package/docs/image.md +517 -0
- package/docs/link.md +456 -0
- package/docs/menu.md +331 -0
- package/docs/modal.md +640 -0
- package/docs/moneyfield.md +385 -0
- package/docs/numberfield.md +393 -0
- package/docs/orderedlist.md +224 -0
- package/docs/page.md +319 -0
- package/docs/paragraph.md +333 -0
- package/docs/passwordfield.md +381 -0
- package/docs/popover.md +419 -0
- package/docs/querycontainer.md +121 -0
- package/docs/searchfield.md +319 -0
- package/docs/section.md +267 -0
- package/docs/select.md +449 -0
- package/docs/spinner.md +121 -0
- package/docs/stack.md +748 -0
- package/docs/switch.md +365 -0
- package/docs/table.md +805 -0
- package/docs/text.md +339 -0
- package/docs/textarea.md +328 -0
- package/docs/textfield.md +425 -0
- package/docs/thumbnail.md +245 -0
- package/docs/tooltip.md +130 -0
- package/docs/unorderedlist.md +135 -0
- package/docs/urlfield.md +314 -0
- package/package.json +43 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: DateField
|
|
3
|
+
description: Allow users to select a specific date with a date picker.
|
|
4
|
+
api_name: app-home
|
|
5
|
+
source_url:
|
|
6
|
+
html: 'https://shopify.dev/docs/api/app-home/polaris-web-components/forms/datefield'
|
|
7
|
+
md: >-
|
|
8
|
+
https://shopify.dev/docs/api/app-home/polaris-web-components/forms/datefield.md
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# DateField
|
|
12
|
+
|
|
13
|
+
Allow users to select a specific date with a date picker.
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
* allow
|
|
18
|
+
|
|
19
|
+
string
|
|
20
|
+
|
|
21
|
+
Default: ""
|
|
22
|
+
|
|
23
|
+
Dates that can be selected.
|
|
24
|
+
|
|
25
|
+
A comma-separated list of dates, date ranges. Whitespace is allowed after commas.
|
|
26
|
+
|
|
27
|
+
The default `''` allows all dates.
|
|
28
|
+
|
|
29
|
+
* Dates in `YYYY-MM-DD` format allow a single date.
|
|
30
|
+
|
|
31
|
+
* Dates in `YYYY-MM` format allow a whole month.
|
|
32
|
+
|
|
33
|
+
* Dates in `YYYY` format allow a whole year.
|
|
34
|
+
|
|
35
|
+
* Ranges are expressed as `start--end`. - Ranges are inclusive.
|
|
36
|
+
|
|
37
|
+
* If either `start` or `end` is omitted, the range is unbounded in that direction.
|
|
38
|
+
* If parts of the date are omitted for `start`, they are assumed to be the minimum possible value. So `2024--` is equivalent to `2024-01-01--`.
|
|
39
|
+
* If parts of the date are omitted for `end`, they are assumed to be the maximum possible value. So `--2024` is equivalent to `--2024-12-31`.
|
|
40
|
+
* Whitespace is allowed either side of `--`.
|
|
41
|
+
|
|
42
|
+
* allowDays
|
|
43
|
+
|
|
44
|
+
string
|
|
45
|
+
|
|
46
|
+
Default: ""
|
|
47
|
+
|
|
48
|
+
Days of the week that can be selected. These intersect with the result of `allow` and `disallow`.
|
|
49
|
+
|
|
50
|
+
A comma-separated list of days. Whitespace is allowed after commas.
|
|
51
|
+
|
|
52
|
+
The default `''` has no effect on the result of `allow` and `disallow`.
|
|
53
|
+
|
|
54
|
+
Days are `sunday`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`.
|
|
55
|
+
|
|
56
|
+
* autocomplete
|
|
57
|
+
|
|
58
|
+
DateAutocompleteField
|
|
59
|
+
|
|
60
|
+
Default: 'on' for everything else
|
|
61
|
+
|
|
62
|
+
A hint as to the intended content of the field.
|
|
63
|
+
|
|
64
|
+
When set to `on` (the default), this property indicates that the field should support autofill, but you do not have any more semantic information on the intended contents.
|
|
65
|
+
|
|
66
|
+
When set to `off`, you are indicating that this field contains sensitive information, or contents that are never saved, like one-time codes.
|
|
67
|
+
|
|
68
|
+
Alternatively, you can provide value which describes the specific data you would like to be entered into this field during autofill.
|
|
69
|
+
|
|
70
|
+
* defaultValue
|
|
71
|
+
|
|
72
|
+
string
|
|
73
|
+
|
|
74
|
+
The default value for the field.
|
|
75
|
+
|
|
76
|
+
* defaultView
|
|
77
|
+
|
|
78
|
+
string
|
|
79
|
+
|
|
80
|
+
Default month to display in `YYYY-MM` format.
|
|
81
|
+
|
|
82
|
+
This value is used until `view` is set, either directly or as a result of user interaction.
|
|
83
|
+
|
|
84
|
+
Defaults to the current month in the user's locale.
|
|
85
|
+
|
|
86
|
+
* details
|
|
87
|
+
|
|
88
|
+
string
|
|
89
|
+
|
|
90
|
+
Additional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user.
|
|
91
|
+
|
|
92
|
+
This will also be exposed to screen reader users.
|
|
93
|
+
|
|
94
|
+
* disabled
|
|
95
|
+
|
|
96
|
+
boolean
|
|
97
|
+
|
|
98
|
+
Default: false
|
|
99
|
+
|
|
100
|
+
Disables the field, disallowing any interaction.
|
|
101
|
+
|
|
102
|
+
* disallow
|
|
103
|
+
|
|
104
|
+
string
|
|
105
|
+
|
|
106
|
+
Default: ""
|
|
107
|
+
|
|
108
|
+
Dates that cannot be selected. These subtract from `allow`.
|
|
109
|
+
|
|
110
|
+
A comma-separated list of dates, date ranges. Whitespace is allowed after commas.
|
|
111
|
+
|
|
112
|
+
The default `''` has no effect on `allow`.
|
|
113
|
+
|
|
114
|
+
* Dates in `YYYY-MM-DD` format disallow a single date.
|
|
115
|
+
|
|
116
|
+
* Dates in `YYYY-MM` format disallow a whole month.
|
|
117
|
+
|
|
118
|
+
* Dates in `YYYY` format disallow a whole year.
|
|
119
|
+
|
|
120
|
+
* Ranges are expressed as `start--end`. - Ranges are inclusive.
|
|
121
|
+
|
|
122
|
+
* If either `start` or `end` is omitted, the range is unbounded in that direction.
|
|
123
|
+
* If parts of the date are omitted for `start`, they are assumed to be the minimum possible value. So `2024--` is equivalent to `2024-01-01--`.
|
|
124
|
+
* If parts of the date are omitted for `end`, they are assumed to be the maximum possible value. So `--2024` is equivalent to `--2024-12-31`.
|
|
125
|
+
* Whitespace is allowed either side of `--`.
|
|
126
|
+
|
|
127
|
+
* disallowDays
|
|
128
|
+
|
|
129
|
+
string
|
|
130
|
+
|
|
131
|
+
Default: ""
|
|
132
|
+
|
|
133
|
+
Days of the week that cannot be selected. This subtracts from `allowDays`, and intersects with the result of `allow` and `disallow`.
|
|
134
|
+
|
|
135
|
+
A comma-separated list of days. Whitespace is allowed after commas.
|
|
136
|
+
|
|
137
|
+
The default `''` has no effect on `allowDays`.
|
|
138
|
+
|
|
139
|
+
Days are `sunday`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`.
|
|
140
|
+
|
|
141
|
+
* error
|
|
142
|
+
|
|
143
|
+
string
|
|
144
|
+
|
|
145
|
+
Indicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately.
|
|
146
|
+
|
|
147
|
+
* id
|
|
148
|
+
|
|
149
|
+
string
|
|
150
|
+
|
|
151
|
+
A unique identifier for the element.
|
|
152
|
+
|
|
153
|
+
* label
|
|
154
|
+
|
|
155
|
+
string
|
|
156
|
+
|
|
157
|
+
Content to use as the field label.
|
|
158
|
+
|
|
159
|
+
* labelAccessibilityVisibility
|
|
160
|
+
|
|
161
|
+
"visible" | "exclusive"
|
|
162
|
+
|
|
163
|
+
Default: 'visible'
|
|
164
|
+
|
|
165
|
+
Changes the visibility of the component's label.
|
|
166
|
+
|
|
167
|
+
* `visible`: the label is visible to all users.
|
|
168
|
+
* `exclusive`: the label is visually hidden but remains in the accessibility tree.
|
|
169
|
+
|
|
170
|
+
* name
|
|
171
|
+
|
|
172
|
+
string
|
|
173
|
+
|
|
174
|
+
An identifier for the field that is unique within the nearest containing form.
|
|
175
|
+
|
|
176
|
+
* placeholder
|
|
177
|
+
|
|
178
|
+
string
|
|
179
|
+
|
|
180
|
+
A short hint that describes the expected value of the field.
|
|
181
|
+
|
|
182
|
+
* readOnly
|
|
183
|
+
|
|
184
|
+
boolean
|
|
185
|
+
|
|
186
|
+
Default: false
|
|
187
|
+
|
|
188
|
+
The field cannot be edited by the user. It is focusable will be announced by screen readers.
|
|
189
|
+
|
|
190
|
+
* required
|
|
191
|
+
|
|
192
|
+
boolean
|
|
193
|
+
|
|
194
|
+
Default: false
|
|
195
|
+
|
|
196
|
+
Whether the field needs a value. This requirement adds semantic value to the field, but it will not cause an error to appear automatically. If you want to present an error when this field is empty, you can do so with the `error` property.
|
|
197
|
+
|
|
198
|
+
* value
|
|
199
|
+
|
|
200
|
+
string
|
|
201
|
+
|
|
202
|
+
The current value for the field. If omitted, the field will be empty.
|
|
203
|
+
|
|
204
|
+
* view
|
|
205
|
+
|
|
206
|
+
string
|
|
207
|
+
|
|
208
|
+
Displayed month in `YYYY-MM` format.
|
|
209
|
+
|
|
210
|
+
`onViewChange` is called when this value changes.
|
|
211
|
+
|
|
212
|
+
Defaults to `defaultView`.
|
|
213
|
+
|
|
214
|
+
### DateAutocompleteField
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
'bday-day' | 'bday-month' | 'bday-year' | 'bday' | 'cc-expiry-month' | 'cc-expiry-year' | 'cc-expiry'
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Events
|
|
221
|
+
|
|
222
|
+
Learn more about [registering events](https://shopify.dev/docs/api/app-home/using-polaris-components#event-handling).
|
|
223
|
+
|
|
224
|
+
* blur
|
|
225
|
+
|
|
226
|
+
CallbackEventListener<'input'>
|
|
227
|
+
|
|
228
|
+
* change
|
|
229
|
+
|
|
230
|
+
CallbackEventListener<'input'>
|
|
231
|
+
|
|
232
|
+
* focus
|
|
233
|
+
|
|
234
|
+
CallbackEventListener<'input'>
|
|
235
|
+
|
|
236
|
+
* input
|
|
237
|
+
|
|
238
|
+
CallbackEventListener<'input'>
|
|
239
|
+
|
|
240
|
+
* invalid
|
|
241
|
+
|
|
242
|
+
CallbackEventListener\<typeof tagName> | null
|
|
243
|
+
|
|
244
|
+
* viewchange
|
|
245
|
+
|
|
246
|
+
CallbackEventListener\<typeof tagName> | null
|
|
247
|
+
|
|
248
|
+
### CallbackEventListener
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
(EventListener & {
|
|
252
|
+
(event: CallbackEvent<T>): void;
|
|
253
|
+
}) | null
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### CallbackEvent
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
Event & {
|
|
260
|
+
currentTarget: HTMLElementTagNameMap[T];
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Examples
|
|
265
|
+
|
|
266
|
+
### Examples
|
|
267
|
+
|
|
268
|
+
* #### Code
|
|
269
|
+
|
|
270
|
+
##### jsx
|
|
271
|
+
|
|
272
|
+
```jsx
|
|
273
|
+
<s-date-field defaultView="2025-09" defaultValue="2025-09-01" />
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
##### html
|
|
277
|
+
|
|
278
|
+
```html
|
|
279
|
+
<s-date-field defaultView="2025-09" defaultValue="2025-09-01"></s-date-field>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
* #### Basic usage
|
|
283
|
+
|
|
284
|
+
##### Description
|
|
285
|
+
|
|
286
|
+
Simple date field for collecting a single date with a descriptive label.
|
|
287
|
+
|
|
288
|
+
##### jsx
|
|
289
|
+
|
|
290
|
+
```jsx
|
|
291
|
+
<s-date-field
|
|
292
|
+
label="Order date"
|
|
293
|
+
name="orderDate"
|
|
294
|
+
placeholder="Select date"
|
|
295
|
+
/>
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
##### html
|
|
299
|
+
|
|
300
|
+
```html
|
|
301
|
+
<s-date-field
|
|
302
|
+
label="Order date"
|
|
303
|
+
name="orderDate"
|
|
304
|
+
placeholder="Select date"
|
|
305
|
+
></s-date-field>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
* #### With default value
|
|
309
|
+
|
|
310
|
+
##### Description
|
|
311
|
+
|
|
312
|
+
Date field pre-populated with a specific date for editing existing data.
|
|
313
|
+
|
|
314
|
+
##### jsx
|
|
315
|
+
|
|
316
|
+
```jsx
|
|
317
|
+
<s-date-field
|
|
318
|
+
label="Shipping date"
|
|
319
|
+
name="shippingDate"
|
|
320
|
+
value="2024-03-15"
|
|
321
|
+
/>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
##### html
|
|
325
|
+
|
|
326
|
+
```html
|
|
327
|
+
<s-date-field
|
|
328
|
+
label="Shipping date"
|
|
329
|
+
name="shippingDate"
|
|
330
|
+
value="2024-03-15"
|
|
331
|
+
></s-date-field>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
* #### With date restrictions
|
|
335
|
+
|
|
336
|
+
##### Description
|
|
337
|
+
|
|
338
|
+
Shows how to restrict selectable dates to weekdays only.
|
|
339
|
+
|
|
340
|
+
##### jsx
|
|
341
|
+
|
|
342
|
+
```jsx
|
|
343
|
+
<s-date-field
|
|
344
|
+
label="Delivery date"
|
|
345
|
+
name="deliveryDate"
|
|
346
|
+
disallowDays="[0, 6]"
|
|
347
|
+
details="Delivery available Monday through Friday only"
|
|
348
|
+
/>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
##### html
|
|
352
|
+
|
|
353
|
+
```html
|
|
354
|
+
<s-date-field
|
|
355
|
+
label="Delivery date"
|
|
356
|
+
name="deliveryDate"
|
|
357
|
+
disallowDays="[0, 6]"
|
|
358
|
+
details="Delivery available Monday through Friday only"
|
|
359
|
+
></s-date-field>
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
* #### With specific allowed dates
|
|
363
|
+
|
|
364
|
+
##### Description
|
|
365
|
+
|
|
366
|
+
Demonstrates allowing only specific dates from a predefined list.
|
|
367
|
+
|
|
368
|
+
##### jsx
|
|
369
|
+
|
|
370
|
+
```jsx
|
|
371
|
+
<s-date-field
|
|
372
|
+
label="Available appointment dates"
|
|
373
|
+
name="appointmentDate"
|
|
374
|
+
allow='["2024-03-20", "2024-03-22", "2024-03-25", "2024-03-27"]'
|
|
375
|
+
details="Select from available time slots"
|
|
376
|
+
/>
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
##### html
|
|
380
|
+
|
|
381
|
+
```html
|
|
382
|
+
<s-date-field
|
|
383
|
+
label="Available appointment dates"
|
|
384
|
+
name="appointmentDate"
|
|
385
|
+
allow='["2024-03-20", "2024-03-22", "2024-03-25", "2024-03-27"]'
|
|
386
|
+
details="Select from available time slots"
|
|
387
|
+
></s-date-field>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
* #### With error state
|
|
391
|
+
|
|
392
|
+
##### Description
|
|
393
|
+
|
|
394
|
+
Date field showing validation error for required field or invalid date entry.
|
|
395
|
+
|
|
396
|
+
##### jsx
|
|
397
|
+
|
|
398
|
+
```jsx
|
|
399
|
+
<s-date-field
|
|
400
|
+
label="Event date"
|
|
401
|
+
error="Event date is required"
|
|
402
|
+
required
|
|
403
|
+
/>
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
##### html
|
|
407
|
+
|
|
408
|
+
```html
|
|
409
|
+
<s-date-field
|
|
410
|
+
label="Event date"
|
|
411
|
+
name="eventDate"
|
|
412
|
+
required
|
|
413
|
+
error="Select a valid event date"
|
|
414
|
+
></s-date-field>
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
* #### Disabled and read-only states
|
|
418
|
+
|
|
419
|
+
##### Description
|
|
420
|
+
|
|
421
|
+
Shows date fields in different interaction states for viewing-only or disabled forms.
|
|
422
|
+
|
|
423
|
+
##### jsx
|
|
424
|
+
|
|
425
|
+
```jsx
|
|
426
|
+
<s-stack gap="base">
|
|
427
|
+
<s-date-field
|
|
428
|
+
label="Creation date"
|
|
429
|
+
name="createdDate"
|
|
430
|
+
value="2024-01-01"
|
|
431
|
+
readOnly
|
|
432
|
+
/>
|
|
433
|
+
|
|
434
|
+
<s-date-field
|
|
435
|
+
label="Archived date"
|
|
436
|
+
name="archivedDate"
|
|
437
|
+
value="2024-02-15"
|
|
438
|
+
disabled
|
|
439
|
+
/>
|
|
440
|
+
</s-stack>
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
##### html
|
|
444
|
+
|
|
445
|
+
```html
|
|
446
|
+
<s-stack gap="base">
|
|
447
|
+
<s-date-field
|
|
448
|
+
label="Creation date"
|
|
449
|
+
name="createdDate"
|
|
450
|
+
value="2024-01-01"
|
|
451
|
+
readOnly
|
|
452
|
+
></s-date-field>
|
|
453
|
+
|
|
454
|
+
<s-date-field
|
|
455
|
+
label="Archived date"
|
|
456
|
+
name="archivedDate"
|
|
457
|
+
value="2024-02-15"
|
|
458
|
+
disabled
|
|
459
|
+
></s-date-field>
|
|
460
|
+
</s-stack>
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
* #### Form integration
|
|
464
|
+
|
|
465
|
+
##### Description
|
|
466
|
+
|
|
467
|
+
Complete form example showing date field with other form elements.
|
|
468
|
+
|
|
469
|
+
##### jsx
|
|
470
|
+
|
|
471
|
+
```jsx
|
|
472
|
+
<form>
|
|
473
|
+
<s-stack gap="base">
|
|
474
|
+
<s-text-field
|
|
475
|
+
label="Customer name"
|
|
476
|
+
name="customerName"
|
|
477
|
+
required
|
|
478
|
+
/>
|
|
479
|
+
|
|
480
|
+
<s-date-field
|
|
481
|
+
label="Order date"
|
|
482
|
+
name="orderDate"
|
|
483
|
+
value="2024-03-15"
|
|
484
|
+
required
|
|
485
|
+
/>
|
|
486
|
+
|
|
487
|
+
<s-date-field
|
|
488
|
+
label="Requested delivery date"
|
|
489
|
+
name="deliveryDate"
|
|
490
|
+
disallowDays="[0, 6]"
|
|
491
|
+
details="Weekdays only"
|
|
492
|
+
/>
|
|
493
|
+
|
|
494
|
+
<s-button type="submit" variant="primary">
|
|
495
|
+
Process order
|
|
496
|
+
</s-button>
|
|
497
|
+
</s-stack>
|
|
498
|
+
</form>
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
##### html
|
|
502
|
+
|
|
503
|
+
```html
|
|
504
|
+
<form>
|
|
505
|
+
<s-stack gap="base">
|
|
506
|
+
<s-text-field
|
|
507
|
+
label="Customer name"
|
|
508
|
+
name="customerName"
|
|
509
|
+
required
|
|
510
|
+
></s-text-field>
|
|
511
|
+
|
|
512
|
+
<s-date-field
|
|
513
|
+
label="Order date"
|
|
514
|
+
name="orderDate"
|
|
515
|
+
value="2024-03-15"
|
|
516
|
+
required
|
|
517
|
+
></s-date-field>
|
|
518
|
+
|
|
519
|
+
<s-date-field
|
|
520
|
+
label="Requested delivery date"
|
|
521
|
+
name="deliveryDate"
|
|
522
|
+
disallowDays="[0, 6]"
|
|
523
|
+
details="Weekdays only"
|
|
524
|
+
></s-date-field>
|
|
525
|
+
|
|
526
|
+
<s-button type="submit" variant="primary">Process order</s-button>
|
|
527
|
+
</s-stack>
|
|
528
|
+
</form>
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
* #### Date range selection
|
|
532
|
+
|
|
533
|
+
##### Description
|
|
534
|
+
|
|
535
|
+
Example showing two date fields for selecting a date range.
|
|
536
|
+
|
|
537
|
+
##### jsx
|
|
538
|
+
|
|
539
|
+
```jsx
|
|
540
|
+
<s-stack gap="base">
|
|
541
|
+
<s-heading>Sales report period</s-heading>
|
|
542
|
+
|
|
543
|
+
<s-stack direction="inline" gap="base">
|
|
544
|
+
<s-date-field
|
|
545
|
+
label="Start date"
|
|
546
|
+
name="startDate"
|
|
547
|
+
id="report-start"
|
|
548
|
+
/>
|
|
549
|
+
|
|
550
|
+
<s-date-field
|
|
551
|
+
label="End date"
|
|
552
|
+
name="endDate"
|
|
553
|
+
id="report-end"
|
|
554
|
+
/>
|
|
555
|
+
</s-stack>
|
|
556
|
+
|
|
557
|
+
<s-button variant="primary">Generate report</s-button>
|
|
558
|
+
</s-stack>
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
##### html
|
|
562
|
+
|
|
563
|
+
```html
|
|
564
|
+
<s-stack gap="base">
|
|
565
|
+
<s-heading>Sales report period</s-heading>
|
|
566
|
+
|
|
567
|
+
<s-stack direction="inline" gap="base">
|
|
568
|
+
<s-date-field
|
|
569
|
+
label="Start date"
|
|
570
|
+
name="startDate"
|
|
571
|
+
id="report-start"
|
|
572
|
+
></s-date-field>
|
|
573
|
+
|
|
574
|
+
<s-date-field
|
|
575
|
+
label="End date"
|
|
576
|
+
name="endDate"
|
|
577
|
+
id="report-end"
|
|
578
|
+
></s-date-field>
|
|
579
|
+
</s-stack>
|
|
580
|
+
|
|
581
|
+
<s-button variant="primary">Generate report</s-button>
|
|
582
|
+
</s-stack>
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
* #### Date fields with validation
|
|
586
|
+
|
|
587
|
+
##### Description
|
|
588
|
+
|
|
589
|
+
Demonstrates date fields with business logic restrictions and validation.
|
|
590
|
+
|
|
591
|
+
##### jsx
|
|
592
|
+
|
|
593
|
+
```jsx
|
|
594
|
+
<s-section>
|
|
595
|
+
<s-heading>Promotion settings</s-heading>
|
|
596
|
+
<s-stack gap="base">
|
|
597
|
+
<s-text-field
|
|
598
|
+
label="Promotion name"
|
|
599
|
+
name="promoName"
|
|
600
|
+
value="Spring sale"
|
|
601
|
+
/>
|
|
602
|
+
|
|
603
|
+
<s-date-field
|
|
604
|
+
label="Start date"
|
|
605
|
+
name="promoStart"
|
|
606
|
+
value="2024-04-01"
|
|
607
|
+
details="Promotion begins at midnight"
|
|
608
|
+
/>
|
|
609
|
+
|
|
610
|
+
<s-date-field
|
|
611
|
+
label="End date"
|
|
612
|
+
name="promoEnd"
|
|
613
|
+
value="2024-04-30"
|
|
614
|
+
details="Promotion ends at 11:59 PM"
|
|
615
|
+
/>
|
|
616
|
+
|
|
617
|
+
<s-checkbox
|
|
618
|
+
name="autoPublish"
|
|
619
|
+
label="Automatically publish on start date"
|
|
620
|
+
/>
|
|
621
|
+
</s-stack>
|
|
622
|
+
</s-section>
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
##### html
|
|
626
|
+
|
|
627
|
+
```html
|
|
628
|
+
<s-section>
|
|
629
|
+
<s-heading>Promotion settings</s-heading>
|
|
630
|
+
<s-stack gap="base">
|
|
631
|
+
<s-text-field
|
|
632
|
+
label="Promotion name"
|
|
633
|
+
name="promoName"
|
|
634
|
+
value="Spring sale"
|
|
635
|
+
></s-text-field>
|
|
636
|
+
|
|
637
|
+
<s-date-field
|
|
638
|
+
label="Start date"
|
|
639
|
+
name="promoStart"
|
|
640
|
+
value="2024-04-01"
|
|
641
|
+
details="Promotion begins at midnight"
|
|
642
|
+
></s-date-field>
|
|
643
|
+
|
|
644
|
+
<s-date-field
|
|
645
|
+
label="End date"
|
|
646
|
+
name="promoEnd"
|
|
647
|
+
value="2024-04-30"
|
|
648
|
+
details="Promotion ends at 11:59 PM"
|
|
649
|
+
></s-date-field>
|
|
650
|
+
|
|
651
|
+
<s-checkbox
|
|
652
|
+
name="autoPublish"
|
|
653
|
+
label="Automatically publish on start date"
|
|
654
|
+
></s-checkbox>
|
|
655
|
+
</s-stack>
|
|
656
|
+
</s-section>
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
* #### Date field validation
|
|
660
|
+
|
|
661
|
+
##### Description
|
|
662
|
+
|
|
663
|
+
Interactive example showing required date field validation with dynamic error messages.
|
|
664
|
+
|
|
665
|
+
##### jsx
|
|
666
|
+
|
|
667
|
+
```jsx
|
|
668
|
+
const [date, setDate] = useState('');
|
|
669
|
+
const [error, setError] = useState('Event date is required');
|
|
670
|
+
|
|
671
|
+
return (
|
|
672
|
+
<s-section>
|
|
673
|
+
<s-stack gap="base" justifyContent="start">
|
|
674
|
+
<s-text-field label="Event name" />
|
|
675
|
+
<s-date-field
|
|
676
|
+
label="Event date"
|
|
677
|
+
value={date}
|
|
678
|
+
error={error}
|
|
679
|
+
required
|
|
680
|
+
onChange={(e) => {
|
|
681
|
+
setDate(e.currentTarget.value);
|
|
682
|
+
setError(e.currentTarget.value ? '' : 'Event date is required');
|
|
683
|
+
}}
|
|
684
|
+
/>
|
|
685
|
+
</s-stack>
|
|
686
|
+
</s-section>
|
|
687
|
+
)
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
##### html
|
|
691
|
+
|
|
692
|
+
```html
|
|
693
|
+
<s-date-field
|
|
694
|
+
label="Event date"
|
|
695
|
+
name="eventDate"
|
|
696
|
+
required
|
|
697
|
+
error="Select a valid event date"
|
|
698
|
+
></s-date-field>
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
## Best practices
|
|
702
|
+
|
|
703
|
+
* Use smart defaults and highlight common selections
|
|
704
|
+
* Use `allow` and `disallow` properties to restrict selectable dates appropriately
|
|
705
|
+
* Provide clear labels and use details text to explain date restrictions
|
|
706
|
+
* Don't use for dates that are many years in the future or the past
|