@primer/components 0.0.0-202192231947 → 0.0.0-20219254849
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 +10 -6
- 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/useDatePicker.d.ts +17 -2
- package/lib/DatePicker/useDatePicker.js +153 -50
- 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 +9 -4
- 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/useDatePicker.d.ts +17 -2
- package/lib-esm/DatePicker/useDatePicker.js +154 -51
- 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
@@ -7,7 +7,7 @@ exports.DatePickerPanel = void 0;
|
|
7
7
|
|
8
8
|
var _dateFns = require("date-fns");
|
9
9
|
|
10
|
-
var _react =
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
11
11
|
|
12
12
|
var _Box = _interopRequireDefault(require("../Box"));
|
13
13
|
|
@@ -19,24 +19,107 @@ var _constants = require("../constants");
|
|
19
19
|
|
20
20
|
var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
|
21
21
|
|
22
|
+
var _octiconsReact = require("@primer/octicons-react");
|
23
|
+
|
24
|
+
var _StyledOcticon = _interopRequireDefault(require("../StyledOcticon"));
|
25
|
+
|
26
|
+
var _Button = _interopRequireWildcard(require("../Button"));
|
27
|
+
|
22
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
29
|
|
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); }
|
31
|
+
|
32
|
+
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; }
|
33
|
+
|
24
34
|
const DatePickerPanelContainer = (0, _styledComponents.default)(_Box.default).withConfig({
|
25
35
|
displayName: "DatePickerPanel__DatePickerPanelContainer",
|
26
36
|
componentId: "sc-19upxpo-0"
|
27
|
-
})(["align-items:
|
37
|
+
})(["align-items:stretch;display:flex;flex-direction:column;"]);
|
38
|
+
const DatePickerPanelMonths = (0, _styledComponents.default)(_Box.default).withConfig({
|
39
|
+
displayName: "DatePickerPanel__DatePickerPanelMonths",
|
40
|
+
componentId: "sc-19upxpo-1"
|
41
|
+
})(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";position:relative;"], (0, _constants.get)('space.6'), (0, _constants.get)('space.3'));
|
42
|
+
const DatePickerPanelFooter = (0, _styledComponents.default)(_Box.default).withConfig({
|
43
|
+
displayName: "DatePickerPanel__DatePickerPanelFooter",
|
44
|
+
componentId: "sc-19upxpo-2"
|
45
|
+
})(["align-items:flex-start;border-top:1px solid;border-top-color:", ";display:flex;gap:", ";padding-top:12px;padding-bottom:12px;padding-left:", ";padding-right:", ";flex-direction:row;justify-content:space-between;position:relative;"], (0, _constants.get)('colors.border.default'), (0, _constants.get)('space.6'), (0, _constants.get)('space.3'), (0, _constants.get)('space.3'));
|
46
|
+
const ArrowButton = (0, _styledComponents.default)(_Button.default).withConfig({
|
47
|
+
displayName: "DatePickerPanel__ArrowButton",
|
48
|
+
componentId: "sc-19upxpo-3"
|
49
|
+
})(["position:absolute;width:40px;height:28px;top:12px;", ";"], props => `${props.side}: ${(0, _constants.get)('space.3')(props)}`);
|
28
50
|
|
29
51
|
const DatePickerPanel = () => {
|
30
52
|
const {
|
31
|
-
configuration
|
53
|
+
configuration,
|
54
|
+
saveValue,
|
55
|
+
revertValue,
|
56
|
+
currentViewingDate,
|
57
|
+
goToMonth,
|
58
|
+
nextMonth,
|
59
|
+
previousMonth
|
32
60
|
} = (0, _useDatePicker.default)();
|
33
|
-
|
34
|
-
|
35
|
-
|
61
|
+
const previousDisabled = (0, _react.useMemo)(() => {
|
62
|
+
const {
|
63
|
+
minDate
|
64
|
+
} = configuration;
|
65
|
+
if (!minDate) return false;
|
66
|
+
const previous = (0, _dateFns.subMonths)(currentViewingDate, 1);
|
67
|
+
|
68
|
+
if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
|
72
|
+
return false;
|
73
|
+
}, [configuration, currentViewingDate]);
|
74
|
+
const nextDisabled = (0, _react.useMemo)(() => {
|
75
|
+
const {
|
76
|
+
maxDate,
|
77
|
+
view
|
78
|
+
} = configuration;
|
79
|
+
if (!maxDate) return false;
|
80
|
+
const next = (0, _dateFns.addMonths)(currentViewingDate, view === '2-month' ? 2 : 1);
|
81
|
+
|
82
|
+
if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
|
83
|
+
return true;
|
84
|
+
}
|
85
|
+
|
86
|
+
return false;
|
87
|
+
}, [configuration, currentViewingDate]);
|
88
|
+
return /*#__PURE__*/_react.default.createElement(DatePickerPanelContainer, null, /*#__PURE__*/_react.default.createElement(DatePickerPanelMonths, null, /*#__PURE__*/_react.default.createElement(ArrowButton, {
|
89
|
+
variant: "small",
|
90
|
+
side: "left",
|
91
|
+
onClick: previousMonth,
|
92
|
+
disabled: previousDisabled
|
93
|
+
}, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
|
94
|
+
icon: _octiconsReact.ChevronLeftIcon,
|
95
|
+
color: "fg.muted"
|
96
|
+
})), /*#__PURE__*/_react.default.createElement(_Month.Month, {
|
97
|
+
month: currentViewingDate.getMonth(),
|
98
|
+
year: currentViewingDate.getFullYear()
|
36
99
|
}), configuration.view === '2-month' && /*#__PURE__*/_react.default.createElement(_Month.Month, {
|
37
|
-
month: (0, _dateFns.addMonths)(
|
38
|
-
year: (0, _dateFns.addMonths)(
|
39
|
-
})
|
100
|
+
month: (0, _dateFns.addMonths)(currentViewingDate, 1).getMonth(),
|
101
|
+
year: (0, _dateFns.addMonths)(currentViewingDate, 1).getFullYear()
|
102
|
+
}), /*#__PURE__*/_react.default.createElement(ArrowButton, {
|
103
|
+
variant: "small",
|
104
|
+
side: "right",
|
105
|
+
onClick: nextMonth,
|
106
|
+
disabled: nextDisabled
|
107
|
+
}, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
|
108
|
+
icon: _octiconsReact.ChevronRightIcon,
|
109
|
+
color: "fg.muted"
|
110
|
+
}))), /*#__PURE__*/_react.default.createElement(DatePickerPanelFooter, null, /*#__PURE__*/_react.default.createElement(_Box.default, null, /*#__PURE__*/_react.default.createElement(_Button.default, {
|
111
|
+
variant: "small",
|
112
|
+
sx: {
|
113
|
+
mr: 1
|
114
|
+
},
|
115
|
+
onClick: () => revertValue()
|
116
|
+
}, "Reset"), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
117
|
+
variant: "small",
|
118
|
+
onClick: () => goToMonth(new Date())
|
119
|
+
}, "Today")), configuration.confirmation && /*#__PURE__*/_react.default.createElement(_Button.ButtonPrimary, {
|
120
|
+
variant: "small",
|
121
|
+
onClick: () => saveValue()
|
122
|
+
}, "Apply")));
|
40
123
|
};
|
41
124
|
|
42
125
|
exports.DatePickerPanel = DatePickerPanel;
|
package/lib/DatePicker/Day.js
CHANGED
@@ -120,7 +120,7 @@ const DayComponent = (0, _styledComponents.default)(DayBaseComponent).attrs(prop
|
|
120
120
|
})).withConfig({
|
121
121
|
displayName: "Day__DayComponent",
|
122
122
|
componentId: "sc-1japneh-1"
|
123
|
-
})(["background-color:", ";border-radius:", ";transition:0.
|
123
|
+
})(["background-color:", ";border-radius:", ";transition:0.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-self:center;user-select:none;transition:0.1s color ease;}&:hover{background-color:", ";cursor:pointer;transition:0.05s background-color ease;& ", "{color:", ";transition:0.1s color ease;}}&:active{background-color:", ";box-shadow:inset ", ";transition:0.1s background-color ease,0.1s box-shadow ease,0.1s color ease;& ", "{color:", ";transition:0.1s color ease;}}"], props => props.background, props => props.borderRadius, _Text.default, props => props.textColor, (0, _constants.get)('fonts.mono'), (0, _constants.get)('fontSizes.0'), props => props.backgroundHover, _Text.default, props => props.textColorHover, props => props.backgroundPressed, (0, _constants.get)('shadows.shadow.medium'), _Text.default, props => props.textColorPressed);
|
124
124
|
|
125
125
|
const Day = ({
|
126
126
|
date,
|
@@ -158,6 +158,7 @@ const Day = ({
|
|
158
158
|
disabled: disabled,
|
159
159
|
selected: selected,
|
160
160
|
onClick: clickHandler,
|
161
|
+
onMouseEnter: () => onDayFocus(date),
|
161
162
|
onFocus: () => onDayFocus(date),
|
162
163
|
onBlur: () => onDayBlur(date),
|
163
164
|
onKeyPress: keyPressHandler
|
@@ -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,7 +13,7 @@ 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';
|
17
18
|
}
|
18
19
|
export declare type RangeSelection = {
|
@@ -26,13 +27,20 @@ export declare type StringRangeSelection = {
|
|
26
27
|
export interface DatePickerContext {
|
27
28
|
disabled?: boolean;
|
28
29
|
configuration: DatePickerConfiguration;
|
30
|
+
currentViewingDate: Date;
|
31
|
+
goToMonth: (date: Date) => void;
|
32
|
+
hoverRange?: RangeSelection | null;
|
29
33
|
selection?: Selection;
|
30
34
|
softSelection?: Partial<RangeSelection> | null;
|
31
35
|
selectionActive?: boolean;
|
32
36
|
formattedDate: string;
|
37
|
+
nextMonth: () => void;
|
33
38
|
onSelection: (date: Date) => void;
|
34
39
|
onDayFocus: (date: Date) => void;
|
35
40
|
onDayBlur: (date: Date) => void;
|
41
|
+
previousMonth: () => void;
|
42
|
+
revertValue: () => void;
|
43
|
+
saveValue: (selection?: Selection) => void;
|
36
44
|
}
|
37
45
|
export declare type Selection = Date | Array<Date> | RangeSelection | null;
|
38
46
|
export declare type StringSelection = string | Array<string> | {
|
@@ -45,13 +53,20 @@ declare const useDatePicker: (date?: Date | undefined) => {
|
|
45
53
|
disabled: boolean;
|
46
54
|
selected: DaySelection;
|
47
55
|
configuration: DatePickerConfiguration;
|
56
|
+
currentViewingDate: Date;
|
57
|
+
goToMonth: (date: Date) => void;
|
58
|
+
hoverRange?: RangeSelection | null | undefined;
|
48
59
|
selection?: Selection | undefined;
|
49
60
|
softSelection?: Partial<RangeSelection> | null | undefined;
|
50
61
|
selectionActive?: boolean | undefined;
|
51
62
|
formattedDate: string;
|
63
|
+
nextMonth: () => void;
|
52
64
|
onSelection: (date: Date) => void;
|
53
65
|
onDayFocus: (date: Date) => void;
|
54
66
|
onDayBlur: (date: Date) => void;
|
67
|
+
previousMonth: () => void;
|
68
|
+
revertValue: () => void;
|
69
|
+
saveValue: (selection?: Selection | undefined) => void;
|
55
70
|
};
|
56
71
|
export default useDatePicker;
|
57
72
|
export interface DatePickerProviderProps {
|
@@ -60,7 +75,7 @@ export interface DatePickerProviderProps {
|
|
60
75
|
value?: Selection | StringSelection;
|
61
76
|
}
|
62
77
|
export declare function isSingleSelection(selection: Selection): selection is Date;
|
63
|
-
export declare function isMultiSelection(selection: Selection): selection is Array<Date>;
|
78
|
+
export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
|
64
79
|
export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
|
65
80
|
export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
|
66
81
|
export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
|
@@ -25,35 +25,50 @@ const DatePickerContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
25
25
|
|
26
26
|
const useDatePicker = date => {
|
27
27
|
const value = (0, _react.useContext)(DatePickerContext);
|
28
|
+
const [selected, setSelected] = (0, _react.useState)(false);
|
28
29
|
|
29
30
|
if (!value) {
|
30
31
|
throw new Error('useDatePicker must be used inside a DatePickerProvider');
|
31
32
|
}
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
47
|
-
|
34
|
+
(0, _react.useEffect)(() => {
|
35
|
+
if (date) {
|
36
|
+
if (value.hoverRange) {
|
37
|
+
if (isRangeSelection(value.hoverRange)) {
|
38
|
+
if ((0, _dateFns.isEqual)(date, value.hoverRange.from)) {
|
39
|
+
setSelected('start');
|
40
|
+
} else if (value.hoverRange.to && (0, _dateFns.isEqual)(date, value.hoverRange.to)) {
|
41
|
+
setSelected('end');
|
42
|
+
} else if ((0, _dateFns.isAfter)(date, value.hoverRange.from) && value.hoverRange.to && (0, _dateFns.isBefore)(date, value.hoverRange.to)) {
|
43
|
+
setSelected('middle');
|
44
|
+
} else {
|
45
|
+
setSelected(false);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
} else if (value.selection) {
|
49
|
+
if (isMultiSelection(value.selection)) {
|
50
|
+
setSelected(!!value.selection.find(d => (0, _dateFns.isEqual)(d, date)));
|
51
|
+
} else if (isRangeSelection(value.selection)) {
|
52
|
+
if ((0, _dateFns.isEqual)(date, value.selection.from)) {
|
53
|
+
setSelected('start');
|
54
|
+
} else if (value.selection.to && (0, _dateFns.isEqual)(date, value.selection.to)) {
|
55
|
+
setSelected('end');
|
56
|
+
} else if ((0, _dateFns.isAfter)(date, value.selection.from) && value.selection.to && (0, _dateFns.isBefore)(date, value.selection.to)) {
|
57
|
+
setSelected('middle');
|
58
|
+
} else {
|
59
|
+
setSelected(false);
|
60
|
+
}
|
48
61
|
} else {
|
49
|
-
|
62
|
+
setSelected((0, _dateFns.isEqual)(date, value.selection));
|
50
63
|
}
|
51
|
-
} else {
|
52
|
-
selected = (0, _dateFns.isEqual)(date, value.selection);
|
53
64
|
}
|
54
|
-
}
|
55
|
-
|
65
|
+
}
|
66
|
+
}, [date, value.hoverRange, value.selection]);
|
67
|
+
let blocked,
|
68
|
+
disabled = false;
|
56
69
|
|
70
|
+
if (date) {
|
71
|
+
// Determine if date is blocked out
|
57
72
|
if (value.configuration.blockedDates) {
|
58
73
|
blocked = !!value.configuration.blockedDates.find(d => (0, _dateFns.isEqual)(d, date));
|
59
74
|
} // Determine if date is disabled
|
@@ -79,7 +94,7 @@ function isSingleSelection(selection) {
|
|
79
94
|
}
|
80
95
|
|
81
96
|
function isMultiSelection(selection) {
|
82
|
-
return Array.isArray(selection)
|
97
|
+
return Array.isArray(selection);
|
83
98
|
}
|
84
99
|
|
85
100
|
function isRangeSelection(selection) {
|
@@ -90,24 +105,57 @@ function isStringRangeSelection(selection) {
|
|
90
105
|
return !!selection.from;
|
91
106
|
}
|
92
107
|
|
93
|
-
function parseSelection(selection) {
|
108
|
+
function parseSelection(selection, variant) {
|
94
109
|
if (!selection) return;
|
95
110
|
|
96
|
-
if (
|
97
|
-
|
111
|
+
if (variant === 'multi') {
|
112
|
+
if (isMultiSelection(selection)) {
|
113
|
+
const parsedSelection = [];
|
98
114
|
|
99
|
-
|
100
|
-
|
101
|
-
|
115
|
+
for (const d of selection) {
|
116
|
+
parsedSelection.push(new Date(new Date(d).toDateString()));
|
117
|
+
}
|
102
118
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
119
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
120
|
+
} else if (selection instanceof Date) {
|
121
|
+
return [new Date(new Date(selection).toDateString())];
|
122
|
+
} else if (isRangeSelection(selection)) {
|
123
|
+
const parsedSelection = [];
|
124
|
+
parsedSelection.push(new Date(new Date(selection.from).toDateString()));
|
125
|
+
|
126
|
+
if (selection.to) {
|
127
|
+
parsedSelection.push(new Date(new Date(selection.to).toDateString()));
|
128
|
+
}
|
129
|
+
|
130
|
+
return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
|
131
|
+
}
|
132
|
+
} else if (variant === 'range') {
|
133
|
+
if (isRangeSelection(selection)) {
|
134
|
+
return {
|
135
|
+
from: new Date(new Date(selection.from).toDateString()),
|
136
|
+
to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
|
137
|
+
};
|
138
|
+
} else if (isMultiSelection(selection)) {
|
139
|
+
return {
|
140
|
+
from: new Date(new Date(selection[0]).toDateString()),
|
141
|
+
to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
|
142
|
+
};
|
143
|
+
} else if (selection instanceof Date) {
|
144
|
+
return {
|
145
|
+
from: new Date(new Date(selection).toDateString()),
|
146
|
+
to: null
|
147
|
+
};
|
148
|
+
}
|
109
149
|
} else {
|
110
|
-
|
150
|
+
if (selection instanceof Date) {
|
151
|
+
return new Date(new Date(selection).toDateString());
|
152
|
+
} else if (isMultiSelection(selection)) {
|
153
|
+
return new Date(new Date(selection[0]).toDateString());
|
154
|
+
} else if (isRangeSelection(selection)) {
|
155
|
+
return new Date(new Date(selection.from).toDateString());
|
156
|
+
} else {
|
157
|
+
return;
|
158
|
+
}
|
111
159
|
}
|
112
160
|
}
|
113
161
|
|
@@ -128,11 +176,24 @@ const DatePickerProvider = ({
|
|
128
176
|
value
|
129
177
|
}) => {
|
130
178
|
const [configuration, setConfiguration] = (0, _react.useState)((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
131
|
-
const [
|
179
|
+
const [previousSelection, setPreviousSelection] = (0, _react.useState)(parseSelection(value, configuration.selection));
|
180
|
+
const [selection, setSelection] = (0, _react.useState)(parseSelection(value, configuration.selection));
|
132
181
|
const [hoverRange, setHoverRange] = (0, _react.useState)(null);
|
182
|
+
const [currentViewingDate, setCurrentViewingDate] = (0, _react.useState)(new Date());
|
133
183
|
(0, _react.useEffect)(() => {
|
134
184
|
setConfiguration((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
135
|
-
|
185
|
+
setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
|
186
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
187
|
+
}, [configuration.selection, externalConfig]);
|
188
|
+
const goToMonth = (0, _react.useCallback)(date => {
|
189
|
+
setCurrentViewingDate(new Date(new Date(date).toDateString()));
|
190
|
+
}, []);
|
191
|
+
const nextMonth = (0, _react.useCallback)(() => {
|
192
|
+
setCurrentViewingDate((0, _dateFns.addMonths)(currentViewingDate, 1));
|
193
|
+
}, [currentViewingDate]);
|
194
|
+
const previousMonth = (0, _react.useCallback)(() => {
|
195
|
+
setCurrentViewingDate((0, _dateFns.subMonths)(currentViewingDate, 1));
|
196
|
+
}, [currentViewingDate]);
|
136
197
|
const getFormattedDate = (0, _react.useMemo)(() => {
|
137
198
|
if (!selection) {
|
138
199
|
return configuration.placeholder;
|
@@ -161,6 +222,10 @@ const DatePickerProvider = ({
|
|
161
222
|
{
|
162
223
|
if (selection instanceof Date) {
|
163
224
|
return (0, _dateFns.format)(selection, template);
|
225
|
+
} else if (Array.isArray(selection)) {
|
226
|
+
return (0, _dateFns.format)(selection[0], template);
|
227
|
+
} else if (isRangeSelection(selection)) {
|
228
|
+
return (0, _dateFns.format)(selection.from, template);
|
164
229
|
} else {
|
165
230
|
return 'Invalid Selection';
|
166
231
|
}
|
@@ -169,7 +234,13 @@ const DatePickerProvider = ({
|
|
169
234
|
case 'multi':
|
170
235
|
{
|
171
236
|
if (Array.isArray(selection)) {
|
172
|
-
|
237
|
+
if (selection.length > 3) return `${selection.length} Selected`;
|
238
|
+
const formatted = selection.map(d => (0, _dateFns.format)(d, template)).join(', ');
|
239
|
+
return formatted;
|
240
|
+
} else if (selection instanceof Date) {
|
241
|
+
return [selection].map(d => (0, _dateFns.format)(d, template)).join(', ');
|
242
|
+
} else if (isRangeSelection(selection)) {
|
243
|
+
return [selection.to, selection.from].map(d => d ? (0, _dateFns.format)(d, template) : '').join(', ');
|
173
244
|
} else {
|
174
245
|
return 'Invalid Selection';
|
175
246
|
}
|
@@ -179,6 +250,18 @@ const DatePickerProvider = ({
|
|
179
250
|
{
|
180
251
|
if (isRangeSelection(selection)) {
|
181
252
|
return Object.entries(selection).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
253
|
+
} else if (selection instanceof Date) {
|
254
|
+
return Object.entries({
|
255
|
+
from: selection,
|
256
|
+
to: null
|
257
|
+
}).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
258
|
+
} else if (Array.isArray(selection)) {
|
259
|
+
return Object.entries({
|
260
|
+
from: selection[0],
|
261
|
+
to: selection[1]
|
262
|
+
}) // to date can still be null
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
264
|
+
.map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
182
265
|
} else {
|
183
266
|
return 'Invalid Selection';
|
184
267
|
}
|
@@ -190,30 +273,41 @@ const DatePickerProvider = ({
|
|
190
273
|
}
|
191
274
|
}
|
192
275
|
}, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
|
276
|
+
const saveValue = (0, _react.useCallback)(updatedSelection => {
|
277
|
+
setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
|
278
|
+
closePicker === null || closePicker === void 0 ? void 0 : closePicker();
|
279
|
+
}, [closePicker, selection]);
|
193
280
|
const selectionHandler = (0, _react.useCallback)(date => {
|
194
281
|
if (configuration.selection === 'multi') {
|
195
|
-
const selections = selection;
|
282
|
+
const selections = [...selection];
|
196
283
|
const existingIndex = selections.findIndex(s => (0, _dateFns.isEqual)(s, date));
|
197
284
|
|
198
285
|
if (existingIndex > -1) {
|
199
|
-
|
286
|
+
selections.splice(existingIndex, 1);
|
287
|
+
setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
|
200
288
|
} else {
|
201
|
-
setSelection([...selections, date]);
|
289
|
+
setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
|
202
290
|
}
|
203
291
|
} else if (configuration.selection === 'range') {
|
204
292
|
if (selection && isRangeSelection(selection) && !selection.to) {
|
205
|
-
|
293
|
+
const updatedSelection = (0, _dateFns.isBefore)(date, selection.from) ? {
|
206
294
|
from: date,
|
207
295
|
to: selection.from
|
208
296
|
} : {
|
209
297
|
from: selection.from,
|
210
298
|
to: date
|
211
|
-
}
|
299
|
+
};
|
300
|
+
setSelection(updatedSelection);
|
301
|
+
setHoverRange(null);
|
212
302
|
|
213
303
|
if (!configuration.confirmation) {
|
214
|
-
|
304
|
+
saveValue(updatedSelection);
|
215
305
|
}
|
216
306
|
} else {
|
307
|
+
setHoverRange({
|
308
|
+
from: date,
|
309
|
+
to: date
|
310
|
+
});
|
217
311
|
setSelection({
|
218
312
|
from: date,
|
219
313
|
to: null
|
@@ -223,14 +317,14 @@ const DatePickerProvider = ({
|
|
223
317
|
setSelection(date);
|
224
318
|
|
225
319
|
if (!configuration.confirmation) {
|
226
|
-
|
320
|
+
saveValue(date);
|
227
321
|
}
|
228
322
|
}
|
229
|
-
}, [
|
323
|
+
}, [configuration.confirmation, configuration.selection, saveValue, selection]);
|
230
324
|
const focusHnadler = (0, _react.useCallback)(date => {
|
231
325
|
if (!selection) return;
|
232
326
|
|
233
|
-
if (configuration.selection === 'range' && isRangeSelection(selection)) {
|
327
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
|
234
328
|
setHoverRange((0, _dateFns.isBefore)(date, selection.from) ? {
|
235
329
|
from: date,
|
236
330
|
to: selection.from
|
@@ -239,26 +333,35 @@ const DatePickerProvider = ({
|
|
239
333
|
to: date
|
240
334
|
});
|
241
335
|
}
|
242
|
-
}, [configuration.selection, selection]);
|
336
|
+
}, [configuration.selection, hoverRange, selection]);
|
243
337
|
const blurHnadler = (0, _react.useCallback)(date => {
|
244
338
|
if (!selection || !hoverRange) return;
|
245
339
|
|
246
|
-
if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
|
247
|
-
setHoverRange(null);
|
340
|
+
if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
|
248
341
|
}
|
249
342
|
}, [configuration.selection, hoverRange, selection]);
|
343
|
+
const revertValue = (0, _react.useCallback)(() => {
|
344
|
+
setSelection(previousSelection);
|
345
|
+
}, [previousSelection]);
|
250
346
|
const datePickerCtx = (0, _react.useMemo)(() => {
|
251
347
|
return {
|
252
348
|
configuration,
|
349
|
+
currentViewingDate,
|
253
350
|
disabled: false,
|
254
351
|
formattedDate: getFormattedDate,
|
352
|
+
goToMonth,
|
353
|
+
hoverRange,
|
354
|
+
nextMonth,
|
255
355
|
onDayBlur: blurHnadler,
|
256
356
|
onDayFocus: focusHnadler,
|
257
357
|
onSelection: selectionHandler,
|
358
|
+
previousMonth,
|
359
|
+
revertValue,
|
360
|
+
saveValue,
|
258
361
|
selectionActive: false,
|
259
362
|
selection
|
260
363
|
};
|
261
|
-
}, [blurHnadler, configuration, focusHnadler, getFormattedDate, selection, selectionHandler]);
|
364
|
+
}, [blurHnadler, configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, hoverRange, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
|
262
365
|
return /*#__PURE__*/_react.default.createElement(DatePickerContext.Provider, {
|
263
366
|
value: datePickerCtx
|
264
367
|
}, children);
|
package/lib/Dialog.js
CHANGED
@@ -122,7 +122,7 @@ const Dialog = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
122
122
|
}), children)) : null;
|
123
123
|
});
|
124
124
|
DialogHeader.defaultProps = {
|
125
|
-
backgroundColor: '
|
125
|
+
backgroundColor: 'canvas.subtle'
|
126
126
|
};
|
127
127
|
DialogHeader.propTypes = { ..._Box.default.propTypes
|
128
128
|
};
|
@@ -7,6 +7,8 @@ exports.FilteredActionList = FilteredActionList;
|
|
7
7
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
9
9
|
|
10
|
+
var _ssr = require("@react-aria/ssr");
|
11
|
+
|
10
12
|
var _TextInput = _interopRequireDefault(require("../TextInput"));
|
11
13
|
|
12
14
|
var _Box = _interopRequireDefault(require("../Box"));
|
@@ -27,7 +29,7 @@ var _useProvidedRefOrCreate = require("../hooks/useProvidedRefOrCreate");
|
|
27
29
|
|
28
30
|
var _useScrollFlash = _interopRequireDefault(require("../hooks/useScrollFlash"));
|
29
31
|
|
30
|
-
var
|
32
|
+
var _scrollIntoViewingArea = require("../behaviors/scrollIntoViewingArea");
|
31
33
|
|
32
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
35
|
|
@@ -37,34 +39,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
37
39
|
|
38
40
|
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); }
|
39
41
|
|
40
|
-
function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
|
41
|
-
const {
|
42
|
-
top: childTop,
|
43
|
-
bottom: childBottom
|
44
|
-
} = child.getBoundingClientRect();
|
45
|
-
const {
|
46
|
-
top: containerTop,
|
47
|
-
bottom: containerBottom
|
48
|
-
} = container.getBoundingClientRect();
|
49
|
-
const isChildTopAboveViewingArea = childTop < containerTop + margin;
|
50
|
-
const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
|
51
|
-
|
52
|
-
if (isChildTopAboveViewingArea) {
|
53
|
-
const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
|
54
|
-
container.scrollTo({
|
55
|
-
behavior,
|
56
|
-
top: scrollHeightToChildTop - margin
|
57
|
-
});
|
58
|
-
} else if (isChildBottomBelowViewingArea) {
|
59
|
-
const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
|
60
|
-
container.scrollTo({
|
61
|
-
behavior,
|
62
|
-
top: scrollHeightToChildBottom + margin
|
63
|
-
});
|
64
|
-
} // either completely in view or outside viewing area on both ends, don't scroll
|
65
|
-
|
66
|
-
}
|
67
|
-
|
68
42
|
const StyledHeader = _styledComponents.default.div.withConfig({
|
69
43
|
displayName: "FilteredActionList__StyledHeader",
|
70
44
|
componentId: "yg3jkv-0"
|
@@ -112,7 +86,7 @@ function FilteredActionList({
|
|
112
86
|
activeDescendantRef.current = current;
|
113
87
|
|
114
88
|
if (current && scrollContainerRef.current && directlyActivated) {
|
115
|
-
scrollIntoViewingArea(current, scrollContainerRef.current);
|
89
|
+
(0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, scrollContainerRef.current);
|
116
90
|
}
|
117
91
|
}
|
118
92
|
}, [// List ref isn't set while loading. Need to re-bind focus zone when it changes
|
@@ -120,7 +94,7 @@ function FilteredActionList({
|
|
120
94
|
(0, _react.useEffect)(() => {
|
121
95
|
// if items changed, we want to instantly move active descendant into view
|
122
96
|
if (activeDescendantRef.current && scrollContainerRef.current) {
|
123
|
-
scrollIntoViewingArea(activeDescendantRef.current, scrollContainerRef.current, undefined, 'auto');
|
97
|
+
(0, _scrollIntoViewingArea.scrollIntoViewingArea)(activeDescendantRef.current, scrollContainerRef.current, 'vertical', undefined, undefined, 'auto');
|
124
98
|
}
|
125
99
|
}, [items]);
|
126
100
|
(0, _useScrollFlash.default)(scrollContainerRef);
|