@primer/components 0.0.0-202192701132 → 0.0.0-2021927175656

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 (76) hide show
  1. package/CHANGELOG.md +8 -4
  2. package/dist/browser.esm.js +2 -2
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +2 -2
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  7. package/lib/Autocomplete/Autocomplete.d.ts +5 -3
  8. package/lib/Autocomplete/AutocompleteInput.d.ts +5 -3
  9. package/lib/Button/ButtonClose.d.ts +1 -1
  10. package/lib/CircleOcticon.d.ts +1 -1
  11. package/lib/DatePicker/DatePicker.d.ts +48 -0
  12. package/lib/DatePicker/DatePicker.js +100 -0
  13. package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
  14. package/lib/DatePicker/DatePickerAnchor.js +182 -0
  15. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  16. package/lib/DatePicker/DatePickerOverlay.js +39 -0
  17. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  18. package/lib/DatePicker/DatePickerPanel.js +126 -0
  19. package/lib/DatePicker/Day.d.ts +14 -0
  20. package/lib/DatePicker/Day.js +192 -0
  21. package/lib/DatePicker/Month.d.ts +9 -0
  22. package/lib/DatePicker/Month.js +120 -0
  23. package/lib/DatePicker/index.d.ts +2 -0
  24. package/lib/DatePicker/index.js +13 -0
  25. package/lib/DatePicker/useDatePicker.d.ts +88 -0
  26. package/lib/DatePicker/useDatePicker.js +383 -0
  27. package/lib/Dialog.d.ts +1 -1
  28. package/lib/Dropdown.d.ts +4 -4
  29. package/lib/DropdownMenu/DropdownButton.d.ts +1 -1
  30. package/lib/FilterList.d.ts +1 -1
  31. package/lib/SelectMenu/SelectMenu.d.ts +9 -7
  32. package/lib/TextInputWithTokens.d.ts +5 -3
  33. package/lib/Timeline.d.ts +1 -1
  34. package/lib/hooks/useDebounce.d.ts +2 -0
  35. package/lib/hooks/useDebounce.js +24 -0
  36. package/lib/sx.d.ts +2 -8
  37. package/lib/theme-preval.js +2 -2
  38. package/lib/theme.d.ts +0 -4
  39. package/lib/theme.js +1 -96
  40. package/lib/utils/testing.d.ts +1 -1
  41. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  42. package/lib-esm/Autocomplete/Autocomplete.d.ts +5 -3
  43. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +5 -3
  44. package/lib-esm/Button/ButtonClose.d.ts +1 -1
  45. package/lib-esm/CircleOcticon.d.ts +1 -1
  46. package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
  47. package/lib-esm/DatePicker/DatePicker.js +83 -0
  48. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
  49. package/lib-esm/DatePicker/DatePickerAnchor.js +155 -0
  50. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  51. package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
  52. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  53. package/lib-esm/DatePicker/DatePickerPanel.js +100 -0
  54. package/lib-esm/DatePicker/Day.d.ts +14 -0
  55. package/lib-esm/DatePicker/Day.js +169 -0
  56. package/lib-esm/DatePicker/Month.d.ts +9 -0
  57. package/lib-esm/DatePicker/Month.js +96 -0
  58. package/lib-esm/DatePicker/index.d.ts +2 -0
  59. package/lib-esm/DatePicker/index.js +1 -0
  60. package/lib-esm/DatePicker/useDatePicker.d.ts +88 -0
  61. package/lib-esm/DatePicker/useDatePicker.js +355 -0
  62. package/lib-esm/Dialog.d.ts +1 -1
  63. package/lib-esm/Dropdown.d.ts +4 -4
  64. package/lib-esm/DropdownMenu/DropdownButton.d.ts +1 -1
  65. package/lib-esm/FilterList.d.ts +1 -1
  66. package/lib-esm/SelectMenu/SelectMenu.d.ts +9 -7
  67. package/lib-esm/TextInputWithTokens.d.ts +5 -3
  68. package/lib-esm/Timeline.d.ts +1 -1
  69. package/lib-esm/hooks/useDebounce.d.ts +2 -0
  70. package/lib-esm/hooks/useDebounce.js +16 -0
  71. package/lib-esm/sx.d.ts +2 -8
  72. package/lib-esm/theme-preval.js +2 -2
  73. package/lib-esm/theme.d.ts +0 -4
  74. package/lib-esm/theme.js +1 -95
  75. package/lib-esm/utils/testing.d.ts +1 -1
  76. package/package.json +9 -8
