@instructure/ui-calendar 11.7.3-snapshot-7 → 11.7.3-snapshot-26
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 -2
- package/es/Calendar/v1/Day/index.js +76 -66
- package/es/Calendar/v1/Day/styles.js +8 -4
- package/es/Calendar/v1/Day/theme.js +21 -20
- package/es/Calendar/v1/index.js +162 -130
- package/es/Calendar/v1/styles.js +3 -1
- package/es/Calendar/v1/theme.js +15 -14
- package/es/Calendar/v2/Day/index.js +76 -66
- package/es/Calendar/v2/Day/styles.js +8 -4
- package/es/Calendar/v2/index.js +162 -130
- package/es/Calendar/v2/styles.js +3 -1
- package/lib/Calendar/v1/Day/index.js +76 -66
- package/lib/Calendar/v1/Day/styles.js +8 -4
- package/lib/Calendar/v1/Day/theme.js +21 -20
- package/lib/Calendar/v1/index.js +162 -130
- package/lib/Calendar/v1/styles.js +3 -1
- package/lib/Calendar/v1/theme.js +15 -14
- package/lib/Calendar/v2/Day/index.js +76 -66
- package/lib/Calendar/v2/Day/styles.js +8 -4
- package/lib/Calendar/v2/index.js +162 -130
- package/lib/Calendar/v2/styles.js +3 -1
- package/package.json +17 -17
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [11.7.3-snapshot-
|
|
6
|
+
## [11.7.3-snapshot-26](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-26) (2026-05-05)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **many:** update dependencies, remove lots of Babel plugins, remove Webpack 4 support ([f916fca](https://github.com/instructure/instructure-ui/commit/f916fcafdddcb2d7de401f93e8ff92cfdfa47bba))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const _excluded = ["children", "label", "interaction", "isOutsideMonth", "isSelected", "isToday", "onClick", "onKeyDown", "as", "styles"];
|
|
3
|
-
var _dec, _class, _Day;
|
|
1
|
+
var _dec, _class;
|
|
4
2
|
/*
|
|
5
3
|
* The MIT License (MIT)
|
|
6
4
|
*
|
|
@@ -40,45 +38,22 @@ parent: Calendar
|
|
|
40
38
|
id: Calendar.Day
|
|
41
39
|
---
|
|
42
40
|
**/
|
|
43
|
-
let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
this.handleKeyDown = event => {
|
|
58
|
-
const _this$props2 = this.props,
|
|
59
|
-
onKeyDown = _this$props2.onKeyDown,
|
|
60
|
-
date = _this$props2.date;
|
|
61
|
-
if (typeof onKeyDown === 'function') {
|
|
62
|
-
onKeyDown(event, {
|
|
63
|
-
date
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
this.handleElementRef = el => {
|
|
68
|
-
const elementRef = this.props.elementRef;
|
|
69
|
-
this.ref = el;
|
|
70
|
-
if (typeof elementRef === 'function') {
|
|
71
|
-
elementRef(el);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
41
|
+
let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = class Day extends Component {
|
|
42
|
+
static displayName = "Day";
|
|
43
|
+
static componentId = 'Calendar.Day';
|
|
44
|
+
static allowedProps = allowedProps;
|
|
45
|
+
static defaultProps = {
|
|
46
|
+
interaction: 'enabled',
|
|
47
|
+
isSelected: false,
|
|
48
|
+
isToday: false,
|
|
49
|
+
isOutsideMonth: false
|
|
50
|
+
};
|
|
51
|
+
ref = null;
|
|
75
52
|
componentDidMount() {
|
|
76
|
-
|
|
77
|
-
(_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3, this.makeStylesVariables);
|
|
53
|
+
this.props.makeStyles?.(this.makeStylesVariables);
|
|
78
54
|
}
|
|
79
55
|
componentDidUpdate() {
|
|
80
|
-
|
|
81
|
-
(_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4, this.makeStylesVariables);
|
|
56
|
+
this.props.makeStyles?.(this.makeStylesVariables);
|
|
82
57
|
}
|
|
83
58
|
get makeStylesVariables() {
|
|
84
59
|
return {
|
|
@@ -86,37 +61,77 @@ let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
|
|
|
86
61
|
};
|
|
87
62
|
}
|
|
88
63
|
get isDisabled() {
|
|
89
|
-
const
|
|
64
|
+
const {
|
|
65
|
+
interaction
|
|
66
|
+
} = this.props;
|
|
90
67
|
return interaction === 'disabled';
|
|
91
68
|
}
|
|
92
69
|
get elementType() {
|
|
93
|
-
const
|
|
70
|
+
const {
|
|
71
|
+
as
|
|
72
|
+
} = this.props;
|
|
94
73
|
return as || getElementType(Day, this.props);
|
|
95
74
|
}
|
|
96
75
|
shouldApplyAriaSelected() {
|
|
97
|
-
const
|
|
76
|
+
const {
|
|
77
|
+
role
|
|
78
|
+
} = this.props;
|
|
98
79
|
return !!role && ['option', 'gridcell'].indexOf(role) > -1;
|
|
99
80
|
}
|
|
81
|
+
handleClick = event => {
|
|
82
|
+
const {
|
|
83
|
+
onClick,
|
|
84
|
+
date
|
|
85
|
+
} = this.props;
|
|
86
|
+
if (typeof onClick === 'function') {
|
|
87
|
+
onClick(event, {
|
|
88
|
+
date
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
handleKeyDown = event => {
|
|
93
|
+
const {
|
|
94
|
+
onKeyDown,
|
|
95
|
+
date
|
|
96
|
+
} = this.props;
|
|
97
|
+
if (typeof onKeyDown === 'function') {
|
|
98
|
+
onKeyDown(event, {
|
|
99
|
+
date
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
handleElementRef = el => {
|
|
104
|
+
const {
|
|
105
|
+
elementRef
|
|
106
|
+
} = this.props;
|
|
107
|
+
this.ref = el;
|
|
108
|
+
if (typeof elementRef === 'function') {
|
|
109
|
+
elementRef(el);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
100
112
|
render() {
|
|
101
|
-
const
|
|
102
|
-
children
|
|
103
|
-
label
|
|
104
|
-
interaction
|
|
105
|
-
isOutsideMonth
|
|
106
|
-
isSelected
|
|
107
|
-
isToday
|
|
108
|
-
onClick
|
|
109
|
-
onKeyDown
|
|
110
|
-
as
|
|
111
|
-
styles
|
|
112
|
-
props
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
const {
|
|
114
|
+
children,
|
|
115
|
+
label,
|
|
116
|
+
interaction,
|
|
117
|
+
isOutsideMonth,
|
|
118
|
+
isSelected,
|
|
119
|
+
isToday,
|
|
120
|
+
onClick,
|
|
121
|
+
onKeyDown,
|
|
122
|
+
as,
|
|
123
|
+
styles,
|
|
124
|
+
...props
|
|
125
|
+
} = this.props;
|
|
126
|
+
const {
|
|
127
|
+
elementType,
|
|
128
|
+
isDisabled
|
|
129
|
+
} = this;
|
|
115
130
|
const passthroughProps = View.omitViewProps(omitProps(props, Day.allowedProps), Day);
|
|
116
131
|
return _jsx(View, {
|
|
117
132
|
...passthroughProps,
|
|
118
133
|
as: elementType,
|
|
119
|
-
css: styles
|
|
134
|
+
css: styles?.calendarDay,
|
|
120
135
|
display: "inline-block",
|
|
121
136
|
margin: "xxx-small",
|
|
122
137
|
borderWidth: "none",
|
|
@@ -124,14 +139,14 @@ let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
|
|
|
124
139
|
background: "transparent",
|
|
125
140
|
cursor: elementType === 'button' || elementType === 'a' ? isDisabled ? 'not-allowed' : 'pointer' : 'auto',
|
|
126
141
|
disabled: isDisabled,
|
|
127
|
-
"aria-current": isToday ? 'date' :
|
|
128
|
-
"aria-selected": this.shouldApplyAriaSelected() ? isSelected ? 'true' : 'false' :
|
|
142
|
+
"aria-current": isToday ? 'date' : undefined,
|
|
143
|
+
"aria-selected": this.shouldApplyAriaSelected() ? isSelected ? 'true' : 'false' : undefined,
|
|
129
144
|
onClick: onClick && this.handleClick,
|
|
130
145
|
onKeyDown: onKeyDown && this.handleKeyDown,
|
|
131
146
|
elementRef: this.handleElementRef,
|
|
132
147
|
"data-cid": "Calendar.Day",
|
|
133
148
|
children: _jsx("span", {
|
|
134
|
-
css: styles
|
|
149
|
+
css: styles?.day,
|
|
135
150
|
children: _jsx(AccessibleContent, {
|
|
136
151
|
alt: label,
|
|
137
152
|
children: callRenderProp(children)
|
|
@@ -139,11 +154,6 @@ let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
|
|
|
139
154
|
})
|
|
140
155
|
});
|
|
141
156
|
}
|
|
142
|
-
}
|
|
143
|
-
interaction: 'enabled',
|
|
144
|
-
isSelected: false,
|
|
145
|
-
isToday: false,
|
|
146
|
-
isOutsideMonth: false
|
|
147
|
-
}, _Day)) || _class);
|
|
157
|
+
}) || _class);
|
|
148
158
|
export default Day;
|
|
149
159
|
export { Day };
|
|
@@ -33,10 +33,14 @@
|
|
|
33
33
|
* @return {Object} The final style object, which will be used in the component
|
|
34
34
|
*/
|
|
35
35
|
const generateStyle = (componentTheme, props, state) => {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const {
|
|
37
|
+
isOutsideMonth,
|
|
38
|
+
isSelected,
|
|
39
|
+
isToday
|
|
40
|
+
} = props;
|
|
41
|
+
const {
|
|
42
|
+
isDisabled
|
|
43
|
+
} = state;
|
|
40
44
|
return {
|
|
41
45
|
calendarDay: {
|
|
42
46
|
label: 'calendarDay',
|
|
@@ -28,13 +28,14 @@
|
|
|
28
28
|
* @return {Object} The final theme object with the overrides and component variables
|
|
29
29
|
*/
|
|
30
30
|
const generateComponentTheme = theme => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
colors
|
|
34
|
-
typography
|
|
35
|
-
spacing
|
|
36
|
-
forms
|
|
37
|
-
themeName
|
|
31
|
+
const {
|
|
32
|
+
borders,
|
|
33
|
+
colors,
|
|
34
|
+
typography,
|
|
35
|
+
spacing,
|
|
36
|
+
forms,
|
|
37
|
+
key: themeName
|
|
38
|
+
} = theme;
|
|
38
39
|
const themeSpecificStyle = {
|
|
39
40
|
canvas: {
|
|
40
41
|
color: theme['ic-brand-font-color-dark'],
|
|
@@ -42,19 +43,19 @@ const generateComponentTheme = theme => {
|
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
45
|
const componentVariables = {
|
|
45
|
-
color: colors
|
|
46
|
-
background: colors
|
|
47
|
-
fontSize: typography
|
|
48
|
-
padding: spacing
|
|
49
|
-
height: forms
|
|
50
|
-
minWidth: forms
|
|
51
|
-
outsideMonthColor: colors
|
|
52
|
-
selectedBackground: colors
|
|
53
|
-
selectedColor: colors
|
|
54
|
-
selectedBorderRadius: borders
|
|
55
|
-
todayBackground: colors
|
|
56
|
-
todayColor: colors
|
|
57
|
-
todayBorderRadius: forms
|
|
46
|
+
color: colors?.contrasts?.grey125125,
|
|
47
|
+
background: colors?.contrasts?.white1010,
|
|
48
|
+
fontSize: typography?.fontSizeMedium,
|
|
49
|
+
padding: spacing?.xxSmall,
|
|
50
|
+
height: forms?.inputHeightSmall,
|
|
51
|
+
minWidth: forms?.inputHeightSmall,
|
|
52
|
+
outsideMonthColor: colors?.contrasts?.grey4570,
|
|
53
|
+
selectedBackground: colors?.contrasts?.green4570,
|
|
54
|
+
selectedColor: colors?.contrasts?.white1010,
|
|
55
|
+
selectedBorderRadius: borders?.radiusMedium,
|
|
56
|
+
todayBackground: colors?.contrasts?.blue4570,
|
|
57
|
+
todayColor: colors?.contrasts?.white1010,
|
|
58
|
+
todayBorderRadius: forms?.inputHeightSmall
|
|
58
59
|
};
|
|
59
60
|
return {
|
|
60
61
|
...componentVariables,
|
package/es/Calendar/v1/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _dec, _dec2, _class
|
|
1
|
+
var _dec, _dec2, _class;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -45,106 +45,22 @@ category: components
|
|
|
45
45
|
---
|
|
46
46
|
**/
|
|
47
47
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
48
|
-
let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class =
|
|
48
|
+
let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class = class Calendar extends Component {
|
|
49
|
+
static displayName = "Calendar";
|
|
50
|
+
static componentId = 'Calendar';
|
|
51
|
+
static contextType = ApplyLocaleContext;
|
|
52
|
+
static Day = Day;
|
|
53
|
+
static DAY_COUNT = 42; // 6 weeks visible
|
|
54
|
+
|
|
55
|
+
static allowedProps = allowedProps;
|
|
56
|
+
static defaultProps = {
|
|
57
|
+
as: 'span',
|
|
58
|
+
role: 'table'
|
|
59
|
+
};
|
|
60
|
+
ref = null;
|
|
61
|
+
_weekdayHeaderIds;
|
|
49
62
|
constructor(props) {
|
|
50
63
|
super(props);
|
|
51
|
-
this.ref = null;
|
|
52
|
-
this._weekdayHeaderIds = void 0;
|
|
53
|
-
this.handleRef = el => {
|
|
54
|
-
this.ref = el;
|
|
55
|
-
};
|
|
56
|
-
this.calculateState = (locale, timezone, currentDate) => {
|
|
57
|
-
const visibleMonth = this.props.visibleMonth || currentDate;
|
|
58
|
-
return {
|
|
59
|
-
visibleMonth: visibleMonth ? DateTime.parse(visibleMonth, locale, timezone) : DateTime.now(locale, timezone),
|
|
60
|
-
today: currentDate ? DateTime.parse(currentDate, locale, timezone) : DateTime.now(locale, timezone)
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
this.renderMonthNavigationButtons = () => {
|
|
64
|
-
const _this$props = this.props,
|
|
65
|
-
renderNextMonthButton = _this$props.renderNextMonthButton,
|
|
66
|
-
renderPrevMonthButton = _this$props.renderPrevMonthButton;
|
|
67
|
-
return {
|
|
68
|
-
prevButton: renderPrevMonthButton ? callRenderProp(renderPrevMonthButton) : _IconButton || (_IconButton = _jsx(IconButton, {
|
|
69
|
-
size: "small",
|
|
70
|
-
withBackground: false,
|
|
71
|
-
withBorder: false,
|
|
72
|
-
renderIcon: _jsx(IconArrowOpenStartSolid, {
|
|
73
|
-
color: "primary"
|
|
74
|
-
}),
|
|
75
|
-
screenReaderLabel: "Previous month"
|
|
76
|
-
})),
|
|
77
|
-
nextButton: renderNextMonthButton ? callRenderProp(renderNextMonthButton) : _IconButton2 || (_IconButton2 = _jsx(IconButton, {
|
|
78
|
-
size: "small",
|
|
79
|
-
withBackground: false,
|
|
80
|
-
withBorder: false,
|
|
81
|
-
renderIcon: _jsx(IconArrowOpenEndSolid, {
|
|
82
|
-
color: "primary"
|
|
83
|
-
}),
|
|
84
|
-
screenReaderLabel: "Next month"
|
|
85
|
-
}))
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
this.handleMonthChange = direction => e => {
|
|
89
|
-
const _this$props2 = this.props,
|
|
90
|
-
onRequestRenderNextMonth = _this$props2.onRequestRenderNextMonth,
|
|
91
|
-
onRequestRenderPrevMonth = _this$props2.onRequestRenderPrevMonth;
|
|
92
|
-
const visibleMonth = this.state.visibleMonth;
|
|
93
|
-
const newDate = visibleMonth.clone();
|
|
94
|
-
if (direction === 'prev') {
|
|
95
|
-
if (!this.hasPrevMonth) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (onRequestRenderPrevMonth) {
|
|
99
|
-
onRequestRenderPrevMonth(e, newDate.subtract({
|
|
100
|
-
months: 1
|
|
101
|
-
}).format('YYYY-MM'));
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
newDate.subtract({
|
|
105
|
-
months: 1
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
if (!this.hasNextMonth) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (onRequestRenderNextMonth) {
|
|
112
|
-
onRequestRenderNextMonth(e, newDate.add({
|
|
113
|
-
months: 1
|
|
114
|
-
}).format('YYYY-MM'));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
newDate.add({
|
|
118
|
-
months: 1
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
this.setState({
|
|
122
|
-
visibleMonth: newDate
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
this.handleYearChange = (e, year) => {
|
|
126
|
-
const withYearPicker = this.props.withYearPicker;
|
|
127
|
-
const visibleMonth = this.state.visibleMonth;
|
|
128
|
-
const yearNumber = Number(DateTime.parse(year, this.locale(), this.timezone()).locale('en').format('YYYY'));
|
|
129
|
-
const newDate = visibleMonth.clone();
|
|
130
|
-
if (withYearPicker !== null && withYearPicker !== void 0 && withYearPicker.onRequestYearChange) {
|
|
131
|
-
withYearPicker.onRequestYearChange(e, yearNumber);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
newDate.year(yearNumber);
|
|
135
|
-
this.setState({
|
|
136
|
-
visibleMonth: newDate
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
// date is returned as an ISO string, like 2021-09-14T22:00:00.000Z
|
|
140
|
-
this.handleDayClick = (event, {
|
|
141
|
-
date
|
|
142
|
-
}) => {
|
|
143
|
-
if (this.props.onDateSelected) {
|
|
144
|
-
const parsedDate = DateTime.parse(date, this.locale(), this.timezone());
|
|
145
|
-
this.props.onDateSelected(parsedDate.toISOString(), parsedDate, event);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
64
|
this._weekdayHeaderIds = (this.props.renderWeekdayLabels || this.defaultWeekdays).reduce((ids, _label, i) => {
|
|
149
65
|
return {
|
|
150
66
|
...ids,
|
|
@@ -153,13 +69,14 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
153
69
|
}, {});
|
|
154
70
|
this.state = this.calculateState(this.locale(), this.timezone(), props.currentDate);
|
|
155
71
|
}
|
|
72
|
+
handleRef = el => {
|
|
73
|
+
this.ref = el;
|
|
74
|
+
};
|
|
156
75
|
componentDidMount() {
|
|
157
|
-
|
|
158
|
-
(_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
|
|
76
|
+
this.props.makeStyles?.();
|
|
159
77
|
}
|
|
160
78
|
componentDidUpdate(prevProps) {
|
|
161
|
-
|
|
162
|
-
(_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
|
|
79
|
+
this.props.makeStyles?.();
|
|
163
80
|
const isUpdated = prevProps.locale !== this.props.locale || prevProps.timezone !== this.props.timezone || prevProps.visibleMonth !== this.props.visibleMonth;
|
|
164
81
|
if (isUpdated) {
|
|
165
82
|
this.setState(() => {
|
|
@@ -169,8 +86,15 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
169
86
|
});
|
|
170
87
|
}
|
|
171
88
|
}
|
|
89
|
+
calculateState = (locale, timezone, currentDate) => {
|
|
90
|
+
const visibleMonth = this.props.visibleMonth || currentDate;
|
|
91
|
+
return {
|
|
92
|
+
visibleMonth: visibleMonth ? DateTime.parse(visibleMonth, locale, timezone) : DateTime.now(locale, timezone),
|
|
93
|
+
today: currentDate ? DateTime.parse(currentDate, locale, timezone) : DateTime.now(locale, timezone)
|
|
94
|
+
};
|
|
95
|
+
};
|
|
172
96
|
get role() {
|
|
173
|
-
return this.props.role === 'listbox' ? this.props.role :
|
|
97
|
+
return this.props.role === 'listbox' ? this.props.role : undefined;
|
|
174
98
|
}
|
|
175
99
|
get hasPrevMonth() {
|
|
176
100
|
// this is needed for locales that doesn't use the latin script for numbers e.g.: arabic
|
|
@@ -186,23 +110,113 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
186
110
|
}).format('YYYY'));
|
|
187
111
|
return !this.props.withYearPicker || this.props.withYearPicker && yearNumber <= this.props.withYearPicker.endYear;
|
|
188
112
|
}
|
|
113
|
+
renderMonthNavigationButtons = () => {
|
|
114
|
+
const {
|
|
115
|
+
renderNextMonthButton,
|
|
116
|
+
renderPrevMonthButton
|
|
117
|
+
} = this.props;
|
|
118
|
+
return {
|
|
119
|
+
prevButton: renderPrevMonthButton ? callRenderProp(renderPrevMonthButton) : _jsx(IconButton, {
|
|
120
|
+
size: "small",
|
|
121
|
+
withBackground: false,
|
|
122
|
+
withBorder: false,
|
|
123
|
+
renderIcon: _jsx(IconArrowOpenStartSolid, {
|
|
124
|
+
color: "primary"
|
|
125
|
+
}),
|
|
126
|
+
screenReaderLabel: "Previous month"
|
|
127
|
+
}),
|
|
128
|
+
nextButton: renderNextMonthButton ? callRenderProp(renderNextMonthButton) : _jsx(IconButton, {
|
|
129
|
+
size: "small",
|
|
130
|
+
withBackground: false,
|
|
131
|
+
withBorder: false,
|
|
132
|
+
renderIcon: _jsx(IconArrowOpenEndSolid, {
|
|
133
|
+
color: "primary"
|
|
134
|
+
}),
|
|
135
|
+
screenReaderLabel: "Next month"
|
|
136
|
+
})
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
handleMonthChange = direction => e => {
|
|
140
|
+
const {
|
|
141
|
+
onRequestRenderNextMonth,
|
|
142
|
+
onRequestRenderPrevMonth
|
|
143
|
+
} = this.props;
|
|
144
|
+
const {
|
|
145
|
+
visibleMonth
|
|
146
|
+
} = this.state;
|
|
147
|
+
const newDate = visibleMonth.clone();
|
|
148
|
+
if (direction === 'prev') {
|
|
149
|
+
if (!this.hasPrevMonth) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (onRequestRenderPrevMonth) {
|
|
153
|
+
onRequestRenderPrevMonth(e, newDate.subtract({
|
|
154
|
+
months: 1
|
|
155
|
+
}).format('YYYY-MM'));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
newDate.subtract({
|
|
159
|
+
months: 1
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
if (!this.hasNextMonth) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (onRequestRenderNextMonth) {
|
|
166
|
+
onRequestRenderNextMonth(e, newDate.add({
|
|
167
|
+
months: 1
|
|
168
|
+
}).format('YYYY-MM'));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
newDate.add({
|
|
172
|
+
months: 1
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
this.setState({
|
|
176
|
+
visibleMonth: newDate
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
handleYearChange = (e, year) => {
|
|
180
|
+
const {
|
|
181
|
+
withYearPicker
|
|
182
|
+
} = this.props;
|
|
183
|
+
const {
|
|
184
|
+
visibleMonth
|
|
185
|
+
} = this.state;
|
|
186
|
+
const yearNumber = Number(DateTime.parse(year, this.locale(), this.timezone()).locale('en').format('YYYY'));
|
|
187
|
+
const newDate = visibleMonth.clone();
|
|
188
|
+
if (withYearPicker?.onRequestYearChange) {
|
|
189
|
+
withYearPicker.onRequestYearChange(e, yearNumber);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
newDate.year(yearNumber);
|
|
193
|
+
this.setState({
|
|
194
|
+
visibleMonth: newDate
|
|
195
|
+
});
|
|
196
|
+
};
|
|
189
197
|
renderHeader() {
|
|
190
|
-
const
|
|
191
|
-
renderNavigationLabel
|
|
192
|
-
styles
|
|
193
|
-
withYearPicker
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
const {
|
|
199
|
+
renderNavigationLabel,
|
|
200
|
+
styles,
|
|
201
|
+
withYearPicker
|
|
202
|
+
} = this.props;
|
|
203
|
+
const {
|
|
204
|
+
visibleMonth
|
|
205
|
+
} = this.state;
|
|
206
|
+
const {
|
|
207
|
+
prevButton,
|
|
208
|
+
nextButton
|
|
209
|
+
} = this.renderMonthNavigationButtons();
|
|
198
210
|
const cloneButton = (button, onClick) => safeCloneElement(button, {
|
|
199
211
|
onClick: createChainedFunction(button.props.onClick, onClick)
|
|
200
212
|
});
|
|
201
|
-
const style = [styles
|
|
213
|
+
const style = [styles?.navigation, ...(prevButton || nextButton ? [styles?.navigationWithButtons] : [])];
|
|
202
214
|
const yearList = [];
|
|
203
215
|
if (withYearPicker) {
|
|
204
|
-
const
|
|
205
|
-
|
|
216
|
+
const {
|
|
217
|
+
startYear,
|
|
218
|
+
endYear
|
|
219
|
+
} = withYearPicker;
|
|
206
220
|
for (let year = endYear; year >= startYear; year--) {
|
|
207
221
|
// add the years to the list with the correct locale
|
|
208
222
|
yearList.push(DateTime.parse(year.toString(), this.locale(), this.timezone()).format('YYYY'));
|
|
@@ -219,7 +233,7 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
219
233
|
}) : null]
|
|
220
234
|
}), nextButton && cloneButton(nextButton, this.handleMonthChange('next'))]
|
|
221
235
|
}), withYearPicker ? _jsx("div", {
|
|
222
|
-
css: styles
|
|
236
|
+
css: styles?.yearPicker,
|
|
223
237
|
children: _jsx(SimpleSelect, {
|
|
224
238
|
width: "90px",
|
|
225
239
|
renderLabel: "",
|
|
@@ -249,15 +263,19 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
249
263
|
});
|
|
250
264
|
}
|
|
251
265
|
renderWeekdayHeaders() {
|
|
252
|
-
const
|
|
266
|
+
const {
|
|
267
|
+
styles
|
|
268
|
+
} = this.props;
|
|
253
269
|
const renderWeekdayLabels = this.props.renderWeekdayLabels || this.defaultWeekdays;
|
|
254
|
-
const
|
|
270
|
+
const {
|
|
271
|
+
length
|
|
272
|
+
} = renderWeekdayLabels;
|
|
255
273
|
error(length === 7, `[Calendar] \`renderWeekdayLabels\` should be an array with 7 labels (one for each weekday). ${length} provided.`);
|
|
256
274
|
return _jsx("tr", {
|
|
257
275
|
children: renderWeekdayLabels.map((label, i) => {
|
|
258
276
|
return _jsx("th", {
|
|
259
277
|
scope: "col",
|
|
260
|
-
css: styles
|
|
278
|
+
css: styles?.weekdayHeader,
|
|
261
279
|
id: this._weekdayHeaderIds[i],
|
|
262
280
|
children: callRenderProp(label)
|
|
263
281
|
}, i);
|
|
@@ -291,10 +309,14 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
291
309
|
}, 7)];
|
|
292
310
|
}
|
|
293
311
|
renderDays() {
|
|
294
|
-
const
|
|
312
|
+
const {
|
|
313
|
+
children
|
|
314
|
+
} = this.props;
|
|
295
315
|
const childrenArr = Children.toArray(children ? children : this.renderDefaultdays());
|
|
296
|
-
const
|
|
297
|
-
|
|
316
|
+
const {
|
|
317
|
+
length
|
|
318
|
+
} = childrenArr;
|
|
319
|
+
const role = this.role === 'listbox' ? 'presentation' : undefined;
|
|
298
320
|
error(length === Calendar.DAY_COUNT, `[Calendar] should have exactly ${Calendar.DAY_COUNT} children. ${length} provided.`);
|
|
299
321
|
return childrenArr.reduce((days, day, i) => {
|
|
300
322
|
const index = Math.floor(i / 7);
|
|
@@ -327,6 +349,16 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
327
349
|
}
|
|
328
350
|
return DateTime.browserTimeZone();
|
|
329
351
|
}
|
|
352
|
+
|
|
353
|
+
// date is returned as an ISO string, like 2021-09-14T22:00:00.000Z
|
|
354
|
+
handleDayClick = (event, {
|
|
355
|
+
date
|
|
356
|
+
}) => {
|
|
357
|
+
if (this.props.onDateSelected) {
|
|
358
|
+
const parsedDate = DateTime.parse(date, this.locale(), this.timezone());
|
|
359
|
+
this.props.onDateSelected(parsedDate.toISOString(), parsedDate, event);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
330
362
|
isDisabledDate(date) {
|
|
331
363
|
const disabledDates = this.props.disabledDates;
|
|
332
364
|
if (!disabledDates) {
|
|
@@ -343,10 +375,13 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
343
375
|
return disabledDates(date.toISOString());
|
|
344
376
|
}
|
|
345
377
|
renderDefaultdays() {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
378
|
+
const {
|
|
379
|
+
selectedDate
|
|
380
|
+
} = this.props;
|
|
381
|
+
const {
|
|
382
|
+
visibleMonth,
|
|
383
|
+
today
|
|
384
|
+
} = this.state;
|
|
350
385
|
// Sets it to the first local day of the week counting back from the start of the month.
|
|
351
386
|
// Note that first day depends on the locale, e.g. it's Sunday in the US and
|
|
352
387
|
// Monday in most of the EU.
|
|
@@ -400,9 +435,6 @@ let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
400
435
|
children: [this.renderHeader(), this.renderBody()]
|
|
401
436
|
});
|
|
402
437
|
}
|
|
403
|
-
}
|
|
404
|
-
as: 'span',
|
|
405
|
-
role: 'table'
|
|
406
|
-
}, _Calendar)) || _class) || _class);
|
|
438
|
+
}) || _class) || _class);
|
|
407
439
|
export default Calendar;
|
|
408
440
|
export { Calendar };
|
package/es/Calendar/v1/styles.js
CHANGED
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
* @return {Object} The final style object, which will be used in the component
|
|
32
32
|
*/
|
|
33
33
|
const generateStyle = (componentTheme, props) => {
|
|
34
|
-
const
|
|
34
|
+
const {
|
|
35
|
+
withYearPicker
|
|
36
|
+
} = props;
|
|
35
37
|
return {
|
|
36
38
|
navigation: {
|
|
37
39
|
label: 'calendar__navigation',
|