@primer/components 0.0.0-2021927173554 → 0.0.0-2021927175656
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 +8 -4
- package/dist/browser.esm.js +2 -2
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +2 -2
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +12 -10
- package/lib/Autocomplete/AutocompleteInput.d.ts +12 -10
- package/lib/Button/Button.d.ts +6 -6
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +5 -5
- package/lib/Button/ButtonDanger.d.ts +6 -6
- package/lib/Button/ButtonInvisible.d.ts +6 -6
- package/lib/Button/ButtonOutline.d.ts +6 -6
- package/lib/Button/ButtonPrimary.d.ts +6 -6
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +4 -4
- package/lib/DatePicker/DatePicker.d.ts +48 -0
- package/lib/DatePicker/DatePicker.js +100 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +182 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +39 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +126 -0
- package/lib/DatePicker/Day.d.ts +14 -0
- package/lib/DatePicker/Day.js +192 -0
- package/lib/DatePicker/Month.d.ts +9 -0
- package/lib/DatePicker/Month.js +120 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +88 -0
- package/lib/DatePicker/useDatePicker.js +383 -0
- package/lib/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +18 -18
- package/lib/DropdownMenu/DropdownButton.d.ts +7 -7
- package/lib/FilterList.d.ts +3 -3
- package/lib/Flash.d.ts +1 -1
- package/lib/Label.d.ts +1 -1
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +32 -30
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +12 -10
- package/lib/Timeline.d.ts +4 -4
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/hooks/useDebounce.d.ts +2 -0
- package/lib/hooks/useDebounce.js +24 -0
- package/lib/sx.d.ts +2 -8
- package/lib/theme-preval.js +2 -2
- package/lib/theme.d.ts +0 -100
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +12 -10
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +12 -10
- package/lib-esm/Button/Button.d.ts +6 -6
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +5 -5
- package/lib-esm/Button/ButtonDanger.d.ts +6 -6
- package/lib-esm/Button/ButtonInvisible.d.ts +6 -6
- package/lib-esm/Button/ButtonOutline.d.ts +6 -6
- package/lib-esm/Button/ButtonPrimary.d.ts +6 -6
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +4 -4
- package/lib-esm/DatePicker/DatePicker.d.ts +48 -0
- package/lib-esm/DatePicker/DatePicker.js +83 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +155 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +100 -0
- package/lib-esm/DatePicker/Day.d.ts +14 -0
- package/lib-esm/DatePicker/Day.js +169 -0
- package/lib-esm/DatePicker/Month.d.ts +9 -0
- package/lib-esm/DatePicker/Month.js +96 -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 +88 -0
- package/lib-esm/DatePicker/useDatePicker.js +355 -0
- package/lib-esm/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +18 -18
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +7 -7
- package/lib-esm/FilterList.d.ts +3 -3
- package/lib-esm/Flash.d.ts +1 -1
- package/lib-esm/Label.d.ts +1 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +32 -30
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +12 -10
- package/lib-esm/Timeline.d.ts +4 -4
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/hooks/useDebounce.d.ts +2 -0
- package/lib-esm/hooks/useDebounce.js +16 -0
- package/lib-esm/sx.d.ts +2 -8
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/theme.d.ts +0 -100
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -8
|
@@ -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 declare type DayProps = {
|
|
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
|
+
} & FontSizeProps & SystemCommonProps & SxProp & SystemLayoutProps;
|
|
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,169 @@
|
|
|
1
|
+
import React, { useCallback, useMemo } 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
|
+
todayColor: get('colors.fg.onEmphasis')
|
|
28
|
+
},
|
|
29
|
+
start: {
|
|
30
|
+
background: get('colors.accent.emphasis'),
|
|
31
|
+
borderRadius: '4px 0 0 4px',
|
|
32
|
+
color: get('colors.fg.onEmphasis'),
|
|
33
|
+
todayColor: get('colors.onEmphasis')
|
|
34
|
+
},
|
|
35
|
+
middle: {
|
|
36
|
+
background: get('colors.accent.subtle'),
|
|
37
|
+
borderRadius: '0',
|
|
38
|
+
color: get('colors.fg.default'),
|
|
39
|
+
todayColor: get('colors.accent.fg')
|
|
40
|
+
},
|
|
41
|
+
end: {
|
|
42
|
+
background: get('colors.accent.emphasis'),
|
|
43
|
+
borderRadius: '0 4px 4px 0',
|
|
44
|
+
color: get('colors.fg.onEmphasis'),
|
|
45
|
+
todayColor: get('colors.onEmphasis')
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
default: {
|
|
49
|
+
normal: {
|
|
50
|
+
background: get('colors.canvas.primary'),
|
|
51
|
+
borderRadius: get('radii.2'),
|
|
52
|
+
color: get('colors.fg.default'),
|
|
53
|
+
todayColor: get('colors.accent.fg')
|
|
54
|
+
},
|
|
55
|
+
hover: {
|
|
56
|
+
background: get('colors.neutral.muted'),
|
|
57
|
+
borderRadius: get('radii.2'),
|
|
58
|
+
color: get('colors.fg.default'),
|
|
59
|
+
todayColor: get('colors.accent.fg')
|
|
60
|
+
},
|
|
61
|
+
pressed: {
|
|
62
|
+
background: get('colors.neutral.emphasis'),
|
|
63
|
+
borderRadius: get('radii.2'),
|
|
64
|
+
color: get('colors.fg.onEmphasis'),
|
|
65
|
+
todayColor: get('colors.fg.onEmphasis')
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const getStateStyles = (props, prop, state) => {
|
|
71
|
+
const {
|
|
72
|
+
blocked,
|
|
73
|
+
disabled,
|
|
74
|
+
selected,
|
|
75
|
+
today
|
|
76
|
+
} = props;
|
|
77
|
+
|
|
78
|
+
if (blocked) {
|
|
79
|
+
return states.blocked[prop];
|
|
80
|
+
} else if (disabled) {
|
|
81
|
+
return states.disabled[prop];
|
|
82
|
+
} else if (selected) {
|
|
83
|
+
switch (selected) {
|
|
84
|
+
case 'start':
|
|
85
|
+
return today && prop === 'color' ? states.selected.start['todayColor'] : states.selected.start[prop];
|
|
86
|
+
|
|
87
|
+
case 'middle':
|
|
88
|
+
return today && prop === 'color' ? states.selected.middle['todayColor'] : states.selected.middle[prop];
|
|
89
|
+
|
|
90
|
+
case 'end':
|
|
91
|
+
return today && prop === 'color' ? states.selected.end['todayColor'] : states.selected.end[prop];
|
|
92
|
+
|
|
93
|
+
default:
|
|
94
|
+
return today && prop === 'color' ? states.selected.default['todayColor'] : states.selected.default[prop];
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
return today && prop === 'color' ? states.default[state]['todayColor'] : states.default[state][prop];
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const DayComponent = styled(DayBaseComponent).attrs(props => ({
|
|
102
|
+
background: getStateStyles(props, 'background', 'normal'),
|
|
103
|
+
borderRadius: getStateStyles(props, 'borderRadius', 'normal'),
|
|
104
|
+
textColor: getStateStyles(props, 'color', 'normal'),
|
|
105
|
+
backgroundHover: getStateStyles(props, 'background', 'hover'),
|
|
106
|
+
textColorHover: getStateStyles(props, 'color', 'hover'),
|
|
107
|
+
backgroundPressed: getStateStyles(props, 'background', 'pressed'),
|
|
108
|
+
textColorPressed: getStateStyles(props, 'color', 'pressed')
|
|
109
|
+
})).withConfig({
|
|
110
|
+
displayName: "Day__DayComponent",
|
|
111
|
+
componentId: "sc-1japneh-1"
|
|
112
|
+
})(["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);
|
|
113
|
+
export const Day = ({
|
|
114
|
+
date,
|
|
115
|
+
onAction
|
|
116
|
+
}) => {
|
|
117
|
+
const {
|
|
118
|
+
onDayFocus,
|
|
119
|
+
onDayBlur,
|
|
120
|
+
onSelection,
|
|
121
|
+
disabled,
|
|
122
|
+
blocked,
|
|
123
|
+
selected,
|
|
124
|
+
today
|
|
125
|
+
} = useDatePicker(date);
|
|
126
|
+
const keyPressHandler = useCallback(event => {
|
|
127
|
+
if (disabled) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ([' ', 'Enter'].includes(event.key)) {
|
|
132
|
+
onSelection(date);
|
|
133
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
|
134
|
+
}
|
|
135
|
+
}, [disabled, onSelection, onAction, date]);
|
|
136
|
+
const clickHandler = useCallback(event => {
|
|
137
|
+
if (disabled) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
onSelection(date);
|
|
142
|
+
onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
|
|
143
|
+
}, [disabled, onSelection, date, onAction]);
|
|
144
|
+
const todayStyles = useMemo(() => today ? {
|
|
145
|
+
border: '2px solid',
|
|
146
|
+
padding: '4px 6px',
|
|
147
|
+
borderRadius: '16px',
|
|
148
|
+
fontWeight: 'bold'
|
|
149
|
+
} : {}, [today]);
|
|
150
|
+
return /*#__PURE__*/React.createElement(DayComponent, {
|
|
151
|
+
role: "button",
|
|
152
|
+
blocked: blocked,
|
|
153
|
+
disabled: disabled,
|
|
154
|
+
selected: selected,
|
|
155
|
+
today: today,
|
|
156
|
+
onClick: clickHandler,
|
|
157
|
+
onMouseEnter: () => onDayFocus(date),
|
|
158
|
+
onFocus: () => onDayFocus(date),
|
|
159
|
+
onBlur: () => onDayBlur(date),
|
|
160
|
+
onKeyPress: keyPressHandler
|
|
161
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
162
|
+
sx: todayStyles
|
|
163
|
+
}, date.getDate()));
|
|
164
|
+
};
|
|
165
|
+
Day.displayName = "Day";
|
|
166
|
+
export const BlankDay = styled(DayBaseComponent).withConfig({
|
|
167
|
+
displayName: "Day__BlankDay",
|
|
168
|
+
componentId: "sc-1japneh-2"
|
|
169
|
+
})(["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,96 @@
|
|
|
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;justify-self:center;"], get('fontSizes.1'), get('fontWeights.bold'));
|
|
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
|
+
month,
|
|
32
|
+
year
|
|
33
|
+
}) => {
|
|
34
|
+
const {
|
|
35
|
+
configuration
|
|
36
|
+
} = useDatePicker();
|
|
37
|
+
const [selectedDay, setSelectedDay] = useState(null);
|
|
38
|
+
const getTitle = useMemo(() => `${format(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
|
|
39
|
+
const weekdayHeaders = useMemo(() => {
|
|
40
|
+
var _configuration$weekSt;
|
|
41
|
+
|
|
42
|
+
const now = new Date(year, month);
|
|
43
|
+
const weekOptions = {
|
|
44
|
+
weekStartsOn: weekdayEnum[(_configuration$weekSt = configuration.weekStartsOn) !== null && _configuration$weekSt !== void 0 ? _configuration$weekSt : 'Sunday']
|
|
45
|
+
};
|
|
46
|
+
return eachDayOfInterval({
|
|
47
|
+
start: startOfWeek(now, weekOptions),
|
|
48
|
+
end: endOfWeek(now, weekOptions)
|
|
49
|
+
}).map(d => /*#__PURE__*/React.createElement(WeekdayHeader, {
|
|
50
|
+
key: `weekday-${d}-header`
|
|
51
|
+
}, format(d, 'EEEEEE')));
|
|
52
|
+
}, [configuration.weekStartsOn, month, year]);
|
|
53
|
+
|
|
54
|
+
const dayAction = date => {
|
|
55
|
+
setSelectedDay(date);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const dayComponents = useMemo(() => {
|
|
59
|
+
var _configuration$weekSt2, _configuration$weekSt3;
|
|
60
|
+
|
|
61
|
+
const components = [];
|
|
62
|
+
const firstDay = new Date(year, month, 1);
|
|
63
|
+
const preBlanks = (firstDay.getDay() + (7 - weekdayEnum[(_configuration$weekSt2 = configuration.weekStartsOn) !== null && _configuration$weekSt2 !== void 0 ? _configuration$weekSt2 : 'Sunday'])) % 7;
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < preBlanks; i++) {
|
|
66
|
+
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
|
67
|
+
key: `month-pre-blank-${i}`
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (let i = 1; i <= getDaysInMonth(firstDay); i++) {
|
|
72
|
+
const date = new Date(year, month, i);
|
|
73
|
+
components.push( /*#__PURE__*/React.createElement(Day, {
|
|
74
|
+
key: `day-component-${date.toString()}`,
|
|
75
|
+
date: date,
|
|
76
|
+
selected: selectedDay ? isEqual(date, selectedDay) : false,
|
|
77
|
+
onAction: dayAction
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const lastDay = lastDayOfMonth(firstDay);
|
|
82
|
+
const postBlanks = (lastDay.getDay() + (7 - weekdayEnum[(_configuration$weekSt3 = configuration.weekStartsOn) !== null && _configuration$weekSt3 !== void 0 ? _configuration$weekSt3 : 'Sunday'])) % 7;
|
|
83
|
+
|
|
84
|
+
for (let i = 6; i > postBlanks; i--) {
|
|
85
|
+
components.push( /*#__PURE__*/React.createElement(BlankDay, {
|
|
86
|
+
key: `month-post-blank-${i}`
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return components;
|
|
91
|
+
}, [configuration.weekStartsOn, month, selectedDay, year]);
|
|
92
|
+
return /*#__PURE__*/React.createElement(MonthComponent, {
|
|
93
|
+
role: "grid"
|
|
94
|
+
}, /*#__PURE__*/React.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
|
|
95
|
+
};
|
|
96
|
+
Month.displayName = "Month";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DatePicker } from './DatePicker';
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
maxDate?: Date;
|
|
14
|
+
maxSelections?: number;
|
|
15
|
+
maxRange?: number;
|
|
16
|
+
minDate?: Date;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
rangeIncrement?: number;
|
|
19
|
+
selection?: SelectionVariant;
|
|
20
|
+
view?: '1-month' | '2-month';
|
|
21
|
+
weekStartsOn?: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
|
22
|
+
}
|
|
23
|
+
export declare type RangeSelection = {
|
|
24
|
+
from: Date;
|
|
25
|
+
to: Date | null;
|
|
26
|
+
};
|
|
27
|
+
export declare type StringRangeSelection = {
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
};
|
|
31
|
+
export interface DatePickerContext {
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
configuration: DatePickerConfiguration;
|
|
34
|
+
currentViewingDate: Date;
|
|
35
|
+
goToMonth: (date: Date) => void;
|
|
36
|
+
hoverRange?: RangeSelection | null;
|
|
37
|
+
selection?: Selection;
|
|
38
|
+
softSelection?: Partial<RangeSelection> | null;
|
|
39
|
+
selectionActive?: boolean;
|
|
40
|
+
formattedDate: string;
|
|
41
|
+
nextMonth: () => void;
|
|
42
|
+
onDateInput: (updatedSelection: Selection) => void;
|
|
43
|
+
onDayFocus: (date: Date) => void;
|
|
44
|
+
onDayBlur: (date: Date) => void;
|
|
45
|
+
onSelection: (date: Date) => void;
|
|
46
|
+
previousMonth: () => void;
|
|
47
|
+
revertValue: () => void;
|
|
48
|
+
saveValue: (selection?: Selection) => void;
|
|
49
|
+
}
|
|
50
|
+
export declare type Selection = Date | Array<Date> | RangeSelection | null;
|
|
51
|
+
export declare type StringSelection = string | Array<string> | {
|
|
52
|
+
to: string;
|
|
53
|
+
from: string;
|
|
54
|
+
} | null;
|
|
55
|
+
export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
|
|
56
|
+
declare const useDatePicker: (date?: Date | undefined) => {
|
|
57
|
+
blocked: boolean | undefined;
|
|
58
|
+
disabled: boolean;
|
|
59
|
+
selected: DaySelection;
|
|
60
|
+
today: boolean;
|
|
61
|
+
configuration: DatePickerConfiguration;
|
|
62
|
+
currentViewingDate: Date;
|
|
63
|
+
goToMonth: (date: Date) => void;
|
|
64
|
+
hoverRange?: RangeSelection | null | undefined;
|
|
65
|
+
selection?: Selection | undefined;
|
|
66
|
+
softSelection?: Partial<RangeSelection> | null | undefined;
|
|
67
|
+
selectionActive?: boolean | undefined;
|
|
68
|
+
formattedDate: string;
|
|
69
|
+
nextMonth: () => void;
|
|
70
|
+
onDateInput: (updatedSelection: Selection) => void;
|
|
71
|
+
onDayFocus: (date: Date) => void;
|
|
72
|
+
onDayBlur: (date: Date) => void;
|
|
73
|
+
onSelection: (date: Date) => void;
|
|
74
|
+
previousMonth: () => void;
|
|
75
|
+
revertValue: () => void;
|
|
76
|
+
saveValue: (selection?: Selection | undefined) => void;
|
|
77
|
+
};
|
|
78
|
+
export default useDatePicker;
|
|
79
|
+
export interface DatePickerProviderProps {
|
|
80
|
+
closePicker?: () => void;
|
|
81
|
+
configuration?: DatePickerConfiguration;
|
|
82
|
+
value?: Selection | StringSelection;
|
|
83
|
+
}
|
|
84
|
+
export declare function isSingleSelection(selection: Selection): selection is Date;
|
|
85
|
+
export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
|
|
86
|
+
export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
|
|
87
|
+
export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
|
|
88
|
+
export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
|