package/lib/theme.js CHANGED
@@ -7,100 +7,5 @@ exports.default = void 0;
7
7
 
8
8
  var _themePreval = require("./theme-preval");
9
9
 
10
- var _default = _themePreval.theme; // typecheck our theme instance:
11
- // theme as Theme
12
- // type ThemeColors = {
13
- // fg: {
14
- // default: 'XXXXXXXXXXX',
15
- // muted: 'XXXXXXXXXXX',
16
- // subtle: 'XXXXXXXXXXX',
17
- // onEmphasis: 'XXXXXXXXXXX'
18
- // },
19
- // canvas: {
20
- // default: 'XXXXXXXXXXX',
21
- // overlay: 'XXXXXXXXXXX',
22
- // inset: 'XXXXXXXXXXX',
23
- // subtle: 'XXXXXXXXXXX'
24
- // },
25
- // border: {
26
- // default: 'XXXXXXXXXXX',
27
- // muted: 'XXXXXXXXXXX',
28
- // subtle: 'XXXXXXXXXXX'
29
- // },
30
- // shadow: {
31
- // small: 'XXXXXXXXXXX',
32
- // medium: 'XXXXXXXXXXX',
33
- // large: 'XXXXXXXXXXX',
34
- // extraLarge: 'XXXXXXXXXXX'
35
- // },
36
- // // Roles
37
- // neutral: {
38
- // emphasisPlus: string,
39
- // emphasis: string,
40
- // muted: string,
41
- // subtle: string
42
- // },
43
- // accent: {
44
- // fg: string,
45
- // emphasis: string,
46
- // muted: string,
47
- // subtle: string
48
- // },
49
- // success: {
50
- // fg: string,
51
- // emphasis: string,
52
- // muted: string,
53
- // subtle: string
54
- // },
55
- // attention: {
56
- // fg: string,
57
- // emphasis: string,
58
- // muted: string,
59
- // subtle: string
60
- // },
61
- // severe: {
62
- // fg: string,
63
- // emphasis: string,
64
- // muted: string,
65
- // subtle: string
66
- // },
67
- // danger: {
68
- // fg: string,
69
- // emphasis: string,
70
- // muted: string,
71
- // subtle: string
72
- // },
73
- // done: {
74
- // fg: string,
75
- // emphasis: string,
76
- // muted: string,
77
- // subtle: string
78
- // },
79
- // sponsors: {
80
- // fg: string,
81
- // emphasis: string,
82
- // muted: string,
83
- // subtle: string
84
- // },
85
- // // Only meant for Primer components
86
- // primer: {
87
- // fg: {
88
- // disabled: string
89
- // },
90
- // canvas: {
91
- // backdrop: string,
92
- // sticky: string
93
- // },
94
- // border: {
95
- // active: string,
96
- // contrast: string
97
- // },
98
- // shadow: {
99
- // highlight: string,
100
- // inset: string,
101
- // focus: string
102
- // }
103
- // }
104
- // }
105
-
10
+ var _default = _themePreval.theme;
106
11
  exports.default = _default;
