@primer/components 0.0.0-2021102224222 → 0.0.0-202110343939

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 (140) hide show
  1. package/CHANGELOG.md +1 -29
  2. package/dist/browser.esm.js +50 -53
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +48 -51
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Header.js +1 -1
  7. package/lib/ActionList/Item.d.ts +0 -6
  8. package/lib/ActionList/Item.js +1 -5
  9. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  10. package/lib/AnchoredOverlay/AnchoredOverlay.js +6 -8
  11. package/lib/Autocomplete/Autocomplete.d.ts +8 -6
  12. package/lib/Autocomplete/AutocompleteInput.d.ts +8 -6
  13. package/lib/Button/Button.d.ts +5 -5
  14. package/lib/Button/ButtonBase.d.ts +1 -1
  15. package/lib/Button/ButtonClose.d.ts +3 -3
  16. package/lib/Button/ButtonDanger.d.ts +5 -5
  17. package/lib/Button/ButtonInvisible.d.ts +5 -5
  18. package/lib/Button/ButtonOutline.d.ts +5 -5
  19. package/lib/Button/ButtonPrimary.d.ts +5 -5
  20. package/lib/CircleBadge.d.ts +7 -6
  21. package/lib/CircleBadge.js +1 -1
  22. package/lib/CircleOcticon.d.ts +4 -4
  23. package/lib/DatePicker/DatePicker.d.ts +48 -0
  24. package/lib/DatePicker/DatePicker.js +109 -0
  25. package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
  26. package/lib/DatePicker/DatePickerAnchor.js +202 -0
  27. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  28. package/lib/DatePicker/DatePickerOverlay.js +53 -0
  29. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  30. package/lib/DatePicker/DatePickerPanel.js +232 -0
  31. package/lib/DatePicker/Day.d.ts +15 -0
  32. package/lib/DatePicker/Day.js +197 -0
  33. package/lib/DatePicker/Month.d.ts +8 -0
  34. package/lib/DatePicker/Month.js +122 -0
  35. package/lib/DatePicker/dateParser.d.ts +12 -0
  36. package/lib/DatePicker/dateParser.js +192 -0
  37. package/lib/DatePicker/index.d.ts +2 -0
  38. package/lib/DatePicker/index.js +13 -0
  39. package/lib/DatePicker/useDatePicker.d.ts +107 -0
  40. package/lib/DatePicker/useDatePicker.js +685 -0
  41. package/lib/Dialog.d.ts +4 -4
  42. package/lib/Dropdown.d.ts +16 -16
  43. package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
  44. package/lib/FilterList.d.ts +3 -3
  45. package/lib/Flash.d.ts +1 -1
  46. package/lib/Label.d.ts +1 -1
  47. package/lib/Position.d.ts +4 -4
  48. package/lib/ProgressBar.d.ts +1 -1
  49. package/lib/SelectMenu/SelectMenu.d.ts +28 -26
  50. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  51. package/lib/TextInputWithTokens.d.ts +8 -10
  52. package/lib/TextInputWithTokens.js +29 -102
  53. package/lib/Timeline.d.ts +4 -4
  54. package/lib/Token/AvatarToken.d.ts +1 -1
  55. package/lib/Token/IssueLabelToken.d.ts +1 -1
  56. package/lib/Token/Token.d.ts +1 -1
  57. package/lib/Token/Token.js +2 -13
  58. package/lib/Token/TokenBase.js +4 -0
  59. package/lib/Token/_RemoveTokenButton.js +2 -15
  60. package/lib/_TextInputWrapper.d.ts +1 -1
  61. package/lib/_TextInputWrapper.js +1 -1
  62. package/lib/hooks/useDebounce.d.ts +2 -0
  63. package/lib/hooks/useDebounce.js +24 -0
  64. package/lib/hooks/useResizeObserver.d.ts +1 -1
  65. package/lib/hooks/useResizeObserver.js +1 -1
  66. package/lib/sx.d.ts +2 -8
  67. package/lib/theme-preval.js +2 -2
  68. package/lib/theme.d.ts +0 -78
  69. package/lib/theme.js +1 -3
  70. package/lib/utils/testing.d.ts +1 -1
  71. package/lib-esm/ActionList/Header.js +1 -1
  72. package/lib-esm/ActionList/Item.d.ts +0 -6
  73. package/lib-esm/ActionList/Item.js +1 -5
  74. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  75. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +6 -7
  76. package/lib-esm/Autocomplete/Autocomplete.d.ts +8 -6
  77. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +8 -6
  78. package/lib-esm/Button/Button.d.ts +5 -5
  79. package/lib-esm/Button/ButtonBase.d.ts +1 -1
  80. package/lib-esm/Button/ButtonClose.d.ts +3 -3
  81. package/lib-esm/Button/ButtonDanger.d.ts +5 -5
  82. package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
  83. package/lib-esm/Button/ButtonOutline.d.ts +5 -5
  84. package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
  85. package/lib-esm/CircleBadge.d.ts +7 -6
  86. package/lib-esm/CircleBadge.js +2 -2
  87. package/lib-esm/CircleOcticon.d.ts +4 -4
  88. package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
  89. package/lib-esm/DatePicker/DatePicker.js +92 -0
  90. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
  91. package/lib-esm/DatePicker/DatePickerAnchor.js +174 -0
  92. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  93. package/lib-esm/DatePicker/DatePickerOverlay.js +38 -0
  94. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  95. package/lib-esm/DatePicker/DatePickerPanel.js +201 -0
  96. package/lib-esm/DatePicker/Day.d.ts +15 -0
  97. package/lib-esm/DatePicker/Day.js +174 -0
  98. package/lib-esm/DatePicker/Month.d.ts +8 -0
  99. package/lib-esm/DatePicker/Month.js +98 -0
  100. package/lib-esm/DatePicker/dateParser.d.ts +12 -0
  101. package/lib-esm/DatePicker/dateParser.js +178 -0
  102. package/lib-esm/DatePicker/index.d.ts +2 -0
  103. package/lib-esm/DatePicker/index.js +1 -0
  104. package/lib-esm/DatePicker/useDatePicker.d.ts +107 -0
  105. package/lib-esm/DatePicker/useDatePicker.js +650 -0
  106. package/lib-esm/Dialog.d.ts +4 -4
  107. package/lib-esm/Dropdown.d.ts +16 -16
  108. package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
  109. package/lib-esm/FilterList.d.ts +3 -3
  110. package/lib-esm/Flash.d.ts +1 -1
  111. package/lib-esm/Label.d.ts +1 -1
  112. package/lib-esm/Position.d.ts +4 -4
  113. package/lib-esm/ProgressBar.d.ts +1 -1
  114. package/lib-esm/SelectMenu/SelectMenu.d.ts +28 -26
  115. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  116. package/lib-esm/TextInputWithTokens.d.ts +8 -10
  117. package/lib-esm/TextInputWithTokens.js +30 -101
  118. package/lib-esm/Timeline.d.ts +4 -4
  119. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  120. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  121. package/lib-esm/Token/Token.d.ts +1 -1
  122. package/lib-esm/Token/Token.js +2 -13
  123. package/lib-esm/Token/TokenBase.js +4 -0
  124. package/lib-esm/Token/_RemoveTokenButton.js +2 -11
  125. package/lib-esm/_TextInputWrapper.d.ts +1 -1
  126. package/lib-esm/_TextInputWrapper.js +1 -1
  127. package/lib-esm/hooks/useDebounce.d.ts +2 -0
  128. package/lib-esm/hooks/useDebounce.js +16 -0
  129. package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
  130. package/lib-esm/hooks/useResizeObserver.js +1 -1
  131. package/lib-esm/sx.d.ts +2 -8
  132. package/lib-esm/theme-preval.js +2 -2
  133. package/lib-esm/theme.d.ts +0 -78
  134. package/lib-esm/theme.js +1 -2
  135. package/lib-esm/utils/testing.d.ts +1 -1
  136. package/package.json +14 -15
  137. package/lib/utils/types/KeyPaths.d.ts +0 -3
  138. package/lib/utils/types/KeyPaths.js +0 -1
  139. package/lib-esm/utils/types/KeyPaths.d.ts +0 -3
  140. package/lib-esm/utils/types/KeyPaths.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { get } from './constants';
