@@ -12,14 +12,27 @@ export type DateInputDemoContext = React.Context<
12
12
AppContextType < {
13
13
monthOnly ?: boolean ;
14
14
hasValue ?: boolean ;
15
+ readonly ?: boolean ;
16
+ disabled ?: boolean ;
17
+ inputFormat ?: DateInputProps . InputFormat | '' ;
18
+ format ?: DateInputProps . Format | '' ;
19
+ locale ?: DateInputProps [ 'locale' ] | '' ;
15
20
} >
16
21
> ;
17
22
18
23
export default function DateInputScenario ( ) {
19
24
const { urlParams, setUrlParams } = useContext ( AppContext as DateInputDemoContext ) ;
20
25
const initValue = '2025-02-14' ;
21
26
const hasValue = urlParams . hasValue ?? false ;
27
+ const inputFormat = urlParams . inputFormat ?? '' ;
28
+ const disabled = urlParams . disabled ?? false ;
29
+ const readonly = urlParams . readonly ?? false ;
30
+ const format = urlParams . format ?? '' ;
31
+ const locale = urlParams . locale ?? 'en-US' ;
32
+ const monthOnly = urlParams . monthOnly ?? false ;
22
33
const [ value , setValue ] = useState < DateInputProps [ 'value' ] > ( '' ) ;
34
+ const isIso = ( format === 'long-localized' && inputFormat === 'iso' ) || inputFormat === 'iso' ;
35
+ const inputFormatPlaceholderText = `YYYY${ isIso ? '-' : '/' } MM${ monthOnly ? `` : `${ isIso ? '-' : '/' } DD` } ` ;
23
36
24
37
useEffect ( ( ) => {
25
38
if ( hasValue ) {
@@ -37,14 +50,85 @@ export default function DateInputScenario() {
37
50
< Checkbox checked = { hasValue } onChange = { ( { detail } ) => setUrlParams ( { hasValue : detail . checked } ) } >
38
51
Has initial value
39
52
</ Checkbox >
53
+ < Checkbox checked = { readonly } onChange = { ( { detail } ) => setUrlParams ( { readonly : detail . checked } ) } >
54
+ Read-only
55
+ </ Checkbox >
56
+ < Checkbox checked = { disabled } onChange = { ( { detail } ) => setUrlParams ( { disabled : detail . checked } ) } >
57
+ Disabled
58
+ </ Checkbox >
59
+ < Checkbox checked = { monthOnly } onChange = { ( { detail } ) => setUrlParams ( { monthOnly : detail . checked } ) } >
60
+ Month-only
61
+ </ Checkbox >
62
+ < label >
63
+ Format
64
+ < select
65
+ value = { format }
66
+ onChange = { event =>
67
+ setUrlParams ( {
68
+ format : event . currentTarget . value as DateInputProps . InputFormat ,
69
+ } )
70
+ }
71
+ >
72
+ < option value = "slashed" > Slashed (Default)</ option >
73
+ < option value = "iso" > Iso</ option >
74
+ < option value = "long-localized" > Long localized</ option >
75
+ </ select >
76
+ </ label >
77
+ < label >
78
+ Input format
79
+ < select
80
+ value = { inputFormat }
81
+ disabled = { format !== 'long-localized' }
82
+ onChange = { event =>
83
+ setUrlParams ( {
84
+ inputFormat : event . currentTarget . value as DateInputProps . InputFormat ,
85
+ } )
86
+ }
87
+ >
88
+ < option value = "slashed" > Slashed (Default)</ option >
89
+ < option value = "iso" > Iso</ option >
90
+ </ select >
91
+ </ label >
92
+ < label >
93
+ Locale
94
+ < select
95
+ value = { locale }
96
+ onChange = { event =>
97
+ setUrlParams ( {
98
+ locale : event . currentTarget . value as DateInputProps [ 'locale' ] ,
99
+ } )
100
+ }
101
+ >
102
+ < option value = "ar" > ar</ option >
103
+ < option value = "en-US" > en-US</ option >
104
+ < option value = "en-GB" > en-GB</ option >
105
+ < option value = "de" > de</ option >
106
+ < option value = "es" > es</ option >
107
+ < option value = "fr" > fr</ option >
108
+ < option value = "it" > it</ option >
109
+ < option value = "ja" > ja</ option >
110
+ < option value = "ko" > ko</ option >
111
+ < option value = "tr" > tr</ option >
112
+ < option value = "pt-BR" > pt-BR</ option >
113
+ < option value = "ru" > ru</ option >
114
+ < option value = "zh-CN" > zh-CN</ option >
115
+ < option value = "zh-TW" > zh-TW</ option >
116
+ </ select >
117
+ </ label >
40
118
</ SpaceBetween >
41
119
< DateInput
42
120
className = "testing-date-input"
43
121
name = "date"
44
- ariaLabel = " Enter the date in YYYY/MM/DD"
45
- placeholder = "YYYY/MM/DD"
122
+ ariaLabel = { ` Enter the date in ${ inputFormatPlaceholderText } ` }
123
+ placeholder = { inputFormatPlaceholderText }
46
124
onChange = { e => setValue ( e . detail . value ) }
47
125
value = { value }
126
+ readOnly = { readonly }
127
+ disabled = { disabled }
128
+ format = { format === '' ? undefined : format }
129
+ inputFormat = { inputFormat === '' ? undefined : inputFormat }
130
+ granularity = { monthOnly ? 'month' : 'day' }
131
+ locale = { locale }
48
132
/>
49
133
< b > Raw value</ b >
50
134
< pre > { JSON . stringify ( value , undefined , 2 ) } </ pre >
0 commit comments