@primer/components 0.0.0-2021919202426 → 0.0.0-2021920152952
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -19
- package/codemods/deprecateUtilityComponents.js +1 -1
- package/dist/browser.esm.js +768 -879
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +773 -884
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +4 -4
- package/lib/ActionList/List.d.ts +1 -2
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
- package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
- package/lib/BaseStyles.js +1 -1
- package/lib/BorderBox.js +1 -1
- package/lib/Button/Button.js +1 -1
- package/lib/Button/ButtonInvisible.js +1 -1
- package/lib/Button/ButtonTableList.js +1 -1
- package/lib/Caret.js +2 -2
- package/lib/DatePicker/DatePicker.d.ts +47 -0
- package/lib/DatePicker/DatePicker.js +76 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +10 -0
- package/lib/DatePicker/DatePickerAnchor.js +83 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +38 -0
- package/lib/DatePicker/Day.d.ts +13 -0
- package/lib/DatePicker/Day.js +136 -0
- package/lib/DatePicker/Month.d.ts +9 -0
- package/lib/DatePicker/Month.js +97 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +51 -0
- package/lib/DatePicker/useDatePicker.js +133 -0
- package/lib/Dialog.js +1 -1
- package/lib/FilteredActionList/FilteredActionList.js +31 -5
- package/lib/Flash.js +16 -16
- package/lib/Label.js +1 -1
- package/lib/Overlay.d.ts +0 -1
- package/lib/Overlay.js +1 -3
- package/lib/Pagination/Pagination.js +1 -1
- package/lib/ProgressBar.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +10 -10
- package/lib/StateLabel.js +19 -13
- package/lib/TextInput.d.ts +13 -5
- package/lib/TextInput.js +46 -4
- package/lib/hooks/useOpenAndCloseFocus.d.ts +1 -2
- package/lib/hooks/useOpenAndCloseFocus.js +2 -7
- package/lib/hooks/useOverlay.d.ts +1 -2
- package/lib/hooks/useOverlay.js +2 -4
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -36
- package/lib/theme-preval.js +3105 -375
- package/lib/utils/testing.d.ts +493 -50
- package/{lib-esm/utils/types/AriaRole.d.ts → lib/utils/types.d.ts} +13 -0
- package/lib/utils/{types/AriaRole.js → types.js} +0 -0
- package/lib-esm/ActionList/Item.js +4 -4
- package/lib-esm/ActionList/List.d.ts +1 -2
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
- package/lib-esm/BaseStyles.js +1 -1
- package/lib-esm/BorderBox.js +1 -1
- package/lib-esm/Button/Button.js +1 -1
- package/lib-esm/Button/ButtonInvisible.js +1 -1
- package/lib-esm/Button/ButtonTableList.js +1 -1
- package/lib-esm/Caret.js +2 -2
- package/lib-esm/DatePicker/DatePicker.d.ts +47 -0
- package/lib-esm/DatePicker/DatePicker.js +57 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +10 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +59 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +20 -0
- package/lib-esm/DatePicker/Day.d.ts +13 -0
- package/lib-esm/DatePicker/Day.js +113 -0
- package/lib-esm/DatePicker/Month.d.ts +9 -0
- package/lib-esm/DatePicker/Month.js +74 -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 +51 -0
- package/lib-esm/DatePicker/useDatePicker.js +114 -0
- package/lib-esm/Dialog.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
- package/lib-esm/Flash.js +16 -16
- package/lib-esm/Label.js +1 -1
- package/lib-esm/Overlay.d.ts +0 -1
- package/lib-esm/Overlay.js +1 -3
- package/lib-esm/Pagination/Pagination.js +1 -1
- package/lib-esm/ProgressBar.js +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +10 -10
- package/lib-esm/StateLabel.js +19 -13
- package/lib-esm/TextInput.d.ts +13 -5
- package/lib-esm/TextInput.js +37 -4
- package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +1 -2
- package/lib-esm/hooks/useOpenAndCloseFocus.js +2 -7
- package/lib-esm/hooks/useOverlay.d.ts +1 -2
- package/lib-esm/hooks/useOverlay.js +2 -4
- package/lib-esm/index.d.ts +0 -5
- package/lib-esm/index.js +0 -3
- package/lib-esm/theme-preval.js +3105 -375
- package/lib-esm/utils/testing.d.ts +493 -50
- package/{lib/utils/types/AriaRole.d.ts → lib-esm/utils/types.d.ts} +13 -0
- package/lib-esm/utils/{types/AriaRole.js → types.js} +0 -0
- package/package.json +4 -4
- package/lib/Autocomplete/Autocomplete.d.ts +0 -304
- package/lib/Autocomplete/Autocomplete.js +0 -145
- package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
- package/lib/Autocomplete/AutocompleteContext.js +0 -11
- package/lib/Autocomplete/AutocompleteInput.d.ts +0 -292
- package/lib/Autocomplete/AutocompleteInput.js +0 -157
- package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -72
- package/lib/Autocomplete/AutocompleteMenu.js +0 -224
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -20
- package/lib/Autocomplete/AutocompleteOverlay.js +0 -80
- package/lib/Autocomplete/index.d.ts +0 -2
- package/lib/Autocomplete/index.js +0 -15
- package/lib/TextInputWithTokens.d.ts +0 -327
- package/lib/TextInputWithTokens.js +0 -298
- package/lib/Token/AvatarToken.d.ts +0 -7
- package/lib/Token/AvatarToken.js +0 -64
- package/lib/Token/IssueLabelToken.d.ts +0 -14
- package/lib/Token/IssueLabelToken.js +0 -144
- package/lib/Token/Token.d.ts +0 -15
- package/lib/Token/Token.js +0 -94
- package/lib/Token/TokenBase.d.ts +0 -31
- package/lib/Token/TokenBase.js +0 -108
- package/lib/Token/_RemoveTokenButton.d.ts +0 -12
- package/lib/Token/_RemoveTokenButton.js +0 -77
- package/lib/Token/_TokenTextContainer.d.ts +0 -3
- package/lib/Token/_TokenTextContainer.js +0 -17
- package/lib/Token/index.d.ts +0 -3
- package/lib/Token/index.js +0 -31
- package/lib/_TextInputWrapper.d.ts +0 -10
- package/lib/_TextInputWrapper.js +0 -51
- package/lib/_UnstyledTextInput.d.ts +0 -2
- package/lib/_UnstyledTextInput.js +0 -20
- package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
- package/lib/behaviors/scrollIntoViewingArea.js +0 -39
- package/lib/utils/types/ComponentProps.d.ts +0 -9
- package/lib/utils/types/ComponentProps.js +0 -1
- package/lib/utils/types/Flatten.d.ts +0 -4
- package/lib/utils/types/Flatten.js +0 -1
- package/lib/utils/types/MandateProps.d.ts +0 -3
- package/lib/utils/types/MandateProps.js +0 -1
- package/lib/utils/types/Merge.d.ts +0 -19
- package/lib/utils/types/Merge.js +0 -1
- package/lib/utils/types/index.d.ts +0 -5
- package/lib/utils/types/index.js +0 -70
- package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -304
- package/lib-esm/Autocomplete/Autocomplete.js +0 -123
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
- package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -292
- package/lib-esm/Autocomplete/AutocompleteInput.js +0 -138
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -72
- package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -205
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -20
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -62
- package/lib-esm/Autocomplete/index.d.ts +0 -2
- package/lib-esm/Autocomplete/index.js +0 -1
- package/lib-esm/TextInputWithTokens.d.ts +0 -327
- package/lib-esm/TextInputWithTokens.js +0 -272
- package/lib-esm/Token/AvatarToken.d.ts +0 -7
- package/lib-esm/Token/AvatarToken.js +0 -43
- package/lib-esm/Token/IssueLabelToken.d.ts +0 -14
- package/lib-esm/Token/IssueLabelToken.js +0 -124
- package/lib-esm/Token/Token.d.ts +0 -15
- package/lib-esm/Token/Token.js +0 -73
- package/lib-esm/Token/TokenBase.d.ts +0 -31
- package/lib-esm/Token/TokenBase.js +0 -87
- package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -12
- package/lib-esm/Token/_RemoveTokenButton.js +0 -60
- package/lib-esm/Token/_TokenTextContainer.d.ts +0 -3
- package/lib-esm/Token/_TokenTextContainer.js +0 -6
- package/lib-esm/Token/index.d.ts +0 -3
- package/lib-esm/Token/index.js +0 -3
- package/lib-esm/_TextInputWrapper.d.ts +0 -10
- package/lib-esm/_TextInputWrapper.js +0 -31
- package/lib-esm/_UnstyledTextInput.d.ts +0 -2
- package/lib-esm/_UnstyledTextInput.js +0 -7
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
- package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
- package/lib-esm/utils/types/ComponentProps.d.ts +0 -9
- package/lib-esm/utils/types/ComponentProps.js +0 -1
- package/lib-esm/utils/types/Flatten.d.ts +0 -4
- package/lib-esm/utils/types/Flatten.js +0 -1
- package/lib-esm/utils/types/MandateProps.d.ts +0 -3
- package/lib-esm/utils/types/MandateProps.js +0 -1
- package/lib-esm/utils/types/Merge.d.ts +0 -19
- package/lib-esm/utils/types/Merge.js +0 -1
- package/lib-esm/utils/types/index.d.ts +0 -5
- package/lib-esm/utils/types/index.js +0 -5
@@ -22,9 +22,7 @@ export const AnchoredOverlay = ({
|
|
22
22
|
width,
|
23
23
|
overlayProps,
|
24
24
|
focusTrapSettings,
|
25
|
-
focusZoneSettings
|
26
|
-
side,
|
27
|
-
align
|
25
|
+
focusZoneSettings
|
28
26
|
}) => {
|
29
27
|
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
30
28
|
const [overlayRef, updateOverlayRef] = useRenderForcingRef();
|
@@ -54,9 +52,7 @@ export const AnchoredOverlay = ({
|
|
54
52
|
position
|
55
53
|
} = useAnchoredPosition({
|
56
54
|
anchorElementRef: anchorRef,
|
57
|
-
floatingElementRef: overlayRef
|
58
|
-
side,
|
59
|
-
align
|
55
|
+
floatingElementRef: overlayRef
|
60
56
|
}, [overlayRef.current]);
|
61
57
|
useEffect(() => {
|
62
58
|
// ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
|
@@ -97,8 +93,4 @@ export const AnchoredOverlay = ({
|
|
97
93
|
anchorSide: position === null || position === void 0 ? void 0 : position.anchorSide
|
98
94
|
}, overlayProps), children) : null);
|
99
95
|
};
|
100
|
-
AnchoredOverlay.displayName = 'AnchoredOverlay';
|
101
|
-
AnchoredOverlay.defaultProps = {
|
102
|
-
side: 'outside-bottom',
|
103
|
-
align: 'start'
|
104
|
-
};
|
96
|
+
AnchoredOverlay.displayName = 'AnchoredOverlay';
|
package/lib-esm/BaseStyles.js
CHANGED
package/lib-esm/BorderBox.js
CHANGED
package/lib-esm/Button/Button.js
CHANGED
@@ -5,5 +5,5 @@ import ButtonBase, { buttonSystemProps } from './ButtonBase';
|
|
5
5
|
const Button = styled(ButtonBase).withConfig({
|
6
6
|
displayName: "Button",
|
7
7
|
componentId: "xjtz72-0"
|
8
|
-
})(["color:", ";background-color:", ";border:1px solid ", ";box-shadow:", ",", "};&:hover{background-color:", ";border-color:", ";}&:focus{border-color:", ";box-shadow:", ";}&:active{background-color:", ";box-shadow:", ";}&:disabled{color:", ";background-color:", ";border-color:", ";}", ";", ";"], get('colors.btn.text'), get('colors.btn.bg'), get('colors.btn.border'), get('shadows.btn.shadow'), get('shadows.btn.insetShadow'), get('colors.btn.hoverBg'), get('colors.btn.hoverBorder'), get('colors.btn.focusBorder'), get('shadows.btn.focusShadow'), get('colors.btn.selectedBg'), get('shadows.btn.shadowActive'), get('colors.
|
8
|
+
})(["color:", ";background-color:", ";border:1px solid ", ";box-shadow:", ",", "};&:hover{background-color:", ";border-color:", ";}&:focus{border-color:", ";box-shadow:", ";}&:active{background-color:", ";box-shadow:", ";}&:disabled{color:", ";background-color:", ";border-color:", ";}", ";", ";"], get('colors.btn.text'), get('colors.btn.bg'), get('colors.btn.border'), get('shadows.btn.shadow'), get('shadows.btn.insetShadow'), get('colors.btn.hoverBg'), get('colors.btn.hoverBorder'), get('colors.btn.focusBorder'), get('shadows.btn.focusShadow'), get('colors.btn.selectedBg'), get('shadows.btn.shadowActive'), get('colors.fg.muted'), get('colors.btn.bg'), get('colors.btn.border'), buttonSystemProps, sx);
|
9
9
|
export default Button;
|
@@ -5,5 +5,5 @@ import ButtonBase, { buttonSystemProps } from './ButtonBase';
|
|
5
5
|
const ButtonInvisible = styled(ButtonBase).withConfig({
|
6
6
|
displayName: "ButtonInvisible",
|
7
7
|
componentId: "sc-1195tpn-0"
|
8
|
-
})(["color:", ";background-color:transparent;border:0;border-radius:", ";box-shadow:none;&:disabled{color:", ";}&:focus{box-shadow:", ";}
|
8
|
+
})(["color:", ";background-color:transparent;border:0;border-radius:", ";box-shadow:none;&:disabled{color:", ";}&:focus{box-shadow:", ";}", ";", ""], get('colors.accent.fg'), get('radii.2'), get('colors.fg.muted'), get('shadows.btn.focusShadow'), buttonSystemProps, sx);
|
9
9
|
export default ButtonInvisible;
|
@@ -4,5 +4,5 @@ import sx from '../sx';
|
|
4
4
|
const ButtonTableList = styled.summary.withConfig({
|
5
5
|
displayName: "ButtonTableList",
|
6
6
|
componentId: "sc-1m4q8ia-0"
|
7
|
-
})(["display:inline-block;padding:0;font-size:", ";color:", ";text-decoration:none;white-space:nowrap;cursor:pointer;user-select:none;background-color:transparent;border:0;appearance:none;&:hover{text-decoration:underline;}&:disabled{&,&:hover{color:", ";cursor:default;}}&:after{display:inline-block;margin-left:", ";width:0;height:0;vertical-align:-2px;content:'';border:4px solid transparent;border-top-color:currentcolor;}", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.muted'), get('colors.
|
7
|
+
})(["display:inline-block;padding:0;font-size:", ";color:", ";text-decoration:none;white-space:nowrap;cursor:pointer;user-select:none;background-color:transparent;border:0;appearance:none;&:hover{text-decoration:underline;}&:disabled{&,&:hover{color:rgba(", ",0.5);cursor:default;}}&:after{display:inline-block;margin-left:", ";width:0;height:0;vertical-align:-2px;content:'';border:4px solid transparent;border-top-color:currentcolor;}", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.muted'), get('colors.fg.muted'), get('space.1'), COMMON, TYPOGRAPHY, LAYOUT, sx);
|
8
8
|
export default ButtonTableList;
|
package/lib-esm/Caret.js
CHANGED
@@ -106,8 +106,8 @@ function Caret(props) {
|
|
106
106
|
Caret.displayName = "Caret";
|
107
107
|
Caret.locations = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
|
108
108
|
Caret.defaultProps = {
|
109
|
-
bg: 'canvas
|
110
|
-
borderColor: 'border.
|
109
|
+
bg: 'bg.canvas',
|
110
|
+
borderColor: 'border.primary',
|
111
111
|
borderWidth: 1
|
112
112
|
};
|
113
113
|
export default Caret;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { OverlayProps } from '../Overlay';
|
3
|
+
import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
|
4
|
+
import { FocusZoneHookSettings } from '../hooks/useFocusZone';
|
5
|
+
declare type OpenGesture = 'anchor-click' | 'anchor-key-press';
|
6
|
+
declare type CloseGesture = 'anchor-click' | 'click-outside' | 'escape';
|
7
|
+
export interface DatePickerProps {
|
8
|
+
/**
|
9
|
+
* An override to the internal ref that will be spread on to the renderAnchor
|
10
|
+
*/
|
11
|
+
anchorRef?: React.RefObject<HTMLElement>;
|
12
|
+
anchorVariant?: 'full' | 'iconOnly';
|
13
|
+
/**
|
14
|
+
* Settings to apply to the Focus Zone on the internal `Overlay` component.
|
15
|
+
*/
|
16
|
+
focusTrapSettings?: Partial<FocusTrapHookSettings>;
|
17
|
+
/**
|
18
|
+
* Settings to apply to the Focus Zone on the internal `Overlay` component.
|
19
|
+
*/
|
20
|
+
focusZoneSettings?: Partial<FocusZoneHookSettings>;
|
21
|
+
initialValue?: 'today' | Date | string | null;
|
22
|
+
placeholder?: string;
|
23
|
+
/**
|
24
|
+
* Determines whether the overlay portion of the component should be shown or not
|
25
|
+
*/
|
26
|
+
open?: boolean;
|
27
|
+
/**
|
28
|
+
* A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
|
29
|
+
*/
|
30
|
+
onOpen?: (gesture: OpenGesture) => unknown;
|
31
|
+
/**
|
32
|
+
* A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
|
33
|
+
*/
|
34
|
+
onClose?: (gesture: CloseGesture) => unknown;
|
35
|
+
/**
|
36
|
+
* Props to be spread on the internal `Overlay` component.
|
37
|
+
*/
|
38
|
+
overlayProps?: Partial<OverlayProps>;
|
39
|
+
/**
|
40
|
+
* A custom function component used to render the anchor element.
|
41
|
+
* Will receive the selected text as `children` prop when an item is activated.
|
42
|
+
*/
|
43
|
+
renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element;
|
44
|
+
value?: Date | string | null;
|
45
|
+
}
|
46
|
+
export declare const DatePicker: React.FC<DatePickerProps>;
|
47
|
+
export {};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
2
|
+
import { AnchoredOverlay } from '../AnchoredOverlay';
|
3
|
+
import { DatePickerAnchor } from './DatePickerAnchor';
|
4
|
+
import { addDays } from 'date-fns';
|
5
|
+
import { DatePickerPanel } from './DatePickerPanel';
|
6
|
+
import { DatePickerProvider } from './useDatePicker';
|
7
|
+
export const DatePicker = ({
|
8
|
+
anchorRef: externalAnchorRef,
|
9
|
+
focusTrapSettings,
|
10
|
+
focusZoneSettings,
|
11
|
+
onOpen: onOpenExternal,
|
12
|
+
onClose: onCloseExternal,
|
13
|
+
open,
|
14
|
+
overlayProps,
|
15
|
+
renderAnchor
|
16
|
+
}) => {
|
17
|
+
const buttonRef = useRef(null);
|
18
|
+
const [isOpen, setIsOpen] = useState(false);
|
19
|
+
|
20
|
+
const onOpen = gesture => {
|
21
|
+
setIsOpen(true);
|
22
|
+
onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
|
23
|
+
};
|
24
|
+
|
25
|
+
const onClose = gesture => {
|
26
|
+
setIsOpen(false);
|
27
|
+
onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
|
28
|
+
};
|
29
|
+
|
30
|
+
const toggleIsOpen = () => {
|
31
|
+
if (isOpen) {
|
32
|
+
setIsOpen(false);
|
33
|
+
onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
|
34
|
+
} else {
|
35
|
+
setIsOpen(true);
|
36
|
+
onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
return /*#__PURE__*/React.createElement(DatePickerProvider, null, /*#__PURE__*/React.createElement(DatePickerAnchor, {
|
41
|
+
ref: buttonRef,
|
42
|
+
fromDate: new Date(),
|
43
|
+
toDate: addDays(new Date(), 7),
|
44
|
+
dateFormat: "short",
|
45
|
+
onAction: toggleIsOpen
|
46
|
+
}), /*#__PURE__*/React.createElement(AnchoredOverlay, {
|
47
|
+
anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : buttonRef,
|
48
|
+
renderAnchor: renderAnchor,
|
49
|
+
open: open !== null && open !== void 0 ? open : isOpen,
|
50
|
+
onOpen: onOpen,
|
51
|
+
onClose: onClose,
|
52
|
+
overlayProps: overlayProps,
|
53
|
+
focusTrapSettings: focusTrapSettings,
|
54
|
+
focusZoneSettings: focusZoneSettings
|
55
|
+
}, /*#__PURE__*/React.createElement(DatePickerPanel, null)));
|
56
|
+
};
|
57
|
+
DatePicker.displayName = "DatePicker";
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface DatePickerAnchorProps {
|
3
|
+
dateFormat?: 'short' | 'long' | string;
|
4
|
+
disabled?: boolean;
|
5
|
+
fromDate: Date;
|
6
|
+
iconOnly?: boolean;
|
7
|
+
onAction?: (event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
|
8
|
+
toDate?: Date;
|
9
|
+
}
|
10
|
+
export declare const DatePickerAnchor: React.ForwardRefExoticComponent<DatePickerAnchorProps & React.RefAttributes<HTMLButtonElement>>;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { CalendarIcon } from '@primer/octicons-react';
|
2
|
+
import styled from 'styled-components';
|
3
|
+
import { format } from 'date-fns';
|
4
|
+
import React, { useCallback, useMemo } from 'react';
|
5
|
+
import Button from '../Button';
|
6
|
+
import Text from '../Text';
|
7
|
+
import { get } from '../constants';
|
8
|
+
import { StyledOcticon } from '..';
|
9
|
+
const DatePickerAnchorButton = styled(Button).withConfig({
|
10
|
+
displayName: "DatePickerAnchor__DatePickerAnchorButton",
|
11
|
+
componentId: "sc-8gpb9d-0"
|
12
|
+
})(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;& ", "{margin-left:", ";}"], Text, get('space.2'));
|
13
|
+
export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
|
14
|
+
dateFormat = 'short',
|
15
|
+
disabled,
|
16
|
+
fromDate,
|
17
|
+
iconOnly = false,
|
18
|
+
onAction,
|
19
|
+
toDate
|
20
|
+
}, ref) => {
|
21
|
+
const formattedDate = useMemo(() => {
|
22
|
+
if (iconOnly) return;
|
23
|
+
|
24
|
+
if (dateFormat === 'short') {
|
25
|
+
return /*#__PURE__*/React.createElement(Text, null, `${format(fromDate, 'MMM d')}${toDate ? ' - ' : ''}${toDate ? format(toDate, 'MMM d') : ''}`);
|
26
|
+
} else if (dateFormat === 'long') {
|
27
|
+
return /*#__PURE__*/React.createElement(Text, null, `${format(fromDate, 'MMM d, yyyy')}${toDate ? ' - ' : ''}${toDate ? format(toDate, 'MMM d, yyyy') : ''}`);
|
28
|
+
} else {
|
29
|
+
return /*#__PURE__*/React.createElement(Text, null, `${format(fromDate, dateFormat)}${toDate ? ' - ' : ''}${toDate ? format(toDate, dateFormat) : ''}`);
|
30
|
+
}
|
31
|
+
}, [dateFormat, fromDate, iconOnly, toDate]);
|
32
|
+
const keyPressHandler = useCallback(event => {
|
33
|
+
if (disabled) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
if ([' ', 'Enter'].includes(event.key)) {
|
38
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(event);
|
39
|
+
}
|
40
|
+
}, [disabled, onAction]);
|
41
|
+
const clickHandler = useCallback(event => {
|
42
|
+
if (disabled) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
|
46
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(event);
|
47
|
+
}, [disabled, onAction]);
|
48
|
+
return /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
|
49
|
+
ref: ref,
|
50
|
+
onClick: clickHandler,
|
51
|
+
onKeyPress: keyPressHandler
|
52
|
+
}, /*#__PURE__*/React.createElement(StyledOcticon, {
|
53
|
+
icon: CalendarIcon,
|
54
|
+
color: "fg.muted",
|
55
|
+
sx: {
|
56
|
+
my: '2px'
|
57
|
+
}
|
58
|
+
}), formattedDate);
|
59
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { addMonths } from 'date-fns';
|
2
|
+
import React from 'react';
|
3
|
+
import Box from '../Box';
|
4
|
+
import { Month } from './Month';
|
5
|
+
import styled from 'styled-components';
|
6
|
+
import { get } from '../constants';
|
7
|
+
const DatePickerPanelContainer = styled(Box).withConfig({
|
8
|
+
displayName: "DatePickerPanel__DatePickerPanelContainer",
|
9
|
+
componentId: "sc-19upxpo-0"
|
10
|
+
})(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";"], get('space.6'), get('space.3'));
|
11
|
+
export const DatePickerPanel = () => {
|
12
|
+
return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(Month, {
|
13
|
+
month: new Date().getMonth(),
|
14
|
+
year: new Date().getFullYear()
|
15
|
+
}), /*#__PURE__*/React.createElement(Month, {
|
16
|
+
month: addMonths(new Date(), 1).getMonth(),
|
17
|
+
year: addMonths(new Date(), 1).getFullYear()
|
18
|
+
}));
|
19
|
+
};
|
20
|
+
DatePickerPanel.displayName = "DatePickerPanel";
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FontSizeProps } from 'styled-system';
|
3
|
+
import { SystemCommonProps, SystemLayoutProps } from '../constants';
|
4
|
+
import { SxProp } from '../sx';
|
5
|
+
export interface DayProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
|
6
|
+
blocked?: boolean;
|
7
|
+
disabled?: boolean;
|
8
|
+
onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
|
9
|
+
selected?: boolean;
|
10
|
+
date: Date;
|
11
|
+
}
|
12
|
+
export declare const Day: React.FC<DayProps>;
|
13
|
+
export declare const BlankDay: import("styled-components").StyledComponent<"div", any, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").TypographyProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").GridProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> & import("styled-system").BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ShadowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & SxProp, never>;
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import React, { useCallback } from 'react';
|
2
|
+
import styled from 'styled-components';
|
3
|
+
import Box from '../Box';
|
4
|
+
import Text from '../Text';
|
5
|
+
import { get } from '../constants';
|
6
|
+
import { useDatePicker } from './useDatePicker';
|
7
|
+
const DayBaseComponent = styled(Box).withConfig({
|
8
|
+
displayName: "Day__DayBaseComponent",
|
9
|
+
componentId: "sc-1japneh-0"
|
10
|
+
})(["align-content:center;display:flex;justify-content:center;min-width:38px;min-height:38px;padding:", ";"], get('space.1'));
|
11
|
+
const states = {
|
12
|
+
blocked: {
|
13
|
+
background: get('colors.neutral.subtle'),
|
14
|
+
color: get('colors.fg.subtle')
|
15
|
+
},
|
16
|
+
disabled: {
|
17
|
+
background: get('colors.canvas.primary'),
|
18
|
+
color: get('colors.fg.subtle')
|
19
|
+
},
|
20
|
+
selected: {
|
21
|
+
background: get('colors.accent.emphasis'),
|
22
|
+
color: get('colors.fg.onEmphasis')
|
23
|
+
},
|
24
|
+
default: {
|
25
|
+
normal: {
|
26
|
+
background: get('colors.canvas.primary'),
|
27
|
+
color: get('colors.fg.default')
|
28
|
+
},
|
29
|
+
hover: {
|
30
|
+
background: get('colors.neutral.muted'),
|
31
|
+
color: get('colors.fg.default')
|
32
|
+
},
|
33
|
+
pressed: {
|
34
|
+
background: get('colors.neutral.emphasis'),
|
35
|
+
color: get('colors.fg.onEmphasis')
|
36
|
+
}
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
const getStateColors = (props, prop, state) => {
|
41
|
+
const {
|
42
|
+
blocked,
|
43
|
+
disabled,
|
44
|
+
selected
|
45
|
+
} = props;
|
46
|
+
|
47
|
+
if (blocked) {
|
48
|
+
return states.blocked[prop];
|
49
|
+
} else if (disabled) {
|
50
|
+
return states.disabled[prop];
|
51
|
+
} else if (selected) {
|
52
|
+
return states.selected[prop];
|
53
|
+
} else {
|
54
|
+
return states.default[state][prop];
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
const DayComponent = styled(DayBaseComponent).attrs(props => ({
|
59
|
+
background: getStateColors(props, 'background', 'normal'),
|
60
|
+
textColor: getStateColors(props, 'color', 'normal'),
|
61
|
+
backgroundHover: getStateColors(props, 'background', 'hover'),
|
62
|
+
textColorHover: getStateColors(props, 'color', 'hover'),
|
63
|
+
backgroundPressed: getStateColors(props, 'background', 'pressed'),
|
64
|
+
textColorPressed: getStateColors(props, 'color', 'pressed')
|
65
|
+
})).withConfig({
|
66
|
+
displayName: "Day__DayComponent",
|
67
|
+
componentId: "sc-1japneh-1"
|
68
|
+
})(["background-color:", ";border-radius:", ";transition:0.2s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-self:center;user-select:none;transition:0.2s color ease;}&:hover{background-color:", ";cursor:pointer;transition:0.05s background-color ease;& ", "{color:", ";transition:0.1s color ease;}}&:active{background-color:", ";box-shadow:inset ", ";transition:0.1s background-color ease,0.1s box-shadow ease,0.1s color ease;& ", "{color:", ";transition:0.1s color ease;}}"], props => props.background, get('radii.2'), Text, props => props.textColor, get('fonts.mono'), get('fontSizes.0'), props => props.backgroundHover, Text, props => props.textColorHover, props => props.backgroundPressed, get('shadows.shadow.medium'), Text, props => props.textColorPressed);
|
69
|
+
export const Day = ({
|
70
|
+
date,
|
71
|
+
onAction
|
72
|
+
}) => {
|
73
|
+
const {
|
74
|
+
onDayFocus,
|
75
|
+
onDayBlur,
|
76
|
+
onSelection,
|
77
|
+
disabled,
|
78
|
+
blocked,
|
79
|
+
selected
|
80
|
+
} = useDatePicker(date);
|
81
|
+
const keyPressHandler = useCallback(event => {
|
82
|
+
if (disabled) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
if ([' ', 'Enter'].includes(event.key)) {
|
87
|
+
onSelection(date);
|
88
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
89
|
+
}
|
90
|
+
}, [disabled, onSelection, onAction, date]);
|
91
|
+
const clickHandler = useCallback(event => {
|
92
|
+
if (disabled) {
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
|
96
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
97
|
+
}, [disabled, onAction, date]);
|
98
|
+
return /*#__PURE__*/React.createElement(DayComponent, {
|
99
|
+
role: "button",
|
100
|
+
blocked: blocked,
|
101
|
+
disabled: disabled,
|
102
|
+
selected: selected,
|
103
|
+
onClick: clickHandler,
|
104
|
+
onFocus: () => onDayFocus(date),
|
105
|
+
onBlur: onDayBlur,
|
106
|
+
onKeyPress: keyPressHandler
|
107
|
+
}, /*#__PURE__*/React.createElement(Text, null, date.getDate()));
|
108
|
+
};
|
109
|
+
Day.displayName = "Day";
|
110
|
+
export const BlankDay = styled(DayBaseComponent).withConfig({
|
111
|
+
displayName: "Day__BlankDay",
|
112
|
+
componentId: "sc-1japneh-2"
|
113
|
+
})(["background-color:", ";"], get('colors.canvas.primary'));
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FontSizeProps } from 'styled-system';
|
3
|
+
import { SystemCommonProps, SystemLayoutProps } from '../constants';
|
4
|
+
import { SxProp } from '../sx';
|
5
|
+
export interface MonthProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
|
6
|
+
month: number;
|
7
|
+
year: number;
|
8
|
+
}
|
9
|
+
export declare const Month: React.FC<MonthProps>;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { format, isEqual, lastDayOfMonth, getDaysInMonth, eachDayOfInterval, startOfWeek, endOfWeek } from 'date-fns';
|
2
|
+
import React, { useMemo, useState } from 'react';
|
3
|
+
import styled from 'styled-components';
|
4
|
+
import Box from '../Box';
|
5
|
+
import Text from '../Text';
|
6
|
+
import { get } from '../constants';
|
7
|
+
import { BlankDay, Day } from './Day';
|
8
|
+
const MonthComponent = styled(Box).withConfig({
|
9
|
+
displayName: "Month__MonthComponent",
|
10
|
+
componentId: "l6j7o0-0"
|
11
|
+
})(["display:grid;grid-auto-rows:min-content;grid-template-columns:repeat(1fr,7);grid-template-rows:1fr;gap:0px 0px;grid-template-areas:'month month month month month month month' 'sunday monday tuesday wednesday thursday friday saturday';justify-items:stretch;align-items:stretch;"]);
|
12
|
+
const MonthTitle = styled(Text).withConfig({
|
13
|
+
displayName: "Month__MonthTitle",
|
14
|
+
componentId: "l6j7o0-1"
|
15
|
+
})(["font-size:", ";font-weight:", ";grid-area:month;justify-self:center;"], get('fontSizes.1'), get('fontWeights.bold'));
|
16
|
+
const WeekdayHeader = styled(Text).withConfig({
|
17
|
+
displayName: "Month__WeekdayHeader",
|
18
|
+
componentId: "l6j7o0-2"
|
19
|
+
})(["color:", ";font-family:", ";font-size:", ";justify-self:center;padding:", " 0 ", ";"], get('colors.fg.subtle'), get('fonts.mono'), get('fontSizes.0'), get('space.3'), get('space.2'));
|
20
|
+
export const Month = ({
|
21
|
+
month,
|
22
|
+
year
|
23
|
+
}) => {
|
24
|
+
const [selectedDay, setSelectedDay] = useState(null);
|
25
|
+
const getTitle = useMemo(() => `${format(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
|
26
|
+
const weekdayHeaders = useMemo(() => {
|
27
|
+
const now = new Date(year, month);
|
28
|
+
return eachDayOfInterval({
|
29
|
+
start: startOfWeek(now),
|
30
|
+
end: endOfWeek(now)
|
31
|
+
}).map(d => /*#__PURE__*/React.createElement(WeekdayHeader, {
|
32
|
+
key: `weekday-${d}-header`
|
33
|
+
}, format(d, 'EEEEEE')));
|
34
|
+
}, [month, year]);
|
35
|
+
|
36
|
+
const dayAction = date => {
|
37
|
+
setSelectedDay(date);
|
38
|
+
};
|
39
|
+
|
40
|
+
const dayComponents = useMemo(() => {
|
41
|
+
const components = [];
|
42
|
+
const firstDay = new Date(year, month, 1);
|
43
|
+
|
44
|
+
for (let i = 0; i < firstDay.getDay(); i++) {
|
45
|
+
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
46
|
+
key: `month-pre-blank-${i}`
|
47
|
+
}));
|
48
|
+
}
|
49
|
+
|
50
|
+
for (let i = 1; i <= getDaysInMonth(firstDay); i++) {
|
51
|
+
const date = new Date(year, month, i);
|
52
|
+
components.push( /*#__PURE__*/React.createElement(Day, {
|
53
|
+
key: `day-component-${date.toString()}`,
|
54
|
+
date: date,
|
55
|
+
selected: selectedDay ? isEqual(date, selectedDay) : false,
|
56
|
+
onAction: dayAction
|
57
|
+
}));
|
58
|
+
}
|
59
|
+
|
60
|
+
const lastDay = lastDayOfMonth(firstDay);
|
61
|
+
|
62
|
+
for (let i = 6; i > lastDay.getDay(); i--) {
|
63
|
+
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
64
|
+
key: `month-post-blank-${i}`
|
65
|
+
}));
|
66
|
+
}
|
67
|
+
|
68
|
+
return components;
|
69
|
+
}, [month, selectedDay, year]);
|
70
|
+
return /*#__PURE__*/React.createElement(MonthComponent, {
|
71
|
+
role: "grid"
|
72
|
+
}, /*#__PURE__*/React.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
|
73
|
+
};
|
74
|
+
Month.displayName = "Month";
|
@@ -0,0 +1 @@
|
|
1
|
+
export { DatePicker } from './DatePicker';
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface DatePickerConfiguration {
|
3
|
+
anchorStyle?: 'input' | 'full-date' | 'icon-only';
|
4
|
+
blockedDates?: Array<Date>;
|
5
|
+
confirmation?: boolean;
|
6
|
+
contiguousSelection?: boolean;
|
7
|
+
dimWeekends?: boolean;
|
8
|
+
minDate?: Date;
|
9
|
+
maxDate?: Date;
|
10
|
+
rangeIncrement?: number;
|
11
|
+
selection?: 'single' | 'multi' | 'range';
|
12
|
+
view?: '1-month' | '2-month';
|
13
|
+
}
|
14
|
+
declare type SingleSelection = {
|
15
|
+
date: Date;
|
16
|
+
};
|
17
|
+
declare type BaseRangeSelection = {
|
18
|
+
from: Date;
|
19
|
+
};
|
20
|
+
declare type RangeSelection = {
|
21
|
+
to: Date;
|
22
|
+
} & BaseRangeSelection;
|
23
|
+
declare type SoftRangeSelection = {
|
24
|
+
to?: Date;
|
25
|
+
} & BaseRangeSelection;
|
26
|
+
export interface DatePickerContext {
|
27
|
+
configuration: DatePickerConfiguration;
|
28
|
+
selection?: SingleSelection | Array<SingleSelection> | RangeSelection | null;
|
29
|
+
softSelection?: SingleSelection | SoftRangeSelection | null;
|
30
|
+
selectionActive?: boolean;
|
31
|
+
onSelection: (date: Date) => void;
|
32
|
+
onDayFocus: (date: Date) => void;
|
33
|
+
onDayBlur: () => void;
|
34
|
+
}
|
35
|
+
export declare const useDatePicker: (date?: Date | undefined) => {
|
36
|
+
blocked: boolean | undefined;
|
37
|
+
disabled: boolean;
|
38
|
+
selected: boolean | undefined;
|
39
|
+
configuration: DatePickerConfiguration;
|
40
|
+
selection?: SingleSelection | RangeSelection | SingleSelection[] | null | undefined;
|
41
|
+
softSelection?: SingleSelection | SoftRangeSelection | null | undefined;
|
42
|
+
selectionActive?: boolean | undefined;
|
43
|
+
onSelection: (date: Date) => void;
|
44
|
+
onDayFocus: (date: Date) => void;
|
45
|
+
onDayBlur: () => void;
|
46
|
+
};
|
47
|
+
export interface DatePickerProviderProps {
|
48
|
+
configuration?: DatePickerConfiguration;
|
49
|
+
}
|
50
|
+
export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
|
51
|
+
export {};
|