@primer/components 0.0.0-202110323331 → 0.0.0-2021103235619
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -29
- package/dist/browser.esm.js +51 -55
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +50 -54
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Header.js +1 -1
- package/lib/ActionList/Item.d.ts +0 -6
- package/lib/ActionList/Item.js +1 -5
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +8 -6
- package/lib/Autocomplete/AutocompleteInput.d.ts +8 -6
- 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 +52 -0
- package/lib/DatePicker/DatePicker.js +109 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +202 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +55 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +363 -0
- package/lib/DatePicker/Day.d.ts +15 -0
- package/lib/DatePicker/Day.js +206 -0
- package/lib/DatePicker/Month.d.ts +8 -0
- package/lib/DatePicker/Month.js +122 -0
- package/lib/DatePicker/dateParser.d.ts +12 -0
- package/lib/DatePicker/dateParser.js +192 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +107 -0
- package/lib/DatePicker/useDatePicker.js +558 -0
- 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 +303 -264
- package/lib/FilterList.js +6 -2
- 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 +28 -26
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +8 -10
- package/lib/TextInputWithTokens.js +29 -102
- 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 +2 -13
- package/lib/Token/TokenBase.js +4 -0
- package/lib/Token/_RemoveTokenButton.js +2 -15
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/_TextInputWrapper.js +1 -1
- package/lib/hooks/useDebounce.d.ts +2 -0
- package/lib/hooks/useDebounce.js +24 -0
- package/lib/hooks/useResizeObserver.d.ts +1 -1
- package/lib/hooks/useResizeObserver.js +1 -1
- package/lib/sx.d.ts +2 -8
- package/lib/theme-preval.js +2 -2
- package/lib/theme.d.ts +0 -78
- package/lib/theme.js +1 -3
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/ActionList/Header.js +1 -1
- package/lib-esm/ActionList/Item.d.ts +0 -6
- package/lib-esm/ActionList/Item.js +1 -5
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +8 -6
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +8 -6
- 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 +52 -0
- package/lib-esm/DatePicker/DatePicker.js +92 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +174 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +40 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +332 -0
- package/lib-esm/DatePicker/Day.d.ts +15 -0
- package/lib-esm/DatePicker/Day.js +182 -0
- package/lib-esm/DatePicker/Month.d.ts +8 -0
- package/lib-esm/DatePicker/Month.js +98 -0
- package/lib-esm/DatePicker/dateParser.d.ts +12 -0
- package/lib-esm/DatePicker/dateParser.js +178 -0
- package/lib-esm/DatePicker/index.d.ts +2 -0
- package/lib-esm/DatePicker/index.js +1 -0
- package/lib-esm/DatePicker/useDatePicker.d.ts +107 -0
- package/lib-esm/DatePicker/useDatePicker.js +523 -0
- 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 +303 -264
- package/lib-esm/FilterList.js +7 -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 +28 -26
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +8 -10
- package/lib-esm/TextInputWithTokens.js +30 -101
- 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 +2 -13
- package/lib-esm/Token/TokenBase.js +4 -0
- package/lib-esm/Token/_RemoveTokenButton.js +2 -11
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.js +1 -1
- package/lib-esm/hooks/useDebounce.d.ts +2 -0
- package/lib-esm/hooks/useDebounce.js +16 -0
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
- package/lib-esm/hooks/useResizeObserver.js +1 -1
- package/lib-esm/sx.d.ts +2 -8
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/theme.d.ts +0 -78
- package/lib-esm/theme.js +1 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -10
- package/lib/utils/types/KeyPaths.d.ts +0 -3
- package/lib/utils/types/KeyPaths.js +0 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +0 -3
- package/lib-esm/utils/types/KeyPaths.js +0 -1
@@ -0,0 +1,363 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.DatePickerPanel = void 0;
|
7
|
+
|
8
|
+
var _dateFns = require("date-fns");
|
9
|
+
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
11
|
+
|
12
|
+
var _Box = _interopRequireDefault(require("../Box"));
|
13
|
+
|
14
|
+
var _Month = require("./Month");
|
15
|
+
|
16
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
17
|
+
|
18
|
+
var _constants = require("../constants");
|
19
|
+
|
20
|
+
var _useDatePicker = _interopRequireWildcard(require("./useDatePicker"));
|
21
|
+
|
22
|
+
var _octiconsReact = require("@primer/octicons-react");
|
23
|
+
|
24
|
+
var _StyledOcticon = _interopRequireDefault(require("../StyledOcticon"));
|
25
|
+
|
26
|
+
var _Button = _interopRequireWildcard(require("../Button"));
|
27
|
+
|
28
|
+
var _sx = _interopRequireDefault(require("../sx"));
|
29
|
+
|
30
|
+
var _useFocusZone = require("../hooks/useFocusZone");
|
31
|
+
|
32
|
+
var _focusZone = require("../behaviors/focusZone");
|
33
|
+
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35
|
+
|
36
|
+
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); }
|
37
|
+
|
38
|
+
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; }
|
39
|
+
|
40
|
+
const DatePickerPanelContainer = (0, _styledComponents.default)(_Box.default).withConfig({
|
41
|
+
displayName: "DatePickerPanel__DatePickerPanelContainer",
|
42
|
+
componentId: "sc-19upxpo-0"
|
43
|
+
})(["align-items:stretch;display:flex;flex-direction:column;position:relative;"]);
|
44
|
+
const DatePickerTopNav = (0, _styledComponents.default)(_Box.default).withConfig({
|
45
|
+
displayName: "DatePickerPanel__DatePickerTopNav",
|
46
|
+
componentId: "sc-19upxpo-1"
|
47
|
+
})(["display:flex;justify-content:space-between;position:absolute;top:0;left:0;right:0;padding:", ";z-index:10;"], (0, _constants.get)('space.3'));
|
48
|
+
const DatePickerPanelMonths = (0, _styledComponents.default)(_Box.default).withConfig({
|
49
|
+
displayName: "DatePickerPanel__DatePickerPanelMonths",
|
50
|
+
componentId: "sc-19upxpo-2"
|
51
|
+
})(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";margin-top:", ";padding:", ";position:relative;"], (0, _constants.get)('space.6'), (0, _constants.get)('space.1'), (0, _constants.get)('space.3'));
|
52
|
+
const DatePickerPanelFooter = (0, _styledComponents.default)(_Box.default).withConfig({
|
53
|
+
displayName: "DatePickerPanel__DatePickerPanelFooter",
|
54
|
+
componentId: "sc-19upxpo-3"
|
55
|
+
})(["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'));
|
56
|
+
const ArrowButton = (0, _styledComponents.default)(_Button.default).withConfig({
|
57
|
+
displayName: "DatePickerPanel__ArrowButton",
|
58
|
+
componentId: "sc-19upxpo-4"
|
59
|
+
})(["width:40px;height:28px;"]);
|
60
|
+
|
61
|
+
const Select = _styledComponents.default.select.withConfig({
|
62
|
+
displayName: "DatePickerPanel__Select",
|
63
|
+
componentId: "sc-19upxpo-5"
|
64
|
+
})(["background:", ";border:0;color:", ";font-weight:600;", ";", ";", ";"], (0, _constants.get)('colors.canvas.default'), (0, _constants.get)('colors.fg.default'), _constants.TYPOGRAPHY, _constants.COMMON, _sx.default);
|
65
|
+
|
66
|
+
const Option = _styledComponents.default.option.withConfig({
|
67
|
+
displayName: "DatePickerPanel__Option",
|
68
|
+
componentId: "sc-19upxpo-6"
|
69
|
+
})(["background:", ";border:0;color:", ";font-weight:400;padding:", " ", ";", ";", ";", ";"], (0, _constants.get)('colors.canvas.default'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('space.2'), (0, _constants.get)('space.2'), _constants.TYPOGRAPHY, _constants.COMMON, _sx.default);
|
70
|
+
|
71
|
+
const DatePickerPanel = () => {
|
72
|
+
const {
|
73
|
+
configuration,
|
74
|
+
saveValue,
|
75
|
+
revertValue,
|
76
|
+
currentViewingDate,
|
77
|
+
goToMonth,
|
78
|
+
nextMonth,
|
79
|
+
previousMonth,
|
80
|
+
onDayFocus,
|
81
|
+
setFocusDate,
|
82
|
+
viewMode
|
83
|
+
} = (0, _useDatePicker.default)();
|
84
|
+
const panelRef = (0, _react.useRef)(null);
|
85
|
+
const headerRef = (0, _react.useRef)(null);
|
86
|
+
const datePanelRef = (0, _react.useRef)(null);
|
87
|
+
const footerRef = (0, _react.useRef)(null);
|
88
|
+
(0, _useFocusZone.useFocusZone)({
|
89
|
+
containerRef: headerRef,
|
90
|
+
bindKeys: _focusZone.FocusKeys.Tab,
|
91
|
+
focusInStrategy: 'closest'
|
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]);
|
223
|
+
(0, _useFocusZone.useFocusZone)({
|
224
|
+
containerRef: footerRef,
|
225
|
+
bindKeys: _focusZone.FocusKeys.Tab,
|
226
|
+
focusInStrategy: 'closest'
|
227
|
+
});
|
228
|
+
const previousDisabled = (0, _react.useMemo)(() => {
|
229
|
+
const {
|
230
|
+
minDate
|
231
|
+
} = configuration;
|
232
|
+
if (!minDate) return false;
|
233
|
+
const previous = (0, _dateFns.subMonths)(currentViewingDate, 1);
|
234
|
+
|
235
|
+
if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
|
236
|
+
return true;
|
237
|
+
}
|
238
|
+
|
239
|
+
return false;
|
240
|
+
}, [configuration, currentViewingDate]);
|
241
|
+
const nextDisabled = (0, _react.useMemo)(() => {
|
242
|
+
const {
|
243
|
+
maxDate,
|
244
|
+
view
|
245
|
+
} = configuration;
|
246
|
+
if (!maxDate) return false;
|
247
|
+
const next = (0, _dateFns.addMonths)(currentViewingDate, view === '2-month' ? 2 : 1);
|
248
|
+
|
249
|
+
if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
|
250
|
+
return true;
|
251
|
+
}
|
252
|
+
|
253
|
+
return false;
|
254
|
+
}, [configuration, currentViewingDate]);
|
255
|
+
const currentMonth = (0, _react.useMemo)(() => currentViewingDate.getMonth(), [currentViewingDate]);
|
256
|
+
const currentYear = (0, _react.useMemo)(() => currentViewingDate.getFullYear(), [currentViewingDate]);
|
257
|
+
const headerSelectionHandler = (0, _react.useCallback)(e => {
|
258
|
+
const selection = parseInt(e.currentTarget.value, 10);
|
259
|
+
|
260
|
+
if (e.currentTarget.id === 'picker-header-year') {
|
261
|
+
goToMonth(new Date(selection, currentMonth));
|
262
|
+
} else {
|
263
|
+
goToMonth(new Date(currentYear, selection));
|
264
|
+
}
|
265
|
+
}, [currentMonth, currentYear, goToMonth]);
|
266
|
+
const getMonthPicker = (0, _react.useMemo)(() => {
|
267
|
+
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
268
|
+
const monthElements = [];
|
269
|
+
|
270
|
+
for (let i = 0; i < months.length; i++) {
|
271
|
+
monthElements.push( /*#__PURE__*/_react.default.createElement(Option, {
|
272
|
+
key: i,
|
273
|
+
value: i
|
274
|
+
}, months[i]));
|
275
|
+
}
|
276
|
+
|
277
|
+
return /*#__PURE__*/_react.default.createElement(Select, {
|
278
|
+
id: "picker-header-month",
|
279
|
+
value: currentMonth,
|
280
|
+
sx: {
|
281
|
+
mr: '6px'
|
282
|
+
},
|
283
|
+
onChange: headerSelectionHandler
|
284
|
+
}, monthElements);
|
285
|
+
}, [currentMonth, headerSelectionHandler]);
|
286
|
+
const getYearPicker = (0, _react.useMemo)(() => {
|
287
|
+
const years = [];
|
288
|
+
const minYear = currentYear - 200;
|
289
|
+
const maxYear = currentYear + 200;
|
290
|
+
|
291
|
+
for (let i = minYear; i <= maxYear; i++) {
|
292
|
+
years.push( /*#__PURE__*/_react.default.createElement(Option, {
|
293
|
+
key: i,
|
294
|
+
value: i
|
295
|
+
}, i));
|
296
|
+
}
|
297
|
+
|
298
|
+
return /*#__PURE__*/_react.default.createElement(Select, {
|
299
|
+
id: "picker-header-year",
|
300
|
+
value: currentYear,
|
301
|
+
onChange: headerSelectionHandler
|
302
|
+
}, years);
|
303
|
+
}, [currentYear, headerSelectionHandler]);
|
304
|
+
return /*#__PURE__*/_react.default.createElement(DatePickerPanelContainer, {
|
305
|
+
ref: panelRef
|
306
|
+
}, /*#__PURE__*/_react.default.createElement(DatePickerTopNav, {
|
307
|
+
ref: headerRef
|
308
|
+
}, configuration.compressedHeader && /*#__PURE__*/_react.default.createElement(_Box.default, {
|
309
|
+
sx: {
|
310
|
+
flex: 1
|
311
|
+
}
|
312
|
+
}, getMonthPicker, getYearPicker), /*#__PURE__*/_react.default.createElement(ArrowButton, {
|
313
|
+
variant: "small",
|
314
|
+
sx: {
|
315
|
+
mr: 1
|
316
|
+
},
|
317
|
+
onClick: previousMonth,
|
318
|
+
disabled: previousDisabled,
|
319
|
+
"aria-label": "Previous Month",
|
320
|
+
"aria-live": "polite"
|
321
|
+
}, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
|
322
|
+
icon: _octiconsReact.ChevronLeftIcon,
|
323
|
+
color: "fg.muted"
|
324
|
+
})), /*#__PURE__*/_react.default.createElement(ArrowButton, {
|
325
|
+
variant: "small",
|
326
|
+
onClick: nextMonth,
|
327
|
+
disabled: nextDisabled,
|
328
|
+
"aria-label": "Next Month",
|
329
|
+
"aria-live": "polite"
|
330
|
+
}, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
|
331
|
+
icon: _octiconsReact.ChevronRightIcon,
|
332
|
+
color: "fg.muted"
|
333
|
+
}))), /*#__PURE__*/_react.default.createElement(DatePickerPanelMonths, {
|
334
|
+
ref: datePanelRef
|
335
|
+
}, /*#__PURE__*/_react.default.createElement(_Month.Month, {
|
336
|
+
date: currentViewingDate
|
337
|
+
}), viewMode === '2-month' && /*#__PURE__*/_react.default.createElement(_Month.Month, {
|
338
|
+
date: (0, _dateFns.addMonths)(currentViewingDate, 1)
|
339
|
+
})), /*#__PURE__*/_react.default.createElement(DatePickerPanelFooter, {
|
340
|
+
ref: footerRef
|
341
|
+
}, /*#__PURE__*/_react.default.createElement(_Box.default, null, /*#__PURE__*/_react.default.createElement(_Button.default, {
|
342
|
+
variant: "small",
|
343
|
+
sx: {
|
344
|
+
mr: 1
|
345
|
+
},
|
346
|
+
onClick: () => revertValue(),
|
347
|
+
"aria-label": "Reset Selection",
|
348
|
+
"aria-live": "polite"
|
349
|
+
}, "Reset"), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
350
|
+
variant: "small",
|
351
|
+
onClick: () => goToMonth(new Date()),
|
352
|
+
"aria-label": "Go to Today",
|
353
|
+
"aria-live": "polite"
|
354
|
+
}, "Today")), configuration.confirmation && /*#__PURE__*/_react.default.createElement(_Button.ButtonPrimary, {
|
355
|
+
variant: "small",
|
356
|
+
onClick: () => saveValue(),
|
357
|
+
"aria-label": "Apply Selection",
|
358
|
+
"aria-live": "polite"
|
359
|
+
}, "Apply")));
|
360
|
+
};
|
361
|
+
|
362
|
+
exports.DatePickerPanel = DatePickerPanel;
|
363
|
+
DatePickerPanel.displayName = "DatePickerPanel";
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FontSizeProps } from 'styled-system';
|
3
|
+
import { SystemCommonProps, SystemLayoutProps } from '../constants';
|
4
|
+
import { SxProp } from '../sx';
|
5
|
+
import { DaySelection } from './useDatePicker';
|
6
|
+
export declare type DayProps = {
|
7
|
+
blocked?: boolean;
|
8
|
+
disabled?: boolean;
|
9
|
+
focused?: boolean;
|
10
|
+
onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
|
11
|
+
selected?: DaySelection;
|
12
|
+
date: Date;
|
13
|
+
} & FontSizeProps & SystemCommonProps & SxProp & SystemLayoutProps;
|
14
|
+
export declare const Day: React.FC<DayProps>;
|
15
|
+
export declare const BlankDay: import("styled-components").StyledComponent<"div", any, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").TypographyProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").GridProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> & import("styled-system").BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ShadowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & SxProp, never>;
|
@@ -0,0 +1,206 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.BlankDay = exports.Day = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
11
|
+
|
12
|
+
var _Box = _interopRequireDefault(require("../Box"));
|
13
|
+
|
14
|
+
var _Text = _interopRequireDefault(require("../Text"));
|
15
|
+
|
16
|
+
var _constants = require("../constants");
|
17
|
+
|
18
|
+
var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
|
19
|
+
|
20
|
+
var _dateFns = require("date-fns");
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
|
+
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
27
|
+
|
28
|
+
const DayBaseComponent = (0, _styledComponents.default)(_Box.default).withConfig({
|
29
|
+
displayName: "Day__DayBaseComponent",
|
30
|
+
componentId: "sc-1japneh-0"
|
31
|
+
})(["align-content:center;display:flex;justify-content:center;min-width:38px;min-height:38px;padding:", ";"], (0, _constants.get)('space.1'));
|
32
|
+
const states = {
|
33
|
+
blocked: {
|
34
|
+
background: (0, _constants.get)('colors.neutral.subtle'),
|
35
|
+
borderRadius: (0, _constants.get)('radii.2'),
|
36
|
+
color: (0, _constants.get)('colors.fg.subtle')
|
37
|
+
},
|
38
|
+
disabled: {
|
39
|
+
background: (0, _constants.get)('colors.canvas.primary'),
|
40
|
+
borderRadius: (0, _constants.get)('radii.2'),
|
41
|
+
color: (0, _constants.get)('colors.fg.subtle')
|
42
|
+
},
|
43
|
+
selected: {
|
44
|
+
default: {
|
45
|
+
background: (0, _constants.get)('colors.accent.emphasis'),
|
46
|
+
borderRadius: (0, _constants.get)('radii.2'),
|
47
|
+
color: (0, _constants.get)('colors.fg.onEmphasis'),
|
48
|
+
todayColor: (0, _constants.get)('colors.fg.onEmphasis')
|
49
|
+
},
|
50
|
+
start: {
|
51
|
+
background: (0, _constants.get)('colors.accent.emphasis'),
|
52
|
+
borderRadius: '4px 0 0 4px',
|
53
|
+
color: (0, _constants.get)('colors.fg.onEmphasis'),
|
54
|
+
todayColor: (0, _constants.get)('colors.fg.onEmphasis')
|
55
|
+
},
|
56
|
+
middle: {
|
57
|
+
background: (0, _constants.get)('colors.accent.subtle'),
|
58
|
+
borderRadius: '0',
|
59
|
+
color: (0, _constants.get)('colors.fg.default'),
|
60
|
+
todayColor: (0, _constants.get)('colors.accent.fg')
|
61
|
+
},
|
62
|
+
end: {
|
63
|
+
background: (0, _constants.get)('colors.accent.emphasis'),
|
64
|
+
borderRadius: '0 4px 4px 0',
|
65
|
+
color: (0, _constants.get)('colors.fg.onEmphasis'),
|
66
|
+
todayColor: (0, _constants.get)('colors.fg.onEmphasis')
|
67
|
+
}
|
68
|
+
},
|
69
|
+
default: {
|
70
|
+
normal: {
|
71
|
+
background: (0, _constants.get)('colors.canvas.primary'),
|
72
|
+
borderRadius: (0, _constants.get)('radii.2'),
|
73
|
+
color: (0, _constants.get)('colors.fg.default'),
|
74
|
+
todayColor: (0, _constants.get)('colors.accent.fg')
|
75
|
+
},
|
76
|
+
hover: {
|
77
|
+
background: (0, _constants.get)('colors.neutral.muted'),
|
78
|
+
borderRadius: (0, _constants.get)('radii.2'),
|
79
|
+
color: (0, _constants.get)('colors.fg.default'),
|
80
|
+
todayColor: (0, _constants.get)('colors.accent.fg')
|
81
|
+
},
|
82
|
+
pressed: {
|
83
|
+
background: (0, _constants.get)('colors.neutral.emphasis'),
|
84
|
+
borderRadius: (0, _constants.get)('radii.2'),
|
85
|
+
color: (0, _constants.get)('colors.fg.onEmphasis'),
|
86
|
+
todayColor: (0, _constants.get)('colors.fg.onEmphasis')
|
87
|
+
}
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
91
|
+
const getStateStyles = (props, prop, state) => {
|
92
|
+
const {
|
93
|
+
blocked,
|
94
|
+
disabled,
|
95
|
+
selected,
|
96
|
+
today
|
97
|
+
} = props;
|
98
|
+
|
99
|
+
if (selected) {
|
100
|
+
switch (selected) {
|
101
|
+
case 'start':
|
102
|
+
return today && prop === 'color' ? states.selected.start['todayColor'] : states.selected.start[prop];
|
103
|
+
|
104
|
+
case 'middle':
|
105
|
+
return today && prop === 'color' ? states.selected.middle['todayColor'] : states.selected.middle[prop];
|
106
|
+
|
107
|
+
case 'end':
|
108
|
+
return today && prop === 'color' ? states.selected.end['todayColor'] : states.selected.end[prop];
|
109
|
+
|
110
|
+
default:
|
111
|
+
return today && prop === 'color' ? states.selected.default['todayColor'] : states.selected.default[prop];
|
112
|
+
}
|
113
|
+
} else if (blocked) {
|
114
|
+
return states.blocked[prop];
|
115
|
+
} else if (disabled) {
|
116
|
+
return states.disabled[prop];
|
117
|
+
} else {
|
118
|
+
return today && prop === 'color' ? states.default[state]['todayColor'] : states.default[state][prop];
|
119
|
+
}
|
120
|
+
};
|
121
|
+
|
122
|
+
const DayComponent = (0, _styledComponents.default)(DayBaseComponent).attrs(props => ({
|
123
|
+
background: getStateStyles(props, 'background', 'normal'),
|
124
|
+
borderRadius: getStateStyles(props, 'borderRadius', 'normal'),
|
125
|
+
textColor: getStateStyles(props, 'color', 'normal'),
|
126
|
+
backgroundHover: getStateStyles(props, 'background', 'hover'),
|
127
|
+
textColorHover: getStateStyles(props, 'color', 'hover'),
|
128
|
+
backgroundPressed: getStateStyles(props, 'background', 'pressed'),
|
129
|
+
textColorPressed: getStateStyles(props, 'color', 'pressed')
|
130
|
+
})).withConfig({
|
131
|
+
displayName: "Day__DayComponent",
|
132
|
+
componentId: "sc-1japneh-1"
|
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);
|
134
|
+
|
135
|
+
const Day = ({
|
136
|
+
date,
|
137
|
+
onAction
|
138
|
+
}) => {
|
139
|
+
const {
|
140
|
+
onDayFocus,
|
141
|
+
onSelection,
|
142
|
+
disabled,
|
143
|
+
blocked,
|
144
|
+
focused,
|
145
|
+
selected,
|
146
|
+
today
|
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]);
|
158
|
+
const keyPressHandler = (0, _react.useCallback)(event => {
|
159
|
+
if (disabled) {
|
160
|
+
return;
|
161
|
+
}
|
162
|
+
|
163
|
+
if ([' ', 'Enter'].includes(event.key)) {
|
164
|
+
onSelection(date);
|
165
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
166
|
+
}
|
167
|
+
}, [disabled, onSelection, onAction, date]);
|
168
|
+
const clickHandler = (0, _react.useCallback)(event => {
|
169
|
+
if (disabled) {
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
|
173
|
+
onSelection(date);
|
174
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
175
|
+
}, [disabled, onSelection, date, onAction]);
|
176
|
+
const todayStyles = (0, _react.useMemo)(() => today ? {
|
177
|
+
fontWeight: 'bold'
|
178
|
+
} : {}, [today]);
|
179
|
+
return /*#__PURE__*/_react.default.createElement(DayComponent, {
|
180
|
+
ref: dayRef,
|
181
|
+
role: "gridcell",
|
182
|
+
"aria-disabled": disabled,
|
183
|
+
"aria-selected": selected !== false,
|
184
|
+
blocked: blocked,
|
185
|
+
disabled: disabled,
|
186
|
+
focused: focused,
|
187
|
+
selected: selected,
|
188
|
+
today: today,
|
189
|
+
onClick: clickHandler,
|
190
|
+
onMouseEnter: () => onDayFocus(date),
|
191
|
+
onFocus: () => onDayFocus(date),
|
192
|
+
onKeyPress: keyPressHandler,
|
193
|
+
tabIndex: -1,
|
194
|
+
"data-date": (0, _dateFns.format)(date, 'MM/dd/yyyy')
|
195
|
+
}, /*#__PURE__*/_react.default.createElement(_Text.default, {
|
196
|
+
sx: todayStyles
|
197
|
+
}, date.getDate()));
|
198
|
+
};
|
199
|
+
|
200
|
+
exports.Day = Day;
|
201
|
+
Day.displayName = "Day";
|
202
|
+
const BlankDay = (0, _styledComponents.default)(DayBaseComponent).withConfig({
|
203
|
+
displayName: "Day__BlankDay",
|
204
|
+
componentId: "sc-1japneh-2"
|
205
|
+
})(["background-color:", ";"], (0, _constants.get)('colors.canvas.primary'));
|
206
|
+
exports.BlankDay = BlankDay;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FontSizeProps } from 'styled-system';
|
3
|
+
import { SystemCommonProps, SystemLayoutProps } from '../constants';
|
4
|
+
import { SxProp } from '../sx';
|
5
|
+
export interface MonthProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
|
6
|
+
date: Date;
|
7
|
+
}
|
8
|
+
export declare const Month: React.FC<MonthProps>;
|