@primer/components 0.0.0-202192822657 → 0.0.0-2021929142717

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 (166) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/browser.esm.js +53 -49
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +50 -46
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.d.ts +6 -0
  7. package/lib/ActionList/Item.js +5 -1
  8. package/lib/ActionList2/Description.d.ts +6 -0
  9. package/lib/ActionList2/Description.js +53 -0
  10. package/lib/ActionList2/Divider.d.ts +5 -0
  11. package/lib/ActionList2/Divider.js +33 -0
  12. package/lib/ActionList2/Group.d.ts +11 -0
  13. package/lib/ActionList2/Group.js +55 -0
  14. package/lib/ActionList2/Header.d.ts +26 -0
  15. package/lib/ActionList2/Header.js +55 -0
  16. package/lib/ActionList2/Item.d.ts +48 -0
  17. package/lib/ActionList2/Item.js +204 -0
  18. package/lib/ActionList2/List.d.ts +26 -0
  19. package/lib/ActionList2/List.js +56 -0
  20. package/lib/ActionList2/Selection.d.ts +5 -0
  21. package/lib/ActionList2/Selection.js +73 -0
  22. package/lib/ActionList2/Visuals.d.ts +11 -0
  23. package/lib/ActionList2/Visuals.js +90 -0
  24. package/lib/ActionList2/hacks.d.ts +30 -0
  25. package/lib/ActionList2/hacks.js +38 -0
  26. package/lib/ActionList2/index.d.ts +28 -0
  27. package/lib/ActionList2/index.js +42 -0
  28. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  29. package/lib/Autocomplete/Autocomplete.d.ts +6 -8
  30. package/lib/Autocomplete/AutocompleteInput.d.ts +6 -8
  31. package/lib/Button/Button.d.ts +4 -4
  32. package/lib/Button/ButtonClose.d.ts +21 -21
  33. package/lib/Button/ButtonDanger.d.ts +4 -4
  34. package/lib/Button/ButtonInvisible.d.ts +4 -4
  35. package/lib/Button/ButtonOutline.d.ts +4 -4
  36. package/lib/Button/ButtonPrimary.d.ts +4 -4
  37. package/lib/CircleOcticon.d.ts +19 -19
  38. package/lib/Dialog.d.ts +21 -21
  39. package/lib/Dropdown.d.ts +82 -82
  40. package/lib/DropdownMenu/DropdownButton.d.ts +23 -23
  41. package/lib/FilterList.d.ts +19 -19
  42. package/lib/Position.d.ts +4 -4
  43. package/lib/SelectMenu/SelectMenu.d.ts +105 -107
  44. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  45. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  46. package/lib/TextInputWithTokens.d.ts +10 -8
  47. package/lib/TextInputWithTokens.js +102 -29
  48. package/lib/Timeline.d.ts +19 -19
  49. package/lib/Token/AvatarToken.d.ts +1 -1
  50. package/lib/Token/IssueLabelToken.d.ts +1 -1
  51. package/lib/Token/Token.d.ts +1 -1
  52. package/lib/Token/Token.js +13 -2
  53. package/lib/Token/TokenBase.js +0 -4
  54. package/lib/Token/_RemoveTokenButton.js +15 -2
  55. package/lib/_TextInputWrapper.js +1 -1
  56. package/lib/experiments.d.ts +1 -0
  57. package/lib/experiments.js +18 -0
  58. package/lib/sx.d.ts +2 -0
  59. package/lib/sx.js +8 -0
  60. package/lib/theme-preval.js +2 -2
  61. package/lib/utils/create-slots.d.ts +17 -0
  62. package/lib/utils/create-slots.js +105 -0
  63. package/lib/utils/testing.d.ts +1 -1
  64. package/lib/utils/use-force-update.d.ts +1 -0
  65. package/lib/utils/use-force-update.js +19 -0
  66. package/lib-esm/ActionList/Item.d.ts +6 -0
  67. package/lib-esm/ActionList/Item.js +5 -1
  68. package/lib-esm/ActionList2/Description.d.ts +6 -0
  69. package/lib-esm/ActionList2/Description.js +37 -0
  70. package/lib-esm/ActionList2/Divider.d.ts +5 -0
  71. package/lib-esm/ActionList2/Divider.js +21 -0
  72. package/lib-esm/ActionList2/Group.d.ts +11 -0
  73. package/lib-esm/ActionList2/Group.js +38 -0
  74. package/lib-esm/ActionList2/Header.d.ts +26 -0
  75. package/lib-esm/ActionList2/Header.js +45 -0
  76. package/lib-esm/ActionList2/Item.d.ts +48 -0
  77. package/lib-esm/ActionList2/Item.js +176 -0
  78. package/lib-esm/ActionList2/List.d.ts +26 -0
  79. package/lib-esm/ActionList2/List.js +38 -0
  80. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  81. package/lib-esm/ActionList2/Selection.js +55 -0
  82. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  83. package/lib-esm/ActionList2/Visuals.js +68 -0
  84. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  85. package/lib-esm/ActionList2/hacks.js +30 -0
  86. package/lib-esm/ActionList2/index.d.ts +28 -0
  87. package/lib-esm/ActionList2/index.js +29 -0
  88. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  89. package/lib-esm/Autocomplete/Autocomplete.d.ts +6 -8
  90. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +6 -8
  91. package/lib-esm/Button/Button.d.ts +4 -4
  92. package/lib-esm/Button/ButtonClose.d.ts +21 -21
  93. package/lib-esm/Button/ButtonDanger.d.ts +4 -4
  94. package/lib-esm/Button/ButtonInvisible.d.ts +4 -4
  95. package/lib-esm/Button/ButtonOutline.d.ts +4 -4
  96. package/lib-esm/Button/ButtonPrimary.d.ts +4 -4
  97. package/lib-esm/CircleOcticon.d.ts +19 -19
  98. package/lib-esm/Dialog.d.ts +21 -21
  99. package/lib-esm/Dropdown.d.ts +82 -82
  100. package/lib-esm/DropdownMenu/DropdownButton.d.ts +23 -23
  101. package/lib-esm/FilterList.d.ts +19 -19
  102. package/lib-esm/Position.d.ts +4 -4
  103. package/lib-esm/SelectMenu/SelectMenu.d.ts +105 -107
  104. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  105. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  106. package/lib-esm/TextInputWithTokens.d.ts +10 -8
  107. package/lib-esm/TextInputWithTokens.js +101 -30
  108. package/lib-esm/Timeline.d.ts +19 -19
  109. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  110. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  111. package/lib-esm/Token/Token.d.ts +1 -1
  112. package/lib-esm/Token/Token.js +13 -2
  113. package/lib-esm/Token/TokenBase.js +0 -4
  114. package/lib-esm/Token/_RemoveTokenButton.js +11 -2
  115. package/lib-esm/_TextInputWrapper.js +1 -1
  116. package/lib-esm/experiments.d.ts +1 -0
  117. package/lib-esm/experiments.js +2 -0
  118. package/lib-esm/sx.d.ts +2 -0
  119. package/lib-esm/sx.js +3 -1
  120. package/lib-esm/theme-preval.js +2 -2
  121. package/lib-esm/utils/create-slots.d.ts +17 -0
  122. package/lib-esm/utils/create-slots.js +84 -0
  123. package/lib-esm/utils/testing.d.ts +1 -1
  124. package/lib-esm/utils/use-force-update.d.ts +1 -0
  125. package/lib-esm/utils/use-force-update.js +6 -0
  126. package/package.json +16 -14
  127. package/lib/DatePicker/DatePicker.d.ts +0 -48
  128. package/lib/DatePicker/DatePicker.js +0 -106
  129. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  130. package/lib/DatePicker/DatePickerAnchor.js +0 -194
  131. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  132. package/lib/DatePicker/DatePickerOverlay.js +0 -48
  133. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  134. package/lib/DatePicker/DatePickerPanel.js +0 -126
  135. package/lib/DatePicker/Day.d.ts +0 -14
  136. package/lib/DatePicker/Day.js +0 -190
  137. package/lib/DatePicker/Month.d.ts +0 -9
  138. package/lib/DatePicker/Month.js +0 -120
  139. package/lib/DatePicker/dateParser.d.ts +0 -11
  140. package/lib/DatePicker/dateParser.js +0 -188
  141. package/lib/DatePicker/index.d.ts +0 -2
  142. package/lib/DatePicker/index.js +0 -13
  143. package/lib/DatePicker/useDatePicker.d.ts +0 -89
  144. package/lib/DatePicker/useDatePicker.js +0 -370
  145. package/lib/hooks/useDebounce.d.ts +0 -2
  146. package/lib/hooks/useDebounce.js +0 -24
  147. package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
  148. package/lib-esm/DatePicker/DatePicker.js +0 -89
  149. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  150. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -167
  151. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  152. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -29
  153. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  154. package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
  155. package/lib-esm/DatePicker/Day.d.ts +0 -14
  156. package/lib-esm/DatePicker/Day.js +0 -167
  157. package/lib-esm/DatePicker/Month.d.ts +0 -9
  158. package/lib-esm/DatePicker/Month.js +0 -96
  159. package/lib-esm/DatePicker/dateParser.d.ts +0 -11
  160. package/lib-esm/DatePicker/dateParser.js +0 -174
  161. package/lib-esm/DatePicker/index.d.ts +0 -2
  162. package/lib-esm/DatePicker/index.js +0 -1
  163. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -89
  164. package/lib-esm/DatePicker/useDatePicker.js +0 -339
  165. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  166. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,48 +0,0 @@
