@primer/components 0.0.0-202192602912 → 0.0.0-2021926102453

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 (60) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/browser.esm.js +22 -22
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +3 -3
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.d.ts +6 -0
  7. package/lib/ActionList/Item.js +5 -1
  8. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  9. package/lib/Autocomplete/Autocomplete.d.ts +2 -4
  10. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
  11. package/lib/SelectMenu/SelectMenu.d.ts +2 -4
  12. package/lib/TextInputWithTokens.d.ts +2 -4
  13. package/lib/theme-preval.js +2 -2
  14. package/lib/utils/testing.d.ts +1 -1
  15. package/lib-esm/ActionList/Item.d.ts +6 -0
  16. package/lib-esm/ActionList/Item.js +5 -1
  17. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  18. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
  19. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
  20. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
  21. package/lib-esm/TextInputWithTokens.d.ts +2 -4
  22. package/lib-esm/theme-preval.js +2 -2
  23. package/lib-esm/utils/testing.d.ts +1 -1
  24. package/package.json +8 -9
  25. package/lib/DatePicker/DatePicker.d.ts +0 -48
  26. package/lib/DatePicker/DatePicker.js +0 -92
  27. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  28. package/lib/DatePicker/DatePickerAnchor.js +0 -158
  29. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  30. package/lib/DatePicker/DatePickerOverlay.js +0 -39
  31. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  32. package/lib/DatePicker/DatePickerPanel.js +0 -126
  33. package/lib/DatePicker/Day.d.ts +0 -14
  34. package/lib/DatePicker/Day.js +0 -174
  35. package/lib/DatePicker/Month.d.ts +0 -9
  36. package/lib/DatePicker/Month.js +0 -107
  37. package/lib/DatePicker/index.d.ts +0 -2
  38. package/lib/DatePicker/index.js +0 -13
  39. package/lib/DatePicker/useDatePicker.d.ts +0 -83
  40. package/lib/DatePicker/useDatePicker.js +0 -375
  41. package/lib/hooks/useDebounce.d.ts +0 -2
  42. package/lib/hooks/useDebounce.js +0 -24
  43. package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
  44. package/lib-esm/DatePicker/DatePicker.js +0 -75
  45. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  46. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -132
  47. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  48. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -24
  49. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  50. package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
  51. package/lib-esm/DatePicker/Day.d.ts +0 -14
  52. package/lib-esm/DatePicker/Day.js +0 -151
  53. package/lib-esm/DatePicker/Month.d.ts +0 -9
  54. package/lib-esm/DatePicker/Month.js +0 -83
  55. package/lib-esm/DatePicker/index.d.ts +0 -2
  56. package/lib-esm/DatePicker/index.js +0 -1
  57. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -83
  58. package/lib-esm/DatePicker/useDatePicker.js +0 -347
  59. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  60. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,132 +0,0 @@
