@primer/components 0.0.0-202191916821 → 0.0.0-2021920152952

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 (229) hide show
  1. package/CHANGELOG.md +1 -17
  2. package/codemods/deprecateUtilityComponents.js +1 -1
  3. package/dist/browser.esm.js +768 -878
  4. package/dist/browser.esm.js.map +1 -1
  5. package/dist/browser.umd.js +773 -883
  6. package/dist/browser.umd.js.map +1 -1
  7. package/lib/ActionList/Item.js +1 -1
  8. package/lib/ActionList/List.d.ts +1 -2
  9. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  10. package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
  11. package/lib/BaseStyles.js +1 -1
  12. package/lib/BorderBox.js +1 -1
  13. package/lib/Button/ButtonInvisible.js +1 -1
  14. package/lib/Caret.js +2 -2
  15. package/lib/DatePicker/DatePicker.d.ts +47 -0
  16. package/lib/DatePicker/DatePicker.js +76 -0
  17. package/lib/DatePicker/DatePickerAnchor.d.ts +10 -0
  18. package/lib/DatePicker/DatePickerAnchor.js +83 -0
  19. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  20. package/lib/DatePicker/DatePickerPanel.js +38 -0
  21. package/lib/DatePicker/Day.d.ts +13 -0
  22. package/lib/DatePicker/Day.js +136 -0
  23. package/lib/DatePicker/Month.d.ts +9 -0
  24. package/lib/DatePicker/Month.js +97 -0
  25. package/lib/DatePicker/index.d.ts +2 -0
  26. package/lib/DatePicker/index.js +13 -0
  27. package/lib/DatePicker/useDatePicker.d.ts +51 -0
  28. package/lib/DatePicker/useDatePicker.js +133 -0
  29. package/lib/Dialog.js +1 -1
  30. package/lib/FilteredActionList/FilteredActionList.js +31 -5
  31. package/lib/Flash.js +16 -16
  32. package/lib/Label.js +1 -1
  33. package/lib/Overlay.d.ts +0 -1
  34. package/lib/Overlay.js +1 -3
  35. package/lib/ProgressBar.js +1 -1
  36. package/lib/SelectMenu/SelectMenu.d.ts +10 -10
  37. package/lib/StateLabel.js +19 -13
  38. package/lib/TextInput.d.ts +13 -5
  39. package/lib/TextInput.js +46 -4
  40. package/lib/hooks/useOpenAndCloseFocus.d.ts +1 -2
  41. package/lib/hooks/useOpenAndCloseFocus.js +2 -7
  42. package/lib/hooks/useOverlay.d.ts +1 -2
  43. package/lib/hooks/useOverlay.js +2 -4
  44. package/lib/index.d.ts +0 -6
  45. package/lib/index.js +0 -44
  46. package/lib/theme-preval.js +3105 -375
  47. package/lib/utils/testing.d.ts +493 -50
  48. package/{lib-esm/utils/types/AriaRole.d.ts → lib/utils/types.d.ts} +13 -0
  49. package/lib/utils/{types/AriaRole.js → types.js} +0 -0
  50. package/lib-esm/ActionList/Item.js +1 -1
  51. package/lib-esm/ActionList/List.d.ts +1 -2
  52. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  53. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
  54. package/lib-esm/BaseStyles.js +1 -1
  55. package/lib-esm/BorderBox.js +1 -1
  56. package/lib-esm/Button/ButtonInvisible.js +1 -1
  57. package/lib-esm/Caret.js +2 -2
  58. package/lib-esm/DatePicker/DatePicker.d.ts +47 -0
  59. package/lib-esm/DatePicker/DatePicker.js +57 -0
  60. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +10 -0
  61. package/lib-esm/DatePicker/DatePickerAnchor.js +59 -0
  62. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  63. package/lib-esm/DatePicker/DatePickerPanel.js +20 -0
  64. package/lib-esm/DatePicker/Day.d.ts +13 -0
  65. package/lib-esm/DatePicker/Day.js +113 -0
  66. package/lib-esm/DatePicker/Month.d.ts +9 -0
  67. package/lib-esm/DatePicker/Month.js +74 -0
  68. package/lib-esm/DatePicker/index.d.ts +2 -0
  69. package/lib-esm/DatePicker/index.js +1 -0
  70. package/lib-esm/DatePicker/useDatePicker.d.ts +51 -0
  71. package/lib-esm/DatePicker/useDatePicker.js +114 -0
  72. package/lib-esm/Dialog.js +1 -1
  73. package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
  74. package/lib-esm/Flash.js +16 -16
  75. package/lib-esm/Label.js +1 -1
  76. package/lib-esm/Overlay.d.ts +0 -1
  77. package/lib-esm/Overlay.js +1 -3
  78. package/lib-esm/ProgressBar.js +1 -1
  79. package/lib-esm/SelectMenu/SelectMenu.d.ts +10 -10
  80. package/lib-esm/StateLabel.js +19 -13
  81. package/lib-esm/TextInput.d.ts +13 -5
  82. package/lib-esm/TextInput.js +37 -4
  83. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +1 -2
  84. package/lib-esm/hooks/useOpenAndCloseFocus.js +2 -7
  85. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  86. package/lib-esm/hooks/useOverlay.js +2 -4
  87. package/lib-esm/index.d.ts +0 -6
  88. package/lib-esm/index.js +0 -4
  89. package/lib-esm/theme-preval.js +3105 -375
  90. package/lib-esm/utils/testing.d.ts +493 -50
  91. package/{lib/utils/types/AriaRole.d.ts → lib-esm/utils/types.d.ts} +13 -0
  92. package/lib-esm/utils/{types/AriaRole.js → types.js} +0 -0
  93. package/package.json +4 -4
  94. package/lib/ActionList2/Description.d.ts +0 -5
  95. package/lib/ActionList2/Description.js +0 -45
  96. package/lib/ActionList2/Divider.d.ts +0 -8
  97. package/lib/ActionList2/Divider.js +0 -42
  98. package/lib/ActionList2/Group.d.ts +0 -8
  99. package/lib/ActionList2/Group.js +0 -39
  100. package/lib/ActionList2/Header.d.ts +0 -26
  101. package/lib/ActionList2/Header.js +0 -55
  102. package/lib/ActionList2/Item.d.ts +0 -52
  103. package/lib/ActionList2/Item.js +0 -171
  104. package/lib/ActionList2/List.d.ts +0 -18
  105. package/lib/ActionList2/List.js +0 -52
  106. package/lib/ActionList2/Selection.d.ts +0 -5
  107. package/lib/ActionList2/Selection.js +0 -67
  108. package/lib/ActionList2/Visuals.d.ts +0 -12
  109. package/lib/ActionList2/Visuals.js +0 -87
  110. package/lib/ActionList2/hacks.d.ts +0 -30
  111. package/lib/ActionList2/hacks.js +0 -38
  112. package/lib/ActionList2/index.d.ts +0 -26
  113. package/lib/ActionList2/index.js +0 -36
  114. package/lib/Autocomplete/Autocomplete.d.ts +0 -304
  115. package/lib/Autocomplete/Autocomplete.js +0 -145
  116. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
  117. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  118. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -292
  119. package/lib/Autocomplete/AutocompleteInput.js +0 -157
  120. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -72
  121. package/lib/Autocomplete/AutocompleteMenu.js +0 -224
  122. package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -20
  123. package/lib/Autocomplete/AutocompleteOverlay.js +0 -80
  124. package/lib/Autocomplete/index.d.ts +0 -2
  125. package/lib/Autocomplete/index.js +0 -15
  126. package/lib/TextInputWithTokens.d.ts +0 -323
  127. package/lib/TextInputWithTokens.js +0 -245
  128. package/lib/Token/AvatarToken.d.ts +0 -7
  129. package/lib/Token/AvatarToken.js +0 -64
  130. package/lib/Token/IssueLabelToken.d.ts +0 -14
  131. package/lib/Token/IssueLabelToken.js +0 -144
  132. package/lib/Token/Token.d.ts +0 -15
  133. package/lib/Token/Token.js +0 -94
  134. package/lib/Token/TokenBase.d.ts +0 -31
  135. package/lib/Token/TokenBase.js +0 -108
  136. package/lib/Token/_RemoveTokenButton.d.ts +0 -12
  137. package/lib/Token/_RemoveTokenButton.js +0 -77
  138. package/lib/Token/_TokenTextContainer.d.ts +0 -3
  139. package/lib/Token/_TokenTextContainer.js +0 -17
  140. package/lib/Token/index.d.ts +0 -3
  141. package/lib/Token/index.js +0 -31
  142. package/lib/_TextInputWrapper.d.ts +0 -10
  143. package/lib/_TextInputWrapper.js +0 -51
  144. package/lib/_UnstyledTextInput.d.ts +0 -2
  145. package/lib/_UnstyledTextInput.js +0 -20
  146. package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
  147. package/lib/behaviors/scrollIntoViewingArea.js +0 -39
  148. package/lib/utils/create-slots.d.ts +0 -15
  149. package/lib/utils/create-slots.js +0 -101
  150. package/lib/utils/types/ComponentProps.d.ts +0 -9
  151. package/lib/utils/types/ComponentProps.js +0 -1
  152. package/lib/utils/types/Flatten.d.ts +0 -4
  153. package/lib/utils/types/Flatten.js +0 -1
  154. package/lib/utils/types/MandateProps.d.ts +0 -3
  155. package/lib/utils/types/MandateProps.js +0 -1
  156. package/lib/utils/types/Merge.d.ts +0 -19
  157. package/lib/utils/types/Merge.js +0 -1
  158. package/lib/utils/types/index.d.ts +0 -5
  159. package/lib/utils/types/index.js +0 -70
  160. package/lib/utils/use-force-update.d.ts +0 -1
  161. package/lib/utils/use-force-update.js +0 -19
  162. package/lib-esm/ActionList2/Description.d.ts +0 -5
  163. package/lib-esm/ActionList2/Description.js +0 -30
  164. package/lib-esm/ActionList2/Divider.d.ts +0 -8
  165. package/lib-esm/ActionList2/Divider.js +0 -30
  166. package/lib-esm/ActionList2/Group.d.ts +0 -8
  167. package/lib-esm/ActionList2/Group.js +0 -29
  168. package/lib-esm/ActionList2/Header.d.ts +0 -26
  169. package/lib-esm/ActionList2/Header.js +0 -45
  170. package/lib-esm/ActionList2/Item.d.ts +0 -52
  171. package/lib-esm/ActionList2/Item.js +0 -172
  172. package/lib-esm/ActionList2/List.d.ts +0 -18
  173. package/lib-esm/ActionList2/List.js +0 -42
  174. package/lib-esm/ActionList2/Selection.d.ts +0 -5
  175. package/lib-esm/ActionList2/Selection.js +0 -50
  176. package/lib-esm/ActionList2/Visuals.d.ts +0 -12
  177. package/lib-esm/ActionList2/Visuals.js +0 -66
  178. package/lib-esm/ActionList2/hacks.d.ts +0 -30
  179. package/lib-esm/ActionList2/hacks.js +0 -30
  180. package/lib-esm/ActionList2/index.d.ts +0 -26
  181. package/lib-esm/ActionList2/index.js +0 -23
  182. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -304
  183. package/lib-esm/Autocomplete/Autocomplete.js +0 -123
  184. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
  185. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  186. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -292
  187. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -138
  188. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -72
  189. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -205
  190. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -20
  191. package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -62
  192. package/lib-esm/Autocomplete/index.d.ts +0 -2
  193. package/lib-esm/Autocomplete/index.js +0 -1
  194. package/lib-esm/TextInputWithTokens.d.ts +0 -323
  195. package/lib-esm/TextInputWithTokens.js +0 -220
  196. package/lib-esm/Token/AvatarToken.d.ts +0 -7
  197. package/lib-esm/Token/AvatarToken.js +0 -43
  198. package/lib-esm/Token/IssueLabelToken.d.ts +0 -14
  199. package/lib-esm/Token/IssueLabelToken.js +0 -124
  200. package/lib-esm/Token/Token.d.ts +0 -15
  201. package/lib-esm/Token/Token.js +0 -73
  202. package/lib-esm/Token/TokenBase.d.ts +0 -31
  203. package/lib-esm/Token/TokenBase.js +0 -87
  204. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -12
  205. package/lib-esm/Token/_RemoveTokenButton.js +0 -60
  206. package/lib-esm/Token/_TokenTextContainer.d.ts +0 -3
  207. package/lib-esm/Token/_TokenTextContainer.js +0 -6
  208. package/lib-esm/Token/index.d.ts +0 -3
  209. package/lib-esm/Token/index.js +0 -3
  210. package/lib-esm/_TextInputWrapper.d.ts +0 -10
  211. package/lib-esm/_TextInputWrapper.js +0 -31
  212. package/lib-esm/_UnstyledTextInput.d.ts +0 -2
  213. package/lib-esm/_UnstyledTextInput.js +0 -7
  214. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
  215. package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
  216. package/lib-esm/utils/create-slots.d.ts +0 -15
  217. package/lib-esm/utils/create-slots.js +0 -80
  218. package/lib-esm/utils/types/ComponentProps.d.ts +0 -9
  219. package/lib-esm/utils/types/ComponentProps.js +0 -1
  220. package/lib-esm/utils/types/Flatten.d.ts +0 -4
  221. package/lib-esm/utils/types/Flatten.js +0 -1
  222. package/lib-esm/utils/types/MandateProps.d.ts +0 -3
  223. package/lib-esm/utils/types/MandateProps.js +0 -1
  224. package/lib-esm/utils/types/Merge.d.ts +0 -19
  225. package/lib-esm/utils/types/Merge.js +0 -1
  226. package/lib-esm/utils/types/index.d.ts +0 -5
  227. package/lib-esm/utils/types/index.js +0 -5
  228. package/lib-esm/utils/use-force-update.d.ts +0 -1
  229. package/lib-esm/utils/use-force-update.js +0 -6
