@simplybusiness/mobius-datepicker 3.11.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/CHANGELOG.md +12 -0
- package/dist/cjs/components/DatePicker/Calendar.d.ts +5 -0
- package/dist/cjs/components/DatePicker/Calendar.js +21 -0
- package/dist/cjs/components/DatePicker/Calendar.js.map +1 -0
- package/dist/cjs/components/DatePicker/CalendarButton.d.ts +13 -0
- package/dist/cjs/components/DatePicker/CalendarButton.js +29 -0
- package/dist/cjs/components/DatePicker/CalendarButton.js.map +1 -0
- package/dist/cjs/components/DatePicker/CalendarCell.d.ts +6 -0
- package/dist/cjs/components/DatePicker/CalendarCell.js +27 -0
- package/dist/cjs/components/DatePicker/CalendarCell.js.map +1 -0
- package/dist/cjs/components/DatePicker/CalendarGrid.d.ts +7 -0
- package/dist/cjs/components/DatePicker/CalendarGrid.js +35 -0
- package/dist/cjs/components/DatePicker/CalendarGrid.js.map +1 -0
- package/dist/cjs/components/DatePicker/DateField.d.ts +6 -0
- package/dist/cjs/components/DatePicker/DateField.js +38 -0
- package/dist/cjs/components/DatePicker/DateField.js.map +1 -0
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +7 -0
- package/dist/cjs/components/DatePicker/DatePicker.js +51 -0
- package/dist/cjs/components/DatePicker/DatePicker.js.map +1 -0
- package/dist/cjs/components/DatePicker/DatePicker.stories.d.ts +16 -0
- package/dist/cjs/components/DatePicker/DatePicker.stories.js +28 -0
- package/dist/cjs/components/DatePicker/DatePicker.stories.js.map +1 -0
- package/dist/cjs/components/DatePicker/DatePicker.test.d.ts +1 -0
- package/dist/cjs/components/DatePicker/DatePicker.test.js +14 -0
- package/dist/cjs/components/DatePicker/DatePicker.test.js.map +1 -0
- package/dist/cjs/components/DatePicker/DateSegment.d.ts +6 -0
- package/dist/cjs/components/DatePicker/DateSegment.js +25 -0
- package/dist/cjs/components/DatePicker/DateSegment.js.map +1 -0
- package/dist/cjs/components/DatePicker/Popover.d.ts +8 -0
- package/dist/cjs/components/DatePicker/Popover.js +49 -0
- package/dist/cjs/components/DatePicker/Popover.js.map +1 -0
- package/dist/cjs/components/DatePicker/index.d.ts +2 -0
- package/dist/cjs/components/DatePicker/index.js +21 -0
- package/dist/cjs/components/DatePicker/index.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/components/DatePicker/Calendar.js +17 -0
- package/dist/esm/components/DatePicker/Calendar.js.map +1 -0
- package/dist/esm/components/DatePicker/CalendarButton.js +23 -0
- package/dist/esm/components/DatePicker/CalendarButton.js.map +1 -0
- package/dist/esm/components/DatePicker/CalendarCell.js +20 -0
- package/dist/esm/components/DatePicker/CalendarCell.js.map +1 -0
- package/dist/esm/components/DatePicker/CalendarGrid.js +31 -0
- package/dist/esm/components/DatePicker/CalendarGrid.js.map +1 -0
- package/dist/esm/components/DatePicker/DateField.js +34 -0
- package/dist/esm/components/DatePicker/DateField.js.map +1 -0
- package/dist/esm/components/DatePicker/DatePicker.js +44 -0
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -0
- package/dist/esm/components/DatePicker/DateSegment.js +18 -0
- package/dist/esm/components/DatePicker/DateSegment.js.map +1 -0
- package/dist/esm/components/DatePicker/Popover.js +45 -0
- package/dist/esm/components/DatePicker/Popover.js.map +1 -0
- package/dist/esm/components/DatePicker/index.js +3 -0
- package/dist/esm/components/DatePicker/index.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +100 -0
- package/src/components/DatePicker/Calendar.tsx +48 -0
- package/src/components/DatePicker/CalendarButton.tsx +58 -0
- package/src/components/DatePicker/CalendarCell.tsx +48 -0
- package/src/components/DatePicker/CalendarGrid.tsx +60 -0
- package/src/components/DatePicker/DateField.tsx +45 -0
- package/src/components/DatePicker/DatePicker.mdx +508 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +32 -0
- package/src/components/DatePicker/DatePicker.test.tsx +16 -0
- package/src/components/DatePicker/DatePicker.tsx +101 -0
- package/src/components/DatePicker/DateSegment.tsx +34 -0
- package/src/components/DatePicker/Popover.tsx +61 -0
- package/src/components/DatePicker/index.tsx +2 -0
- package/src/index.tsx +1 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { Meta, ArgTypes, Canvas, Story } from "@storybook/blocks";
|
|
2
|
+
import { parseDate } from "@internationalized/date";
|
|
3
|
+
import { I18nProvider } from "@react-aria/i18n";
|
|
4
|
+
import { DatePicker } from "./DatePicker";
|
|
5
|
+
import * as DatePickerStories from "./DatePicker.stories";
|
|
6
|
+
|
|
7
|
+
<Meta of={DatePickerStories} />
|
|
8
|
+
|
|
9
|
+
# DatePicker
|
|
10
|
+
|
|
11
|
+
DatePicker allows you to display a date picker.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @simplybusiness/mobius-datepicker
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { DatePicker } from "@simplybusiness/mobius-datepicker";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Normal
|
|
26
|
+
|
|
27
|
+
<Story of={DatePickerStories.Normal} />
|
|
28
|
+
|
|
29
|
+
{/* prettier-ignore */}
|
|
30
|
+
```jsx
|
|
31
|
+
import { DatePicker } from "@simplybusiness/mobius-datepicker";
|
|
32
|
+
import { I18nProvider } from "@react-aria/i18n";
|
|
33
|
+
import { parseDate } from "@internationalized/date";
|
|
34
|
+
|
|
35
|
+
<I18nProvider locale="en-GB">
|
|
36
|
+
<DatePicker minValue={parseDate("2022-05-05")} label="Start date" />
|
|
37
|
+
</I18nProvider>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# Localising
|
|
41
|
+
|
|
42
|
+
## Props
|
|
43
|
+
|
|
44
|
+
<ArgTypes of={DatePicker} />
|
|
45
|
+
|
|
46
|
+
## Component HTML Structure and Class names
|
|
47
|
+
|
|
48
|
+
The following HTML is rendered for a DatePicker:
|
|
49
|
+
|
|
50
|
+
### DateField
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<div class="mobius/DateFieldGroup">
|
|
54
|
+
<div class="mobius/DateField">
|
|
55
|
+
<span></span>
|
|
56
|
+
<div role="presentation" class="mobius/DateSegments">
|
|
57
|
+
<div class="mobius/DateSegment --is-placeholder">mm</div>
|
|
58
|
+
<div aria-hidden="true" class="mobius/DateSegment --is-literal">/</div>
|
|
59
|
+
<div class="mobius/DateSegment --is-placeholder">dd</div>
|
|
60
|
+
<div aria-hidden="true" class="mobius/DateSegment --is-literal">/</div>
|
|
61
|
+
<div class="mobius/DateSegment --is-placeholder">yyyy</div>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
class="mobius mobius/Button --variant-secondary --size-medium mobius/DateFieldButton"
|
|
67
|
+
>
|
|
68
|
+
<span>
|
|
69
|
+
<div>Pick date</div>
|
|
70
|
+
</span>
|
|
71
|
+
</button>
|
|
72
|
+
</div>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Calendar
|
|
76
|
+
|
|
77
|
+
```html
|
|
78
|
+
<div class="mobius/Calendar">
|
|
79
|
+
<div class="mobius/CalendarHeader">
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
aria-label="Previous"
|
|
83
|
+
class="mobius mobius/CalendarButton mobius/CalendarPreviousButton"
|
|
84
|
+
>
|
|
85
|
+
<div><</div>
|
|
86
|
+
</button>
|
|
87
|
+
<h2 class="mobius/CalendarTitle">June 2022</h2>
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
aria-label="Next"
|
|
91
|
+
class="mobius mobius/CalendarButton mobius/CalendarNextButton"
|
|
92
|
+
>
|
|
93
|
+
<div>></div>
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
<table class="mobius/CalendarGrid">
|
|
97
|
+
<thead aria-hidden="true" class="mobius/CalendarGridHead">
|
|
98
|
+
<tr>
|
|
99
|
+
<th class="mobius/CalendarGridHeadCell">S</th>
|
|
100
|
+
<th class="mobius/CalendarGridHeadCell">M</th>
|
|
101
|
+
<th class="mobius/CalendarGridHeadCell">T</th>
|
|
102
|
+
<th class="mobius/CalendarGridHeadCell">W</th>
|
|
103
|
+
<th class="mobius/CalendarGridHeadCell">T</th>
|
|
104
|
+
<th class="mobius/CalendarGridHeadCell">F</th>
|
|
105
|
+
<th class="mobius/CalendarGridHeadCell">S</th>
|
|
106
|
+
</tr>
|
|
107
|
+
</thead>
|
|
108
|
+
<tbody class="mobius/CalendarGridBody">
|
|
109
|
+
<tr>
|
|
110
|
+
<td
|
|
111
|
+
class="mobius/CalendarCell --is-outside-visible-range --is-disabled"
|
|
112
|
+
role="gridcell"
|
|
113
|
+
aria-disabled="true"
|
|
114
|
+
>
|
|
115
|
+
<div
|
|
116
|
+
role="button"
|
|
117
|
+
aria-disabled="true"
|
|
118
|
+
aria-label="Sunday, May 29, 2022"
|
|
119
|
+
class="mobius/CalendarCellInner"
|
|
120
|
+
hidden=""
|
|
121
|
+
>
|
|
122
|
+
29
|
|
123
|
+
</div>
|
|
124
|
+
</td>
|
|
125
|
+
<td
|
|
126
|
+
class="mobius/CalendarCell --is-outside-visible-range --is-disabled"
|
|
127
|
+
role="gridcell"
|
|
128
|
+
aria-disabled="true"
|
|
129
|
+
>
|
|
130
|
+
<div
|
|
131
|
+
role="button"
|
|
132
|
+
aria-disabled="true"
|
|
133
|
+
aria-label="Monday, May 30, 2022"
|
|
134
|
+
class="mobius/CalendarCellInner"
|
|
135
|
+
hidden=""
|
|
136
|
+
>
|
|
137
|
+
30
|
|
138
|
+
</div>
|
|
139
|
+
</td>
|
|
140
|
+
<td
|
|
141
|
+
class="mobius/CalendarCell --is-outside-visible-range --is-disabled"
|
|
142
|
+
role="gridcell"
|
|
143
|
+
aria-disabled="true"
|
|
144
|
+
>
|
|
145
|
+
<div
|
|
146
|
+
role="button"
|
|
147
|
+
aria-disabled="true"
|
|
148
|
+
aria-label="Tuesday, May 31, 2022"
|
|
149
|
+
class="mobius/CalendarCellInner"
|
|
150
|
+
hidden=""
|
|
151
|
+
>
|
|
152
|
+
31
|
|
153
|
+
</div>
|
|
154
|
+
</td>
|
|
155
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
156
|
+
<div
|
|
157
|
+
tabindex="-1"
|
|
158
|
+
role="button"
|
|
159
|
+
aria-label="Wednesday, June 1, 2022"
|
|
160
|
+
class="mobius/CalendarCellInner"
|
|
161
|
+
>
|
|
162
|
+
1
|
|
163
|
+
</div>
|
|
164
|
+
</td>
|
|
165
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
166
|
+
<div
|
|
167
|
+
tabindex="-1"
|
|
168
|
+
role="button"
|
|
169
|
+
aria-label="Thursday, June 2, 2022"
|
|
170
|
+
class="mobius/CalendarCellInner"
|
|
171
|
+
>
|
|
172
|
+
2
|
|
173
|
+
</div>
|
|
174
|
+
</td>
|
|
175
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
176
|
+
<div
|
|
177
|
+
tabindex="-1"
|
|
178
|
+
role="button"
|
|
179
|
+
aria-label="Friday, June 3, 2022"
|
|
180
|
+
class="mobius/CalendarCellInner"
|
|
181
|
+
>
|
|
182
|
+
3
|
|
183
|
+
</div>
|
|
184
|
+
</td>
|
|
185
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
186
|
+
<div
|
|
187
|
+
tabindex="-1"
|
|
188
|
+
role="button"
|
|
189
|
+
aria-label="Saturday, June 4, 2022"
|
|
190
|
+
class="mobius/CalendarCellInner"
|
|
191
|
+
>
|
|
192
|
+
4
|
|
193
|
+
</div>
|
|
194
|
+
</td>
|
|
195
|
+
</tr>
|
|
196
|
+
<tr>
|
|
197
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
198
|
+
<div
|
|
199
|
+
tabindex="-1"
|
|
200
|
+
role="button"
|
|
201
|
+
aria-label="Sunday, June 5, 2022"
|
|
202
|
+
class="mobius/CalendarCellInner"
|
|
203
|
+
>
|
|
204
|
+
5
|
|
205
|
+
</div>
|
|
206
|
+
</td>
|
|
207
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
208
|
+
<div
|
|
209
|
+
tabindex="-1"
|
|
210
|
+
role="button"
|
|
211
|
+
aria-label="Monday, June 6, 2022"
|
|
212
|
+
class="mobius/CalendarCellInner"
|
|
213
|
+
>
|
|
214
|
+
6
|
|
215
|
+
</div>
|
|
216
|
+
</td>
|
|
217
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
218
|
+
<div
|
|
219
|
+
tabindex="-1"
|
|
220
|
+
role="button"
|
|
221
|
+
aria-label="Tuesday, June 7, 2022"
|
|
222
|
+
class="mobius/CalendarCellInner"
|
|
223
|
+
>
|
|
224
|
+
7
|
|
225
|
+
</div>
|
|
226
|
+
</td>
|
|
227
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
228
|
+
<div
|
|
229
|
+
tabindex="-1"
|
|
230
|
+
role="button"
|
|
231
|
+
aria-label="Wednesday, June 8, 2022"
|
|
232
|
+
class="mobius/CalendarCellInner"
|
|
233
|
+
>
|
|
234
|
+
8
|
|
235
|
+
</div>
|
|
236
|
+
</td>
|
|
237
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
238
|
+
<div
|
|
239
|
+
tabindex="-1"
|
|
240
|
+
role="button"
|
|
241
|
+
aria-label="Thursday, June 9, 2022"
|
|
242
|
+
class="mobius/CalendarCellInner"
|
|
243
|
+
>
|
|
244
|
+
9
|
|
245
|
+
</div>
|
|
246
|
+
</td>
|
|
247
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
248
|
+
<div
|
|
249
|
+
tabindex="-1"
|
|
250
|
+
role="button"
|
|
251
|
+
aria-label="Friday, June 10, 2022"
|
|
252
|
+
class="mobius/CalendarCellInner"
|
|
253
|
+
>
|
|
254
|
+
10
|
|
255
|
+
</div>
|
|
256
|
+
</td>
|
|
257
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
258
|
+
<div
|
|
259
|
+
tabindex="-1"
|
|
260
|
+
role="button"
|
|
261
|
+
aria-label="Saturday, June 11, 2022"
|
|
262
|
+
class="mobius/CalendarCellInner"
|
|
263
|
+
>
|
|
264
|
+
11
|
|
265
|
+
</div>
|
|
266
|
+
</td>
|
|
267
|
+
</tr>
|
|
268
|
+
<tr>
|
|
269
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
270
|
+
<div
|
|
271
|
+
tabindex="-1"
|
|
272
|
+
role="button"
|
|
273
|
+
aria-label="Sunday, June 12, 2022"
|
|
274
|
+
class="mobius/CalendarCellInner"
|
|
275
|
+
>
|
|
276
|
+
12
|
|
277
|
+
</div>
|
|
278
|
+
</td>
|
|
279
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
280
|
+
<div
|
|
281
|
+
tabindex="-1"
|
|
282
|
+
role="button"
|
|
283
|
+
aria-label="Monday, June 13, 2022"
|
|
284
|
+
class="mobius/CalendarCellInner"
|
|
285
|
+
>
|
|
286
|
+
13
|
|
287
|
+
</div>
|
|
288
|
+
</td>
|
|
289
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
290
|
+
<div
|
|
291
|
+
tabindex="-1"
|
|
292
|
+
role="button"
|
|
293
|
+
aria-label="Tuesday, June 14, 2022"
|
|
294
|
+
class="mobius/CalendarCellInner"
|
|
295
|
+
>
|
|
296
|
+
14
|
|
297
|
+
</div>
|
|
298
|
+
</td>
|
|
299
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
300
|
+
<div
|
|
301
|
+
tabindex="-1"
|
|
302
|
+
role="button"
|
|
303
|
+
aria-label="Wednesday, June 15, 2022"
|
|
304
|
+
class="mobius/CalendarCellInner"
|
|
305
|
+
>
|
|
306
|
+
15
|
|
307
|
+
</div>
|
|
308
|
+
</td>
|
|
309
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
310
|
+
<div
|
|
311
|
+
tabindex="-1"
|
|
312
|
+
role="button"
|
|
313
|
+
aria-label="Thursday, June 16, 2022"
|
|
314
|
+
class="mobius/CalendarCellInner"
|
|
315
|
+
>
|
|
316
|
+
16
|
|
317
|
+
</div>
|
|
318
|
+
</td>
|
|
319
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
320
|
+
<div
|
|
321
|
+
tabindex="-1"
|
|
322
|
+
role="button"
|
|
323
|
+
aria-label="Friday, June 17, 2022"
|
|
324
|
+
class="mobius/CalendarCellInner"
|
|
325
|
+
>
|
|
326
|
+
17
|
|
327
|
+
</div>
|
|
328
|
+
</td>
|
|
329
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
330
|
+
<div
|
|
331
|
+
tabindex="-1"
|
|
332
|
+
role="button"
|
|
333
|
+
aria-label="Saturday, June 18, 2022"
|
|
334
|
+
class="mobius/CalendarCellInner"
|
|
335
|
+
>
|
|
336
|
+
18
|
|
337
|
+
</div>
|
|
338
|
+
</td>
|
|
339
|
+
</tr>
|
|
340
|
+
<tr>
|
|
341
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
342
|
+
<div
|
|
343
|
+
tabindex="-1"
|
|
344
|
+
role="button"
|
|
345
|
+
aria-label="Sunday, June 19, 2022"
|
|
346
|
+
class="mobius/CalendarCellInner"
|
|
347
|
+
>
|
|
348
|
+
19
|
|
349
|
+
</div>
|
|
350
|
+
</td>
|
|
351
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
352
|
+
<div
|
|
353
|
+
tabindex="-1"
|
|
354
|
+
role="button"
|
|
355
|
+
aria-label="Monday, June 20, 2022"
|
|
356
|
+
class="mobius/CalendarCellInner"
|
|
357
|
+
>
|
|
358
|
+
20
|
|
359
|
+
</div>
|
|
360
|
+
</td>
|
|
361
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
362
|
+
<div
|
|
363
|
+
tabindex="0"
|
|
364
|
+
role="button"
|
|
365
|
+
aria-label="Today, Tuesday, June 21, 2022"
|
|
366
|
+
class="mobius/CalendarCellInner"
|
|
367
|
+
>
|
|
368
|
+
21
|
|
369
|
+
</div>
|
|
370
|
+
</td>
|
|
371
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
372
|
+
<div
|
|
373
|
+
tabindex="-1"
|
|
374
|
+
role="button"
|
|
375
|
+
aria-label="Wednesday, June 22, 2022"
|
|
376
|
+
class="mobius/CalendarCellInner"
|
|
377
|
+
>
|
|
378
|
+
22
|
|
379
|
+
</div>
|
|
380
|
+
</td>
|
|
381
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
382
|
+
<div
|
|
383
|
+
tabindex="-1"
|
|
384
|
+
role="button"
|
|
385
|
+
aria-label="Thursday, June 23, 2022"
|
|
386
|
+
class="mobius/CalendarCellInner"
|
|
387
|
+
>
|
|
388
|
+
23
|
|
389
|
+
</div>
|
|
390
|
+
</td>
|
|
391
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
392
|
+
<div
|
|
393
|
+
tabindex="-1"
|
|
394
|
+
role="button"
|
|
395
|
+
aria-label="Friday, June 24, 2022"
|
|
396
|
+
class="mobius/CalendarCellInner"
|
|
397
|
+
>
|
|
398
|
+
24
|
|
399
|
+
</div>
|
|
400
|
+
</td>
|
|
401
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
402
|
+
<div
|
|
403
|
+
tabindex="-1"
|
|
404
|
+
role="button"
|
|
405
|
+
aria-label="Saturday, June 25, 2022"
|
|
406
|
+
class="mobius/CalendarCellInner"
|
|
407
|
+
>
|
|
408
|
+
25
|
|
409
|
+
</div>
|
|
410
|
+
</td>
|
|
411
|
+
</tr>
|
|
412
|
+
<tr>
|
|
413
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
414
|
+
<div
|
|
415
|
+
tabindex="-1"
|
|
416
|
+
role="button"
|
|
417
|
+
aria-label="Sunday, June 26, 2022"
|
|
418
|
+
class="mobius/CalendarCellInner"
|
|
419
|
+
>
|
|
420
|
+
26
|
|
421
|
+
</div>
|
|
422
|
+
</td>
|
|
423
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
424
|
+
<div
|
|
425
|
+
tabindex="-1"
|
|
426
|
+
role="button"
|
|
427
|
+
aria-label="Monday, June 27, 2022"
|
|
428
|
+
class="mobius/CalendarCellInner"
|
|
429
|
+
>
|
|
430
|
+
27
|
|
431
|
+
</div>
|
|
432
|
+
</td>
|
|
433
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
434
|
+
<div
|
|
435
|
+
tabindex="-1"
|
|
436
|
+
role="button"
|
|
437
|
+
aria-label="Tuesday, June 28, 2022"
|
|
438
|
+
class="mobius/CalendarCellInner"
|
|
439
|
+
>
|
|
440
|
+
28
|
|
441
|
+
</div>
|
|
442
|
+
</td>
|
|
443
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
444
|
+
<div
|
|
445
|
+
tabindex="-1"
|
|
446
|
+
role="button"
|
|
447
|
+
aria-label="Wednesday, June 29, 2022"
|
|
448
|
+
class="mobius/CalendarCellInner"
|
|
449
|
+
>
|
|
450
|
+
29
|
|
451
|
+
</div>
|
|
452
|
+
</td>
|
|
453
|
+
<td class="mobius/CalendarCell" role="gridcell">
|
|
454
|
+
<div
|
|
455
|
+
tabindex="-1"
|
|
456
|
+
role="button"
|
|
457
|
+
aria-label="Thursday, June 30, 2022"
|
|
458
|
+
class="mobius/CalendarCellInner"
|
|
459
|
+
>
|
|
460
|
+
30
|
|
461
|
+
</div>
|
|
462
|
+
</td>
|
|
463
|
+
<td
|
|
464
|
+
class="mobius/CalendarCell --is-outside-visible-range --is-disabled"
|
|
465
|
+
role="gridcell"
|
|
466
|
+
aria-disabled="true"
|
|
467
|
+
>
|
|
468
|
+
<div
|
|
469
|
+
role="button"
|
|
470
|
+
aria-disabled="true"
|
|
471
|
+
aria-label="Friday, July 1, 2022"
|
|
472
|
+
class="mobius/CalendarCellInner"
|
|
473
|
+
hidden=""
|
|
474
|
+
>
|
|
475
|
+
1
|
|
476
|
+
</div>
|
|
477
|
+
</td>
|
|
478
|
+
<td
|
|
479
|
+
class="mobius/CalendarCell --is-outside-visible-range --is-disabled"
|
|
480
|
+
role="gridcell"
|
|
481
|
+
aria-disabled="true"
|
|
482
|
+
>
|
|
483
|
+
<div
|
|
484
|
+
role="button"
|
|
485
|
+
aria-disabled="true"
|
|
486
|
+
aria-label="Saturday, July 2, 2022"
|
|
487
|
+
class="mobius/CalendarCellInner"
|
|
488
|
+
hidden=""
|
|
489
|
+
>
|
|
490
|
+
2
|
|
491
|
+
</div>
|
|
492
|
+
</td>
|
|
493
|
+
</tr>
|
|
494
|
+
</tbody>
|
|
495
|
+
</table>
|
|
496
|
+
</div>
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Class names are augmented with the following flags if true:
|
|
500
|
+
|
|
501
|
+
- \--is-valid
|
|
502
|
+
- \--is-invalid
|
|
503
|
+
- \--is-required
|
|
504
|
+
- \--is-optional
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
[See on Github](https://github.com/simplybusiness/mobius/tree/master/packages/mobius/src/components/DatePicker) | [Give feedback](https://simplybusiness.atlassian.net/CreateIssue.jspa?issuetype=10103&pid=10609) | [Get support](https://simplybusiness.slack.com/archives/C016CC0NDNE)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Meta } from "@storybook/react";
|
|
2
|
+
import { parseDate } from "@internationalized/date";
|
|
3
|
+
import { I18nProvider } from "@react-aria/i18n";
|
|
4
|
+
import { DatePicker, DatePickerProps } from "./DatePicker";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Forms/DatePicker",
|
|
8
|
+
component: DatePicker,
|
|
9
|
+
argTypes: {
|
|
10
|
+
locale: {
|
|
11
|
+
control: { type: "select" },
|
|
12
|
+
options: ["", "en-GB", "en-US"],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Normal: Meta<typeof DatePicker> = {
|
|
18
|
+
render: (args: DatePickerProps) => (
|
|
19
|
+
<DatePicker minValue={parseDate("2022-05-05")} {...args} />
|
|
20
|
+
),
|
|
21
|
+
args: {
|
|
22
|
+
label: "Start date",
|
|
23
|
+
isRequired: false,
|
|
24
|
+
},
|
|
25
|
+
decorators: [
|
|
26
|
+
(Story, context) => (
|
|
27
|
+
<I18nProvider locale={context.allArgs.locale}>
|
|
28
|
+
<Story />
|
|
29
|
+
</I18nProvider>
|
|
30
|
+
),
|
|
31
|
+
],
|
|
32
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { I18nProvider } from "@react-aria/i18n";
|
|
4
|
+
import { parseDate } from "@internationalized/date";
|
|
5
|
+
import { DatePicker } from ".";
|
|
6
|
+
|
|
7
|
+
describe("DatePicker", () => {
|
|
8
|
+
it("should render without errors", () => {
|
|
9
|
+
const component = render(
|
|
10
|
+
<I18nProvider locale="en-GB">
|
|
11
|
+
<DatePicker minValue={parseDate("2022-05-05")} label="Start date" />
|
|
12
|
+
</I18nProvider>,
|
|
13
|
+
);
|
|
14
|
+
expect(component).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DatePickerStateOptions,
|
|
5
|
+
useDatePickerState,
|
|
6
|
+
} from "@react-stately/datepicker";
|
|
7
|
+
import { AriaDatePickerProps, useDatePicker } from "@react-aria/datepicker";
|
|
8
|
+
import { useRef } from "react";
|
|
9
|
+
import { ModalProvider } from "@react-aria/overlays";
|
|
10
|
+
import { DateValue } from "@internationalized/date";
|
|
11
|
+
import { useHover } from "@react-aria/interactions";
|
|
12
|
+
import { useFocusRing } from "@react-aria/focus";
|
|
13
|
+
import clsx from "clsx";
|
|
14
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
15
|
+
import { Button, Label } from "@simplybusiness/mobius";
|
|
16
|
+
import { DateField } from "./DateField";
|
|
17
|
+
import { Popover } from "./Popover";
|
|
18
|
+
import { Calendar } from "./Calendar";
|
|
19
|
+
|
|
20
|
+
export interface DatePickerProps
|
|
21
|
+
extends AriaDatePickerProps<DateValue>,
|
|
22
|
+
DatePickerStateOptions<DateValue> {
|
|
23
|
+
label: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function DatePicker(props: DatePickerProps) {
|
|
27
|
+
const { label, isRequired } = props;
|
|
28
|
+
const state = useDatePickerState(props);
|
|
29
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
30
|
+
const {
|
|
31
|
+
groupProps,
|
|
32
|
+
labelProps,
|
|
33
|
+
fieldProps,
|
|
34
|
+
buttonProps,
|
|
35
|
+
dialogProps,
|
|
36
|
+
calendarProps,
|
|
37
|
+
} = useDatePicker(props, state, ref);
|
|
38
|
+
|
|
39
|
+
const classes = clsx("mobius/DatePicker", {
|
|
40
|
+
"--is-valid": state.validationState === "valid",
|
|
41
|
+
"--is-invalid": state.validationState === "invalid",
|
|
42
|
+
"--is-required": typeof isRequired === "boolean" && isRequired,
|
|
43
|
+
"--is-optional": typeof isRequired === "boolean" && !isRequired,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { hoverProps, isHovered } = useHover({
|
|
47
|
+
...props,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { focusProps, isFocusVisible } = useFocusRing(props);
|
|
51
|
+
|
|
52
|
+
const dateFieldGroupClasses = clsx("mobius/DateFieldGroup", {
|
|
53
|
+
"--is-hovered": isHovered,
|
|
54
|
+
"--is-focused": isFocusVisible,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const dateFieldClasses = clsx("mobius/DateField", {
|
|
58
|
+
"--is-hovered": isHovered,
|
|
59
|
+
"--is-focused": isFocusVisible,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const buttonClasses = clsx("mobius/DateFieldButton", {
|
|
63
|
+
"--is-hovered": isHovered,
|
|
64
|
+
"--is-focused": isFocusVisible,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<ModalProvider>
|
|
69
|
+
<div className={classes} style={{ position: "relative" }}>
|
|
70
|
+
<Label {...labelProps}>{label}</Label>
|
|
71
|
+
<div
|
|
72
|
+
{...groupProps}
|
|
73
|
+
{...hoverProps}
|
|
74
|
+
{...focusProps}
|
|
75
|
+
ref={ref}
|
|
76
|
+
className={dateFieldGroupClasses}
|
|
77
|
+
>
|
|
78
|
+
<DateField {...fieldProps} className={dateFieldClasses} />
|
|
79
|
+
{/* @ts-expect-error wrong type for onPress */}
|
|
80
|
+
<Button
|
|
81
|
+
variant="secondary"
|
|
82
|
+
{...buttonProps}
|
|
83
|
+
className={buttonClasses}
|
|
84
|
+
>
|
|
85
|
+
<VisuallyHidden>Pick date</VisuallyHidden>
|
|
86
|
+
</Button>
|
|
87
|
+
</div>
|
|
88
|
+
{state.isOpen && (
|
|
89
|
+
/* @ts-expect-error */
|
|
90
|
+
<Popover
|
|
91
|
+
{...dialogProps}
|
|
92
|
+
isOpen={state.isOpen}
|
|
93
|
+
onClose={() => state.setOpen(false)}
|
|
94
|
+
>
|
|
95
|
+
<Calendar {...calendarProps} />
|
|
96
|
+
</Popover>
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
</ModalProvider>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useDateSegment } from "@react-aria/datepicker";
|
|
4
|
+
import { useFocusRing } from "@react-aria/focus";
|
|
5
|
+
import {
|
|
6
|
+
DateFieldState,
|
|
7
|
+
DateSegment as DateSegmentType,
|
|
8
|
+
} from "@react-stately/datepicker";
|
|
9
|
+
import clsx from "clsx";
|
|
10
|
+
import { useRef } from "react";
|
|
11
|
+
|
|
12
|
+
export interface DateSegmentProps {
|
|
13
|
+
segment: DateSegmentType;
|
|
14
|
+
state: DateFieldState;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function DateSegment({ segment, state }: DateSegmentProps) {
|
|
18
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
19
|
+
const { segmentProps } = useDateSegment(segment, state, ref);
|
|
20
|
+
|
|
21
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
22
|
+
|
|
23
|
+
const classes = clsx("mobius/DateSegment", {
|
|
24
|
+
"--is-literal": segment.type === "literal",
|
|
25
|
+
"--is-placeholder": segment.isPlaceholder,
|
|
26
|
+
"--is-focused": isFocusVisible,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div {...segmentProps} {...focusProps} ref={ref} className={classes}>
|
|
31
|
+
{segment.text}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|