@primer/components 0.0.0-202192219616 → 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.
- package/CHANGELOG.md +1 -1
- package/dist/browser.esm.js +37 -38
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +32 -33
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +4 -2
- package/lib/Autocomplete/AutocompleteInput.d.ts +4 -2
- package/lib/DatePicker/DatePicker.d.ts +48 -0
- package/lib/DatePicker/DatePicker.js +82 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +88 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +39 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +43 -0
- package/lib/DatePicker/Day.d.ts +14 -0
- package/lib/DatePicker/Day.js +173 -0
- package/lib/DatePicker/Month.d.ts +9 -0
- package/lib/DatePicker/Month.js +97 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +69 -0
- package/lib/DatePicker/useDatePicker.js +336 -0
- package/lib/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib/TextInputWithTokens.d.ts +4 -6
- package/lib/TextInputWithTokens.js +8 -61
- package/lib/_TextInputWrapper.js +1 -1
- package/lib/theme-preval.js +2 -2
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -2
- package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
- package/lib-esm/DatePicker/DatePicker.js +65 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +63 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +24 -0
- package/lib-esm/DatePicker/Day.d.ts +14 -0
- package/lib-esm/DatePicker/Day.js +150 -0
- package/lib-esm/DatePicker/Month.d.ts +9 -0
- package/lib-esm/DatePicker/Month.js +74 -0
- package/lib-esm/DatePicker/index.d.ts +2 -0
- package/lib-esm/DatePicker/index.js +1 -0
- package/lib-esm/DatePicker/useDatePicker.d.ts +69 -0
- package/lib-esm/DatePicker/useDatePicker.js +308 -0
- package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib-esm/TextInputWithTokens.d.ts +4 -6
- package/lib-esm/TextInputWithTokens.js +9 -61
- package/lib-esm/_TextInputWrapper.js +1 -1
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -8
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FontSizeProps } from 'styled-system';
|
3
|
+
import { SystemCommonProps, SystemLayoutProps } from '../constants';
|
4
|
+
import { SxProp } from '../sx';
|
5
|
+
export interface MonthProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
|
6
|
+
month: number;
|
7
|
+
year: number;
|
8
|
+
}
|
9
|
+
export declare const Month: React.FC<MonthProps>;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { format, isEqual, lastDayOfMonth, getDaysInMonth, eachDayOfInterval, startOfWeek, endOfWeek } from 'date-fns';
|
2
|
+
import React, { useMemo, useState } from 'react';
|
3
|
+
import styled from 'styled-components';
|
4
|
+
import Box from '../Box';
|
5
|
+
import Text from '../Text';
|
6
|
+
import { get } from '../constants';
|
7
|
+
import { BlankDay, Day } from './Day';
|
8
|
+
const MonthComponent = styled(Box).withConfig({
|
9
|
+
displayName: "Month__MonthComponent",
|
10
|
+
componentId: "l6j7o0-0"
|
11
|
+
})(["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;"]);
|
12
|
+
const MonthTitle = styled(Text).withConfig({
|
13
|
+
displayName: "Month__MonthTitle",
|
14
|
+
componentId: "l6j7o0-1"
|
15
|
+
})(["font-size:", ";font-weight:", ";grid-area:month;justify-self:center;"], get('fontSizes.1'), get('fontWeights.bold'));
|
16
|
+
const WeekdayHeader = styled(Text).withConfig({
|
17
|
+
displayName: "Month__WeekdayHeader",
|
18
|
+
componentId: "l6j7o0-2"
|
19
|
+
})(["color:", ";font-family:", ";font-size:", ";justify-self:center;padding:", " 0 ", ";"], get('colors.fg.subtle'), get('fonts.mono'), get('fontSizes.0'), get('space.3'), get('space.2'));
|
20
|
+
export const Month = ({
|
21
|
+
month,
|
22
|
+
year
|
23
|
+
}) => {
|
24
|
+
const [selectedDay, setSelectedDay] = useState(null);
|
25
|
+
const getTitle = useMemo(() => `${format(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
|
26
|
+
const weekdayHeaders = useMemo(() => {
|
27
|
+
const now = new Date(year, month);
|
28
|
+
return eachDayOfInterval({
|
29
|
+
start: startOfWeek(now),
|
30
|
+
end: endOfWeek(now)
|
31
|
+
}).map(d => /*#__PURE__*/React.createElement(WeekdayHeader, {
|
32
|
+
key: `weekday-${d}-header`
|
33
|
+
}, format(d, 'EEEEEE')));
|
34
|
+
}, [month, year]);
|
35
|
+
|
36
|
+
const dayAction = date => {
|
37
|
+
setSelectedDay(date);
|
38
|
+
};
|
39
|
+
|
40
|
+
const dayComponents = useMemo(() => {
|
41
|
+
const components = [];
|
42
|
+
const firstDay = new Date(year, month, 1);
|
43
|
+
|
44
|
+
for (let i = 0; i < firstDay.getDay(); i++) {
|
45
|
+
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
46
|
+
key: `month-pre-blank-${i}`
|
47
|
+
}));
|
48
|
+
}
|
49
|
+
|
50
|
+
for (let i = 1; i <= getDaysInMonth(firstDay); i++) {
|
51
|
+
const date = new Date(year, month, i);
|
52
|
+
components.push( /*#__PURE__*/React.createElement(Day, {
|
53
|
+
key: `day-component-${date.toString()}`,
|
54
|
+
date: date,
|
55
|
+
selected: selectedDay ? isEqual(date, selectedDay) : false,
|
56
|
+
onAction: dayAction
|
57
|
+
}));
|
58
|
+
}
|
59
|
+
|
60
|
+
const lastDay = lastDayOfMonth(firstDay);
|
61
|
+
|
62
|
+
for (let i = 6; i > lastDay.getDay(); i--) {
|
63
|
+
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
64
|
+
key: `month-post-blank-${i}`
|
65
|
+
}));
|
66
|
+
}
|
67
|
+
|
68
|
+
return components;
|
69
|
+
}, [month, selectedDay, year]);
|
70
|
+
return /*#__PURE__*/React.createElement(MonthComponent, {
|
71
|
+
role: "grid"
|
72
|
+
}, /*#__PURE__*/React.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
|
73
|
+
};
|
74
|
+
Month.displayName = "Month";
|
@@ -0,0 +1 @@
|
|
1
|
+
export { DatePicker } from './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,308 @@
|
|
1
|
+
import { format, isEqual, isAfter, isBefore } from 'date-fns';
|
2
|
+
import deepmerge from 'deepmerge';
|
3
|
+
import React, { createContext, useCallback, useContext, useMemo, useEffect, useState } from 'react';
|
4
|
+
const DatePickerContext = /*#__PURE__*/createContext(null);
|
5
|
+
|
6
|
+
const useDatePicker = date => {
|
7
|
+
const value = useContext(DatePickerContext);
|
8
|
+
|
9
|
+
if (!value) {
|
10
|
+
throw new Error('useDatePicker must be used inside a DatePickerProvider');
|
11
|
+
}
|
12
|
+
|
13
|
+
let selected = false;
|
14
|
+
let blocked,
|
15
|
+
disabled = false;
|
16
|
+
|
17
|
+
if (date) {
|
18
|
+
if (value.selection) {
|
19
|
+
if (isMultiSelection(value.selection)) {
|
20
|
+
selected = !!value.selection.find(d => isEqual(d, date));
|
21
|
+
} else if (isRangeSelection(value.selection)) {
|
22
|
+
if (isEqual(date, value.selection.from)) {
|
23
|
+
selected = 'start';
|
24
|
+
} else if (value.selection.to && isEqual(date, value.selection.to)) {
|
25
|
+
selected = 'end';
|
26
|
+
} else if (isAfter(date, value.selection.from) && value.selection.to && isBefore(date, value.selection.to)) {
|
27
|
+
selected = 'middle';
|
28
|
+
} else {
|
29
|
+
selected = false;
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
selected = isEqual(date, value.selection);
|
33
|
+
}
|
34
|
+
} // Determine if date is blocked out
|
35
|
+
|
36
|
+
|
37
|
+
if (value.configuration.blockedDates) {
|
38
|
+
blocked = !!value.configuration.blockedDates.find(d => isEqual(d, date));
|
39
|
+
} // Determine if date is disabled
|
40
|
+
|
41
|
+
|
42
|
+
if (value.configuration.minDate || value.configuration.maxDate) {
|
43
|
+
disabled = (value.configuration.minDate ? isBefore(date, value.configuration.minDate) : false) || (value.configuration.maxDate ? isAfter(date, value.configuration.maxDate) : false);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
return { ...value,
|
48
|
+
blocked,
|
49
|
+
disabled,
|
50
|
+
selected
|
51
|
+
};
|
52
|
+
};
|
53
|
+
|
54
|
+
export default useDatePicker;
|
55
|
+
export function isSingleSelection(selection) {
|
56
|
+
return selection instanceof Date;
|
57
|
+
}
|
58
|
+
export function isMultiSelection(selection) {
|
59
|
+
return Array.isArray(selection);
|
60
|
+
}
|
61
|
+
export function isRangeSelection(selection) {
|
62
|
+
return !!selection.from;
|
63
|
+
}
|
64
|
+
export function isStringRangeSelection(selection) {
|
65
|
+
return !!selection.from;
|
66
|
+
}
|
67
|
+
|
68
|
+
function parseSelection(selection, variant) {
|
69
|
+
if (!selection) return;
|
70
|
+
|
71
|
+
if (variant === 'multi') {
|
72
|
+
if (isMultiSelection(selection)) {
|
73
|
+
const parsedSelection = [];
|
74
|
+
|
75
|
+
for (const d of selection) {
|
76
|
+
parsedSelection.push(new Date(new Date(d).toDateString()));
|
77
|
+
}
|
78
|
+
|
79
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
80
|
+
} else if (selection instanceof Date) {
|
81
|
+
return [new Date(new Date(selection).toDateString())];
|
82
|
+
} else if (isRangeSelection(selection)) {
|
83
|
+
const parsedSelection = [];
|
84
|
+
parsedSelection.push(new Date(new Date(selection.from).toDateString()));
|
85
|
+
|
86
|
+
if (selection.to) {
|
87
|
+
parsedSelection.push(new Date(new Date(selection.to).toDateString()));
|
88
|
+
}
|
89
|
+
|
90
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
91
|
+
}
|
92
|
+
} else if (variant === 'range') {
|
93
|
+
if (isRangeSelection(selection)) {
|
94
|
+
return {
|
95
|
+
from: new Date(new Date(selection.from).toDateString()),
|
96
|
+
to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
|
97
|
+
};
|
98
|
+
} else if (isMultiSelection(selection)) {
|
99
|
+
return {
|
100
|
+
from: new Date(new Date(selection[0]).toDateString()),
|
101
|
+
to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
|
102
|
+
};
|
103
|
+
} else if (selection instanceof Date) {
|
104
|
+
return {
|
105
|
+
from: new Date(new Date(selection).toDateString()),
|
106
|
+
to: null
|
107
|
+
};
|
108
|
+
}
|
109
|
+
} else {
|
110
|
+
if (selection instanceof Date) {
|
111
|
+
return new Date(new Date(selection).toDateString());
|
112
|
+
} else if (isMultiSelection(selection)) {
|
113
|
+
return new Date(new Date(selection[0]).toDateString());
|
114
|
+
} else if (isRangeSelection(selection)) {
|
115
|
+
return new Date(new Date(selection.from).toDateString());
|
116
|
+
} else {
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
const defaultConfiguration = {
|
123
|
+
anchorVariant: 'button',
|
124
|
+
confirmation: false,
|
125
|
+
contiguousSelection: false,
|
126
|
+
dimWeekends: false,
|
127
|
+
placeholder: 'Select a Date...',
|
128
|
+
selection: 'single',
|
129
|
+
view: '2-month'
|
130
|
+
};
|
131
|
+
export const DatePickerProvider = ({
|
132
|
+
configuration: externalConfig = {},
|
133
|
+
children,
|
134
|
+
closePicker,
|
135
|
+
value
|
136
|
+
}) => {
|
137
|
+
const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
|
138
|
+
const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.selection));
|
139
|
+
const [selection, setSelection] = useState(parseSelection(value, configuration.selection));
|
140
|
+
const [hoverRange, setHoverRange] = useState(null);
|
141
|
+
useEffect(() => {
|
142
|
+
setConfiguration(deepmerge(defaultConfiguration, externalConfig));
|
143
|
+
setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
|
144
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
145
|
+
}, [configuration.selection, externalConfig]);
|
146
|
+
const getFormattedDate = useMemo(() => {
|
147
|
+
if (!selection) {
|
148
|
+
return configuration.placeholder;
|
149
|
+
}
|
150
|
+
|
151
|
+
let template = 'MMM d';
|
152
|
+
|
153
|
+
if (configuration.dateFormat) {
|
154
|
+
switch (configuration.dateFormat) {
|
155
|
+
case 'short':
|
156
|
+
template = 'MMM d';
|
157
|
+
break;
|
158
|
+
|
159
|
+
case 'long':
|
160
|
+
template = 'MMM d, yyyy';
|
161
|
+
break;
|
162
|
+
|
163
|
+
default:
|
164
|
+
template = configuration.dateFormat;
|
165
|
+
break;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
switch (configuration.selection) {
|
170
|
+
case 'single':
|
171
|
+
{
|
172
|
+
if (selection instanceof Date) {
|
173
|
+
return format(selection, template);
|
174
|
+
} else if (Array.isArray(selection)) {
|
175
|
+
return format(selection[0], template);
|
176
|
+
} else if (isRangeSelection(selection)) {
|
177
|
+
return format(selection.from, template);
|
178
|
+
} else {
|
179
|
+
return 'Invalid Selection';
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
case 'multi':
|
184
|
+
{
|
185
|
+
if (Array.isArray(selection)) {
|
186
|
+
if (selection.length > 3) return `${selection.length} Selected`;
|
187
|
+
const formatted = selection.map(d => format(d, template)).join(', ');
|
188
|
+
return formatted;
|
189
|
+
} else if (selection instanceof Date) {
|
190
|
+
return [selection].map(d => format(d, template)).join(', ');
|
191
|
+
} else if (isRangeSelection(selection)) {
|
192
|
+
return [selection.to, selection.from].map(d => d ? format(d, template) : '').join(', ');
|
193
|
+
} else {
|
194
|
+
return 'Invalid Selection';
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
case 'range':
|
199
|
+
{
|
200
|
+
if (isRangeSelection(selection)) {
|
201
|
+
return Object.entries(selection).map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
202
|
+
} else if (selection instanceof Date) {
|
203
|
+
return Object.entries({
|
204
|
+
from: selection,
|
205
|
+
to: null
|
206
|
+
}).map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
207
|
+
} else if (Array.isArray(selection)) {
|
208
|
+
return Object.entries({
|
209
|
+
from: selection[0],
|
210
|
+
to: selection[1]
|
211
|
+
}) // to date can still be null
|
212
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
213
|
+
.map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
214
|
+
} else {
|
215
|
+
return 'Invalid Selection';
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
default:
|
220
|
+
{
|
221
|
+
return 'Invalid Configuration';
|
222
|
+
}
|
223
|
+
}
|
224
|
+
}, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
|
225
|
+
const handleSave = useCallback(updatedSelection => {
|
226
|
+
setPreviousSelection(updatedSelection);
|
227
|
+
closePicker === null || closePicker === void 0 ? void 0 : closePicker();
|
228
|
+
}, [closePicker]);
|
229
|
+
const selectionHandler = useCallback(date => {
|
230
|
+
if (configuration.selection === 'multi') {
|
231
|
+
const selections = [...selection];
|
232
|
+
const existingIndex = selections.findIndex(s => isEqual(s, date));
|
233
|
+
|
234
|
+
if (existingIndex > -1) {
|
235
|
+
selections.splice(existingIndex, 1);
|
236
|
+
setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
|
237
|
+
} else {
|
238
|
+
setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
|
239
|
+
}
|
240
|
+
} else if (configuration.selection === 'range') {
|
241
|
+
if (selection && isRangeSelection(selection) && !selection.to) {
|
242
|
+
const updatedSelection = isBefore(date, selection.from) ? {
|
243
|
+
from: date,
|
244
|
+
to: selection.from
|
245
|
+
} : {
|
246
|
+
from: selection.from,
|
247
|
+
to: date
|
248
|
+
};
|
249
|
+
setSelection(updatedSelection);
|
250
|
+
|
251
|
+
if (!configuration.confirmation) {
|
252
|
+
handleSave(updatedSelection);
|
253
|
+
}
|
254
|
+
} else {
|
255
|
+
setSelection({
|
256
|
+
from: date,
|
257
|
+
to: null
|
258
|
+
});
|
259
|
+
}
|
260
|
+
} else {
|
261
|
+
setSelection(date);
|
262
|
+
|
263
|
+
if (!configuration.confirmation) {
|
264
|
+
handleSave(date);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}, [configuration.confirmation, configuration.selection, handleSave, selection]);
|
268
|
+
const focusHnadler = useCallback(date => {
|
269
|
+
if (!selection) return;
|
270
|
+
|
271
|
+
if (configuration.selection === 'range' && isRangeSelection(selection)) {
|
272
|
+
setHoverRange(isBefore(date, selection.from) ? {
|
273
|
+
from: date,
|
274
|
+
to: selection.from
|
275
|
+
} : {
|
276
|
+
from: selection.from,
|
277
|
+
to: date
|
278
|
+
});
|
279
|
+
}
|
280
|
+
}, [configuration.selection, selection]);
|
281
|
+
const blurHnadler = useCallback(date => {
|
282
|
+
if (!selection || !hoverRange) return;
|
283
|
+
|
284
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
|
285
|
+
setHoverRange(null);
|
286
|
+
}
|
287
|
+
}, [configuration.selection, hoverRange, selection]);
|
288
|
+
const revertValue = useCallback(() => {
|
289
|
+
setSelection(previousSelection);
|
290
|
+
}, [previousSelection]);
|
291
|
+
const datePickerCtx = useMemo(() => {
|
292
|
+
return {
|
293
|
+
configuration,
|
294
|
+
disabled: false,
|
295
|
+
formattedDate: getFormattedDate,
|
296
|
+
onDayBlur: blurHnadler,
|
297
|
+
onDayFocus: focusHnadler,
|
298
|
+
onSelection: selectionHandler,
|
299
|
+
revertValue,
|
300
|
+
selectionActive: false,
|
301
|
+
selection
|
302
|
+
};
|
303
|
+
}, [blurHnadler, configuration, focusHnadler, getFormattedDate, revertValue, selection, selectionHandler]);
|
304
|
+
return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
|
305
|
+
value: datePickerCtx
|
306
|
+
}, children);
|
307
|
+
};
|
308
|
+
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,16 +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
|
-
|
36
|
-
* The number of tokens to display before truncating
|
37
|
-
*/
|
38
|
-
visibleTokenCount?: number | undefined;
|
39
|
-
} & Pick<Omit<Pick<{
|
35
|
+
} & Pick<Omit<Pick<({
|
40
36
|
[x: string]: any;
|
41
37
|
[x: number]: any;
|
42
38
|
} & {
|
43
39
|
theme?: any;
|
44
|
-
} & {
|
40
|
+
} & ({} | {
|
41
|
+
children?: React.ReactNode;
|
42
|
+
})) & {
|
45
43
|
as?: string | React.ComponentType<any> | undefined;
|
46
44
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
47
45
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
@@ -9,16 +9,9 @@ import Token from './Token/Token';
|
|
9
9
|
import { useProvidedRefOrCreate } from './hooks';
|
10
10
|
import UnstyledTextInput from './_UnstyledTextInput';
|
11
11
|
import TextInputWrapper from './_TextInputWrapper';
|
12
|
-
import Box from './Box';
|
13
|
-
import Text from './Text'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
-
|
15
|
-
const overflowCountFontSizeMap = {
|
16
|
-
small: 0,
|
17
|
-
medium: 1,
|
18
|
-
large: 1,
|
19
|
-
extralarge: 2
|
20
|
-
}; // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
12
|
+
import Box from './Box'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
21
13
|
|
14
|
+
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
22
15
|
function TextInputWithTokensInnerComponent({
|
23
16
|
icon: IconComponent,
|
24
17
|
contrast,
|
@@ -38,11 +31,9 @@ function TextInputWithTokensInnerComponent({
|
|
38
31
|
minWidth: minWidthProp,
|
39
32
|
maxWidth: maxWidthProp,
|
40
33
|
variant: variantProp,
|
41
|
-
visibleTokenCount,
|
42
34
|
...rest
|
43
35
|
}, externalRef) {
|
44
36
|
const {
|
45
|
-
onBlur,
|
46
37
|
onFocus,
|
47
38
|
onKeyDown,
|
48
39
|
...inputPropsRest
|
@@ -51,7 +42,6 @@ function TextInputWithTokensInnerComponent({
|
|
51
42
|
const localInputRef = useRef(null);
|
52
43
|
const combinedInputRef = useCombinedRefs(localInputRef, ref);
|
53
44
|
const [selectedTokenIndex, setSelectedTokenIndex] = useState();
|
54
|
-
const [tokensAreTruncated, setTokensAreTruncated] = useState(Boolean(visibleTokenCount));
|
55
45
|
const {
|
56
46
|
containerRef
|
57
47
|
} = useFocusZone({
|
@@ -101,45 +91,20 @@ function TextInputWithTokensInnerComponent({
|
|
101
91
|
};
|
102
92
|
|
103
93
|
const handleTokenBlur = () => {
|
104
|
-
setSelectedTokenIndex(undefined);
|
105
|
-
// this prevents the tokens from hiding when the user is moving focus between tokens,
|
106
|
-
// but still hides the tokens when the user blurs the token by tabbing out or clicking somewhere else on the page
|
107
|
-
|
108
|
-
setTimeout(() => {
|
109
|
-
var _containerRef$current3;
|
110
|
-
|
111
|
-
if (!((_containerRef$current3 = containerRef.current) !== null && _containerRef$current3 !== void 0 && _containerRef$current3.contains(document.activeElement)) && visibleTokenCount) {
|
112
|
-
setTokensAreTruncated(true);
|
113
|
-
}
|
114
|
-
}, 0);
|
94
|
+
setSelectedTokenIndex(undefined);
|
115
95
|
};
|
116
96
|
|
117
|
-
const handleTokenKeyUp =
|
118
|
-
if (
|
97
|
+
const handleTokenKeyUp = e => {
|
98
|
+
if (e.key === 'Escape') {
|
119
99
|
var _ref$current;
|
120
100
|
|
121
101
|
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
122
102
|
}
|
123
103
|
};
|
124
104
|
|
125
|
-
const handleInputFocus =
|
126
|
-
onFocus && onFocus(
|
105
|
+
const handleInputFocus = e => {
|
106
|
+
onFocus && onFocus(e);
|
127
107
|
setSelectedTokenIndex(undefined);
|
128
|
-
visibleTokenCount && setTokensAreTruncated(false);
|
129
|
-
};
|
130
|
-
|
131
|
-
const handleInputBlur = event => {
|
132
|
-
onBlur && onBlur(event); // HACK: wait a tick and check the focused element before hiding truncated tokens
|
133
|
-
// this prevents the tokens from hiding when the user is moving focus from the input to a token,
|
134
|
-
// but still hides the tokens when the user blurs the input by tabbing out or clicking somewhere else on the page
|
135
|
-
|
136
|
-
setTimeout(() => {
|
137
|
-
var _containerRef$current4;
|
138
|
-
|
139
|
-
if (!((_containerRef$current4 = containerRef.current) !== null && _containerRef$current4 !== void 0 && _containerRef$current4.contains(document.activeElement)) && visibleTokenCount) {
|
140
|
-
setTokensAreTruncated(true);
|
141
|
-
}
|
142
|
-
}, 0);
|
143
108
|
};
|
144
109
|
|
145
110
|
const handleInputKeyDown = e => {
|
@@ -177,17 +142,6 @@ function TextInputWithTokensInnerComponent({
|
|
177
142
|
}
|
178
143
|
};
|
179
144
|
|
180
|
-
const focusInput = () => {
|
181
|
-
var _combinedInputRef$cur;
|
182
|
-
|
183
|
-
(_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
|
184
|
-
};
|
185
|
-
|
186
|
-
const preventTokenClickPropagation = event => {
|
187
|
-
event.stopPropagation();
|
188
|
-
};
|
189
|
-
|
190
|
-
const visibleTokens = tokensAreTruncated ? tokens.slice(0, visibleTokenCount) : tokens;
|
191
145
|
return /*#__PURE__*/React.createElement(TextInputWrapper, {
|
192
146
|
block: block,
|
193
147
|
className: className,
|
@@ -200,7 +154,6 @@ function TextInputWithTokensInnerComponent({
|
|
200
154
|
maxWidth: maxWidthProp,
|
201
155
|
variant: variantProp,
|
202
156
|
ref: containerRef,
|
203
|
-
onClick: focusInput,
|
204
157
|
sx: {
|
205
158
|
alignItems: 'center',
|
206
159
|
flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
|
@@ -232,13 +185,12 @@ function TextInputWithTokensInnerComponent({
|
|
232
185
|
ref: combinedInputRef,
|
233
186
|
disabled: disabled,
|
234
187
|
onFocus: handleInputFocus,
|
235
|
-
onBlur: handleInputBlur,
|
236
188
|
onKeyDown: handleInputKeyDown,
|
237
189
|
type: "text",
|
238
190
|
sx: {
|
239
191
|
height: '100%'
|
240
192
|
}
|
241
|
-
}, inputPropsRest))), TokenComponent ?
|
193
|
+
}, inputPropsRest))), tokens.length && TokenComponent ? tokens.map(({
|
242
194
|
id,
|
243
195
|
...tokenRest
|
244
196
|
}, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
|
@@ -246,7 +198,6 @@ function TextInputWithTokensInnerComponent({
|
|
246
198
|
onFocus: handleTokenFocus(i),
|
247
199
|
onBlur: handleTokenBlur,
|
248
200
|
onKeyUp: handleTokenKeyUp,
|
249
|
-
onClick: preventTokenClickPropagation,
|
250
201
|
isSelected: selectedTokenIndex === i,
|
251
202
|
onRemove: () => {
|
252
203
|
handleTokenRemove(id);
|
@@ -254,10 +205,7 @@ function TextInputWithTokensInnerComponent({
|
|
254
205
|
hideRemoveButton: hideTokenRemoveButtons,
|
255
206
|
size: size,
|
256
207
|
tabIndex: 0
|
257
|
-
}, tokenRest))) : null
|
258
|
-
color: "fg.muted",
|
259
|
-
fontSize: size && overflowCountFontSizeMap[size]
|
260
|
-
}, "+", tokens.length - visibleTokens.length) : null);
|
208
|
+
}, tokenRest))) : null);
|
261
209
|
}
|
262
210
|
|
263
211
|
TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
|
@@ -21,7 +21,7 @@ const sizeVariants = variant({
|
|
21
21
|
const TextInputWrapper = styled.span.withConfig({
|
22
22
|
displayName: "_TextInputWrapper__TextInputWrapper",
|
23
23
|
componentId: "sc-5vfcis-0"
|
24
|
-
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";
|
24
|
+
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
|
25
25
|
if (props.hasIcon) {
|
26
26
|
return css(["padding:0;"]);
|
27
27
|
} else {
|
package/lib-esm/theme-preval.js
CHANGED
@@ -515,7 +515,7 @@ module.exports = {
|
|
515
515
|
}
|
516
516
|
}
|
517
517
|
},
|
518
|
-
"
|
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
|
-
"
|
2459
|
+
"dark_colorblind": {
|
2460
2460
|
"colors": {
|
2461
2461
|
"canvasDefaultTransparent": "rgba(13,17,23,0)",
|
2462
2462
|
"marketingIcon": {
|