@@ -53,7 +53,7 @@ export declare function render(component: React.ReactElement, theme?: {
53
53
  xlarge: string;
54
54
  };
55
55
  space: string[];
56
- colorSchemes: Record<"light" | "light_protanopia" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
56
+ colorSchemes: Record<"light" | "light_colorblind" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_colorblind", Record<"colors" | "shadows", Partial<{
57
57
  canvasDefaultTransparent: string;
58
58
  marketingIcon: {
59
59
  primary: string;
@@ -26,6 +26,8 @@ interface AnchoredOverlayPropsWithoutAnchor {
26
26
  */
27
27
  anchorRef: React.RefObject<HTMLElement>;
28
28
  }
29
+ export declare type OverlayOpenGesture = 'anchor-click' | 'anchor-key-press';
30
+ export declare type OverlayCloseGesture = 'anchor-click' | 'click-outside' | 'escape';
29
31
  export declare type AnchoredOverlayWrapperAnchorProps = Partial<AnchoredOverlayPropsWithAnchor> | AnchoredOverlayPropsWithoutAnchor;
30
32
  interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'> {
31
33
  /**
@@ -35,11 +37,11 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'
35
37
  /**
36
38
  * A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
37
39
  */
38
- onOpen?: (gesture: 'anchor-click' | 'anchor-key-press') => unknown;
40
+ onOpen?: (gesture: OverlayOpenGesture) => unknown;
39
41
  /**
40
42
  * A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
41
43
  */
42
- onClose?: (gesture: 'anchor-click' | 'click-outside' | 'escape') => unknown;
44
+ onClose?: (gesture: OverlayCloseGesture) => unknown;
43
45
  /**
44
46
  * Props to be spread on the internal `Overlay` component.
45
47
  */
@@ -12,12 +12,14 @@ export type { AutocompleteOverlayProps } from './AutocompleteOverlay';
12
12
  declare const _default: React.FC<{
13
13
  id?: string | undefined;
14
14
  }> & {
15
- Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<{
15
+ Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<({
16
16
  [x: string]: any;
17
17
  [x: number]: any;
18
18
  } & {
19
19
  theme?: any;
20
- } & {
20
+ } & ({} | {
21
+ children?: React.ReactNode;
22
+ })) & {
21
23
  as?: string | React.ComponentType<any> | undefined;
22
24
  forwardedAs?: string | React.ComponentType<any> | undefined;
23
25
  }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
@@ -288,7 +290,7 @@ declare const _default: React.FC<{
288
290
  onTransitionEnd?: React.TransitionEventHandler<HTMLSpanElement> | undefined;
289
291
  onTransitionEndCapture?: React.TransitionEventHandler<HTMLSpanElement> | undefined;
290
292
  block?: boolean | undefined;
291
- sx?: import("../sx").BetterSystemStyleObject | undefined;
293
+ sx?: import("@styled-system/css").SystemStyleObject | undefined;
292
294
  disabled?: boolean | undefined;
293
295
  variant?: "large" | "small" | undefined;
294
296
  hasIcon?: boolean | undefined;
@@ -4,12 +4,14 @@ import { ComponentProps } from '../utils/types';
4
4
  declare type InternalAutocompleteInputProps = {
5
5
  as?: React.ComponentType<any>;
6
6
  };
7
- declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<{
7
+ declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<({
8
8
  [x: string]: any;
9
9
  [x: number]: any;
10
10
  } & {
11
11
  theme?: any;
12
- } & {
12
+ } & ({} | {
13
+ children?: React.ReactNode;
14
+ })) & {
13
15
  as?: string | React.ComponentType<any> | undefined;
14
16
  forwardedAs?: string | React.ComponentType<any> | undefined;
15
17
  }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
@@ -280,7 +282,7 @@ declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRef
280
282
  onTransitionEnd?: React.TransitionEventHandler<HTMLSpanElement> | undefined;
281
283
  onTransitionEndCapture?: React.TransitionEventHandler<HTMLSpanElement> | undefined;
282
284
  block?: boolean | undefined;
283
- sx?: import("../sx").BetterSystemStyleObject | undefined;
285
+ sx?: import("@styled-system/css").SystemStyleObject | undefined;
284
286
  disabled?: boolean | undefined;
285
287
  variant?: "large" | "small" | undefined;
286
288
  hasIcon?: boolean | undefined;
@@ -306,7 +306,7 @@ declare const ButtonClose: React.ForwardRefExoticComponent<Pick<{
306
306
  py?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
307
307
  paddingY?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
308
308
  size?: import("styled-system").ResponsiveValue<import("csstype").Property.Height<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
309
- sx?: import("../sx").BetterSystemStyleObject | undefined;
309
+ sx?: import("@styled-system/css").SystemStyleObject | undefined;
310
310
  autoFocus?: boolean | undefined;
311
311
  disabled?: boolean | undefined;
312
312
  formAction?: 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,83 @@
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
+ dateFormat,
10
+ focusTrapSettings,
11
+ focusZoneSettings,
12
+ iconPlacement,
13
+ maxDate,
14
+ maxRange,
15
+ maxSelections,
16
+ minDate,
17
+ onOpen: onOpenExternal,
18
+ onClose: onCloseExternal,
19
+ open,
20
+ overlayProps,
21
+ placeholder,
22
+ renderAnchor,
23
+ selection,
24
+ value,
25
+ view,
26
+ weekStartsOn
27
+ }) => {
28
+ const anchorRef = useRef(null);
29
+ const [isOpen, setIsOpen] = useState(false);
30
+ const datePickerConfiguration = {
31
+ anchorVariant,
32
+ confirmation,
33
+ dateFormat,
34
+ iconPlacement,
35
+ maxDate,
36
+ maxRange,
37
+ maxSelections,
38
+ minDate,
39
+ placeholder,
40
+ selection,
41
+ view,
42
+ weekStartsOn
43
+ };
44
+
45
+ const onOpen = gesture => {
46
+ setIsOpen(true);
47
+ onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
48
+ };
49
+
50
+ const onClose = gesture => {
51
+ setIsOpen(false);
52
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
53
+ };
54
+
55
+ const toggleIsOpen = () => {
56
+ if (isOpen) {
57
+ setIsOpen(false);
58
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
59
+ } else {
60
+ setIsOpen(true);
61
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
62
+ }
63
+ };
64
+
65
+ return /*#__PURE__*/React.createElement(DatePickerProvider, {
66
+ configuration: datePickerConfiguration,
67
+ value: value,
68
+ closePicker: () => setIsOpen(false)
69
+ }, /*#__PURE__*/React.createElement(DatePickerAnchor, {
70
+ ref: anchorRef,
71
+ onAction: toggleIsOpen
72
+ }), /*#__PURE__*/React.createElement(DatePickerOverlay, {
73
+ anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : anchorRef,
74
+ renderAnchor: renderAnchor,
75
+ open: open !== null && open !== void 0 ? open : isOpen,
76
+ onOpen: onOpen,
77
+ onClose: onClose,
78
+ overlayProps: overlayProps,
79
+ focusTrapSettings: focusTrapSettings,
80
+ focusZoneSettings: focusZoneSettings
81
+ }));
82
+ };
83
+ 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,155 @@
1
+ import { CalendarIcon } from '@primer/octicons-react';
2
+ import styled from 'styled-components';
3
+ import React, { useCallback, 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 { isBefore } from 'date-fns';
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
+ const INVALID_DATE = 'Invalid Date';
17
+ export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
18
+ onAction
19
+ }, ref) => {
20
+ const {
21
+ configuration: {
22
+ anchorVariant,
23
+ iconPlacement,
24
+ selection
25
+ },
26
+ disabled,
27
+ formattedDate,
28
+ onDateInput
29
+ } = useDatePicker();
30
+ const [inputValue, setInputValue] = useState(formattedDate);
31
+ const keyPressHandler = useCallback(event => {
32
+ if (disabled) {
33
+ return;
34
+ }
35
+
36
+ if ([' ', 'Enter'].includes(event.key)) {
37
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
38
+ }
39
+ }, [disabled, onAction]);
40
+ const clickHandler = useCallback(event => {
41
+ if (disabled) {
42
+ return;
43
+ }
44
+
45
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
46
+ }, [disabled, onAction]);
47
+ const onInputChangeHandler = useCallback(e => {
48
+ const value = e.currentTarget.value;
49
+ if (!value) return;
50
+
51
+ if (selection === 'range') {
52
+ var _values$, _values$2, _values$3, _values$4, _values$5, _values$6;
53
+
54
+ const values = value.split(' - ');
55
+ const dates = isBefore(new Date((_values$ = values[0]) === null || _values$ === void 0 ? void 0 : _values$.trim()), new Date((_values$2 = values[1]) === null || _values$2 === void 0 ? void 0 : _values$2.trim())) ? {
56
+ from: new Date((_values$3 = values[0]) === null || _values$3 === void 0 ? void 0 : _values$3.trim()),
57
+ to: new Date((_values$4 = values[1]) === null || _values$4 === void 0 ? void 0 : _values$4.trim())
58
+ } : {
59
+ from: new Date((_values$5 = values[1]) === null || _values$5 === void 0 ? void 0 : _values$5.trim()),
60
+ to: new Date((_values$6 = values[0]) === null || _values$6 === void 0 ? void 0 : _values$6.trim())
61
+ };
62
+ setInputValue(value);
63
+
64
+ if (dates.from.toString() !== INVALID_DATE && dates.to.toString() !== INVALID_DATE) {
65
+ onDateInput(dates);
66
+ }
67
+ } else if (selection === 'multi') {
68
+ const values = value.split(',');
69
+ const dates = [];
70
+
71
+ for (const date of values) {
72
+ dates.push(new Date(date.trim()));
73
+ }
74
+
75
+ setInputValue(value);
76
+
77
+ if (dates.every(d => d.toString() !== INVALID_DATE)) {
78
+ onDateInput(dates);
79
+ }
80
+ } else {
81
+ const date = new Date(value);
82
+ setInputValue(value);
83
+ if (date.toString() !== INVALID_DATE) onDateInput(date);
84
+ }
85
+ }, [onDateInput, selection]);
86
+
87
+ const onBlurHandler = () => {
88
+ setInputValue(formattedDate);
89
+ };
90
+
91
+ if (anchorVariant === 'input') {
92
+ const calendarButton = side => /*#__PURE__*/React.createElement(ButtonInvisible, {
93
+ onClick: clickHandler,
94
+ sx: {
95
+ width: '32px',
96
+ px: '6px',
97
+ position: 'absolute',
98
+ [side]: '1px',
99
+ top: '1px'
100
+ }
101
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
102
+ icon: CalendarIcon
103
+ }));
104
+
105
+ const inputSx = () => {
106
+ if (iconPlacement === 'start') {
107
+ return {
108
+ pl: 5,
109
+ pr: 2
110
+ };
111
+ } else if (iconPlacement === 'end') {
112
+ return {
113
+ pl: 2,
114
+ pr: 5
115
+ };
116
+ } else {
117
+ return {};
118
+ }
119
+ };
120
+
121
+ return /*#__PURE__*/React.createElement(Box, {
122
+ ref: ref,
123
+ sx: {
124
+ position: 'relative',
125
+ display: 'flex',
126
+ flex: 1
127
+ }
128
+ }, iconPlacement === 'start' && calendarButton('left'), /*#__PURE__*/React.createElement(TextInput, {
129
+ value: inputValue,
130
+ onChange: onInputChangeHandler,
131
+ sx: inputSx(),
132
+ onBlur: onBlurHandler
133
+ }), iconPlacement === 'end' && calendarButton('right'));
134
+ }
135
+
136
+ const calendarIcon = () => /*#__PURE__*/React.createElement(StyledOcticon, {
137
+ icon: CalendarIcon,
138
+ color: "fg.muted",
139
+ sx: {
140
+ my: '2px'
141
+ }
142
+ });
143
+
144
+ return /*#__PURE__*/React.createElement(Box, {
145
+ ref: ref
146
+ }, /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
147
+ onClick: clickHandler,
148
+ onKeyPress: keyPressHandler
149
+ }, iconPlacement === 'start' && calendarIcon(), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
150
+ sx: {
151
+ overflow: 'hidden',
152
+ textOverflow: 'ellipsis'
153
+ }
154
+ }, formattedDate), iconPlacement === 'end' && calendarIcon()));
155
+ });
@@ -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,24 @@
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
+ revertValue
13
+ } = useDatePicker();
14
+
15
+ const onOverlayClose = gesture => {
16
+ revertValue();
17
+ onClose === null || onClose === void 0 ? void 0 : onClose(gesture);
18
+ };
19
+
20
+ return /*#__PURE__*/React.createElement(AnchoredOverlay, _extends({
21
+ onClose: onOverlayClose
22
+ }, rest), /*#__PURE__*/React.createElement(DatePickerPanel, null));
23
+ };
24
+ DatePickerOverlay.displayName = "DatePickerOverlay";
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const DatePickerPanel: () => JSX.Element;
@@ -0,0 +1,100 @@
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";
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { FontSizeProps } from 'styled-system';
3
+ import { SystemCommonProps, SystemLayoutProps } from '../constants';
4
+ import { SxProp } from '../sx';
5
+ import { DaySelection } from './useDatePicker';
6
+ export declare type DayProps = {
7
+ blocked?: boolean;
8
+ disabled?: boolean;
9
+ onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
10
+ selected?: DaySelection;
11
+ date: Date;
12
+ } & FontSizeProps & SystemCommonProps & SxProp & SystemLayoutProps;
13
+ export declare const Day: React.FC<DayProps>;
14
+ export declare const BlankDay: import("styled-components").StyledComponent<"div", any, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").TypographyProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").GridProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> & import("styled-system").BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ShadowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & SxProp, never>;