@primer/components 0.0.0-202192219616 → 0.0.0-2021922204627

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 (56) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +37 -38
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +32 -33
  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 +4 -2
  8. package/lib/Autocomplete/AutocompleteInput.d.ts +4 -2
  9. package/lib/DatePicker/DatePicker.d.ts +48 -0
  10. package/lib/DatePicker/DatePicker.js +82 -0
  11. package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
  12. package/lib/DatePicker/DatePickerAnchor.js +88 -0
  13. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  14. package/lib/DatePicker/DatePickerOverlay.js +39 -0
  15. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  16. package/lib/DatePicker/DatePickerPanel.js +43 -0
  17. package/lib/DatePicker/Day.d.ts +14 -0
  18. package/lib/DatePicker/Day.js +173 -0
  19. package/lib/DatePicker/Month.d.ts +9 -0
  20. package/lib/DatePicker/Month.js +97 -0
  21. package/lib/DatePicker/index.d.ts +2 -0
  22. package/lib/DatePicker/index.js +13 -0
  23. package/lib/DatePicker/useDatePicker.d.ts +69 -0
  24. package/lib/DatePicker/useDatePicker.js +336 -0
  25. package/lib/SelectMenu/SelectMenu.d.ts +4 -2
  26. package/lib/TextInputWithTokens.d.ts +4 -6
  27. package/lib/TextInputWithTokens.js +8 -61
  28. package/lib/_TextInputWrapper.js +1 -1
  29. package/lib/theme-preval.js +2 -2
  30. package/lib/utils/testing.d.ts +1 -1
  31. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
  32. package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -2
  33. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -2
  34. package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
  35. package/lib-esm/DatePicker/DatePicker.js +65 -0
  36. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
  37. package/lib-esm/DatePicker/DatePickerAnchor.js +63 -0
  38. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  39. package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
  40. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  41. package/lib-esm/DatePicker/DatePickerPanel.js +24 -0
  42. package/lib-esm/DatePicker/Day.d.ts +14 -0
  43. package/lib-esm/DatePicker/Day.js +150 -0
  44. package/lib-esm/DatePicker/Month.d.ts +9 -0
  45. package/lib-esm/DatePicker/Month.js +74 -0
  46. package/lib-esm/DatePicker/index.d.ts +2 -0
  47. package/lib-esm/DatePicker/index.js +1 -0
  48. package/lib-esm/DatePicker/useDatePicker.d.ts +69 -0
  49. package/lib-esm/DatePicker/useDatePicker.js +308 -0
  50. package/lib-esm/SelectMenu/SelectMenu.d.ts +4 -2
  51. package/lib-esm/TextInputWithTokens.d.ts +4 -6
  52. package/lib-esm/TextInputWithTokens.js +9 -61
  53. package/lib-esm/_TextInputWrapper.js +1 -1
  54. package/lib-esm/theme-preval.js +2 -2
  55. package/lib-esm/utils/testing.d.ts +1 -1
  56. package/package.json +9 -8
@@ -25,8 +25,6 @@ var _TextInputWrapper = _interopRequireDefault(require("./_TextInputWrapper"));
25
25
 
26
26
  var _Box = _interopRequireDefault(require("./Box"));
27
27
 
28
- var _Text = _interopRequireDefault(require("./Text"));
29
-
30
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
29
 
32
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -35,13 +33,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
35
33
 
36
34
  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); }
37
35
 
