@primer/components 0.0.0-20219293614 → 0.0.0-2021931194230

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 (142) hide show
  1. package/CHANGELOG.md +1 -7
  2. package/dist/browser.esm.js +439 -436
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +443 -440
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.d.ts +0 -6
  7. package/lib/ActionList/Item.js +1 -5
  8. package/lib/ActionMenu.js +2 -2
  9. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  10. package/lib/Autocomplete/Autocomplete.d.ts +13 -11
  11. package/lib/Autocomplete/AutocompleteInput.d.ts +13 -11
  12. package/lib/Button/Button.d.ts +11 -11
  13. package/lib/Button/ButtonBase.d.ts +1 -1
  14. package/lib/Button/ButtonClose.d.ts +29 -29
  15. package/lib/Button/ButtonDanger.d.ts +11 -11
  16. package/lib/Button/ButtonInvisible.d.ts +11 -11
  17. package/lib/Button/ButtonOutline.d.ts +11 -11
  18. package/lib/Button/ButtonPrimary.d.ts +11 -11
  19. package/lib/Button/ButtonStyles.js +1 -1
  20. package/lib/CircleBadge.d.ts +2 -2
  21. package/lib/CircleOcticon.d.ts +33 -33
  22. package/lib/DatePicker/DatePicker.d.ts +48 -0
  23. package/lib/DatePicker/DatePicker.js +106 -0
  24. package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
  25. package/lib/DatePicker/DatePickerAnchor.js +223 -0
  26. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  27. package/lib/DatePicker/DatePickerOverlay.js +48 -0
  28. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  29. package/lib/DatePicker/DatePickerPanel.js +143 -0
  30. package/lib/DatePicker/Day.d.ts +14 -0
  31. package/lib/DatePicker/Day.js +192 -0
  32. package/lib/DatePicker/Month.d.ts +9 -0
  33. package/lib/DatePicker/Month.js +122 -0
  34. package/lib/DatePicker/dateParser.d.ts +11 -0
  35. package/lib/DatePicker/dateParser.js +192 -0
  36. package/lib/DatePicker/index.d.ts +2 -0
  37. package/lib/DatePicker/index.js +13 -0
  38. package/lib/DatePicker/useDatePicker.d.ts +89 -0
  39. package/lib/DatePicker/useDatePicker.js +439 -0
  40. package/lib/Dialog/Dialog.d.ts +4 -4
  41. package/lib/Dialog/Dialog.js +22 -12
  42. package/lib/Dialog.d.ts +35 -35
  43. package/lib/Dropdown.d.ts +165 -85
  44. package/lib/Dropdown.js +5 -6
  45. package/lib/DropdownMenu/DropdownButton.d.ts +30 -30
  46. package/lib/FilterList.d.ts +26 -26
  47. package/lib/Label.d.ts +1 -1
  48. package/lib/Position.d.ts +4 -4
  49. package/lib/ProgressBar.d.ts +1 -1
  50. package/lib/SelectMenu/SelectMenu.d.ts +153 -151
  51. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  52. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  53. package/lib/TextInputWithTokens.d.ts +13 -11
  54. package/lib/Timeline.d.ts +33 -33
  55. package/lib/Token/AvatarToken.d.ts +1 -1
  56. package/lib/Token/IssueLabelToken.d.ts +1 -1
  57. package/lib/Token/Token.d.ts +1 -1
  58. package/lib/_TextInputWrapper.d.ts +1 -1
  59. package/lib/constants.js +1 -3
  60. package/lib/hooks/useDebounce.d.ts +2 -0
  61. package/lib/hooks/useDebounce.js +24 -0
  62. package/lib/hooks/useResizeObserver.d.ts +1 -1
  63. package/lib/hooks/useResizeObserver.js +1 -1
  64. package/lib/index.d.ts +0 -2
  65. package/lib/index.js +0 -8
  66. package/lib/theme-preval.js +2 -2
  67. package/lib/utils/testing.d.ts +1 -1
  68. package/lib-esm/ActionList/Item.d.ts +0 -6
  69. package/lib-esm/ActionList/Item.js +1 -5
  70. package/lib-esm/ActionMenu.js +2 -2
  71. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  72. package/lib-esm/Autocomplete/Autocomplete.d.ts +13 -11
  73. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +13 -11
  74. package/lib-esm/Button/Button.d.ts +11 -11
  75. package/lib-esm/Button/ButtonBase.d.ts +1 -1
  76. package/lib-esm/Button/ButtonClose.d.ts +29 -29
  77. package/lib-esm/Button/ButtonDanger.d.ts +11 -11
  78. package/lib-esm/Button/ButtonInvisible.d.ts +11 -11
  79. package/lib-esm/Button/ButtonOutline.d.ts +11 -11
  80. package/lib-esm/Button/ButtonPrimary.d.ts +11 -11
  81. package/lib-esm/Button/ButtonStyles.js +1 -1
  82. package/lib-esm/CircleBadge.d.ts +2 -2
  83. package/lib-esm/CircleOcticon.d.ts +33 -33
  84. package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
  85. package/lib-esm/DatePicker/DatePicker.js +89 -0
  86. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
  87. package/lib-esm/DatePicker/DatePickerAnchor.js +196 -0
  88. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  89. package/lib-esm/DatePicker/DatePickerOverlay.js +29 -0
  90. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  91. package/lib-esm/DatePicker/DatePickerPanel.js +116 -0
  92. package/lib-esm/DatePicker/Day.d.ts +14 -0
  93. package/lib-esm/DatePicker/Day.js +169 -0
  94. package/lib-esm/DatePicker/Month.d.ts +9 -0
  95. package/lib-esm/DatePicker/Month.js +98 -0
  96. package/lib-esm/DatePicker/dateParser.d.ts +11 -0
  97. package/lib-esm/DatePicker/dateParser.js +178 -0
  98. package/lib-esm/DatePicker/index.d.ts +2 -0
  99. package/lib-esm/DatePicker/index.js +1 -0
  100. package/lib-esm/DatePicker/useDatePicker.d.ts +89 -0
  101. package/lib-esm/DatePicker/useDatePicker.js +408 -0
  102. package/lib-esm/Dialog/Dialog.d.ts +4 -4
  103. package/lib-esm/Dialog/Dialog.js +21 -12
  104. package/lib-esm/Dialog.d.ts +35 -35
  105. package/lib-esm/Dropdown.d.ts +165 -85
  106. package/lib-esm/Dropdown.js +3 -4
  107. package/lib-esm/DropdownMenu/DropdownButton.d.ts +30 -30
  108. package/lib-esm/FilterList.d.ts +26 -26
  109. package/lib-esm/Label.d.ts +1 -1
  110. package/lib-esm/Position.d.ts +4 -4
  111. package/lib-esm/ProgressBar.d.ts +1 -1
  112. package/lib-esm/SelectMenu/SelectMenu.d.ts +153 -151
  113. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  114. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  115. package/lib-esm/TextInputWithTokens.d.ts +13 -11
  116. package/lib-esm/Timeline.d.ts +33 -33
  117. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  118. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  119. package/lib-esm/Token/Token.d.ts +1 -1
  120. package/lib-esm/_TextInputWrapper.d.ts +1 -1
  121. package/lib-esm/constants.js +1 -3
  122. package/lib-esm/hooks/useDebounce.d.ts +2 -0
  123. package/lib-esm/hooks/useDebounce.js +16 -0
  124. package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
  125. package/lib-esm/hooks/useResizeObserver.js +1 -1
  126. package/lib-esm/index.d.ts +0 -2
  127. package/lib-esm/index.js +0 -1
  128. package/lib-esm/theme-preval.js +2 -2
  129. package/lib-esm/utils/testing.d.ts +1 -1
  130. package/package.json +14 -13
  131. package/lib/NewButton/button.d.ts +0 -579
  132. package/lib/NewButton/button.js +0 -298
  133. package/lib/NewButton/counter.d.ts +0 -6
  134. package/lib/NewButton/counter.js +0 -33
  135. package/lib/NewButton/index.d.ts +0 -4
  136. package/lib/NewButton/index.js +0 -21
  137. package/lib-esm/NewButton/button.d.ts +0 -579
  138. package/lib-esm/NewButton/button.js +0 -274
  139. package/lib-esm/NewButton/counter.d.ts +0 -6
  140. package/lib-esm/NewButton/counter.js +0 -21
  141. package/lib-esm/NewButton/index.d.ts +0 -4
  142. package/lib-esm/NewButton/index.js +0 -3
