@instructure/ui-calendar 11.6.0 → 11.6.1-snapshot-129
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 +36 -286
- package/es/Calendar/{Day → v1/Day}/index.js +2 -2
- package/es/Calendar/{index.js → v1/index.js} +4 -4
- package/es/Calendar/v2/Day/index.js +148 -0
- package/{src/index.ts → es/Calendar/v2/Day/props.js} +2 -4
- package/es/Calendar/v2/Day/styles.js +78 -0
- package/es/Calendar/v2/index.js +407 -0
- package/es/Calendar/v2/props.js +26 -0
- package/es/Calendar/v2/styles.js +66 -0
- package/es/{index.js → exports/a.js} +2 -2
- package/es/exports/b.js +25 -0
- package/lib/Calendar/{Day → v1/Day}/index.js +4 -4
- package/lib/Calendar/{index.js → v1/index.js} +12 -12
- package/lib/Calendar/v2/Day/index.js +155 -0
- package/lib/Calendar/v2/Day/props.js +31 -0
- package/lib/Calendar/v2/Day/styles.js +84 -0
- package/lib/Calendar/v2/index.js +416 -0
- package/lib/Calendar/v2/props.js +31 -0
- package/lib/Calendar/v2/styles.js +72 -0
- package/lib/{index.js → exports/a.js} +3 -3
- package/lib/exports/b.js +19 -0
- package/package.json +45 -23
- package/src/Calendar/{Day → v1/Day}/index.tsx +3 -3
- package/src/Calendar/{Day → v1/Day}/props.ts +1 -1
- package/src/Calendar/{index.tsx → v1/index.tsx} +4 -4
- package/src/Calendar/v2/Day/index.tsx +176 -0
- package/src/Calendar/v2/Day/props.ts +126 -0
- package/src/Calendar/v2/Day/styles.ts +96 -0
- package/src/Calendar/v2/README.md +255 -0
- package/src/Calendar/v2/index.tsx +560 -0
- package/src/Calendar/v2/props.ts +207 -0
- package/src/Calendar/v2/styles.ts +75 -0
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Calendar/{Day → v1/Day}/index.d.ts +1 -1
- package/types/Calendar/v1/Day/index.d.ts.map +1 -0
- package/types/Calendar/{Day → v1/Day}/props.d.ts +1 -1
- package/types/Calendar/v1/Day/props.d.ts.map +1 -0
- package/types/Calendar/v1/Day/styles.d.ts.map +1 -0
- package/types/Calendar/v1/Day/theme.d.ts.map +1 -0
- package/types/Calendar/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Calendar/v1/index.d.ts.map +1 -0
- package/types/Calendar/v1/props.d.ts.map +1 -0
- package/types/Calendar/v1/styles.d.ts.map +1 -0
- package/types/Calendar/v1/theme.d.ts.map +1 -0
- package/types/Calendar/v2/Day/index.d.ts +49 -0
- package/types/Calendar/v2/Day/index.d.ts.map +1 -0
- package/types/Calendar/v2/Day/props.d.ts +76 -0
- package/types/Calendar/v2/Day/props.d.ts.map +1 -0
- package/types/Calendar/v2/Day/styles.d.ts +15 -0
- package/types/Calendar/v2/Day/styles.d.ts.map +1 -0
- package/types/Calendar/v2/index.d.ts +84 -0
- package/types/Calendar/v2/index.d.ts.map +1 -0
- package/types/Calendar/v2/props.d.ts +135 -0
- package/types/Calendar/v2/props.d.ts.map +1 -0
- package/types/Calendar/v2/styles.d.ts +13 -0
- package/types/Calendar/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +5 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +5 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Calendar/Day/index.d.ts.map +0 -1
- package/types/Calendar/Day/props.d.ts.map +0 -1
- package/types/Calendar/Day/styles.d.ts.map +0 -1
- package/types/Calendar/Day/theme.d.ts.map +0 -1
- package/types/Calendar/index.d.ts.map +0 -1
- package/types/Calendar/props.d.ts.map +0 -1
- package/types/Calendar/styles.d.ts.map +0 -1
- package/types/Calendar/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/Calendar/{Day → v1/Day}/props.js +0 -0
- /package/es/Calendar/{Day → v1/Day}/styles.js +0 -0
- /package/es/Calendar/{Day → v1/Day}/theme.js +0 -0
- /package/es/Calendar/{props.js → v1/props.js} +0 -0
- /package/es/Calendar/{styles.js → v1/styles.js} +0 -0
- /package/es/Calendar/{theme.js → v1/theme.js} +0 -0
- /package/lib/Calendar/{Day → v1/Day}/props.js +0 -0
- /package/lib/Calendar/{Day → v1/Day}/styles.js +0 -0
- /package/lib/Calendar/{Day → v1/Day}/theme.js +0 -0
- /package/lib/Calendar/{props.js → v1/props.js} +0 -0
- /package/lib/Calendar/{styles.js → v1/styles.js} +0 -0
- /package/lib/Calendar/{theme.js → v1/theme.js} +0 -0
- /package/src/Calendar/{Day → v1/Day}/styles.ts +0 -0
- /package/src/Calendar/{Day → v1/Day}/theme.ts +0 -0
- /package/src/Calendar/{README.md → v1/README.md} +0 -0
- /package/src/Calendar/{props.ts → v1/props.ts} +0 -0
- /package/src/Calendar/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Calendar/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Calendar/{Day → v1/Day}/styles.d.ts +0 -0
- /package/types/Calendar/{Day → v1/Day}/theme.d.ts +0 -0
- /package/types/Calendar/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Calendar/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Calendar/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
const _excluded = ["children", "label", "interaction", "isOutsideMonth", "isSelected", "isToday", "onClick", "onKeyDown", "as", "styles"];
|
|
3
|
+
var _dec, _class, _Day;
|
|
4
|
+
/*
|
|
5
|
+
* The MIT License (MIT)
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { Component } from 'react';
|
|
29
|
+
import { View } from '@instructure/ui-view/latest';
|
|
30
|
+
import { AccessibleContent } from '@instructure/ui-a11y-content';
|
|
31
|
+
import { omitProps, callRenderProp, getElementType } from '@instructure/ui-react-utils';
|
|
32
|
+
import { withStyle } from '@instructure/emotion';
|
|
33
|
+
import generateStyle from "./styles.js";
|
|
34
|
+
import { allowedProps } from "./props.js";
|
|
35
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
36
|
+
/**
|
|
37
|
+
---
|
|
38
|
+
parent: Calendar
|
|
39
|
+
id: Calendar.Day
|
|
40
|
+
---
|
|
41
|
+
**/
|
|
42
|
+
let Day = (_dec = withStyle(generateStyle), _dec(_class = (_Day = class Day extends Component {
|
|
43
|
+
constructor(...args) {
|
|
44
|
+
super(...args);
|
|
45
|
+
this.ref = null;
|
|
46
|
+
this.handleClick = event => {
|
|
47
|
+
const _this$props = this.props,
|
|
48
|
+
onClick = _this$props.onClick,
|
|
49
|
+
date = _this$props.date;
|
|
50
|
+
if (typeof onClick === 'function') {
|
|
51
|
+
onClick(event, {
|
|
52
|
+
date
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
this.handleKeyDown = event => {
|
|
57
|
+
const _this$props2 = this.props,
|
|
58
|
+
onKeyDown = _this$props2.onKeyDown,
|
|
59
|
+
date = _this$props2.date;
|
|
60
|
+
if (typeof onKeyDown === 'function') {
|
|
61
|
+
onKeyDown(event, {
|
|
62
|
+
date
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this.handleElementRef = el => {
|
|
67
|
+
const elementRef = this.props.elementRef;
|
|
68
|
+
this.ref = el;
|
|
69
|
+
if (typeof elementRef === 'function') {
|
|
70
|
+
elementRef(el);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
componentDidMount() {
|
|
75
|
+
var _this$props$makeStyle, _this$props3;
|
|
76
|
+
(_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3, this.makeStylesVariables);
|
|
77
|
+
}
|
|
78
|
+
componentDidUpdate() {
|
|
79
|
+
var _this$props$makeStyle2, _this$props4;
|
|
80
|
+
(_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4, this.makeStylesVariables);
|
|
81
|
+
}
|
|
82
|
+
get makeStylesVariables() {
|
|
83
|
+
return {
|
|
84
|
+
isDisabled: this.isDisabled
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
get isDisabled() {
|
|
88
|
+
const interaction = this.props.interaction;
|
|
89
|
+
return interaction === 'disabled';
|
|
90
|
+
}
|
|
91
|
+
get elementType() {
|
|
92
|
+
const as = this.props.as;
|
|
93
|
+
return as || getElementType(Day, this.props);
|
|
94
|
+
}
|
|
95
|
+
shouldApplyAriaSelected() {
|
|
96
|
+
const role = this.props.role;
|
|
97
|
+
return !!role && ['option', 'gridcell'].indexOf(role) > -1;
|
|
98
|
+
}
|
|
99
|
+
render() {
|
|
100
|
+
const _this$props5 = this.props,
|
|
101
|
+
children = _this$props5.children,
|
|
102
|
+
label = _this$props5.label,
|
|
103
|
+
interaction = _this$props5.interaction,
|
|
104
|
+
isOutsideMonth = _this$props5.isOutsideMonth,
|
|
105
|
+
isSelected = _this$props5.isSelected,
|
|
106
|
+
isToday = _this$props5.isToday,
|
|
107
|
+
onClick = _this$props5.onClick,
|
|
108
|
+
onKeyDown = _this$props5.onKeyDown,
|
|
109
|
+
as = _this$props5.as,
|
|
110
|
+
styles = _this$props5.styles,
|
|
111
|
+
props = _objectWithoutProperties(_this$props5, _excluded);
|
|
112
|
+
const elementType = this.elementType,
|
|
113
|
+
isDisabled = this.isDisabled;
|
|
114
|
+
const passthroughProps = View.omitViewProps(omitProps(props, Day.allowedProps), Day);
|
|
115
|
+
return _jsx(View, {
|
|
116
|
+
...passthroughProps,
|
|
117
|
+
as: elementType,
|
|
118
|
+
css: styles === null || styles === void 0 ? void 0 : styles.calendarDay,
|
|
119
|
+
display: "inline-block",
|
|
120
|
+
margin: "xxx-small",
|
|
121
|
+
borderWidth: "none",
|
|
122
|
+
borderColor: "transparent",
|
|
123
|
+
background: "transparent",
|
|
124
|
+
cursor: elementType === 'button' || elementType === 'a' ? isDisabled ? 'not-allowed' : 'pointer' : 'auto',
|
|
125
|
+
disabled: isDisabled,
|
|
126
|
+
"aria-current": isToday ? 'date' : void 0,
|
|
127
|
+
"aria-selected": this.shouldApplyAriaSelected() ? isSelected ? 'true' : 'false' : void 0,
|
|
128
|
+
onClick: onClick && this.handleClick,
|
|
129
|
+
onKeyDown: onKeyDown && this.handleKeyDown,
|
|
130
|
+
elementRef: this.handleElementRef,
|
|
131
|
+
"data-cid": "Calendar.Day",
|
|
132
|
+
children: _jsx("span", {
|
|
133
|
+
css: styles === null || styles === void 0 ? void 0 : styles.day,
|
|
134
|
+
children: _jsx(AccessibleContent, {
|
|
135
|
+
alt: label,
|
|
136
|
+
children: callRenderProp(children)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}, _Day.displayName = "Day", _Day.componentId = 'Calendar.Day', _Day.allowedProps = allowedProps, _Day.defaultProps = {
|
|
142
|
+
interaction: 'enabled',
|
|
143
|
+
isSelected: false,
|
|
144
|
+
isToday: false,
|
|
145
|
+
isOutsideMonth: false
|
|
146
|
+
}, _Day)) || _class);
|
|
147
|
+
export default Day;
|
|
148
|
+
export { Day };
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
export { Calendar } from './Calendar'
|
|
25
|
-
export { Day as CalendarDay } from './Calendar/Day'
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
export
|
|
25
|
+
const allowedProps = ['children', 'date', 'label', 'interaction', 'isSelected', 'isToday', 'isOutsideMonth', 'onClick', 'onKeyDown', 'elementRef', 'as'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ---
|
|
27
|
+
* private: true
|
|
28
|
+
* ---
|
|
29
|
+
* Generates the style object from the theme and provided additional information
|
|
30
|
+
* @param {Object} componentTheme The theme variable object.
|
|
31
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
32
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
33
|
+
* @return {Object} The final style object, which will be used in the component
|
|
34
|
+
*/
|
|
35
|
+
const generateStyle = (componentTheme, props, _sharedTokens, state) => {
|
|
36
|
+
const isOutsideMonth = props.isOutsideMonth,
|
|
37
|
+
isSelected = props.isSelected,
|
|
38
|
+
isToday = props.isToday;
|
|
39
|
+
const isDisabled = state.isDisabled;
|
|
40
|
+
return {
|
|
41
|
+
calendarDay: {
|
|
42
|
+
label: 'calendarDay',
|
|
43
|
+
padding: 0
|
|
44
|
+
},
|
|
45
|
+
day: {
|
|
46
|
+
label: 'calendarDay__day',
|
|
47
|
+
display: 'flex',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
justifyContent: 'center',
|
|
50
|
+
background: componentTheme.background,
|
|
51
|
+
color: componentTheme.color,
|
|
52
|
+
fontSize: componentTheme.fontSize,
|
|
53
|
+
textDecoration: 'none',
|
|
54
|
+
lineHeight: 1,
|
|
55
|
+
height: componentTheme.height,
|
|
56
|
+
minWidth: componentTheme.minWidth,
|
|
57
|
+
border: 'none',
|
|
58
|
+
margin: 0,
|
|
59
|
+
...(isOutsideMonth && {
|
|
60
|
+
color: componentTheme.outsideMonthColor
|
|
61
|
+
}),
|
|
62
|
+
...(isSelected && {
|
|
63
|
+
background: componentTheme.selectedBackground,
|
|
64
|
+
borderRadius: componentTheme.selectedBorderRadius,
|
|
65
|
+
color: componentTheme.selectedColor
|
|
66
|
+
}),
|
|
67
|
+
...(isToday && !isSelected && {
|
|
68
|
+
background: componentTheme.todayBackground,
|
|
69
|
+
borderRadius: componentTheme.todayBorderRadius,
|
|
70
|
+
color: componentTheme.todayColor
|
|
71
|
+
}),
|
|
72
|
+
...(isDisabled && {
|
|
73
|
+
opacity: 0.5
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export default generateStyle;
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
var _dec, _dec2, _class, _Calendar, _IconButton, _IconButton2;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Children, Component } from 'react';
|
|
27
|
+
import { View } from '@instructure/ui-view/latest';
|
|
28
|
+
import { safeCloneElement, callRenderProp, omitProps, withDeterministicId } from '@instructure/ui-react-utils';
|
|
29
|
+
import { createChainedFunction } from '@instructure/ui-utils';
|
|
30
|
+
import { logError as error } from '@instructure/console';
|
|
31
|
+
import { AccessibleContent } from '@instructure/ui-a11y-content';
|
|
32
|
+
import { withStyle } from '@instructure/emotion';
|
|
33
|
+
import { Locale, DateTime, ApplyLocaleContext } from '@instructure/ui-i18n';
|
|
34
|
+
import generateStyle from "./styles.js";
|
|
35
|
+
import { Day } from "./Day/index.js";
|
|
36
|
+
import { allowedProps } from "./props.js";
|
|
37
|
+
import { IconButton } from '@instructure/ui-buttons/latest';
|
|
38
|
+
import { ChevronLeftInstUIIcon, ChevronRightInstUIIcon } from '@instructure/ui-icons';
|
|
39
|
+
import { SimpleSelect } from '@instructure/ui-simple-select/latest';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
category: components
|
|
44
|
+
---
|
|
45
|
+
**/
|
|
46
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
47
|
+
let Calendar = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_Calendar = class Calendar extends Component {
|
|
48
|
+
constructor(props) {
|
|
49
|
+
super(props);
|
|
50
|
+
this.ref = null;
|
|
51
|
+
this._weekdayHeaderIds = void 0;
|
|
52
|
+
this.handleRef = el => {
|
|
53
|
+
this.ref = el;
|
|
54
|
+
};
|
|
55
|
+
this.calculateState = (locale, timezone, currentDate) => {
|
|
56
|
+
const visibleMonth = this.props.visibleMonth || currentDate;
|
|
57
|
+
return {
|
|
58
|
+
visibleMonth: visibleMonth ? DateTime.parse(visibleMonth, locale, timezone) : DateTime.now(locale, timezone),
|
|
59
|
+
today: currentDate ? DateTime.parse(currentDate, locale, timezone) : DateTime.now(locale, timezone)
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
this.renderMonthNavigationButtons = () => {
|
|
63
|
+
const _this$props = this.props,
|
|
64
|
+
renderNextMonthButton = _this$props.renderNextMonthButton,
|
|
65
|
+
renderPrevMonthButton = _this$props.renderPrevMonthButton;
|
|
66
|
+
return {
|
|
67
|
+
prevButton: renderPrevMonthButton ? callRenderProp(renderPrevMonthButton) : _IconButton || (_IconButton = _jsx(IconButton, {
|
|
68
|
+
size: "small",
|
|
69
|
+
withBackground: false,
|
|
70
|
+
withBorder: false,
|
|
71
|
+
renderIcon: _jsx(ChevronLeftInstUIIcon, {
|
|
72
|
+
color: "baseColor"
|
|
73
|
+
}),
|
|
74
|
+
screenReaderLabel: "Previous month"
|
|
75
|
+
})),
|
|
76
|
+
nextButton: renderNextMonthButton ? callRenderProp(renderNextMonthButton) : _IconButton2 || (_IconButton2 = _jsx(IconButton, {
|
|
77
|
+
size: "small",
|
|
78
|
+
withBackground: false,
|
|
79
|
+
withBorder: false,
|
|
80
|
+
renderIcon: _jsx(ChevronRightInstUIIcon, {
|
|
81
|
+
color: "baseColor"
|
|
82
|
+
}),
|
|
83
|
+
screenReaderLabel: "Next month"
|
|
84
|
+
}))
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
this.handleMonthChange = direction => e => {
|
|
88
|
+
const _this$props2 = this.props,
|
|
89
|
+
onRequestRenderNextMonth = _this$props2.onRequestRenderNextMonth,
|
|
90
|
+
onRequestRenderPrevMonth = _this$props2.onRequestRenderPrevMonth;
|
|
91
|
+
const visibleMonth = this.state.visibleMonth;
|
|
92
|
+
const newDate = visibleMonth.clone();
|
|
93
|
+
if (direction === 'prev') {
|
|
94
|
+
if (!this.hasPrevMonth) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (onRequestRenderPrevMonth) {
|
|
98
|
+
onRequestRenderPrevMonth(e, newDate.subtract({
|
|
99
|
+
months: 1
|
|
100
|
+
}).format('YYYY-MM'));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
newDate.subtract({
|
|
104
|
+
months: 1
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
if (!this.hasNextMonth) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (onRequestRenderNextMonth) {
|
|
111
|
+
onRequestRenderNextMonth(e, newDate.add({
|
|
112
|
+
months: 1
|
|
113
|
+
}).format('YYYY-MM'));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
newDate.add({
|
|
117
|
+
months: 1
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
this.setState({
|
|
121
|
+
visibleMonth: newDate
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
this.handleYearChange = (e, year) => {
|
|
125
|
+
const withYearPicker = this.props.withYearPicker;
|
|
126
|
+
const visibleMonth = this.state.visibleMonth;
|
|
127
|
+
const yearNumber = Number(DateTime.parse(year, this.locale(), this.timezone()).locale('en').format('YYYY'));
|
|
128
|
+
const newDate = visibleMonth.clone();
|
|
129
|
+
if (withYearPicker !== null && withYearPicker !== void 0 && withYearPicker.onRequestYearChange) {
|
|
130
|
+
withYearPicker.onRequestYearChange(e, yearNumber);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
newDate.year(yearNumber);
|
|
134
|
+
this.setState({
|
|
135
|
+
visibleMonth: newDate
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
// date is returned as an ISO string, like 2021-09-14T22:00:00.000Z
|
|
139
|
+
this.handleDayClick = (event, {
|
|
140
|
+
date
|
|
141
|
+
}) => {
|
|
142
|
+
if (this.props.onDateSelected) {
|
|
143
|
+
const parsedDate = DateTime.parse(date, this.locale(), this.timezone());
|
|
144
|
+
this.props.onDateSelected(parsedDate.toISOString(), parsedDate, event);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
this._weekdayHeaderIds = (this.props.renderWeekdayLabels || this.defaultWeekdays).reduce((ids, _label, i) => {
|
|
148
|
+
return {
|
|
149
|
+
...ids,
|
|
150
|
+
[i]: this.props.deterministicId('weekday-header')
|
|
151
|
+
};
|
|
152
|
+
}, {});
|
|
153
|
+
this.state = this.calculateState(this.locale(), this.timezone(), props.currentDate);
|
|
154
|
+
}
|
|
155
|
+
componentDidMount() {
|
|
156
|
+
var _this$props$makeStyle, _this$props3;
|
|
157
|
+
(_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
|
|
158
|
+
}
|
|
159
|
+
componentDidUpdate(prevProps) {
|
|
160
|
+
var _this$props$makeStyle2, _this$props4;
|
|
161
|
+
(_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
|
|
162
|
+
const isUpdated = prevProps.locale !== this.props.locale || prevProps.timezone !== this.props.timezone || prevProps.visibleMonth !== this.props.visibleMonth;
|
|
163
|
+
if (isUpdated) {
|
|
164
|
+
this.setState(() => {
|
|
165
|
+
return {
|
|
166
|
+
...this.calculateState(this.locale(), this.timezone(), this.props.currentDate)
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
get role() {
|
|
172
|
+
return this.props.role === 'listbox' ? this.props.role : void 0;
|
|
173
|
+
}
|
|
174
|
+
get hasPrevMonth() {
|
|
175
|
+
// this is needed for locales that doesn't use the latin script for numbers e.g.: arabic
|
|
176
|
+
const yearNumber = Number(this.state.visibleMonth.clone().locale('en').subtract({
|
|
177
|
+
months: 1
|
|
178
|
+
}).format('YYYY'));
|
|
179
|
+
return !this.props.withYearPicker || this.props.withYearPicker && yearNumber >= this.props.withYearPicker.startYear;
|
|
180
|
+
}
|
|
181
|
+
get hasNextMonth() {
|
|
182
|
+
// this is needed for locales that doesn't use the latin script for numbers e.g.: arabic
|
|
183
|
+
const yearNumber = Number(this.state.visibleMonth.clone().locale('en').add({
|
|
184
|
+
months: 1
|
|
185
|
+
}).format('YYYY'));
|
|
186
|
+
return !this.props.withYearPicker || this.props.withYearPicker && yearNumber <= this.props.withYearPicker.endYear;
|
|
187
|
+
}
|
|
188
|
+
renderHeader() {
|
|
189
|
+
const _this$props5 = this.props,
|
|
190
|
+
renderNavigationLabel = _this$props5.renderNavigationLabel,
|
|
191
|
+
styles = _this$props5.styles,
|
|
192
|
+
withYearPicker = _this$props5.withYearPicker;
|
|
193
|
+
const visibleMonth = this.state.visibleMonth;
|
|
194
|
+
const _this$renderMonthNavi = this.renderMonthNavigationButtons(),
|
|
195
|
+
prevButton = _this$renderMonthNavi.prevButton,
|
|
196
|
+
nextButton = _this$renderMonthNavi.nextButton;
|
|
197
|
+
const cloneButton = (button, onClick) => safeCloneElement(button, {
|
|
198
|
+
onClick: createChainedFunction(button.props.onClick, onClick)
|
|
199
|
+
});
|
|
200
|
+
const style = [styles === null || styles === void 0 ? void 0 : styles.navigation, ...(prevButton || nextButton ? [styles === null || styles === void 0 ? void 0 : styles.navigationWithButtons] : [])];
|
|
201
|
+
const yearList = [];
|
|
202
|
+
if (withYearPicker) {
|
|
203
|
+
const startYear = withYearPicker.startYear,
|
|
204
|
+
endYear = withYearPicker.endYear;
|
|
205
|
+
for (let year = endYear; year >= startYear; year--) {
|
|
206
|
+
// add the years to the list with the correct locale
|
|
207
|
+
yearList.push(DateTime.parse(year.toString(), this.locale(), this.timezone()).format('YYYY'));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return _jsxs("div", {
|
|
211
|
+
children: [_jsxs("div", {
|
|
212
|
+
css: style,
|
|
213
|
+
children: [prevButton && cloneButton(prevButton, this.handleMonthChange('prev')), renderNavigationLabel ? callRenderProp(renderNavigationLabel) : _jsxs("span", {
|
|
214
|
+
children: [_jsx("div", {
|
|
215
|
+
children: visibleMonth.format('MMMM')
|
|
216
|
+
}), !withYearPicker ? _jsx("div", {
|
|
217
|
+
children: visibleMonth.format('YYYY')
|
|
218
|
+
}) : null]
|
|
219
|
+
}), nextButton && cloneButton(nextButton, this.handleMonthChange('next'))]
|
|
220
|
+
}), withYearPicker ? _jsx("div", {
|
|
221
|
+
css: styles === null || styles === void 0 ? void 0 : styles.yearPicker,
|
|
222
|
+
children: _jsx(SimpleSelect, {
|
|
223
|
+
width: "90px",
|
|
224
|
+
renderLabel: "",
|
|
225
|
+
placeholder: "--",
|
|
226
|
+
assistiveText: withYearPicker.screenReaderLabel,
|
|
227
|
+
value: visibleMonth.format('YYYY'),
|
|
228
|
+
onChange: (e, {
|
|
229
|
+
value
|
|
230
|
+
}) => this.handleYearChange(e, `${value}`),
|
|
231
|
+
children: yearList.map(year => _jsx(SimpleSelect.Option, {
|
|
232
|
+
id: `opt-${year}`,
|
|
233
|
+
value: year,
|
|
234
|
+
children: `${year}`
|
|
235
|
+
}, year))
|
|
236
|
+
})
|
|
237
|
+
}) : null]
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
renderBody() {
|
|
241
|
+
return _jsxs("table", {
|
|
242
|
+
role: this.role,
|
|
243
|
+
children: [_jsx("thead", {
|
|
244
|
+
children: this.renderWeekdayHeaders()
|
|
245
|
+
}), _jsx("tbody", {
|
|
246
|
+
children: this.renderDays()
|
|
247
|
+
})]
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
renderWeekdayHeaders() {
|
|
251
|
+
const styles = this.props.styles;
|
|
252
|
+
const renderWeekdayLabels = this.props.renderWeekdayLabels || this.defaultWeekdays;
|
|
253
|
+
const length = renderWeekdayLabels.length;
|
|
254
|
+
error(length === 7, `[Calendar] \`renderWeekdayLabels\` should be an array with 7 labels (one for each weekday). ${length} provided.`);
|
|
255
|
+
return _jsx("tr", {
|
|
256
|
+
children: renderWeekdayLabels.map((label, i) => {
|
|
257
|
+
return _jsx("th", {
|
|
258
|
+
scope: "col",
|
|
259
|
+
css: styles === null || styles === void 0 ? void 0 : styles.weekdayHeader,
|
|
260
|
+
id: this._weekdayHeaderIds[i],
|
|
261
|
+
children: callRenderProp(label)
|
|
262
|
+
}, i);
|
|
263
|
+
})
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
get defaultWeekdays() {
|
|
267
|
+
const shortDayNames = DateTime.getLocalDayNamesOfTheWeek(this.locale(), 'short');
|
|
268
|
+
const longDayNames = DateTime.getLocalDayNamesOfTheWeek(this.locale(), 'long');
|
|
269
|
+
return [_jsx(AccessibleContent, {
|
|
270
|
+
alt: longDayNames[0],
|
|
271
|
+
children: shortDayNames[0]
|
|
272
|
+
}, 1), _jsx(AccessibleContent, {
|
|
273
|
+
alt: longDayNames[1],
|
|
274
|
+
children: shortDayNames[1]
|
|
275
|
+
}, 2), _jsx(AccessibleContent, {
|
|
276
|
+
alt: longDayNames[2],
|
|
277
|
+
children: shortDayNames[2]
|
|
278
|
+
}, 3), _jsx(AccessibleContent, {
|
|
279
|
+
alt: longDayNames[3],
|
|
280
|
+
children: shortDayNames[3]
|
|
281
|
+
}, 4), _jsx(AccessibleContent, {
|
|
282
|
+
alt: longDayNames[4],
|
|
283
|
+
children: shortDayNames[4]
|
|
284
|
+
}, 5), _jsx(AccessibleContent, {
|
|
285
|
+
alt: longDayNames[5],
|
|
286
|
+
children: shortDayNames[5]
|
|
287
|
+
}, 6), _jsx(AccessibleContent, {
|
|
288
|
+
alt: longDayNames[6],
|
|
289
|
+
children: shortDayNames[6]
|
|
290
|
+
}, 7)];
|
|
291
|
+
}
|
|
292
|
+
renderDays() {
|
|
293
|
+
const children = this.props.children;
|
|
294
|
+
const childrenArr = Children.toArray(children ? children : this.renderDefaultdays());
|
|
295
|
+
const length = childrenArr.length;
|
|
296
|
+
const role = this.role === 'listbox' ? 'presentation' : void 0;
|
|
297
|
+
error(length === Calendar.DAY_COUNT, `[Calendar] should have exactly ${Calendar.DAY_COUNT} children. ${length} provided.`);
|
|
298
|
+
return childrenArr.reduce((days, day, i) => {
|
|
299
|
+
const index = Math.floor(i / 7);
|
|
300
|
+
if (!days[index]) days.push([]);
|
|
301
|
+
days[index].push(day);
|
|
302
|
+
return days; // 7xN 2D array of `Day`s
|
|
303
|
+
}, []).map(row => _jsx("tr", {
|
|
304
|
+
role: role,
|
|
305
|
+
children: row.map((day, i) => _jsx("td", {
|
|
306
|
+
role: role,
|
|
307
|
+
children: role === 'presentation' ? safeCloneElement(day, {
|
|
308
|
+
'aria-describedby': this._weekdayHeaderIds[i]
|
|
309
|
+
}) : day
|
|
310
|
+
}, day.props.date))
|
|
311
|
+
}, `row${row[0].props.date}`));
|
|
312
|
+
}
|
|
313
|
+
locale() {
|
|
314
|
+
if (this.props.locale) {
|
|
315
|
+
return this.props.locale;
|
|
316
|
+
} else if (this.context && this.context.locale) {
|
|
317
|
+
return this.context.locale;
|
|
318
|
+
}
|
|
319
|
+
return Locale.browserLocale();
|
|
320
|
+
}
|
|
321
|
+
timezone() {
|
|
322
|
+
if (this.props.timezone) {
|
|
323
|
+
return this.props.timezone;
|
|
324
|
+
} else if (this.context && this.context.timezone) {
|
|
325
|
+
return this.context.timezone;
|
|
326
|
+
}
|
|
327
|
+
return DateTime.browserTimeZone();
|
|
328
|
+
}
|
|
329
|
+
isDisabledDate(date) {
|
|
330
|
+
const disabledDates = this.props.disabledDates;
|
|
331
|
+
if (!disabledDates) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
if (Array.isArray(disabledDates)) {
|
|
335
|
+
for (const aDisabledDate of disabledDates) {
|
|
336
|
+
if (date.isSame(aDisabledDate, 'day')) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
return disabledDates(date.toISOString());
|
|
343
|
+
}
|
|
344
|
+
renderDefaultdays() {
|
|
345
|
+
const selectedDate = this.props.selectedDate;
|
|
346
|
+
const _this$state = this.state,
|
|
347
|
+
visibleMonth = _this$state.visibleMonth,
|
|
348
|
+
today = _this$state.today;
|
|
349
|
+
// Sets it to the first local day of the week counting back from the start of the month.
|
|
350
|
+
// Note that first day depends on the locale, e.g. it's Sunday in the US and
|
|
351
|
+
// Monday in most of the EU.
|
|
352
|
+
const currDate = DateTime.getFirstDayOfWeek(visibleMonth.clone().startOf('month'));
|
|
353
|
+
const arr = [];
|
|
354
|
+
for (let i = 0; i < Calendar.DAY_COUNT; i++) {
|
|
355
|
+
// This workaround is needed because moment's `.add({days: 1})` function has a bug that happens when the date added lands perfectly onto the DST cutoff,
|
|
356
|
+
// in these cases adding 1 day results in 23 hours added instead,
|
|
357
|
+
// so `moment.tz('2024-09-07T00:00:00', 'America/Santiago').add({days: 1})` results
|
|
358
|
+
// in "Sat Sep 07 2024 23:00:00 GMT-0400" instead of "Sun Sep 08 2024 00:00:00 GMT-0400".
|
|
359
|
+
// which would cause duplicate dates in the calendar.
|
|
360
|
+
// More info on the bug: https://github.com/moment/moment/issues/4743
|
|
361
|
+
// Please note that this causes one hour of time difference in the affected timezones/dates and to
|
|
362
|
+
// fully solve this bug we need to change to something like luxon which handles this properly
|
|
363
|
+
if (currDate.clone().format('HH') === '23') {
|
|
364
|
+
arr.push(currDate.clone().add({
|
|
365
|
+
hours: 1
|
|
366
|
+
}));
|
|
367
|
+
} else {
|
|
368
|
+
arr.push(currDate.clone());
|
|
369
|
+
}
|
|
370
|
+
currDate.add({
|
|
371
|
+
days: 1
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
return arr.map(date => {
|
|
375
|
+
const dateStr = date.toISOString();
|
|
376
|
+
return _jsx(Calendar.Day, {
|
|
377
|
+
date: dateStr,
|
|
378
|
+
isSelected: selectedDate ? date.isSame(selectedDate, 'day') : false,
|
|
379
|
+
isToday: date.isSame(today, 'day'),
|
|
380
|
+
isOutsideMonth: !date.isSame(visibleMonth, 'month'),
|
|
381
|
+
label: date.format('D MMMM YYYY') // used by screen readers
|
|
382
|
+
,
|
|
383
|
+
onClick: this.handleDayClick,
|
|
384
|
+
interaction: this.isDisabledDate(date) ? 'disabled' : 'enabled',
|
|
385
|
+
children: date.format('DD')
|
|
386
|
+
}, dateStr);
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
render() {
|
|
390
|
+
const passthroughProps = View.omitViewProps(omitProps(this.props, Calendar.allowedProps), Calendar);
|
|
391
|
+
return _jsxs(View, {
|
|
392
|
+
...passthroughProps,
|
|
393
|
+
as: this.props.as,
|
|
394
|
+
display: "inline-block",
|
|
395
|
+
padding: "small",
|
|
396
|
+
background: "primary",
|
|
397
|
+
elementRef: this.handleRef,
|
|
398
|
+
"data-cid": "Calendar",
|
|
399
|
+
children: [this.renderHeader(), this.renderBody()]
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}, _Calendar.displayName = "Calendar", _Calendar.componentId = 'Calendar', _Calendar.contextType = ApplyLocaleContext, _Calendar.Day = Day, _Calendar.DAY_COUNT = 42, _Calendar.allowedProps = allowedProps, _Calendar.defaultProps = {
|
|
403
|
+
as: 'span',
|
|
404
|
+
role: 'table'
|
|
405
|
+
}, _Calendar)) || _class) || _class);
|
|
406
|
+
export default Calendar;
|
|
407
|
+
export { Calendar };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const allowedProps = ['as', 'children', 'currentDate', 'disabledDates', 'locale', 'onDateSelected', 'onRequestRenderNextMonth', 'onRequestRenderPrevMonth', 'renderNavigationLabel', 'renderNextMonthButton', 'renderPrevMonthButton', 'renderWeekdayLabels', 'role', 'selectedDate', 'timezone', 'visibleMonth'];
|
|
26
|
+
export { allowedProps };
|