2
+ import { COMMON, get } from './constants';
3
3
  import StyledOcticon from './StyledOcticon';
4
4
  import sx from './sx';
5
5
  import isNumeric from './utils/isNumeric';
@@ -23,7 +23,7 @@ const sizeStyles = ({
23
23
  const CircleBadge = styled.div.withConfig({
24
24
  displayName: "CircleBadge",
25
25
  componentId: "sc-1lho816-0"
26
- })(["display:", ";align-items:center;justify-content:center;background-color:", ";border-radius:50%;box-shadow:", ";", ";", ";"], props => props.inline ? 'inline-flex' : 'flex', get('colors.canvas.default'), get('shadows.shadow.medium'), sizeStyles, sx);
26
+ })(["display:", ";align-items:center;justify-content:center;background-color:", ";border-radius:50%;box-shadow:", ";", ";", ";", ";"], props => props.inline ? 'inline-flex' : 'flex', get('colors.canvas.default'), get('shadows.shadow.medium'), COMMON, sizeStyles, sx);
27
27
  const CircleBadgeIcon = styled(StyledOcticon).withConfig({
28
28
  displayName: "CircleBadge__CircleBadgeIcon",
29
29
  componentId: "sc-1lho816-1"
@@ -13,7 +13,6 @@ declare namespace CircleOcticon {
13
13
  var defaultProps: {
14
14
  size: number;
15
15
  lineHeight?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
16
- border?: import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
17
16
  alignContent?: import("styled-system").ResponsiveValue<import("csstype").Property.AlignContent, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
18
17
  alignItems?: import("styled-system").ResponsiveValue<import("csstype").Property.AlignItems, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
19
18
  alignSelf?: import("styled-system").ResponsiveValue<import("csstype").Property.AlignSelf, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
@@ -89,6 +88,7 @@ declare namespace CircleOcticon {
89
88
  zIndex?: import("styled-system").ResponsiveValue<import("csstype").Property.ZIndex, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
90
89
  background?: import("styled-system").ResponsiveValue<import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
91
90
  backgroundPosition?: import("styled-system").ResponsiveValue<import("csstype").Property.BackgroundPosition<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
91
+ border?: import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
92
92
  borderBottom?: import("styled-system").ResponsiveValue<import("csstype").Property.BorderBottom<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
93
93
  borderColor?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
94
94
  borderLeft?: import("styled-system").ResponsiveValue<import("csstype").Property.BorderLeft<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
@@ -151,7 +151,7 @@ declare namespace CircleOcticon {
151
151
  results?: number | undefined;
152
152
  security?: string | undefined;
153
153
  unselectable?: "on" | "off" | undefined;
154
- inputMode?: "search" | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
154
+ inputMode?: "none" | "text" | "search" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
155
155
  is?: string | undefined;
156
156
  'aria-activedescendant'?: string | undefined;
157
157
  'aria-atomic'?: boolean | "true" | "false" | undefined;
@@ -166,7 +166,7 @@ declare namespace CircleOcticon {
166
166
  'aria-describedby'?: string | undefined;
167
167
  'aria-details'?: string | undefined;
168
168
  'aria-disabled'?: boolean | "true" | "false" | undefined;
169
- 'aria-dropeffect'?: "link" | "none" | "copy" | "execute" | "move" | "popup" | undefined;
169
+ 'aria-dropeffect'?: "none" | "link" | "copy" | "execute" | "move" | "popup" | undefined;
170
170
  'aria-errormessage'?: string | undefined;
171
171
  'aria-expanded'?: boolean | "true" | "false" | undefined;
172
172
  'aria-flowto'?: string | undefined;
@@ -384,7 +384,7 @@ declare namespace CircleOcticon {
384
384
  paddingY?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
385
385
  borderX?: import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
386
386
  borderY?: import("styled-system").ResponsiveValue<import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
387
- sx?: import("./sx").BetterSystemStyleObject | undefined;
387
+ sx?: import("@styled-system/css").SystemStyleObject | undefined;
388
388
  theme?: any;
389
389
  };
390
390
  }
@@ -0,0 +1,48 @@
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 {};
@@ -0,0 +1,92 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { DatePickerAnchor } from './DatePickerAnchor';
3
+ import { DatePickerProvider } from './useDatePicker';
4
+ import { DatePickerOverlay } from './DatePickerOverlay';
5
+ export const DatePicker = ({
6
+ anchorVariant,
7
+ anchorRef: externalAnchorRef,
8
+ confirmation,
9
+ confirmUnsavedClose,
10
+ compressedHeader,
11
+ dateFormat,
12
+ disableWeekends,
13
+ focusTrapSettings,
14
+ focusZoneSettings,
15
+ iconPlacement,
16
+ maxDate,
17
+ maxRangeSize,
18
+ maxSelections,
19
+ minDate,
20
+ onOpen: onOpenExternal,
21
+ onClose: onCloseExternal,
22
+ open,
23
+ overlayProps,
24
+ placeholder,
25
+ renderAnchor,
26
+ showInputPrompt,
27
+ value,
28
+ variant,
29
+ view,
30
+ weekStartsOn
31
+ }) => {
32
+ const anchorRef = useRef(null);
33
+ const [isOpen, setIsOpen] = useState(false);
34
+ const datePickerConfiguration = {
35
+ anchorVariant,
36
+ confirmation,
37
+ confirmUnsavedClose,
38
+ compressedHeader,
39
+ dateFormat,
40
+ disableWeekends,
41
+ iconPlacement,
42
+ maxDate: maxDate ? new Date(new Date(maxDate).toDateString()) : maxDate,
43
+ maxRangeSize,
44
+ maxSelections,
45
+ minDate: minDate ? new Date(new Date(minDate).toDateString()) : minDate,
46
+ placeholder,
47
+ showInputPrompt,
48
+ variant,
49
+ view,
50
+ weekStartsOn
51
+ };
52
+
53
+ const onOpen = gesture => {
54
+ setIsOpen(true);
55
+ onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
56
+ };
57
+
58
+ const onClose = gesture => {
59
+ setIsOpen(false);
60
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
61
+ };
62
+
63
+ const toggleIsOpen = () => {
64
+ if (isOpen) {
65
+ setIsOpen(false);
66
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
67
+ } else {
68
+ setIsOpen(true);
69
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
70
+ }
71
+ };
72
+
73
+ return /*#__PURE__*/React.createElement(DatePickerProvider, {
74
+ configuration: datePickerConfiguration,
75
+ isOpen: isOpen,
76
+ value: value,
77
+ closePicker: () => setIsOpen(false)
78
+ }, /*#__PURE__*/React.createElement(DatePickerAnchor, {
79
+ ref: anchorRef,
80
+ onAction: toggleIsOpen
81
+ }), /*#__PURE__*/React.createElement(DatePickerOverlay, {
82
+ anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : anchorRef,
83
+ renderAnchor: renderAnchor,
84
+ open: open !== null && open !== void 0 ? open : isOpen,
85
+ onOpen: onOpen,
86
+ onClose: onClose,
87
+ overlayProps: overlayProps,
88
+ focusTrapSettings: focusTrapSettings,
89
+ focusZoneSettings: focusZoneSettings
90
+ }));
91
+ };
92
+ DatePicker.displayName = "DatePicker";
@@ -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,174 @@
1
+ import { AlertIcon, CalendarIcon, CheckIcon } from '@primer/octicons-react';
2
+ import styled from 'styled-components';
3
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import Button, { ButtonInvisible } from '../Button';
5
+ import Text from '../Text';
6
+ import { get } from '../constants';
7
+ import StyledOcticon from '../StyledOcticon';
8
+ import useDatePicker from './useDatePicker';
9
+ import TextInput from '../TextInput';
10
+ import Box from '../Box';
11
+ import { parseDate } from './dateParser';
12
+ import { Tooltip } from '..';
13
+ const DatePickerAnchorButton = styled(Button).withConfig({
14
+ displayName: "DatePickerAnchor__DatePickerAnchorButton",
15
+ componentId: "sc-8gpb9d-0"
16
+ })(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;max-width:350px;overflow:hidden;& ", " ~ svg{margin-left:", ";}& svg ~ ", "{margin-left:", ";}"], Text, get('space.2'), Text, get('space.2'));
17
+ export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
18
+ onAction
19
+ }, ref) => {
20
+ const {
21
+ configuration: {
22
+ anchorVariant,
23
+ iconPlacement,
24
+ placeholder,
25
+ variant
26
+ },
27
+ disabled,
28
+ formattedDate,
29
+ inputDate,
30
+ onDateInput
31
+ } = useDatePicker();
32
+ const [inputValue, setInputValue] = useState(formattedDate);
33
+ const inputRef = useRef(null);
34
+ const [inputValid, setInputValid] = useState(true);
35
+ const [inputFocused, setInputFocused] = useState(false);
36
+ const keyPressHandler = useCallback(event => {
37
+ if (disabled) {
38
+ return;
39
+ }
40
+
41
+ if ([' ', 'Enter'].includes(event.key)) {
42
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
43
+ }
44
+ }, [disabled, onAction]);
45
+ const clickHandler = useCallback(event => {
46
+ if (disabled) {
47
+ return;
48
+ }
49
+
50
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
51
+ }, [disabled, onAction]);
52
+ useEffect(() => {
53
+ if (document.activeElement !== inputRef.current) {
54
+ setInputValue(formattedDate);
55
+ }
56
+ }, [formattedDate]);
57
+ const onInputChangeHandler = useCallback(e => {
58
+ const value = e.currentTarget.value;
59
+ setInputValue(value);
60
+
61
+ if (!value) {
62
+ return;
63
+ }
64
+
65
+ const parsedDate = parseDate(value, variant);
66
+ setInputValid(!!parsedDate);
67
+
68
+ if (parsedDate) {
69
+ onDateInput(parsedDate);
70
+ }
71
+ }, [onDateInput, variant]);
72
+
73
+ const onFocusHandler = () => {
74
+ setInputValue(inputDate);
75
+ setInputFocused(true);
76
+ };
77
+
78
+ const onBlurHandler = () => {
79
+ setInputValue(formattedDate);
80
+ setInputValid(true);
81
+ setInputFocused(false);
82
+ };
83
+
84
+ const inputSx = useMemo(() => {
85
+ let sxObject = {};
86
+
87
+ if (iconPlacement === 'start') {
88
+ sxObject = { ...sxObject,
89
+ pl: 5,
90
+ pr: 2
91
+ };
92
+ } else if (iconPlacement === 'end') {
93
+ sxObject = { ...sxObject,
94
+ pl: 2,
95
+ pr: 5
96
+ };
97
+ }
98
+
99
+ return sxObject;
100
+ }, [iconPlacement]);
101
+
102
+ if (anchorVariant === 'input') {
103
+ const calendarButton = side => /*#__PURE__*/React.createElement(ButtonInvisible, {
104
+ onClick: clickHandler,
105
+ sx: {
106
+ width: '32px',
107
+ px: '6px',
108
+ position: 'absolute',
109
+ [side]: '1px',
110
+ top: '1px',
111
+ bottom: '1px'
112
+ }
113
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
114
+ icon: CalendarIcon
115
+ }));
116
+
117
+ const iconSx = () => ({
118
+ position: 'absolute',
119
+ top: 0,
120
+ bottom: 0,
121
+ right: iconPlacement === 'end' ? '36px' : '10px',
122
+ display: 'flex',
123
+ alignItems: 'center'
124
+ });
125
+
126
+ return /*#__PURE__*/React.createElement(Box, {
127
+ ref: ref,
128
+ sx: {
129
+ position: 'relative',
130
+ display: 'flex'
131
+ }
132
+ }, iconPlacement === 'start' && calendarButton('left'), /*#__PURE__*/React.createElement(TextInput, {
133
+ ref: inputRef,
134
+ placeholder: placeholder,
135
+ value: inputValue,
136
+ onChange: onInputChangeHandler,
137
+ sx: inputSx,
138
+ onBlur: onBlurHandler,
139
+ onFocus: onFocusHandler
140
+ }), /*#__PURE__*/React.createElement(Box, {
141
+ sx: iconSx()
142
+ }, inputValid && inputFocused && /*#__PURE__*/React.createElement(StyledOcticon, {
143
+ icon: CheckIcon,
144
+ color: "success.emphasis"
145
+ }), !inputValid && /*#__PURE__*/React.createElement(Tooltip, {
146
+ direction: "s",
147
+ text: "Invalid entry. Please make sure you use the 'MM/DD/YYYY' format."
148
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
149
+ icon: AlertIcon,
150
+ color: "attention.emphasis"
151
+ }))), iconPlacement === 'end' && calendarButton('right'));
152
+ }
153
+
154
+ const calendarIcon = () => /*#__PURE__*/React.createElement(StyledOcticon, {
155
+ icon: CalendarIcon,
156
+ color: "fg.muted",
157
+ sx: {
158
+ my: '2px'
159
+ }
160
+ });
161
+
162
+ return /*#__PURE__*/React.createElement(Box, {
163
+ ref: ref
164
+ }, /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
165
+ onClick: clickHandler,
166
+ onKeyPress: keyPressHandler,
167
+ "aria-label": formattedDate
168
+ }, iconPlacement === 'start' && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
169
+ sx: {
170
+ overflow: 'hidden',
171
+ textOverflow: 'ellipsis'
172
+ }
173
+ }, formattedDate), iconPlacement === 'end' && calendarIcon()));
174
+ });
@@ -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,38 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from 'react';
4
+ import useDatePicker from './useDatePicker';
5
+ import { AnchoredOverlay } from '../AnchoredOverlay';
6
+ import { DatePickerPanel } from './DatePickerPanel';
7
+ export const DatePickerOverlay = ({
8
+ onClose,
9
+ ...rest
10
+ }) => {
11
+ const {
12
+ dialogOpen,
13
+ onClose: onDatePickerClose,
14
+ setDialogOpen,
15
+ currentViewingDate
16
+ } = useDatePicker();
17
+
18
+ const onOverlayClose = async gesture => {
19
+ if (!dialogOpen) {
20
+ setDialogOpen(true);
21
+ await onDatePickerClose();
22
+ setDialogOpen(false);
23
+ onClose === null || onClose === void 0 ? void 0 : onClose(gesture);
24
+ }
25
+ };
26
+
27
+ return /*#__PURE__*/React.createElement(AnchoredOverlay, _extends({
28
+ onClose: onOverlayClose,
29
+ focusZoneSettings: {
30
+ disabled: true
31
+ }
32
+ }, rest, {
33
+ "aria-modal": "true",
34
+ "aria-labelledby": `${currentViewingDate.getMonth()} ${currentViewingDate.getFullYear()}`,
35
+ "aria-live": "polite"
36
+ }), /*#__PURE__*/React.createElement(DatePickerPanel, null));
37
+ };
38
+ DatePickerOverlay.displayName = "DatePickerOverlay";
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const DatePickerPanel: () => JSX.Element;
@@ -0,0 +1,201 @@
1
+ import { addMonths, subMonths } from 'date-fns';
2
+ import React, { useCallback, useMemo, useRef } from 'react';
3
+ import Box from '../Box';
4
+ import { Month } from './Month';
5
+ import styled from 'styled-components';
6
+ import { COMMON, get, TYPOGRAPHY } from '../constants';
7
+ import useDatePicker from './useDatePicker';
8
+ import { ChevronLeftIcon, ChevronRightIcon } from '@primer/octicons-react';
9
+ import StyledOcticon from '../StyledOcticon';
10
+ import Button, { ButtonPrimary } from '../Button';
11
+ import sx from '../sx';
12
+ import { useFocusZone } from '../hooks/useFocusZone';
13
+ import { FocusKeys } from '../behaviors/focusZone';
14
+ const DatePickerPanelContainer = styled(Box).withConfig({
15
+ displayName: "DatePickerPanel__DatePickerPanelContainer",
16
+ componentId: "sc-19upxpo-0"
17
+ })(["align-items:stretch;display:flex;flex-direction:column;position:relative;"]);
18
+ const DatePickerTopNav = styled(Box).withConfig({
19
+ displayName: "DatePickerPanel__DatePickerTopNav",
20
+ componentId: "sc-19upxpo-1"
21
+ })(["display:flex;justify-content:space-between;position:absolute;top:0;left:0;right:0;padding:", ";z-index:10;"], get('space.3'));
22
+ const DatePickerPanelMonths = styled(Box).withConfig({
23
+ displayName: "DatePickerPanel__DatePickerPanelMonths",
24
+ componentId: "sc-19upxpo-2"
25
+ })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";margin-top:", ";padding:", ";position:relative;"], get('space.6'), get('space.1'), get('space.3'));
26
+ const DatePickerPanelFooter = styled(Box).withConfig({
27
+ displayName: "DatePickerPanel__DatePickerPanelFooter",
28
+ componentId: "sc-19upxpo-3"
29
+ })(["align-items:flex-start;border-top:1px solid;border-top-color:", ";display:flex;gap:", ";padding-top:12px;padding-bottom:12px;padding-left:", ";padding-right:", ";flex-direction:row;justify-content:space-between;position:relative;"], get('colors.border.default'), get('space.6'), get('space.3'), get('space.3'));
30
+ const ArrowButton = styled(Button).withConfig({
31
+ displayName: "DatePickerPanel__ArrowButton",
32
+ componentId: "sc-19upxpo-4"
33
+ })(["width:40px;height:28px;"]);
34
+ const Select = styled.select.withConfig({
35
+ displayName: "DatePickerPanel__Select",
36
+ componentId: "sc-19upxpo-5"
37
+ })(["background:", ";border:0;color:", ";font-weight:600;", ";", ";", ";"], get('colors.canvas.default'), get('colors.fg.default'), TYPOGRAPHY, COMMON, sx);
38
+ const Option = styled.option.withConfig({
39
+ displayName: "DatePickerPanel__Option",
40
+ componentId: "sc-19upxpo-6"
41
+ })(["background:", ";border:0;color:", ";font-weight:400;padding:", " ", ";", ";", ";", ";"], get('colors.canvas.default'), get('colors.fg.default'), get('space.2'), get('space.2'), TYPOGRAPHY, COMMON, sx);
42
+ export const DatePickerPanel = () => {
43
+ const {
44
+ configuration,
45
+ saveValue,
46
+ revertValue,
47
+ currentViewingDate,
48
+ goToMonth,
49
+ nextMonth,
50
+ previousMonth,
51
+ viewMode
52
+ } = useDatePicker();
53
+ const panelRef = useRef(null);
54
+ const headerRef = useRef(null);
55
+ const datePanelRef = useRef(null);
56
+ const footerRef = useRef(null);
57
+ useFocusZone({
58
+ containerRef: headerRef,
59
+ bindKeys: FocusKeys.Tab,
60
+ focusInStrategy: 'closest'
61
+ });
62
+ useFocusZone({
63
+ containerRef: footerRef,
64
+ bindKeys: FocusKeys.Tab,
65
+ focusInStrategy: 'closest'
66
+ });
67
+ const previousDisabled = useMemo(() => {
68
+ const {
69
+ minDate
70
+ } = configuration;
71
+ if (!minDate) return false;
72
+ const previous = subMonths(currentViewingDate, 1);
73
+
74
+ if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
75
+ return true;
76
+ }
77
+
78
+ return false;
79
+ }, [configuration, currentViewingDate]);
80
+ const nextDisabled = useMemo(() => {
81
+ const {
82
+ maxDate,
83
+ view
84
+ } = configuration;
85
+ if (!maxDate) return false;
86
+ const next = addMonths(currentViewingDate, view === '2-month' ? 2 : 1);
87
+
88
+ if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
89
+ return true;
90
+ }
91
+
92
+ return false;
93
+ }, [configuration, currentViewingDate]);
94
+ const currentMonth = useMemo(() => currentViewingDate.getMonth(), [currentViewingDate]);
95
+ const currentYear = useMemo(() => currentViewingDate.getFullYear(), [currentViewingDate]);
96
+ const headerSelectionHandler = useCallback(e => {
97
+ const selection = parseInt(e.currentTarget.value, 10);
98
+
99
+ if (e.currentTarget.id === 'picker-header-year') {
100
+ goToMonth(new Date(selection, currentMonth));
101
+ } else {
102
+ goToMonth(new Date(currentYear, selection));
103
+ }
104
+ }, [currentMonth, currentYear, goToMonth]);
105
+ const getMonthPicker = useMemo(() => {
106
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
107
+ const monthElements = [];
108
+
109
+ for (let i = 0; i < months.length; i++) {
110
+ monthElements.push( /*#__PURE__*/React.createElement(Option, {
111
+ key: i,
112
+ value: i
113
+ }, months[i]));
114
+ }
115
+
116
+ return /*#__PURE__*/React.createElement(Select, {
117
+ id: "picker-header-month",
118
+ value: currentMonth,
119
+ sx: {
120
+ mr: '6px'
121
+ },
122
+ onChange: headerSelectionHandler
123
+ }, monthElements);
124
+ }, [currentMonth, headerSelectionHandler]);
125
+ const getYearPicker = useMemo(() => {
126
+ const years = [];
127
+ const minYear = currentYear - 200;
128
+ const maxYear = currentYear + 200;
129
+
130
+ for (let i = minYear; i <= maxYear; i++) {
131
+ years.push( /*#__PURE__*/React.createElement(Option, {
132
+ key: i,
133
+ value: i
134
+ }, i));
135
+ }
136
+
137
+ return /*#__PURE__*/React.createElement(Select, {
138
+ id: "picker-header-year",
139
+ value: currentYear,
140
+ onChange: headerSelectionHandler
141
+ }, years);
142
+ }, [currentYear, headerSelectionHandler]);
143
+ return /*#__PURE__*/React.createElement(DatePickerPanelContainer, {
144
+ ref: panelRef
145
+ }, /*#__PURE__*/React.createElement(DatePickerTopNav, {
146
+ ref: headerRef
147
+ }, configuration.compressedHeader && /*#__PURE__*/React.createElement(Box, {
148
+ sx: {
149
+ flex: 1
150
+ }
151
+ }, getMonthPicker, getYearPicker), /*#__PURE__*/React.createElement(ArrowButton, {
152
+ variant: "small",
153
+ sx: {
154
+ mr: 1
155
+ },
156
+ onClick: previousMonth,
157
+ disabled: previousDisabled,
158
+ "aria-label": "Previous Month",
159
+ "aria-live": "polite"
160
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
161
+ icon: ChevronLeftIcon,
162
+ color: "fg.muted"
163
+ })), /*#__PURE__*/React.createElement(ArrowButton, {
164
+ variant: "small",
165
+ onClick: nextMonth,
166
+ disabled: nextDisabled,
167
+ "aria-label": "Next Month",
168
+ "aria-live": "polite"
169
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
170
+ icon: ChevronRightIcon,
171
+ color: "fg.muted"
172
+ }))), /*#__PURE__*/React.createElement(DatePickerPanelMonths, {
173
+ ref: datePanelRef,
174
+ tabIndex: 0
175
+ }, /*#__PURE__*/React.createElement(Month, {
176
+ date: currentViewingDate
177
+ }), viewMode === '2-month' && /*#__PURE__*/React.createElement(Month, {
178
+ date: addMonths(currentViewingDate, 1)
179
+ })), /*#__PURE__*/React.createElement(DatePickerPanelFooter, {
180
+ ref: footerRef
181
+ }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Button, {
182
+ variant: "small",
183
+ sx: {
184
+ mr: 1
185
+ },
186
+ onClick: () => revertValue(),
187
+ "aria-label": "Reset Selection",
188
+ "aria-live": "polite"
189
+ }, "Reset"), /*#__PURE__*/React.createElement(Button, {
190
+ variant: "small",
191
+ onClick: () => goToMonth(new Date()),
192
+ "aria-label": "Go to Today",
193
+ "aria-live": "polite"
194
+ }, "Today")), configuration.confirmation && /*#__PURE__*/React.createElement(ButtonPrimary, {
195
+ variant: "small",
196
+ onClick: () => saveValue(),
197
+ "aria-label": "Apply Selection",
198
+ "aria-live": "polite"
199
+ }, "Apply")));
200
+ };
201
+ DatePickerPanel.displayName = "DatePickerPanel";
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { FontSizeProps } from 'styled-system';
3
+ import { SystemCommonProps, SystemLayoutProps } from '../constants';
4
+ import { SxProp } from '../sx';
5
+ import { DaySelection } from './useDatePicker';
6
+ export declare type DayProps = {
7
+ blocked?: boolean;
8
+ disabled?: boolean;
9
+ focused?: boolean;
10
+ onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
11
+ selected?: DaySelection;
12
+ date: Date;
13
+ } & FontSizeProps & SystemCommonProps & SxProp & SystemLayoutProps;
14
+ export declare const Day: React.FC<DayProps>;
15
+ export declare const BlankDay: import("styled-components").StyledComponent<"div", any, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").TypographyProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").GridProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> & import("styled-system").BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ShadowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & SxProp, never>;