@@ -0,0 +1,89 @@
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
+ dateFormat,
11
+ disableWeekends,
12
+ focusTrapSettings,
13
+ focusZoneSettings,
14
+ iconPlacement,
15
+ maxDate,
16
+ maxRangeSize,
17
+ maxSelections,
18
+ minDate,
19
+ onOpen: onOpenExternal,
20
+ onClose: onCloseExternal,
21
+ open,
22
+ overlayProps,
23
+ placeholder,
24
+ renderAnchor,
25
+ showInputPrompt,
26
+ value,
27
+ variant,
28
+ view,
29
+ weekStartsOn
30
+ }) => {
31
+ const anchorRef = useRef(null);
32
+ const [isOpen, setIsOpen] = useState(false);
33
+ const datePickerConfiguration = {
34
+ anchorVariant,
35
+ confirmation,
36
+ confirmUnsavedClose,
37
+ dateFormat,
38
+ disableWeekends,
39
+ iconPlacement,
40
+ maxDate: maxDate ? new Date(new Date(maxDate).toDateString()) : maxDate,
41
+ maxRangeSize,
42
+ maxSelections,
43
+ minDate: minDate ? new Date(new Date(minDate).toDateString()) : minDate,
44
+ placeholder,
45
+ showInputPrompt,
46
+ variant,
47
+ view,
48
+ weekStartsOn
49
+ };
50
+
51
+ const onOpen = gesture => {
52
+ setIsOpen(true);
53
+ onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
54
+ };
55
+
56
+ const onClose = gesture => {
57
+ setIsOpen(false);
58
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
59
+ };
60
+
61
+ const toggleIsOpen = () => {
62
+ if (isOpen) {
63
+ setIsOpen(false);
64
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
65
+ } else {
66
+ setIsOpen(true);
67
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
68
+ }
69
+ };
70
+
71
+ return /*#__PURE__*/React.createElement(DatePickerProvider, {
72
+ configuration: datePickerConfiguration,
73
+ value: value,
74
+ closePicker: () => setIsOpen(false)
75
+ }, /*#__PURE__*/React.createElement(DatePickerAnchor, {
76
+ ref: anchorRef,
77
+ onAction: toggleIsOpen
78
+ }), /*#__PURE__*/React.createElement(DatePickerOverlay, {
79
+ anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : anchorRef,
80
+ renderAnchor: renderAnchor,
81
+ open: open !== null && open !== void 0 ? open : isOpen,
82
+ onOpen: onOpen,
83
+ onClose: onClose,
84
+ overlayProps: overlayProps,
85
+ focusTrapSettings: focusTrapSettings,
86
+ focusZoneSettings: focusZoneSettings
87
+ }));
88
+ };
89
+ DatePicker.displayName = "DatePicker";
@@ -0,0 +1,5 @@
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>>;
@@ -0,0 +1,196 @@
1
+ import { CalendarIcon } 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
+ const DatePickerAnchorButton = styled(Button).withConfig({
13
+ displayName: "DatePickerAnchor__DatePickerAnchorButton",
14
+ componentId: "sc-8gpb9d-0"
15
+ })(["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'));
16
+ export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
17
+ onAction
18
+ }, ref) => {
19
+ const {
20
+ configuration: {
21
+ anchorVariant,
22
+ iconPlacement,
23
+ placeholder,
24
+ showInputPrompt,
25
+ variant
26
+ },
27
+ disabled,
28
+ formattedDate,
29
+ onDateInput
30
+ } = useDatePicker();
31
+ const [inputValue, setInputValue] = useState(formattedDate);
32
+ const inputRef = useRef(null);
33
+ const [inputValid, setInputValid] = useState(true);
34
+ const keyPressHandler = useCallback(event => {
35
+ if (disabled) {
36
+ return;
37
+ }
38
+
39
+ if ([' ', 'Enter'].includes(event.key)) {
40
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
41
+ }
42
+ }, [disabled, onAction]);
43
+ const clickHandler = useCallback(event => {
44
+ if (disabled) {
45
+ return;
46
+ }
47
+
48
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
49
+ }, [disabled, onAction]);
50
+ useEffect(() => {
51
+ if (document.activeElement !== inputRef.current) {
52
+ setInputValue(formattedDate);
53
+ }
54
+ }, [formattedDate]);
55
+ const onInputChangeHandler = useCallback(e => {
56
+ const value = e.currentTarget.value;
57
+ setInputValue(value);
58
+
59
+ if (!value) {
60
+ return;
61
+ }
62
+
63
+ const parsedDate = parseDate(value, variant);
64
+ setInputValid(!!parsedDate);
65
+
66
+ if (parsedDate) {
67
+ onDateInput(parsedDate);
68
+ }
69
+ }, [onDateInput, variant]);
70
+
71
+ const onBlurHandler = () => {
72
+ setInputValue(formattedDate);
73
+ };
74
+
75
+ const inputSx = useMemo(() => {
76
+ let sxObject = {};
77
+
78
+ if (iconPlacement === 'start') {
79
+ sxObject = { ...sxObject,
80
+ pl: 5,
81
+ pr: 2
82
+ };
83
+ } else if (iconPlacement === 'end') {
84
+ sxObject = { ...sxObject,
85
+ pl: 2,
86
+ pr: 5
87
+ };
88
+ }
89
+
90
+ if (showInputPrompt) {
91
+ sxObject = { ...sxObject,
92
+ pt: '20px'
93
+ };
94
+ }
95
+
96
+ if (inputValid) {
97
+ sxObject = { ...sxObject,
98
+ color: 'success.emphasis'
99
+ };
100
+ } else {
101
+ sxObject = { ...sxObject,
102
+ color: 'danger.emphasis'
103
+ };
104
+ }
105
+
106
+ return sxObject;
107
+ }, [iconPlacement, inputValid, showInputPrompt]);
108
+ const inputPrompt = useMemo(() => {
109
+ if (!showInputPrompt) return;
110
+
111
+ switch (variant) {
112
+ case 'single':
113
+ return 'MM/DD/YYYY';
114
+
115
+ case 'multi':
116
+ return 'MM/DD/YYYY, MM/DD/YYYY, ...';
117
+
118
+ case 'range':
119
+ return 'MM/DD/YYYY - MM/DD/YYYY';
120
+
121
+ default:
122
+ return 'MM/DD/YYYY';
123
+ }
124
+ }, [showInputPrompt, variant]);
125
+
126
+ if (anchorVariant === 'input') {
127
+ const calendarButton = side => /*#__PURE__*/React.createElement(ButtonInvisible, {
128
+ onClick: clickHandler,
129
+ sx: {
130
+ width: '32px',
131
+ px: '6px',
132
+ position: 'absolute',
133
+ [side]: '1px',
134
+ top: '1px',
135
+ bottom: '1px'
136
+ }
137
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
138
+ icon: CalendarIcon
139
+ }));
140
+
141
+ const promptSx = () => {
142
+ let sxObject = {
143
+ position: 'absolute',
144
+ top: '2px',
145
+ fontSize: '11px',
146
+ color: 'fg.subtle'
147
+ };
148
+
149
+ if (iconPlacement === 'start') {
150
+ sxObject = { ...sxObject,
151
+ left: '36px'
152
+ };
153
+ }
154
+
155
+ return sxObject;
156
+ };
157
+
158
+ return /*#__PURE__*/React.createElement(Box, {
159
+ ref: ref,
160
+ sx: {
161
+ position: 'relative',
162
+ display: 'flex',
163
+ flex: 1
164
+ }
165
+ }, iconPlacement === 'start' && calendarButton('left'), showInputPrompt && /*#__PURE__*/React.createElement(Text, {
166
+ sx: promptSx()
167
+ }, inputPrompt), /*#__PURE__*/React.createElement(TextInput, {
168
+ ref: inputRef,
169
+ placeholder: placeholder,
170
+ value: inputValue,
171
+ onChange: onInputChangeHandler,
172
+ sx: inputSx,
173
+ onBlur: onBlurHandler
174
+ }), iconPlacement === 'end' && calendarButton('right'));
175
+ }
176
+
177
+ const calendarIcon = () => /*#__PURE__*/React.createElement(StyledOcticon, {
178
+ icon: CalendarIcon,
179
+ color: "fg.muted",
180
+ sx: {
181
+ my: '2px'
182
+ }
183
+ });
184
+
185
+ return /*#__PURE__*/React.createElement(Box, {
186
+ ref: ref
187
+ }, /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
188
+ onClick: clickHandler,
189
+ onKeyPress: keyPressHandler
190
+ }, iconPlacement === 'start' && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
191
+ sx: {
192
+ overflow: 'hidden',
193
+ textOverflow: 'ellipsis'
194
+ }
195
+ }, formattedDate), iconPlacement === 'end' && calendarIcon()));
196
+ });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { AnchoredOverlayProps } from '../AnchoredOverlay';
3
+ export declare const DatePickerOverlay: React.FC<AnchoredOverlayProps>;
@@ -0,0 +1,29 @@
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, { useState } 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
+ onClose: onDatePickerClose
13
+ } = useDatePicker();
14
+ const [suspendFocusTrap, setSuspendFocusTrap] = useState(false);
15
+
16
+ const onOverlayClose = async gesture => {
17
+ if (!suspendFocusTrap) {
18
+ setSuspendFocusTrap(true);
19
+ await onDatePickerClose();
20
+ setSuspendFocusTrap(false);
21
+ onClose === null || onClose === void 0 ? void 0 : onClose(gesture);
22
+ }
23
+ };
24
+
25
+ return /*#__PURE__*/React.createElement(AnchoredOverlay, _extends({
26
+ onClose: onOverlayClose
27
+ }, rest), /*#__PURE__*/React.createElement(DatePickerPanel, null));
28
+ };
29
+ DatePickerOverlay.displayName = "DatePickerOverlay";
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const DatePickerPanel: () => JSX.Element;
@@ -0,0 +1,116 @@
1
+ import { addMonths, subMonths } from 'date-fns';
2
+ import React, { useMemo, useRef, useState } from 'react';
3
+ import Box from '../Box';
4
+ import { Month } from './Month';
5
+ import styled from 'styled-components';
6
+ import { get } from '../constants';
7
+ import useDatePicker from './useDatePicker';
8
+ import { ChevronLeftIcon, ChevronRightIcon } from '@primer/octicons-react';
9
+ import StyledOcticon from '../StyledOcticon';
10
+ import Button, { ButtonPrimary } from '../Button';
11
+ import { useResizeObserver } from '../hooks/useResizeObserver';
12
+ const DatePickerPanelContainer = styled(Box).withConfig({
13
+ displayName: "DatePickerPanel__DatePickerPanelContainer",
14
+ componentId: "sc-19upxpo-0"
15
+ })(["align-items:stretch;display:flex;flex-direction:column;"]);
16
+ const DatePickerPanelMonths = styled(Box).withConfig({
17
+ displayName: "DatePickerPanel__DatePickerPanelMonths",
18
+ componentId: "sc-19upxpo-1"
19
+ })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";position:relative;"], get('space.6'), get('space.3'));
20
+ const DatePickerPanelFooter = styled(Box).withConfig({
21
+ displayName: "DatePickerPanel__DatePickerPanelFooter",
22
+ componentId: "sc-19upxpo-2"
23
+ })(["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'));
24
+ const ArrowButton = styled(Button).withConfig({
25
+ displayName: "DatePickerPanel__ArrowButton",
26
+ componentId: "sc-19upxpo-3"
27
+ })(["position:absolute;width:40px;height:28px;top:12px;", ";"], props => `${props.side}: ${get('space.3')(props)}`);
28
+ export const DatePickerPanel = () => {
29
+ const {
30
+ configuration,
31
+ saveValue,
32
+ revertValue,
33
+ currentViewingDate,
34
+ goToMonth,
35
+ nextMonth,
36
+ previousMonth
37
+ } = useDatePicker();
38
+ const [multiMonthSupport, setMultiMonthSupport] = useState(true);
39
+ const panelRef = useRef(null);
40
+
41
+ const onResize = windowEntry => {
42
+ // Only care about the first element, we expect one element ot be watched
43
+ const {
44
+ width
45
+ } = windowEntry.contentRect; // 610 is the panel width with 2 months
46
+
47
+ setMultiMonthSupport(width > 610);
48
+ };
49
+
50
+ useResizeObserver(onResize);
51
+ const previousDisabled = useMemo(() => {
52
+ const {
53
+ minDate
54
+ } = configuration;
55
+ if (!minDate) return false;
56
+ const previous = subMonths(currentViewingDate, 1);
57
+
58
+ if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
59
+ return true;
60
+ }
61
+
62
+ return false;
63
+ }, [configuration, currentViewingDate]);
64
+ const nextDisabled = useMemo(() => {
65
+ const {
66
+ maxDate,
67
+ view
68
+ } = configuration;
69
+ if (!maxDate) return false;
70
+ const next = addMonths(currentViewingDate, view === '2-month' ? 2 : 1);
71
+
72
+ if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
73
+ return true;
74
+ }
75
+
76
+ return false;
77
+ }, [configuration, currentViewingDate]);
78
+ return /*#__PURE__*/React.createElement(DatePickerPanelContainer, {
79
+ ref: panelRef
80
+ }, /*#__PURE__*/React.createElement(DatePickerPanelMonths, null, /*#__PURE__*/React.createElement(ArrowButton, {
81
+ variant: "small",
82
+ side: "left",
83
+ onClick: previousMonth,
84
+ disabled: previousDisabled
85
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
86
+ icon: ChevronLeftIcon,
87
+ color: "fg.muted"
88
+ })), /*#__PURE__*/React.createElement(Month, {
89
+ month: currentViewingDate.getMonth(),
90
+ year: currentViewingDate.getFullYear()
91
+ }), configuration.view === '2-month' && multiMonthSupport && /*#__PURE__*/React.createElement(Month, {
92
+ month: addMonths(currentViewingDate, 1).getMonth(),
93
+ year: addMonths(currentViewingDate, 1).getFullYear()
94
+ }), /*#__PURE__*/React.createElement(ArrowButton, {
95
+ variant: "small",
96
+ side: "right",
97
+ onClick: nextMonth,
98
+ disabled: nextDisabled
99
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
100
+ icon: ChevronRightIcon,
101
+ color: "fg.muted"
102
+ }))), /*#__PURE__*/React.createElement(DatePickerPanelFooter, null, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Button, {
103
+ variant: "small",
104
+ sx: {
105
+ mr: 1
106
+ },
107
+ onClick: () => revertValue()
108
+ }, "Reset"), /*#__PURE__*/React.createElement(Button, {
109
+ variant: "small",
110
+ onClick: () => goToMonth(new Date())
111
+ }, "Today")), configuration.confirmation && /*#__PURE__*/React.createElement(ButtonPrimary, {
112
+ variant: "small",
113
+ onClick: () => saveValue()
114
+ }, "Apply")));
115
+ };
116
+ DatePickerPanel.displayName = "DatePickerPanel";
@@ -0,0 +1,14 @@
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
+ onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
10
+ selected?: DaySelection;
11
+ date: Date;
12
+ } & FontSizeProps & SystemCommonProps & SxProp & SystemLayoutProps;
13
+ export declare const Day: React.FC<DayProps>;
14
+ 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,169 @@
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import styled from 'styled-components';
3
+ import Box from '../Box';
4
+ import Text from '../Text';
5
+ import { get } from '../constants';
6
+ import useDatePicker from './useDatePicker';
7
+ const DayBaseComponent = styled(Box).withConfig({
8
+ displayName: "Day__DayBaseComponent",
9
+ componentId: "sc-1japneh-0"
10
+ })(["align-content:center;display:flex;justify-content:center;min-width:38px;min-height:38px;padding:", ";"], get('space.1'));
11
+ const states = {
12
+ blocked: {
13
+ background: get('colors.neutral.subtle'),
14
+ borderRadius: get('radii.2'),
15
+ color: get('colors.fg.subtle')
16
+ },
17
+ disabled: {
18
+ background: get('colors.canvas.primary'),
19
+ borderRadius: get('radii.2'),
20
+ color: get('colors.fg.subtle')
21
+ },
22
+ selected: {
23
+ default: {
24
+ background: get('colors.accent.emphasis'),
25
+ borderRadius: get('radii.2'),
26
+ color: get('colors.fg.onEmphasis'),
27
+ todayColor: get('colors.fg.onEmphasis')
28
+ },
29
+ start: {
30
+ background: get('colors.accent.emphasis'),
31
+ borderRadius: '4px 0 0 4px',
32
+ color: get('colors.fg.onEmphasis'),
33
+ todayColor: get('colors.fg.onEmphasis')
34
+ },
35
+ middle: {
36
+ background: get('colors.accent.subtle'),
37
+ borderRadius: '0',
38
+ color: get('colors.fg.default'),
39
+ todayColor: get('colors.accent.fg')
40
+ },
41
+ end: {
42
+ background: get('colors.accent.emphasis'),
43
+ borderRadius: '0 4px 4px 0',
44
+ color: get('colors.fg.onEmphasis'),
45
+ todayColor: get('colors.fg.onEmphasis')
46
+ }
47
+ },
48
+ default: {
49
+ normal: {
50
+ background: get('colors.canvas.primary'),
51
+ borderRadius: get('radii.2'),
52
+ color: get('colors.fg.default'),
53
+ todayColor: get('colors.accent.fg')
54
+ },
55
+ hover: {
56
+ background: get('colors.neutral.muted'),
57
+ borderRadius: get('radii.2'),
58
+ color: get('colors.fg.default'),
59
+ todayColor: get('colors.accent.fg')
60
+ },
61
+ pressed: {
62
+ background: get('colors.neutral.emphasis'),
63
+ borderRadius: get('radii.2'),
64
+ color: get('colors.fg.onEmphasis'),
65
+ todayColor: get('colors.fg.onEmphasis')
66
+ }
67
+ }
68
+ };
69
+
70
+ const getStateStyles = (props, prop, state) => {
71
+ const {
72
+ blocked,
73
+ disabled,
74
+ selected,
75
+ today
76
+ } = props;
77
+
78
+ if (blocked) {
79
+ return states.blocked[prop];
80
+ } else if (disabled) {
81
+ return states.disabled[prop];
82
+ } else if (selected) {
83
+ switch (selected) {
84
+ case 'start':
85
+ return today && prop === 'color' ? states.selected.start['todayColor'] : states.selected.start[prop];
86
+
87
+ case 'middle':
88
+ return today && prop === 'color' ? states.selected.middle['todayColor'] : states.selected.middle[prop];
89
+
90
+ case 'end':
91
+ return today && prop === 'color' ? states.selected.end['todayColor'] : states.selected.end[prop];
92
+
93
+ default:
94
+ return today && prop === 'color' ? states.selected.default['todayColor'] : states.selected.default[prop];
95
+ }
96
+ } else {
97
+ return today && prop === 'color' ? states.default[state]['todayColor'] : states.default[state][prop];
98
+ }
99
+ };
100
+
101
+ const DayComponent = styled(DayBaseComponent).attrs(props => ({
102
+ background: getStateStyles(props, 'background', 'normal'),
103
+ borderRadius: getStateStyles(props, 'borderRadius', 'normal'),
104
+ textColor: getStateStyles(props, 'color', 'normal'),
105
+ backgroundHover: getStateStyles(props, 'background', 'hover'),
106
+ textColorHover: getStateStyles(props, 'color', 'hover'),
107
+ backgroundPressed: getStateStyles(props, 'background', 'pressed'),
108
+ textColorPressed: getStateStyles(props, 'color', 'pressed')
109
+ })).withConfig({
110
+ displayName: "Day__DayComponent",
111
+ componentId: "sc-1japneh-1"
112
+ })(["background-color:", ";border-radius:", ";transition:0.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-self:center;user-select:none;transition:0.1s color ease;}&:hover{background-color:", ";cursor:pointer;transition:0.05s background-color ease;& ", "{color:", ";transition:0.1s color ease;}}&:active{background-color:", ";box-shadow:inset ", ";transition:0.1s background-color ease,0.1s box-shadow ease,0.1s color ease;& ", "{color:", ";transition:0.1s color ease;}}"], props => props.background, props => props.borderRadius, Text, props => props.textColor, get('fonts.mono'), get('fontSizes.0'), props => props.backgroundHover, Text, props => props.textColorHover, props => props.backgroundPressed, get('shadows.shadow.medium'), Text, props => props.textColorPressed);
113
+ export const Day = ({
114
+ date,
115
+ onAction
116
+ }) => {
117
+ const {
118
+ onDayFocus,
119
+ onSelection,
120
+ disabled,
121
+ blocked,
122
+ selected,
123
+ today
124
+ } = useDatePicker(date);
125
+ const keyPressHandler = useCallback(event => {
126
+ if (disabled) {
127
+ return;
128
+ }
129
+
130
+ if ([' ', 'Enter'].includes(event.key)) {
131
+ onSelection(date);
132
+ onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
133
+ }
134
+ }, [disabled, onSelection, onAction, date]);
135
+ const clickHandler = useCallback(event => {
136
+ if (disabled) {
137
+ return;
138
+ }
139
+
140
+ onSelection(date);
141
+ onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
142
+ }, [disabled, onSelection, date, onAction]);
143
+ const todayStyles = useMemo(() => today ? {
144
+ border: '2px solid',
145
+ padding: '4px 6px',
146
+ borderRadius: '16px',
147
+ fontWeight: 'bold'
148
+ } : {}, [today]);
149
+ return /*#__PURE__*/React.createElement(DayComponent, {
150
+ role: "gridcell",
151
+ "aria-disabled": disabled,
152
+ "aria-selected": selected !== false,
153
+ blocked: blocked,
154
+ disabled: disabled,
155
+ selected: selected,
156
+ today: today,
157
+ onClick: clickHandler,
158
+ onMouseEnter: () => onDayFocus(date),
159
+ onFocus: () => onDayFocus(date),
160
+ onKeyPress: keyPressHandler
161
+ }, /*#__PURE__*/React.createElement(Text, {
162
+ sx: todayStyles
163
+ }, date.getDate()));
164
+ };
165
+ Day.displayName = "Day";
166
+ export const BlankDay = styled(DayBaseComponent).withConfig({
167
+ displayName: "Day__BlankDay",
168
+ componentId: "sc-1japneh-2"
169
+ })(["background-color:", ";"], get('colors.canvas.primary'));
@@ -0,0 +1,9 @@
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
+ month: number;
7
+ year: number;
8
+ }
9
+ export declare const Month: React.FC<MonthProps>;