@primer/components 0.0.0-2021104155617 → 0.0.0-2021104225742

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/browser.esm.js +4 -7
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +29 -32
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  7. package/lib/Autocomplete/Autocomplete.d.ts +2 -4
  8. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
  9. package/lib/Button/Button.js +1 -1
  10. package/lib/SelectMenu/SelectMenu.d.ts +2 -4
  11. package/lib/TextInputWithTokens.d.ts +2 -4
  12. package/lib/Truncate.d.ts +1 -2
  13. package/lib/Truncate.js +1 -3
  14. package/lib/hooks/useResizeObserver.d.ts +1 -1
  15. package/lib/hooks/useResizeObserver.js +1 -1
  16. package/lib/theme-preval.js +2 -2
  17. package/lib/utils/testing.d.ts +1 -1
  18. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  19. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
  20. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
  21. package/lib-esm/Button/Button.js +1 -1
  22. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
  23. package/lib-esm/TextInputWithTokens.d.ts +2 -4
  24. package/lib-esm/Truncate.d.ts +1 -2
  25. package/lib-esm/Truncate.js +1 -2
  26. package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
  27. package/lib-esm/hooks/useResizeObserver.js +1 -1
  28. package/lib-esm/theme-preval.js +2 -2
  29. package/lib-esm/utils/testing.d.ts +1 -1
  30. package/package.json +8 -9
  31. package/lib/DatePicker/DatePicker.d.ts +0 -52
  32. package/lib/DatePicker/DatePicker.js +0 -109
  33. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  34. package/lib/DatePicker/DatePickerAnchor.js +0 -202
  35. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  36. package/lib/DatePicker/DatePickerOverlay.js +0 -55
  37. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  38. package/lib/DatePicker/DatePickerPanel.js +0 -363
  39. package/lib/DatePicker/Day.d.ts +0 -15
  40. package/lib/DatePicker/Day.js +0 -206
  41. package/lib/DatePicker/Month.d.ts +0 -8
  42. package/lib/DatePicker/Month.js +0 -122
  43. package/lib/DatePicker/dateParser.d.ts +0 -12
  44. package/lib/DatePicker/dateParser.js +0 -193
  45. package/lib/DatePicker/index.d.ts +0 -2
  46. package/lib/DatePicker/index.js +0 -13
  47. package/lib/DatePicker/useDatePicker.d.ts +0 -107
  48. package/lib/DatePicker/useDatePicker.js +0 -558
  49. package/lib/hooks/useDebounce.d.ts +0 -2
  50. package/lib/hooks/useDebounce.js +0 -24
  51. package/lib-esm/DatePicker/DatePicker.d.ts +0 -52
  52. package/lib-esm/DatePicker/DatePicker.js +0 -92
  53. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  54. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -174
  55. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  56. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -40
  57. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  58. package/lib-esm/DatePicker/DatePickerPanel.js +0 -332
  59. package/lib-esm/DatePicker/Day.d.ts +0 -15
  60. package/lib-esm/DatePicker/Day.js +0 -182
  61. package/lib-esm/DatePicker/Month.d.ts +0 -8
  62. package/lib-esm/DatePicker/Month.js +0 -98
  63. package/lib-esm/DatePicker/dateParser.d.ts +0 -12
  64. package/lib-esm/DatePicker/dateParser.js +0 -179
  65. package/lib-esm/DatePicker/index.d.ts +0 -2
  66. package/lib-esm/DatePicker/index.js +0 -1
  67. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -107
  68. package/lib-esm/DatePicker/useDatePicker.js +0 -523
  69. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  70. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,92 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
