@dhis2-ui/calendar 9.12.0-alpha.3 → 9.12.0
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/calendar/calendar-table-cell.js +2 -5
- package/build/cjs/calendar/calendar-table.js +5 -9
- package/build/cjs/calendar/calendar.js +33 -34
- package/build/cjs/calendar/navigation-container.js +34 -36
- package/build/cjs/calendar-input/calendar-input.js +34 -118
- package/build/cjs/stories/calendar-input.prod.stories.js +2 -71
- package/build/cjs/stories/calendar-story-wrapper.js +3 -8
- package/build/es/calendar/calendar-table-cell.js +2 -5
- package/build/es/calendar/calendar-table.js +4 -8
- package/build/es/calendar/calendar.js +34 -35
- package/build/es/calendar/navigation-container.js +33 -35
- package/build/es/calendar-input/calendar-input.js +36 -120
- package/build/es/stories/calendar-input.prod.stories.js +1 -67
- package/build/es/stories/calendar-story-wrapper.js +3 -8
- package/package.json +9 -9
- package/build/cjs/calendar/calendar-container.js +0 -81
- package/build/cjs/calendar-input/__tests__/calendar-input.test.js +0 -46
- package/build/es/calendar/calendar-container.js +0 -72
- package/build/es/calendar-input/__tests__/calendar-input.test.js +0 -43
@@ -1,81 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.CalendarContainer = void 0;
|
7
|
-
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
8
|
-
var _uiConstants = require("@dhis2/ui-constants");
|
9
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
11
|
-
var _calendarTable = require("./calendar-table.js");
|
12
|
-
var _navigationContainer = require("./navigation-container.js");
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
16
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
17
|
-
const wrapperBorderColor = _uiConstants.colors.grey300;
|
18
|
-
const backgroundColor = 'none';
|
19
|
-
const CalendarContainer = exports.CalendarContainer = /*#__PURE__*/_react.default.memo(function CalendarContainer(_ref) {
|
20
|
-
let {
|
21
|
-
date,
|
22
|
-
width,
|
23
|
-
cellSize,
|
24
|
-
calendarWeekDays,
|
25
|
-
weekDayLabels,
|
26
|
-
currMonth,
|
27
|
-
currYear,
|
28
|
-
nextMonth,
|
29
|
-
nextYear,
|
30
|
-
prevMonth,
|
31
|
-
prevYear,
|
32
|
-
languageDirection,
|
33
|
-
excludedRef,
|
34
|
-
unfocusable
|
35
|
-
} = _ref;
|
36
|
-
const navigationProps = (0, _react.useMemo)(() => {
|
37
|
-
return {
|
38
|
-
currMonth,
|
39
|
-
currYear,
|
40
|
-
nextMonth,
|
41
|
-
nextYear,
|
42
|
-
prevMonth,
|
43
|
-
prevYear,
|
44
|
-
languageDirection
|
45
|
-
};
|
46
|
-
}, [currMonth, currYear, languageDirection, nextMonth, nextYear, prevMonth, prevYear]);
|
47
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
48
|
-
className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
49
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
50
|
-
dir: languageDirection,
|
51
|
-
"data-test": "calendar",
|
52
|
-
className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
|
53
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
54
|
-
ref: excludedRef,
|
55
|
-
className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
56
|
-
}, /*#__PURE__*/_react.default.createElement(_navigationContainer.NavigationContainer, _extends({}, navigationProps, {
|
57
|
-
unfocusable: unfocusable
|
58
|
-
})), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
|
59
|
-
selectedDate: date,
|
60
|
-
calendarWeekDays: calendarWeekDays,
|
61
|
-
weekDayLabels: weekDayLabels,
|
62
|
-
cellSize: cellSize,
|
63
|
-
width: width,
|
64
|
-
unfocusable: unfocusable
|
65
|
-
}))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
66
|
-
id: "2823859047",
|
67
|
-
dynamic: [backgroundColor, wrapperBorderColor, width]
|
68
|
-
}, [`.calendar-wrapper.__jsx-style-dynamic-selector{font-family:Roboto,sans-serif;font-weight:400;font-size:14px;background-color:${backgroundColor};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;border:1px solid ${wrapperBorderColor};border-radius:3px;min-width:${width};width:-webkit-max-content;width:-moz-max-content;width:max-content;box-shadow:0px 4px 6px -2px #2129340d;box-shadow:0px 10px 15px -3px #2129341a;}`]));
|
69
|
-
});
|
70
|
-
CalendarContainer.defaultProps = {
|
71
|
-
cellSize: '32px',
|
72
|
-
width: '240px',
|
73
|
-
unfocusable: false
|
74
|
-
};
|
75
|
-
CalendarContainer.propTypes = {
|
76
|
-
/** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
|
77
|
-
date: _propTypes.default.string,
|
78
|
-
unfocusable: _propTypes.default.bool,
|
79
|
-
..._calendarTable.CalendarTableProps,
|
80
|
-
..._navigationContainer.NavigationContainerProps
|
81
|
-
};
|
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _react = require("@testing-library/react");
|
4
|
-
var _react2 = _interopRequireDefault(require("react"));
|
5
|
-
var _calendarInput = require("../calendar-input.js");
|
6
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
7
|
-
describe('Calendar Input', () => {
|
8
|
-
it('allow selection of a date through the calendar widget', async () => {
|
9
|
-
const onDateSelectMock = jest.fn();
|
10
|
-
const screen = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_calendarInput.CalendarInput, {
|
11
|
-
calendar: "gregory",
|
12
|
-
onDateSelect: onDateSelectMock
|
13
|
-
}));
|
14
|
-
const dateInput = (0, _react.within)(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
|
15
|
-
_react.fireEvent.focus(dateInput);
|
16
|
-
const calendar = await screen.findByTestId('calendar');
|
17
|
-
expect(calendar).toBeInTheDocument();
|
18
|
-
const todayString = new Date().toISOString().slice(0, -14);
|
19
|
-
const today = (0, _react.within)(calendar).getByTestId(todayString);
|
20
|
-
_react.fireEvent.click(today);
|
21
|
-
await (0, _react.waitFor)(() => {
|
22
|
-
expect(calendar).not.toBeInTheDocument();
|
23
|
-
});
|
24
|
-
expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
|
25
|
-
calendarDateString: todayString
|
26
|
-
}));
|
27
|
-
});
|
28
|
-
it('allow selection of a date through the input', async () => {
|
29
|
-
const onDateSelectMock = jest.fn();
|
30
|
-
const screen = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_calendarInput.CalendarInput, {
|
31
|
-
calendar: "gregory",
|
32
|
-
onDateSelect: onDateSelectMock
|
33
|
-
}));
|
34
|
-
const dateInputString = '2024/10/12';
|
35
|
-
const dateInput = (0, _react.within)(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
|
36
|
-
_react.fireEvent.change(dateInput, {
|
37
|
-
target: {
|
38
|
-
value: dateInputString
|
39
|
-
}
|
40
|
-
});
|
41
|
-
_react.fireEvent.blur(dateInput);
|
42
|
-
expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
|
43
|
-
calendarDateString: dateInputString
|
44
|
-
}));
|
45
|
-
});
|
46
|
-
});
|
@@ -1,72 +0,0 @@
|
|
1
|
-
import _JSXStyle from "styled-jsx/style";
|
2
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
3
|
-
import { colors } from '@dhis2/ui-constants';
|
4
|
-
import PropTypes from 'prop-types';
|
5
|
-
import React, { useMemo } from 'react';
|
6
|
-
import { CalendarTable, CalendarTableProps } from './calendar-table.js';
|
7
|
-
import { NavigationContainer, NavigationContainerProps } from './navigation-container.js';
|
8
|
-
const wrapperBorderColor = colors.grey300;
|
9
|
-
const backgroundColor = 'none';
|
10
|
-
export const CalendarContainer = /*#__PURE__*/React.memo(function CalendarContainer(_ref) {
|
11
|
-
let {
|
12
|
-
date,
|
13
|
-
width,
|
14
|
-
cellSize,
|
15
|
-
calendarWeekDays,
|
16
|
-
weekDayLabels,
|
17
|
-
currMonth,
|
18
|
-
currYear,
|
19
|
-
nextMonth,
|
20
|
-
nextYear,
|
21
|
-
prevMonth,
|
22
|
-
prevYear,
|
23
|
-
languageDirection,
|
24
|
-
excludedRef,
|
25
|
-
unfocusable
|
26
|
-
} = _ref;
|
27
|
-
const navigationProps = useMemo(() => {
|
28
|
-
return {
|
29
|
-
currMonth,
|
30
|
-
currYear,
|
31
|
-
nextMonth,
|
32
|
-
nextYear,
|
33
|
-
prevMonth,
|
34
|
-
prevYear,
|
35
|
-
languageDirection
|
36
|
-
};
|
37
|
-
}, [currMonth, currYear, languageDirection, nextMonth, nextYear, prevMonth, prevYear]);
|
38
|
-
return /*#__PURE__*/React.createElement("div", {
|
39
|
-
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
40
|
-
}, /*#__PURE__*/React.createElement("div", {
|
41
|
-
dir: languageDirection,
|
42
|
-
"data-test": "calendar",
|
43
|
-
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
|
44
|
-
}, /*#__PURE__*/React.createElement("div", {
|
45
|
-
ref: excludedRef,
|
46
|
-
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
47
|
-
}, /*#__PURE__*/React.createElement(NavigationContainer, _extends({}, navigationProps, {
|
48
|
-
unfocusable: unfocusable
|
49
|
-
})), /*#__PURE__*/React.createElement(CalendarTable, {
|
50
|
-
selectedDate: date,
|
51
|
-
calendarWeekDays: calendarWeekDays,
|
52
|
-
weekDayLabels: weekDayLabels,
|
53
|
-
cellSize: cellSize,
|
54
|
-
width: width,
|
55
|
-
unfocusable: unfocusable
|
56
|
-
}))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
57
|
-
id: "2823859047",
|
58
|
-
dynamic: [backgroundColor, wrapperBorderColor, width]
|
59
|
-
}, [`.calendar-wrapper.__jsx-style-dynamic-selector{font-family:Roboto,sans-serif;font-weight:400;font-size:14px;background-color:${backgroundColor};display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;border:1px solid ${wrapperBorderColor};border-radius:3px;min-width:${width};width:-webkit-max-content;width:-moz-max-content;width:max-content;box-shadow:0px 4px 6px -2px #2129340d;box-shadow:0px 10px 15px -3px #2129341a;}`]));
|
60
|
-
});
|
61
|
-
CalendarContainer.defaultProps = {
|
62
|
-
cellSize: '32px',
|
63
|
-
width: '240px',
|
64
|
-
unfocusable: false
|
65
|
-
};
|
66
|
-
CalendarContainer.propTypes = {
|
67
|
-
/** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
|
68
|
-
date: PropTypes.string,
|
69
|
-
unfocusable: PropTypes.bool,
|
70
|
-
...CalendarTableProps,
|
71
|
-
...NavigationContainerProps
|
72
|
-
};
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { fireEvent, render, waitFor, within } from '@testing-library/react';
|
2
|
-
import React from 'react';
|
3
|
-
import { CalendarInput } from '../calendar-input.js';
|
4
|
-
describe('Calendar Input', () => {
|
5
|
-
it('allow selection of a date through the calendar widget', async () => {
|
6
|
-
const onDateSelectMock = jest.fn();
|
7
|
-
const screen = render( /*#__PURE__*/React.createElement(CalendarInput, {
|
8
|
-
calendar: "gregory",
|
9
|
-
onDateSelect: onDateSelectMock
|
10
|
-
}));
|
11
|
-
const dateInput = within(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
|
12
|
-
fireEvent.focus(dateInput);
|
13
|
-
const calendar = await screen.findByTestId('calendar');
|
14
|
-
expect(calendar).toBeInTheDocument();
|
15
|
-
const todayString = new Date().toISOString().slice(0, -14);
|
16
|
-
const today = within(calendar).getByTestId(todayString);
|
17
|
-
fireEvent.click(today);
|
18
|
-
await waitFor(() => {
|
19
|
-
expect(calendar).not.toBeInTheDocument();
|
20
|
-
});
|
21
|
-
expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
|
22
|
-
calendarDateString: todayString
|
23
|
-
}));
|
24
|
-
});
|
25
|
-
it('allow selection of a date through the input', async () => {
|
26
|
-
const onDateSelectMock = jest.fn();
|
27
|
-
const screen = render( /*#__PURE__*/React.createElement(CalendarInput, {
|
28
|
-
calendar: "gregory",
|
29
|
-
onDateSelect: onDateSelectMock
|
30
|
-
}));
|
31
|
-
const dateInputString = '2024/10/12';
|
32
|
-
const dateInput = within(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
|
33
|
-
fireEvent.change(dateInput, {
|
34
|
-
target: {
|
35
|
-
value: dateInputString
|
36
|
-
}
|
37
|
-
});
|
38
|
-
fireEvent.blur(dateInput);
|
39
|
-
expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
|
40
|
-
calendarDateString: dateInputString
|
41
|
-
}));
|
42
|
-
});
|
43
|
-
});
|