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