- import { DatePickerAnchor } from './DatePickerAnchor';
3
- import { DatePickerProvider } from './useDatePicker';
4
- import { DatePickerOverlay } from './DatePickerOverlay';
5
- export const DatePicker = ({
6
- anchorVariant,
7
- anchorRef: externalAnchorRef,
8
- confirmation,
9
- confirmUnsavedClose,
10
- compressedHeader,
11
- dateFormat,
12
- disableWeekends,
13
- focusTrapSettings,
14
- focusZoneSettings,
15
- iconPlacement,
16
- maxDate,
17
- maxRangeSize,
18
- maxSelections,
19
- minDate,
20
- onOpen: onOpenExternal,
21
- onClose: onCloseExternal,
22
- open,
23
- overlayProps,
24
- placeholder,
25
- renderAnchor = null,
26
- showInputPrompt,
27
- value,
28
- variant,
29
- view,
30
- weekStartsOn
31
- }) => {
32
- const anchorRef = useRef(null);
33
- const [isOpen, setIsOpen] = useState(false);
34
- const datePickerConfiguration = {
35
- anchorVariant,
36
- confirmation,
37
- confirmUnsavedClose,
38
- compressedHeader,
39
- dateFormat,
40
- disableWeekends,
41
- iconPlacement,
42
- maxDate: maxDate ? new Date(new Date(maxDate).toDateString()) : maxDate,
43
- maxRangeSize,
44
- maxSelections,
45
- minDate: minDate ? new Date(new Date(minDate).toDateString()) : minDate,
46
- placeholder,
47
- showInputPrompt,
48
- variant,
49
- view,
50
- weekStartsOn
51
- };
52
-
53
- const onOpen = gesture => {
54
- setIsOpen(true);
55
- onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
56
- };
57
-
58
- const onClose = gesture => {
59
- setIsOpen(false);
60
- onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
61
- };
62
-
63
- const toggleIsOpen = () => {
64
- if (isOpen) {
65
- setIsOpen(false);
66
- onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
67
- } else {
68
- setIsOpen(true);
69
- onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
70
- }
71
- };
72
-
73
- return /*#__PURE__*/React.createElement(DatePickerProvider, {
74
- configuration: datePickerConfiguration,
75
- isOpen: isOpen,
76
- value: value,
77
- closePicker: () => setIsOpen(false)
78
- }, /*#__PURE__*/React.createElement(DatePickerAnchor, {
79
- ref: anchorRef,
80
- onAction: toggleIsOpen
81
- }), /*#__PURE__*/React.createElement(DatePickerOverlay, {
82
- anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : anchorRef,
83
- renderAnchor: renderAnchor,
84
- open: open !== null && open !== void 0 ? open : isOpen,
85
- onOpen: onOpen,
86
- onClose: onClose,
87
- overlayProps: overlayProps,
88
- focusTrapSettings: focusTrapSettings,
89
- focusZoneSettings: focusZoneSettings
90
- }));
91
- };
92
- DatePicker.displayName = "DatePicker";
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- export interface DatePickerAnchorProps {
3
- onAction?: (event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
4
- }
5
- export declare const DatePickerAnchor: React.ForwardRefExoticComponent<DatePickerAnchorProps & React.RefAttributes<HTMLDivElement>>;
@@ -1,174 +0,0 @@
1
- import { AlertIcon, CalendarIcon, CheckIcon } from '@primer/octicons-react';
2
- import styled from 'styled-components';
3
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
- import Button, { ButtonInvisible } from '../Button';
5
- import Text from '../Text';
6
- import { get } from '../constants';
7
- import StyledOcticon from '../StyledOcticon';
8
- import useDatePicker from './useDatePicker';
9
- import TextInput from '../TextInput';
10
- import Box from '../Box';
11
- import { parseDate } from './dateParser';
12
- import { Tooltip } from '..';
13
- const DatePickerAnchorButton = styled(Button).withConfig({
14
- displayName: "DatePickerAnchor__DatePickerAnchorButton",
15
- componentId: "sc-8gpb9d-0"
16
- })(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;max-width:350px;overflow:hidden;& ", " ~ svg{margin-left:", ";}& svg ~ ", "{margin-left:", ";}"], Text, get('space.2'), Text, get('space.2'));
17
- export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
18
- onAction
19
- }, ref) => {
20
- const {
21
- configuration: {
22
- anchorVariant,
23
- iconPlacement,
24
- placeholder,
25
- variant
26
- },
27
- disabled,
28
- formattedDate,
29
- inputDate,
30
- onDateInput
31
- } = useDatePicker();
32
- const [inputValue, setInputValue] = useState(formattedDate);
33
- const inputRef = useRef(null);
34
- const [inputValid, setInputValid] = useState(true);
35
- const [inputFocused, setInputFocused] = useState(false);
36
- const keyPressHandler = useCallback(event => {
37
- if (disabled) {
38
- return;
39
- }
40
-
41
- if ([' ', 'Enter'].includes(event.key)) {
42
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
43
- }
44
- }, [disabled, onAction]);
45
- const clickHandler = useCallback(event => {
46
- if (disabled) {
47
- return;
48
- }
49
-
50
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
51
- }, [disabled, onAction]);
52
- useEffect(() => {
53
- if (document.activeElement !== inputRef.current) {
54
- setInputValue(formattedDate);
55
- }
56
- }, [formattedDate]);
57
- const onInputChangeHandler = useCallback(e => {
58
- const value = e.currentTarget.value;
59
- setInputValue(value);
60
-
61
- if (!value) {
62
- return;
63
- }
64
-
65
- const parsedDate = parseDate(value, variant);
66
- setInputValid(!!parsedDate);
67
-
68
- if (parsedDate) {
69
- onDateInput(parsedDate);
70
- }
71
- }, [onDateInput, variant]);
72
-
73
- const onFocusHandler = () => {
74
- setInputValue(inputDate);
75
- setInputFocused(true);
76
- };
77
-
78
- const onBlurHandler = () => {
79
- setInputValue(formattedDate);
80
- setInputValid(true);
81
- setInputFocused(false);
82
- };
83
-
84
- const inputSx = useMemo(() => {
85
- let sxObject = {};
86
-
87
- if (iconPlacement === 'start') {
88
- sxObject = { ...sxObject,
89
- pl: 5,
90
- pr: 2
91
- };
92
- } else if (iconPlacement === 'end') {
93
- sxObject = { ...sxObject,
94
- pl: 2,
95
- pr: 5
96
- };
97
- }
98
-
99
- return sxObject;
100
- }, [iconPlacement]);
101
-
102
- if (anchorVariant === 'input') {
103
- const calendarButton = side => /*#__PURE__*/React.createElement(ButtonInvisible, {
104
- onClick: clickHandler,
105
- sx: {
106
- width: '32px',
107
- px: '6px',
108
- position: 'absolute',
109
- [side]: '1px',
110
- top: '1px',
111
- bottom: '1px'
112
- }
113
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
114
- icon: CalendarIcon
115
- }));
116
-
117
- const iconSx = () => ({
118
- position: 'absolute',
119
- top: 0,
120
- bottom: 0,
121
- right: iconPlacement === 'end' ? '36px' : '10px',
122
- display: 'flex',
123
- alignItems: 'center'
124
- });
125
-
126
- return /*#__PURE__*/React.createElement(Box, {
127
- ref: ref,
128
- sx: {
129
- position: 'relative',
130
- display: 'flex'
131
- }
132
- }, iconPlacement === 'start' && calendarButton('left'), /*#__PURE__*/React.createElement(TextInput, {
133
- ref: inputRef,
134
- placeholder: placeholder,
135
- value: inputValue,
136
- onChange: onInputChangeHandler,
137
- sx: inputSx,
138
- onBlur: onBlurHandler,
139
- onFocus: onFocusHandler
140
- }), /*#__PURE__*/React.createElement(Box, {
141
- sx: iconSx()
142
- }, inputValid && inputFocused && /*#__PURE__*/React.createElement(StyledOcticon, {
143
- icon: CheckIcon,
144
- color: "success.emphasis"
145
- }), !inputValid && /*#__PURE__*/React.createElement(Tooltip, {
146
- direction: "s",
147
- text: "Invalid entry. Please make sure you use the 'MM/DD/YYYY' format."
148
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
149
- icon: AlertIcon,
150
- color: "attention.emphasis"
151
- }))), iconPlacement === 'end' && calendarButton('right'));
152
- }
153
-
154
- const calendarIcon = () => /*#__PURE__*/React.createElement(StyledOcticon, {
155
- icon: CalendarIcon,
156
- color: "fg.muted",
157
- sx: {
158
- my: '2px'
159
- }
160
- });
161
-
162
- return /*#__PURE__*/React.createElement(Box, {
163
- ref: ref
164
- }, /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
165
- onClick: clickHandler,
166
- onKeyPress: keyPressHandler,
167
- "aria-label": formattedDate
168
- }, (iconPlacement === 'start' || anchorVariant === 'icon-only') && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
169
- sx: {
170
- overflow: 'hidden',
171
- textOverflow: 'ellipsis'
172
- }
173
- }, formattedDate), iconPlacement === 'end' && calendarIcon()));
174
- });
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import { AnchoredOverlayProps } from '../AnchoredOverlay';
3
- export declare const DatePickerOverlay: React.FC<AnchoredOverlayProps>;
@@ -1,40 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React from 'react';
4
- import useDatePicker from './useDatePicker';
5
- import { AnchoredOverlay } from '../AnchoredOverlay';
6
- import { DatePickerPanel } from './DatePickerPanel';
7
- export const DatePickerOverlay = ({
8
- onClose,
9
- ...rest
10
- }) => {
11
- const {
12
- dialogOpen,
13
- onClose: onDatePickerClose,
14
- setDialogOpen,
15
- currentViewingDate
16
- } = useDatePicker();
17
-
18
- const onOverlayClose = async gesture => {
19
- if (!dialogOpen) {
20
- setDialogOpen(true);
21
- await onDatePickerClose();
22
- setDialogOpen(false);
23
- onClose === null || onClose === void 0 ? void 0 : onClose(gesture);
24
- }
25
- };
26
-
27
- return /*#__PURE__*/React.createElement(AnchoredOverlay, _extends({}, rest, {
28
- onClose: onOverlayClose,
29
- focusTrapSettings: {
30
- restoreFocusOnCleanUp: true
31
- },
32
- focusZoneSettings: {
33
- disabled: true
34
- },
35
- "aria-modal": "true",
36
- "aria-labelledby": `${currentViewingDate.getMonth()} ${currentViewingDate.getFullYear()}`,
37
- "aria-live": "polite"
38
- }), /*#__PURE__*/React.createElement(DatePickerPanel, null));
39
- };
40
- DatePickerOverlay.displayName = "DatePickerOverlay";
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const DatePickerPanel: () => JSX.Element;
@@ -1,332 +0,0 @@
1
- import { isAfter, isBefore, addMonths, subMonths, isWeekend, addDays, subDays, addWeeks, subWeeks, isSaturday, isSunday, nextSaturday, previousFriday, previousSunday, subYears, addYears, nextMonday, isMonday, previousMonday, isFriday, nextFriday, format } from 'date-fns';
2
- import React, { useCallback, useMemo, useRef } from 'react';
3
- import Box from '../Box';
4
- import { Month } from './Month';
5
- import styled from 'styled-components';
6
- import { COMMON, get, TYPOGRAPHY } from '../constants';
7
- import useDatePicker, { normalizeDate } from './useDatePicker';
8
- import { ChevronLeftIcon, ChevronRightIcon } from '@primer/octicons-react';
9
- import StyledOcticon from '../StyledOcticon';
10
- import Button, { ButtonPrimary } from '../Button';
11
- import sx from '../sx';
12
- import { useFocusZone } from '../hooks/useFocusZone';
13
- import { FocusKeys } from '../behaviors/focusZone';
14
- const DatePickerPanelContainer = styled(Box).withConfig({
15
- displayName: "DatePickerPanel__DatePickerPanelContainer",
16
- componentId: "sc-19upxpo-0"
17
- })(["align-items:stretch;display:flex;flex-direction:column;position:relative;"]);
18
- const DatePickerTopNav = styled(Box).withConfig({
19
- displayName: "DatePickerPanel__DatePickerTopNav",
20
- componentId: "sc-19upxpo-1"
21
- })(["display:flex;justify-content:space-between;position:absolute;top:0;left:0;right:0;padding:", ";z-index:10;"], get('space.3'));
22
- const DatePickerPanelMonths = styled(Box).withConfig({
23
- displayName: "DatePickerPanel__DatePickerPanelMonths",
24
- componentId: "sc-19upxpo-2"
25
- })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";margin-top:", ";padding:", ";position:relative;"], get('space.6'), get('space.1'), get('space.3'));
26
- const DatePickerPanelFooter = styled(Box).withConfig({
27
- displayName: "DatePickerPanel__DatePickerPanelFooter",
28
- componentId: "sc-19upxpo-3"
29
- })(["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;"], get('colors.border.default'), get('space.6'), get('space.3'), get('space.3'));
30
- const ArrowButton = styled(Button).withConfig({
31
- displayName: "DatePickerPanel__ArrowButton",
32
- componentId: "sc-19upxpo-4"
33
- })(["width:40px;height:28px;"]);
34
- const Select = styled.select.withConfig({
35
- displayName: "DatePickerPanel__Select",
36
- componentId: "sc-19upxpo-5"
37
- })(["background:", ";border:0;color:", ";font-weight:600;", ";", ";", ";"], get('colors.canvas.default'), get('colors.fg.default'), TYPOGRAPHY, COMMON, sx);
38
- const Option = styled.option.withConfig({
39
- displayName: "DatePickerPanel__Option",
40
- componentId: "sc-19upxpo-6"
41
- })(["background:", ";border:0;color:", ";font-weight:400;padding:", " ", ";", ";", ";", ";"], get('colors.canvas.default'), get('colors.fg.default'), get('space.2'), get('space.2'), TYPOGRAPHY, COMMON, sx);
42
- export const DatePickerPanel = () => {
43
- const {
44
- configuration,
45
- saveValue,
46
- revertValue,
47
- currentViewingDate,
48
- goToMonth,
49
- nextMonth,
50
- previousMonth,
51
- onDayFocus,
52
- setFocusDate,
53
- viewMode
54
- } = useDatePicker();
55
- const panelRef = useRef(null);
56
- const headerRef = useRef(null);
57
- const datePanelRef = useRef(null);
58
- const footerRef = useRef(null);
59
- useFocusZone({
60
- containerRef: headerRef,
61
- bindKeys: FocusKeys.Tab,
62
- focusInStrategy: 'closest'
63
- });
64
- const getNextFocusable = useCallback((direction, from, event) => {
65
- var _datePanelRef$current, _datePanelRef$current2;
66
-
67
- const key = event.key;
68
- const {
69
- disableWeekends,
70
- minDate,
71
- maxDate
72
- } = configuration;
73
- const fromDate = from === null || from === void 0 ? void 0 : from.getAttribute('data-date');
74
- const focusDate = fromDate ? new Date(fromDate) : new Date();
75
- let newDate = normalizeDate(focusDate);
76
-
77
- switch (key) {
78
- case 'ArrowRight':
79
- {
80
- // Increase selection by 1 day
81
- newDate = normalizeDate(addDays(focusDate, 1));
82
- if (maxDate && isAfter(newDate, maxDate)) newDate = maxDate;
83
-
84
- if (disableWeekends && isWeekend(newDate)) {
85
- const monday = nextMonday(newDate);
86
- newDate = maxDate && isAfter(monday, maxDate) ? maxDate : monday;
87
- }
88
-
89
- setFocusDate(newDate);
90
- onDayFocus(newDate);
91
- break;
92
- }
93
-
94
- case 'ArrowLeft':
95
- {
96
- // Decrease selection by 1 day
97
- newDate = normalizeDate(subDays(focusDate, 1));
98
- if (minDate && isBefore(newDate, minDate)) newDate = minDate;
99
-
100
- if (disableWeekends && isWeekend(newDate)) {
101
- const friday = previousFriday(newDate);
102
- newDate = minDate && isBefore(friday, minDate) ? minDate : friday;
103
- }
104
-
105
- setFocusDate(newDate);
106
- onDayFocus(newDate);
107
- break;
108
- }
109
-
110
- case 'ArrowUp':
111
- {
112
- // Decrease selection by 1 week
113
- newDate = normalizeDate(subWeeks(focusDate, 1));
114
- if (minDate && isBefore(newDate, minDate)) newDate = minDate;
115
- setFocusDate(newDate);
116
- onDayFocus(newDate);
117
- break;
118
- }
119
-
120
- case 'ArrowDown':
121
- {
122
- // Increase selection by 1 week
123
- newDate = normalizeDate(addWeeks(focusDate, 1));
124
- if (maxDate && isAfter(newDate, maxDate)) newDate = maxDate;
125
- setFocusDate(newDate);
126
- onDayFocus(newDate);
127
- break;
128
- }
129
-
130
- case 'Home':
131
- {
132
- newDate = focusDate;
133
-
134
- if (disableWeekends) {
135
- newDate = normalizeDate(isMonday(focusDate) ? focusDate : previousMonday(focusDate));
136
- } else {
137
- newDate = normalizeDate(isSunday(focusDate) ? focusDate : previousSunday(focusDate));
138
- }
139
-
140
- if (minDate && isBefore(newDate, minDate)) newDate = minDate;
141
- setFocusDate(newDate);
142
- onDayFocus(newDate);
143
- break;
144
- }
145
-
146
- case 'End':
147
- {
148
- newDate = focusDate;
149
-
150
- if (disableWeekends) {
151
- newDate = normalizeDate(isFriday(focusDate) ? focusDate : nextFriday(focusDate));
152
- } else {
153
- newDate = normalizeDate(isSaturday(focusDate) ? focusDate : nextSaturday(focusDate));
154
- }
155
-
156
- if (maxDate && isAfter(newDate, maxDate)) newDate = maxDate;
157
- setFocusDate(newDate);
158
- onDayFocus(newDate);
159
- break;
160
- }
161
-
162
- case 'PageUp':
163
- {
164
- newDate = normalizeDate(event.shiftKey ? subYears(focusDate, 1) : subMonths(focusDate, 1));
165
- if (minDate && isBefore(newDate, minDate)) newDate = minDate;
166
- setFocusDate(newDate);
167
- onDayFocus(newDate);
168
- break;
169
- }
170
-
171
- case 'PageDown':
172
- {
173
- newDate = normalizeDate(event.shiftKey ? addYears(focusDate, 1) : addMonths(focusDate, 1));
174
- if (maxDate && isAfter(newDate, maxDate)) newDate = maxDate;
175
- setFocusDate(newDate);
176
- onDayFocus(newDate);
177
- break;
178
- }
179
-
180
- default:
181
- {
182
- break;
183
- }
184
- }
185
-
186
- return (_datePanelRef$current = (_datePanelRef$current2 = datePanelRef.current) === null || _datePanelRef$current2 === void 0 ? void 0 : _datePanelRef$current2.querySelector(`[data-date="${format(newDate, 'MM/dd/yyyy')}"]`)) !== null && _datePanelRef$current !== void 0 ? _datePanelRef$current : undefined;
187
- }, [configuration, onDayFocus, setFocusDate]);
188
- useFocusZone({
189
- containerRef: datePanelRef,
190
- bindKeys: FocusKeys.ArrowAll | FocusKeys.HomeAndEnd | FocusKeys.PageUpDown,
191
- focusInStrategy: 'previous',
192
- getNextFocusable
193
- }, [getNextFocusable]);
194
- useFocusZone({
195
- containerRef: footerRef,
196
- bindKeys: FocusKeys.Tab,
197
- focusInStrategy: 'closest'
198
- });
199
- const previousDisabled = useMemo(() => {
200
- const {
201
- minDate
202
- } = configuration;
203
- if (!minDate) return false;
204
- const previous = subMonths(currentViewingDate, 1);
205
-
206
- if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
207
- return true;
208
- }
209
-
210
- return false;
211
- }, [configuration, currentViewingDate]);
212
- const nextDisabled = useMemo(() => {
213
- const {
214
- maxDate,
215
- view
216
- } = configuration;
217
- if (!maxDate) return false;
218
- const next = addMonths(currentViewingDate, view === '2-month' ? 2 : 1);
219
-
220
- if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
221
- return true;
222
- }
223
-
224
- return false;
225
- }, [configuration, currentViewingDate]);
226
- const currentMonth = useMemo(() => currentViewingDate.getMonth(), [currentViewingDate]);
227
- const currentYear = useMemo(() => currentViewingDate.getFullYear(), [currentViewingDate]);
228
- const headerSelectionHandler = useCallback(e => {
229
- const selection = parseInt(e.currentTarget.value, 10);
230
-
231
- if (e.currentTarget.id === 'picker-header-year') {
232
- goToMonth(new Date(selection, currentMonth));
233
- } else {
234
- goToMonth(new Date(currentYear, selection));
235
- }
236
- }, [currentMonth, currentYear, goToMonth]);
237
- const getMonthPicker = useMemo(() => {
238
- const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
239
- const monthElements = [];
240
-
241
- for (let i = 0; i < months.length; i++) {
242
- monthElements.push( /*#__PURE__*/React.createElement(Option, {
243
- key: i,
244
- value: i
245
- }, months[i]));
246
- }
247
-
248
- return /*#__PURE__*/React.createElement(Select, {
249
- id: "picker-header-month",
250
- value: currentMonth,
251
- sx: {
252
- mr: '6px'
253
- },
254
- onChange: headerSelectionHandler
255
- }, monthElements);
256
- }, [currentMonth, headerSelectionHandler]);
257
- const getYearPicker = useMemo(() => {
258
- const years = [];
259
- const minYear = currentYear - 200;
260
- const maxYear = currentYear + 200;
261
-
262
- for (let i = minYear; i <= maxYear; i++) {
263
- years.push( /*#__PURE__*/React.createElement(Option, {
264
- key: i,
265
- value: i
266
- }, i));
267
- }
268
-
269
- return /*#__PURE__*/React.createElement(Select, {
270
- id: "picker-header-year",
271
- value: currentYear,
272
- onChange: headerSelectionHandler
273
- }, years);
274
- }, [currentYear, headerSelectionHandler]);
275
- return /*#__PURE__*/React.createElement(DatePickerPanelContainer, {
276
- ref: panelRef
277
- }, /*#__PURE__*/React.createElement(DatePickerTopNav, {
278
- ref: headerRef
279
- }, configuration.compressedHeader && /*#__PURE__*/React.createElement(Box, {
280
- sx: {
281
- flex: 1
282
- }
283
- }, getMonthPicker, getYearPicker), /*#__PURE__*/React.createElement(ArrowButton, {
284
- variant: "small",
285
- sx: {
286
- mr: 1
287
- },
288
- onClick: previousMonth,
289
- disabled: previousDisabled,
290
- "aria-label": "Previous Month",
291
- "aria-live": "polite"
292
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
293
- icon: ChevronLeftIcon,
294
- color: "fg.muted"
295
- })), /*#__PURE__*/React.createElement(ArrowButton, {
296
- variant: "small",
297
- onClick: nextMonth,
298
- disabled: nextDisabled,
299
- "aria-label": "Next Month",
300
- "aria-live": "polite"
301
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
302
- icon: ChevronRightIcon,
303
- color: "fg.muted"
304
- }))), /*#__PURE__*/React.createElement(DatePickerPanelMonths, {
305
- ref: datePanelRef
306
- }, /*#__PURE__*/React.createElement(Month, {
307
- date: currentViewingDate
308
- }), viewMode === '2-month' && /*#__PURE__*/React.createElement(Month, {
309
- date: addMonths(currentViewingDate, 1)
310
- })), /*#__PURE__*/React.createElement(DatePickerPanelFooter, {
311
- ref: footerRef
312
- }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Button, {
313
- variant: "small",
314
- sx: {
315
- mr: 1
316
- },
317
- onClick: () => revertValue(),
318
- "aria-label": "Reset Selection",
319
- "aria-live": "polite"
320
- }, "Reset"), /*#__PURE__*/React.createElement(Button, {
321
- variant: "small",
322
- onClick: () => goToMonth(new Date()),
323
- "aria-label": "Go to Today",
324
- "aria-live": "polite"
325
- }, "Today")), configuration.confirmation && /*#__PURE__*/React.createElement(ButtonPrimary, {
326
- variant: "small",
327
- onClick: () => saveValue(),
328
- "aria-label": "Apply Selection",
329
- "aria-live": "polite"
330
- }, "Apply")));
331
- };
332
- DatePickerPanel.displayName = "DatePickerPanel";
@@ -1,15 +0,0 @@
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>;