@@ -42,7 +42,7 @@ function BaseStyles(props) {
42
42
 
43
43
  BaseStyles.displayName = "BaseStyles";
44
44
  BaseStyles.defaultProps = {
45
- color: 'fg.default',
45
+ color: 'text.primary',
46
46
  fontFamily: 'normal',
47
47
  lineHeight: 'default'
48
48
  };
@@ -11,7 +11,7 @@ const BorderBox = styled(Box).withConfig({
11
11
  BorderBox.defaultProps = {
12
12
  borderWidth: '1px',
13
13
  borderStyle: 'solid',
14
- borderColor: 'border.default',
14
+ borderColor: 'border.primary',
15
15
  borderRadius: 2
16
16
  };
17
17
  export default BorderBox;
@@ -5,5 +5,5 @@ import ButtonBase, { buttonSystemProps } from './ButtonBase';
5
5
  const ButtonInvisible = styled(ButtonBase).withConfig({
6
6
  displayName: "ButtonInvisible",
7
7
  componentId: "sc-1195tpn-0"
8
- })(["color:", ";background-color:transparent;border:0;border-radius:", ";box-shadow:none;&:disabled{color:", ";}&:focus{box-shadow:", ";}&:hover{background-color:", ";}&:active{background-color:", ";}", ";", ""], get('colors.accent.fg'), get('radii.2'), get('colors.primer.fg.disabled'), get('shadows.btn.focusShadow'), get('colors.btn.hoverBg'), get('colors.btn.selectedBg'), buttonSystemProps, sx);
8
+ })(["color:", ";background-color:transparent;border:0;border-radius:", ";box-shadow:none;&:disabled{color:", ";}&:focus{box-shadow:", ";}", ";", ""], get('colors.accent.fg'), get('radii.2'), get('colors.fg.muted'), get('shadows.btn.focusShadow'), buttonSystemProps, sx);
9
9
  export default ButtonInvisible;
package/lib-esm/Caret.js CHANGED
@@ -106,8 +106,8 @@ function Caret(props) {
106
106
  Caret.displayName = "Caret";
107
107
  Caret.locations = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
108
108
  Caret.defaultProps = {
109
- bg: 'canvas.default',
110
- borderColor: 'border.default',
109
+ bg: 'bg.canvas',
110
+ borderColor: 'border.primary',
111
111
  borderWidth: 1
112
112
  };
113
113
  export default Caret;
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { OverlayProps } from '../Overlay';
3
+ import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
4
+ import { FocusZoneHookSettings } from '../hooks/useFocusZone';
5
+ declare type OpenGesture = 'anchor-click' | 'anchor-key-press';
6
+ declare type CloseGesture = 'anchor-click' | 'click-outside' | 'escape';
7
+ export interface DatePickerProps {
8
+ /**
9
+ * An override to the internal ref that will be spread on to the renderAnchor
10
+ */
11
+ anchorRef?: React.RefObject<HTMLElement>;
12
+ anchorVariant?: 'full' | 'iconOnly';
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
+ placeholder?: string;
23
+ /**
24
+ * Determines whether the overlay portion of the component should be shown or not
25
+ */
26
+ open?: boolean;
27
+ /**
28
+ * A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
29
+ */
30
+ onOpen?: (gesture: OpenGesture) => unknown;
31
+ /**
32
+ * A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
33
+ */
34
+ onClose?: (gesture: CloseGesture) => unknown;
35
+ /**
36
+ * Props to be spread on the internal `Overlay` component.
37
+ */
38
+ overlayProps?: Partial<OverlayProps>;
39
+ /**
40
+ * A custom function component used to render the anchor element.
41
+ * Will receive the selected text as `children` prop when an item is activated.
42
+ */
43
+ renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element;
44
+ value?: Date | string | null;
45
+ }
46
+ export declare const DatePicker: React.FC<DatePickerProps>;
47
+ export {};
@@ -0,0 +1,57 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { AnchoredOverlay } from '../AnchoredOverlay';
3
+ import { DatePickerAnchor } from './DatePickerAnchor';
4
+ import { addDays } from 'date-fns';
5
+ import { DatePickerPanel } from './DatePickerPanel';
6
+ import { DatePickerProvider } from './useDatePicker';
7
+ export const DatePicker = ({
8
+ anchorRef: externalAnchorRef,
9
+ focusTrapSettings,
10
+ focusZoneSettings,
11
+ onOpen: onOpenExternal,
12
+ onClose: onCloseExternal,
13
+ open,
14
+ overlayProps,
15
+ renderAnchor
16
+ }) => {
17
+ const buttonRef = useRef(null);
18
+ const [isOpen, setIsOpen] = useState(false);
19
+
20
+ const onOpen = gesture => {
21
+ setIsOpen(true);
22
+ onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
23
+ };
24
+
25
+ const onClose = gesture => {
26
+ setIsOpen(false);
27
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
28
+ };
29
+
30
+ const toggleIsOpen = () => {
31
+ if (isOpen) {
32
+ setIsOpen(false);
33
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
34
+ } else {
35
+ setIsOpen(true);
36
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
37
+ }
38
+ };
39
+
40
+ return /*#__PURE__*/React.createElement(DatePickerProvider, null, /*#__PURE__*/React.createElement(DatePickerAnchor, {
41
+ ref: buttonRef,
42
+ fromDate: new Date(),
43
+ toDate: addDays(new Date(), 7),
44
+ dateFormat: "short",
45
+ onAction: toggleIsOpen
46
+ }), /*#__PURE__*/React.createElement(AnchoredOverlay, {
47
+ anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : buttonRef,
48
+ renderAnchor: renderAnchor,
49
+ open: open !== null && open !== void 0 ? open : isOpen,
50
+ onOpen: onOpen,
51
+ onClose: onClose,
52
+ overlayProps: overlayProps,
53
+ focusTrapSettings: focusTrapSettings,
54
+ focusZoneSettings: focusZoneSettings
55
+ }, /*#__PURE__*/React.createElement(DatePickerPanel, null)));
56
+ };
57
+ DatePicker.displayName = "DatePicker";
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export interface DatePickerAnchorProps {
3
+ dateFormat?: 'short' | 'long' | string;
4
+ disabled?: boolean;
5
+ fromDate: Date;
6
+ iconOnly?: boolean;
7
+ onAction?: (event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
8
+ toDate?: Date;
9
+ }
10
+ export declare const DatePickerAnchor: React.ForwardRefExoticComponent<DatePickerAnchorProps & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,59 @@
1
+ import { CalendarIcon } from '@primer/octicons-react';
2
+ import styled from 'styled-components';
3
+ import { format } from 'date-fns';
4
+ import React, { useCallback, useMemo } from 'react';
5
+ import Button from '../Button';
6
+ import Text from '../Text';
7
+ import { get } from '../constants';
8
+ import { StyledOcticon } from '..';
9
+ const DatePickerAnchorButton = styled(Button).withConfig({
10
+ displayName: "DatePickerAnchor__DatePickerAnchorButton",
11
+ componentId: "sc-8gpb9d-0"
12
+ })(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;& ", "{margin-left:", ";}"], Text, get('space.2'));
13
+ export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
14
+ dateFormat = 'short',
15
+ disabled,
16
+ fromDate,
17
+ iconOnly = false,
18
+ onAction,
19
+ toDate
20
+ }, ref) => {
21
+ const formattedDate = useMemo(() => {
22
+ if (iconOnly) return;
23
+
24
+ if (dateFormat === 'short') {
25
+ return /*#__PURE__*/React.createElement(Text, null, `${format(fromDate, 'MMM d')}${toDate ? ' - ' : ''}${toDate ? format(toDate, 'MMM d') : ''}`);
26
+ } else if (dateFormat === 'long') {
27
+ return /*#__PURE__*/React.createElement(Text, null, `${format(fromDate, 'MMM d, yyyy')}${toDate ? ' - ' : ''}${toDate ? format(toDate, 'MMM d, yyyy') : ''}`);
28
+ } else {
29
+ return /*#__PURE__*/React.createElement(Text, null, `${format(fromDate, dateFormat)}${toDate ? ' - ' : ''}${toDate ? format(toDate, dateFormat) : ''}`);
30
+ }
31
+ }, [dateFormat, fromDate, iconOnly, toDate]);
32
+ const keyPressHandler = useCallback(event => {
33
+ if (disabled) {
34
+ return;
35
+ }
36
+
37
+ if ([' ', 'Enter'].includes(event.key)) {
38
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
39
+ }
40
+ }, [disabled, onAction]);
41
+ const clickHandler = useCallback(event => {
42
+ if (disabled) {
43
+ return;
44
+ }
45
+
46
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
47
+ }, [disabled, onAction]);
48
+ return /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
49
+ ref: ref,
50
+ onClick: clickHandler,
51
+ onKeyPress: keyPressHandler
52
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
53
+ icon: CalendarIcon,
54
+ color: "fg.muted",
55
+ sx: {
56
+ my: '2px'
57
+ }
58
+ }), formattedDate);
59
+ });
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const DatePickerPanel: () => JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { addMonths } from 'date-fns';
2
+ import React from 'react';
3
+ import Box from '../Box';
4
+ import { Month } from './Month';
5
+ import styled from 'styled-components';
6
+ import { get } from '../constants';
7
+ const DatePickerPanelContainer = styled(Box).withConfig({
8
+ displayName: "DatePickerPanel__DatePickerPanelContainer",
9
+ componentId: "sc-19upxpo-0"
10
+ })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";"], get('space.6'), get('space.3'));
11
+ export const DatePickerPanel = () => {
12
+ return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(Month, {
13
+ month: new Date().getMonth(),
14
+ year: new Date().getFullYear()
15
+ }), /*#__PURE__*/React.createElement(Month, {
16
+ month: addMonths(new Date(), 1).getMonth(),
17
+ year: addMonths(new Date(), 1).getFullYear()
18
+ }));
19
+ };
20
+ DatePickerPanel.displayName = "DatePickerPanel";
@@ -0,0 +1,13 @@
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 DayProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
6
+ blocked?: boolean;
7
+ disabled?: boolean;
8
+ onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
9
+ selected?: boolean;
10
+ date: Date;
11
+ }
12
+ export declare const Day: React.FC<DayProps>;
13
+ 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,113 @@
1
+ import React, { useCallback } 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
+ color: get('colors.fg.subtle')
15
+ },
16
+ disabled: {
17
+ background: get('colors.canvas.primary'),
18
+ color: get('colors.fg.subtle')
19
+ },
20
+ selected: {
21
+ background: get('colors.accent.emphasis'),
22
+ color: get('colors.fg.onEmphasis')
23
+ },
24
+ default: {
25
+ normal: {
26
+ background: get('colors.canvas.primary'),
27
+ color: get('colors.fg.default')
28
+ },
29
+ hover: {
30
+ background: get('colors.neutral.muted'),
31
+ color: get('colors.fg.default')
32
+ },
33
+ pressed: {
34
+ background: get('colors.neutral.emphasis'),
35
+ color: get('colors.fg.onEmphasis')
36
+ }
37
+ }
38
+ };
39
+
40
+ const getStateColors = (props, prop, state) => {
41
+ const {
42
+ blocked,
43
+ disabled,
44
+ selected
45
+ } = props;
46
+
47
+ if (blocked) {
48
+ return states.blocked[prop];
49
+ } else if (disabled) {
50
+ return states.disabled[prop];
51
+ } else if (selected) {
52
+ return states.selected[prop];
53
+ } else {
54
+ return states.default[state][prop];
55
+ }
56
+ };
57
+
58
+ const DayComponent = styled(DayBaseComponent).attrs(props => ({
59
+ background: getStateColors(props, 'background', 'normal'),
60
+ textColor: getStateColors(props, 'color', 'normal'),
61
+ backgroundHover: getStateColors(props, 'background', 'hover'),
62
+ textColorHover: getStateColors(props, 'color', 'hover'),
63
+ backgroundPressed: getStateColors(props, 'background', 'pressed'),
64
+ textColorPressed: getStateColors(props, 'color', 'pressed')
65
+ })).withConfig({
66
+ displayName: "Day__DayComponent",
67
+ componentId: "sc-1japneh-1"
68
+ })(["background-color:", ";border-radius:", ";transition:0.2s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-self:center;user-select:none;transition:0.2s 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, get('radii.2'), 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);
69
+ export const Day = ({
70
+ date,
71
+ onAction
72
+ }) => {
73
+ const {
74
+ onDayFocus,
75
+ onDayBlur,
76
+ onSelection,
77
+ disabled,
78
+ blocked,
79
+ selected
80
+ } = useDatePicker(date);
81
+ const keyPressHandler = useCallback(event => {
82
+ if (disabled) {
83
+ return;
84
+ }
85
+
86
+ if ([' ', 'Enter'].includes(event.key)) {
87
+ onSelection(date);
88
+ onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
89
+ }
90
+ }, [disabled, onSelection, onAction, date]);
91
+ const clickHandler = useCallback(event => {
92
+ if (disabled) {
93
+ return;
94
+ }
95
+
96
+ onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
97
+ }, [disabled, onAction, date]);
98
+ return /*#__PURE__*/React.createElement(DayComponent, {
99
+ role: "button",
100
+ blocked: blocked,
101
+ disabled: disabled,
102
+ selected: selected,
103
+ onClick: clickHandler,
104
+ onFocus: () => onDayFocus(date),
105
+ onBlur: onDayBlur,
106
+ onKeyPress: keyPressHandler
107
+ }, /*#__PURE__*/React.createElement(Text, null, date.getDate()));
108
+ };
109
+ Day.displayName = "Day";
110
+ export const BlankDay = styled(DayBaseComponent).withConfig({
111
+ displayName: "Day__BlankDay",
112
+ componentId: "sc-1japneh-2"
113
+ })(["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>;
@@ -0,0 +1,74 @@
1
+ import { format, isEqual, lastDayOfMonth, getDaysInMonth, eachDayOfInterval, startOfWeek, endOfWeek } from 'date-fns';
2
+ import React, { useMemo, useState } from 'react';
3
+ import styled from 'styled-components';
4
+ import Box from '../Box';
5
+ import Text from '../Text';
6
+ import { get } from '../constants';
7
+ import { BlankDay, Day } from './Day';
8
+ const MonthComponent = styled(Box).withConfig({
9
+ displayName: "Month__MonthComponent",
10
+ componentId: "l6j7o0-0"
11
+ })(["display:grid;grid-auto-rows:min-content;grid-template-columns:repeat(1fr,7);grid-template-rows:1fr;gap:0px 0px;grid-template-areas:'month month month month month month month' 'sunday monday tuesday wednesday thursday friday saturday';justify-items:stretch;align-items:stretch;"]);
12
+ const MonthTitle = styled(Text).withConfig({
13
+ displayName: "Month__MonthTitle",
14
+ componentId: "l6j7o0-1"
15
+ })(["font-size:", ";font-weight:", ";grid-area:month;justify-self:center;"], get('fontSizes.1'), get('fontWeights.bold'));
16
+ const WeekdayHeader = styled(Text).withConfig({
17
+ displayName: "Month__WeekdayHeader",
18
+ componentId: "l6j7o0-2"
19
+ })(["color:", ";font-family:", ";font-size:", ";justify-self:center;padding:", " 0 ", ";"], get('colors.fg.subtle'), get('fonts.mono'), get('fontSizes.0'), get('space.3'), get('space.2'));
20
+ export const Month = ({
21
+ month,
22
+ year
23
+ }) => {
24
+ const [selectedDay, setSelectedDay] = useState(null);
25
+ const getTitle = useMemo(() => `${format(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
26
+ const weekdayHeaders = useMemo(() => {
27
+ const now = new Date(year, month);
28
+ return eachDayOfInterval({
29
+ start: startOfWeek(now),
30
+ end: endOfWeek(now)
31
+ }).map(d => /*#__PURE__*/React.createElement(WeekdayHeader, {
32
+ key: `weekday-${d}-header`
33
+ }, format(d, 'EEEEEE')));
34
+ }, [month, year]);
35
+
36
+ const dayAction = date => {
37
+ setSelectedDay(date);
38
+ };
39
+
40
+ const dayComponents = useMemo(() => {
41
+ const components = [];
42
+ const firstDay = new Date(year, month, 1);
43
+
44
+ for (let i = 0; i < firstDay.getDay(); i++) {
45
+ components.push( /*#__PURE__*/React.createElement(BlankDay, {
46
+ key: `month-pre-blank-${i}`
47
+ }));
48
+ }
49
+
50
+ for (let i = 1; i <= getDaysInMonth(firstDay); i++) {
51
+ const date = new Date(year, month, i);
52
+ components.push( /*#__PURE__*/React.createElement(Day, {
53
+ key: `day-component-${date.toString()}`,
54
+ date: date,
55
+ selected: selectedDay ? isEqual(date, selectedDay) : false,
56
+ onAction: dayAction
57
+ }));
58
+ }
59
+
60
+ const lastDay = lastDayOfMonth(firstDay);
61
+
62
+ for (let i = 6; i > lastDay.getDay(); i--) {
63
+ components.push( /*#__PURE__*/React.createElement(BlankDay, {
64
+ key: `month-post-blank-${i}`
65
+ }));
66
+ }
67
+
68
+ return components;
69
+ }, [month, selectedDay, year]);
70
+ return /*#__PURE__*/React.createElement(MonthComponent, {
71
+ role: "grid"
72
+ }, /*#__PURE__*/React.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
73
+ };
74
+ Month.displayName = "Month";
@@ -0,0 +1,2 @@
1
+ export { DatePicker } from './DatePicker';
2
+ export type { DatePickerProps } from './DatePicker';
@@ -0,0 +1 @@
1
+ export { DatePicker } from './DatePicker';
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ export interface DatePickerConfiguration {
3
+ anchorStyle?: 'input' | 'full-date' | 'icon-only';
4
+ blockedDates?: Array<Date>;
5
+ confirmation?: boolean;
6
+ contiguousSelection?: boolean;
7
+ dimWeekends?: boolean;
8
+ minDate?: Date;
9
+ maxDate?: Date;
10
+ rangeIncrement?: number;
11
+ selection?: 'single' | 'multi' | 'range';
12
+ view?: '1-month' | '2-month';
13
+ }
14
+ declare type SingleSelection = {
15
+ date: Date;
16
+ };
17
+ declare type BaseRangeSelection = {
18
+ from: Date;
19
+ };
20
+ declare type RangeSelection = {
21
+ to: Date;
22
+ } & BaseRangeSelection;
23
+ declare type SoftRangeSelection = {
24
+ to?: Date;
25
+ } & BaseRangeSelection;
26
+ export interface DatePickerContext {
27
+ configuration: DatePickerConfiguration;
28
+ selection?: SingleSelection | Array<SingleSelection> | RangeSelection | null;
29
+ softSelection?: SingleSelection | SoftRangeSelection | null;
30
+ selectionActive?: boolean;
31
+ onSelection: (date: Date) => void;
32
+ onDayFocus: (date: Date) => void;
33
+ onDayBlur: () => void;
34
+ }
35
+ export declare const useDatePicker: (date?: Date | undefined) => {
36
+ blocked: boolean | undefined;
37
+ disabled: boolean;
38
+ selected: boolean | undefined;
39
+ configuration: DatePickerConfiguration;
40
+ selection?: SingleSelection | RangeSelection | SingleSelection[] | null | undefined;
41
+ softSelection?: SingleSelection | SoftRangeSelection | null | undefined;
42
+ selectionActive?: boolean | undefined;
43
+ onSelection: (date: Date) => void;
44
+ onDayFocus: (date: Date) => void;
45
+ onDayBlur: () => void;
46
+ };
47
+ export interface DatePickerProviderProps {
48
+ configuration?: DatePickerConfiguration;
49
+ }
50
+ export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
51
+ export {};
@@ -0,0 +1,114 @@
1
+ import { isEqual } from 'date-fns';
2
+ import { isAfter, isBefore } from 'date-fns/esm';
3
+ import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
4
+ const DatePickerContext = /*#__PURE__*/createContext(null);
5
+ export const useDatePicker = date => {
6
+ const value = useContext(DatePickerContext);
7
+
8
+ if (!value) {
9
+ throw new Error('useDatePicker must be used inside a DatePickerProvider');
10
+ }
11
+
12
+ let selected,
13
+ blocked,
14
+ disabled = false;
15
+
16
+ if (date) {
17
+ if (Array.isArray(value.selection)) {
18
+ selected = !!value.selection.find(d => isEqual(d.date, date));
19
+ } // Determine if date is blocked out
20
+
21
+
22
+ if (value.configuration.blockedDates) {
23
+ blocked = !!value.configuration.blockedDates.find(d => isEqual(d, date));
24
+ } // Determine if date is disabled
25
+
26
+
27
+ if (value.configuration.minDate || value.configuration.maxDate) {
28
+ disabled = (value.configuration.minDate ? isBefore(date, value.configuration.minDate) : false) || (value.configuration.maxDate ? isAfter(date, value.configuration.maxDate) : false);
29
+ }
30
+ }
31
+
32
+ return { ...value,
33
+ blocked,
34
+ disabled,
35
+ selected
36
+ };
37
+ };
38
+
39
+ function isRangeSelection(selection) {
40
+ return !!selection.from;
41
+ }
42
+
43
+ export const DatePickerProvider = ({
44
+ configuration,
45
+ children
46
+ }) => {
47
+ const [selection, setSelection] = useState(null);
48
+ const [softSelection, setSoftSelection] = useState(null);
49
+ const selectionHandler = useCallback(date => {
50
+ if ((configuration === null || configuration === void 0 ? void 0 : configuration.selection) === 'single') {
51
+ setSelection({
52
+ date
53
+ });
54
+ } else if ((configuration === null || configuration === void 0 ? void 0 : configuration.selection) === 'range') {
55
+ if (softSelection && isRangeSelection(softSelection)) {
56
+ setSelection({
57
+ from: softSelection.from,
58
+ to: date
59
+ });
60
+ } else {
61
+ setSoftSelection({
62
+ from: date,
63
+ to: date
64
+ });
65
+ }
66
+ }
67
+ }, [configuration === null || configuration === void 0 ? void 0 : configuration.selection, softSelection]);
68
+ const focusHnadler = useCallback(date => {
69
+ if ((configuration === null || configuration === void 0 ? void 0 : configuration.selection) === 'single' || !softSelection) {
70
+ setSoftSelection({
71
+ date
72
+ });
73
+ }
74
+
75
+ if ((configuration === null || configuration === void 0 ? void 0 : configuration.selection) === 'range' && softSelection && isRangeSelection(softSelection)) {
76
+ setSoftSelection({ ...softSelection,
77
+ to: date
78
+ });
79
+ }
80
+ }, [configuration === null || configuration === void 0 ? void 0 : configuration.selection, softSelection]);
81
+ const blurHnadler = useCallback(() => {
82
+ if ((configuration === null || configuration === void 0 ? void 0 : configuration.selection) === 'single' || !softSelection) {
83
+ setSoftSelection(null);
84
+ }
85
+
86
+ if ((configuration === null || configuration === void 0 ? void 0 : configuration.selection) === 'range' && softSelection && isRangeSelection(softSelection)) {
87
+ setSoftSelection({
88
+ from: softSelection.from
89
+ });
90
+ }
91
+ }, [configuration === null || configuration === void 0 ? void 0 : configuration.selection, softSelection]);
92
+ const datePickerCtx = useMemo(() => {
93
+ return {
94
+ configuration: {
95
+ anchorStyle: 'full-date',
96
+ confirmation: false,
97
+ contiguousSelection: false,
98
+ dimWeekends: false,
99
+ selection: 'single',
100
+ view: '2-month',
101
+ ...configuration
102
+ },
103
+ selectionActive: false,
104
+ selection,
105
+ onSelection: selectionHandler,
106
+ onDayFocus: focusHnadler,
107
+ onDayBlur: blurHnadler
108
+ };
109
+ }, [blurHnadler, configuration, focusHnadler, selection, selectionHandler]);
110
+ return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
111
+ value: datePickerCtx
112
+ }, children);
113
+ };
114
+ DatePickerProvider.displayName = "DatePickerProvider";
package/lib-esm/Dialog.js CHANGED
@@ -98,7 +98,7 @@ const Dialog = /*#__PURE__*/forwardRef(({
98
98
  }), children)) : null;
99
99
  });
100
100
  DialogHeader.defaultProps = {
101
- backgroundColor: 'canvas.subtle'
101
+ backgroundColor: 'bg.tertiary'
102
102
  };
103
103
  DialogHeader.propTypes = { ...Box.propTypes
104
104
  };