@pingux/astro 2.70.0-alpha.2 → 2.70.0
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/lib/cjs/components/AccordionItem/AccordionItem.d.ts +1 -1
- package/lib/cjs/components/AccordionItem/AccordionItem.js +1 -1
- package/lib/cjs/components/Calendar/Calendar.js +4 -0
- package/lib/cjs/components/Calendar/Calendar.mdx +1 -1
- package/lib/cjs/components/Calendar/Calendar.test.js +1 -4
- package/lib/cjs/components/Calendar/CalendarCell.js +1 -1
- package/lib/cjs/components/DatePicker/DatePicker.test.js +62 -6
- package/lib/cjs/components/RangeCalendar/RangeCalendar.d.ts +7 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.js +100 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.mdx +39 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.stories.d.ts +103 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.stories.js +131 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.styles.d.ts +104 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.styles.js +118 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.test.d.ts +1 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendar.test.js +217 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendarCell.d.ts +4 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendarCell.js +96 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendarGrid.d.ts +4 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendarGrid.js +70 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendarHeader.d.ts +4 -0
- package/lib/cjs/components/RangeCalendar/RangeCalendarHeader.js +85 -0
- package/lib/cjs/components/RangeCalendar/index.d.ts +2 -0
- package/lib/cjs/components/RangeCalendar/index.js +33 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +45 -26
- package/lib/cjs/styles/variants/variants.js +2 -0
- package/lib/cjs/types/calendar.d.ts +51 -16
- package/lib/components/AccordionItem/AccordionItem.js +0 -3
- package/lib/components/Calendar/Calendar.js +4 -0
- package/lib/components/Calendar/Calendar.mdx +1 -1
- package/lib/components/Calendar/Calendar.test.js +1 -4
- package/lib/components/Calendar/CalendarCell.js +1 -1
- package/lib/components/DatePicker/DatePicker.test.js +62 -6
- package/lib/components/RangeCalendar/RangeCalendar.js +86 -0
- package/lib/components/RangeCalendar/RangeCalendar.mdx +39 -0
- package/lib/components/RangeCalendar/RangeCalendar.stories.js +112 -0
- package/lib/components/RangeCalendar/RangeCalendar.styles.js +110 -0
- package/lib/components/RangeCalendar/RangeCalendar.test.js +208 -0
- package/lib/components/RangeCalendar/RangeCalendarCell.js +82 -0
- package/lib/components/RangeCalendar/RangeCalendarGrid.js +61 -0
- package/lib/components/RangeCalendar/RangeCalendarHeader.js +76 -0
- package/lib/components/RangeCalendar/index.js +2 -0
- package/lib/index.js +2 -0
- package/lib/styles/variants/variants.js +2 -0
- package/package.json +1 -1
@@ -0,0 +1,39 @@
|
|
1
|
+
import { Meta } from '@storybook/addon-docs';
|
2
|
+
|
3
|
+
<Meta title="Experimental/RangeCalendar/RangeCalendar" />
|
4
|
+
|
5
|
+
# RangeCalendar
|
6
|
+
|
7
|
+
The RangeCalendar component displays months in two grid-like views and gives users the ability to quickly to select a contiguous range of dates.
|
8
|
+
|
9
|
+
This component is built on [useRangeCalendar](https://react-spectrum.adobe.com/react-aria/useRangeCalendar.html), [useCalendarGrid](https://react-spectrum.adobe.com/react-aria/useCalendar.html#usecalendargrid), and
|
10
|
+
[useCalendarCell](https://react-spectrum.adobe.com/react-aria/useCalendar.html#usecalendarcell) from React Aria, and [useRangeCalendarState](https://react-spectrum.adobe.com/react-stately/useRangeCalendarState.html) from React Stately.
|
11
|
+
|
12
|
+
### Required components
|
13
|
+
|
14
|
+
This component can be used independently and does not require additional components.
|
15
|
+
|
16
|
+
### Accessibility
|
17
|
+
|
18
|
+
#### Keyboard Navigation
|
19
|
+
|
20
|
+
These keys provide additional functionality to the component.
|
21
|
+
|
22
|
+
| Keys | Functions |
|
23
|
+
| ---- | --------- |
|
24
|
+
| Space or Enter | Selects the start and end dates when a date is focused, and navigates to the calendar pages when the navigational buttons are focused. |
|
25
|
+
| Tab | Components in the calendar are focusable and follow the page tab sequence. |
|
26
|
+
| Shift + Tab | Moves focus to the previous focusable component. |
|
27
|
+
| Pressing Home:(Fn + Right Arrow Key) Or Control or Command + Home | Shifts the focus to the first calendar date of the currently focused month. |
|
28
|
+
| Pressing End:(Fn + left Arrow Key) Or Control or Command + End | Shifts the focus to the last calendar date of the currently focused month. |
|
29
|
+
| Arrow key | Navigates up, down, right, and left across the calendar. If at the end of the current calendar, the right arrow key navigates to the next calendar. If at the beginning of the current calendar, the left arrow key navigates to the previous calendar. |
|
30
|
+
| Page up | Changes focus to the same date in the previous month. |
|
31
|
+
| Page down | Changes focus to the same date in the next month. |
|
32
|
+
| Shift + page up | Changes the grid of dates to the same months in the previous year. |
|
33
|
+
| Shift+ page down | Changes the grid of dates to the same months in the next year. |
|
34
|
+
|
35
|
+
#### Screen Readers
|
36
|
+
|
37
|
+
This component uses the following attributes to assist screen readers:
|
38
|
+
- The **`aria-label`** attribute is used to provide an accessible name.
|
39
|
+
- In each data cell, the **`aria-selected`** attribute is set to “true” for all dates within the selected range, and **`aria-disabled`** is set to “false” by default.
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
|
+
import _someInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/some";
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
|
+
import React, { useState } from 'react';
|
16
|
+
import { parseDate } from '@internationalized/date';
|
17
|
+
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
18
|
+
import { RangeCalendar } from '../../index';
|
19
|
+
import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
|
20
|
+
import RangeCalendarReadme from './RangeCalendar.mdx';
|
21
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
22
|
+
export default {
|
23
|
+
title: 'Experimental/RangeCalendar',
|
24
|
+
component: RangeCalendar,
|
25
|
+
parameters: {
|
26
|
+
actions: {
|
27
|
+
argTypesRegex: '^on.*'
|
28
|
+
},
|
29
|
+
source: {
|
30
|
+
type: 'code'
|
31
|
+
},
|
32
|
+
docs: {
|
33
|
+
page: function page() {
|
34
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(RangeCalendarReadme, null), ___EmotionJSX(DocsLayout, null));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
},
|
38
|
+
argTypes: _objectSpread({}, ariaAttributeBaseArgTypes),
|
39
|
+
args: {
|
40
|
+
defaultFocusedValue: '2030-01-15'
|
41
|
+
}
|
42
|
+
};
|
43
|
+
export var Default = function Default(args) {
|
44
|
+
return ___EmotionJSX(RangeCalendar, _extends({}, args, {
|
45
|
+
"aria-label": "range-calendar"
|
46
|
+
}));
|
47
|
+
};
|
48
|
+
export var DefaultValue = function DefaultValue() {
|
49
|
+
return ___EmotionJSX(RangeCalendar, {
|
50
|
+
"aria-label": "calendar-with-default-vaue",
|
51
|
+
defaultValue: {
|
52
|
+
start: '2030-01-15',
|
53
|
+
end: '2030-01-22'
|
54
|
+
}
|
55
|
+
});
|
56
|
+
};
|
57
|
+
export var Disabled = function Disabled(args) {
|
58
|
+
return ___EmotionJSX(RangeCalendar, _extends({}, args, {
|
59
|
+
"aria-label": "calendar--range-component-disabled",
|
60
|
+
isDisabled: true
|
61
|
+
}));
|
62
|
+
};
|
63
|
+
export var UnavailableDates = function UnavailableDates() {
|
64
|
+
var unavailableRanges = [['2030-07-28', '2030-08-03'], ['2030-08-11', '2030-08-17'], ['2030-08-25', '2030-08-31']];
|
65
|
+
var isDateUnavailable = function isDateUnavailable(date) {
|
66
|
+
return _someInstanceProperty(unavailableRanges).call(unavailableRanges, function (interval) {
|
67
|
+
return date.compare(parseDate(interval[0])) >= 0 && date.compare(parseDate(interval[1])) <= 0;
|
68
|
+
});
|
69
|
+
};
|
70
|
+
return ___EmotionJSX(RangeCalendar, {
|
71
|
+
"aria-label": "Trip dates",
|
72
|
+
defaultValue: {
|
73
|
+
start: '2030-08-07',
|
74
|
+
end: '2030-08-09'
|
75
|
+
},
|
76
|
+
isDateUnavailable: isDateUnavailable
|
77
|
+
});
|
78
|
+
};
|
79
|
+
export var MinimumDate = function MinimumDate() {
|
80
|
+
return ___EmotionJSX(RangeCalendar, {
|
81
|
+
"aria-label": "range-calendar-component-min-date",
|
82
|
+
minValue: "2030-01-15",
|
83
|
+
defaultValue: {
|
84
|
+
start: '2030-01-15',
|
85
|
+
end: '2030-01-20'
|
86
|
+
}
|
87
|
+
});
|
88
|
+
};
|
89
|
+
export var MaximumDate = function MaximumDate() {
|
90
|
+
return ___EmotionJSX(RangeCalendar, {
|
91
|
+
"aria-label": "range-calendar-component-max-date",
|
92
|
+
defaultValue: {
|
93
|
+
start: '2030-01-12',
|
94
|
+
end: '2030-01-15'
|
95
|
+
},
|
96
|
+
maxValue: "2030-01-17"
|
97
|
+
});
|
98
|
+
};
|
99
|
+
export var Controlled = function Controlled(args) {
|
100
|
+
var _useState = useState({
|
101
|
+
start: '2030-01-12',
|
102
|
+
end: '2030-01-15'
|
103
|
+
}),
|
104
|
+
_useState2 = _slicedToArray(_useState, 2),
|
105
|
+
range = _useState2[0],
|
106
|
+
setRange = _useState2[1];
|
107
|
+
return ___EmotionJSX(RangeCalendar, _extends({}, args, {
|
108
|
+
"aria-label": "calendar-component-controlled",
|
109
|
+
value: range,
|
110
|
+
onChange: setRange
|
111
|
+
}));
|
112
|
+
};
|
@@ -0,0 +1,110 @@
|
|
1
|
+
var calendarBody = {
|
2
|
+
pb: 'sm',
|
3
|
+
borderTop: '1px solid',
|
4
|
+
borderTopColor: 'neutral.80',
|
5
|
+
'& > tr:nth-of-type(odd) ': {
|
6
|
+
backgroundColor: 'white'
|
7
|
+
}
|
8
|
+
};
|
9
|
+
var calendarButton = {
|
10
|
+
justifyContent: 'center',
|
11
|
+
alignItems: 'center',
|
12
|
+
fontSize: 'sm',
|
13
|
+
fontWeight: 1,
|
14
|
+
color: 'neutral.10',
|
15
|
+
lineHeight: '16px',
|
16
|
+
width: '40px',
|
17
|
+
height: '40px',
|
18
|
+
outline: 'none',
|
19
|
+
'&.is-hovered': {
|
20
|
+
bg: 'accent.99',
|
21
|
+
cursor: 'pointer'
|
22
|
+
},
|
23
|
+
'&.is-selected': {
|
24
|
+
bg: 'accent.99',
|
25
|
+
'&.is-hovered': {
|
26
|
+
bg: 'active',
|
27
|
+
color: 'white'
|
28
|
+
}
|
29
|
+
},
|
30
|
+
'&.is-range-ends': {
|
31
|
+
bg: 'active',
|
32
|
+
color: 'white',
|
33
|
+
outline: 'none',
|
34
|
+
boxShadow: 'none'
|
35
|
+
},
|
36
|
+
'&.is-selection-start': {
|
37
|
+
borderRadius: '6px 0 0 6px'
|
38
|
+
},
|
39
|
+
'&.is-selection-end': {
|
40
|
+
borderRadius: '0 6px 6px 0'
|
41
|
+
},
|
42
|
+
'&.is-start-and-end': {
|
43
|
+
borderRadius: '0'
|
44
|
+
},
|
45
|
+
'&.is-focused': {
|
46
|
+
outline: '1px',
|
47
|
+
outlineStyle: 'solid',
|
48
|
+
outlineColor: 'focus',
|
49
|
+
outlineOffset: '-1px'
|
50
|
+
},
|
51
|
+
'&.is-unavailable': {
|
52
|
+
backgroundColor: 'neutral.80'
|
53
|
+
},
|
54
|
+
'&:not(.is-outside-visible-range)&.is-extreme&:not(.is-completely-disabled)': {
|
55
|
+
backgroundColor: 'neutral.80',
|
56
|
+
color: 'neutral.10',
|
57
|
+
opacity: 1
|
58
|
+
},
|
59
|
+
'&.is-disabled': {
|
60
|
+
'&.is-hovered': {
|
61
|
+
backgroundColor: 'unset'
|
62
|
+
}
|
63
|
+
}
|
64
|
+
};
|
65
|
+
var calendarCell = {
|
66
|
+
cursor: 'default',
|
67
|
+
textAlign: 'center',
|
68
|
+
position: 'relative',
|
69
|
+
color: '#333',
|
70
|
+
padding: '0',
|
71
|
+
width: '40px',
|
72
|
+
height: '40px'
|
73
|
+
};
|
74
|
+
var columnHeader = {
|
75
|
+
display: 'flex',
|
76
|
+
justifyContent: 'center',
|
77
|
+
alignItems: 'center',
|
78
|
+
color: 'text.primary',
|
79
|
+
fontSize: 'sm',
|
80
|
+
fontWeight: 1,
|
81
|
+
width: '40px',
|
82
|
+
height: '40px'
|
83
|
+
};
|
84
|
+
var calendarHeaderContainer = {
|
85
|
+
justifyContent: 'space-between',
|
86
|
+
mt: 'sm',
|
87
|
+
alignItems: 'center',
|
88
|
+
width: '586px',
|
89
|
+
height: '31px'
|
90
|
+
};
|
91
|
+
var calendarHeader = {
|
92
|
+
position: 'relative',
|
93
|
+
justifyContent: 'center',
|
94
|
+
alignItems: 'center',
|
95
|
+
width: '280px',
|
96
|
+
height: '100%'
|
97
|
+
};
|
98
|
+
var calendarContainer = {
|
99
|
+
width: '586px',
|
100
|
+
textAlign: 'center'
|
101
|
+
};
|
102
|
+
export default {
|
103
|
+
calendarBody: calendarBody,
|
104
|
+
calendarButton: calendarButton,
|
105
|
+
calendarCell: calendarCell,
|
106
|
+
calendarContainer: calendarContainer,
|
107
|
+
calendarHeader: calendarHeader,
|
108
|
+
calendarHeaderContainer: calendarHeaderContainer,
|
109
|
+
columnHeader: columnHeader
|
110
|
+
};
|
@@ -0,0 +1,208 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
3
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
4
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
5
|
+
import React from 'react';
|
6
|
+
import { CalendarDate, getLocalTimeZone, today } from '@internationalized/date';
|
7
|
+
import userEvent from '@testing-library/user-event';
|
8
|
+
import { isDateWithinRanges } from '../../utils/devUtils/props/isDateWithinRanges';
|
9
|
+
import { act, fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
10
|
+
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
11
|
+
import RangeCalendar, { parseDateIfString, parseDateRangeIfString } from './RangeCalendar';
|
12
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
13
|
+
var unavailableRanges = [['2022-08-10', '2022-08-15']];
|
14
|
+
var defaultProps = {
|
15
|
+
defaultValue: {
|
16
|
+
start: new CalendarDate(2022, 8, 1),
|
17
|
+
end: new CalendarDate(2022, 8, 7)
|
18
|
+
}
|
19
|
+
};
|
20
|
+
var isDateUnavailable = function isDateUnavailable(date) {
|
21
|
+
return isDateWithinRanges(date, unavailableRanges);
|
22
|
+
};
|
23
|
+
var getComponent = function getComponent() {
|
24
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
25
|
+
return render(___EmotionJSX(RangeCalendar, _extends({}, defaultProps, props, {
|
26
|
+
"aria-label": "Calendar Range"
|
27
|
+
})));
|
28
|
+
};
|
29
|
+
|
30
|
+
// Needs to be added to each components test file.
|
31
|
+
universalComponentTests({
|
32
|
+
renderComponent: function renderComponent(props) {
|
33
|
+
return ___EmotionJSX(RangeCalendar, _extends({}, defaultProps, props, {
|
34
|
+
"aria-label": "Calendar Range"
|
35
|
+
}));
|
36
|
+
}
|
37
|
+
});
|
38
|
+
test('renders calendar range component', function () {
|
39
|
+
getComponent();
|
40
|
+
var calendarContainer = screen.getByRole('group');
|
41
|
+
expect(calendarContainer).toBeInTheDocument();
|
42
|
+
expect(calendarContainer).toHaveTextContent('Calendar Range, August to September 2022');
|
43
|
+
var buttons = screen.getAllByRole('button');
|
44
|
+
expect(buttons[0]).toHaveAttribute('aria-label', 'Previous month navigation');
|
45
|
+
expect(buttons[1]).toHaveAttribute('aria-label', 'Next month navigation');
|
46
|
+
var calendarGrids = screen.getAllByRole('grid');
|
47
|
+
expect(calendarGrids).toHaveLength(2);
|
48
|
+
var calendarHeaders = screen.getAllByRole('columnheader', {
|
49
|
+
hidden: true
|
50
|
+
});
|
51
|
+
expect(calendarHeaders).toHaveLength(14);
|
52
|
+
var calendarCells = screen.queryAllByRole('gridcell');
|
53
|
+
expect(calendarCells).toHaveLength(70);
|
54
|
+
});
|
55
|
+
test('should able to navigate to previous and next month', function () {
|
56
|
+
getComponent();
|
57
|
+
var buttons = screen.getAllByRole('button');
|
58
|
+
var heading = screen.getByRole('group');
|
59
|
+
expect(heading).toHaveTextContent('Calendar Range, August to September 2022');
|
60
|
+
|
61
|
+
// navigation to previous month
|
62
|
+
userEvent.click(buttons[0]);
|
63
|
+
expect(heading).toHaveTextContent('Calendar Range, July to August 2022');
|
64
|
+
|
65
|
+
// navigation to next month
|
66
|
+
userEvent.click(buttons[1]);
|
67
|
+
expect(heading).toHaveTextContent('Calendar Range, August to September 2022');
|
68
|
+
|
69
|
+
// navigation to next month
|
70
|
+
userEvent.click(buttons[1]);
|
71
|
+
expect(heading).toHaveTextContent('Calendar Range, September to October 2022');
|
72
|
+
});
|
73
|
+
test('should be able to select a range of dates', function () {
|
74
|
+
getComponent();
|
75
|
+
var calendarCells = screen.queryAllByRole('gridcell');
|
76
|
+
var startCell = calendarCells[7];
|
77
|
+
var endCell = calendarCells[13];
|
78
|
+
userEvent.click(startCell);
|
79
|
+
userEvent.click(endCell);
|
80
|
+
var selectedCells = screen.getAllByRole('gridcell', {
|
81
|
+
selected: true
|
82
|
+
});
|
83
|
+
expect(selectedCells).toHaveLength(7);
|
84
|
+
});
|
85
|
+
test('should disable unavailable dates', function () {
|
86
|
+
getComponent({
|
87
|
+
isDateUnavailable: isDateUnavailable
|
88
|
+
});
|
89
|
+
var calendarCells = screen.queryAllByRole('gridcell');
|
90
|
+
var unavailableCells = _sliceInstanceProperty(calendarCells).call(calendarCells, 10, 16);
|
91
|
+
_forEachInstanceProperty(unavailableCells).call(unavailableCells, function (cell) {
|
92
|
+
expect(cell).toHaveAttribute('aria-disabled', 'true');
|
93
|
+
});
|
94
|
+
});
|
95
|
+
test('allows users to select and navigate through calendar items', function () {
|
96
|
+
getComponent();
|
97
|
+
var buttons = screen.queryAllByRole('button');
|
98
|
+
act(function () {
|
99
|
+
buttons[4].focus();
|
100
|
+
});
|
101
|
+
expect(buttons[4]).toHaveFocus();
|
102
|
+
fireEvent.keyDown(buttons[4], {
|
103
|
+
key: 'ArrowRight'
|
104
|
+
});
|
105
|
+
expect(buttons[5]).toHaveFocus();
|
106
|
+
fireEvent.keyDown(buttons[5], {
|
107
|
+
key: 'ArrowLeft'
|
108
|
+
});
|
109
|
+
expect(buttons[4]).toHaveFocus();
|
110
|
+
fireEvent.keyDown(buttons[4], {
|
111
|
+
key: 'ArrowDown'
|
112
|
+
});
|
113
|
+
expect(buttons[11]).toHaveFocus();
|
114
|
+
fireEvent.keyDown(buttons[11], {
|
115
|
+
key: 'ArrowUp'
|
116
|
+
});
|
117
|
+
expect(buttons[4]).toHaveFocus();
|
118
|
+
fireEvent.keyDown(buttons[4], {
|
119
|
+
key: 'Enter'
|
120
|
+
});
|
121
|
+
fireEvent.keyUp(buttons[4], {
|
122
|
+
key: 'Enter'
|
123
|
+
});
|
124
|
+
expect(buttons[5]).toHaveFocus();
|
125
|
+
});
|
126
|
+
test('readonly calendar', function () {
|
127
|
+
getComponent({
|
128
|
+
isReadOnly: true
|
129
|
+
});
|
130
|
+
var calendars = screen.queryAllByRole('grid');
|
131
|
+
expect(calendars).toHaveLength(2);
|
132
|
+
_forEachInstanceProperty(calendars).call(calendars, function (calendar) {
|
133
|
+
expect(calendar).toHaveAttribute('aria-readonly', 'true');
|
134
|
+
});
|
135
|
+
var buttons = screen.queryAllByRole('button');
|
136
|
+
userEvent.click(buttons[12]);
|
137
|
+
expect(buttons[12]).not.toHaveClass('is-selected');
|
138
|
+
});
|
139
|
+
test('dates before minimum date cannot be selected', function () {
|
140
|
+
var onChange = jest.fn();
|
141
|
+
var defaultValue = {
|
142
|
+
start: '2022-08-10',
|
143
|
+
end: '2022-08-15'
|
144
|
+
};
|
145
|
+
getComponent({
|
146
|
+
onChange: onChange,
|
147
|
+
minValue: '2022-08-06',
|
148
|
+
defaultValue: defaultValue
|
149
|
+
});
|
150
|
+
var buttons = screen.queryAllByRole('button');
|
151
|
+
userEvent.click(buttons[2]);
|
152
|
+
expect(buttons[2]).not.toHaveClass('is-selected');
|
153
|
+
expect(onChange).not.toHaveBeenCalled();
|
154
|
+
});
|
155
|
+
test('dates past maxiumum date cannot be selected', function () {
|
156
|
+
var onChange = jest.fn();
|
157
|
+
var defaultValue = {
|
158
|
+
start: new CalendarDate(2022, 8, 10),
|
159
|
+
end: new CalendarDate(2022, 8, 15)
|
160
|
+
};
|
161
|
+
getComponent({
|
162
|
+
onChange: onChange,
|
163
|
+
maxValue: '2022-08-20',
|
164
|
+
defaultValue: defaultValue
|
165
|
+
});
|
166
|
+
var buttons = screen.queryAllByRole('button');
|
167
|
+
userEvent.click(buttons[55]);
|
168
|
+
expect(buttons[55]).not.toHaveClass('is-selected');
|
169
|
+
expect(onChange).not.toHaveBeenCalled();
|
170
|
+
});
|
171
|
+
test('should autofocus on current day with hasAutoFocus', function () {
|
172
|
+
var _context;
|
173
|
+
getComponent({
|
174
|
+
hasAutoFocus: true,
|
175
|
+
defaultValue: null
|
176
|
+
});
|
177
|
+
var dateToday = today(getLocalTimeZone());
|
178
|
+
var day = dateToday.day;
|
179
|
+
var focusedDay = _filterInstanceProperty(_context = screen.queryAllByText(day)).call(_context, function (cell) {
|
180
|
+
return cell.getAttribute('aria-disabled') !== 'true';
|
181
|
+
});
|
182
|
+
expect(focusedDay[0]).toHaveTextContent(day.toString());
|
183
|
+
expect(focusedDay[0]).toHaveFocus();
|
184
|
+
});
|
185
|
+
test('parseDateRangeIfString should correctly parse string or DateValue inputs', function () {
|
186
|
+
var value1 = {
|
187
|
+
start: '2022-08-01',
|
188
|
+
end: '2022-08-07'
|
189
|
+
};
|
190
|
+
var value2 = {
|
191
|
+
start: new CalendarDate(2022, 8, 10),
|
192
|
+
end: new CalendarDate(2022, 8, 15)
|
193
|
+
};
|
194
|
+
var result1 = parseDateRangeIfString(value1);
|
195
|
+
var result2 = parseDateRangeIfString(value2);
|
196
|
+
expect(result1.start).toEqual(new CalendarDate(2022, 8, 1));
|
197
|
+
expect(result1.end).toEqual(new CalendarDate(2022, 8, 7));
|
198
|
+
expect(result2.start).toEqual(new CalendarDate(2022, 8, 10));
|
199
|
+
expect(result2.end).toEqual(new CalendarDate(2022, 8, 15));
|
200
|
+
});
|
201
|
+
test('parseDateIfString should correctly parse string or DateValue inputs', function () {
|
202
|
+
var value1 = '2022-08-01';
|
203
|
+
var value2 = new CalendarDate(2022, 8, 10);
|
204
|
+
var result1 = parseDateIfString(value1);
|
205
|
+
var result2 = parseDateIfString(value2);
|
206
|
+
expect(result1).toEqual(new CalendarDate(2022, 8, 1));
|
207
|
+
expect(result2).toEqual(new CalendarDate(2022, 8, 10));
|
208
|
+
});
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["state", "date", "currentMonth", "className"];
|
4
|
+
import React, { forwardRef } from 'react';
|
5
|
+
import { isSameDay, isSameMonth } from '@internationalized/date';
|
6
|
+
import { useCalendarCell } from '@react-aria/calendar';
|
7
|
+
import { useFocusRing } from '@react-aria/focus';
|
8
|
+
import { useHover, usePress } from '@react-aria/interactions';
|
9
|
+
import { mergeProps } from '@react-aria/utils';
|
10
|
+
import { useLocalOrForwardRef, useStatusClasses } from '../../hooks';
|
11
|
+
import { Box, TableCell } from '../../index';
|
12
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
13
|
+
var RangeCalendarCell = /*#__PURE__*/forwardRef(function (props, ref) {
|
14
|
+
var state = props.state,
|
15
|
+
date = props.date,
|
16
|
+
currentMonth = props.currentMonth,
|
17
|
+
className = props.className,
|
18
|
+
others = _objectWithoutProperties(props, _excluded);
|
19
|
+
var cellRef = useLocalOrForwardRef(ref);
|
20
|
+
var _useCalendarCell = useCalendarCell({
|
21
|
+
date: date
|
22
|
+
}, state, cellRef),
|
23
|
+
cellProps = _useCalendarCell.cellProps,
|
24
|
+
buttonProps = _useCalendarCell.buttonProps,
|
25
|
+
isSelected = _useCalendarCell.isSelected,
|
26
|
+
isOutsideVisibleRange = _useCalendarCell.isOutsideVisibleRange,
|
27
|
+
isUnavailable = _useCalendarCell.isUnavailable,
|
28
|
+
formattedDate = _useCalendarCell.formattedDate,
|
29
|
+
isDisabled = _useCalendarCell.isDisabled;
|
30
|
+
var highlightedRange = state.highlightedRange;
|
31
|
+
var isOutsideMonth = !isSameMonth(currentMonth, date);
|
32
|
+
|
33
|
+
// The start and end date of the selected range will have
|
34
|
+
// an emphasized appearance.
|
35
|
+
var isSelectionStart = highlightedRange ? isSameDay(date, highlightedRange.start) : isSelected;
|
36
|
+
var isSelectionEnd = highlightedRange ? isSameDay(date, highlightedRange.end) : isSelected;
|
37
|
+
var _useHover = useHover({}),
|
38
|
+
hoverProps = _useHover.hoverProps,
|
39
|
+
isHovered = _useHover.isHovered;
|
40
|
+
var _usePress = usePress({
|
41
|
+
ref: cellRef
|
42
|
+
}),
|
43
|
+
pressProps = _usePress.pressProps,
|
44
|
+
isPressed = _usePress.isPressed;
|
45
|
+
var _useFocusRing = useFocusRing({
|
46
|
+
within: true
|
47
|
+
}),
|
48
|
+
focusWithinProps = _useFocusRing.focusProps,
|
49
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
50
|
+
var mergedProps = mergeProps(cellProps, hoverProps, pressProps, focusWithinProps);
|
51
|
+
var _useStatusClasses = useStatusClasses(className, {
|
52
|
+
isSelected: isSelected,
|
53
|
+
isExtreme: isDisabled,
|
54
|
+
isUnavailable: isUnavailable,
|
55
|
+
isPressed: isPressed,
|
56
|
+
isFocused: isFocusVisible,
|
57
|
+
isHovered: isHovered,
|
58
|
+
isOutsideVisibleRange: isOutsideVisibleRange,
|
59
|
+
isCompletelyDisabled: state.isDisabled,
|
60
|
+
isRangeEnds: isSelectionStart || isSelectionEnd,
|
61
|
+
isStartAndEnd: isSelectionStart && isSelectionEnd,
|
62
|
+
isSelectionStart: isSelectionStart,
|
63
|
+
isSelectionEnd: isSelectionEnd
|
64
|
+
}),
|
65
|
+
classNames = _useStatusClasses.classNames;
|
66
|
+
return ___EmotionJSX(TableCell, _extends({}, mergedProps, {
|
67
|
+
variant: "rangeCalendar.calendarCell"
|
68
|
+
}), ___EmotionJSX(Box, {
|
69
|
+
style: {
|
70
|
+
display: isOutsideMonth ? 'none' : 'flex'
|
71
|
+
}
|
72
|
+
}, ___EmotionJSX(Box, _extends({
|
73
|
+
variant: "rangeCalendar.calendarButton",
|
74
|
+
ref: cellRef
|
75
|
+
}, mergeProps(buttonProps, others), {
|
76
|
+
isSelected: isSelected,
|
77
|
+
isDisabled: isDisabled,
|
78
|
+
isUnavailable: isUnavailable,
|
79
|
+
className: classNames
|
80
|
+
}), formattedDate)));
|
81
|
+
});
|
82
|
+
export default RangeCalendarCell;
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
3
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
4
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
5
|
+
import _keysInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/keys";
|
6
|
+
import React from 'react';
|
7
|
+
import { endOfMonth, getWeeksInMonth } from '@internationalized/date';
|
8
|
+
import { useCalendarGrid } from '@react-aria/calendar';
|
9
|
+
import { useLocale } from '@react-aria/i18n';
|
10
|
+
import { Table, TableBody, TableCell, TableHead, TableRow } from '../../index';
|
11
|
+
import RangeCalendarCell from './RangeCalendarCell';
|
12
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
13
|
+
var RangeCalendarGrid = function RangeCalendarGrid(props) {
|
14
|
+
var _context2, _context3;
|
15
|
+
var state = props.state,
|
16
|
+
_props$offset = props.offset,
|
17
|
+
offset = _props$offset === void 0 ? {} : _props$offset;
|
18
|
+
var visibleRange = state.visibleRange,
|
19
|
+
getDatesInWeek = state.getDatesInWeek;
|
20
|
+
var _useLocale = useLocale(),
|
21
|
+
locale = _useLocale.locale;
|
22
|
+
var startDate = visibleRange.start.add(offset);
|
23
|
+
var endDate = endOfMonth(startDate);
|
24
|
+
var _useCalendarGrid = useCalendarGrid({
|
25
|
+
startDate: startDate,
|
26
|
+
endDate: endDate
|
27
|
+
}, state),
|
28
|
+
gridProps = _useCalendarGrid.gridProps,
|
29
|
+
headerProps = _useCalendarGrid.headerProps,
|
30
|
+
weekDays = _useCalendarGrid.weekDays;
|
31
|
+
var weeksInMonth = getWeeksInMonth(startDate, locale);
|
32
|
+
var getKey = function getKey(day, index) {
|
33
|
+
var _context;
|
34
|
+
return _concatInstanceProperty(_context = "".concat(day, "-")).call(_context, index);
|
35
|
+
};
|
36
|
+
return ___EmotionJSX(Table, _extends({}, gridProps, {
|
37
|
+
role: "grid"
|
38
|
+
}), ___EmotionJSX(TableHead, headerProps, ___EmotionJSX(TableRow, null, _mapInstanceProperty(weekDays).call(weekDays, function (day, index) {
|
39
|
+
return ___EmotionJSX(TableCell, {
|
40
|
+
isHeading: true,
|
41
|
+
variant: "rangeCalendar.columnHeader",
|
42
|
+
key: getKey(day, index),
|
43
|
+
role: "columnheader"
|
44
|
+
}, day);
|
45
|
+
}))), ___EmotionJSX(TableBody, {
|
46
|
+
variant: "rangeCalendar.calendarBody"
|
47
|
+
}, _mapInstanceProperty(_context2 = _Array$from(_keysInstanceProperty(_context3 = Array(weeksInMonth)).call(_context3))).call(_context2, function (weekIndex) {
|
48
|
+
var _context4;
|
49
|
+
return ___EmotionJSX(TableRow, {
|
50
|
+
key: weekIndex
|
51
|
+
}, _mapInstanceProperty(_context4 = getDatesInWeek(weekIndex, startDate)).call(_context4, function (date) {
|
52
|
+
return (date === null || date === void 0 ? void 0 : date.day) && ___EmotionJSX(RangeCalendarCell, {
|
53
|
+
key: date.toString(),
|
54
|
+
state: state,
|
55
|
+
date: date,
|
56
|
+
currentMonth: startDate
|
57
|
+
});
|
58
|
+
}));
|
59
|
+
})));
|
60
|
+
};
|
61
|
+
export default RangeCalendarGrid;
|