@indico-data/design-system 1.0.52 → 1.0.53
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/jest.config.js +1 -2
- package/lib/components/Icon/Icon.stories.d.ts +2 -2
- package/lib/components/Icon/indicons.d.ts +1 -0
- package/lib/components/Navigation/Drawer/constants.d.ts +3 -0
- package/lib/components/index.d.ts +1 -1
- package/lib/components/inputs/DatePicker/DatePicker.d.ts +15 -0
- package/lib/components/inputs/DatePicker/DatePicker.stories.d.ts +6 -0
- package/lib/components/inputs/DatePicker/DatePicker.styles.d.ts +2 -0
- package/lib/components/inputs/DatePicker/index.d.ts +1 -0
- package/lib/components/inputs/NoInputDatePicker/NoInputDatePicker.d.ts +19 -0
- package/lib/components/inputs/NoInputDatePicker/NoInputDatePicker.stories.d.ts +7 -0
- package/lib/components/inputs/NoInputDatePicker/NoInputDatePicker.styles.d.ts +2 -0
- package/lib/components/inputs/NoInputDatePicker/__tests__/NoInputDatePicker.test.d.ts +1 -0
- package/lib/components/inputs/NoInputDatePicker/index.d.ts +1 -0
- package/lib/components/inputs/index.d.ts +2 -0
- package/lib/components/text-truncate/TextTruncate.d.ts +1 -1
- package/lib/index.d.ts +61 -28
- package/lib/index.esm.js +21441 -13325
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +21462 -13328
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/utils/color.d.ts +21 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/number.d.ts +21 -0
- package/lib/utils/string.d.ts +12 -0
- package/package.json +10 -3
- package/src/components/Icon/indicons.tsx +6 -0
- package/src/components/ListTable/Header/Header.tsx +1 -1
- package/src/components/Pagination/Pagination.tsx +1 -1
- package/src/components/basic-section/SectionTable/SectionTable.styles.ts +1 -2
- package/src/components/basic-section/SectionTable/SectionTable.tsx +12 -10
- package/src/components/dropdowns/MultiCombobox/MultiCombobox.stories.tsx +1 -1
- package/src/components/dropdowns/MultiCombobox/MultiCombobox.tsx +1 -1
- package/src/components/dropdowns/SingleCombobox/SingleCombobox.tsx +1 -1
- package/src/components/index.ts +2 -0
- package/src/components/inputs/DatePicker/DatePicker.stories.tsx +30 -0
- package/src/components/inputs/DatePicker/DatePicker.styles.ts +437 -0
- package/src/components/inputs/DatePicker/DatePicker.tsx +165 -0
- package/src/components/inputs/DatePicker/index.ts +1 -0
- package/src/components/inputs/EditableInput/EditableInput.tsx +1 -1
- package/src/components/inputs/NoInputDatePicker/NoInputDatePicker.stories.tsx +52 -0
- package/src/components/inputs/NoInputDatePicker/NoInputDatePicker.styles.ts +449 -0
- package/src/components/inputs/NoInputDatePicker/NoInputDatePicker.tsx +204 -0
- package/src/components/inputs/NoInputDatePicker/__tests__/NoInputDatePicker.test.tsx +126 -0
- package/src/components/inputs/NoInputDatePicker/index.ts +1 -0
- package/src/components/inputs/TextInput/TextInput.stories.tsx +1 -1
- package/src/components/inputs/index.ts +2 -0
- package/src/components/modals/ModalBase/ModalBase.styles.tsx +1 -1
- package/src/components/text-truncate/TextTruncate.test.tsx +3 -4
- package/src/components/text-truncate/TextTruncate.tsx +3 -2
- package/src/index.ts +2 -0
- package/src/styles/globals/forms.ts +1 -9
- package/src/styles/globals/tables.ts +1 -5
- package/src/utils/color.ts +139 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/number.ts +29 -0
- package/src/utils/string.ts +87 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const StyledNoInputDatePicker = styled.div`
|
|
4
|
+
/************************************
|
|
5
|
+
* Default react-day-picker styling - this needed to be added because we were unable to import styling as specified by the docs (most likely because we are not using webpack)
|
|
6
|
+
*************************************/
|
|
7
|
+
|
|
8
|
+
.rdp {
|
|
9
|
+
--rdp-cell-size: 40px;
|
|
10
|
+
--rdp-accent-color: #6833d0;
|
|
11
|
+
--rdp-background-color: #ffffff;
|
|
12
|
+
--rdp-accent-color-dark: #3003e1;
|
|
13
|
+
--rdp-background-color-dark: #180270;
|
|
14
|
+
--rdp-outline: 2px solid var(--rdp-accent-color); /* Outline border for focused elements */
|
|
15
|
+
--rdp-outline-selected: 3px solid var(--rdp-accent-color); /* Outline border for focused _and_ selected elements */
|
|
16
|
+
|
|
17
|
+
margin: 1em;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Hide elements for devices that are not screen readers */
|
|
21
|
+
.rdp-vhidden {
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
padding: 0;
|
|
24
|
+
margin: 0;
|
|
25
|
+
background: transparent;
|
|
26
|
+
border: 0;
|
|
27
|
+
-moz-appearance: none;
|
|
28
|
+
-webkit-appearance: none;
|
|
29
|
+
appearance: none;
|
|
30
|
+
position: absolute !important;
|
|
31
|
+
top: 0;
|
|
32
|
+
width: 1px !important;
|
|
33
|
+
height: 1px !important;
|
|
34
|
+
padding: 0 !important;
|
|
35
|
+
overflow: hidden !important;
|
|
36
|
+
clip: rect(1px, 1px, 1px, 1px) !important;
|
|
37
|
+
border: 0 !important;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Buttons */
|
|
41
|
+
.rdp-button_reset {
|
|
42
|
+
appearance: none;
|
|
43
|
+
position: relative;
|
|
44
|
+
margin: 0;
|
|
45
|
+
padding: 0;
|
|
46
|
+
cursor: default;
|
|
47
|
+
color: inherit;
|
|
48
|
+
background: none;
|
|
49
|
+
font: inherit;
|
|
50
|
+
|
|
51
|
+
-moz-appearance: none;
|
|
52
|
+
-webkit-appearance: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.rdp-button_reset:focus-visible {
|
|
56
|
+
/* Make sure to reset outline only when :focus-visible is supported */
|
|
57
|
+
outline: none;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.rdp-button {
|
|
61
|
+
border: 2px solid transparent;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.rdp-button[disabled]:not(.rdp-day_selected) {
|
|
65
|
+
opacity: 0.25;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.rdp-button:not([disabled]) {
|
|
69
|
+
cursor: pointer;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.rdp-button:focus-visible:not([disabled]) {
|
|
73
|
+
color: inherit;
|
|
74
|
+
background-color: var(--rdp-background-color);
|
|
75
|
+
border: var(--rdp-outline);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rdp-months {
|
|
79
|
+
display: flex;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.rdp-month {
|
|
83
|
+
margin: 0 1em;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.rdp-month:first-child {
|
|
87
|
+
margin-left: 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.rdp-month:last-child {
|
|
91
|
+
margin-right: 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.rdp-table {
|
|
95
|
+
margin: 0;
|
|
96
|
+
max-width: calc(var(--rdp-cell-size) * 7);
|
|
97
|
+
border-collapse: collapse;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.rdp-with_weeknumber .rdp-table {
|
|
101
|
+
max-width: calc(var(--rdp-cell-size) * 8);
|
|
102
|
+
border-collapse: collapse;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.rdp-caption {
|
|
106
|
+
display: flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: space-between;
|
|
109
|
+
padding: 0;
|
|
110
|
+
text-align: left;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.rdp-multiple_months .rdp-caption {
|
|
114
|
+
position: relative;
|
|
115
|
+
display: block;
|
|
116
|
+
text-align: center;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.rdp-caption_dropdowns {
|
|
120
|
+
position: relative;
|
|
121
|
+
display: inline-flex;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.rdp-caption_label {
|
|
125
|
+
position: relative;
|
|
126
|
+
z-index: 1;
|
|
127
|
+
display: inline-flex;
|
|
128
|
+
align-items: center;
|
|
129
|
+
margin: 0;
|
|
130
|
+
padding: 0 0.25em;
|
|
131
|
+
white-space: nowrap;
|
|
132
|
+
color: currentColor;
|
|
133
|
+
border: 0;
|
|
134
|
+
border: 2px solid transparent;
|
|
135
|
+
font-family: inherit;
|
|
136
|
+
font-size: 140%;
|
|
137
|
+
font-weight: bold;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.rdp-nav {
|
|
141
|
+
white-space: nowrap;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.rdp-multiple_months .rdp-caption_start .rdp-nav {
|
|
145
|
+
position: absolute;
|
|
146
|
+
top: 50%;
|
|
147
|
+
left: 0;
|
|
148
|
+
transform: translateY(-50%);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.rdp-multiple_months .rdp-caption_end .rdp-nav {
|
|
152
|
+
position: absolute;
|
|
153
|
+
top: 50%;
|
|
154
|
+
right: 0;
|
|
155
|
+
transform: translateY(-50%);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.rdp-nav_button {
|
|
159
|
+
display: inline-flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
justify-content: center;
|
|
162
|
+
width: var(--rdp-cell-size);
|
|
163
|
+
height: var(--rdp-cell-size);
|
|
164
|
+
padding: 0.25em;
|
|
165
|
+
border-radius: 100%;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* ---------- */
|
|
169
|
+
/* Dropdowns */
|
|
170
|
+
/* ---------- */
|
|
171
|
+
|
|
172
|
+
.rdp-dropdown_year,
|
|
173
|
+
.rdp-dropdown_month {
|
|
174
|
+
position: relative;
|
|
175
|
+
display: inline-flex;
|
|
176
|
+
align-items: center;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.rdp-dropdown {
|
|
180
|
+
appearance: none;
|
|
181
|
+
position: absolute;
|
|
182
|
+
z-index: 2;
|
|
183
|
+
top: 0;
|
|
184
|
+
bottom: 0;
|
|
185
|
+
left: 0;
|
|
186
|
+
width: 100%;
|
|
187
|
+
margin: 0;
|
|
188
|
+
padding: 0;
|
|
189
|
+
cursor: inherit;
|
|
190
|
+
opacity: 0;
|
|
191
|
+
border: none;
|
|
192
|
+
background-color: transparent;
|
|
193
|
+
font-family: inherit;
|
|
194
|
+
font-size: inherit;
|
|
195
|
+
line-height: inherit;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.rdp-dropdown[disabled] {
|
|
199
|
+
opacity: unset;
|
|
200
|
+
color: unset;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.rdp-dropdown:focus-visible:not([disabled]) + .rdp-caption_label {
|
|
204
|
+
background-color: var(--rdp-background-color);
|
|
205
|
+
border: var(--rdp-outline);
|
|
206
|
+
border-radius: 6px;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.rdp-dropdown_icon {
|
|
210
|
+
margin: 0 0 0 5px;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.rdp-head {
|
|
214
|
+
border: 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.rdp-head_row,
|
|
218
|
+
.rdp-row {
|
|
219
|
+
height: 100%;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.rdp-head_cell {
|
|
223
|
+
vertical-align: middle;
|
|
224
|
+
font-size: 0.75em;
|
|
225
|
+
font-weight: 700;
|
|
226
|
+
text-align: center;
|
|
227
|
+
height: 100%;
|
|
228
|
+
height: var(--rdp-cell-size);
|
|
229
|
+
padding: 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.rdp-tbody {
|
|
233
|
+
border: 0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.rdp-tfoot {
|
|
237
|
+
margin: 0.5em;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.rdp-cell {
|
|
241
|
+
width: var(--rdp-cell-size);
|
|
242
|
+
height: 100%;
|
|
243
|
+
height: var(--rdp-cell-size);
|
|
244
|
+
padding: 0;
|
|
245
|
+
text-align: center;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.rdp-weeknumber {
|
|
249
|
+
font-size: 0.75em;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.rdp-weeknumber,
|
|
253
|
+
.rdp-day {
|
|
254
|
+
display: flex;
|
|
255
|
+
overflow: hidden;
|
|
256
|
+
align-items: center;
|
|
257
|
+
justify-content: center;
|
|
258
|
+
box-sizing: border-box;
|
|
259
|
+
width: var(--rdp-cell-size);
|
|
260
|
+
max-width: var(--rdp-cell-size);
|
|
261
|
+
height: var(--rdp-cell-size);
|
|
262
|
+
margin: 0;
|
|
263
|
+
border: 2px solid transparent;
|
|
264
|
+
border-radius: 100%;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.rdp-day_today:not(.rdp-day_outside) {
|
|
268
|
+
font-weight: bold;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.rdp-day_selected,
|
|
272
|
+
.rdp-day_selected:focus-visible,
|
|
273
|
+
.rdp-day_selected:hover {
|
|
274
|
+
color: white;
|
|
275
|
+
opacity: 1;
|
|
276
|
+
background-color: var(--rdp-accent-color);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.rdp-day_outside {
|
|
280
|
+
opacity: 0.5;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.rdp-day_selected:focus-visible {
|
|
284
|
+
/* Since the background is the same use again the outline */
|
|
285
|
+
outline: var(--rdp-outline);
|
|
286
|
+
outline-offset: 2px;
|
|
287
|
+
z-index: 1;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.rdp:not([dir='rtl']) .rdp-day_range_start:not(.rdp-day_range_end) {
|
|
291
|
+
border-top-right-radius: 0;
|
|
292
|
+
border-bottom-right-radius: 0;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.rdp:not([dir='rtl']) .rdp-day_range_end:not(.rdp-day_range_start) {
|
|
296
|
+
border-top-left-radius: 0;
|
|
297
|
+
border-bottom-left-radius: 0;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.rdp[dir='rtl'] .rdp-day_range_start:not(.rdp-day_range_end) {
|
|
301
|
+
border-top-left-radius: 0;
|
|
302
|
+
border-bottom-left-radius: 0;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.rdp[dir='rtl'] .rdp-day_range_end:not(.rdp-day_range_start) {
|
|
306
|
+
border-top-right-radius: 0;
|
|
307
|
+
border-bottom-right-radius: 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.rdp-day_range_end.rdp-day_range_start {
|
|
311
|
+
border-radius: 100%;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.rdp-day_range_middle {
|
|
315
|
+
border-radius: 0;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/*# sourceMappingURL=style.css.map */
|
|
319
|
+
|
|
320
|
+
/******************************
|
|
321
|
+
* Indico Custom Styling For Insights
|
|
322
|
+
*******************************/
|
|
323
|
+
.rdp-button:hover:not([disabled]):not(.rdp-day_selected) {
|
|
324
|
+
background-color: #976cec;
|
|
325
|
+
}
|
|
326
|
+
.rdp-button,
|
|
327
|
+
.rdp-day {
|
|
328
|
+
box-shadow: none;
|
|
329
|
+
color: #000000;
|
|
330
|
+
&:hover {
|
|
331
|
+
background-color: #6833d0;
|
|
332
|
+
color: white;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.rdp-head_cell,
|
|
337
|
+
.rdp-cell {
|
|
338
|
+
border: none;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.DayPickerInput-Overlay {
|
|
342
|
+
border-radius: 4px;
|
|
343
|
+
z-index: 999;
|
|
344
|
+
.rdp {
|
|
345
|
+
background: white;
|
|
346
|
+
z-index: 999;
|
|
347
|
+
border: solid 1px #000000;
|
|
348
|
+
border-radius: 4px;
|
|
349
|
+
box-shadow: 0px 1px 10px 0px rgba(0, 0, 0, 0.4);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.rdp-caption_label {
|
|
354
|
+
font-weight: 400;
|
|
355
|
+
font-size: 14px;
|
|
356
|
+
color: #000000;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.rdp-day_today {
|
|
360
|
+
background-color: #dbd5e6;
|
|
361
|
+
color: #ffffff;
|
|
362
|
+
font-weight: 400;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.rdp-button_reset {
|
|
366
|
+
&.rdp-button {
|
|
367
|
+
&.rdp-day {
|
|
368
|
+
&.rdp-day_selected {
|
|
369
|
+
background-color: #6833d0;
|
|
370
|
+
color: white;
|
|
371
|
+
|
|
372
|
+
&:focus {
|
|
373
|
+
color: white;
|
|
374
|
+
}
|
|
375
|
+
&:active {
|
|
376
|
+
color: white;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.rdp-head_cell {
|
|
384
|
+
color: #6833d0;
|
|
385
|
+
font-weight: 400;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.date__picker__trigger {
|
|
389
|
+
color: #000000;
|
|
390
|
+
cursor: pointer;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.custom__caption {
|
|
394
|
+
display: flex;
|
|
395
|
+
justify-content: space-between;
|
|
396
|
+
align-items: center;
|
|
397
|
+
padding: 15px 5px 15px 5px;
|
|
398
|
+
|
|
399
|
+
.custom__caption__text {
|
|
400
|
+
font-size: 14px;
|
|
401
|
+
color: #000000;
|
|
402
|
+
margin: 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
.custom__caption__action__button {
|
|
406
|
+
background: none;
|
|
407
|
+
border: none;
|
|
408
|
+
cursor: pointer;
|
|
409
|
+
box-shadow: none;
|
|
410
|
+
padding: 0 5px 0 5px;
|
|
411
|
+
|
|
412
|
+
border-radius: 60px;
|
|
413
|
+
color: #6833d0;
|
|
414
|
+
height: 20px;
|
|
415
|
+
width: 20px;
|
|
416
|
+
|
|
417
|
+
&:hover {
|
|
418
|
+
background-color: #6833d0;
|
|
419
|
+
color: #ffffff;
|
|
420
|
+
border-radius: 20px;
|
|
421
|
+
|
|
422
|
+
.rdp-nav_icon {
|
|
423
|
+
color: #ffffff;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.rdp-nav_icon {
|
|
428
|
+
color: #6833d0;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.visually-hidden,
|
|
434
|
+
.visually-hidden-focusable:not(:focus):not(:focus-within) {
|
|
435
|
+
border: 0 !important;
|
|
436
|
+
clip: rect(0, 0, 0, 0) !important;
|
|
437
|
+
height: 1px !important;
|
|
438
|
+
margin: -1px !important;
|
|
439
|
+
overflow: hidden !important;
|
|
440
|
+
padding: 0 !important;
|
|
441
|
+
white-space: nowrap !important;
|
|
442
|
+
width: 1px !important;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.visually-hidden:not(caption),
|
|
446
|
+
.visually-hidden-focusable:not(:focus):not(:focus-within):not(caption) {
|
|
447
|
+
position: absolute !important;
|
|
448
|
+
}
|
|
449
|
+
`;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// TODO: This component's migration was fast-tracked for Insights. Assess for potential refactor and documentation.
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
|
+
import FocusTrap from 'focus-trap-react';
|
|
5
|
+
import {
|
|
6
|
+
DayPicker,
|
|
7
|
+
SelectSingleEventHandler,
|
|
8
|
+
SelectRangeEventHandler,
|
|
9
|
+
useNavigation,
|
|
10
|
+
CaptionProps,
|
|
11
|
+
DateRange,
|
|
12
|
+
} from 'react-day-picker';
|
|
13
|
+
import { usePopper } from 'react-popper';
|
|
14
|
+
import { IconName, PermafrostComponent } from '@/types';
|
|
15
|
+
import { Icon } from '@/index';
|
|
16
|
+
|
|
17
|
+
import { StyledNoInputDatePicker } from './NoInputDatePicker.styles';
|
|
18
|
+
|
|
19
|
+
type Props = PermafrostComponent & {
|
|
20
|
+
ariaLabel?: string;
|
|
21
|
+
disableBeforeDate?: Date;
|
|
22
|
+
disableAfterDate?: Date;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
id: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
onChange: (value: Date | DateRange | undefined) => void;
|
|
27
|
+
selected?: Date | undefined;
|
|
28
|
+
value: Date | undefined;
|
|
29
|
+
triggerIcon: IconName;
|
|
30
|
+
triggerIconSize: [string | number];
|
|
31
|
+
isRangePicker?: boolean;
|
|
32
|
+
isOpen?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function CustomCaption(props: CaptionProps) {
|
|
36
|
+
const { goToMonth, nextMonth, previousMonth } = useNavigation();
|
|
37
|
+
return (
|
|
38
|
+
<div className="custom__caption">
|
|
39
|
+
<button
|
|
40
|
+
className="custom__caption__action__button"
|
|
41
|
+
disabled={!previousMonth}
|
|
42
|
+
onClick={() => previousMonth && goToMonth(previousMonth)}
|
|
43
|
+
>
|
|
44
|
+
<Icon size={[10]} ariaLabel="Previous Month" name="chevron-left" />
|
|
45
|
+
</button>
|
|
46
|
+
<h2 className="custom__caption__text">{format(props.displayMonth, 'MMM yyyy')}</h2>
|
|
47
|
+
<button
|
|
48
|
+
className="custom__caption__action__button"
|
|
49
|
+
disabled={!nextMonth}
|
|
50
|
+
onClick={() => nextMonth && goToMonth(nextMonth)}
|
|
51
|
+
>
|
|
52
|
+
<Icon size={[10]} ariaLabel="Next Month" name="chevron-right" />
|
|
53
|
+
</button>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
export const NoInputDatePicker = (props: Props) => {
|
|
58
|
+
const {
|
|
59
|
+
ariaLabel,
|
|
60
|
+
className,
|
|
61
|
+
disabled,
|
|
62
|
+
disableBeforeDate,
|
|
63
|
+
disableAfterDate,
|
|
64
|
+
id,
|
|
65
|
+
label,
|
|
66
|
+
onChange,
|
|
67
|
+
selected,
|
|
68
|
+
triggerIcon,
|
|
69
|
+
triggerIconSize,
|
|
70
|
+
isRangePicker,
|
|
71
|
+
isOpen,
|
|
72
|
+
} = props;
|
|
73
|
+
|
|
74
|
+
const [localSelected, setLocalSelected] = useState<Date | undefined>(selected || undefined);
|
|
75
|
+
const [range, setRange] = useState<DateRange | undefined>(undefined);
|
|
76
|
+
const [isPopperOpen, setIsPopperOpen] = useState(isOpen || false);
|
|
77
|
+
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
|
78
|
+
const popperRef = useRef<HTMLDivElement>(null);
|
|
79
|
+
const popper = usePopper(popperRef.current, popperElement, {
|
|
80
|
+
placement: 'bottom-start',
|
|
81
|
+
modifiers: [
|
|
82
|
+
{
|
|
83
|
+
name: 'offset',
|
|
84
|
+
options: {
|
|
85
|
+
offset: [-12, -12],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const [isTrapActive, setIsTrapActive] = useState(false);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (isOpen) {
|
|
95
|
+
// Delay the activation of the FocusTrap to allow the DayPicker to render
|
|
96
|
+
const timeoutId = setTimeout(() => setIsTrapActive(true), 0);
|
|
97
|
+
return () => clearTimeout(timeoutId);
|
|
98
|
+
} else {
|
|
99
|
+
setIsTrapActive(false);
|
|
100
|
+
}
|
|
101
|
+
}, [isOpen]);
|
|
102
|
+
|
|
103
|
+
const closePopper = () => {
|
|
104
|
+
setIsPopperOpen(false);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleDaySelect: SelectSingleEventHandler = (date) => {
|
|
108
|
+
setLocalSelected(date);
|
|
109
|
+
if (date) {
|
|
110
|
+
onChange(date);
|
|
111
|
+
closePopper();
|
|
112
|
+
} else {
|
|
113
|
+
onChange(date);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const handleRangeSelect: SelectRangeEventHandler = (range: DateRange | undefined) => {
|
|
118
|
+
setRange(range);
|
|
119
|
+
if (range?.from && range?.to) {
|
|
120
|
+
onChange(range);
|
|
121
|
+
closePopper();
|
|
122
|
+
} else {
|
|
123
|
+
onChange(range);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
return (
|
|
127
|
+
<StyledNoInputDatePicker
|
|
128
|
+
className={className}
|
|
129
|
+
aria-label={ariaLabel || 'date select'}
|
|
130
|
+
aria-describedby={`picker-label--${id}`}
|
|
131
|
+
data-cy={props['data-cy']}
|
|
132
|
+
data-testid={props['data-testid']}
|
|
133
|
+
id={id}
|
|
134
|
+
>
|
|
135
|
+
{label ? (
|
|
136
|
+
<div id={`picker-label--${id}`} className="visually-hidden">
|
|
137
|
+
{label}
|
|
138
|
+
</div>
|
|
139
|
+
) : null}
|
|
140
|
+
<div ref={popperRef} className="no__input__date__picker-inputParent">
|
|
141
|
+
<Icon
|
|
142
|
+
aria-label="Open date picker"
|
|
143
|
+
name={triggerIcon}
|
|
144
|
+
size={triggerIconSize}
|
|
145
|
+
className="date__picker__trigger"
|
|
146
|
+
data-testid={`datepicker-trigger-for-${id}`}
|
|
147
|
+
onClick={() => setIsPopperOpen(!isPopperOpen)}
|
|
148
|
+
/>
|
|
149
|
+
</div>
|
|
150
|
+
{isPopperOpen && (
|
|
151
|
+
<FocusTrap
|
|
152
|
+
active={isTrapActive}
|
|
153
|
+
focusTrapOptions={{
|
|
154
|
+
initialFocus: false,
|
|
155
|
+
allowOutsideClick: true,
|
|
156
|
+
clickOutsideDeactivates: true,
|
|
157
|
+
onDeactivate: closePopper,
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
<div
|
|
161
|
+
tabIndex={-1}
|
|
162
|
+
style={popper.styles.popper}
|
|
163
|
+
className="DayPickerInput-Overlay"
|
|
164
|
+
{...popper.attributes.popper}
|
|
165
|
+
ref={setPopperElement}
|
|
166
|
+
role="dialog"
|
|
167
|
+
aria-label="DayPicker calendar"
|
|
168
|
+
data-testid="datepicker-dialog"
|
|
169
|
+
>
|
|
170
|
+
{isRangePicker ? (
|
|
171
|
+
<DayPicker
|
|
172
|
+
components={{
|
|
173
|
+
Caption: CustomCaption,
|
|
174
|
+
}}
|
|
175
|
+
disabled={disabled}
|
|
176
|
+
mode={'range'}
|
|
177
|
+
defaultMonth={localSelected}
|
|
178
|
+
selected={range}
|
|
179
|
+
onSelect={handleRangeSelect}
|
|
180
|
+
fromDate={disableBeforeDate}
|
|
181
|
+
toDate={disableAfterDate}
|
|
182
|
+
data-testid="range-datepicker"
|
|
183
|
+
/>
|
|
184
|
+
) : (
|
|
185
|
+
<DayPicker
|
|
186
|
+
components={{
|
|
187
|
+
Caption: CustomCaption,
|
|
188
|
+
}}
|
|
189
|
+
disabled={disabled}
|
|
190
|
+
mode={'single'}
|
|
191
|
+
defaultMonth={localSelected}
|
|
192
|
+
selected={localSelected}
|
|
193
|
+
onSelect={handleDaySelect}
|
|
194
|
+
fromDate={disableBeforeDate}
|
|
195
|
+
toDate={disableAfterDate}
|
|
196
|
+
data-testid="single-datepicker"
|
|
197
|
+
/>
|
|
198
|
+
)}
|
|
199
|
+
</div>
|
|
200
|
+
</FocusTrap>
|
|
201
|
+
)}
|
|
202
|
+
</StyledNoInputDatePicker>
|
|
203
|
+
);
|
|
204
|
+
};
|