1
- import React from 'react';
2
- import { OverlayProps } from '../Overlay';
3
- import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
4
- import { FocusZoneHookSettings } from '../hooks/useFocusZone';
5
- import { DatePickerConfiguration, Selection } from './useDatePicker';
6
- declare type OpenGesture = 'anchor-click' | 'anchor-key-press';
7
- declare type CloseGesture = 'anchor-click' | 'click-outside' | 'escape';
8
- export interface DatePickerProps extends DatePickerConfiguration {
9
- /**
10
- * An override to the internal ref that will be spread on to the renderAnchor
11
- */
12
- anchorRef?: React.RefObject<HTMLElement>;
13
- /**
14
- * Settings to apply to the Focus Zone on the internal `Overlay` component.
15
- */
16
- focusTrapSettings?: Partial<FocusTrapHookSettings>;
17
- /**
18
- * Settings to apply to the Focus Zone on the internal `Overlay` component.
19
- */
20
- focusZoneSettings?: Partial<FocusZoneHookSettings>;
21
- initialValue?: 'today' | Date | string | null;
22
- iconOnly?: boolean;
23
- placeholder?: string;
24
- /**
25
- * Determines whether the overlay portion of the component should be shown or not
26
- */
27
- open?: boolean;
28
- /**
29
- * A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
30
- */
31
- onOpen?: (gesture: OpenGesture) => unknown;
32
- /**
33
- * A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
34
- */
35
- onClose?: (gesture: CloseGesture) => unknown;
36
- /**
37
- * Props to be spread on the internal `Overlay` component.
38
- */
39
- overlayProps?: Partial<OverlayProps>;
40
- /**
41
- * A custom function component used to render the anchor element.
42
- * Will receive the selected text as `children` prop when an item is activated.
43
- */
44
- renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element;
45
- value?: Selection;
46
- }
47
- export declare const DatePicker: React.FC<DatePickerProps>;
48
- export {};
@@ -1,89 +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
- 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";
@@ -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,167 +0,0 @@
1
- import { CalendarIcon } from '@primer/octicons-react';
2
- import styled from 'styled-components';
3
- import React, { useCallback, useEffect, 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 keyPressHandler = useCallback(event => {
34
- if (disabled) {
35
- return;
36
- }
37
-
38
- if ([' ', 'Enter'].includes(event.key)) {
39
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
40
- }
41
- }, [disabled, onAction]);
42
- const clickHandler = useCallback(event => {
43
- if (disabled) {
44
- return;
45
- }
46
-
47
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
48
- }, [disabled, onAction]);
49
- useEffect(() => {
50
- if (document.activeElement !== inputRef.current) {
51
- setInputValue(formattedDate);
52
- }
53
- }, [formattedDate]);
54
- const onInputChangeHandler = useCallback(e => {
55
- const value = e.currentTarget.value;
56
-
57
- if (!value) {
58
- setInputValue(value);
59
- return;
60
- }
61
-
62
- const parsedDate = parseDate(value, variant);
63
-
64
- if (parsedDate) {
65
- onDateInput(parsedDate);
66
- }
67
- }, [onDateInput, variant]);
68
-
69
- const onBlurHandler = () => {
70
- setInputValue(formattedDate);
71
- };
72
-
73
- if (anchorVariant === 'input') {
74
- const calendarButton = side => /*#__PURE__*/React.createElement(ButtonInvisible, {
75
- onClick: clickHandler,
76
- sx: {
77
- width: '32px',
78
- px: '6px',
79
- position: 'absolute',
80
- [side]: '1px',
81
- top: '1px',
82
- bottom: '1px'
83
- }
84
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
85
- icon: CalendarIcon
86
- }));
87
-
88
- const inputSx = () => {
89
- let sxObject = {};
90
-
91
- if (iconPlacement === 'start') {
92
- sxObject = { ...sxObject,
93
- pl: 5,
94
- pr: 2
95
- };
96
- } else if (iconPlacement === 'end') {
97
- sxObject = { ...sxObject,
98
- pl: 2,
99
- pr: 5
100
- };
101
- }
102
-
103
- if (showInputPrompt) {
104
- sxObject = { ...sxObject,
105
- pt: '20px'
106
- };
107
- }
108
-
109
- return sxObject;
110
- };
111
-
112
- const promptSx = () => {
113
- let sxObject = {
114
- position: 'absolute',
115
- top: '2px',
116
- fontSize: 0,
117
- color: 'fg.subtle'
118
- };
119
-
120
- if (iconPlacement === 'start') {
121
- sxObject = { ...sxObject,
122
- left: '36px'
123
- };
124
- }
125
-
126
- return sxObject;
127
- };
128
-
129
- return /*#__PURE__*/React.createElement(Box, {
130
- ref: ref,
131
- sx: {
132
- position: 'relative',
133
- display: 'flex',
134
- flex: 1
135
- }
136
- }, iconPlacement === 'start' && calendarButton('left'), showInputPrompt && /*#__PURE__*/React.createElement(Text, {
137
- sx: promptSx()
138
- }, "MM/DD/YYYY"), /*#__PURE__*/React.createElement(TextInput, {
139
- ref: inputRef,
140
- placeholder: placeholder,
141
- value: inputValue,
142
- onChange: onInputChangeHandler,
143
- sx: inputSx(),
144
- onBlur: onBlurHandler
145
- }), iconPlacement === 'end' && calendarButton('right'));
146
- }
147
-
148
- const calendarIcon = () => /*#__PURE__*/React.createElement(StyledOcticon, {
149
- icon: CalendarIcon,
150
- color: "fg.muted",
151
- sx: {
152
- my: '2px'
153
- }
154
- });
155
-
156
- return /*#__PURE__*/React.createElement(Box, {
157
- ref: ref
158
- }, /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
159
- onClick: clickHandler,
160
- onKeyPress: keyPressHandler
161
- }, iconPlacement === 'start' && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
162
- sx: {
163
- overflow: 'hidden',
164
- textOverflow: 'ellipsis'
165
- }
166
- }, formattedDate), iconPlacement === 'end' && calendarIcon()));
167
- });
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import { AnchoredOverlayProps } from '../AnchoredOverlay';
3
- export declare const DatePickerOverlay: React.FC<AnchoredOverlayProps>;
@@ -1,29 +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, { 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";
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const DatePickerPanel: () => JSX.Element;
@@ -1,100 +0,0 @@
1
- import { addMonths, subMonths } from 'date-fns';
2
- import React, { useMemo } 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
- const DatePickerPanelContainer = styled(Box).withConfig({
12
- displayName: "DatePickerPanel__DatePickerPanelContainer",
13
- componentId: "sc-19upxpo-0"
14
- })(["align-items:stretch;display:flex;flex-direction:column;"]);
15
- const DatePickerPanelMonths = styled(Box).withConfig({
16
- displayName: "DatePickerPanel__DatePickerPanelMonths",
17
- componentId: "sc-19upxpo-1"
18
- })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";position:relative;"], get('space.6'), get('space.3'));
19
- const DatePickerPanelFooter = styled(Box).withConfig({
20
- displayName: "DatePickerPanel__DatePickerPanelFooter",
21
- componentId: "sc-19upxpo-2"
22
- })(["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'));
23
- const ArrowButton = styled(Button).withConfig({
24
- displayName: "DatePickerPanel__ArrowButton",
25
- componentId: "sc-19upxpo-3"
26
- })(["position:absolute;width:40px;height:28px;top:12px;", ";"], props => `${props.side}: ${get('space.3')(props)}`);
27
- export const DatePickerPanel = () => {
28
- const {
29
- configuration,
30
- saveValue,
31
- revertValue,
32
- currentViewingDate,
33
- goToMonth,
34
- nextMonth,
35
- previousMonth
36
- } = useDatePicker();
37
- const previousDisabled = useMemo(() => {
38
- const {
39
- minDate
40
- } = configuration;
41
- if (!minDate) return false;
42
- const previous = subMonths(currentViewingDate, 1);
43
-
44
- if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
45
- return true;
46
- }
47
-
48
- return false;
49
- }, [configuration, currentViewingDate]);
50
- const nextDisabled = useMemo(() => {
51
- const {
52
- maxDate,
53
- view
54
- } = configuration;
55
- if (!maxDate) return false;
56
- const next = addMonths(currentViewingDate, view === '2-month' ? 2 : 1);
57
-
58
- if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
59
- return true;
60
- }
61
-
62
- return false;
63
- }, [configuration, currentViewingDate]);
64
- return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(DatePickerPanelMonths, null, /*#__PURE__*/React.createElement(ArrowButton, {
65
- variant: "small",
66
- side: "left",
67
- onClick: previousMonth,
68
- disabled: previousDisabled
69
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
70
- icon: ChevronLeftIcon,
71
- color: "fg.muted"
72
- })), /*#__PURE__*/React.createElement(Month, {
73
- month: currentViewingDate.getMonth(),
74
- year: currentViewingDate.getFullYear()
75
- }), configuration.view === '2-month' && /*#__PURE__*/React.createElement(Month, {
76
- month: addMonths(currentViewingDate, 1).getMonth(),
77
- year: addMonths(currentViewingDate, 1).getFullYear()
78
- }), /*#__PURE__*/React.createElement(ArrowButton, {
79
- variant: "small",
80
- side: "right",
81
- onClick: nextMonth,
82
- disabled: nextDisabled
83
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
84
- icon: ChevronRightIcon,
85
- color: "fg.muted"
86
- }))), /*#__PURE__*/React.createElement(DatePickerPanelFooter, null, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Button, {
87
- variant: "small",
88
- sx: {
89
- mr: 1
90
- },
91
- onClick: () => revertValue()
92
- }, "Reset"), /*#__PURE__*/React.createElement(Button, {
93
- variant: "small",
94
- onClick: () => goToMonth(new Date())
95
- }, "Today")), configuration.confirmation && /*#__PURE__*/React.createElement(ButtonPrimary, {
96
- variant: "small",
97
- onClick: () => saveValue()
98
- }, "Apply")));
99
- };
100
- DatePickerPanel.displayName = "DatePickerPanel";
@@ -1,14 +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
- 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>;
@@ -1,167 +0,0 @@
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: "button",
151
- blocked: blocked,
152
- disabled: disabled,
153
- selected: selected,
154
- today: today,
155
- onClick: clickHandler,
156
- onMouseEnter: () => onDayFocus(date),
157
- onFocus: () => onDayFocus(date),
158
- onKeyPress: keyPressHandler
159
- }, /*#__PURE__*/React.createElement(Text, {
160
- sx: todayStyles
161
- }, date.getDate()));
162
- };
163
- Day.displayName = "Day";
164
- export const BlankDay = styled(DayBaseComponent).withConfig({
165
- displayName: "Day__BlankDay",
166
- componentId: "sc-1japneh-2"
167
- })(["background-color:", ";"], get('colors.canvas.primary'));
@@ -1,9 +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
- export interface MonthProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
6
- month: number;
7
- year: number;
8
- }
9
- export declare const Month: React.FC<MonthProps>;