@primer/components 0.0.0-2021103235619 → 0.0.0-2021104151625
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 +27 -1
- package/dist/browser.esm.js +509 -505
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +112 -108
- 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/ActionList2/Description.d.ts +12 -0
- package/lib/ActionList2/Description.js +53 -0
- package/lib/ActionList2/Divider.d.ts +5 -0
- package/lib/ActionList2/Divider.js +35 -0
- package/lib/ActionList2/Group.d.ts +11 -0
- package/lib/ActionList2/Group.js +57 -0
- package/lib/ActionList2/Header.d.ts +26 -0
- package/lib/ActionList2/Header.js +55 -0
- package/lib/ActionList2/Item.d.ts +67 -0
- package/lib/ActionList2/Item.js +221 -0
- package/lib/ActionList2/LinkItem.d.ts +17 -0
- package/lib/ActionList2/LinkItem.js +57 -0
- package/lib/ActionList2/List.d.ts +26 -0
- package/lib/ActionList2/List.js +51 -0
- package/lib/ActionList2/Selection.d.ts +5 -0
- package/lib/ActionList2/Selection.js +70 -0
- package/lib/ActionList2/Visuals.d.ts +11 -0
- package/lib/ActionList2/Visuals.js +90 -0
- package/lib/ActionList2/index.d.ts +40 -0
- package/lib/ActionList2/index.js +47 -0
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib/Autocomplete/Autocomplete.d.ts +30 -32
- package/lib/Autocomplete/AutocompleteInput.d.ts +30 -32
- package/lib/Button/Button.d.ts +27 -27
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +45 -45
- package/lib/Button/ButtonDanger.d.ts +27 -27
- package/lib/Button/ButtonInvisible.d.ts +27 -27
- package/lib/Button/ButtonOutline.d.ts +27 -27
- package/lib/Button/ButtonPrimary.d.ts +27 -27
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +43 -43
- package/lib/Dialog.d.ts +46 -46
- package/lib/Dropdown.d.ts +178 -178
- package/lib/DropdownMenu/DropdownButton.d.ts +47 -47
- package/lib/FilterList.d.ts +42 -42
- 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 +246 -248
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +34 -32
- package/lib/TextInputWithTokens.js +102 -29
- package/lib/Timeline.d.ts +44 -44
- 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/experiments.d.ts +1 -0
- package/lib/experiments.js +18 -0
- package/lib/hooks/useResizeObserver.d.ts +1 -1
- package/lib/hooks/useResizeObserver.js +1 -1
- package/lib/sx.d.ts +10 -2
- package/lib/sx.js +8 -0
- package/lib/theme-preval.js +79 -0
- package/lib/theme.d.ts +78 -0
- package/lib/theme.js +3 -1
- package/lib/utils/create-slots.d.ts +17 -0
- package/lib/utils/create-slots.js +105 -0
- package/lib/utils/testing.d.ts +13 -0
- package/lib/utils/types/KeyPaths.d.ts +3 -0
- package/lib/utils/types/KeyPaths.js +1 -0
- package/lib/utils/use-force-update.d.ts +1 -0
- package/lib/utils/use-force-update.js +19 -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/ActionList2/Description.d.ts +12 -0
- package/lib-esm/ActionList2/Description.js +37 -0
- package/lib-esm/ActionList2/Divider.d.ts +5 -0
- package/lib-esm/ActionList2/Divider.js +23 -0
- package/lib-esm/ActionList2/Group.d.ts +11 -0
- package/lib-esm/ActionList2/Group.js +40 -0
- package/lib-esm/ActionList2/Header.d.ts +26 -0
- package/lib-esm/ActionList2/Header.js +44 -0
- package/lib-esm/ActionList2/Item.d.ts +67 -0
- package/lib-esm/ActionList2/Item.js +195 -0
- package/lib-esm/ActionList2/LinkItem.d.ts +17 -0
- package/lib-esm/ActionList2/LinkItem.js +43 -0
- package/lib-esm/ActionList2/List.d.ts +26 -0
- package/lib-esm/ActionList2/List.js +34 -0
- package/lib-esm/ActionList2/Selection.d.ts +5 -0
- package/lib-esm/ActionList2/Selection.js +52 -0
- package/lib-esm/ActionList2/Visuals.d.ts +11 -0
- package/lib-esm/ActionList2/Visuals.js +68 -0
- package/lib-esm/ActionList2/index.d.ts +40 -0
- package/lib-esm/ActionList2/index.js +33 -0
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib-esm/Autocomplete/Autocomplete.d.ts +30 -32
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +30 -32
- package/lib-esm/Button/Button.d.ts +27 -27
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +45 -45
- package/lib-esm/Button/ButtonDanger.d.ts +27 -27
- package/lib-esm/Button/ButtonInvisible.d.ts +27 -27
- package/lib-esm/Button/ButtonOutline.d.ts +27 -27
- package/lib-esm/Button/ButtonPrimary.d.ts +27 -27
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +43 -43
- package/lib-esm/Dialog.d.ts +46 -46
- package/lib-esm/Dropdown.d.ts +178 -178
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +47 -47
- package/lib-esm/FilterList.d.ts +42 -42
- 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 +246 -248
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +34 -32
- package/lib-esm/TextInputWithTokens.js +101 -30
- package/lib-esm/Timeline.d.ts +44 -44
- 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/experiments.d.ts +1 -0
- package/lib-esm/experiments.js +2 -0
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
- package/lib-esm/hooks/useResizeObserver.js +1 -1
- package/lib-esm/sx.d.ts +10 -2
- package/lib-esm/sx.js +3 -1
- package/lib-esm/theme-preval.js +79 -0
- package/lib-esm/theme.d.ts +78 -0
- package/lib-esm/theme.js +2 -1
- package/lib-esm/utils/create-slots.d.ts +17 -0
- package/lib-esm/utils/create-slots.js +84 -0
- package/lib-esm/utils/testing.d.ts +13 -0
- package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
- package/lib-esm/utils/types/KeyPaths.js +1 -0
- package/lib-esm/utils/use-force-update.d.ts +1 -0
- package/lib-esm/utils/use-force-update.js +6 -0
- package/package.json +12 -9
- package/lib/DatePicker/DatePicker.d.ts +0 -52
- package/lib/DatePicker/DatePicker.js +0 -109
- package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib/DatePicker/DatePickerAnchor.js +0 -202
- package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib/DatePicker/DatePickerOverlay.js +0 -55
- package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib/DatePicker/DatePickerPanel.js +0 -363
- package/lib/DatePicker/Day.d.ts +0 -15
- package/lib/DatePicker/Day.js +0 -206
- package/lib/DatePicker/Month.d.ts +0 -8
- package/lib/DatePicker/Month.js +0 -122
- package/lib/DatePicker/dateParser.d.ts +0 -12
- package/lib/DatePicker/dateParser.js +0 -192
- package/lib/DatePicker/index.d.ts +0 -2
- package/lib/DatePicker/index.js +0 -13
- package/lib/DatePicker/useDatePicker.d.ts +0 -107
- package/lib/DatePicker/useDatePicker.js +0 -558
- package/lib/hooks/useDebounce.d.ts +0 -2
- package/lib/hooks/useDebounce.js +0 -24
- package/lib-esm/DatePicker/DatePicker.d.ts +0 -52
- package/lib-esm/DatePicker/DatePicker.js +0 -92
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib-esm/DatePicker/DatePickerAnchor.js +0 -174
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib-esm/DatePicker/DatePickerOverlay.js +0 -40
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib-esm/DatePicker/DatePickerPanel.js +0 -332
- package/lib-esm/DatePicker/Day.d.ts +0 -15
- package/lib-esm/DatePicker/Day.js +0 -182
- package/lib-esm/DatePicker/Month.d.ts +0 -8
- package/lib-esm/DatePicker/Month.js +0 -98
- package/lib-esm/DatePicker/dateParser.d.ts +0 -12
- package/lib-esm/DatePicker/dateParser.js +0 -178
- package/lib-esm/DatePicker/index.d.ts +0 -2
- package/lib-esm/DatePicker/index.js +0 -1
- package/lib-esm/DatePicker/useDatePicker.d.ts +0 -107
- package/lib-esm/DatePicker/useDatePicker.js +0 -523
- package/lib-esm/hooks/useDebounce.d.ts +0 -2
- 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' && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
|
169
|
-
sx: {
|
170
|
-
overflow: 'hidden',
|
171
|
-
textOverflow: 'ellipsis'
|
172
|
-
}
|
173
|
-
}, formattedDate), iconPlacement === 'end' && calendarIcon()));
|
174
|
-
});
|
@@ -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,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>;
|