@instructure/ui-calendar 10.16.1-snapshot-0 → 10.16.1
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 +1 -1
- package/es/Calendar/Day/__new-tests__/Day.test.js +89 -71
- package/es/Calendar/Day/index.js +13 -9
- package/es/Calendar/__new-tests__/Calendar.test.js +96 -62
- package/es/Calendar/index.js +94 -74
- package/lib/Calendar/Day/__new-tests__/Day.test.js +96 -78
- package/lib/Calendar/Day/index.js +12 -8
- package/lib/Calendar/__new-tests__/Calendar.test.js +112 -79
- package/lib/Calendar/index.js +93 -74
- package/package.json +20 -20
- package/src/Calendar/Day/__new-tests__/Day.test.tsx +16 -17
- package/src/Calendar/Day/index.tsx +1 -2
- package/src/Calendar/__new-tests__/Calendar.test.tsx +4 -8
- package/src/Calendar/index.tsx +4 -6
- package/src/Calendar/props.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Calendar/Day/__new-tests__/Day.test.d.ts.map +1 -1
- package/types/Calendar/Day/index.d.ts +1 -3
- package/types/Calendar/Day/index.d.ts.map +1 -1
- package/types/Calendar/index.d.ts +8 -10
- package/types/Calendar/index.d.ts.map +1 -1
- package/types/Calendar/props.d.ts +1 -1
- package/types/Calendar/props.d.ts.map +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
6
|
var _vitest = require("vitest");
|
|
8
7
|
require("@testing-library/jest-dom");
|
|
@@ -10,6 +9,7 @@ var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yT
|
|
|
10
9
|
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
11
10
|
var _Calendar5 = _interopRequireDefault(require("../__examples__/Calendar.examples"));
|
|
12
11
|
var _index = _interopRequireDefault(require("../index"));
|
|
12
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
13
13
|
var _Calendar, _Calendar2, _Calendar3, _Calendar4, _span, _button, _button2, _button3, _button4, _button5, _button6;
|
|
14
14
|
/*
|
|
15
15
|
* The MIT License (MIT)
|
|
@@ -40,12 +40,12 @@ const generateDays = (count = _index.default.DAY_COUNT) => {
|
|
|
40
40
|
const days = [];
|
|
41
41
|
const date = new Date('2019-07-28');
|
|
42
42
|
while (days.length < count) {
|
|
43
|
-
days.push(
|
|
44
|
-
key: date.toISOString(),
|
|
43
|
+
days.push((0, _jsxRuntime.jsx)(_index.default.Day, {
|
|
45
44
|
date: date.toISOString(),
|
|
46
45
|
label: date.toISOString(),
|
|
47
|
-
isOutsideMonth: date.getMonth() !== 7
|
|
48
|
-
|
|
46
|
+
isOutsideMonth: date.getMonth() !== 7,
|
|
47
|
+
children: date.getDate()
|
|
48
|
+
}, date.toISOString()));
|
|
49
49
|
date.setDate(date.getDate() + 1);
|
|
50
50
|
}
|
|
51
51
|
return days;
|
|
@@ -64,18 +64,18 @@ describe('<Calendar />', () => {
|
|
|
64
64
|
});
|
|
65
65
|
describe('with minimal config', () => {
|
|
66
66
|
it('should render 44 buttons without config', async () => {
|
|
67
|
-
(0,
|
|
67
|
+
(0, _react.render)(_Calendar || (_Calendar = (0, _jsxRuntime.jsx)(_index.default, {})));
|
|
68
68
|
const buttons = document.getElementsByTagName('button');
|
|
69
69
|
expect(buttons.length).toEqual(44);
|
|
70
70
|
});
|
|
71
71
|
it('should render proper week names by default', async () => {
|
|
72
|
-
const _render = (0,
|
|
72
|
+
const _render = (0, _react.render)(_Calendar2 || (_Calendar2 = (0, _jsxRuntime.jsx)(_index.default, {}))),
|
|
73
73
|
container = _render.container;
|
|
74
74
|
const thead = container.querySelector('thead');
|
|
75
75
|
expect(thead).toHaveTextContent('SundaySuMondayMoTuesdayTuWednesdayWeThursdayThFridayFrSaturdaySa');
|
|
76
76
|
});
|
|
77
77
|
it('should render proper week names if locale is set', async () => {
|
|
78
|
-
const _render2 = (0,
|
|
78
|
+
const _render2 = (0, _react.render)(_Calendar3 || (_Calendar3 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
79
79
|
locale: "hu"
|
|
80
80
|
}))),
|
|
81
81
|
container = _render2.container;
|
|
@@ -83,7 +83,7 @@ describe('<Calendar />', () => {
|
|
|
83
83
|
expect(thead).toHaveTextContent('hétfőhkeddkszerdaszecsütörtökcspéntekpszombatszovasárnapv');
|
|
84
84
|
});
|
|
85
85
|
it('should disable days properly', async () => {
|
|
86
|
-
const _render3 = (0,
|
|
86
|
+
const _render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
87
87
|
currentDate: "2023-12-15",
|
|
88
88
|
disabledDates: ['2023-12-22', '2023-12-12', '2023-12-11']
|
|
89
89
|
})),
|
|
@@ -96,11 +96,11 @@ describe('<Calendar />', () => {
|
|
|
96
96
|
});
|
|
97
97
|
it('should indicate selected day', async () => {
|
|
98
98
|
var _screen$queryByText, _screen$queryByText$p;
|
|
99
|
-
(0,
|
|
99
|
+
(0, _react.render)(_Calendar4 || (_Calendar4 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
100
100
|
currentDate: "2023-12-15",
|
|
101
101
|
selectedDate: "2023-12-22"
|
|
102
102
|
})));
|
|
103
|
-
const selectedDay = (_screen$queryByText =
|
|
103
|
+
const selectedDay = (_screen$queryByText = _react.screen.queryByText('22 December 2023')) === null || _screen$queryByText === void 0 ? void 0 : (_screen$queryByText$p = _screen$queryByText.parentElement) === null || _screen$queryByText$p === void 0 ? void 0 : _screen$queryByText$p.parentElement;
|
|
104
104
|
expect(selectedDay).toBeDefined();
|
|
105
105
|
if (selectedDay) {
|
|
106
106
|
var _window$getComputedSt;
|
|
@@ -109,25 +109,28 @@ describe('<Calendar />', () => {
|
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
it('should render children', async () => {
|
|
112
|
-
const _render4 = (0,
|
|
113
|
-
renderWeekdayLabels: weekdayLabels
|
|
114
|
-
|
|
112
|
+
const _render4 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
113
|
+
renderWeekdayLabels: weekdayLabels,
|
|
114
|
+
children: generateDays()
|
|
115
|
+
})),
|
|
115
116
|
container = _render4.container;
|
|
116
|
-
const calendarDays = container.querySelectorAll('span[class
|
|
117
|
+
const calendarDays = container.querySelectorAll('span[class*="-calendarDay__day"]');
|
|
117
118
|
expect(calendarDays.length).toEqual(_index.default.DAY_COUNT);
|
|
118
119
|
});
|
|
119
120
|
it(`should warn if the correct number of children are not provided`, async () => {
|
|
120
121
|
const count = _index.default.DAY_COUNT - 1;
|
|
121
|
-
(0,
|
|
122
|
-
renderWeekdayLabels: weekdayLabels
|
|
123
|
-
|
|
122
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
123
|
+
renderWeekdayLabels: weekdayLabels,
|
|
124
|
+
children: generateDays(count)
|
|
125
|
+
}));
|
|
124
126
|
const expectedErrorMessage = `should have exactly ${_index.default.DAY_COUNT} children. ${count} provided.`;
|
|
125
127
|
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
126
128
|
});
|
|
127
129
|
it('should render weekday labels', async () => {
|
|
128
|
-
const _render5 = (0,
|
|
129
|
-
renderWeekdayLabels: weekdayLabels
|
|
130
|
-
|
|
130
|
+
const _render5 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
131
|
+
renderWeekdayLabels: weekdayLabels,
|
|
132
|
+
children: generateDays()
|
|
133
|
+
})),
|
|
131
134
|
container = _render5.container,
|
|
132
135
|
rerender = _render5.rerender;
|
|
133
136
|
const originalHeaders = container.querySelectorAll('th');
|
|
@@ -138,9 +141,10 @@ describe('<Calendar />', () => {
|
|
|
138
141
|
const functionalWeekdayLabels = [() => 'Sx', () => 'Mx', () => 'Tx', () => 'Wx', () => 'Tx', () => 'Fx', () => 'Sx'];
|
|
139
142
|
|
|
140
143
|
// Set prop: renderWeekdayLabels
|
|
141
|
-
rerender(
|
|
142
|
-
renderWeekdayLabels: functionalWeekdayLabels
|
|
143
|
-
|
|
144
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
145
|
+
renderWeekdayLabels: functionalWeekdayLabels,
|
|
146
|
+
children: generateDays()
|
|
147
|
+
}));
|
|
144
148
|
const updatedHeaders = container.querySelectorAll('th');
|
|
145
149
|
expect(updatedHeaders.length).toEqual(7);
|
|
146
150
|
functionalWeekdayLabels.forEach((functionalLabel, i) => {
|
|
@@ -148,16 +152,18 @@ describe('<Calendar />', () => {
|
|
|
148
152
|
});
|
|
149
153
|
});
|
|
150
154
|
it('should warn if 7 weekday labels are not provided', async () => {
|
|
151
|
-
(0,
|
|
152
|
-
renderWeekdayLabels: []
|
|
153
|
-
|
|
155
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
156
|
+
renderWeekdayLabels: [],
|
|
157
|
+
children: generateDays()
|
|
158
|
+
}));
|
|
154
159
|
const expectedErrorMessage = '`renderWeekdayLabels` should be an array with 7 labels (one for each weekday). 0 provided.';
|
|
155
160
|
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
156
161
|
});
|
|
157
162
|
it('should format the weekday labels and days correctly', async () => {
|
|
158
|
-
const _render6 = (0,
|
|
159
|
-
renderWeekdayLabels: weekdayLabels
|
|
160
|
-
|
|
163
|
+
const _render6 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
164
|
+
renderWeekdayLabels: weekdayLabels,
|
|
165
|
+
children: generateDays()
|
|
166
|
+
})),
|
|
161
167
|
container = _render6.container;
|
|
162
168
|
const headerRow = container.querySelectorAll('thead > tr');
|
|
163
169
|
expect(headerRow.length).toEqual(1);
|
|
@@ -171,82 +177,107 @@ describe('<Calendar />', () => {
|
|
|
171
177
|
}
|
|
172
178
|
});
|
|
173
179
|
it('should render navigation label', async () => {
|
|
174
|
-
const navLabel = _span || (_span =
|
|
175
|
-
|
|
180
|
+
const navLabel = _span || (_span = (0, _jsxRuntime.jsxs)("span", {
|
|
181
|
+
children: [(0, _jsxRuntime.jsx)("div", {
|
|
182
|
+
children: "March"
|
|
183
|
+
}), (0, _jsxRuntime.jsx)("div", {
|
|
184
|
+
children: "2019"
|
|
185
|
+
})]
|
|
186
|
+
}));
|
|
187
|
+
const _render7 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
176
188
|
renderWeekdayLabels: weekdayLabels,
|
|
177
|
-
renderNavigationLabel: navLabel
|
|
178
|
-
|
|
189
|
+
renderNavigationLabel: navLabel,
|
|
190
|
+
children: generateDays()
|
|
191
|
+
})),
|
|
179
192
|
rerender = _render7.rerender;
|
|
180
|
-
const month =
|
|
181
|
-
const year =
|
|
193
|
+
const month = _react.screen.getByText('March');
|
|
194
|
+
const year = _react.screen.getByText('2019');
|
|
182
195
|
expect(month).toBeInTheDocument();
|
|
183
196
|
expect(year).toBeInTheDocument();
|
|
184
197
|
|
|
185
198
|
// Set prop: renderNavigationLabel
|
|
186
|
-
rerender(
|
|
199
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
187
200
|
renderWeekdayLabels: weekdayLabels,
|
|
188
|
-
renderNavigationLabel: () => navLabel
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
201
|
+
renderNavigationLabel: () => navLabel,
|
|
202
|
+
children: generateDays()
|
|
203
|
+
}));
|
|
204
|
+
const updatedMonth = _react.screen.getByText('March');
|
|
205
|
+
const updatedYear = _react.screen.getByText('2019');
|
|
192
206
|
expect(updatedMonth).toBeInTheDocument();
|
|
193
207
|
expect(updatedYear).toBeInTheDocument();
|
|
194
208
|
});
|
|
195
209
|
it('should render next and prev buttons', async () => {
|
|
196
|
-
const _render8 = (0,
|
|
197
|
-
renderWeekdayLabels: weekdayLabels
|
|
198
|
-
|
|
210
|
+
const _render8 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
211
|
+
renderWeekdayLabels: weekdayLabels,
|
|
212
|
+
children: generateDays()
|
|
213
|
+
})),
|
|
199
214
|
rerender = _render8.rerender;
|
|
200
|
-
const defaultPrevButton =
|
|
201
|
-
const defaultNextButton =
|
|
215
|
+
const defaultPrevButton = _react.screen.getByText('Previous month');
|
|
216
|
+
const defaultNextButton = _react.screen.getByText('Next month');
|
|
202
217
|
expect(defaultPrevButton).toBeInTheDocument();
|
|
203
218
|
expect(defaultNextButton).toBeInTheDocument();
|
|
204
|
-
rerender(
|
|
219
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
205
220
|
renderWeekdayLabels: weekdayLabels,
|
|
206
|
-
renderPrevMonthButton: _button || (_button =
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
221
|
+
renderPrevMonthButton: _button || (_button = (0, _jsxRuntime.jsx)("button", {
|
|
222
|
+
children: "test-prev"
|
|
223
|
+
})),
|
|
224
|
+
renderNextMonthButton: _button2 || (_button2 = (0, _jsxRuntime.jsx)("button", {
|
|
225
|
+
children: "test-next"
|
|
226
|
+
})),
|
|
227
|
+
children: generateDays()
|
|
228
|
+
}));
|
|
229
|
+
const customPrevButton = _react.screen.getByText('test-prev');
|
|
230
|
+
const customNextButton = _react.screen.getByText('test-next');
|
|
211
231
|
expect(customPrevButton).toBeInTheDocument();
|
|
212
232
|
expect(customNextButton).toBeInTheDocument();
|
|
213
|
-
rerender(
|
|
233
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
214
234
|
renderWeekdayLabels: weekdayLabels,
|
|
215
|
-
renderPrevMonthButton: () => _button3 || (_button3 =
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
235
|
+
renderPrevMonthButton: () => _button3 || (_button3 = (0, _jsxRuntime.jsx)("button", {
|
|
236
|
+
children: "func-test-prev"
|
|
237
|
+
})),
|
|
238
|
+
renderNextMonthButton: () => _button4 || (_button4 = (0, _jsxRuntime.jsx)("button", {
|
|
239
|
+
children: "func-test-next"
|
|
240
|
+
})),
|
|
241
|
+
children: generateDays()
|
|
242
|
+
}));
|
|
243
|
+
const funcPrevButton = _react.screen.getByText('func-test-prev');
|
|
244
|
+
const funcNextButton = _react.screen.getByText('func-test-next');
|
|
220
245
|
expect(funcPrevButton).toBeInTheDocument();
|
|
221
246
|
expect(funcNextButton).toBeInTheDocument();
|
|
222
247
|
});
|
|
223
248
|
it('should call onRequestRenderNextMonth and onRequestRenderPrevMonth', async () => {
|
|
224
249
|
const onRequestRenderPrevMonth = _vitest.vi.fn();
|
|
225
250
|
const onRequestRenderNextMonth = _vitest.vi.fn();
|
|
226
|
-
(0,
|
|
251
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
227
252
|
renderWeekdayLabels: weekdayLabels,
|
|
228
|
-
renderPrevMonthButton: _button5 || (_button5 =
|
|
229
|
-
|
|
253
|
+
renderPrevMonthButton: _button5 || (_button5 = (0, _jsxRuntime.jsx)("button", {
|
|
254
|
+
children: "prev month"
|
|
255
|
+
})),
|
|
256
|
+
renderNextMonthButton: _button6 || (_button6 = (0, _jsxRuntime.jsx)("button", {
|
|
257
|
+
children: "next month"
|
|
258
|
+
})),
|
|
230
259
|
onRequestRenderPrevMonth: onRequestRenderPrevMonth,
|
|
231
|
-
onRequestRenderNextMonth: onRequestRenderNextMonth
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
260
|
+
onRequestRenderNextMonth: onRequestRenderNextMonth,
|
|
261
|
+
children: generateDays()
|
|
262
|
+
}));
|
|
263
|
+
const prevButton = _react.screen.getByText('prev month');
|
|
264
|
+
const nextButton = _react.screen.getByText('next month');
|
|
235
265
|
expect(onRequestRenderPrevMonth).not.toHaveBeenCalled();
|
|
236
266
|
expect(onRequestRenderNextMonth).not.toHaveBeenCalled();
|
|
237
267
|
await _userEvent.default.click(prevButton);
|
|
238
268
|
await _userEvent.default.click(nextButton);
|
|
239
|
-
await (0,
|
|
269
|
+
await (0, _react.waitFor)(() => {
|
|
240
270
|
expect(onRequestRenderPrevMonth).toHaveBeenCalledTimes(1);
|
|
241
271
|
expect(onRequestRenderNextMonth).toHaveBeenCalledTimes(1);
|
|
242
272
|
});
|
|
243
273
|
});
|
|
244
274
|
describe('when role="listbox"', () => {
|
|
245
275
|
it('should set role="listbox" on table root and role="presentation" on the correct elements', async () => {
|
|
246
|
-
const _render9 = (0,
|
|
276
|
+
const _render9 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
247
277
|
renderWeekdayLabels: weekdayLabels,
|
|
248
|
-
role: "listbox"
|
|
249
|
-
|
|
278
|
+
role: "listbox",
|
|
279
|
+
children: generateDays()
|
|
280
|
+
})),
|
|
250
281
|
container = _render9.container;
|
|
251
282
|
const table = container.querySelector('table');
|
|
252
283
|
expect(table).toHaveAttribute('role', 'listbox');
|
|
@@ -260,26 +291,28 @@ describe('<Calendar />', () => {
|
|
|
260
291
|
}
|
|
261
292
|
});
|
|
262
293
|
it("should link each day with it's weekday header via `aria-describedby`", async () => {
|
|
263
|
-
const _render10 = (0,
|
|
294
|
+
const _render10 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
264
295
|
renderWeekdayLabels: weekdayLabels,
|
|
265
|
-
role: "listbox"
|
|
266
|
-
|
|
296
|
+
role: "listbox",
|
|
297
|
+
children: generateDays()
|
|
298
|
+
})),
|
|
267
299
|
container = _render10.container;
|
|
268
300
|
const days = container.querySelectorAll('tbody > tr > td');
|
|
269
301
|
const headers = container.querySelectorAll('th');
|
|
270
302
|
days.forEach((dayTd, i) => {
|
|
271
303
|
const index = i % 7;
|
|
272
|
-
const day = dayTd.querySelector('span[class
|
|
304
|
+
const day = dayTd.querySelector('span[class*="-calendarDay"]');
|
|
273
305
|
expect(day).toHaveAttribute('aria-describedby', headers[index].getAttribute('id'));
|
|
274
306
|
});
|
|
275
307
|
});
|
|
276
308
|
});
|
|
277
309
|
it('should render root as designated by the `as` prop', async () => {
|
|
278
|
-
(0,
|
|
310
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
279
311
|
renderWeekdayLabels: weekdayLabels,
|
|
280
|
-
as: "ul"
|
|
281
|
-
|
|
282
|
-
|
|
312
|
+
as: "ul",
|
|
313
|
+
children: generateDays()
|
|
314
|
+
}));
|
|
315
|
+
const calendar = _react.screen.getByRole('list');
|
|
283
316
|
expect(calendar.tagName).toBe('UL');
|
|
284
317
|
expect(calendar).toHaveTextContent(weekdayLabels.join(''));
|
|
285
318
|
});
|
|
@@ -287,7 +320,7 @@ describe('<Calendar />', () => {
|
|
|
287
320
|
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.default, _Calendar5.default);
|
|
288
321
|
for (const component of generatedComponents) {
|
|
289
322
|
it(component.description, async () => {
|
|
290
|
-
const _render11 = (0,
|
|
323
|
+
const _render11 = (0, _react.render)(component.content),
|
|
291
324
|
container = _render11.container;
|
|
292
325
|
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
293
326
|
expect(axeCheck).toBe(true);
|
package/lib/Calendar/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.Calendar = void 0;
|
|
9
|
-
var _react =
|
|
8
|
+
var _react = require("react");
|
|
10
9
|
var _View = require("@instructure/ui-view/lib/View");
|
|
11
10
|
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
12
11
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
@@ -28,6 +27,7 @@ var _IconButton3 = require("@instructure/ui-buttons/lib/IconButton");
|
|
|
28
27
|
var _IconArrowOpenStartSolid = require("@instructure/ui-icons/lib/IconArrowOpenStartSolid.js");
|
|
29
28
|
var _IconArrowOpenEndSolid = require("@instructure/ui-icons/lib/IconArrowOpenEndSolid.js");
|
|
30
29
|
var _SimpleSelect = require("@instructure/ui-simple-select/lib/SimpleSelect");
|
|
30
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
31
31
|
var _dec, _dec2, _class, _Calendar, _IconButton, _IconButton2;
|
|
32
32
|
/*
|
|
33
33
|
* The MIT License (MIT)
|
|
@@ -52,7 +52,6 @@ var _dec, _dec2, _class, _Calendar, _IconButton, _IconButton2;
|
|
|
52
52
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
53
53
|
* SOFTWARE.
|
|
54
54
|
*/
|
|
55
|
-
/** @jsx jsx */
|
|
56
55
|
/**
|
|
57
56
|
---
|
|
58
57
|
category: components
|
|
@@ -83,20 +82,20 @@ let Calendar = exports.Calendar = (_dec = (0, _emotion.withStyle)(_styles.defaul
|
|
|
83
82
|
renderNextMonthButton = _this$props.renderNextMonthButton,
|
|
84
83
|
renderPrevMonthButton = _this$props.renderPrevMonthButton;
|
|
85
84
|
return {
|
|
86
|
-
prevButton: renderPrevMonthButton ? (0, _callRenderProp.callRenderProp)(renderPrevMonthButton) : _IconButton || (_IconButton = (0,
|
|
85
|
+
prevButton: renderPrevMonthButton ? (0, _callRenderProp.callRenderProp)(renderPrevMonthButton) : _IconButton || (_IconButton = (0, _jsxRuntime.jsx)(_IconButton3.IconButton, {
|
|
87
86
|
size: "small",
|
|
88
87
|
withBackground: false,
|
|
89
88
|
withBorder: false,
|
|
90
|
-
renderIcon: (0,
|
|
89
|
+
renderIcon: (0, _jsxRuntime.jsx)(_IconArrowOpenStartSolid.IconArrowOpenStartSolid, {
|
|
91
90
|
color: "primary"
|
|
92
91
|
}),
|
|
93
92
|
screenReaderLabel: "Previous month"
|
|
94
93
|
})),
|
|
95
|
-
nextButton: renderNextMonthButton ? (0, _callRenderProp.callRenderProp)(renderNextMonthButton) : _IconButton2 || (_IconButton2 = (0,
|
|
94
|
+
nextButton: renderNextMonthButton ? (0, _callRenderProp.callRenderProp)(renderNextMonthButton) : _IconButton2 || (_IconButton2 = (0, _jsxRuntime.jsx)(_IconButton3.IconButton, {
|
|
96
95
|
size: "small",
|
|
97
96
|
withBackground: false,
|
|
98
97
|
withBorder: false,
|
|
99
|
-
renderIcon: (0,
|
|
98
|
+
renderIcon: (0, _jsxRuntime.jsx)(_IconArrowOpenEndSolid.IconArrowOpenEndSolid, {
|
|
100
99
|
color: "primary"
|
|
101
100
|
}),
|
|
102
101
|
screenReaderLabel: "Next month"
|
|
@@ -220,69 +219,87 @@ let Calendar = exports.Calendar = (_dec = (0, _emotion.withStyle)(_styles.defaul
|
|
|
220
219
|
yearList.push(_DateTime.DateTime.parse(year.toString(), this.locale(), this.timezone()).format('YYYY'));
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
|
-
return (0,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
222
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
223
|
+
children: [(0, _jsxRuntime.jsxs)("div", {
|
|
224
|
+
css: style,
|
|
225
|
+
children: [prevButton && cloneButton(prevButton, this.handleMonthChange('prev')), renderNavigationLabel ? (0, _callRenderProp.callRenderProp)(renderNavigationLabel) : (0, _jsxRuntime.jsxs)("span", {
|
|
226
|
+
children: [(0, _jsxRuntime.jsx)("div", {
|
|
227
|
+
children: visibleMonth.format('MMMM')
|
|
228
|
+
}), !withYearPicker ? (0, _jsxRuntime.jsx)("div", {
|
|
229
|
+
children: visibleMonth.format('YYYY')
|
|
230
|
+
}) : null]
|
|
231
|
+
}), nextButton && cloneButton(nextButton, this.handleMonthChange('next'))]
|
|
232
|
+
}), withYearPicker ? (0, _jsxRuntime.jsx)("div", {
|
|
233
|
+
css: styles === null || styles === void 0 ? void 0 : styles.yearPicker,
|
|
234
|
+
children: (0, _jsxRuntime.jsx)(_SimpleSelect.SimpleSelect, {
|
|
235
|
+
width: "90px",
|
|
236
|
+
renderLabel: "",
|
|
237
|
+
placeholder: "--",
|
|
238
|
+
assistiveText: withYearPicker.screenReaderLabel,
|
|
239
|
+
value: visibleMonth.format('YYYY'),
|
|
240
|
+
onChange: (e, {
|
|
241
|
+
value
|
|
242
|
+
}) => this.handleYearChange(e, `${value}`),
|
|
243
|
+
children: yearList.map(year => (0, _jsxRuntime.jsx)(_SimpleSelect.SimpleSelect.Option, {
|
|
244
|
+
id: `opt-${year}`,
|
|
245
|
+
value: year,
|
|
246
|
+
children: `${year}`
|
|
247
|
+
}, year))
|
|
248
|
+
})
|
|
249
|
+
}) : null]
|
|
250
|
+
});
|
|
241
251
|
}
|
|
242
252
|
renderBody() {
|
|
243
|
-
return (0,
|
|
244
|
-
role: this.role
|
|
245
|
-
|
|
253
|
+
return (0, _jsxRuntime.jsxs)("table", {
|
|
254
|
+
role: this.role,
|
|
255
|
+
children: [(0, _jsxRuntime.jsx)("thead", {
|
|
256
|
+
children: this.renderWeekdayHeaders()
|
|
257
|
+
}), (0, _jsxRuntime.jsx)("tbody", {
|
|
258
|
+
children: this.renderDays()
|
|
259
|
+
})]
|
|
260
|
+
});
|
|
246
261
|
}
|
|
247
262
|
renderWeekdayHeaders() {
|
|
248
263
|
const styles = this.props.styles;
|
|
249
264
|
const renderWeekdayLabels = this.props.renderWeekdayLabels || this.defaultWeekdays;
|
|
250
265
|
const length = renderWeekdayLabels.length;
|
|
251
266
|
(0, _console.logError)(length === 7, `[Calendar] \`renderWeekdayLabels\` should be an array with 7 labels (one for each weekday). ${length} provided.`);
|
|
252
|
-
return (0,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
267
|
+
return (0, _jsxRuntime.jsx)("tr", {
|
|
268
|
+
children: renderWeekdayLabels.map((label, i) => {
|
|
269
|
+
return (0, _jsxRuntime.jsx)("th", {
|
|
270
|
+
scope: "col",
|
|
271
|
+
css: styles === null || styles === void 0 ? void 0 : styles.weekdayHeader,
|
|
272
|
+
id: this._weekdayHeaderIds[i],
|
|
273
|
+
children: (0, _callRenderProp.callRenderProp)(label)
|
|
274
|
+
}, i);
|
|
275
|
+
})
|
|
276
|
+
});
|
|
260
277
|
}
|
|
261
278
|
get defaultWeekdays() {
|
|
262
279
|
const shortDayNames = _DateTime.DateTime.getLocalDayNamesOfTheWeek(this.locale(), 'short');
|
|
263
280
|
const longDayNames = _DateTime.DateTime.getLocalDayNamesOfTheWeek(this.locale(), 'long');
|
|
264
|
-
return [(0,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
},
|
|
281
|
+
return [(0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
282
|
+
alt: longDayNames[0],
|
|
283
|
+
children: shortDayNames[0]
|
|
284
|
+
}, 1), (0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
285
|
+
alt: longDayNames[1],
|
|
286
|
+
children: shortDayNames[1]
|
|
287
|
+
}, 2), (0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
288
|
+
alt: longDayNames[2],
|
|
289
|
+
children: shortDayNames[2]
|
|
290
|
+
}, 3), (0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
291
|
+
alt: longDayNames[3],
|
|
292
|
+
children: shortDayNames[3]
|
|
293
|
+
}, 4), (0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
294
|
+
alt: longDayNames[4],
|
|
295
|
+
children: shortDayNames[4]
|
|
296
|
+
}, 5), (0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
297
|
+
alt: longDayNames[5],
|
|
298
|
+
children: shortDayNames[5]
|
|
299
|
+
}, 6), (0, _jsxRuntime.jsx)(_AccessibleContent.AccessibleContent, {
|
|
300
|
+
alt: longDayNames[6],
|
|
301
|
+
children: shortDayNames[6]
|
|
302
|
+
}, 7)];
|
|
286
303
|
}
|
|
287
304
|
renderDays() {
|
|
288
305
|
const children = this.props.children;
|
|
@@ -295,15 +312,15 @@ let Calendar = exports.Calendar = (_dec = (0, _emotion.withStyle)(_styles.defaul
|
|
|
295
312
|
if (!days[index]) days.push([]);
|
|
296
313
|
days[index].push(day);
|
|
297
314
|
return days; // 7xN 2D array of `Day`s
|
|
298
|
-
}, []).map(row => (0,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
315
|
+
}, []).map(row => (0, _jsxRuntime.jsx)("tr", {
|
|
316
|
+
role: role,
|
|
317
|
+
children: row.map((day, i) => (0, _jsxRuntime.jsx)("td", {
|
|
318
|
+
role: role,
|
|
319
|
+
children: role === 'presentation' ? (0, _safeCloneElement.safeCloneElement)(day, {
|
|
320
|
+
'aria-describedby': this._weekdayHeaderIds[i]
|
|
321
|
+
}) : day
|
|
322
|
+
}, day.props.date))
|
|
323
|
+
}, `row${row[0].props.date}`));
|
|
307
324
|
}
|
|
308
325
|
locale() {
|
|
309
326
|
if (this.props.locale) {
|
|
@@ -368,8 +385,7 @@ let Calendar = exports.Calendar = (_dec = (0, _emotion.withStyle)(_styles.defaul
|
|
|
368
385
|
}
|
|
369
386
|
return arr.map(date => {
|
|
370
387
|
const dateStr = date.toISOString();
|
|
371
|
-
return (0,
|
|
372
|
-
key: dateStr,
|
|
388
|
+
return (0, _jsxRuntime.jsx)(Calendar.Day, {
|
|
373
389
|
date: dateStr,
|
|
374
390
|
isSelected: selectedDate ? date.isSame(selectedDate, 'day') : false,
|
|
375
391
|
isToday: date.isSame(today, 'day'),
|
|
@@ -377,19 +393,22 @@ let Calendar = exports.Calendar = (_dec = (0, _emotion.withStyle)(_styles.defaul
|
|
|
377
393
|
label: date.format('D MMMM YYYY') // used by screen readers
|
|
378
394
|
,
|
|
379
395
|
onClick: this.handleDayClick,
|
|
380
|
-
interaction: this.isDisabledDate(date) ? 'disabled' : 'enabled'
|
|
381
|
-
|
|
396
|
+
interaction: this.isDisabledDate(date) ? 'disabled' : 'enabled',
|
|
397
|
+
children: date.format('DD')
|
|
398
|
+
}, dateStr);
|
|
382
399
|
});
|
|
383
400
|
}
|
|
384
401
|
render() {
|
|
385
402
|
const passthroughProps = _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Calendar.allowedProps), Calendar);
|
|
386
|
-
return (0,
|
|
403
|
+
return (0, _jsxRuntime.jsxs)(_View.View, {
|
|
404
|
+
...passthroughProps,
|
|
387
405
|
as: this.props.as,
|
|
388
406
|
display: "inline-block",
|
|
389
407
|
padding: "small",
|
|
390
408
|
background: "primary",
|
|
391
|
-
elementRef: this.handleRef
|
|
392
|
-
|
|
409
|
+
elementRef: this.handleRef,
|
|
410
|
+
children: [this.renderHeader(), this.renderBody()]
|
|
411
|
+
});
|
|
393
412
|
}
|
|
394
413
|
}, _Calendar.displayName = "Calendar", _Calendar.componentId = 'Calendar', _Calendar.contextType = _ApplyLocaleContext.ApplyLocaleContext, _Calendar.Day = _Day.Day, _Calendar.DAY_COUNT = 42, _Calendar.propTypes = _props.propTypes, _Calendar.allowedProps = _props.allowedProps, _Calendar.defaultProps = {
|
|
395
414
|
as: 'span',
|