@primer/components 0.0.0-202110343939 → 0.0.0-20211040245
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 +25 -1
- package/dist/browser.esm.js +52 -48
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +37 -33
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Header.js +1 -1
- package/lib/ActionList/Item.d.ts +6 -0
- package/lib/ActionList/Item.js +5 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.js +8 -6
- package/lib/Autocomplete/Autocomplete.d.ts +4 -4
- package/lib/Autocomplete/AutocompleteInput.d.ts +4 -4
- package/lib/Button/Button.d.ts +5 -5
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +3 -3
- package/lib/Button/ButtonDanger.d.ts +5 -5
- package/lib/Button/ButtonInvisible.d.ts +5 -5
- package/lib/Button/ButtonOutline.d.ts +5 -5
- package/lib/Button/ButtonPrimary.d.ts +5 -5
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +4 -4
- package/lib/DatePicker/DatePicker.d.ts +5 -1
- package/lib/DatePicker/DatePicker.js +1 -1
- package/lib/DatePicker/DatePickerOverlay.js +5 -3
- package/lib/DatePicker/DatePickerPanel.js +134 -3
- package/lib/DatePicker/Day.js +17 -8
- package/lib/DatePicker/useDatePicker.js +24 -151
- package/lib/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +16 -16
- package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib/FilterList.d.ts +3 -3
- package/lib/Flash.d.ts +1 -1
- package/lib/Label.d.ts +1 -1
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +8 -4
- package/lib/TextInputWithTokens.js +102 -29
- package/lib/Timeline.d.ts +4 -4
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/Token/Token.js +13 -2
- package/lib/Token/TokenBase.js +0 -4
- package/lib/Token/_RemoveTokenButton.js +15 -2
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/_TextInputWrapper.js +1 -1
- package/lib/sx.d.ts +8 -2
- package/lib/theme.d.ts +78 -0
- package/lib/theme.js +3 -1
- package/lib/utils/types/KeyPaths.d.ts +3 -0
- package/lib/utils/types/KeyPaths.js +1 -0
- package/lib-esm/ActionList/Header.js +1 -1
- package/lib-esm/ActionList/Item.d.ts +6 -0
- package/lib-esm/ActionList/Item.js +5 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +7 -6
- package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -4
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -4
- package/lib-esm/Button/Button.d.ts +5 -5
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +3 -3
- package/lib-esm/Button/ButtonDanger.d.ts +5 -5
- package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
- package/lib-esm/Button/ButtonOutline.d.ts +5 -5
- package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +4 -4
- package/lib-esm/DatePicker/DatePicker.d.ts +5 -1
- package/lib-esm/DatePicker/DatePicker.js +1 -1
- package/lib-esm/DatePicker/DatePickerOverlay.js +5 -3
- package/lib-esm/DatePicker/DatePickerPanel.js +135 -4
- package/lib-esm/DatePicker/Day.js +17 -9
- package/lib-esm/DatePicker/useDatePicker.js +25 -152
- package/lib-esm/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +16 -16
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib-esm/FilterList.d.ts +3 -3
- package/lib-esm/Flash.d.ts +1 -1
- package/lib-esm/Label.d.ts +1 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +8 -4
- package/lib-esm/TextInputWithTokens.js +101 -30
- package/lib-esm/Timeline.d.ts +4 -4
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/Token/Token.js +13 -2
- package/lib-esm/Token/TokenBase.js +0 -4
- package/lib-esm/Token/_RemoveTokenButton.js +11 -2
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.js +1 -1
- package/lib-esm/sx.d.ts +8 -2
- package/lib-esm/theme.d.ts +78 -0
- package/lib-esm/theme.js +2 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
- package/lib-esm/utils/types/KeyPaths.js +1 -0
- package/package.json +8 -6
@@ -17,7 +17,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
17
17
|
|
18
18
|
var _constants = require("../constants");
|
19
19
|
|
20
|
-
var _useDatePicker =
|
20
|
+
var _useDatePicker = _interopRequireWildcard(require("./useDatePicker"));
|
21
21
|
|
22
22
|
var _octiconsReact = require("@primer/octicons-react");
|
23
23
|
|
@@ -77,6 +77,8 @@ const DatePickerPanel = () => {
|
|
77
77
|
goToMonth,
|
78
78
|
nextMonth,
|
79
79
|
previousMonth,
|
80
|
+
onDayFocus,
|
81
|
+
setFocusDate,
|
80
82
|
viewMode
|
81
83
|
} = (0, _useDatePicker.default)();
|
82
84
|
const panelRef = (0, _react.useRef)(null);
|
@@ -88,6 +90,136 @@ const DatePickerPanel = () => {
|
|
88
90
|
bindKeys: _focusZone.FocusKeys.Tab,
|
89
91
|
focusInStrategy: 'closest'
|
90
92
|
});
|
93
|
+
const getNextFocusable = (0, _react.useCallback)((direction, from, event) => {
|
94
|
+
var _datePanelRef$current, _datePanelRef$current2;
|
95
|
+
|
96
|
+
const key = event.key;
|
97
|
+
const {
|
98
|
+
disableWeekends,
|
99
|
+
minDate,
|
100
|
+
maxDate
|
101
|
+
} = configuration;
|
102
|
+
const fromDate = from === null || from === void 0 ? void 0 : from.getAttribute('data-date');
|
103
|
+
const focusDate = fromDate ? new Date(fromDate) : new Date();
|
104
|
+
let newDate = (0, _useDatePicker.normalizeDate)(focusDate);
|
105
|
+
|
106
|
+
switch (key) {
|
107
|
+
case 'ArrowRight':
|
108
|
+
{
|
109
|
+
// Increase selection by 1 day
|
110
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.addDays)(focusDate, 1));
|
111
|
+
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
112
|
+
|
113
|
+
if (disableWeekends && (0, _dateFns.isWeekend)(newDate)) {
|
114
|
+
const monday = (0, _dateFns.nextMonday)(newDate);
|
115
|
+
newDate = maxDate && (0, _dateFns.isAfter)(monday, maxDate) ? maxDate : monday;
|
116
|
+
}
|
117
|
+
|
118
|
+
setFocusDate(newDate);
|
119
|
+
onDayFocus(newDate);
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
|
123
|
+
case 'ArrowLeft':
|
124
|
+
{
|
125
|
+
// Decrease selection by 1 day
|
126
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.subDays)(focusDate, 1));
|
127
|
+
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
128
|
+
|
129
|
+
if (disableWeekends && (0, _dateFns.isWeekend)(newDate)) {
|
130
|
+
const friday = (0, _dateFns.previousFriday)(newDate);
|
131
|
+
newDate = minDate && (0, _dateFns.isBefore)(friday, minDate) ? minDate : friday;
|
132
|
+
}
|
133
|
+
|
134
|
+
setFocusDate(newDate);
|
135
|
+
onDayFocus(newDate);
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
|
139
|
+
case 'ArrowUp':
|
140
|
+
{
|
141
|
+
// Decrease selection by 1 week
|
142
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.subWeeks)(focusDate, 1));
|
143
|
+
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
144
|
+
setFocusDate(newDate);
|
145
|
+
onDayFocus(newDate);
|
146
|
+
break;
|
147
|
+
}
|
148
|
+
|
149
|
+
case 'ArrowDown':
|
150
|
+
{
|
151
|
+
// Increase selection by 1 week
|
152
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.addWeeks)(focusDate, 1));
|
153
|
+
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
154
|
+
setFocusDate(newDate);
|
155
|
+
onDayFocus(newDate);
|
156
|
+
break;
|
157
|
+
}
|
158
|
+
|
159
|
+
case 'Home':
|
160
|
+
{
|
161
|
+
newDate = focusDate;
|
162
|
+
|
163
|
+
if (disableWeekends) {
|
164
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.isMonday)(focusDate) ? focusDate : (0, _dateFns.previousMonday)(focusDate));
|
165
|
+
} else {
|
166
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.isSunday)(focusDate) ? focusDate : (0, _dateFns.previousSunday)(focusDate));
|
167
|
+
}
|
168
|
+
|
169
|
+
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
170
|
+
setFocusDate(newDate);
|
171
|
+
onDayFocus(newDate);
|
172
|
+
break;
|
173
|
+
}
|
174
|
+
|
175
|
+
case 'End':
|
176
|
+
{
|
177
|
+
newDate = focusDate;
|
178
|
+
|
179
|
+
if (disableWeekends) {
|
180
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.isFriday)(focusDate) ? focusDate : (0, _dateFns.nextFriday)(focusDate));
|
181
|
+
} else {
|
182
|
+
newDate = (0, _useDatePicker.normalizeDate)((0, _dateFns.isSaturday)(focusDate) ? focusDate : (0, _dateFns.nextSaturday)(focusDate));
|
183
|
+
}
|
184
|
+
|
185
|
+
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
186
|
+
setFocusDate(newDate);
|
187
|
+
onDayFocus(newDate);
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
|
191
|
+
case 'PageUp':
|
192
|
+
{
|
193
|
+
newDate = (0, _useDatePicker.normalizeDate)(event.shiftKey ? (0, _dateFns.subYears)(focusDate, 1) : (0, _dateFns.subMonths)(focusDate, 1));
|
194
|
+
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
195
|
+
setFocusDate(newDate);
|
196
|
+
onDayFocus(newDate);
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
|
200
|
+
case 'PageDown':
|
201
|
+
{
|
202
|
+
newDate = (0, _useDatePicker.normalizeDate)(event.shiftKey ? (0, _dateFns.addYears)(focusDate, 1) : (0, _dateFns.addMonths)(focusDate, 1));
|
203
|
+
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
204
|
+
setFocusDate(newDate);
|
205
|
+
onDayFocus(newDate);
|
206
|
+
break;
|
207
|
+
}
|
208
|
+
|
209
|
+
default:
|
210
|
+
{
|
211
|
+
break;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
return (_datePanelRef$current = (_datePanelRef$current2 = datePanelRef.current) === null || _datePanelRef$current2 === void 0 ? void 0 : _datePanelRef$current2.querySelector(`[data-date="${(0, _dateFns.format)(newDate, 'MM/dd/yyyy')}"]`)) !== null && _datePanelRef$current !== void 0 ? _datePanelRef$current : undefined;
|
216
|
+
}, [configuration, onDayFocus, setFocusDate]);
|
217
|
+
(0, _useFocusZone.useFocusZone)({
|
218
|
+
containerRef: datePanelRef,
|
219
|
+
bindKeys: _focusZone.FocusKeys.ArrowAll | _focusZone.FocusKeys.HomeAndEnd | _focusZone.FocusKeys.PageUpDown,
|
220
|
+
focusInStrategy: 'previous',
|
221
|
+
getNextFocusable
|
222
|
+
}, [getNextFocusable]);
|
91
223
|
(0, _useFocusZone.useFocusZone)({
|
92
224
|
containerRef: footerRef,
|
93
225
|
bindKeys: _focusZone.FocusKeys.Tab,
|
@@ -199,8 +331,7 @@ const DatePickerPanel = () => {
|
|
199
331
|
icon: _octiconsReact.ChevronRightIcon,
|
200
332
|
color: "fg.muted"
|
201
333
|
}))), /*#__PURE__*/_react.default.createElement(DatePickerPanelMonths, {
|
202
|
-
ref: datePanelRef
|
203
|
-
tabIndex: 0
|
334
|
+
ref: datePanelRef
|
204
335
|
}, /*#__PURE__*/_react.default.createElement(_Month.Month, {
|
205
336
|
date: currentViewingDate
|
206
337
|
}), viewMode === '2-month' && /*#__PURE__*/_react.default.createElement(_Month.Month, {
|
package/lib/DatePicker/Day.js
CHANGED
@@ -17,6 +17,8 @@ var _constants = require("../constants");
|
|
17
17
|
|
18
18
|
var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
|
19
19
|
|
20
|
+
var _dateFns = require("date-fns");
|
21
|
+
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
23
|
|
22
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -90,7 +92,6 @@ const getStateStyles = (props, prop, state) => {
|
|
90
92
|
const {
|
91
93
|
blocked,
|
92
94
|
disabled,
|
93
|
-
focused,
|
94
95
|
selected,
|
95
96
|
today
|
96
97
|
} = props;
|
@@ -113,8 +114,6 @@ const getStateStyles = (props, prop, state) => {
|
|
113
114
|
return states.blocked[prop];
|
114
115
|
} else if (disabled) {
|
115
116
|
return states.disabled[prop];
|
116
|
-
} else if (focused) {
|
117
|
-
return states.default.hover[prop];
|
118
117
|
} else {
|
119
118
|
return today && prop === 'color' ? states.default[state]['todayColor'] : states.default[state][prop];
|
120
119
|
}
|
@@ -131,7 +130,7 @@ const DayComponent = (0, _styledComponents.default)(DayBaseComponent).attrs(prop
|
|
131
130
|
})).withConfig({
|
132
131
|
displayName: "Day__DayComponent",
|
133
132
|
componentId: "sc-1japneh-1"
|
134
|
-
})(["background-color:", ";border-radius:", ";opacity:", ";transition:0.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-content:center;justify-self:center;
|
133
|
+
})(["background-color:", ";border-radius:", ";opacity:", ";transition:0.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-content:center;justify-self:center;padding:4px 0;position:relative;transition:0.1s color ease;user-select:none;width:16px;&:after{content:'';display:", ";position:absolute;bottom:0;background:", ";width:100%;height:2px;border-radius:1px;}}&:hover,&:focus{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, props => props.disabled ? 0.5 : 1, _Text.default, props => props.textColor, (0, _constants.get)('fonts.mono'), (0, _constants.get)('fontSizes.0'), props => props.today ? 'block' : 'none', props => props.selected && props.selected !== 'middle' ? (0, _constants.get)('colors.fg.onEmphasis')(props) : (0, _constants.get)('colors.accent.emphasis')(props), props => props.backgroundHover, _Text.default, props => props.textColorHover, props => props.backgroundPressed, (0, _constants.get)('shadows.shadow.medium'), _Text.default, props => props.textColorPressed);
|
135
134
|
|
136
135
|
const Day = ({
|
137
136
|
date,
|
@@ -146,6 +145,16 @@ const Day = ({
|
|
146
145
|
selected,
|
147
146
|
today
|
148
147
|
} = (0, _useDatePicker.default)(date);
|
148
|
+
const dayRef = (0, _react.useRef)(null);
|
149
|
+
(0, _react.useEffect)(() => {
|
150
|
+
if (focused) {
|
151
|
+
setTimeout(() => {
|
152
|
+
var _dayRef$current;
|
153
|
+
|
154
|
+
return (_dayRef$current = dayRef.current) === null || _dayRef$current === void 0 ? void 0 : _dayRef$current.focus();
|
155
|
+
}, 0);
|
156
|
+
}
|
157
|
+
}, [focused]);
|
149
158
|
const keyPressHandler = (0, _react.useCallback)(event => {
|
150
159
|
if (disabled) {
|
151
160
|
return;
|
@@ -165,12 +174,10 @@ const Day = ({
|
|
165
174
|
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
166
175
|
}, [disabled, onSelection, date, onAction]);
|
167
176
|
const todayStyles = (0, _react.useMemo)(() => today ? {
|
168
|
-
border: '2px solid',
|
169
|
-
padding: '4px 6px',
|
170
|
-
borderRadius: '16px',
|
171
177
|
fontWeight: 'bold'
|
172
178
|
} : {}, [today]);
|
173
179
|
return /*#__PURE__*/_react.default.createElement(DayComponent, {
|
180
|
+
ref: dayRef,
|
174
181
|
role: "gridcell",
|
175
182
|
"aria-disabled": disabled,
|
176
183
|
"aria-selected": selected !== false,
|
@@ -182,7 +189,9 @@ const Day = ({
|
|
182
189
|
onClick: clickHandler,
|
183
190
|
onMouseEnter: () => onDayFocus(date),
|
184
191
|
onFocus: () => onDayFocus(date),
|
185
|
-
onKeyPress: keyPressHandler
|
192
|
+
onKeyPress: keyPressHandler,
|
193
|
+
tabIndex: -1,
|
194
|
+
"data-date": (0, _dateFns.format)(date, 'MM/dd/yyyy')
|
186
195
|
}, /*#__PURE__*/_react.default.createElement(_Text.default, {
|
187
196
|
sx: todayStyles
|
188
197
|
}, date.getDate()));
|
@@ -214,7 +214,6 @@ const DatePickerProvider = ({
|
|
214
214
|
configuration: externalConfig = {},
|
215
215
|
children,
|
216
216
|
closePicker,
|
217
|
-
isOpen = false,
|
218
217
|
value
|
219
218
|
}) => {
|
220
219
|
const [configuration, setConfiguration] = (0, _react.useState)((0, _deepmerge.default)(defaultConfiguration, externalConfig));
|
@@ -398,15 +397,35 @@ const DatePickerProvider = ({
|
|
398
397
|
}
|
399
398
|
}, [configuration]);
|
400
399
|
(0, _react.useEffect)(() => {
|
401
|
-
if (
|
402
|
-
|
400
|
+
if (configuration.view === '1-month') {
|
401
|
+
if (currentViewingDate.getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear()) {
|
402
|
+
return;
|
403
|
+
} else {
|
404
|
+
setCurrentViewingDate((0, _dateFns.setDate)(focusDate, 1));
|
405
|
+
return;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
/**
|
409
|
+
* This logic is rough, so buckle up.
|
410
|
+
* We want to set the currently shown months based on what has focus. If the focus leaves what we're able to view,
|
411
|
+
* we want to be able to change the currently shown month. However, this gets complicated with the 2-month view.
|
412
|
+
* FIRST: If it's the same month/year: Easy
|
413
|
+
* SECOND: If it's the next month, but same year: Done
|
414
|
+
* THIRD: If it's the next month AND next year, but it's January (i.e. we're viewing Dec/Jan): Good to go
|
415
|
+
*/
|
416
|
+
|
417
|
+
|
418
|
+
if (currentViewingDate.getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear() || (0, _dateFns.addMonths)(currentViewingDate, 1).getMonth() === focusDate.getMonth() && currentViewingDate.getFullYear() === focusDate.getFullYear() || (0, _dateFns.addMonths)(currentViewingDate, 1).getMonth() === focusDate.getMonth() && focusDate.getMonth() === 0 && (0, _dateFns.addYears)(currentViewingDate, 1).getFullYear() === focusDate.getFullYear()) {
|
419
|
+
return;
|
420
|
+
} else {
|
421
|
+
setCurrentViewingDate((0, _dateFns.setDate)(focusDate, 1));
|
403
422
|
}
|
404
|
-
}, [currentViewingDate, focusDate]);
|
423
|
+
}, [configuration.view, currentViewingDate, focusDate]);
|
405
424
|
const selectionHandler = (0, _react.useCallback)(date => {
|
406
425
|
setIsDirty(true);
|
407
426
|
|
408
427
|
if (configuration.variant === 'multi') {
|
409
|
-
const selections = [
|
428
|
+
const selections = Array.isArray(selection) ? selection : [];
|
410
429
|
const existingIndex = selections.findIndex(s => (0, _dateFns.isEqual)(s, date));
|
411
430
|
|
412
431
|
if (existingIndex > -1) {
|
@@ -492,152 +511,6 @@ const DatePickerProvider = ({
|
|
492
511
|
});
|
493
512
|
}
|
494
513
|
}, [configuration, hoverRange, selection]);
|
495
|
-
const handleKeyDown = (0, _react.useCallback)(async e => {
|
496
|
-
const key = e.key;
|
497
|
-
const {
|
498
|
-
disableWeekends,
|
499
|
-
minDate,
|
500
|
-
maxDate
|
501
|
-
} = configuration;
|
502
|
-
|
503
|
-
switch (key) {
|
504
|
-
case 'ArrowRight':
|
505
|
-
{
|
506
|
-
// Increase selection by 1 day
|
507
|
-
let newDate = normalizeDate((0, _dateFns.addDays)(focusDate, 1));
|
508
|
-
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
509
|
-
|
510
|
-
if (disableWeekends && (0, _dateFns.isWeekend)(newDate)) {
|
511
|
-
const monday = (0, _dateFns.nextMonday)(newDate);
|
512
|
-
newDate = maxDate && (0, _dateFns.isAfter)(monday, maxDate) ? maxDate : monday;
|
513
|
-
}
|
514
|
-
|
515
|
-
setFocusDate(newDate);
|
516
|
-
focusHandler(newDate);
|
517
|
-
break;
|
518
|
-
}
|
519
|
-
|
520
|
-
case 'ArrowLeft':
|
521
|
-
{
|
522
|
-
// Decrease selection by 1 day
|
523
|
-
let newDate = normalizeDate((0, _dateFns.subDays)(focusDate, 1));
|
524
|
-
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
525
|
-
|
526
|
-
if (disableWeekends && (0, _dateFns.isWeekend)(newDate)) {
|
527
|
-
const friday = (0, _dateFns.previousFriday)(newDate);
|
528
|
-
newDate = minDate && (0, _dateFns.isBefore)(friday, minDate) ? minDate : friday;
|
529
|
-
}
|
530
|
-
|
531
|
-
setFocusDate(newDate);
|
532
|
-
focusHandler(newDate);
|
533
|
-
break;
|
534
|
-
}
|
535
|
-
|
536
|
-
case 'ArrowUp':
|
537
|
-
{
|
538
|
-
// Decrease selection by 1 week
|
539
|
-
let newDate = normalizeDate((0, _dateFns.subWeeks)(focusDate, 1));
|
540
|
-
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
541
|
-
setFocusDate(newDate);
|
542
|
-
focusHandler(newDate);
|
543
|
-
break;
|
544
|
-
}
|
545
|
-
|
546
|
-
case 'ArrowDown':
|
547
|
-
{
|
548
|
-
// Increase selection by 1 week
|
549
|
-
let newDate = normalizeDate((0, _dateFns.addWeeks)(focusDate, 1));
|
550
|
-
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
551
|
-
setFocusDate(newDate);
|
552
|
-
focusHandler(newDate);
|
553
|
-
break;
|
554
|
-
}
|
555
|
-
|
556
|
-
case 'Home':
|
557
|
-
{
|
558
|
-
let newDate = focusDate;
|
559
|
-
|
560
|
-
if (disableWeekends) {
|
561
|
-
newDate = normalizeDate((0, _dateFns.isMonday)(focusDate) ? focusDate : (0, _dateFns.previousMonday)(focusDate));
|
562
|
-
} else {
|
563
|
-
newDate = normalizeDate((0, _dateFns.isSunday)(focusDate) ? focusDate : (0, _dateFns.previousSunday)(focusDate));
|
564
|
-
}
|
565
|
-
|
566
|
-
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
567
|
-
setFocusDate(newDate);
|
568
|
-
focusHandler(newDate);
|
569
|
-
break;
|
570
|
-
}
|
571
|
-
|
572
|
-
case 'End':
|
573
|
-
{
|
574
|
-
let newDate = focusDate;
|
575
|
-
|
576
|
-
if (disableWeekends) {
|
577
|
-
newDate = normalizeDate((0, _dateFns.isFriday)(focusDate) ? focusDate : (0, _dateFns.nextFriday)(focusDate));
|
578
|
-
} else {
|
579
|
-
newDate = normalizeDate((0, _dateFns.isSaturday)(focusDate) ? focusDate : (0, _dateFns.nextSaturday)(focusDate));
|
580
|
-
}
|
581
|
-
|
582
|
-
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
583
|
-
setFocusDate(newDate);
|
584
|
-
focusHandler(newDate);
|
585
|
-
break;
|
586
|
-
}
|
587
|
-
|
588
|
-
case 'PageUp':
|
589
|
-
{
|
590
|
-
let newDate = normalizeDate(e.shiftKey ? (0, _dateFns.subYears)(focusDate, 1) : (0, _dateFns.subMonths)(focusDate, 1));
|
591
|
-
if (minDate && (0, _dateFns.isBefore)(newDate, minDate)) newDate = minDate;
|
592
|
-
setFocusDate(newDate);
|
593
|
-
focusHandler(newDate);
|
594
|
-
break;
|
595
|
-
}
|
596
|
-
|
597
|
-
case 'PageDown':
|
598
|
-
{
|
599
|
-
let newDate = normalizeDate(e.shiftKey ? (0, _dateFns.addYears)(focusDate, 1) : (0, _dateFns.addMonths)(focusDate, 1));
|
600
|
-
if (maxDate && (0, _dateFns.isAfter)(newDate, maxDate)) newDate = maxDate;
|
601
|
-
setFocusDate(newDate);
|
602
|
-
focusHandler(newDate);
|
603
|
-
break;
|
604
|
-
}
|
605
|
-
|
606
|
-
case 'Enter':
|
607
|
-
case ' ':
|
608
|
-
{
|
609
|
-
// Start Selection
|
610
|
-
selectionHandler(focusDate);
|
611
|
-
break;
|
612
|
-
}
|
613
|
-
|
614
|
-
case 'Esc':
|
615
|
-
{
|
616
|
-
// Cancel Selection if started, reset if not? or close
|
617
|
-
if (hoverRange) {
|
618
|
-
setHoverRange(null);
|
619
|
-
}
|
620
|
-
|
621
|
-
break;
|
622
|
-
}
|
623
|
-
|
624
|
-
default:
|
625
|
-
{
|
626
|
-
break;
|
627
|
-
}
|
628
|
-
}
|
629
|
-
}, [configuration, focusDate, focusHandler, hoverRange, selectionHandler]);
|
630
|
-
(0, _react.useEffect)(() => {
|
631
|
-
if (isOpen) {
|
632
|
-
window.addEventListener('keydown', handleKeyDown);
|
633
|
-
} else {
|
634
|
-
window.removeEventListener('keydown', handleKeyDown);
|
635
|
-
}
|
636
|
-
|
637
|
-
return () => {
|
638
|
-
window.removeEventListener('keydown', handleKeyDown);
|
639
|
-
};
|
640
|
-
}, [handleKeyDown, isOpen]);
|
641
514
|
|
642
515
|
const onResize = windowEntry => {
|
643
516
|
// Only care about the first element, we expect one element ot be watched
|
package/lib/Dialog.d.ts
CHANGED
@@ -15,6 +15,7 @@ declare namespace DialogHeader {
|
|
15
15
|
};
|
16
16
|
var propTypes: {
|
17
17
|
lineHeight?: React.Validator<import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
18
|
+
border?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
18
19
|
alignContent?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.AlignContent, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
19
20
|
alignItems?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.AlignItems, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
20
21
|
alignSelf?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.AlignSelf, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
@@ -90,7 +91,6 @@ declare namespace DialogHeader {
|
|
90
91
|
zIndex?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.ZIndex, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
91
92
|
background?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
92
93
|
backgroundPosition?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.BackgroundPosition<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
93
|
-
border?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
94
94
|
borderBottom?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.BorderBottom<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
95
95
|
borderColor?: React.Validator<import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
96
96
|
borderLeft?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.BorderLeft<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
@@ -153,7 +153,7 @@ declare namespace DialogHeader {
|
|
153
153
|
results?: React.Validator<number | null | undefined> | undefined;
|
154
154
|
security?: React.Validator<string | null | undefined> | undefined;
|
155
155
|
unselectable?: React.Validator<"on" | "off" | null | undefined> | undefined;
|
156
|
-
inputMode?: React.Validator<"
|
156
|
+
inputMode?: React.Validator<"search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | null | undefined> | undefined;
|
157
157
|
is?: React.Validator<string | null | undefined> | undefined;
|
158
158
|
'aria-activedescendant'?: React.Validator<string | null | undefined> | undefined;
|
159
159
|
'aria-atomic'?: React.Validator<boolean | "true" | "false" | null | undefined> | undefined;
|
@@ -168,7 +168,7 @@ declare namespace DialogHeader {
|
|
168
168
|
'aria-describedby'?: React.Validator<string | null | undefined> | undefined;
|
169
169
|
'aria-details'?: React.Validator<string | null | undefined> | undefined;
|
170
170
|
'aria-disabled'?: React.Validator<boolean | "true" | "false" | null | undefined> | undefined;
|
171
|
-
'aria-dropeffect'?: React.Validator<"
|
171
|
+
'aria-dropeffect'?: React.Validator<"link" | "none" | "copy" | "execute" | "move" | "popup" | null | undefined> | undefined;
|
172
172
|
'aria-errormessage'?: React.Validator<string | null | undefined> | undefined;
|
173
173
|
'aria-expanded'?: React.Validator<boolean | "true" | "false" | null | undefined> | undefined;
|
174
174
|
'aria-flowto'?: React.Validator<string | null | undefined> | undefined;
|
@@ -387,7 +387,7 @@ declare namespace DialogHeader {
|
|
387
387
|
size?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.Height<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
388
388
|
borderX?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
389
389
|
borderY?: React.Validator<import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined> | undefined;
|
390
|
-
sx?: React.Validator<import("
|
390
|
+
sx?: React.Validator<import("./sx").BetterSystemStyleObject | undefined> | undefined;
|
391
391
|
theme?: React.Validator<any> | undefined;
|
392
392
|
};
|
393
393
|
var displayName: string;
|
package/lib/Dropdown.d.ts
CHANGED
@@ -75,7 +75,7 @@ declare const _default: {
|
|
75
75
|
results?: number | undefined;
|
76
76
|
security?: string | undefined;
|
77
77
|
unselectable?: "on" | "off" | undefined;
|
78
|
-
inputMode?: "
|
78
|
+
inputMode?: "search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
79
79
|
is?: string | undefined;
|
80
80
|
'aria-activedescendant'?: string | undefined;
|
81
81
|
'aria-atomic'?: boolean | "true" | "false" | undefined;
|
@@ -90,7 +90,7 @@ declare const _default: {
|
|
90
90
|
'aria-describedby'?: string | undefined;
|
91
91
|
'aria-details'?: string | undefined;
|
92
92
|
'aria-disabled'?: boolean | "true" | "false" | undefined;
|
93
|
-
'aria-dropeffect'?: "
|
93
|
+
'aria-dropeffect'?: "link" | "none" | "copy" | "execute" | "move" | "popup" | undefined;
|
94
94
|
'aria-errormessage'?: string | undefined;
|
95
95
|
'aria-expanded'?: boolean | "true" | "false" | undefined;
|
96
96
|
'aria-flowto'?: string | undefined;
|
@@ -307,7 +307,7 @@ declare const _default: {
|
|
307
307
|
py?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
308
308
|
paddingY?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
309
309
|
open?: boolean | undefined;
|
310
|
-
sx?: import("
|
310
|
+
sx?: import("./sx").BetterSystemStyleObject | undefined;
|
311
311
|
onToggle?: React.ReactEventHandler<HTMLElement> | undefined;
|
312
312
|
} & {
|
313
313
|
theme?: any;
|
@@ -372,7 +372,7 @@ declare const _default: {
|
|
372
372
|
results?: number | undefined;
|
373
373
|
security?: string | undefined;
|
374
374
|
unselectable?: "on" | "off" | undefined;
|
375
|
-
inputMode?: "
|
375
|
+
inputMode?: "search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
376
376
|
is?: string | undefined;
|
377
377
|
'aria-activedescendant'?: string | undefined;
|
378
378
|
'aria-atomic'?: boolean | "true" | "false" | undefined;
|
@@ -387,7 +387,7 @@ declare const _default: {
|
|
387
387
|
'aria-describedby'?: string | undefined;
|
388
388
|
'aria-details'?: string | undefined;
|
389
389
|
'aria-disabled'?: boolean | "true" | "false" | undefined;
|
390
|
-
'aria-dropeffect'?: "
|
390
|
+
'aria-dropeffect'?: "link" | "none" | "copy" | "execute" | "move" | "popup" | undefined;
|
391
391
|
'aria-errormessage'?: string | undefined;
|
392
392
|
'aria-expanded'?: boolean | "true" | "false" | undefined;
|
393
393
|
'aria-flowto'?: string | undefined;
|
@@ -604,7 +604,7 @@ declare const _default: {
|
|
604
604
|
py?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
605
605
|
paddingY?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
606
606
|
open?: boolean | undefined;
|
607
|
-
sx?: import("
|
607
|
+
sx?: import("./sx").BetterSystemStyleObject | undefined;
|
608
608
|
onToggle?: React.ReactEventHandler<HTMLElement> | undefined;
|
609
609
|
} & {
|
610
610
|
theme?: any;
|
@@ -691,7 +691,7 @@ declare const _default: {
|
|
691
691
|
results?: number | undefined;
|
692
692
|
security?: string | undefined;
|
693
693
|
unselectable?: "on" | "off" | undefined;
|
694
|
-
inputMode?: "
|
694
|
+
inputMode?: "search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
695
695
|
is?: string | undefined;
|
696
696
|
'aria-activedescendant'?: string | undefined;
|
697
697
|
'aria-atomic'?: boolean | "true" | "false" | undefined;
|
@@ -706,7 +706,7 @@ declare const _default: {
|
|
706
706
|
'aria-describedby'?: string | undefined;
|
707
707
|
'aria-details'?: string | undefined;
|
708
708
|
'aria-disabled'?: boolean | "true" | "false" | undefined;
|
709
|
-
'aria-dropeffect'?: "
|
709
|
+
'aria-dropeffect'?: "link" | "none" | "copy" | "execute" | "move" | "popup" | undefined;
|
710
710
|
'aria-errormessage'?: string | undefined;
|
711
711
|
'aria-expanded'?: boolean | "true" | "false" | undefined;
|
712
712
|
'aria-flowto'?: string | undefined;
|
@@ -923,7 +923,8 @@ declare const _default: {
|
|
923
923
|
py?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
924
924
|
paddingY?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
925
925
|
size?: import("styled-system").ResponsiveValue<import("csstype").Property.Height<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
926
|
-
sx?: import("
|
926
|
+
sx?: import("./sx").BetterSystemStyleObject | undefined;
|
927
|
+
as?: string | React.ComponentClass<any, any> | React.FunctionComponent<any> | undefined;
|
927
928
|
autoFocus?: boolean | undefined;
|
928
929
|
disabled?: boolean | undefined;
|
929
930
|
formAction?: string | undefined;
|
@@ -931,8 +932,7 @@ declare const _default: {
|
|
931
932
|
formMethod?: string | undefined;
|
932
933
|
formNoValidate?: boolean | undefined;
|
933
934
|
formTarget?: string | undefined;
|
934
|
-
|
935
|
-
variant?: "large" | "medium" | "small" | undefined;
|
935
|
+
variant?: "small" | "medium" | "large" | undefined;
|
936
936
|
} & {
|
937
937
|
theme?: any;
|
938
938
|
}): JSX.Element;
|
@@ -1011,7 +1011,7 @@ declare const _default: {
|
|
1011
1011
|
results?: number | undefined;
|
1012
1012
|
security?: string | undefined;
|
1013
1013
|
unselectable?: "on" | "off" | undefined;
|
1014
|
-
inputMode?: "
|
1014
|
+
inputMode?: "search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
1015
1015
|
is?: string | undefined;
|
1016
1016
|
'aria-activedescendant'?: string | undefined;
|
1017
1017
|
'aria-atomic'?: boolean | "true" | "false" | undefined;
|
@@ -1026,7 +1026,7 @@ declare const _default: {
|
|
1026
1026
|
'aria-describedby'?: string | undefined;
|
1027
1027
|
'aria-details'?: string | undefined;
|
1028
1028
|
'aria-disabled'?: boolean | "true" | "false" | undefined;
|
1029
|
-
'aria-dropeffect'?: "
|
1029
|
+
'aria-dropeffect'?: "link" | "none" | "copy" | "execute" | "move" | "popup" | undefined;
|
1030
1030
|
'aria-errormessage'?: string | undefined;
|
1031
1031
|
'aria-expanded'?: boolean | "true" | "false" | undefined;
|
1032
1032
|
'aria-flowto'?: string | undefined;
|
@@ -1243,7 +1243,8 @@ declare const _default: {
|
|
1243
1243
|
py?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
1244
1244
|
paddingY?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
1245
1245
|
size?: import("styled-system").ResponsiveValue<import("csstype").Property.Height<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
1246
|
-
sx?: import("
|
1246
|
+
sx?: import("./sx").BetterSystemStyleObject | undefined;
|
1247
|
+
as?: string | React.ComponentClass<any, any> | React.FunctionComponent<any> | undefined;
|
1247
1248
|
autoFocus?: boolean | undefined;
|
1248
1249
|
disabled?: boolean | undefined;
|
1249
1250
|
formAction?: string | undefined;
|
@@ -1251,8 +1252,7 @@ declare const _default: {
|
|
1251
1252
|
formMethod?: string | undefined;
|
1252
1253
|
formNoValidate?: boolean | undefined;
|
1253
1254
|
formTarget?: string | undefined;
|
1254
|
-
|
1255
|
-
variant?: "large" | "medium" | "small" | undefined;
|
1255
|
+
variant?: "small" | "medium" | "large" | undefined;
|
1256
1256
|
} & {
|
1257
1257
|
theme?: any;
|
1258
1258
|
}> | undefined;
|