@coinbase/cds-mobile 8.53.1 → 8.54.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 +10 -0
- package/README.md +5 -2
- package/dts/buttons/IconButton.d.ts +23 -1
- package/dts/buttons/IconButton.d.ts.map +1 -1
- package/dts/controls/InputIconButton.d.ts +22 -1
- package/dts/controls/InputIconButton.d.ts.map +1 -1
- package/dts/dates/Calendar.d.ts +170 -0
- package/dts/dates/Calendar.d.ts.map +1 -0
- package/dts/dates/DateInput.d.ts +2 -2
- package/dts/dates/DateInput.d.ts.map +1 -1
- package/dts/dates/DatePicker.d.ts +136 -67
- package/dts/dates/DatePicker.d.ts.map +1 -1
- package/dts/overlays/drawer/Drawer.d.ts +4 -0
- package/dts/overlays/drawer/Drawer.d.ts.map +1 -1
- package/dts/overlays/tooltip/Tooltip.d.ts +9 -1
- package/dts/overlays/tooltip/Tooltip.d.ts.map +1 -1
- package/esm/buttons/IconButton.js +4 -3
- package/esm/controls/InputIconButton.js +4 -3
- package/esm/dates/Calendar.js +346 -0
- package/esm/dates/DateInput.js +3 -1
- package/esm/dates/DatePicker.js +116 -39
- package/esm/dates/__stories__/Calendar.stories.js +360 -0
- package/esm/dates/__stories__/DatePicker.stories.js +51 -25
- package/esm/overlays/drawer/Drawer.js +4 -2
- package/esm/overlays/tooltip/Tooltip.js +7 -2
- package/package.json +2 -4
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useLocale } from '@coinbase/cds-common/system/LocaleProvider';
|
|
3
|
+
import { Accordion, AccordionItem } from '../../accordion';
|
|
4
|
+
import { Button } from '../../buttons/Button';
|
|
5
|
+
import { Chip } from '../../chips';
|
|
6
|
+
import { Example, ExampleScreen } from '../../examples/ExampleScreen';
|
|
7
|
+
import { useTheme } from '../../hooks/useTheme';
|
|
8
|
+
import { Icon } from '../../icons';
|
|
9
|
+
import { Box } from '../../layout';
|
|
10
|
+
import { AnimatedCaret } from '../../motion/AnimatedCaret';
|
|
11
|
+
import { Tray } from '../../overlays/tray/Tray';
|
|
12
|
+
import { Calendar } from '../Calendar';
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const today = new Date(new Date().setHours(0, 0, 0, 0));
|
|
15
|
+
const nextMonth15th = new Date(today.getFullYear(), today.getMonth() + 1, 15);
|
|
16
|
+
const lastMonth15th = new Date(today.getFullYear(), today.getMonth() - 1, 15);
|
|
17
|
+
const nextWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7);
|
|
18
|
+
const yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
|
|
19
|
+
const tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
|
|
20
|
+
const twoDaysAgo = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 2);
|
|
21
|
+
|
|
22
|
+
// Generate all weekend date ranges for a wide range (10 years before and after)
|
|
23
|
+
const getWeekendDates = centerDate => {
|
|
24
|
+
const weekends = [];
|
|
25
|
+
|
|
26
|
+
// Cover 10 years before and after to ensure all weekends are disabled
|
|
27
|
+
const startDate = new Date(centerDate.getFullYear() - 10, 0, 1);
|
|
28
|
+
const endDate = new Date(centerDate.getFullYear() + 10, 11, 31);
|
|
29
|
+
|
|
30
|
+
// Find the first Saturday in the range
|
|
31
|
+
const currentDate = new Date(startDate);
|
|
32
|
+
const dayOfWeek = currentDate.getDay();
|
|
33
|
+
const daysUntilSaturday = dayOfWeek === 6 ? 0 : (6 - dayOfWeek + 7) % 7;
|
|
34
|
+
currentDate.setDate(currentDate.getDate() + daysUntilSaturday);
|
|
35
|
+
|
|
36
|
+
// Iterate through weekends, jumping 7 days at a time
|
|
37
|
+
while (currentDate <= endDate) {
|
|
38
|
+
const saturday = new Date(currentDate);
|
|
39
|
+
const sunday = new Date(currentDate);
|
|
40
|
+
sunday.setDate(sunday.getDate() + 1);
|
|
41
|
+
|
|
42
|
+
// Add the weekend as a date range tuple
|
|
43
|
+
weekends.push([saturday, sunday]);
|
|
44
|
+
|
|
45
|
+
// Jump to next Saturday (7 days later)
|
|
46
|
+
currentDate.setDate(currentDate.getDate() + 7);
|
|
47
|
+
}
|
|
48
|
+
return weekends;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Compute weekends once at module level
|
|
52
|
+
const disabledWeekend = getWeekendDates(today);
|
|
53
|
+
const DATE_ACCORDION_ITEM_KEY = 'date';
|
|
54
|
+
const formatDateLabel = (date, locale) => {
|
|
55
|
+
if (!date) {
|
|
56
|
+
return 'Select date';
|
|
57
|
+
}
|
|
58
|
+
return date.toLocaleDateString(locale, {
|
|
59
|
+
month: 'short',
|
|
60
|
+
day: 'numeric',
|
|
61
|
+
year: 'numeric'
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const CalendarTrayExample = /*#__PURE__*/memo(function CalendarTrayExample(_ref) {
|
|
65
|
+
let {
|
|
66
|
+
renderTrigger
|
|
67
|
+
} = _ref;
|
|
68
|
+
const {
|
|
69
|
+
locale
|
|
70
|
+
} = useLocale();
|
|
71
|
+
const [date, setDate] = useState(null);
|
|
72
|
+
const [showPicker, setShowPicker] = useState(false);
|
|
73
|
+
const [calendarSelectedDate, setCalendarSelectedDate] = useState(null);
|
|
74
|
+
const calendarRef = useRef(null);
|
|
75
|
+
const handleOpenPicker = useCallback(() => {
|
|
76
|
+
setCalendarSelectedDate(date);
|
|
77
|
+
setShowPicker(true);
|
|
78
|
+
}, [date]);
|
|
79
|
+
const handleClosePicker = useCallback(() => {
|
|
80
|
+
setShowPicker(false);
|
|
81
|
+
}, []);
|
|
82
|
+
const handleCancelPicker = useCallback(() => {
|
|
83
|
+
setCalendarSelectedDate(null);
|
|
84
|
+
handleClosePicker();
|
|
85
|
+
}, [handleClosePicker]);
|
|
86
|
+
const handleCalendarDatePress = useCallback(selectedDate => {
|
|
87
|
+
setCalendarSelectedDate(selectedDate);
|
|
88
|
+
}, []);
|
|
89
|
+
const handleModalShow = useCallback(() => {
|
|
90
|
+
var _calendarRef$current;
|
|
91
|
+
(_calendarRef$current = calendarRef.current) == null || _calendarRef$current.focusInitialDate();
|
|
92
|
+
}, []);
|
|
93
|
+
const handleConfirmCalendar = useCallback(() => {
|
|
94
|
+
if (calendarSelectedDate) {
|
|
95
|
+
setDate(calendarSelectedDate);
|
|
96
|
+
handleClosePicker();
|
|
97
|
+
}
|
|
98
|
+
}, [calendarSelectedDate, handleClosePicker]);
|
|
99
|
+
const trayFooter = useMemo(() => /*#__PURE__*/_jsx(Box, {
|
|
100
|
+
paddingTop: 3,
|
|
101
|
+
paddingX: 3,
|
|
102
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
103
|
+
block: true,
|
|
104
|
+
compact: true,
|
|
105
|
+
accessibilityHint: !calendarSelectedDate ? 'Select a date first' : undefined,
|
|
106
|
+
accessibilityLabel: "Confirm date selection",
|
|
107
|
+
disabled: !calendarSelectedDate,
|
|
108
|
+
onPress: handleConfirmCalendar,
|
|
109
|
+
children: "Confirm"
|
|
110
|
+
})
|
|
111
|
+
}), [calendarSelectedDate, handleConfirmCalendar]);
|
|
112
|
+
const formattedLabel = formatDateLabel(date, locale);
|
|
113
|
+
const triggerProps = useMemo(() => ({
|
|
114
|
+
formattedLabel,
|
|
115
|
+
onOpen: handleOpenPicker,
|
|
116
|
+
showPicker
|
|
117
|
+
}), [formattedLabel, handleOpenPicker, showPicker]);
|
|
118
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
119
|
+
children: [renderTrigger(triggerProps), showPicker && /*#__PURE__*/_jsx(Tray, {
|
|
120
|
+
accessibilityRole: "none",
|
|
121
|
+
footer: trayFooter,
|
|
122
|
+
handleBarAccessibilityLabel: "Close calendar",
|
|
123
|
+
handleBarVariant: "inside",
|
|
124
|
+
onCloseComplete: handleCancelPicker,
|
|
125
|
+
onOpenComplete: handleModalShow,
|
|
126
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
127
|
+
ref: calendarRef,
|
|
128
|
+
onPressDate: handleCalendarDatePress,
|
|
129
|
+
paddingBottom: 2,
|
|
130
|
+
paddingX: 2,
|
|
131
|
+
selectedDate: calendarSelectedDate
|
|
132
|
+
})
|
|
133
|
+
})]
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
const CalendarChipWithTrayExample = () => {
|
|
137
|
+
const renderTrigger = useCallback(_ref2 => {
|
|
138
|
+
let {
|
|
139
|
+
formattedLabel,
|
|
140
|
+
onOpen,
|
|
141
|
+
showPicker
|
|
142
|
+
} = _ref2;
|
|
143
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
144
|
+
alignSelf: "flex-start",
|
|
145
|
+
children: /*#__PURE__*/_jsx(Chip, {
|
|
146
|
+
compact: true,
|
|
147
|
+
accessibilityLabel: formattedLabel,
|
|
148
|
+
end: /*#__PURE__*/_jsx(AnimatedCaret, {
|
|
149
|
+
active: true,
|
|
150
|
+
color: "fg",
|
|
151
|
+
rotate: showPicker ? 0 : 180,
|
|
152
|
+
size: "xs"
|
|
153
|
+
}),
|
|
154
|
+
onPress: onOpen,
|
|
155
|
+
children: formattedLabel
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
}, []);
|
|
159
|
+
return /*#__PURE__*/_jsx(CalendarTrayExample, {
|
|
160
|
+
renderTrigger: renderTrigger
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const CalendarChipWithTrayButtonExample = () => {
|
|
164
|
+
const renderTrigger = useCallback(_ref3 => {
|
|
165
|
+
let {
|
|
166
|
+
formattedLabel,
|
|
167
|
+
onOpen
|
|
168
|
+
} = _ref3;
|
|
169
|
+
return /*#__PURE__*/_jsx(Button, {
|
|
170
|
+
compact: true,
|
|
171
|
+
accessibilityLabel: formattedLabel,
|
|
172
|
+
onPress: onOpen,
|
|
173
|
+
children: formattedLabel
|
|
174
|
+
});
|
|
175
|
+
}, []);
|
|
176
|
+
return /*#__PURE__*/_jsx(CalendarTrayExample, {
|
|
177
|
+
renderTrigger: renderTrigger
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
const CalendarAccordionExample = () => {
|
|
181
|
+
const {
|
|
182
|
+
locale
|
|
183
|
+
} = useLocale();
|
|
184
|
+
const [date, setDate] = useState(null);
|
|
185
|
+
const [activeKey, setActiveKey] = useState(null);
|
|
186
|
+
const expanded = activeKey === DATE_ACCORDION_ITEM_KEY;
|
|
187
|
+
const calendarRef = useRef(null);
|
|
188
|
+
const handleDatePress = useCallback(selectedDate => {
|
|
189
|
+
setDate(selectedDate);
|
|
190
|
+
setActiveKey(null);
|
|
191
|
+
}, []);
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (expanded) {
|
|
194
|
+
const id = requestAnimationFrame(() => {
|
|
195
|
+
var _calendarRef$current2;
|
|
196
|
+
(_calendarRef$current2 = calendarRef.current) == null || _calendarRef$current2.focusInitialDate();
|
|
197
|
+
});
|
|
198
|
+
return () => cancelAnimationFrame(id);
|
|
199
|
+
}
|
|
200
|
+
}, [expanded]);
|
|
201
|
+
return /*#__PURE__*/_jsx(Accordion, {
|
|
202
|
+
activeKey: activeKey,
|
|
203
|
+
setActiveKey: setActiveKey,
|
|
204
|
+
children: /*#__PURE__*/_jsx(AccordionItem, {
|
|
205
|
+
itemKey: DATE_ACCORDION_ITEM_KEY,
|
|
206
|
+
media: /*#__PURE__*/_jsx(Icon, {
|
|
207
|
+
color: "fg",
|
|
208
|
+
name: "calendarEmpty"
|
|
209
|
+
}),
|
|
210
|
+
subtitle: formatDateLabel(date, locale),
|
|
211
|
+
title: "Date",
|
|
212
|
+
children: expanded ? /*#__PURE__*/_jsx(Calendar, {
|
|
213
|
+
ref: calendarRef,
|
|
214
|
+
onPressDate: handleDatePress,
|
|
215
|
+
selectedDate: date
|
|
216
|
+
}) : null
|
|
217
|
+
})
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
const CalendarScreen = () => {
|
|
221
|
+
const [basicDate, setBasicDate] = useState(today);
|
|
222
|
+
const [noSelectionDate, setNoSelectionDate] = useState(null);
|
|
223
|
+
const [seedDateDate, setSeedDateDate] = useState(null);
|
|
224
|
+
const [minMaxDate, setMinMaxDate] = useState(today);
|
|
225
|
+
const [futureDatesDate, setFutureDatesDate] = useState(null);
|
|
226
|
+
const [highlightedDate, setHighlightedDate] = useState(today);
|
|
227
|
+
const [disabledDatesDate, setDisabledDatesDate] = useState(null);
|
|
228
|
+
const [rangeDate, setRangeDate] = useState(today);
|
|
229
|
+
const [hiddenControlsDate, setHiddenControlsDate] = useState(today);
|
|
230
|
+
const highlightedRange = [yesterday, nextWeek];
|
|
231
|
+
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
|
232
|
+
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
|
233
|
+
const {
|
|
234
|
+
color
|
|
235
|
+
} = useTheme();
|
|
236
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
237
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
238
|
+
title: "Basic",
|
|
239
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
240
|
+
onPressDate: setBasicDate,
|
|
241
|
+
selectedDate: basicDate
|
|
242
|
+
})
|
|
243
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
244
|
+
title: "No selection",
|
|
245
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
246
|
+
onPressDate: setNoSelectionDate,
|
|
247
|
+
selectedDate: noSelectionDate
|
|
248
|
+
})
|
|
249
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
250
|
+
title: "With seedDate (different month)",
|
|
251
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
252
|
+
onPressDate: setSeedDateDate,
|
|
253
|
+
seedDate: nextMonth15th,
|
|
254
|
+
selectedDate: seedDateDate
|
|
255
|
+
})
|
|
256
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
257
|
+
title: "With min/max dates",
|
|
258
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
259
|
+
disabledDateError: "Date is outside allowed range",
|
|
260
|
+
maxDate: nextMonth15th,
|
|
261
|
+
minDate: lastMonth15th,
|
|
262
|
+
onPressDate: setMinMaxDate,
|
|
263
|
+
selectedDate: minMaxDate
|
|
264
|
+
})
|
|
265
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
266
|
+
title: "Future dates only",
|
|
267
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
268
|
+
disabledDateError: "Past dates are not available",
|
|
269
|
+
minDate: today,
|
|
270
|
+
onPressDate: setFutureDatesDate,
|
|
271
|
+
selectedDate: futureDatesDate
|
|
272
|
+
})
|
|
273
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
274
|
+
title: "With highlighted dates",
|
|
275
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
276
|
+
highlightedDates: [yesterday, today, nextWeek],
|
|
277
|
+
onPressDate: setHighlightedDate,
|
|
278
|
+
selectedDate: highlightedDate
|
|
279
|
+
})
|
|
280
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
281
|
+
title: "With disabled dates",
|
|
282
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
283
|
+
disabledDateError: "Weekends are not available",
|
|
284
|
+
disabledDates: disabledWeekend,
|
|
285
|
+
onPressDate: setDisabledDatesDate,
|
|
286
|
+
seedDate: today,
|
|
287
|
+
selectedDate: disabledDatesDate
|
|
288
|
+
})
|
|
289
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
290
|
+
title: "With date range",
|
|
291
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
292
|
+
highlightedDates: [highlightedRange],
|
|
293
|
+
onPressDate: setRangeDate,
|
|
294
|
+
selectedDate: rangeDate
|
|
295
|
+
})
|
|
296
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
297
|
+
title: "Hidden controls",
|
|
298
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
299
|
+
hideControls: true,
|
|
300
|
+
maxDate: lastDayOfMonth,
|
|
301
|
+
minDate: firstDayOfMonth,
|
|
302
|
+
onPressDate: setHiddenControlsDate,
|
|
303
|
+
selectedDate: hiddenControlsDate
|
|
304
|
+
})
|
|
305
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
306
|
+
title: "Disabled",
|
|
307
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
308
|
+
disabled: true,
|
|
309
|
+
selectedDate: today
|
|
310
|
+
})
|
|
311
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
312
|
+
title: "Slot styling",
|
|
313
|
+
children: /*#__PURE__*/_jsx(Calendar, {
|
|
314
|
+
disabledDateError: "Date unavailable",
|
|
315
|
+
disabledDates: [twoDaysAgo],
|
|
316
|
+
highlightedDates: [tomorrow],
|
|
317
|
+
maxDate: nextMonth15th,
|
|
318
|
+
minDate: lastMonth15th,
|
|
319
|
+
onPressDate: setBasicDate,
|
|
320
|
+
selectedDate: basicDate,
|
|
321
|
+
styles: {
|
|
322
|
+
root: {
|
|
323
|
+
borderColor: color.bgLineHeavy,
|
|
324
|
+
borderRadius: 16,
|
|
325
|
+
borderWidth: 1,
|
|
326
|
+
padding: 12
|
|
327
|
+
},
|
|
328
|
+
header: {
|
|
329
|
+
backgroundColor: color.bgPositiveWash,
|
|
330
|
+
borderRadius: 16,
|
|
331
|
+
paddingBottom: 0
|
|
332
|
+
},
|
|
333
|
+
content: {
|
|
334
|
+
paddingVertical: 8
|
|
335
|
+
},
|
|
336
|
+
day: {
|
|
337
|
+
borderColor: color.bgNegative,
|
|
338
|
+
borderWidth: 1
|
|
339
|
+
},
|
|
340
|
+
navigation: {
|
|
341
|
+
borderColor: color.bgLineHeavy,
|
|
342
|
+
borderRadius: 8,
|
|
343
|
+
borderStyle: 'dashed',
|
|
344
|
+
borderWidth: 1
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
349
|
+
title: "With tray (Chip trigger)",
|
|
350
|
+
children: /*#__PURE__*/_jsx(CalendarChipWithTrayExample, {})
|
|
351
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
352
|
+
title: "With tray (Button trigger)",
|
|
353
|
+
children: /*#__PURE__*/_jsx(CalendarChipWithTrayButtonExample, {})
|
|
354
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
355
|
+
title: "With Accordion (select to collapse)",
|
|
356
|
+
children: /*#__PURE__*/_jsx(CalendarAccordionExample, {})
|
|
357
|
+
})]
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
export default CalendarScreen;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
const _excluded = ["date"];
|
|
1
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
2
4
|
import { useState } from 'react';
|
|
3
5
|
import { InputLabel } from '../../controls/InputLabel';
|
|
4
6
|
import { TextInput } from '../../controls/TextInput';
|
|
@@ -10,23 +12,25 @@ import { Tooltip } from '../../overlays/tooltip/Tooltip';
|
|
|
10
12
|
import { Text } from '../../typography/Text';
|
|
11
13
|
import { DatePicker } from '../DatePicker';
|
|
12
14
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
const today = new Date(new Date(
|
|
15
|
+
const today = new Date(new Date().setHours(0, 0, 0, 0));
|
|
14
16
|
const nextMonth15th = new Date(today.getFullYear(), today.getMonth() + 1, 15);
|
|
15
|
-
const
|
|
17
|
+
const tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
|
|
16
18
|
const exampleProps = {
|
|
17
|
-
maxDate: nextMonth15th,
|
|
18
|
-
minDate: lastMonth15th,
|
|
19
19
|
invalidDateError: 'Please enter a valid date',
|
|
20
20
|
disabledDateError: 'Date unavailable',
|
|
21
21
|
requiredError: 'This field is required'
|
|
22
22
|
};
|
|
23
|
-
const ExampleDatePicker =
|
|
24
|
-
|
|
23
|
+
const ExampleDatePicker = _ref => {
|
|
24
|
+
let {
|
|
25
|
+
date
|
|
26
|
+
} = _ref,
|
|
27
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
28
|
+
const [dateValue, setDateValue] = useState(date != null ? date : null);
|
|
25
29
|
const [error, setError] = useState(null);
|
|
26
30
|
return /*#__PURE__*/_jsx(DatePicker, _extends({}, exampleProps, props, {
|
|
27
|
-
date:
|
|
31
|
+
date: dateValue,
|
|
28
32
|
error: error,
|
|
29
|
-
onChangeDate:
|
|
33
|
+
onChangeDate: setDateValue,
|
|
30
34
|
onErrorDate: setError
|
|
31
35
|
}));
|
|
32
36
|
};
|
|
@@ -36,20 +40,20 @@ export const FullExample = () => {
|
|
|
36
40
|
title: "Default",
|
|
37
41
|
children: /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
38
42
|
required: true,
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
label: "Birthdate",
|
|
44
|
+
openCalendarAccessibilityLabel: "Birthdate calendar"
|
|
41
45
|
})
|
|
42
46
|
}), /*#__PURE__*/_jsx(Example, {
|
|
43
47
|
title: "Multiple pickers",
|
|
44
48
|
children: /*#__PURE__*/_jsxs(HStack, {
|
|
45
49
|
gap: 2,
|
|
46
50
|
children: [/*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
47
|
-
calendarIconButtonAccessibilityLabel: "Example 1 calendar",
|
|
48
51
|
label: "Example 1",
|
|
52
|
+
openCalendarAccessibilityLabel: "Example 1 calendar",
|
|
49
53
|
width: "auto"
|
|
50
54
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
51
|
-
calendarIconButtonAccessibilityLabel: "Example 2 calendar",
|
|
52
55
|
label: "Example 2",
|
|
56
|
+
openCalendarAccessibilityLabel: "Example 2 calendar",
|
|
53
57
|
width: "auto"
|
|
54
58
|
})]
|
|
55
59
|
})
|
|
@@ -62,8 +66,8 @@ export const FullExample = () => {
|
|
|
62
66
|
placeholder: "1",
|
|
63
67
|
width: "auto"
|
|
64
68
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
65
|
-
calendarIconButtonAccessibilityLabel: "Example calendar",
|
|
66
69
|
label: "Example Date",
|
|
70
|
+
openCalendarAccessibilityLabel: "Example calendar",
|
|
67
71
|
width: "auto"
|
|
68
72
|
})]
|
|
69
73
|
})
|
|
@@ -76,8 +80,8 @@ export const FullExample = () => {
|
|
|
76
80
|
placeholder: "1",
|
|
77
81
|
width: "50%"
|
|
78
82
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
79
|
-
calendarIconButtonAccessibilityLabel: "Example calendar",
|
|
80
83
|
label: "Example Date",
|
|
84
|
+
openCalendarAccessibilityLabel: "Example calendar",
|
|
81
85
|
width: "auto"
|
|
82
86
|
})]
|
|
83
87
|
})
|
|
@@ -85,7 +89,6 @@ export const FullExample = () => {
|
|
|
85
89
|
title: "DatePicker with labelNode",
|
|
86
90
|
children: /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
87
91
|
accessibilityLabel: "Birthdate",
|
|
88
|
-
calendarIconButtonAccessibilityLabel: "Birthdate calendar",
|
|
89
92
|
labelNode: /*#__PURE__*/_jsxs(HStack, {
|
|
90
93
|
alignItems: "center",
|
|
91
94
|
children: [/*#__PURE__*/_jsx(InputLabel, {
|
|
@@ -100,7 +103,8 @@ export const FullExample = () => {
|
|
|
100
103
|
size: "xs"
|
|
101
104
|
})
|
|
102
105
|
})]
|
|
103
|
-
})
|
|
106
|
+
}),
|
|
107
|
+
openCalendarAccessibilityLabel: "Birthdate calendar"
|
|
104
108
|
})
|
|
105
109
|
}), /*#__PURE__*/_jsx(Example, {
|
|
106
110
|
title: "DatePicker fit-content width",
|
|
@@ -108,19 +112,41 @@ export const FullExample = () => {
|
|
|
108
112
|
flexWrap: "wrap",
|
|
109
113
|
gap: 2,
|
|
110
114
|
children: [/*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
111
|
-
calendarIconButtonAccessibilityLabel: "Example calendar",
|
|
112
115
|
label: "Example Date",
|
|
116
|
+
openCalendarAccessibilityLabel: "Example calendar",
|
|
113
117
|
width: "fit-content"
|
|
114
118
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
115
|
-
calendarIconButtonAccessibilityLabel: "Example calendar 2",
|
|
116
119
|
label: "Example Date 2",
|
|
120
|
+
openCalendarAccessibilityLabel: "Example calendar 2",
|
|
117
121
|
width: "fit-content"
|
|
118
122
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
119
|
-
calendarIconButtonAccessibilityLabel: "Example calendar 3",
|
|
120
123
|
label: "Example Date 3",
|
|
124
|
+
openCalendarAccessibilityLabel: "Example calendar 3",
|
|
121
125
|
width: "fit-content"
|
|
122
126
|
})]
|
|
123
127
|
})
|
|
128
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
129
|
+
title: "DatePicker with seed date (next month)",
|
|
130
|
+
children: /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
131
|
+
label: "Event date",
|
|
132
|
+
openCalendarAccessibilityLabel: "Seed date calendar",
|
|
133
|
+
seedDate: nextMonth15th
|
|
134
|
+
})
|
|
135
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
136
|
+
title: "DatePicker with pre-selected date (next month)",
|
|
137
|
+
children: /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
138
|
+
date: nextMonth15th,
|
|
139
|
+
label: "Event date",
|
|
140
|
+
openCalendarAccessibilityLabel: "Seed date calendar"
|
|
141
|
+
})
|
|
142
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
143
|
+
title: "DatePicker with minimum date of tomorrow",
|
|
144
|
+
children: /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
145
|
+
disabledDateError: "Future dates only",
|
|
146
|
+
invalidDateError: "Future dates only",
|
|
147
|
+
label: "Future date",
|
|
148
|
+
minDate: tomorrow
|
|
149
|
+
})
|
|
124
150
|
})]
|
|
125
151
|
});
|
|
126
152
|
};
|
|
@@ -132,7 +158,6 @@ export const CustomLabel = () => {
|
|
|
132
158
|
gap: 2,
|
|
133
159
|
children: [/*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
134
160
|
accessibilityLabel: "Date of birth",
|
|
135
|
-
calendarIconButtonAccessibilityLabel: "Date of birth calendar",
|
|
136
161
|
labelNode: /*#__PURE__*/_jsxs(HStack, {
|
|
137
162
|
alignItems: "center",
|
|
138
163
|
children: [/*#__PURE__*/_jsx(InputLabel, {
|
|
@@ -147,11 +172,11 @@ export const CustomLabel = () => {
|
|
|
147
172
|
size: "xs"
|
|
148
173
|
})
|
|
149
174
|
})]
|
|
150
|
-
})
|
|
175
|
+
}),
|
|
176
|
+
openCalendarAccessibilityLabel: "Date of birth calendar"
|
|
151
177
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
152
178
|
compact: true,
|
|
153
179
|
accessibilityLabel: "Start date",
|
|
154
|
-
calendarIconButtonAccessibilityLabel: "Start date calendar",
|
|
155
180
|
labelNode: /*#__PURE__*/_jsxs(HStack, {
|
|
156
181
|
alignItems: "center",
|
|
157
182
|
gap: 0.5,
|
|
@@ -162,10 +187,10 @@ export const CustomLabel = () => {
|
|
|
162
187
|
font: "label1",
|
|
163
188
|
children: "*"
|
|
164
189
|
})]
|
|
165
|
-
})
|
|
190
|
+
}),
|
|
191
|
+
openCalendarAccessibilityLabel: "Start date calendar"
|
|
166
192
|
}), /*#__PURE__*/_jsx(ExampleDatePicker, {
|
|
167
193
|
accessibilityLabel: "End date",
|
|
168
|
-
calendarIconButtonAccessibilityLabel: "End date calendar",
|
|
169
194
|
labelNode: /*#__PURE__*/_jsxs(HStack, {
|
|
170
195
|
alignItems: "center",
|
|
171
196
|
gap: 1,
|
|
@@ -178,7 +203,8 @@ export const CustomLabel = () => {
|
|
|
178
203
|
children: "(optional)"
|
|
179
204
|
})]
|
|
180
205
|
}),
|
|
181
|
-
labelVariant: "inside"
|
|
206
|
+
labelVariant: "inside",
|
|
207
|
+
openCalendarAccessibilityLabel: "End date calendar"
|
|
182
208
|
})]
|
|
183
209
|
})
|
|
184
210
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["children", "pin", "onCloseComplete", "preventDismissGestures", "preventHardwareBackBehaviorAndroid", "handleBarVariant", "hideHandleBar", "disableCapturePanGestureToDismiss", "onBlur", "verticalDrawerPercentageOfView", "handleBarAccessibilityLabel", "accessibilityLabel", "accessibilityLabelledBy", "reduceMotion", "style", "styles", "accessibilityRole", "animationType"];
|
|
1
|
+
const _excluded = ["children", "pin", "onCloseComplete", "preventDismissGestures", "preventHardwareBackBehaviorAndroid", "handleBarVariant", "hideHandleBar", "disableCapturePanGestureToDismiss", "onBlur", "verticalDrawerPercentageOfView", "handleBarAccessibilityLabel", "accessibilityLabel", "accessibilityLabelledBy", "reduceMotion", "onOpenComplete", "style", "styles", "accessibilityRole", "animationType"];
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
4
|
import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
@@ -39,6 +39,7 @@ export const Drawer = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function Drawer(
|
|
|
39
39
|
accessibilityLabel,
|
|
40
40
|
accessibilityLabelledBy,
|
|
41
41
|
reduceMotion,
|
|
42
|
+
onOpenComplete,
|
|
42
43
|
style,
|
|
43
44
|
styles,
|
|
44
45
|
accessibilityRole = 'alert',
|
|
@@ -95,10 +96,11 @@ export const Drawer = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function Drawer(
|
|
|
95
96
|
} = _ref4;
|
|
96
97
|
if (finished) {
|
|
97
98
|
isMounted.current = true;
|
|
99
|
+
onOpenComplete == null || onOpenComplete();
|
|
98
100
|
}
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
|
-
}, [drawerAnimation, animateDrawerIn, animateOverlayIn]);
|
|
103
|
+
}, [drawerAnimation, animateDrawerIn, animateOverlayIn, onOpenComplete]);
|
|
102
104
|
const panGestureHandlers = useDrawerPanResponder({
|
|
103
105
|
pin,
|
|
104
106
|
drawerAnimation,
|
|
@@ -19,6 +19,7 @@ export const Tooltip = /*#__PURE__*/memo(_ref => {
|
|
|
19
19
|
accessibilityHint,
|
|
20
20
|
accessibilityLabelForContent,
|
|
21
21
|
accessibilityHintForContent,
|
|
22
|
+
accessibilityState,
|
|
22
23
|
visible,
|
|
23
24
|
invertColorScheme = true,
|
|
24
25
|
elevation,
|
|
@@ -92,8 +93,12 @@ export const Tooltip = /*#__PURE__*/memo(_ref => {
|
|
|
92
93
|
// equals the component where when you click on it, it will show the tooltip
|
|
93
94
|
const accessibilityPropsForTrigger = useMemo(() => ({
|
|
94
95
|
accessibilityLabel: typeof children === 'string' && accessibilityLabel === undefined ? children : accessibilityLabel,
|
|
95
|
-
accessibilityHint: typeof children === 'string' && accessibilityHint === undefined ? children : accessibilityHint
|
|
96
|
-
|
|
96
|
+
accessibilityHint: typeof children === 'string' && accessibilityHint === undefined ? children : accessibilityHint,
|
|
97
|
+
// accessibilityState is applied to the trigger regardless of screen reader usage.
|
|
98
|
+
// Only set it when you need screen reader behavior.
|
|
99
|
+
// e.g. disabled = true: state is announced and the trigger cannot activate
|
|
100
|
+
accessibilityState
|
|
101
|
+
}), [children, accessibilityLabel, accessibilityHint, accessibilityState]);
|
|
97
102
|
const accessibilityPropsForContent = useMemo(() => ({
|
|
98
103
|
accessibilityLabel: typeof content === 'string' && accessibilityLabelForContent === undefined ? content : accessibilityLabelForContent,
|
|
99
104
|
accessibilityHint: typeof content === 'string' && accessibilityHintForContent === undefined ? content : accessibilityHintForContent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cds-mobile",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.54.0",
|
|
4
4
|
"description": "Coinbase Design System - Mobile",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -187,7 +187,6 @@
|
|
|
187
187
|
"lottie-react-native": "^6.7.0",
|
|
188
188
|
"react": "^18.3.1",
|
|
189
189
|
"react-native": "^0.74.5",
|
|
190
|
-
"react-native-date-picker": "^4.4.2",
|
|
191
190
|
"react-native-gesture-handler": "^2.16.2",
|
|
192
191
|
"react-native-inappbrowser-reborn": "^3.7.0",
|
|
193
192
|
"react-native-linear-gradient": "^2.8.3",
|
|
@@ -198,7 +197,7 @@
|
|
|
198
197
|
"react-native-svg": "^14.1.0"
|
|
199
198
|
},
|
|
200
199
|
"dependencies": {
|
|
201
|
-
"@coinbase/cds-common": "^8.
|
|
200
|
+
"@coinbase/cds-common": "^8.54.0",
|
|
202
201
|
"@coinbase/cds-icons": "^5.13.0",
|
|
203
202
|
"@coinbase/cds-illustrations": "^4.34.0",
|
|
204
203
|
"@coinbase/cds-lottie-files": "^3.3.4",
|
|
@@ -223,7 +222,6 @@
|
|
|
223
222
|
"eslint-plugin-reanimated": "^2.0.1",
|
|
224
223
|
"lottie-react-native": "6.7.0",
|
|
225
224
|
"react-native-accessibility-engine": "^3.2.0",
|
|
226
|
-
"react-native-date-picker": "4.4.2",
|
|
227
225
|
"react-native-gesture-handler": "2.16.2",
|
|
228
226
|
"react-native-inappbrowser-reborn": "3.7.0",
|
|
229
227
|
"react-native-linear-gradient": "2.8.3",
|