@primer/components 0.0.0-2021103231920 → 0.0.0-20211040245
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.
- package/CHANGELOG.md +1 -5
- package/dist/browser.esm.js +5 -3
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +30 -28
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +4 -2
- package/lib/Autocomplete/AutocompleteInput.d.ts +4 -2
- package/lib/DatePicker/DatePicker.d.ts +52 -0
- package/lib/DatePicker/DatePicker.js +109 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +202 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +55 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +363 -0
- package/lib/DatePicker/Day.d.ts +15 -0
- package/lib/DatePicker/Day.js +206 -0
- package/lib/DatePicker/Month.d.ts +8 -0
- package/lib/DatePicker/Month.js +122 -0
- package/lib/DatePicker/dateParser.d.ts +12 -0
- package/lib/DatePicker/dateParser.js +192 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +107 -0
- package/lib/DatePicker/useDatePicker.js +558 -0
- package/lib/Link.d.ts +2 -1
- package/lib/Link.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib/SideNav.d.ts +2 -2
- package/lib/TextInputWithTokens.d.ts +4 -2
- package/lib/hooks/useDebounce.d.ts +2 -0
- package/lib/hooks/useDebounce.js +24 -0
- package/lib/hooks/useResizeObserver.d.ts +1 -1
- package/lib/hooks/useResizeObserver.js +1 -1
- package/lib/theme-preval.js +2 -2
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -2
- package/lib-esm/DatePicker/DatePicker.d.ts +52 -0
- package/lib-esm/DatePicker/DatePicker.js +92 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +174 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +40 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +332 -0
- package/lib-esm/DatePicker/Day.d.ts +15 -0
- package/lib-esm/DatePicker/Day.js +182 -0
- package/lib-esm/DatePicker/Month.d.ts +8 -0
- package/lib-esm/DatePicker/Month.js +98 -0
- package/lib-esm/DatePicker/dateParser.d.ts +12 -0
- package/lib-esm/DatePicker/dateParser.js +178 -0
- package/lib-esm/DatePicker/index.d.ts +2 -0
- package/lib-esm/DatePicker/index.js +1 -0
- package/lib-esm/DatePicker/useDatePicker.d.ts +107 -0
- package/lib-esm/DatePicker/useDatePicker.js +523 -0
- package/lib-esm/Link.d.ts +2 -1
- package/lib-esm/Link.js +2 -2
- package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
- package/lib-esm/SideNav.d.ts +2 -2
- package/lib-esm/TextInputWithTokens.d.ts +4 -2
- package/lib-esm/hooks/useDebounce.d.ts +2 -0
- package/lib-esm/hooks/useDebounce.js +16 -0
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
- package/lib-esm/hooks/useResizeObserver.js +1 -1
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -8
package/lib/theme-preval.js
CHANGED
@@ -515,7 +515,7 @@ module.exports = {
|
|
515
515
|
}
|
516
516
|
}
|
517
517
|
},
|
518
|
-
"
|
518
|
+
"light_colorblind": {
|
519
519
|
"colors": {
|
520
520
|
"canvasDefaultTransparent": "rgba(255,255,255,0)",
|
521
521
|
"marketingIcon": {
|
@@ -2456,7 +2456,7 @@ module.exports = {
|
|
2456
2456
|
}
|
2457
2457
|
}
|
2458
2458
|
},
|
2459
|
-
"
|
2459
|
+
"dark_colorblind": {
|
2460
2460
|
"colors": {
|
2461
2461
|
"canvasDefaultTransparent": "rgba(13,17,23,0)",
|
2462
2462
|
"marketingIcon": {
|
package/lib/utils/testing.d.ts
CHANGED
@@ -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" | "
|
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:
|
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:
|
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"> & {
|
@@ -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"> & {
|
@@ -0,0 +1,52 @@
|
|
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
|
+
* Minimum date to select
|
48
|
+
*/
|
49
|
+
minDate?: Date | null;
|
50
|
+
}
|
51
|
+
export declare const DatePicker: React.FC<DatePickerProps>;
|
52
|
+
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 = null,
|
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,40 @@
|
|
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({}, rest, {
|
28
|
+
onClose: onOverlayClose,
|
29
|
+
focusTrapSettings: {
|
30
|
+
restoreFocusOnCleanUp: true
|
31
|
+
},
|
32
|
+
focusZoneSettings: {
|
33
|
+
disabled: true
|
34
|
+
},
|
35
|
+
"aria-modal": "true",
|
36
|
+
"aria-labelledby": `${currentViewingDate.getMonth()} ${currentViewingDate.getFullYear()}`,
|
37
|
+
"aria-live": "polite"
|
38
|
+
}), /*#__PURE__*/React.createElement(DatePickerPanel, null));
|
39
|
+
};
|
40
|
+
DatePickerOverlay.displayName = "DatePickerOverlay";
|