38
- const overflowCountFontSizeMap = {
39
- small: 0,
40
- medium: 1,
41
- large: 1,
42
- extralarge: 2
43
- }; // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
44
-
36
+ // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
45
37
  function TextInputWithTokensInnerComponent({
46
38
  icon: IconComponent,
47
39
  contrast,
@@ -61,11 +53,9 @@ function TextInputWithTokensInnerComponent({
61
53
  minWidth: minWidthProp,
62
54
  maxWidth: maxWidthProp,
63
55
  variant: variantProp,
64
- visibleTokenCount,
65
56
  ...rest
66
57
  }, externalRef) {
67
58
  const {
68
- onBlur,
69
59
  onFocus,
70
60
  onKeyDown,
71
61
  ...inputPropsRest
@@ -74,7 +64,6 @@ function TextInputWithTokensInnerComponent({
74
64
  const localInputRef = (0, _react.useRef)(null);
75
65
  const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(localInputRef, ref);
76
66
  const [selectedTokenIndex, setSelectedTokenIndex] = (0, _react.useState)();
77
- const [tokensAreTruncated, setTokensAreTruncated] = (0, _react.useState)(Boolean(visibleTokenCount));
78
67
  const {
79
68
  containerRef
80
69
  } = (0, _useFocusZone.useFocusZone)({
@@ -124,45 +113,20 @@ function TextInputWithTokensInnerComponent({
124
113
  };
125
114
 
126
115
  const handleTokenBlur = () => {
127
- setSelectedTokenIndex(undefined); // HACK: wait a tick and check the focused element before hiding truncated tokens
128
- // this prevents the tokens from hiding when the user is moving focus between tokens,
129
- // but still hides the tokens when the user blurs the token by tabbing out or clicking somewhere else on the page
130
-
131
- setTimeout(() => {
132
- var _containerRef$current3;
133
-
134
- if (!((_containerRef$current3 = containerRef.current) !== null && _containerRef$current3 !== void 0 && _containerRef$current3.contains(document.activeElement)) && visibleTokenCount) {
135
- setTokensAreTruncated(true);
136
- }
137
- }, 0);
116
+ setSelectedTokenIndex(undefined);
138
117
  };
139
118
 
140
- const handleTokenKeyUp = event => {
141
- if (event.key === 'Escape') {
119
+ const handleTokenKeyUp = e => {
120
+ if (e.key === 'Escape') {
142
121
  var _ref$current;
143
122
 
144
123
  (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
145
124
  }
146
125
  };
147
126
 
148
- const handleInputFocus = event => {
149
- onFocus && onFocus(event);
127
+ const handleInputFocus = e => {
128
+ onFocus && onFocus(e);
150
129
  setSelectedTokenIndex(undefined);
151
- visibleTokenCount && setTokensAreTruncated(false);
152
- };
153
-
154
- const handleInputBlur = event => {
155
- onBlur && onBlur(event); // HACK: wait a tick and check the focused element before hiding truncated tokens
156
- // this prevents the tokens from hiding when the user is moving focus from the input to a token,
157
- // but still hides the tokens when the user blurs the input by tabbing out or clicking somewhere else on the page
158
-
159
- setTimeout(() => {
160
- var _containerRef$current4;
161
-
162
- if (!((_containerRef$current4 = containerRef.current) !== null && _containerRef$current4 !== void 0 && _containerRef$current4.contains(document.activeElement)) && visibleTokenCount) {
163
- setTokensAreTruncated(true);
164
- }
165
- }, 0);
166
130
  };
167
131
 
168
132
  const handleInputKeyDown = e => {
@@ -200,17 +164,6 @@ function TextInputWithTokensInnerComponent({
200
164
  }
201
165
  };
202
166
 
203
- const focusInput = () => {
204
- var _combinedInputRef$cur;
205
-
206
- (_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
207
- };
208
-
209
- const preventTokenClickPropagation = event => {
210
- event.stopPropagation();
211
- };
212
-
213
- const visibleTokens = tokensAreTruncated ? tokens.slice(0, visibleTokenCount) : tokens;
214
167
  return /*#__PURE__*/_react.default.createElement(_TextInputWrapper.default, {
215
168
  block: block,
216
169
  className: className,
@@ -223,7 +176,6 @@ function TextInputWithTokensInnerComponent({
223
176
  maxWidth: maxWidthProp,
224
177
  variant: variantProp,
225
178
  ref: containerRef,
226
- onClick: focusInput,
227
179
  sx: {
228
180
  alignItems: 'center',
229
181
  flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
@@ -255,13 +207,12 @@ function TextInputWithTokensInnerComponent({
255
207
  ref: combinedInputRef,
256
208
  disabled: disabled,
257
209
  onFocus: handleInputFocus,
258
- onBlur: handleInputBlur,
259
210
  onKeyDown: handleInputKeyDown,
260
211
  type: "text",
261
212
  sx: {
262
213
  height: '100%'
263
214
  }
264
- }, inputPropsRest))), TokenComponent ? visibleTokens.map(({
215
+ }, inputPropsRest))), tokens.length && TokenComponent ? tokens.map(({
265
216
  id,
266
217
  ...tokenRest
267
218
  }, i) => /*#__PURE__*/_react.default.createElement(TokenComponent, _extends({
@@ -269,7 +220,6 @@ function TextInputWithTokensInnerComponent({
269
220
  onFocus: handleTokenFocus(i),
270
221
  onBlur: handleTokenBlur,
271
222
  onKeyUp: handleTokenKeyUp,
272
- onClick: preventTokenClickPropagation,
273
223
  isSelected: selectedTokenIndex === i,
274
224
  onRemove: () => {
275
225
  handleTokenRemove(id);
@@ -277,10 +227,7 @@ function TextInputWithTokensInnerComponent({
277
227
  hideRemoveButton: hideTokenRemoveButtons,
278
228
  size: size,
279
229
  tabIndex: 0
280
- }, tokenRest))) : null, tokensAreTruncated ? /*#__PURE__*/_react.default.createElement(_Text.default, {
281
- color: "fg.muted",
282
- fontSize: size && overflowCountFontSizeMap[size]
283
- }, "+", tokens.length - visibleTokens.length) : null);
230
+ }, tokenRest))) : null);
284
231
  }
285
232
 
286
233
  TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
@@ -39,7 +39,7 @@ const sizeVariants = (0, _styledSystem.variant)({
39
39
  const TextInputWrapper = _styledComponents.default.span.withConfig({
40
40
  displayName: "_TextInputWrapper__TextInputWrapper",
41
41
  componentId: "sc-5vfcis-0"
42
- })(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";cursor:text;", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
42
+ })(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
43
43
  if (props.hasIcon) {
44
44
  return (0, _styledComponents.css)(["padding:0;"]);
45
45
  } else {
@@ -515,7 +515,7 @@ module.exports = {
515
515
  }
516
516
  }
517
517
  },
518
- "light_protanopia": {
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
- "dark_protanopia": {
2459
+ "dark_colorblind": {
2460
2460
  "colors": {
2461
2461
  "canvasDefaultTransparent": "rgba(13,17,23,0)",
2462
2462
  "marketingIcon": {
@@ -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"> & {
@@ -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,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,65 @@
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
+ focusTrapSettings,
9
+ focusZoneSettings,
10
+ onOpen: onOpenExternal,
11
+ onClose: onCloseExternal,
12
+ open,
13
+ overlayProps,
14
+ renderAnchor,
15
+ selection,
16
+ value,
17
+ view
18
+ }) => {
19
+ const buttonRef = useRef(null);
20
+ const [isOpen, setIsOpen] = useState(false);
21
+ const datePickerConfiguration = {
22
+ anchorVariant,
23
+ selection,
24
+ view
25
+ };
26
+
27
+ const onOpen = gesture => {
28
+ setIsOpen(true);
29
+ onOpenExternal === null || onOpenExternal === void 0 ? void 0 : onOpenExternal(gesture);
30
+ };
31
+
32
+ const onClose = gesture => {
33
+ setIsOpen(false);
34
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal(gesture);
35
+ };
36
+
37
+ const toggleIsOpen = () => {
38
+ if (isOpen) {
39
+ setIsOpen(false);
40
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
41
+ } else {
42
+ setIsOpen(true);
43
+ onCloseExternal === null || onCloseExternal === void 0 ? void 0 : onCloseExternal('anchor-click');
44
+ }
45
+ };
46
+
47
+ return /*#__PURE__*/React.createElement(DatePickerProvider, {
48
+ configuration: datePickerConfiguration,
49
+ value: value,
50
+ closePicker: () => setIsOpen(false)
51
+ }, /*#__PURE__*/React.createElement(DatePickerAnchor, {
52
+ ref: buttonRef,
53
+ onAction: toggleIsOpen
54
+ }), /*#__PURE__*/React.createElement(DatePickerOverlay, {
55
+ anchorRef: externalAnchorRef !== null && externalAnchorRef !== void 0 ? externalAnchorRef : buttonRef,
56
+ renderAnchor: renderAnchor,
57
+ open: open !== null && open !== void 0 ? open : isOpen,
58
+ onOpen: onOpen,
59
+ onClose: onClose,
60
+ overlayProps: overlayProps,
61
+ focusTrapSettings: focusTrapSettings,
62
+ focusZoneSettings: focusZoneSettings
63
+ }));
64
+ };
65
+ 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<HTMLButtonElement>>;
@@ -0,0 +1,63 @@
1
+ import { CalendarIcon } from '@primer/octicons-react';
2
+ import styled from 'styled-components';
3
+ import React, { useCallback } from 'react';
4
+ import Button 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
+ const DatePickerAnchorButton = styled(Button).withConfig({
11
+ displayName: "DatePickerAnchor__DatePickerAnchorButton",
12
+ componentId: "sc-8gpb9d-0"
13
+ })(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;max-width:350px;overflow:hidden;& ", "{margin-left:", ";}"], Text, get('space.2'));
14
+ export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
15
+ onAction
16
+ }, ref) => {
17
+ const {
18
+ configuration: {
19
+ anchorVariant
20
+ },
21
+ disabled,
22
+ formattedDate
23
+ } = useDatePicker();
24
+ const keyPressHandler = useCallback(event => {
25
+ if (disabled) {
26
+ return;
27
+ }
28
+
29
+ if ([' ', 'Enter'].includes(event.key)) {
30
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
31
+ }
32
+ }, [disabled, onAction]);
33
+ const clickHandler = useCallback(event => {
34
+ if (disabled) {
35
+ return;
36
+ }
37
+
38
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
39
+ }, [disabled, onAction]);
40
+
41
+ if (anchorVariant === 'input') {
42
+ return /*#__PURE__*/React.createElement(TextInput, {
43
+ value: formattedDate
44
+ });
45
+ }
46
+
47
+ return /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
48
+ ref: ref,
49
+ onClick: clickHandler,
50
+ onKeyPress: keyPressHandler
51
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
52
+ icon: CalendarIcon,
53
+ color: "fg.muted",
54
+ sx: {
55
+ my: '2px'
56
+ }
57
+ }), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
58
+ sx: {
59
+ overflow: 'hidden',
60
+ textOverflow: 'ellipsis'
61
+ }
62
+ }, formattedDate));
63
+ });
@@ -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,24 @@
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
+ import useDatePicker from './useDatePicker';
8
+ const DatePickerPanelContainer = styled(Box).withConfig({
9
+ displayName: "DatePickerPanel__DatePickerPanelContainer",
10
+ componentId: "sc-19upxpo-0"
11
+ })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";"], get('space.6'), get('space.3'));
12
+ export const DatePickerPanel = () => {
13
+ const {
14
+ configuration
15
+ } = useDatePicker();
16
+ return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(Month, {
17
+ month: new Date().getMonth(),
18
+ year: new Date().getFullYear()
19
+ }), configuration.view === '2-month' && /*#__PURE__*/React.createElement(Month, {
20
+ month: addMonths(new Date(), 1).getMonth(),
21
+ year: addMonths(new Date(), 1).getFullYear()
22
+ }));
23
+ };
24
+ 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 interface DayProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
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
+ }
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>;
@@ -0,0 +1,150 @@
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
+ borderRadius: get('radii.2'),
15
+ color: get('colors.fg.subtle')
16
+ },
17
+ disabled: {
18
+ background: get('colors.canvas.primary'),
19
+ borderRadius: get('radii.2'),
20
+ color: get('colors.fg.subtle')
21
+ },
22
+ selected: {
23
+ default: {
24
+ background: get('colors.accent.emphasis'),
25
+ borderRadius: get('radii.2'),
26
+ color: get('colors.fg.onEmphasis')
27
+ },
28
+ start: {
29
+ background: get('colors.accent.emphasis'),
30
+ borderRadius: '4px 0 0 4px',
31
+ color: get('colors.fg.onEmphasis')
32
+ },
33
+ middle: {
34
+ background: get('colors.accent.subtle'),
35
+ borderRadius: '0',
36
+ color: get('colors.fg.default')
37
+ },
38
+ end: {
39
+ background: get('colors.accent.emphasis'),
40
+ borderRadius: '0 4px 4px 0',
41
+ color: get('colors.fg.onEmphasis')
42
+ }
43
+ },
44
+ default: {
45
+ normal: {
46
+ background: get('colors.canvas.primary'),
47
+ borderRadius: get('radii.2'),
48
+ color: get('colors.fg.default')
49
+ },
50
+ hover: {
51
+ background: get('colors.neutral.muted'),
52
+ borderRadius: get('radii.2'),
53
+ color: get('colors.fg.default')
54
+ },
55
+ pressed: {
56
+ background: get('colors.neutral.emphasis'),
57
+ borderRadius: get('radii.2'),
58
+ color: get('colors.fg.onEmphasis')
59
+ }
60
+ }
61
+ };
62
+
63
+ const getStateStyles = (props, prop, state) => {
64
+ const {
65
+ blocked,
66
+ disabled,
67
+ selected
68
+ } = props;
69
+
70
+ if (blocked) {
71
+ return states.blocked[prop];
72
+ } else if (disabled) {
73
+ return states.disabled[prop];
74
+ } else if (selected) {
75
+ switch (selected) {
76
+ case 'start':
77
+ return states.selected.start[prop];
78
+
79
+ case 'middle':
80
+ return states.selected.middle[prop];
81
+
82
+ case 'end':
83
+ return states.selected.end[prop];
84
+
85
+ default:
86
+ return states.selected.default[prop];
87
+ }
88
+ } else {
89
+ return states.default[state][prop];
90
+ }
91
+ };
92
+
93
+ const DayComponent = styled(DayBaseComponent).attrs(props => ({
94
+ background: getStateStyles(props, 'background', 'normal'),
95
+ borderRadius: getStateStyles(props, 'borderRadius', 'normal'),
96
+ textColor: getStateStyles(props, 'color', 'normal'),
97
+ backgroundHover: getStateStyles(props, 'background', 'hover'),
98
+ textColorHover: getStateStyles(props, 'color', 'hover'),
99
+ backgroundPressed: getStateStyles(props, 'background', 'pressed'),
100
+ textColorPressed: getStateStyles(props, 'color', 'pressed')
101
+ })).withConfig({
102
+ displayName: "Day__DayComponent",
103
+ componentId: "sc-1japneh-1"
104
+ })(["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, props => props.borderRadius, 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);
105
+ export const Day = ({
106
+ date,
107
+ onAction
108
+ }) => {
109
+ const {
110
+ onDayFocus,
111
+ onDayBlur,
112
+ onSelection,
113
+ disabled,
114
+ blocked,
115
+ selected
116
+ } = useDatePicker(date);
117
+ const keyPressHandler = useCallback(event => {
118
+ if (disabled) {
119
+ return;
120
+ }
121
+
122
+ if ([' ', 'Enter'].includes(event.key)) {
123
+ onSelection(date);
124
+ onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
125
+ }
126
+ }, [disabled, onSelection, onAction, date]);
127
+ const clickHandler = useCallback(event => {
128
+ if (disabled) {
129
+ return;
130
+ }
131
+
132
+ onSelection(date);
133
+ onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
134
+ }, [disabled, onSelection, date, onAction]);
135
+ return /*#__PURE__*/React.createElement(DayComponent, {
136
+ role: "button",
137
+ blocked: blocked,
138
+ disabled: disabled,
139
+ selected: selected,
140
+ onClick: clickHandler,
141
+ onFocus: () => onDayFocus(date),
142
+ onBlur: () => onDayBlur(date),
143
+ onKeyPress: keyPressHandler
144
+ }, /*#__PURE__*/React.createElement(Text, null, date.getDate()));
145
+ };
146
+ Day.displayName = "Day";
147
+ export const BlankDay = styled(DayBaseComponent).withConfig({
148
+ displayName: "Day__BlankDay",
149
+ componentId: "sc-1japneh-2"
150
+ })(["background-color:", ";"], get('colors.canvas.primary'));