@primer/components 0.0.0-2021922191125 → 0.0.0-2021922204627

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +3 -3
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +28 -28
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  7. package/lib/Autocomplete/Autocomplete.d.ts +4 -2
  8. package/lib/Autocomplete/AutocompleteInput.d.ts +4 -2
  9. package/lib/DatePicker/DatePicker.d.ts +48 -0
  10. package/lib/DatePicker/DatePicker.js +82 -0
  11. package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
  12. package/lib/DatePicker/DatePickerAnchor.js +88 -0
  13. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  14. package/lib/DatePicker/DatePickerOverlay.js +39 -0
  15. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  16. package/lib/DatePicker/DatePickerPanel.js +43 -0
  17. package/lib/DatePicker/Day.d.ts +14 -0
  18. package/lib/DatePicker/Day.js +173 -0
  19. package/lib/DatePicker/Month.d.ts +9 -0
  20. package/lib/DatePicker/Month.js +97 -0
  21. package/lib/DatePicker/index.d.ts +2 -0
  22. package/lib/DatePicker/index.js +13 -0
  23. package/lib/DatePicker/useDatePicker.d.ts +69 -0
  24. package/lib/DatePicker/useDatePicker.js +336 -0
  25. package/lib/SelectMenu/SelectMenu.d.ts +4 -2
  26. package/lib/TextInputWithTokens.d.ts +4 -2
  27. package/lib/TextInputWithTokens.js +12 -25
  28. package/lib/theme-preval.js +2 -2
  29. package/lib/utils/testing.d.ts +1 -1
  30. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  31. package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -2
  32. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -2
  33. package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
  34. package/lib-esm/DatePicker/DatePicker.js +65 -0
  35. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
  36. package/lib-esm/DatePicker/DatePickerAnchor.js +63 -0
  37. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  38. package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
  39. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  40. package/lib-esm/DatePicker/DatePickerPanel.js +24 -0
  41. package/lib-esm/DatePicker/Day.d.ts +14 -0
  42. package/lib-esm/DatePicker/Day.js +150 -0
  43. package/lib-esm/DatePicker/Month.d.ts +9 -0
  44. package/lib-esm/DatePicker/Month.js +74 -0
  45. package/lib-esm/DatePicker/index.d.ts +2 -0
  46. package/lib-esm/DatePicker/index.js +1 -0
  47. package/lib-esm/DatePicker/useDatePicker.d.ts +69 -0
  48. package/lib-esm/DatePicker/useDatePicker.js +308 -0
  49. package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
  50. package/lib-esm/TextInputWithTokens.d.ts +4 -2
  51. package/lib-esm/TextInputWithTokens.js +13 -25
  52. package/lib-esm/theme-preval.js +2 -2
  53. package/lib-esm/utils/testing.d.ts +1 -1
  54. package/package.json +9 -8
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Month = void 0;
7
+
8
+ var _dateFns = require("date-fns");
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
13
+
14
+ var _Box = _interopRequireDefault(require("../Box"));
15
+
16
+ var _Text = _interopRequireDefault(require("../Text"));
17
+
18
+ var _constants = require("../constants");
19
+
20
+ var _Day = require("./Day");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
+
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+
28
+ const MonthComponent = (0, _styledComponents.default)(_Box.default).withConfig({
29
+ displayName: "Month__MonthComponent",
30
+ componentId: "l6j7o0-0"
31
+ })(["display:grid;grid-auto-rows:min-content;grid-template-columns:repeat(1fr,7);grid-template-rows:1fr;gap:0px 0px;grid-template-areas:'month month month month month month month' 'sunday monday tuesday wednesday thursday friday saturday';justify-items:stretch;align-items:stretch;"]);
32
+ const MonthTitle = (0, _styledComponents.default)(_Text.default).withConfig({
33
+ displayName: "Month__MonthTitle",
34
+ componentId: "l6j7o0-1"
35
+ })(["font-size:", ";font-weight:", ";grid-area:month;justify-self:center;"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('fontWeights.bold'));
36
+ const WeekdayHeader = (0, _styledComponents.default)(_Text.default).withConfig({
37
+ displayName: "Month__WeekdayHeader",
38
+ componentId: "l6j7o0-2"
39
+ })(["color:", ";font-family:", ";font-size:", ";justify-self:center;padding:", " 0 ", ";"], (0, _constants.get)('colors.fg.subtle'), (0, _constants.get)('fonts.mono'), (0, _constants.get)('fontSizes.0'), (0, _constants.get)('space.3'), (0, _constants.get)('space.2'));
40
+
41
+ const Month = ({
42
+ month,
43
+ year
44
+ }) => {
45
+ const [selectedDay, setSelectedDay] = (0, _react.useState)(null);
46
+ const getTitle = (0, _react.useMemo)(() => `${(0, _dateFns.format)(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
47
+ const weekdayHeaders = (0, _react.useMemo)(() => {
48
+ const now = new Date(year, month);
49
+ return (0, _dateFns.eachDayOfInterval)({
50
+ start: (0, _dateFns.startOfWeek)(now),
51
+ end: (0, _dateFns.endOfWeek)(now)
52
+ }).map(d => /*#__PURE__*/_react.default.createElement(WeekdayHeader, {
53
+ key: `weekday-${d}-header`
54
+ }, (0, _dateFns.format)(d, 'EEEEEE')));
55
+ }, [month, year]);
56
+
57
+ const dayAction = date => {
58
+ setSelectedDay(date);
59
+ };
60
+
61
+ const dayComponents = (0, _react.useMemo)(() => {
62
+ const components = [];
63
+ const firstDay = new Date(year, month, 1);
64
+
65
+ for (let i = 0; i < firstDay.getDay(); i++) {
66
+ components.push( /*#__PURE__*/_react.default.createElement(_Day.BlankDay, {
67
+ key: `month-pre-blank-${i}`
68
+ }));
69
+ }
70
+
71
+ for (let i = 1; i <= (0, _dateFns.getDaysInMonth)(firstDay); i++) {
72
+ const date = new Date(year, month, i);
73
+ components.push( /*#__PURE__*/_react.default.createElement(_Day.Day, {
74
+ key: `day-component-${date.toString()}`,
75
+ date: date,
76
+ selected: selectedDay ? (0, _dateFns.isEqual)(date, selectedDay) : false,
77
+ onAction: dayAction
78
+ }));
79
+ }
80
+
81
+ const lastDay = (0, _dateFns.lastDayOfMonth)(firstDay);
82
+
83
+ for (let i = 6; i > lastDay.getDay(); i--) {
84
+ components.push( /*#__PURE__*/_react.default.createElement(_Day.BlankDay, {
85
+ key: `month-post-blank-${i}`
86
+ }));
87
+ }
88
+
89
+ return components;
90
+ }, [month, selectedDay, year]);
91
+ return /*#__PURE__*/_react.default.createElement(MonthComponent, {
92
+ role: "grid"
93
+ }, /*#__PURE__*/_react.default.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
94
+ };
95
+
96
+ exports.Month = Month;
97
+ Month.displayName = "Month";
@@ -0,0 +1,2 @@
1
+ export { DatePicker } from './DatePicker';
2
+ export type { DatePickerProps } from './DatePicker';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "DatePicker", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _DatePicker.DatePicker;
10
+ }
11
+ });
12
+
13
+ var _DatePicker = require("./DatePicker");
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
3
+ export declare type DateFormat = 'short' | 'long' | string;
4
+ export declare type SelectionVariant = 'single' | 'multi' | 'range';
5
+ export interface DatePickerConfiguration {
6
+ anchorVariant?: AnchorVariant;
7
+ blockedDates?: Array<Date>;
8
+ confirmation?: boolean;
9
+ contiguousSelection?: boolean;
10
+ dateFormat?: DateFormat;
11
+ dimWeekends?: boolean;
12
+ minDate?: Date;
13
+ maxDate?: Date;
14
+ placeholder?: string;
15
+ rangeIncrement?: number;
16
+ selection?: SelectionVariant;
17
+ view?: '1-month' | '2-month';
18
+ }
19
+ export declare type RangeSelection = {
20
+ from: Date;
21
+ to: Date | null;
22
+ };
23
+ export declare type StringRangeSelection = {
24
+ from: string;
25
+ to: string;
26
+ };
27
+ export interface DatePickerContext {
28
+ disabled?: boolean;
29
+ configuration: DatePickerConfiguration;
30
+ selection?: Selection;
31
+ softSelection?: Partial<RangeSelection> | null;
32
+ selectionActive?: boolean;
33
+ formattedDate: string;
34
+ onSelection: (date: Date) => void;
35
+ onDayFocus: (date: Date) => void;
36
+ onDayBlur: (date: Date) => void;
37
+ revertValue: () => void;
38
+ }
39
+ export declare type Selection = Date | Array<Date> | RangeSelection | null;
40
+ export declare type StringSelection = string | Array<string> | {
41
+ to: string;
42
+ from: string;
43
+ } | null;
44
+ export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
45
+ declare const useDatePicker: (date?: Date | undefined) => {
46
+ blocked: boolean | undefined;
47
+ disabled: boolean;
48
+ selected: DaySelection;
49
+ configuration: DatePickerConfiguration;
50
+ selection?: Selection | undefined;
51
+ softSelection?: Partial<RangeSelection> | null | undefined;
52
+ selectionActive?: boolean | undefined;
53
+ formattedDate: string;
54
+ onSelection: (date: Date) => void;
55
+ onDayFocus: (date: Date) => void;
56
+ onDayBlur: (date: Date) => void;
57
+ revertValue: () => void;
58
+ };
59
+ export default useDatePicker;
60
+ export interface DatePickerProviderProps {
61
+ closePicker?: () => void;
62
+ configuration?: DatePickerConfiguration;
63
+ value?: Selection | StringSelection;
64
+ }
65
+ export declare function isSingleSelection(selection: Selection): selection is Date;
66
+ export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
67
+ export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
68
+ export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
69
+ export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isSingleSelection = isSingleSelection;
7
+ exports.isMultiSelection = isMultiSelection;
8
+ exports.isRangeSelection = isRangeSelection;
9
+ exports.isStringRangeSelection = isStringRangeSelection;
10
+ exports.DatePickerProvider = exports.default = void 0;
11
+
12
+ var _dateFns = require("date-fns");
13
+
14
+ var _deepmerge = _interopRequireDefault(require("deepmerge"));
15
+
16
+ var _react = _interopRequireWildcard(require("react"));
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ const DatePickerContext = /*#__PURE__*/(0, _react.createContext)(null);
25
+
26
+ const useDatePicker = date => {
27
+ const value = (0, _react.useContext)(DatePickerContext);
28
+
29
+ if (!value) {
30
+ throw new Error('useDatePicker must be used inside a DatePickerProvider');
31
+ }
32
+
33
+ let selected = false;
34
+ let blocked,
35
+ disabled = false;
36
+
37
+ if (date) {
38
+ if (value.selection) {
39
+ if (isMultiSelection(value.selection)) {
40
+ selected = !!value.selection.find(d => (0, _dateFns.isEqual)(d, date));
41
+ } else if (isRangeSelection(value.selection)) {
42
+ if ((0, _dateFns.isEqual)(date, value.selection.from)) {
43
+ selected = 'start';
44
+ } else if (value.selection.to && (0, _dateFns.isEqual)(date, value.selection.to)) {
45
+ selected = 'end';
46
+ } else if ((0, _dateFns.isAfter)(date, value.selection.from) && value.selection.to && (0, _dateFns.isBefore)(date, value.selection.to)) {
47
+ selected = 'middle';
48
+ } else {
49
+ selected = false;
50
+ }
51
+ } else {
52
+ selected = (0, _dateFns.isEqual)(date, value.selection);
53
+ }
54
+ } // Determine if date is blocked out
55
+
56
+
57
+ if (value.configuration.blockedDates) {
58
+ blocked = !!value.configuration.blockedDates.find(d => (0, _dateFns.isEqual)(d, date));
59
+ } // Determine if date is disabled
60
+
61
+
62
+ if (value.configuration.minDate || value.configuration.maxDate) {
63
+ disabled = (value.configuration.minDate ? (0, _dateFns.isBefore)(date, value.configuration.minDate) : false) || (value.configuration.maxDate ? (0, _dateFns.isAfter)(date, value.configuration.maxDate) : false);
64
+ }
65
+ }
66
+
67
+ return { ...value,
68
+ blocked,
69
+ disabled,
70
+ selected
71
+ };
72
+ };
73
+
74
+ var _default = useDatePicker;
75
+ exports.default = _default;
76
+
77
+ function isSingleSelection(selection) {
78
+ return selection instanceof Date;
79
+ }
80
+
81
+ function isMultiSelection(selection) {
82
+ return Array.isArray(selection);
83
+ }
84
+
85
+ function isRangeSelection(selection) {
86
+ return !!selection.from;
87
+ }
88
+
89
+ function isStringRangeSelection(selection) {
90
+ return !!selection.from;
91
+ }
92
+
93
+ function parseSelection(selection, variant) {
94
+ if (!selection) return;
95
+
96
+ if (variant === 'multi') {
97
+ if (isMultiSelection(selection)) {
98
+ const parsedSelection = [];
99
+
100
+ for (const d of selection) {
101
+ parsedSelection.push(new Date(new Date(d).toDateString()));
102
+ }
103
+
104
+ return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
105
+ } else if (selection instanceof Date) {
106
+ return [new Date(new Date(selection).toDateString())];
107
+ } else if (isRangeSelection(selection)) {
108
+ const parsedSelection = [];
109
+ parsedSelection.push(new Date(new Date(selection.from).toDateString()));
110
+
111
+ if (selection.to) {
112
+ parsedSelection.push(new Date(new Date(selection.to).toDateString()));
113
+ }
114
+
115
+ return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
116
+ }
117
+ } else if (variant === 'range') {
118
+ if (isRangeSelection(selection)) {
119
+ return {
120
+ from: new Date(new Date(selection.from).toDateString()),
121
+ to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
122
+ };
123
+ } else if (isMultiSelection(selection)) {
124
+ return {
125
+ from: new Date(new Date(selection[0]).toDateString()),
126
+ to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
127
+ };
128
+ } else if (selection instanceof Date) {
129
+ return {
130
+ from: new Date(new Date(selection).toDateString()),
131
+ to: null
132
+ };
133
+ }
134
+ } else {
135
+ if (selection instanceof Date) {
136
+ return new Date(new Date(selection).toDateString());
137
+ } else if (isMultiSelection(selection)) {
138
+ return new Date(new Date(selection[0]).toDateString());
139
+ } else if (isRangeSelection(selection)) {
140
+ return new Date(new Date(selection.from).toDateString());
141
+ } else {
142
+ return;
143
+ }
144
+ }
145
+ }
146
+
147
+ const defaultConfiguration = {
148
+ anchorVariant: 'button',
149
+ confirmation: false,
150
+ contiguousSelection: false,
151
+ dimWeekends: false,
152
+ placeholder: 'Select a Date...',
153
+ selection: 'single',
154
+ view: '2-month'
155
+ };
156
+
157
+ const DatePickerProvider = ({
158
+ configuration: externalConfig = {},
159
+ children,
160
+ closePicker,
161
+ value
162
+ }) => {
163
+ const [configuration, setConfiguration] = (0, _react.useState)((0, _deepmerge.default)(defaultConfiguration, externalConfig));
164
+ const [previousSelection, setPreviousSelection] = (0, _react.useState)(parseSelection(value, configuration.selection));
165
+ const [selection, setSelection] = (0, _react.useState)(parseSelection(value, configuration.selection));
166
+ const [hoverRange, setHoverRange] = (0, _react.useState)(null);
167
+ (0, _react.useEffect)(() => {
168
+ setConfiguration((0, _deepmerge.default)(defaultConfiguration, externalConfig));
169
+ setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
170
+ // eslint-disable-next-line react-hooks/exhaustive-deps
171
+ }, [configuration.selection, externalConfig]);
172
+ const getFormattedDate = (0, _react.useMemo)(() => {
173
+ if (!selection) {
174
+ return configuration.placeholder;
175
+ }
176
+
177
+ let template = 'MMM d';
178
+
179
+ if (configuration.dateFormat) {
180
+ switch (configuration.dateFormat) {
181
+ case 'short':
182
+ template = 'MMM d';
183
+ break;
184
+
185
+ case 'long':
186
+ template = 'MMM d, yyyy';
187
+ break;
188
+
189
+ default:
190
+ template = configuration.dateFormat;
191
+ break;
192
+ }
193
+ }
194
+
195
+ switch (configuration.selection) {
196
+ case 'single':
197
+ {
198
+ if (selection instanceof Date) {
199
+ return (0, _dateFns.format)(selection, template);
200
+ } else if (Array.isArray(selection)) {
201
+ return (0, _dateFns.format)(selection[0], template);
202
+ } else if (isRangeSelection(selection)) {
203
+ return (0, _dateFns.format)(selection.from, template);
204
+ } else {
205
+ return 'Invalid Selection';
206
+ }
207
+ }
208
+
209
+ case 'multi':
210
+ {
211
+ if (Array.isArray(selection)) {
212
+ if (selection.length > 3) return `${selection.length} Selected`;
213
+ const formatted = selection.map(d => (0, _dateFns.format)(d, template)).join(', ');
214
+ return formatted;
215
+ } else if (selection instanceof Date) {
216
+ return [selection].map(d => (0, _dateFns.format)(d, template)).join(', ');
217
+ } else if (isRangeSelection(selection)) {
218
+ return [selection.to, selection.from].map(d => d ? (0, _dateFns.format)(d, template) : '').join(', ');
219
+ } else {
220
+ return 'Invalid Selection';
221
+ }
222
+ }
223
+
224
+ case 'range':
225
+ {
226
+ if (isRangeSelection(selection)) {
227
+ return Object.entries(selection).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
228
+ } else if (selection instanceof Date) {
229
+ return Object.entries({
230
+ from: selection,
231
+ to: null
232
+ }).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
233
+ } else if (Array.isArray(selection)) {
234
+ return Object.entries({
235
+ from: selection[0],
236
+ to: selection[1]
237
+ }) // to date can still be null
238
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
239
+ .map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
240
+ } else {
241
+ return 'Invalid Selection';
242
+ }
243
+ }
244
+
245
+ default:
246
+ {
247
+ return 'Invalid Configuration';
248
+ }
249
+ }
250
+ }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
251
+ const handleSave = (0, _react.useCallback)(updatedSelection => {
252
+ setPreviousSelection(updatedSelection);
253
+ closePicker === null || closePicker === void 0 ? void 0 : closePicker();
254
+ }, [closePicker]);
255
+ const selectionHandler = (0, _react.useCallback)(date => {
256
+ if (configuration.selection === 'multi') {
257
+ const selections = [...selection];
258
+ const existingIndex = selections.findIndex(s => (0, _dateFns.isEqual)(s, date));
259
+
260
+ if (existingIndex > -1) {
261
+ selections.splice(existingIndex, 1);
262
+ setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
263
+ } else {
264
+ setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
265
+ }
266
+ } else if (configuration.selection === 'range') {
267
+ if (selection && isRangeSelection(selection) && !selection.to) {
268
+ const updatedSelection = (0, _dateFns.isBefore)(date, selection.from) ? {
269
+ from: date,
270
+ to: selection.from
271
+ } : {
272
+ from: selection.from,
273
+ to: date
274
+ };
275
+ setSelection(updatedSelection);
276
+
277
+ if (!configuration.confirmation) {
278
+ handleSave(updatedSelection);
279
+ }
280
+ } else {
281
+ setSelection({
282
+ from: date,
283
+ to: null
284
+ });
285
+ }
286
+ } else {
287
+ setSelection(date);
288
+
289
+ if (!configuration.confirmation) {
290
+ handleSave(date);
291
+ }
292
+ }
293
+ }, [configuration.confirmation, configuration.selection, handleSave, selection]);
294
+ const focusHnadler = (0, _react.useCallback)(date => {
295
+ if (!selection) return;
296
+
297
+ if (configuration.selection === 'range' && isRangeSelection(selection)) {
298
+ setHoverRange((0, _dateFns.isBefore)(date, selection.from) ? {
299
+ from: date,
300
+ to: selection.from
301
+ } : {
302
+ from: selection.from,
303
+ to: date
304
+ });
305
+ }
306
+ }, [configuration.selection, selection]);
307
+ const blurHnadler = (0, _react.useCallback)(date => {
308
+ if (!selection || !hoverRange) return;
309
+
310
+ if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
311
+ setHoverRange(null);
312
+ }
313
+ }, [configuration.selection, hoverRange, selection]);
314
+ const revertValue = (0, _react.useCallback)(() => {
315
+ setSelection(previousSelection);
316
+ }, [previousSelection]);
317
+ const datePickerCtx = (0, _react.useMemo)(() => {
318
+ return {
319
+ configuration,
320
+ disabled: false,
321
+ formattedDate: getFormattedDate,
322
+ onDayBlur: blurHnadler,
323
+ onDayFocus: focusHnadler,
324
+ onSelection: selectionHandler,
325
+ revertValue,
326
+ selectionActive: false,
327
+ selection
328
+ };
329
+ }, [blurHnadler, configuration, focusHnadler, getFormattedDate, revertValue, selection, selectionHandler]);
330
+ return /*#__PURE__*/_react.default.createElement(DatePickerContext.Provider, {
331
+ value: datePickerCtx
332
+ }, children);
333
+ };
334
+
335
+ exports.DatePickerProvider = DatePickerProvider;
336
+ DatePickerProvider.displayName = "DatePickerProvider";
@@ -32,12 +32,14 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
32
32
  Divider: import("styled-components").StyledComponent<"div", any, SystemCommonProps & SxProp, never>;
33
33
  Filter: React.ForwardRefExoticComponent<Pick<{
34
34
  value?: string | undefined;
35
- } & Pick<Omit<Pick<{
35
+ } & Pick<Omit<Pick<({
36
36
  [x: string]: any;
37
37
  [x: number]: any;
38
38
  } & {
39
39
  theme?: any;
40
- } & {
40
+ } & ({} | {
41
+ children?: React.ReactNode;
42
+ })) & {
41
43
  as?: string | React.ComponentType<any> | undefined;
42
44
  forwardedAs?: string | React.ComponentType<any> | undefined;
43
45
  }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
@@ -32,12 +32,14 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
32
32
  * Whether the remove buttons should be rendered in the tokens
33
33
  */
34
34
  hideTokenRemoveButtons?: boolean | undefined;
35
- } & Pick<Omit<Pick<{
35
+ } & Pick<Omit<Pick<({
36
36
  [x: string]: any;
37
37
  [x: number]: any;
38
38
  } & {
39
39
  theme?: any;
40
- } & {
40
+ } & ({} | {
41
+ children?: React.ReactNode;
42
+ })) & {
41
43
  as?: string | React.ComponentType<any> | undefined;
42
44
  forwardedAs?: string | React.ComponentType<any> | undefined;
43
45
  }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
@@ -25,8 +25,6 @@ var _TextInputWrapper = _interopRequireDefault(require("./_TextInputWrapper"));
25
25
 
26
26
  var _Box = _interopRequireDefault(require("./Box"));
27
27
 
28
- var _iterateFocusableElements = require("./utils/iterateFocusableElements");
29
-
30
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
29
 
32
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -100,25 +98,14 @@ function TextInputWithTokensInnerComponent({
100
98
  }, [selectedTokenIndex]);
101
99
 
102
100
  const handleTokenRemove = tokenId => {
103
- onTokenRemove(tokenId); // HACK: wait a tick for the the token node to be removed from the DOM
104
-
105
- setTimeout(() => {
106
- var _containerRef$current2, _containerRef$current3;
107
-
108
- const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex || 0]; // when removing the first token by keying "Backspace" or "Delete",
109
- // `nextFocusableElement` is the div that wraps the input
101
+ onTokenRemove(tokenId);
110
102
 
111
- const firstFocusable = nextElementToFocus && (0, _iterateFocusableElements.isFocusable)(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => (0, _iterateFocusableElements.isFocusable)(el));
103
+ if (selectedTokenIndex) {
104
+ var _containerRef$current2;
112
105
 
113
- if (firstFocusable) {
114
- firstFocusable.focus();
115
- } else {
116
- var _ref$current;
117
-
118
- // if there are no tokens left, focus the input
119
- (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
120
- }
121
- }, 0);
106
+ const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
107
+ nextElementToFocus.focus();
108
+ }
122
109
  };
123
110
 
124
111
  const handleTokenFocus = tokenIndex => () => {
@@ -131,9 +118,9 @@ function TextInputWithTokensInnerComponent({
131
118
 
132
119
  const handleTokenKeyUp = e => {
133
120
  if (e.key === 'Escape') {
134
- var _ref$current2;
121
+ var _ref$current;
135
122
 
136
- (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
123
+ (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
137
124
  }
138
125
  };
139
126
 
@@ -143,13 +130,13 @@ function TextInputWithTokensInnerComponent({
143
130
  };
144
131
 
145
132
  const handleInputKeyDown = e => {
146
- var _ref$current3;
133
+ var _ref$current2;
147
134
 
148
135
  if (onKeyDown) {
149
136
  onKeyDown(e);
150
137
  }
151
138
 
152
- if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.value) {
139
+ if ((_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
153
140
  return;
154
141
  }
155
142
 
@@ -170,9 +157,9 @@ function TextInputWithTokensInnerComponent({
170
157
 
171
158
 
172
159
  setTimeout(() => {
173
- var _ref$current4;
160
+ var _ref$current3;
174
161
 
175
- (_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.select();
162
+ (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
176
163
  }, 0);
177
164
  }
178
165
  };
@@ -515,7 +515,7 @@ module.exports = {
515
515
  }
516
516
  }
517
517
  },
518
- "light_protanopia": {
518
+ "light_colorblind": {
519
519
  "colors": {
520
520
  "canvasDefaultTransparent": "rgba(255,255,255,0)",
521
521
  "marketingIcon": {
@@ -2456,7 +2456,7 @@ module.exports = {
2456
2456
  }
2457
2457
  }
2458
2458
  },
2459
- "dark_protanopia": {
2459
+ "dark_colorblind": {
2460
2460
  "colors": {
2461
2461
  "canvasDefaultTransparent": "rgba(13,17,23,0)",
2462
2462
  "marketingIcon": {
@@ -53,7 +53,7 @@ export declare function render(component: React.ReactElement, theme?: {
53
53
  xlarge: string;
54
54
  };
55
55
  space: string[];
56
- colorSchemes: Record<"light" | "light_protanopia" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
56
+ colorSchemes: Record<"light" | "light_colorblind" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_colorblind", Record<"colors" | "shadows", Partial<{
57
57
  canvasDefaultTransparent: string;
58
58
  marketingIcon: {
59
59
  primary: string;