@primer/components 0.0.0-2021104155617 → 0.0.0-2021104225742
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 +5 -1
- package/dist/browser.esm.js +4 -7
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +29 -32
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib/Autocomplete/Autocomplete.d.ts +2 -4
- package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
- package/lib/Button/Button.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +2 -4
- package/lib/TextInputWithTokens.d.ts +2 -4
- package/lib/Truncate.d.ts +1 -2
- package/lib/Truncate.js +1 -3
- package/lib/hooks/useResizeObserver.d.ts +1 -1
- package/lib/hooks/useResizeObserver.js +1 -1
- package/lib/theme-preval.js +2 -2
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
- package/lib-esm/Button/Button.js +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
- package/lib-esm/TextInputWithTokens.d.ts +2 -4
- package/lib-esm/Truncate.d.ts +1 -2
- package/lib-esm/Truncate.js +1 -2
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
- package/lib-esm/hooks/useResizeObserver.js +1 -1
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +8 -9
- package/lib/DatePicker/DatePicker.d.ts +0 -52
- package/lib/DatePicker/DatePicker.js +0 -109
- package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib/DatePicker/DatePickerAnchor.js +0 -202
- package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib/DatePicker/DatePickerOverlay.js +0 -55
- package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib/DatePicker/DatePickerPanel.js +0 -363
- package/lib/DatePicker/Day.d.ts +0 -15
- package/lib/DatePicker/Day.js +0 -206
- package/lib/DatePicker/Month.d.ts +0 -8
- package/lib/DatePicker/Month.js +0 -122
- package/lib/DatePicker/dateParser.d.ts +0 -12
- package/lib/DatePicker/dateParser.js +0 -193
- package/lib/DatePicker/index.d.ts +0 -2
- package/lib/DatePicker/index.js +0 -13
- package/lib/DatePicker/useDatePicker.d.ts +0 -107
- package/lib/DatePicker/useDatePicker.js +0 -558
- package/lib/hooks/useDebounce.d.ts +0 -2
- package/lib/hooks/useDebounce.js +0 -24
- package/lib-esm/DatePicker/DatePicker.d.ts +0 -52
- package/lib-esm/DatePicker/DatePicker.js +0 -92
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib-esm/DatePicker/DatePickerAnchor.js +0 -174
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib-esm/DatePicker/DatePickerOverlay.js +0 -40
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib-esm/DatePicker/DatePickerPanel.js +0 -332
- package/lib-esm/DatePicker/Day.d.ts +0 -15
- package/lib-esm/DatePicker/Day.js +0 -182
- package/lib-esm/DatePicker/Month.d.ts +0 -8
- package/lib-esm/DatePicker/Month.js +0 -98
- package/lib-esm/DatePicker/dateParser.d.ts +0 -12
- package/lib-esm/DatePicker/dateParser.js +0 -179
- package/lib-esm/DatePicker/index.d.ts +0 -2
- package/lib-esm/DatePicker/index.js +0 -1
- package/lib-esm/DatePicker/useDatePicker.d.ts +0 -107
- package/lib-esm/DatePicker/useDatePicker.js +0 -523
- package/lib-esm/hooks/useDebounce.d.ts +0 -2
- package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,182 +0,0 @@
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useRef } 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
|
-
import { format } from 'date-fns';
|
8
|
-
const DayBaseComponent = styled(Box).withConfig({
|
9
|
-
displayName: "Day__DayBaseComponent",
|
10
|
-
componentId: "sc-1japneh-0"
|
11
|
-
})(["align-content:center;display:flex;justify-content:center;min-width:38px;min-height:38px;padding:", ";"], get('space.1'));
|
12
|
-
const states = {
|
13
|
-
blocked: {
|
14
|
-
background: get('colors.neutral.subtle'),
|
15
|
-
borderRadius: get('radii.2'),
|
16
|
-
color: get('colors.fg.subtle')
|
17
|
-
},
|
18
|
-
disabled: {
|
19
|
-
background: get('colors.canvas.primary'),
|
20
|
-
borderRadius: get('radii.2'),
|
21
|
-
color: get('colors.fg.subtle')
|
22
|
-
},
|
23
|
-
selected: {
|
24
|
-
default: {
|
25
|
-
background: get('colors.accent.emphasis'),
|
26
|
-
borderRadius: get('radii.2'),
|
27
|
-
color: get('colors.fg.onEmphasis'),
|
28
|
-
todayColor: get('colors.fg.onEmphasis')
|
29
|
-
},
|
30
|
-
start: {
|
31
|
-
background: get('colors.accent.emphasis'),
|
32
|
-
borderRadius: '4px 0 0 4px',
|
33
|
-
color: get('colors.fg.onEmphasis'),
|
34
|
-
todayColor: get('colors.fg.onEmphasis')
|
35
|
-
},
|
36
|
-
middle: {
|
37
|
-
background: get('colors.accent.subtle'),
|
38
|
-
borderRadius: '0',
|
39
|
-
color: get('colors.fg.default'),
|
40
|
-
todayColor: get('colors.accent.fg')
|
41
|
-
},
|
42
|
-
end: {
|
43
|
-
background: get('colors.accent.emphasis'),
|
44
|
-
borderRadius: '0 4px 4px 0',
|
45
|
-
color: get('colors.fg.onEmphasis'),
|
46
|
-
todayColor: get('colors.fg.onEmphasis')
|
47
|
-
}
|
48
|
-
},
|
49
|
-
default: {
|
50
|
-
normal: {
|
51
|
-
background: get('colors.canvas.primary'),
|
52
|
-
borderRadius: get('radii.2'),
|
53
|
-
color: get('colors.fg.default'),
|
54
|
-
todayColor: get('colors.accent.fg')
|
55
|
-
},
|
56
|
-
hover: {
|
57
|
-
background: get('colors.neutral.muted'),
|
58
|
-
borderRadius: get('radii.2'),
|
59
|
-
color: get('colors.fg.default'),
|
60
|
-
todayColor: get('colors.accent.fg')
|
61
|
-
},
|
62
|
-
pressed: {
|
63
|
-
background: get('colors.neutral.emphasis'),
|
64
|
-
borderRadius: get('radii.2'),
|
65
|
-
color: get('colors.fg.onEmphasis'),
|
66
|
-
todayColor: get('colors.fg.onEmphasis')
|
67
|
-
}
|
68
|
-
}
|
69
|
-
};
|
70
|
-
|
71
|
-
const getStateStyles = (props, prop, state) => {
|
72
|
-
const {
|
73
|
-
blocked,
|
74
|
-
disabled,
|
75
|
-
selected,
|
76
|
-
today
|
77
|
-
} = props;
|
78
|
-
|
79
|
-
if (selected) {
|
80
|
-
switch (selected) {
|
81
|
-
case 'start':
|
82
|
-
return today && prop === 'color' ? states.selected.start['todayColor'] : states.selected.start[prop];
|
83
|
-
|
84
|
-
case 'middle':
|
85
|
-
return today && prop === 'color' ? states.selected.middle['todayColor'] : states.selected.middle[prop];
|
86
|
-
|
87
|
-
case 'end':
|
88
|
-
return today && prop === 'color' ? states.selected.end['todayColor'] : states.selected.end[prop];
|
89
|
-
|
90
|
-
default:
|
91
|
-
return today && prop === 'color' ? states.selected.default['todayColor'] : states.selected.default[prop];
|
92
|
-
}
|
93
|
-
} else if (blocked) {
|
94
|
-
return states.blocked[prop];
|
95
|
-
} else if (disabled) {
|
96
|
-
return states.disabled[prop];
|
97
|
-
} else {
|
98
|
-
return today && prop === 'color' ? states.default[state]['todayColor'] : states.default[state][prop];
|
99
|
-
}
|
100
|
-
};
|
101
|
-
|
102
|
-
const DayComponent = styled(DayBaseComponent).attrs(props => ({
|
103
|
-
background: getStateStyles(props, 'background', 'normal'),
|
104
|
-
borderRadius: getStateStyles(props, 'borderRadius', 'normal'),
|
105
|
-
textColor: getStateStyles(props, 'color', 'normal'),
|
106
|
-
backgroundHover: getStateStyles(props, 'background', 'hover'),
|
107
|
-
textColorHover: getStateStyles(props, 'color', 'hover'),
|
108
|
-
backgroundPressed: getStateStyles(props, 'background', 'pressed'),
|
109
|
-
textColorPressed: getStateStyles(props, 'color', 'pressed')
|
110
|
-
})).withConfig({
|
111
|
-
displayName: "Day__DayComponent",
|
112
|
-
componentId: "sc-1japneh-1"
|
113
|
-
})(["background-color:", ";border-radius:", ";cursor:", ";opacity:", ";transition:0.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-content:center;justify-self:center;padding:4px 0;position:relative;transition:0.1s color ease;user-select:none;width:16px;&:after{content:'';display:", ";position:absolute;bottom:0;background:", ";width:100%;height:2px;border-radius:1px;}}&:hover,&:focus{background-color:", ";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, props => props.disabled ? 'default' : 'pointer', props => props.disabled ? 0.5 : 1, Text, props => props.textColor, get('fonts.mono'), get('fontSizes.0'), props => props.today ? 'block' : 'none', props => props.selected && props.selected !== 'middle' ? get('colors.fg.onEmphasis')(props) : get('colors.accent.emphasis')(props), props => props.backgroundHover, Text, props => props.textColorHover, props => props.backgroundPressed, get('shadows.shadow.medium'), Text, props => props.textColorPressed);
|
114
|
-
export const Day = ({
|
115
|
-
date,
|
116
|
-
onAction
|
117
|
-
}) => {
|
118
|
-
const {
|
119
|
-
onDayFocus,
|
120
|
-
onSelection,
|
121
|
-
disabled,
|
122
|
-
blocked,
|
123
|
-
focused,
|
124
|
-
selected,
|
125
|
-
today
|
126
|
-
} = useDatePicker(date);
|
127
|
-
const dayRef = useRef(null);
|
128
|
-
useEffect(() => {
|
129
|
-
if (focused) {
|
130
|
-
setTimeout(() => {
|
131
|
-
var _dayRef$current;
|
132
|
-
|
133
|
-
return (_dayRef$current = dayRef.current) === null || _dayRef$current === void 0 ? void 0 : _dayRef$current.focus();
|
134
|
-
}, 0);
|
135
|
-
}
|
136
|
-
}, [focused]);
|
137
|
-
const keyPressHandler = useCallback(event => {
|
138
|
-
if (disabled) {
|
139
|
-
return;
|
140
|
-
}
|
141
|
-
|
142
|
-
if ([' ', 'Enter'].includes(event.key)) {
|
143
|
-
onSelection(date);
|
144
|
-
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
145
|
-
}
|
146
|
-
}, [disabled, onSelection, onAction, date]);
|
147
|
-
const clickHandler = useCallback(event => {
|
148
|
-
if (disabled) {
|
149
|
-
return;
|
150
|
-
}
|
151
|
-
|
152
|
-
onSelection(date);
|
153
|
-
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
154
|
-
}, [disabled, onSelection, date, onAction]);
|
155
|
-
const todayStyles = useMemo(() => today ? {
|
156
|
-
fontWeight: 'bold'
|
157
|
-
} : {}, [today]);
|
158
|
-
return /*#__PURE__*/React.createElement(DayComponent, {
|
159
|
-
ref: dayRef,
|
160
|
-
role: "gridcell",
|
161
|
-
"aria-disabled": disabled,
|
162
|
-
"aria-selected": selected !== false,
|
163
|
-
blocked: blocked,
|
164
|
-
disabled: disabled,
|
165
|
-
focused: focused,
|
166
|
-
selected: selected,
|
167
|
-
today: today,
|
168
|
-
onClick: clickHandler,
|
169
|
-
onMouseEnter: () => onDayFocus(date),
|
170
|
-
onFocus: () => onDayFocus(date),
|
171
|
-
onKeyPress: keyPressHandler,
|
172
|
-
tabIndex: -1,
|
173
|
-
"data-date": format(date, 'MM/dd/yyyy')
|
174
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
175
|
-
sx: todayStyles
|
176
|
-
}, date.getDate()));
|
177
|
-
};
|
178
|
-
Day.displayName = "Day";
|
179
|
-
export const BlankDay = styled(DayBaseComponent).withConfig({
|
180
|
-
displayName: "Day__BlankDay",
|
181
|
-
componentId: "sc-1japneh-2"
|
182
|
-
})(["background-color:", ";"], get('colors.canvas.primary'));
|
@@ -1,8 +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
|
-
date: Date;
|
7
|
-
}
|
8
|
-
export declare const Month: React.FC<MonthProps>;
|
@@ -1,98 +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 weekdayEnum = {
|
10
|
-
Sunday: 0,
|
11
|
-
Monday: 1,
|
12
|
-
Tuesday: 2,
|
13
|
-
Wednesday: 3,
|
14
|
-
Thursday: 4,
|
15
|
-
Friday: 5,
|
16
|
-
Saturday: 6
|
17
|
-
};
|
18
|
-
const MonthComponent = styled(Box).withConfig({
|
19
|
-
displayName: "Month__MonthComponent",
|
20
|
-
componentId: "l6j7o0-0"
|
21
|
-
})(["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;"]);
|
22
|
-
const MonthTitle = styled(Text).withConfig({
|
23
|
-
displayName: "Month__MonthTitle",
|
24
|
-
componentId: "l6j7o0-1"
|
25
|
-
})(["font-size:", ";font-weight:", ";grid-area:month;height:", ";justify-self:center;"], get('fontSizes.1'), get('fontWeights.bold'), get('space.4'));
|
26
|
-
const WeekdayHeader = styled(Text).withConfig({
|
27
|
-
displayName: "Month__WeekdayHeader",
|
28
|
-
componentId: "l6j7o0-2"
|
29
|
-
})(["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'));
|
30
|
-
export const Month = ({
|
31
|
-
date
|
32
|
-
}) => {
|
33
|
-
const {
|
34
|
-
configuration
|
35
|
-
} = useDatePicker();
|
36
|
-
const [selectedDay, setSelectedDay] = useState(null);
|
37
|
-
const getTitle = useMemo(() => `${format(new Date(date), 'MMMM yyyy')}`, [date]);
|
38
|
-
const weekdayHeaders = useMemo(() => {
|
39
|
-
var _configuration$weekSt;
|
40
|
-
|
41
|
-
const now = new Date(date);
|
42
|
-
const weekOptions = {
|
43
|
-
weekStartsOn: weekdayEnum[(_configuration$weekSt = configuration.weekStartsOn) !== null && _configuration$weekSt !== void 0 ? _configuration$weekSt : 'Sunday']
|
44
|
-
};
|
45
|
-
return eachDayOfInterval({
|
46
|
-
start: startOfWeek(now, weekOptions),
|
47
|
-
end: endOfWeek(now, weekOptions)
|
48
|
-
}).map(d => /*#__PURE__*/React.createElement(WeekdayHeader, {
|
49
|
-
key: `weekday-${d}-header`
|
50
|
-
}, format(d, 'EEEEEE')));
|
51
|
-
}, [configuration.weekStartsOn, date]);
|
52
|
-
|
53
|
-
const dayAction = day => {
|
54
|
-
setSelectedDay(day);
|
55
|
-
};
|
56
|
-
|
57
|
-
const dayComponents = useMemo(() => {
|
58
|
-
var _configuration$weekSt2, _configuration$weekSt3;
|
59
|
-
|
60
|
-
const components = [];
|
61
|
-
const firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
|
62
|
-
const preBlanks = (firstDay.getDay() + (7 - weekdayEnum[(_configuration$weekSt2 = configuration.weekStartsOn) !== null && _configuration$weekSt2 !== void 0 ? _configuration$weekSt2 : 'Sunday'])) % 7;
|
63
|
-
|
64
|
-
for (let i = 0; i < preBlanks; i++) {
|
65
|
-
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
66
|
-
key: `month-pre-blank-${i}`
|
67
|
-
}));
|
68
|
-
}
|
69
|
-
|
70
|
-
for (let i = 1; i <= getDaysInMonth(firstDay); i++) {
|
71
|
-
const day = new Date(date.getFullYear(), date.getMonth(), i);
|
72
|
-
components.push( /*#__PURE__*/React.createElement(Day, {
|
73
|
-
key: `day-component-${day.toString()}`,
|
74
|
-
date: day,
|
75
|
-
selected: selectedDay ? isEqual(day, selectedDay) : false,
|
76
|
-
onAction: dayAction
|
77
|
-
}));
|
78
|
-
}
|
79
|
-
|
80
|
-
const lastDay = lastDayOfMonth(firstDay);
|
81
|
-
const postBlanks = (lastDay.getDay() + (7 - weekdayEnum[(_configuration$weekSt3 = configuration.weekStartsOn) !== null && _configuration$weekSt3 !== void 0 ? _configuration$weekSt3 : 'Sunday'])) % 7;
|
82
|
-
|
83
|
-
for (let i = 6; i > postBlanks; i--) {
|
84
|
-
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
85
|
-
key: `month-post-blank-${i}`
|
86
|
-
}));
|
87
|
-
}
|
88
|
-
|
89
|
-
return components;
|
90
|
-
}, [configuration.weekStartsOn, date, selectedDay]);
|
91
|
-
return /*#__PURE__*/React.createElement(MonthComponent, {
|
92
|
-
role: "grid",
|
93
|
-
"aria-labelledby": `${date.getMonth()} ${date.getFullYear()}`
|
94
|
-
}, /*#__PURE__*/React.createElement(MonthTitle, {
|
95
|
-
"aria-live": "polite"
|
96
|
-
}, !configuration.compressedHeader ? getTitle : ''), weekdayHeaders, dayComponents);
|
97
|
-
};
|
98
|
-
Month.displayName = "Month";
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { AnchorVariant, Selection, SelectionVariant } from './useDatePicker';
|
2
|
-
export declare const parseDate: (dateString: string, variant?: SelectionVariant) => Selection;
|
3
|
-
declare type FormatDateOptions = {
|
4
|
-
selection?: Selection;
|
5
|
-
anchorVariant?: AnchorVariant;
|
6
|
-
dateFormat?: string;
|
7
|
-
placeholder?: string;
|
8
|
-
rawFormat?: boolean;
|
9
|
-
variant?: SelectionVariant;
|
10
|
-
};
|
11
|
-
export declare const formatDate: ({ selection, dateFormat, placeholder, rawFormat, variant }: FormatDateOptions) => string;
|
12
|
-
export {};
|
@@ -1,179 +0,0 @@
|
|
1
|
-
import { eachDayOfInterval, format, isBefore } from 'date-fns';
|
2
|
-
import { isRangeSelection } from './useDatePicker';
|
3
|
-
const INVALID_DATE = 'Invalid Date';
|
4
|
-
const DATE_REGEX = new RegExp(/(\d{1,2}[-/.]\d{1,2}[-/.](?:\d{2}){1,2})(?:\s?-\s?)?(\d{1,2}[-/.]\d{1,2}[-/.](?:\d{2}){1,2})?/g);
|
5
|
-
|
6
|
-
const sanitizeDate = dateString => {
|
7
|
-
return dateString.replaceAll('.', '/').replaceAll('-', '/');
|
8
|
-
};
|
9
|
-
|
10
|
-
export const parseDate = (dateString, variant = 'single') => {
|
11
|
-
const dateItems = dateString.matchAll(DATE_REGEX);
|
12
|
-
const parsedDateItems = []; // Determine Format
|
13
|
-
|
14
|
-
for (const d of dateItems) {
|
15
|
-
const tempD1 = new Date(sanitizeDate(d[1]));
|
16
|
-
const tempD2 = d[2] ? new Date(sanitizeDate(d[2])) : null;
|
17
|
-
|
18
|
-
if (tempD2) {
|
19
|
-
// Range
|
20
|
-
if (tempD1.toString() !== INVALID_DATE && tempD2.toString() !== INVALID_DATE) {
|
21
|
-
parsedDateItems.push(isBefore(tempD1, tempD2) ? {
|
22
|
-
from: tempD1,
|
23
|
-
to: tempD2
|
24
|
-
} : {
|
25
|
-
from: tempD2,
|
26
|
-
to: tempD1
|
27
|
-
});
|
28
|
-
} else if (tempD1.toString() !== INVALID_DATE) {
|
29
|
-
parsedDateItems.push(tempD1);
|
30
|
-
} else if (tempD2.toString() !== INVALID_DATE) {
|
31
|
-
parsedDateItems.push(tempD2);
|
32
|
-
}
|
33
|
-
} else {
|
34
|
-
if (tempD1.toString() !== INVALID_DATE) {
|
35
|
-
parsedDateItems.push(tempD1);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
if (parsedDateItems.length === 0) {
|
41
|
-
// No Valid Dates
|
42
|
-
return null;
|
43
|
-
} // Cast Format based on variant
|
44
|
-
|
45
|
-
|
46
|
-
switch (variant) {
|
47
|
-
case 'single':
|
48
|
-
{
|
49
|
-
return parsedDateItems[0];
|
50
|
-
}
|
51
|
-
|
52
|
-
case 'multi':
|
53
|
-
{
|
54
|
-
const expandedParsedItems = [];
|
55
|
-
|
56
|
-
for (const item of parsedDateItems) {
|
57
|
-
if (isRangeSelection(item)) {
|
58
|
-
if (item.to) {
|
59
|
-
eachDayOfInterval({
|
60
|
-
start: item.from,
|
61
|
-
end: item.to
|
62
|
-
}).map(d => expandedParsedItems.push(d));
|
63
|
-
} else {
|
64
|
-
expandedParsedItems.push(item.from);
|
65
|
-
}
|
66
|
-
} else {
|
67
|
-
if (item) {
|
68
|
-
if (Array.isArray(item)) {
|
69
|
-
item.map(d => expandedParsedItems.push(d));
|
70
|
-
} else {
|
71
|
-
expandedParsedItems.push(item);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
return expandedParsedItems;
|
78
|
-
}
|
79
|
-
|
80
|
-
case 'range':
|
81
|
-
{
|
82
|
-
return parsedDateItems.filter(d => isRangeSelection(d))[0];
|
83
|
-
}
|
84
|
-
|
85
|
-
default:
|
86
|
-
{
|
87
|
-
return parsedDateItems[0];
|
88
|
-
}
|
89
|
-
}
|
90
|
-
};
|
91
|
-
export const formatDate = ({
|
92
|
-
selection,
|
93
|
-
dateFormat = 'short',
|
94
|
-
placeholder = 'Choose Date',
|
95
|
-
rawFormat = false,
|
96
|
-
variant = 'single'
|
97
|
-
}) => {
|
98
|
-
if (!selection) {
|
99
|
-
if (rawFormat) return '';
|
100
|
-
return placeholder;
|
101
|
-
}
|
102
|
-
|
103
|
-
let template = 'MMM d';
|
104
|
-
|
105
|
-
if (!rawFormat && dateFormat) {
|
106
|
-
switch (dateFormat) {
|
107
|
-
case 'short':
|
108
|
-
template = 'MMM d';
|
109
|
-
break;
|
110
|
-
|
111
|
-
case 'long':
|
112
|
-
template = 'MMM d, yyyy';
|
113
|
-
break;
|
114
|
-
|
115
|
-
default:
|
116
|
-
template = dateFormat;
|
117
|
-
break;
|
118
|
-
}
|
119
|
-
} else {
|
120
|
-
template = 'MM/dd/yyyy';
|
121
|
-
}
|
122
|
-
|
123
|
-
switch (variant) {
|
124
|
-
case 'single':
|
125
|
-
{
|
126
|
-
if (selection instanceof Date) {
|
127
|
-
return format(selection, template);
|
128
|
-
} else if (Array.isArray(selection)) {
|
129
|
-
return format(selection[0], template);
|
130
|
-
} else if (isRangeSelection(selection)) {
|
131
|
-
return format(selection.from, template);
|
132
|
-
} else {
|
133
|
-
return 'Invalid Selection';
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
case 'multi':
|
138
|
-
{
|
139
|
-
if (Array.isArray(selection)) {
|
140
|
-
if (selection.length > 3 && !rawFormat) return `${selection.length} Selected`;
|
141
|
-
if (selection.length === 0 && !rawFormat) return placeholder;
|
142
|
-
const formatted = selection.map(d => format(d, template)).join(', ');
|
143
|
-
return formatted;
|
144
|
-
} else if (selection instanceof Date) {
|
145
|
-
return [selection].map(d => format(d, template)).join(', ');
|
146
|
-
} else if (isRangeSelection(selection)) {
|
147
|
-
return [selection.to, selection.from].map(d => d ? format(d, template) : '').join(', ');
|
148
|
-
} else {
|
149
|
-
return 'Invalid Selection';
|
150
|
-
}
|
151
|
-
}
|
152
|
-
|
153
|
-
case 'range':
|
154
|
-
{
|
155
|
-
if (isRangeSelection(selection)) {
|
156
|
-
return Object.entries(selection).map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
157
|
-
} else if (selection instanceof Date) {
|
158
|
-
return Object.entries({
|
159
|
-
from: selection,
|
160
|
-
to: null
|
161
|
-
}).map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
162
|
-
} else if (Array.isArray(selection)) {
|
163
|
-
return Object.entries({
|
164
|
-
from: selection[0],
|
165
|
-
to: selection[1]
|
166
|
-
}) // to date can still be null
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
168
|
-
.map(([_, date]) => date ? format(date, template) : '').join(' - ');
|
169
|
-
} else {
|
170
|
-
return 'Invalid Selection';
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
default:
|
175
|
-
{
|
176
|
-
return 'Invalid Configuration';
|
177
|
-
}
|
178
|
-
}
|
179
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export { DatePicker } from './DatePicker';
|
@@ -1,107 +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
|
-
confirmUnsavedClose?: boolean;
|
10
|
-
compressedHeader?: boolean;
|
11
|
-
dateFormat?: DateFormat;
|
12
|
-
disableWeekends?: boolean;
|
13
|
-
iconPlacement?: 'start' | 'end' | 'none';
|
14
|
-
maxDate?: Date | null;
|
15
|
-
maxSelections?: number;
|
16
|
-
maxRangeSize?: number;
|
17
|
-
minDate?: Date | null;
|
18
|
-
placeholder?: string;
|
19
|
-
rangeIncrement?: number;
|
20
|
-
showInputPrompt?: boolean;
|
21
|
-
variant?: SelectionVariant;
|
22
|
-
view?: '1-month' | '2-month';
|
23
|
-
weekStartsOn?: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
24
|
-
}
|
25
|
-
export declare type RangeSelection = {
|
26
|
-
from: Date;
|
27
|
-
to: Date | null;
|
28
|
-
};
|
29
|
-
export declare type StringRangeSelection = {
|
30
|
-
from: string;
|
31
|
-
to: string;
|
32
|
-
};
|
33
|
-
export interface DatePickerContext {
|
34
|
-
disabled?: boolean;
|
35
|
-
configuration: DatePickerConfiguration;
|
36
|
-
currentViewingDate: Date;
|
37
|
-
dialogOpen: boolean;
|
38
|
-
focusDate: Date;
|
39
|
-
formattedDate: string;
|
40
|
-
goToMonth: (date: Date) => void;
|
41
|
-
inputDate: string;
|
42
|
-
hoverRange?: RangeSelection | null;
|
43
|
-
nextMonth: () => void;
|
44
|
-
onClose: () => void;
|
45
|
-
onDateInput: (updatedSelection: Selection) => void;
|
46
|
-
onDayFocus: (date: Date) => void;
|
47
|
-
onSelection: (date: Date) => void;
|
48
|
-
previousMonth: () => void;
|
49
|
-
revertValue: () => void;
|
50
|
-
saveValue: (selection?: Selection) => void;
|
51
|
-
selection?: Selection;
|
52
|
-
selectionActive?: boolean;
|
53
|
-
setFocusDate: React.Dispatch<React.SetStateAction<Date>>;
|
54
|
-
setHoverRange: React.Dispatch<React.SetStateAction<RangeSelection | null>>;
|
55
|
-
softSelection?: Partial<RangeSelection> | null;
|
56
|
-
setDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
57
|
-
viewMode: '1-month' | '2-month';
|
58
|
-
}
|
59
|
-
export declare type Selection = Date | Array<Date> | RangeSelection | null;
|
60
|
-
export declare type StringSelection = string | Array<string> | {
|
61
|
-
to: string;
|
62
|
-
from: string;
|
63
|
-
} | null;
|
64
|
-
export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
|
65
|
-
declare const useDatePicker: (date?: Date | undefined) => {
|
66
|
-
blocked: boolean | undefined;
|
67
|
-
disabled: boolean;
|
68
|
-
focused: boolean;
|
69
|
-
selected: DaySelection;
|
70
|
-
today: boolean;
|
71
|
-
configuration: DatePickerConfiguration;
|
72
|
-
currentViewingDate: Date;
|
73
|
-
dialogOpen: boolean;
|
74
|
-
focusDate: Date;
|
75
|
-
formattedDate: string;
|
76
|
-
goToMonth: (date: Date) => void;
|
77
|
-
inputDate: string;
|
78
|
-
hoverRange?: RangeSelection | null | undefined;
|
79
|
-
nextMonth: () => void;
|
80
|
-
onClose: () => void;
|
81
|
-
onDateInput: (updatedSelection: Selection) => void;
|
82
|
-
onDayFocus: (date: Date) => void;
|
83
|
-
onSelection: (date: Date) => void;
|
84
|
-
previousMonth: () => void;
|
85
|
-
revertValue: () => void;
|
86
|
-
saveValue: (selection?: Selection | undefined) => void;
|
87
|
-
selection?: Selection | undefined;
|
88
|
-
selectionActive?: boolean | undefined;
|
89
|
-
setFocusDate: React.Dispatch<React.SetStateAction<Date>>;
|
90
|
-
setHoverRange: React.Dispatch<React.SetStateAction<RangeSelection | null>>;
|
91
|
-
softSelection?: Partial<RangeSelection> | null | undefined;
|
92
|
-
setDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
93
|
-
viewMode: '1-month' | '2-month';
|
94
|
-
};
|
95
|
-
export default useDatePicker;
|
96
|
-
export interface DatePickerProviderProps {
|
97
|
-
closePicker?: () => void;
|
98
|
-
configuration?: DatePickerConfiguration;
|
99
|
-
isOpen?: boolean;
|
100
|
-
value?: Selection | StringSelection;
|
101
|
-
}
|
102
|
-
export declare function isSingleSelection(selection: Selection): selection is Date;
|
103
|
-
export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
|
104
|
-
export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
|
105
|
-
export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
|
106
|
-
export declare const normalizeDate: (date: Date | string) => Date;
|
107
|
-
export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
|