@primer/components 0.0.0-202110323331 → 0.0.0-2021103235619
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 -29
- package/dist/browser.esm.js +51 -55
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +50 -54
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Header.js +1 -1
- package/lib/ActionList/Item.d.ts +0 -6
- package/lib/ActionList/Item.js +1 -5
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +8 -6
- package/lib/Autocomplete/AutocompleteInput.d.ts +8 -6
- package/lib/Button/Button.d.ts +5 -5
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +3 -3
- package/lib/Button/ButtonDanger.d.ts +5 -5
- package/lib/Button/ButtonInvisible.d.ts +5 -5
- package/lib/Button/ButtonOutline.d.ts +5 -5
- package/lib/Button/ButtonPrimary.d.ts +5 -5
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +4 -4
- 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/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +16 -16
- package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib/FilterList.d.ts +303 -264
- package/lib/FilterList.js +6 -2
- package/lib/Flash.d.ts +1 -1
- package/lib/Label.d.ts +1 -1
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +28 -26
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +8 -10
- package/lib/TextInputWithTokens.js +29 -102
- package/lib/Timeline.d.ts +4 -4
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/Token/Token.js +2 -13
- package/lib/Token/TokenBase.js +4 -0
- package/lib/Token/_RemoveTokenButton.js +2 -15
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/_TextInputWrapper.js +1 -1
- 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/sx.d.ts +2 -8
- package/lib/theme-preval.js +2 -2
- package/lib/theme.d.ts +0 -78
- package/lib/theme.js +1 -3
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/ActionList/Header.js +1 -1
- package/lib-esm/ActionList/Item.d.ts +0 -6
- package/lib-esm/ActionList/Item.js +1 -5
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +8 -6
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +8 -6
- package/lib-esm/Button/Button.d.ts +5 -5
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +3 -3
- package/lib-esm/Button/ButtonDanger.d.ts +5 -5
- package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
- package/lib-esm/Button/ButtonOutline.d.ts +5 -5
- package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +4 -4
- 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/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +16 -16
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib-esm/FilterList.d.ts +303 -264
- package/lib-esm/FilterList.js +7 -3
- package/lib-esm/Flash.d.ts +1 -1
- package/lib-esm/Label.d.ts +1 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +28 -26
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +8 -10
- package/lib-esm/TextInputWithTokens.js +30 -101
- package/lib-esm/Timeline.d.ts +4 -4
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/Token/Token.js +2 -13
- package/lib-esm/Token/TokenBase.js +4 -0
- package/lib-esm/Token/_RemoveTokenButton.js +2 -11
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.js +1 -1
- 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/sx.d.ts +2 -8
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/theme.d.ts +0 -78
- package/lib-esm/theme.js +1 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -10
- package/lib/utils/types/KeyPaths.d.ts +0 -3
- package/lib/utils/types/KeyPaths.js +0 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +0 -3
- package/lib-esm/utils/types/KeyPaths.js +0 -1
@@ -3,7 +3,7 @@ import { SxProp } from '../sx';
|
|
3
3
|
import { ComponentProps } from '../utils/types';
|
4
4
|
declare const ButtonOutline: import("styled-components").StyledComponent<"button", any, {
|
5
5
|
as?: string | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
|
6
|
-
variant?: "
|
6
|
+
variant?: "large" | "medium" | "small" | undefined;
|
7
7
|
} & import("styled-system").FontSizeProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & {
|
8
8
|
color?: string | undefined;
|
9
9
|
fontSize?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
@@ -55,7 +55,7 @@ declare const ButtonOutline: import("styled-components").StyledComponent<"button
|
|
55
55
|
results?: number | undefined;
|
56
56
|
security?: string | undefined;
|
57
57
|
unselectable?: "on" | "off" | undefined;
|
58
|
-
inputMode?: "
|
58
|
+
inputMode?: "none" | "text" | "search" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
59
59
|
is?: string | undefined;
|
60
60
|
'aria-activedescendant'?: string | undefined;
|
61
61
|
'aria-atomic'?: boolean | "true" | "false" | undefined;
|
@@ -70,7 +70,7 @@ declare const ButtonOutline: import("styled-components").StyledComponent<"button
|
|
70
70
|
'aria-describedby'?: string | undefined;
|
71
71
|
'aria-details'?: string | undefined;
|
72
72
|
'aria-disabled'?: boolean | "true" | "false" | undefined;
|
73
|
-
'aria-dropeffect'?: "
|
73
|
+
'aria-dropeffect'?: "none" | "link" | "copy" | "execute" | "move" | "popup" | undefined;
|
74
74
|
'aria-errormessage'?: string | undefined;
|
75
75
|
'aria-expanded'?: boolean | "true" | "false" | undefined;
|
76
76
|
'aria-flowto'?: string | undefined;
|
@@ -268,7 +268,6 @@ declare const ButtonOutline: import("styled-components").StyledComponent<"button
|
|
268
268
|
onAnimationIterationCapture?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
269
269
|
onTransitionEnd?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
270
270
|
onTransitionEndCapture?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
271
|
-
as?: string | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
|
272
271
|
autoFocus?: boolean | undefined;
|
273
272
|
disabled?: boolean | undefined;
|
274
273
|
formAction?: string | undefined;
|
@@ -276,7 +275,8 @@ declare const ButtonOutline: import("styled-components").StyledComponent<"button
|
|
276
275
|
formMethod?: string | undefined;
|
277
276
|
formNoValidate?: boolean | undefined;
|
278
277
|
formTarget?: string | undefined;
|
279
|
-
|
278
|
+
as?: string | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
|
279
|
+
variant?: "large" | "medium" | "small" | undefined;
|
280
280
|
} & {
|
281
281
|
theme?: any;
|
282
282
|
} & import("styled-system").FontSizeProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("../constants").SystemCommonProps & import("../constants").SystemLayoutProps & SxProp, never>;
|
@@ -3,7 +3,7 @@ import { SxProp } from '../sx';
|
|
3
3
|
import { ComponentProps } from '../utils/types';
|
4
4
|
export declare const ButtonPrimary: import("styled-components").StyledComponent<"button", any, {
|
5
5
|
as?: string | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
|
6
|
-
variant?: "
|
6
|
+
variant?: "large" | "medium" | "small" | undefined;
|
7
7
|
} & import("styled-system").FontSizeProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & {
|
8
8
|
color?: string | undefined;
|
9
9
|
fontSize?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
@@ -55,7 +55,7 @@ export declare const ButtonPrimary: import("styled-components").StyledComponent<
|
|
55
55
|
results?: number | undefined;
|
56
56
|
security?: string | undefined;
|
57
57
|
unselectable?: "on" | "off" | undefined;
|
58
|
-
inputMode?: "
|
58
|
+
inputMode?: "none" | "text" | "search" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined;
|
59
59
|
is?: string | undefined;
|
60
60
|
'aria-activedescendant'?: string | undefined;
|
61
61
|
'aria-atomic'?: boolean | "true" | "false" | undefined;
|
@@ -70,7 +70,7 @@ export declare const ButtonPrimary: import("styled-components").StyledComponent<
|
|
70
70
|
'aria-describedby'?: string | undefined;
|
71
71
|
'aria-details'?: string | undefined;
|
72
72
|
'aria-disabled'?: boolean | "true" | "false" | undefined;
|
73
|
-
'aria-dropeffect'?: "
|
73
|
+
'aria-dropeffect'?: "none" | "link" | "copy" | "execute" | "move" | "popup" | undefined;
|
74
74
|
'aria-errormessage'?: string | undefined;
|
75
75
|
'aria-expanded'?: boolean | "true" | "false" | undefined;
|
76
76
|
'aria-flowto'?: string | undefined;
|
@@ -268,7 +268,6 @@ export declare const ButtonPrimary: import("styled-components").StyledComponent<
|
|
268
268
|
onAnimationIterationCapture?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
269
269
|
onTransitionEnd?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
270
270
|
onTransitionEndCapture?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
271
|
-
as?: string | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
|
272
271
|
autoFocus?: boolean | undefined;
|
273
272
|
disabled?: boolean | undefined;
|
274
273
|
formAction?: string | undefined;
|
@@ -276,7 +275,8 @@ export declare const ButtonPrimary: import("styled-components").StyledComponent<
|
|
276
275
|
formMethod?: string | undefined;
|
277
276
|
formNoValidate?: boolean | undefined;
|
278
277
|
formTarget?: string | undefined;
|
279
|
-
|
278
|
+
as?: string | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | undefined;
|
279
|
+
variant?: "large" | "medium" | "small" | undefined;
|
280
280
|
} & {
|
281
281
|
theme?: any;
|
282
282
|
} & import("styled-system").FontSizeProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("../constants").SystemCommonProps & import("../constants").SystemLayoutProps & SxProp, never>;
|
package/lib-esm/CircleBadge.d.ts
CHANGED
@@ -5,7 +5,7 @@ import { SxProp } from './sx';
|
|
5
5
|
import { ComponentProps } from './utils/types';
|
6
6
|
declare const CircleBadge: import("styled-components").StyledComponent<"div", any, {
|
7
7
|
inline?: boolean | undefined;
|
8
|
-
variant?: "
|
8
|
+
variant?: "large" | "medium" | "small" | undefined;
|
9
9
|
size?: number | undefined;
|
10
10
|
} & SystemCommonProps & SxProp, never>;
|
11
11
|
declare const CircleBadgeIcon: import("styled-components").StyledComponent<({ icon: IconComponent, ...rest }: {
|
@@ -15,7 +15,7 @@ export declare type CircleBadgeProps = ComponentProps<typeof CircleBadge>;
|
|
15
15
|
export declare type CircleBadgeIconProps = ComponentProps<typeof CircleBadgeIcon>;
|
16
16
|
declare const _default: string & import("styled-components").StyledComponentBase<"div", any, {
|
17
17
|
inline?: boolean | undefined;
|
18
|
-
variant?: "
|
18
|
+
variant?: "large" | "medium" | "small" | undefined;
|
19
19
|
size?: number | undefined;
|
20
20
|
} & SystemCommonProps & SxProp, never> & import("hoist-non-react-statics").NonReactStatics<never, {}> & {
|
21
21
|
Icon: import("styled-components").StyledComponent<({ icon: IconComponent, ...rest }: {
|
@@ -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?: "
|
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'?: "
|
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("
|
387
|
+
sx?: import("@styled-system/css").SystemStyleObject | undefined;
|
388
388
|
theme?: any;
|
389
389
|
};
|
390
390
|
}
|
@@ -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";
|