@primer/components 0.0.0-202192231947 → 0.0.0-202192543046
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 +23 -1
- package/codemods/deprecateUtilityComponents.js +1 -1
- package/dist/browser.esm.js +880 -770
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +883 -773
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +4 -4
- package/lib/ActionList/List.d.ts +2 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +6 -3
- package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib/Autocomplete/Autocomplete.d.ts +306 -0
- package/lib/Autocomplete/Autocomplete.js +145 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib/Autocomplete/AutocompleteContext.js +11 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +294 -0
- package/lib/Autocomplete/AutocompleteInput.js +157 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib/Autocomplete/AutocompleteMenu.js +224 -0
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib/Autocomplete/AutocompleteOverlay.js +80 -0
- package/lib/Autocomplete/index.d.ts +2 -0
- package/lib/Autocomplete/index.js +15 -0
- package/lib/BaseStyles.js +1 -1
- package/lib/BorderBox.js +1 -1
- package/lib/Button/Button.js +1 -1
- package/lib/Button/ButtonInvisible.js +1 -1
- package/lib/Button/ButtonTableList.js +1 -1
- package/lib/Caret.js +2 -2
- package/lib/DatePicker/DatePicker.js +14 -8
- package/lib/DatePicker/DatePickerAnchor.js +7 -2
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +39 -0
- package/lib/DatePicker/DatePickerPanel.js +92 -9
- package/lib/DatePicker/Day.js +2 -1
- package/lib/DatePicker/Month.js +16 -6
- package/lib/DatePicker/useDatePicker.d.ts +18 -2
- package/lib/DatePicker/useDatePicker.js +155 -51
- package/lib/Dialog.js +1 -1
- package/lib/FilteredActionList/FilteredActionList.js +5 -31
- package/lib/Flash.js +16 -16
- package/lib/Label.js +1 -1
- package/lib/Overlay.d.ts +1 -0
- package/lib/Overlay.js +3 -1
- package/lib/Pagination/Pagination.js +1 -1
- package/lib/ProgressBar.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +12 -10
- package/lib/StateLabel.js +13 -19
- package/lib/TextInput.d.ts +5 -13
- package/lib/TextInput.js +4 -46
- package/lib/TextInputWithTokens.d.ts +325 -0
- package/lib/TextInputWithTokens.js +245 -0
- package/lib/Token/AvatarToken.d.ts +7 -0
- package/lib/Token/AvatarToken.js +64 -0
- package/lib/Token/IssueLabelToken.d.ts +14 -0
- package/lib/Token/IssueLabelToken.js +144 -0
- package/lib/Token/Token.d.ts +15 -0
- package/lib/Token/Token.js +94 -0
- package/lib/Token/TokenBase.d.ts +31 -0
- package/lib/Token/TokenBase.js +108 -0
- package/lib/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib/Token/_RemoveTokenButton.js +77 -0
- package/lib/Token/_TokenTextContainer.d.ts +3 -0
- package/lib/Token/_TokenTextContainer.js +17 -0
- package/lib/Token/index.d.ts +3 -0
- package/lib/Token/index.js +31 -0
- package/lib/_TextInputWrapper.d.ts +10 -0
- package/lib/_TextInputWrapper.js +51 -0
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib/behaviors/scrollIntoViewingArea.js +39 -0
- package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib/hooks/useOverlay.d.ts +2 -1
- package/lib/hooks/useOverlay.js +4 -2
- package/lib/index.d.ts +5 -0
- package/lib/index.js +36 -0
- package/lib/theme-preval.js +372 -3102
- package/lib/utils/testing.d.ts +51 -494
- package/lib/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
- package/lib/utils/{types.js → types/AriaRole.js} +0 -0
- package/lib/utils/types/ComponentProps.d.ts +9 -0
- package/lib/utils/types/ComponentProps.js +1 -0
- package/lib/utils/types/Flatten.d.ts +4 -0
- package/lib/utils/types/Flatten.js +1 -0
- package/lib/utils/types/MandateProps.d.ts +3 -0
- package/lib/utils/types/MandateProps.js +1 -0
- package/lib/utils/types/Merge.d.ts +19 -0
- package/lib/utils/types/Merge.js +1 -0
- package/lib/utils/types/index.d.ts +5 -0
- package/lib/utils/types/index.js +70 -0
- package/lib-esm/ActionList/Item.js +4 -4
- package/lib-esm/ActionList/List.d.ts +2 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +6 -3
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib-esm/Autocomplete/Autocomplete.d.ts +306 -0
- package/lib-esm/Autocomplete/Autocomplete.js +123 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +294 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
- package/lib-esm/Autocomplete/index.d.ts +2 -0
- package/lib-esm/Autocomplete/index.js +1 -0
- package/lib-esm/BaseStyles.js +1 -1
- package/lib-esm/BorderBox.js +1 -1
- package/lib-esm/Button/Button.js +1 -1
- package/lib-esm/Button/ButtonInvisible.js +1 -1
- package/lib-esm/Button/ButtonTableList.js +1 -1
- package/lib-esm/Caret.js +2 -2
- package/lib-esm/DatePicker/DatePicker.js +13 -6
- package/lib-esm/DatePicker/DatePickerAnchor.js +7 -2
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +86 -10
- package/lib-esm/DatePicker/Day.js +2 -1
- package/lib-esm/DatePicker/Month.js +15 -6
- package/lib-esm/DatePicker/useDatePicker.d.ts +18 -2
- package/lib-esm/DatePicker/useDatePicker.js +156 -52
- package/lib-esm/Dialog.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.js +3 -31
- package/lib-esm/Flash.js +16 -16
- package/lib-esm/Label.js +1 -1
- package/lib-esm/Overlay.d.ts +1 -0
- package/lib-esm/Overlay.js +3 -1
- package/lib-esm/Pagination/Pagination.js +1 -1
- package/lib-esm/ProgressBar.js +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +12 -10
- package/lib-esm/StateLabel.js +13 -19
- package/lib-esm/TextInput.d.ts +5 -13
- package/lib-esm/TextInput.js +4 -37
- package/lib-esm/TextInputWithTokens.d.ts +325 -0
- package/lib-esm/TextInputWithTokens.js +220 -0
- package/lib-esm/Token/AvatarToken.d.ts +7 -0
- package/lib-esm/Token/AvatarToken.js +43 -0
- package/lib-esm/Token/IssueLabelToken.d.ts +14 -0
- package/lib-esm/Token/IssueLabelToken.js +124 -0
- package/lib-esm/Token/Token.d.ts +15 -0
- package/lib-esm/Token/Token.js +73 -0
- package/lib-esm/Token/TokenBase.d.ts +31 -0
- package/lib-esm/Token/TokenBase.js +87 -0
- package/lib-esm/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib-esm/Token/_RemoveTokenButton.js +60 -0
- package/lib-esm/Token/_TokenTextContainer.d.ts +3 -0
- package/lib-esm/Token/_TokenTextContainer.js +6 -0
- package/lib-esm/Token/index.d.ts +3 -0
- package/lib-esm/Token/index.js +3 -0
- package/lib-esm/_TextInputWrapper.d.ts +10 -0
- package/lib-esm/_TextInputWrapper.js +31 -0
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
- package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib-esm/hooks/useOverlay.d.ts +2 -1
- package/lib-esm/hooks/useOverlay.js +4 -2
- package/lib-esm/index.d.ts +5 -0
- package/lib-esm/index.js +3 -0
- package/lib-esm/theme-preval.js +372 -3102
- package/lib-esm/utils/testing.d.ts +51 -494
- package/lib-esm/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
- package/lib-esm/utils/{types.js → types/AriaRole.js} +0 -0
- package/lib-esm/utils/types/ComponentProps.d.ts +9 -0
- package/lib-esm/utils/types/ComponentProps.js +1 -0
- package/lib-esm/utils/types/Flatten.d.ts +4 -0
- package/lib-esm/utils/types/Flatten.js +1 -0
- package/lib-esm/utils/types/MandateProps.d.ts +3 -0
- package/lib-esm/utils/types/MandateProps.js +1 -0
- package/lib-esm/utils/types/Merge.d.ts +19 -0
- package/lib-esm/utils/types/Merge.js +1 -0
- package/lib-esm/utils/types/index.d.ts +5 -0
- package/lib-esm/utils/types/index.js +5 -0
- package/package.json +10 -9
@@ -1,6 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
|
3
3
|
export declare type DateFormat = 'short' | 'long' | string;
|
4
|
+
export declare type SelectionVariant = 'single' | 'multi' | 'range';
|
4
5
|
export interface DatePickerConfiguration {
|
5
6
|
anchorVariant?: AnchorVariant;
|
6
7
|
blockedDates?: Array<Date>;
|
@@ -12,8 +13,9 @@ export interface DatePickerConfiguration {
|
|
12
13
|
maxDate?: Date;
|
13
14
|
placeholder?: string;
|
14
15
|
rangeIncrement?: number;
|
15
|
-
selection?:
|
16
|
+
selection?: SelectionVariant;
|
16
17
|
view?: '1-month' | '2-month';
|
18
|
+
weekStartsOn?: 'Sunday' | 'Monday';
|
17
19
|
}
|
18
20
|
export declare type RangeSelection = {
|
19
21
|
from: Date;
|
@@ -26,13 +28,20 @@ export declare type StringRangeSelection = {
|
|
26
28
|
export interface DatePickerContext {
|
27
29
|
disabled?: boolean;
|
28
30
|
configuration: DatePickerConfiguration;
|
31
|
+
currentViewingDate: Date;
|
32
|
+
goToMonth: (date: Date) => void;
|
33
|
+
hoverRange?: RangeSelection | null;
|
29
34
|
selection?: Selection;
|
30
35
|
softSelection?: Partial<RangeSelection> | null;
|
31
36
|
selectionActive?: boolean;
|
32
37
|
formattedDate: string;
|
38
|
+
nextMonth: () => void;
|
33
39
|
onSelection: (date: Date) => void;
|
34
40
|
onDayFocus: (date: Date) => void;
|
35
41
|
onDayBlur: (date: Date) => void;
|
42
|
+
previousMonth: () => void;
|
43
|
+
revertValue: () => void;
|
44
|
+
saveValue: (selection?: Selection) => void;
|
36
45
|
}
|
37
46
|
export declare type Selection = Date | Array<Date> | RangeSelection | null;
|
38
47
|
export declare type StringSelection = string | Array<string> | {
|
@@ -45,13 +54,20 @@ declare const useDatePicker: (date?: Date | undefined) => {
|
|
45
54
|
disabled: boolean;
|
46
55
|
selected: DaySelection;
|
47
56
|
configuration: DatePickerConfiguration;
|
57
|
+
currentViewingDate: Date;
|
58
|
+
goToMonth: (date: Date) => void;
|
59
|
+
hoverRange?: RangeSelection | null | undefined;
|
48
60
|
selection?: Selection | undefined;
|
49
61
|
softSelection?: Partial<RangeSelection> | null | undefined;
|
50
62
|
selectionActive?: boolean | undefined;
|
51
63
|
formattedDate: string;
|
64
|
+
nextMonth: () => void;
|
52
65
|
onSelection: (date: Date) => void;
|
53
66
|
onDayFocus: (date: Date) => void;
|
54
67
|
onDayBlur: (date: Date) => void;
|
68
|
+
previousMonth: () => void;
|
69
|
+
revertValue: () => void;
|
70
|
+
saveValue: (selection?: Selection | undefined) => void;
|
55
71
|
};
|
56
72
|
export default useDatePicker;
|
57
73
|
export interface DatePickerProviderProps {
|
@@ -60,7 +76,7 @@ export interface DatePickerProviderProps {
|
|
60
76
|
value?: Selection | StringSelection;
|
61
77
|
}
|
62
78
|
export declare function isSingleSelection(selection: Selection): selection is Date;
|
63
|
-
export declare function isMultiSelection(selection: Selection): selection is Array<Date>;
|
79
|
+
export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
|
64
80
|
export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
|
65
81
|
export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
|
66
82
|
export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
|
@@ -1,39 +1,54 @@
|
|
1
|
-
import { format, isEqual, isAfter, isBefore } from 'date-fns';
|
1
|
+
import { format, isEqual, isAfter, isBefore, addMonths, subMonths } from 'date-fns';
|
2
2
|
import deepmerge from 'deepmerge';
|
3
3
|
import React, { createContext, useCallback, useContext, useMemo, useEffect, useState } from 'react';
|
4
4
|
const DatePickerContext = /*#__PURE__*/createContext(null);
|
5
5
|
|
6
6
|
const useDatePicker = date => {
|
7
7
|
const value = useContext(DatePickerContext);
|
8
|
+
const [selected, setSelected] = useState(false);
|
8
9
|
|
9
10
|
if (!value) {
|
10
11
|
throw new Error('useDatePicker must be used inside a DatePickerProvider');
|
11
12
|
}
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
|
14
|
+
useEffect(() => {
|
15
|
+
if (date) {
|
16
|
+
if (value.hoverRange) {
|
17
|
+
if (isRangeSelection(value.hoverRange)) {
|
18
|
+
if (isEqual(date, value.hoverRange.from)) {
|
19
|
+
setSelected('start');
|
20
|
+
} else if (value.hoverRange.to && isEqual(date, value.hoverRange.to)) {
|
21
|
+
setSelected('end');
|
22
|
+
} else if (isAfter(date, value.hoverRange.from) && value.hoverRange.to && isBefore(date, value.hoverRange.to)) {
|
23
|
+
setSelected('middle');
|
24
|
+
} else {
|
25
|
+
setSelected(false);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
} else if (value.selection) {
|
29
|
+
if (isMultiSelection(value.selection)) {
|
30
|
+
setSelected(!!value.selection.find(d => isEqual(d, date)));
|
31
|
+
} else if (isRangeSelection(value.selection)) {
|
32
|
+
if (isEqual(date, value.selection.from)) {
|
33
|
+
setSelected('start');
|
34
|
+
} else if (value.selection.to && isEqual(date, value.selection.to)) {
|
35
|
+
setSelected('end');
|
36
|
+
} else if (isAfter(date, value.selection.from) && value.selection.to && isBefore(date, value.selection.to)) {
|
37
|
+
setSelected('middle');
|
38
|
+
} else {
|
39
|
+
setSelected(false);
|
40
|
+
}
|
28
41
|
} else {
|
29
|
-
|
42
|
+
setSelected(isEqual(date, value.selection));
|
30
43
|
}
|
31
|
-
} else {
|
32
|
-
selected = isEqual(date, value.selection);
|
33
44
|
}
|
34
|
-
}
|
35
|
-
|
45
|
+
}
|
46
|
+
}, [date, value.hoverRange, value.selection]);
|
47
|
+
let blocked,
|
48
|
+
disabled = false;
|
36
49
|
|
50
|
+
if (date) {
|
51
|
+
// Determine if date is blocked out
|
37
52
|
if (value.configuration.blockedDates) {
|
38
53
|
blocked = !!value.configuration.blockedDates.find(d => isEqual(d, date));
|
39
54
|
} // Determine if date is disabled
|
@@ -56,7 +71,7 @@ export function isSingleSelection(selection) {
|
|
56
71
|
return selection instanceof Date;
|
57
72
|
}
|
58
73
|
export function isMultiSelection(selection) {
|
59
|
-
return Array.isArray(selection)
|
74
|
+
return Array.isArray(selection);
|
60
75
|
}
|
61
76
|
export function isRangeSelection(selection) {
|
62
77
|
return !!selection.from;
|
@@ -65,24 +80,57 @@ export function isStringRangeSelection(selection) {
|
|
65
80
|
return !!selection.from;
|
66
81
|
}
|
67
82
|
|
68
|
-
function parseSelection(selection) {
|
83
|
+
function parseSelection(selection, variant) {
|
69
84
|
if (!selection) return;
|
70
85
|
|
71
|
-
if (
|
72
|
-
|
86
|
+
if (variant === 'multi') {
|
87
|
+
if (isMultiSelection(selection)) {
|
88
|
+
const parsedSelection = [];
|
73
89
|
|
74
|
-
|
75
|
-
|
76
|
-
|
90
|
+
for (const d of selection) {
|
91
|
+
parsedSelection.push(new Date(new Date(d).toDateString()));
|
92
|
+
}
|
77
93
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
94
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
95
|
+
} else if (selection instanceof Date) {
|
96
|
+
return [new Date(new Date(selection).toDateString())];
|
97
|
+
} else if (isRangeSelection(selection)) {
|
98
|
+
const parsedSelection = [];
|
99
|
+
parsedSelection.push(new Date(new Date(selection.from).toDateString()));
|
100
|
+
|
101
|
+
if (selection.to) {
|
102
|
+
parsedSelection.push(new Date(new Date(selection.to).toDateString()));
|
103
|
+
}
|
104
|
+
|
105
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
106
|
+
}
|
107
|
+
} else if (variant === 'range') {
|
108
|
+
if (isRangeSelection(selection)) {
|
109
|
+
return {
|
110
|
+
from: new Date(new Date(selection.from).toDateString()),
|
111
|
+
to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
|
112
|
+
};
|
113
|
+
} else if (isMultiSelection(selection)) {
|
114
|
+
return {
|
115
|
+
from: new Date(new Date(selection[0]).toDateString()),
|
116
|
+
to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
|
117
|
+
};
|
118
|
+
} else if (selection instanceof Date) {
|
119
|
+
return {
|
120
|
+
from: new Date(new Date(selection).toDateString()),
|
121
|
+
to: null
|
122
|
+
};
|
123
|
+
}
|
84
124
|
} else {
|
85
|
-
|
125
|
+
if (selection instanceof Date) {
|
126
|
+
return new Date(new Date(selection).toDateString());
|
127
|
+
} else if (isMultiSelection(selection)) {
|
128
|
+
return new Date(new Date(selection[0]).toDateString());
|
129
|
+
} else if (isRangeSelection(selection)) {
|
130
|
+
return new Date(new Date(selection.from).toDateString());
|
131
|
+
} else {
|
132
|
+
return;
|
133
|
+
}
|
86
134
|
}
|
87
135
|
}
|
88
136
|
|
@@ -93,7 +141,8 @@ const defaultConfiguration = {
|
|
93
141
|
dimWeekends: false,
|
94
142
|
placeholder: 'Select a Date...',
|
95
143
|
selection: 'single',
|
96
|
-
view: '2-month'
|
144
|
+
view: '2-month',
|
145
|
+
weekStartsOn: 'Sunday'
|
97
146
|
};
|
98
147
|
export const DatePickerProvider = ({
|
99
148
|
configuration: externalConfig = {},
|
@@ -102,11 +151,24 @@ export const DatePickerProvider = ({
|
|
102
151
|
value
|
103
152
|
}) => {
|
104
153
|
const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
|
105
|
-
const [
|
154
|
+
const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.selection));
|
155
|
+
const [selection, setSelection] = useState(parseSelection(value, configuration.selection));
|
106
156
|
const [hoverRange, setHoverRange] = useState(null);
|
157
|
+
const [currentViewingDate, setCurrentViewingDate] = useState(new Date());
|
107
158
|
useEffect(() => {
|
108
159
|
setConfiguration(deepmerge(defaultConfiguration, externalConfig));
|
109
|
-
|
160
|
+
setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
|
161
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
162
|
+
}, [configuration.selection, externalConfig]);
|
163
|
+
const goToMonth = useCallback(date => {
|
164
|
+
setCurrentViewingDate(new Date(new Date(date).toDateString()));
|
165
|
+
}, []);
|
166
|
+
const nextMonth = useCallback(() => {
|
167
|
+
setCurrentViewingDate(addMonths(currentViewingDate, 1));
|
168
|
+
}, [currentViewingDate]);
|
169
|
+
const previousMonth = useCallback(() => {
|
170
|
+
setCurrentViewingDate(subMonths(currentViewingDate, 1));
|
171
|
+
}, [currentViewingDate]);
|
110
172
|
const getFormattedDate = useMemo(() => {
|
111
173
|
if (!selection) {
|
112
174
|
return configuration.placeholder;
|
@@ -135,6 +197,10 @@ export const DatePickerProvider = ({
|
|
135
197
|
{
|
136
198
|
if (selection instanceof Date) {
|
137
199
|
return format(selection, template);
|
200
|
+
} else if (Array.isArray(selection)) {
|
201
|
+
return format(selection[0], template);
|
202
|
+
} else if (isRangeSelection(selection)) {
|
203
|
+
return format(selection.from, template);
|
138
204
|
} else {
|
139
205
|
return 'Invalid Selection';
|
140
206
|
}
|
@@ -143,7 +209,13 @@ export const DatePickerProvider = ({
|
|
143
209
|
case 'multi':
|
144
210
|
{
|
145
211
|
if (Array.isArray(selection)) {
|
146
|
-
|
212
|
+
if (selection.length > 3) return `${selection.length} Selected`;
|
213
|
+
const formatted = selection.map(d => format(d, template)).join(', ');
|
214
|
+
return formatted;
|
215
|
+
} else if (selection instanceof Date) {
|
216
|
+
return [selection].map(d => format(d, template)).join(', ');
|
217
|
+
} else if (isRangeSelection(selection)) {
|
218
|
+
return [selection.to, selection.from].map(d => d ? format(d, template) : '').join(', ');
|
147
219
|
} else {
|
148
220
|
return 'Invalid Selection';
|
149
221
|
}
|
@@ -153,6 +225,18 @@ export const DatePickerProvider = ({
|
|
153
225
|
{
|
154
226
|
if (isRangeSelection(selection)) {
|
155
227
|
return Object.entries(selection).map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
228
|
+
} else if (selection instanceof Date) {
|
229
|
+
return Object.entries({
|
230
|
+
from: selection,
|
231
|
+
to: null
|
232
|
+
}).map(([_, date]) => date ? 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 ? format(date, template) : '').join(' - ');
|
156
240
|
} else {
|
157
241
|
return 'Invalid Selection';
|
158
242
|
}
|
@@ -164,30 +248,41 @@ export const DatePickerProvider = ({
|
|
164
248
|
}
|
165
249
|
}
|
166
250
|
}, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
|
251
|
+
const saveValue = useCallback(updatedSelection => {
|
252
|
+
setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
|
253
|
+
closePicker === null || closePicker === void 0 ? void 0 : closePicker();
|
254
|
+
}, [closePicker, selection]);
|
167
255
|
const selectionHandler = useCallback(date => {
|
168
256
|
if (configuration.selection === 'multi') {
|
169
|
-
const selections = selection;
|
257
|
+
const selections = [...selection];
|
170
258
|
const existingIndex = selections.findIndex(s => isEqual(s, date));
|
171
259
|
|
172
260
|
if (existingIndex > -1) {
|
173
|
-
|
261
|
+
selections.splice(existingIndex, 1);
|
262
|
+
setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
|
174
263
|
} else {
|
175
|
-
setSelection([...selections, date]);
|
264
|
+
setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
|
176
265
|
}
|
177
266
|
} else if (configuration.selection === 'range') {
|
178
267
|
if (selection && isRangeSelection(selection) && !selection.to) {
|
179
|
-
|
268
|
+
const updatedSelection = isBefore(date, selection.from) ? {
|
180
269
|
from: date,
|
181
270
|
to: selection.from
|
182
271
|
} : {
|
183
272
|
from: selection.from,
|
184
273
|
to: date
|
185
|
-
}
|
274
|
+
};
|
275
|
+
setSelection(updatedSelection);
|
276
|
+
setHoverRange(null);
|
186
277
|
|
187
278
|
if (!configuration.confirmation) {
|
188
|
-
|
279
|
+
saveValue(updatedSelection);
|
189
280
|
}
|
190
281
|
} else {
|
282
|
+
setHoverRange({
|
283
|
+
from: date,
|
284
|
+
to: date
|
285
|
+
});
|
191
286
|
setSelection({
|
192
287
|
from: date,
|
193
288
|
to: null
|
@@ -197,14 +292,14 @@ export const DatePickerProvider = ({
|
|
197
292
|
setSelection(date);
|
198
293
|
|
199
294
|
if (!configuration.confirmation) {
|
200
|
-
|
295
|
+
saveValue(date);
|
201
296
|
}
|
202
297
|
}
|
203
|
-
}, [
|
298
|
+
}, [configuration.confirmation, configuration.selection, saveValue, selection]);
|
204
299
|
const focusHnadler = useCallback(date => {
|
205
300
|
if (!selection) return;
|
206
301
|
|
207
|
-
if (configuration.selection === 'range' && isRangeSelection(selection)) {
|
302
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
|
208
303
|
setHoverRange(isBefore(date, selection.from) ? {
|
209
304
|
from: date,
|
210
305
|
to: selection.from
|
@@ -213,26 +308,35 @@ export const DatePickerProvider = ({
|
|
213
308
|
to: date
|
214
309
|
});
|
215
310
|
}
|
216
|
-
}, [configuration.selection, selection]);
|
311
|
+
}, [configuration.selection, hoverRange, selection]);
|
217
312
|
const blurHnadler = useCallback(date => {
|
218
313
|
if (!selection || !hoverRange) return;
|
219
314
|
|
220
|
-
if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
|
221
|
-
setHoverRange(null);
|
315
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
|
222
316
|
}
|
223
317
|
}, [configuration.selection, hoverRange, selection]);
|
318
|
+
const revertValue = useCallback(() => {
|
319
|
+
setSelection(previousSelection);
|
320
|
+
}, [previousSelection]);
|
224
321
|
const datePickerCtx = useMemo(() => {
|
225
322
|
return {
|
226
323
|
configuration,
|
324
|
+
currentViewingDate,
|
227
325
|
disabled: false,
|
228
326
|
formattedDate: getFormattedDate,
|
327
|
+
goToMonth,
|
328
|
+
hoverRange,
|
329
|
+
nextMonth,
|
229
330
|
onDayBlur: blurHnadler,
|
230
331
|
onDayFocus: focusHnadler,
|
231
332
|
onSelection: selectionHandler,
|
333
|
+
previousMonth,
|
334
|
+
revertValue,
|
335
|
+
saveValue,
|
232
336
|
selectionActive: false,
|
233
337
|
selection
|
234
338
|
};
|
235
|
-
}, [blurHnadler, configuration, focusHnadler, getFormattedDate, selection, selectionHandler]);
|
339
|
+
}, [blurHnadler, configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, hoverRange, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
|
236
340
|
return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
|
237
341
|
value: datePickerCtx
|
238
342
|
}, children);
|
package/lib-esm/Dialog.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
2
|
|
3
3
|
import React, { useCallback, useEffect, useRef } from 'react';
|
4
|
+
import { useSSRSafeId } from '@react-aria/ssr';
|
4
5
|
import TextInput from '../TextInput';
|
5
6
|
import Box from '../Box';
|
6
7
|
import { ActionList } from '../ActionList';
|
@@ -11,36 +12,7 @@ import styled from 'styled-components';
|
|
11
12
|
import { get } from '../constants';
|
12
13
|
import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate';
|
13
14
|
import useScrollFlash from '../hooks/useScrollFlash';
|
14
|
-
import {
|
15
|
-
|
16
|
-
function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
|
17
|
-
const {
|
18
|
-
top: childTop,
|
19
|
-
bottom: childBottom
|
20
|
-
} = child.getBoundingClientRect();
|
21
|
-
const {
|
22
|
-
top: containerTop,
|
23
|
-
bottom: containerBottom
|
24
|
-
} = container.getBoundingClientRect();
|
25
|
-
const isChildTopAboveViewingArea = childTop < containerTop + margin;
|
26
|
-
const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
|
27
|
-
|
28
|
-
if (isChildTopAboveViewingArea) {
|
29
|
-
const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
|
30
|
-
container.scrollTo({
|
31
|
-
behavior,
|
32
|
-
top: scrollHeightToChildTop - margin
|
33
|
-
});
|
34
|
-
} else if (isChildBottomBelowViewingArea) {
|
35
|
-
const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
|
36
|
-
container.scrollTo({
|
37
|
-
behavior,
|
38
|
-
top: scrollHeightToChildBottom + margin
|
39
|
-
});
|
40
|
-
} // either completely in view or outside viewing area on both ends, don't scroll
|
41
|
-
|
42
|
-
}
|
43
|
-
|
15
|
+
import { scrollIntoViewingArea } from '../behaviors/scrollIntoViewingArea';
|
44
16
|
const StyledHeader = styled.div.withConfig({
|
45
17
|
displayName: "FilteredActionList__StyledHeader",
|
46
18
|
componentId: "yg3jkv-0"
|
@@ -95,7 +67,7 @@ export function FilteredActionList({
|
|
95
67
|
useEffect(() => {
|
96
68
|
// if items changed, we want to instantly move active descendant into view
|
97
69
|
if (activeDescendantRef.current && scrollContainerRef.current) {
|
98
|
-
scrollIntoViewingArea(activeDescendantRef.current, scrollContainerRef.current, undefined, 'auto');
|
70
|
+
scrollIntoViewingArea(activeDescendantRef.current, scrollContainerRef.current, 'vertical', undefined, undefined, 'auto');
|
99
71
|
}
|
100
72
|
}, [items]);
|
101
73
|
useScrollFlash(scrollContainerRef);
|
package/lib-esm/Flash.js
CHANGED
@@ -5,35 +5,35 @@ import sx from './sx';
|
|
5
5
|
const variants = variant({
|
6
6
|
variants: {
|
7
7
|
default: {
|
8
|
-
color: '
|
9
|
-
backgroundColor: '
|
10
|
-
borderColor: '
|
8
|
+
color: 'fg.default',
|
9
|
+
backgroundColor: 'accent.subtle',
|
10
|
+
borderColor: 'accent.muted',
|
11
11
|
svg: {
|
12
|
-
color: '
|
12
|
+
color: 'accent.fg'
|
13
13
|
}
|
14
14
|
},
|
15
15
|
success: {
|
16
|
-
color: '
|
17
|
-
backgroundColor: '
|
18
|
-
borderColor: '
|
16
|
+
color: 'fg.default',
|
17
|
+
backgroundColor: 'success.subtle',
|
18
|
+
borderColor: 'success.muted',
|
19
19
|
svg: {
|
20
|
-
color: '
|
20
|
+
color: 'success.fg'
|
21
21
|
}
|
22
22
|
},
|
23
23
|
danger: {
|
24
|
-
color: '
|
25
|
-
backgroundColor: '
|
26
|
-
borderColor: '
|
24
|
+
color: 'fg.default',
|
25
|
+
backgroundColor: 'danger.subtle',
|
26
|
+
borderColor: 'danger.muted',
|
27
27
|
svg: {
|
28
|
-
color: '
|
28
|
+
color: 'danger.fg'
|
29
29
|
}
|
30
30
|
},
|
31
31
|
warning: {
|
32
|
-
color: '
|
33
|
-
backgroundColor: '
|
34
|
-
borderColor: '
|
32
|
+
color: 'fg.default',
|
33
|
+
backgroundColor: 'attention.subtle',
|
34
|
+
borderColor: 'attention.muted',
|
35
35
|
svg: {
|
36
|
-
color: '
|
36
|
+
color: 'attention.fg'
|
37
37
|
}
|
38
38
|
}
|
39
39
|
}
|
package/lib-esm/Label.js
CHANGED
@@ -33,7 +33,7 @@ const Label = styled.span.withConfig({
|
|
33
33
|
componentId: "sc-1t3ykp0-0"
|
34
34
|
})(["display:inline-block;font-weight:", ";color:", ";border-radius:", ";&:hover{text-decoration:none;}", " ", " ", " ", " ", ""], get('fontWeights.semibold'), get('colors.fg.onEmphasis'), get('radii.3'), sizeVariant, COMMON, props => props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '', props => props.outline ? outlineStyles : '', sx);
|
35
35
|
Label.defaultProps = {
|
36
|
-
bg: '
|
36
|
+
bg: 'neutral.emphasis',
|
37
37
|
variant: 'medium'
|
38
38
|
};
|
39
39
|
export default Label;
|
package/lib-esm/Overlay.d.ts
CHANGED
@@ -40,6 +40,7 @@ export declare type OverlayProps = {
|
|
40
40
|
top: number;
|
41
41
|
left: number;
|
42
42
|
portalContainerName?: string;
|
43
|
+
preventFocusOnOpen?: boolean;
|
43
44
|
} & Omit<ComponentProps<typeof StyledOverlay>, 'visibility' | keyof SystemPositionProps>;
|
44
45
|
/**
|
45
46
|
* An `Overlay` is a flexible floating surface, used to display transient content such as menus,
|
package/lib-esm/Overlay.js
CHANGED
@@ -92,6 +92,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
92
92
|
left,
|
93
93
|
anchorSide,
|
94
94
|
portalContainerName,
|
95
|
+
preventFocusOnOpen,
|
95
96
|
...rest
|
96
97
|
}, forwardedRef) => {
|
97
98
|
const overlayRef = useRef(null);
|
@@ -107,7 +108,8 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
107
108
|
onEscape,
|
108
109
|
ignoreClickRefs,
|
109
110
|
onClickOutside,
|
110
|
-
initialFocusRef
|
111
|
+
initialFocusRef,
|
112
|
+
preventFocusOnOpen
|
111
113
|
});
|
112
114
|
useEffect(() => {
|
113
115
|
var _combinedRef$current;
|
@@ -9,7 +9,7 @@ import { buildComponentData, buildPaginationModel } from './model';
|
|
9
9
|
const Page = styled.a.withConfig({
|
10
10
|
displayName: "Pagination__Page",
|
11
11
|
componentId: "b80nss-0"
|
12
|
-
})(["display:inline-block;min-width:32px;padding:5px 10px;font-style:normal;line-height:20px;color:", ";text-align:center;white-space:nowrap;vertical-align:middle;cursor:pointer;user-select:none;text-decoration:none;margin-right:", ";&:last-child{margin-right:0;}border:", " solid transparent;border-radius:", ";transition:border-color 0.2s cubic-bezier(0.3,0,0.5,1);&:hover,&:focus{text-decoration:none;border-color:", ";outline:0;transition-duration:0.1s;}&:active{border-color:", ";}&[rel='prev'],&[rel='next']{color:", ";}&[aria-current],&[aria-current]:hover{color:", ";background-color:", ";border-color:transparent;}&[aria-disabled],&[aria-disabled]:hover{color:", ";cursor:default;border-color:transparent;}@supports (clip-path:polygon(50% 0,100% 50%,50% 100%)){&[rel='prev']::before,&[rel='next']::after{display:inline-block;width:16px;height:16px;vertical-align:text-bottom;content:'';background-color:currentColor;}&[rel='prev']::before{margin-right:", ";clip-path:polygon( 9.8px 12.8px,8.7px 12.8px,4.5px 8.5px,4.5px 7.5px,8.7px 3.2px,9.8px 4.3px,6.1px 8px,9.8px 11.7px,9.8px 12.8px );}&[rel='next']::after{margin-left:", ";clip-path:polygon( 6.2px 3.2px,7.3px 3.2px,11.5px 7.5px,11.5px 8.5px,7.3px 12.8px,6.2px 11.7px,9.9px 8px,6.2px 4.3px,6.2px 3.2px );}}", ";"], get('colors.fg.default'), get('space.1'), get('borderWidths.1'), get('radii.2'), get('colors.border.default'), get('colors.border.muted'), get('colors.accent.fg'), get('colors.fg.onEmphasis'), get('colors.accent.emphasis'), get('colors.fg.
|
12
|
+
})(["display:inline-block;min-width:32px;padding:5px 10px;font-style:normal;line-height:20px;color:", ";text-align:center;white-space:nowrap;vertical-align:middle;cursor:pointer;user-select:none;text-decoration:none;margin-right:", ";&:last-child{margin-right:0;}border:", " solid transparent;border-radius:", ";transition:border-color 0.2s cubic-bezier(0.3,0,0.5,1);&:hover,&:focus{text-decoration:none;border-color:", ";outline:0;transition-duration:0.1s;}&:active{border-color:", ";}&[rel='prev'],&[rel='next']{color:", ";}&[aria-current],&[aria-current]:hover{color:", ";background-color:", ";border-color:transparent;}&[aria-disabled],&[aria-disabled]:hover{color:", ";cursor:default;border-color:transparent;}@supports (clip-path:polygon(50% 0,100% 50%,50% 100%)){&[rel='prev']::before,&[rel='next']::after{display:inline-block;width:16px;height:16px;vertical-align:text-bottom;content:'';background-color:currentColor;}&[rel='prev']::before{margin-right:", ";clip-path:polygon( 9.8px 12.8px,8.7px 12.8px,4.5px 8.5px,4.5px 7.5px,8.7px 3.2px,9.8px 4.3px,6.1px 8px,9.8px 11.7px,9.8px 12.8px );}&[rel='next']::after{margin-left:", ";clip-path:polygon( 6.2px 3.2px,7.3px 3.2px,11.5px 7.5px,11.5px 8.5px,7.3px 12.8px,6.2px 11.7px,9.9px 8px,6.2px 4.3px,6.2px 3.2px );}}", ";"], get('colors.fg.default'), get('space.1'), get('borderWidths.1'), get('radii.2'), get('colors.border.default'), get('colors.border.muted'), get('colors.accent.fg'), get('colors.fg.onEmphasis'), get('colors.accent.emphasis'), get('colors.primer.fg.disabled'), get('space.1'), get('space.1'), COMMON);
|
13
13
|
|
14
14
|
function usePaginationPages({
|
15
15
|
theme,
|
package/lib-esm/ProgressBar.js
CHANGED
@@ -32,7 +32,17 @@ 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<{
|
35
|
+
} & Pick<Omit<Pick<({
|
36
|
+
[x: string]: any;
|
37
|
+
[x: number]: any;
|
38
|
+
} & {
|
39
|
+
theme?: any;
|
40
|
+
} & ({} | {
|
41
|
+
children?: React.ReactNode;
|
42
|
+
})) & {
|
43
|
+
as?: string | React.ComponentType<any> | undefined;
|
44
|
+
forwardedAs?: string | React.ComponentType<any> | undefined;
|
45
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
36
46
|
className?: string | undefined;
|
37
47
|
icon?: React.ComponentType<{
|
38
48
|
className?: string | undefined;
|
@@ -307,15 +317,7 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
307
317
|
contrast?: boolean | undefined;
|
308
318
|
} & {
|
309
319
|
theme?: any;
|
310
|
-
}, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast"> &
|
311
|
-
[x: string]: any;
|
312
|
-
[x: number]: any;
|
313
|
-
} & {
|
314
|
-
theme?: any;
|
315
|
-
} & {
|
316
|
-
as?: string | React.ComponentType<any> | undefined;
|
317
|
-
forwardedAs?: string | React.ComponentType<any> | undefined;
|
318
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
320
|
+
}, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
319
321
|
Footer: import("styled-components").StyledComponent<"footer", any, SystemCommonProps & SxProp, never>;
|
320
322
|
Item: React.ForwardRefExoticComponent<Pick<{
|
321
323
|
as?: React.ElementType<any> | undefined;
|