1
- import { CalendarIcon } from '@primer/octicons-react';
2
- import styled from 'styled-components';
3
- import React, { useCallback } 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
- const DatePickerAnchorButton = styled(Button).withConfig({
12
- displayName: "DatePickerAnchor__DatePickerAnchorButton",
13
- componentId: "sc-8gpb9d-0"
14
- })(["align-items:center;display:flex;flex-direction:row;justify-content:space-between;max-width:350px;overflow:hidden;& ", "{margin-left:", ";}"], Text, get('space.2'));
15
- export const DatePickerAnchor = /*#__PURE__*/React.forwardRef(({
16
- onAction
17
- }, ref) => {
18
- const {
19
- configuration: {
20
- anchorVariant,
21
- iconPlacement,
22
- selection
23
- },
24
- disabled,
25
- formattedDate
26
- } = useDatePicker();
27
- const keyPressHandler = useCallback(event => {
28
- if (disabled) {
29
- return;
30
- }
31
-
32
- if ([' ', 'Enter'].includes(event.key)) {
33
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
34
- }
35
- }, [disabled, onAction]);
36
- const clickHandler = useCallback(event => {
37
- if (disabled) {
38
- return;
39
- }
40
-
41
- onAction === null || onAction === void 0 ? void 0 : onAction(event);
42
- }, [disabled, onAction]);
43
- const onInputChangeHandler = useCallback(e => {
44
- const value = e.currentTarget.value;
45
- if (!value) return;
46
-
47
- if (selection === 'range') {
48
- var _values$, _values$2;
49
-
50
- const values = value.split(' - ');
51
- const dates = {
52
- from: new Date((_values$ = values[0]) === null || _values$ === void 0 ? void 0 : _values$.trim()),
53
- to: new Date((_values$2 = values[1]) === null || _values$2 === void 0 ? void 0 : _values$2.trim())
54
- };
55
- console.log(dates);
56
- } else if (selection === 'multi') {
57
- const values = value.split(',');
58
- const dates = [];
59
-
60
- for (const date of values) {
61
- dates.push(new Date(date.trim()));
62
- }
63
-
64
- console.log(dates);
65
- } else {
66
- const date = new Date(value);
67
- console.log(date);
68
- }
69
- }, [selection]);
70
-
71
- if (anchorVariant === 'input') {
72
- const calendarButton = side => /*#__PURE__*/React.createElement(ButtonInvisible, {
73
- onClick: clickHandler,
74
- sx: {
75
- width: '32px',
76
- px: '6px',
77
- position: 'absolute',
78
- [side]: '1px',
79
- top: '1px'
80
- }
81
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
82
- icon: CalendarIcon
83
- }));
84
-
85
- const inputSx = () => {
86
- if (iconPlacement === 'start') {
87
- return {
88
- pl: 5,
89
- pr: 2
90
- };
91
- } else if (iconPlacement === 'end') {
92
- return {
93
- pl: 2,
94
- pr: 5
95
- };
96
- } else {
97
- return {};
98
- }
99
- };
100
-
101
- return /*#__PURE__*/React.createElement(Box, {
102
- ref: ref,
103
- sx: {
104
- position: 'relative',
105
- display: 'flex',
106
- flex: 1
107
- }
108
- }, iconPlacement === 'start' && calendarButton('left'), /*#__PURE__*/React.createElement(TextInput, {
109
- defaultValue: formattedDate,
110
- onChange: onInputChangeHandler,
111
- sx: inputSx()
112
- }), iconPlacement === 'end' && calendarButton('right'));
113
- }
114
-
115
- return /*#__PURE__*/React.createElement(Box, {
116
- ref: ref
117
- }, /*#__PURE__*/React.createElement(DatePickerAnchorButton, {
118
- onClick: clickHandler,
119
- onKeyPress: keyPressHandler
120
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
121
- icon: CalendarIcon,
122
- color: "fg.muted",
123
- sx: {
124
- my: '2px'
125
- }
126
- }), anchorVariant !== 'icon-only' && /*#__PURE__*/React.createElement(Text, {
127
- sx: {
128
- overflow: 'hidden',
129
- textOverflow: 'ellipsis'
130
- }
131
- }, formattedDate)));
132
- });
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import { AnchoredOverlayProps } from '../AnchoredOverlay';
3
- export declare const DatePickerOverlay: React.FC<AnchoredOverlayProps>;
@@ -1,24 +0,0 @@
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";
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const DatePickerPanel: () => JSX.Element;
@@ -1,100 +0,0 @@
1
- import { addMonths, subMonths } from 'date-fns';
2
- import React, { useMemo } from 'react';
3
- import Box from '../Box';
4
- import { Month } from './Month';
5
- import styled from 'styled-components';
6
- import { get } from '../constants';
7
- import useDatePicker from './useDatePicker';
8
- import { ChevronLeftIcon, ChevronRightIcon } from '@primer/octicons-react';
9
- import StyledOcticon from '../StyledOcticon';
10
- import Button, { ButtonPrimary } from '../Button';
11
- const DatePickerPanelContainer = styled(Box).withConfig({
12
- displayName: "DatePickerPanel__DatePickerPanelContainer",
13
- componentId: "sc-19upxpo-0"
14
- })(["align-items:stretch;display:flex;flex-direction:column;"]);
15
- const DatePickerPanelMonths = styled(Box).withConfig({
16
- displayName: "DatePickerPanel__DatePickerPanelMonths",
17
- componentId: "sc-19upxpo-1"
18
- })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";position:relative;"], get('space.6'), get('space.3'));
19
- const DatePickerPanelFooter = styled(Box).withConfig({
20
- displayName: "DatePickerPanel__DatePickerPanelFooter",
21
- componentId: "sc-19upxpo-2"
22
- })(["align-items:flex-start;border-top:1px solid;border-top-color:", ";display:flex;gap:", ";padding-top:12px;padding-bottom:12px;padding-left:", ";padding-right:", ";flex-direction:row;justify-content:space-between;position:relative;"], get('colors.border.default'), get('space.6'), get('space.3'), get('space.3'));
23
- const ArrowButton = styled(Button).withConfig({
24
- displayName: "DatePickerPanel__ArrowButton",
25
- componentId: "sc-19upxpo-3"
26
- })(["position:absolute;width:40px;height:28px;top:12px;", ";"], props => `${props.side}: ${get('space.3')(props)}`);
27
- export const DatePickerPanel = () => {
28
- const {
29
- configuration,
30
- saveValue,
31
- revertValue,
32
- currentViewingDate,
33
- goToMonth,
34
- nextMonth,
35
- previousMonth
36
- } = useDatePicker();
37
- const previousDisabled = useMemo(() => {
38
- const {
39
- minDate
40
- } = configuration;
41
- if (!minDate) return false;
42
- const previous = subMonths(currentViewingDate, 1);
43
-
44
- if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
45
- return true;
46
- }
47
-
48
- return false;
49
- }, [configuration, currentViewingDate]);
50
- const nextDisabled = useMemo(() => {
51
- const {
52
- maxDate,
53
- view
54
- } = configuration;
55
- if (!maxDate) return false;
56
- const next = addMonths(currentViewingDate, view === '2-month' ? 2 : 1);
57
-
58
- if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
59
- return true;
60
- }
61
-
62
- return false;
63
- }, [configuration, currentViewingDate]);
64
- return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(DatePickerPanelMonths, null, /*#__PURE__*/React.createElement(ArrowButton, {
65
- variant: "small",
66
- side: "left",
67
- onClick: previousMonth,
68
- disabled: previousDisabled
69
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
70
- icon: ChevronLeftIcon,
71
- color: "fg.muted"
72
- })), /*#__PURE__*/React.createElement(Month, {
73
- month: currentViewingDate.getMonth(),
74
- year: currentViewingDate.getFullYear()
75
- }), configuration.view === '2-month' && /*#__PURE__*/React.createElement(Month, {
76
- month: addMonths(currentViewingDate, 1).getMonth(),
77
- year: addMonths(currentViewingDate, 1).getFullYear()
78
- }), /*#__PURE__*/React.createElement(ArrowButton, {
79
- variant: "small",
80
- side: "right",
81
- onClick: nextMonth,
82
- disabled: nextDisabled
83
- }, /*#__PURE__*/React.createElement(StyledOcticon, {
84
- icon: ChevronRightIcon,
85
- color: "fg.muted"
86
- }))), /*#__PURE__*/React.createElement(DatePickerPanelFooter, null, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Button, {
87
- variant: "small",
88
- sx: {
89
- mr: 1
90
- },
91
- onClick: () => revertValue()
92
- }, "Reset"), /*#__PURE__*/React.createElement(Button, {
93
- variant: "small",
94
- onClick: () => goToMonth(new Date())
95
- }, "Today")), configuration.confirmation && /*#__PURE__*/React.createElement(ButtonPrimary, {
96
- variant: "small",
97
- onClick: () => saveValue()
98
- }, "Apply")));
99
- };
100
- DatePickerPanel.displayName = "DatePickerPanel";
@@ -1,14 +0,0 @@
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>;
@@ -1,151 +0,0 @@
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.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-self:center;user-select:none;transition:0.1s 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
- onMouseEnter: () => onDayFocus(date),
142
- onFocus: () => onDayFocus(date),
143
- onBlur: () => onDayBlur(date),
144
- onKeyPress: keyPressHandler
145
- }, /*#__PURE__*/React.createElement(Text, null, date.getDate()));
146
- };
147
- Day.displayName = "Day";
148
- export const BlankDay = styled(DayBaseComponent).withConfig({
149
- displayName: "Day__BlankDay",
150
- componentId: "sc-1japneh-2"
151
- })(["background-color:", ";"], get('colors.canvas.primary'));
@@ -1,9 +0,0 @@
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>;
@@ -1,83 +0,0 @@
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
- import useDatePicker from './useDatePicker';
9
- const MonthComponent = styled(Box).withConfig({
10
- displayName: "Month__MonthComponent",
11
- componentId: "l6j7o0-0"
12
- })(["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;"]);
13
- const MonthTitle = styled(Text).withConfig({
14
- displayName: "Month__MonthTitle",
15
- componentId: "l6j7o0-1"
16
- })(["font-size:", ";font-weight:", ";grid-area:month;justify-self:center;"], get('fontSizes.1'), get('fontWeights.bold'));
17
- const WeekdayHeader = styled(Text).withConfig({
18
- displayName: "Month__WeekdayHeader",
19
- componentId: "l6j7o0-2"
20
- })(["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'));
21
- export const Month = ({
22
- month,
23
- year
24
- }) => {
25
- const {
26
- configuration
27
- } = useDatePicker();
28
- const [selectedDay, setSelectedDay] = useState(null);
29
- const getTitle = useMemo(() => `${format(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
30
- const weekdayHeaders = useMemo(() => {
31
- const now = new Date(year, month);
32
- const weekOptions = {
33
- weekStartsOn: configuration.weekStartsOn === 'Sunday' ? 0 : 1
34
- };
35
- return eachDayOfInterval({
36
- start: startOfWeek(now, weekOptions),
37
- end: endOfWeek(now, weekOptions)
38
- }).map(d => /*#__PURE__*/React.createElement(WeekdayHeader, {
39
- key: `weekday-${d}-header`
40
- }, format(d, 'EEEEEE')));
41
- }, [configuration.weekStartsOn, month, year]);
42
-
43
- const dayAction = date => {
44
- setSelectedDay(date);
45
- };
46
-
47
- const dayComponents = useMemo(() => {
48
- const components = [];
49
- const firstDay = new Date(year, month, 1);
50
- const preBlanks = configuration.weekStartsOn === 'Sunday' ? firstDay.getDay() : (firstDay.getDay() + 6) % 7;
51
-
52
- for (let i = 0; i < preBlanks; i++) {
53
- components.push( /*#__PURE__*/React.createElement(BlankDay, {
54
- key: `month-pre-blank-${i}`
55
- }));
56
- }
57
-
58
- for (let i = 1; i <= getDaysInMonth(firstDay); i++) {
59
- const date = new Date(year, month, i);
60
- components.push( /*#__PURE__*/React.createElement(Day, {
61
- key: `day-component-${date.toString()}`,
62
- date: date,
63
- selected: selectedDay ? isEqual(date, selectedDay) : false,
64
- onAction: dayAction
65
- }));
66
- }
67
-
68
- const lastDay = lastDayOfMonth(firstDay);
69
- const postBlanks = configuration.weekStartsOn === 'Sunday' ? lastDay.getDay() : (lastDay.getDay() + 6) % 7;
70
-
71
- for (let i = 6; i > postBlanks; i--) {
72
- components.push( /*#__PURE__*/React.createElement(BlankDay, {
73
- key: `month-post-blank-${i}`
74
- }));
75
- }
76
-
77
- return components;
78
- }, [configuration.weekStartsOn, month, selectedDay, year]);
79
- return /*#__PURE__*/React.createElement(MonthComponent, {
80
- role: "grid"
81
- }, /*#__PURE__*/React.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
82
- };
83
- Month.displayName = "Month";
@@ -1,2 +0,0 @@
1
- export { DatePicker } from './DatePicker';
2
- export type { DatePickerProps } from './DatePicker';
@@ -1 +0,0 @@
1
- export { DatePicker } from './DatePicker';
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
3
- export declare type DateFormat = 'short' | 'long' | string;
4
- export declare type SelectionVariant = 'single' | 'multi' | 'range';
5
- export interface DatePickerConfiguration {
6
- anchorVariant?: AnchorVariant;
7
- blockedDates?: Array<Date>;
8
- confirmation?: boolean;
9
- contiguousSelection?: boolean;
10
- dateFormat?: DateFormat;
11
- dimWeekends?: boolean;
12
- iconPlacement?: 'start' | 'end' | 'none';
13
- minDate?: Date;
14
- maxDate?: Date;
15
- placeholder?: string;
16
- rangeIncrement?: number;
17
- selection?: SelectionVariant;
18
- view?: '1-month' | '2-month';
19
- weekStartsOn?: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
20
- }
21
- export declare type RangeSelection = {
22
- from: Date;
23
- to: Date | null;
24
- };
25
- export declare type StringRangeSelection = {
26
- from: string;
27
- to: string;
28
- };
29
- export interface DatePickerContext {
30
- disabled?: boolean;
31
- configuration: DatePickerConfiguration;
32
- currentViewingDate: Date;
33
- goToMonth: (date: Date) => void;
34
- hoverRange?: RangeSelection | null;
35
- selection?: Selection;
36
- softSelection?: Partial<RangeSelection> | null;
37
- selectionActive?: boolean;
38
- formattedDate: string;
39
- nextMonth: () => void;
40
- onSelection: (date: Date) => void;
41
- onDayFocus: (date: Date) => void;
42
- onDayBlur: (date: Date) => void;
43
- previousMonth: () => void;
44
- revertValue: () => void;
45
- saveValue: (selection?: Selection) => void;
46
- }
47
- export declare type Selection = Date | Array<Date> | RangeSelection | null;
48
- export declare type StringSelection = string | Array<string> | {
49
- to: string;
50
- from: string;
51
- } | null;
52
- export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
53
- declare const useDatePicker: (date?: Date | undefined) => {
54
- blocked: boolean | undefined;
55
- disabled: boolean;
56
- selected: DaySelection;
57
- configuration: DatePickerConfiguration;
58
- currentViewingDate: Date;
59
- goToMonth: (date: Date) => void;
60
- hoverRange?: RangeSelection | null | undefined;
61
- selection?: Selection | undefined;
62
- softSelection?: Partial<RangeSelection> | null | undefined;
63
- selectionActive?: boolean | undefined;
64
- formattedDate: string;
65
- nextMonth: () => void;
66
- onSelection: (date: Date) => void;
67
- onDayFocus: (date: Date) => void;
68
- onDayBlur: (date: Date) => void;
69
- previousMonth: () => void;
70
- revertValue: () => void;
71
- saveValue: (selection?: Selection | undefined) => void;
72
- };
73
- export default useDatePicker;
74
- export interface DatePickerProviderProps {
75
- closePicker?: () => void;
76
- configuration?: DatePickerConfiguration;
77
- value?: Selection | StringSelection;
78
- }
79
- export declare function isSingleSelection(selection: Selection): selection is Date;
80
- export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
81
- export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
82
- export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
83
- export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;