@dhis2-ui/calendar 10.0.2 → 10.0.3
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/build/cjs/calendar/calendar-container.js +4 -10
- package/build/cjs/calendar/calendar-table-cell.js +2 -5
- package/build/cjs/calendar/calendar-table.js +2 -5
- package/build/cjs/calendar/navigation-container.js +2 -8
- package/build/cjs/calendar-input/calendar-input.js +25 -37
- package/build/cjs/stories/calendar-input.prod.stories.js +17 -9
- package/build/es/calendar/calendar-container.js +4 -10
- package/build/es/calendar/calendar-table-cell.js +2 -5
- package/build/es/calendar/calendar-table.js +2 -5
- package/build/es/calendar/navigation-container.js +2 -8
- package/build/es/calendar-input/calendar-input.js +25 -37
- package/build/es/stories/calendar-input.prod.stories.js +17 -9
- package/package.json +8 -8
@@ -13,7 +13,6 @@ var _navigationContainer = require("./navigation-container.js");
|
|
13
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
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
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
16
|
const wrapperBorderColor = _uiConstants.colors.grey300;
|
18
17
|
const backgroundColor = 'none';
|
19
18
|
const CalendarContainer = exports.CalendarContainer = /*#__PURE__*/_react.default.memo(function CalendarContainer(_ref) {
|
@@ -30,8 +29,7 @@ const CalendarContainer = exports.CalendarContainer = /*#__PURE__*/_react.defaul
|
|
30
29
|
prevMonth,
|
31
30
|
prevYear,
|
32
31
|
languageDirection,
|
33
|
-
|
34
|
-
unfocusable = false
|
32
|
+
calendarRef
|
35
33
|
} = _ref;
|
36
34
|
const navigationProps = (0, _react.useMemo)(() => {
|
37
35
|
return {
|
@@ -51,17 +49,14 @@ const CalendarContainer = exports.CalendarContainer = /*#__PURE__*/_react.defaul
|
|
51
49
|
"data-test": "calendar",
|
52
50
|
className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
|
53
51
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
54
|
-
ref:
|
52
|
+
ref: calendarRef,
|
55
53
|
className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
56
|
-
}, /*#__PURE__*/_react.default.createElement(_navigationContainer.NavigationContainer,
|
57
|
-
unfocusable: unfocusable
|
58
|
-
})), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
|
54
|
+
}, /*#__PURE__*/_react.default.createElement(_navigationContainer.NavigationContainer, navigationProps), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
|
59
55
|
selectedDate: date,
|
60
56
|
calendarWeekDays: calendarWeekDays,
|
61
57
|
weekDayLabels: weekDayLabels,
|
62
58
|
cellSize: cellSize,
|
63
|
-
width: width
|
64
|
-
unfocusable: unfocusable
|
59
|
+
width: width
|
65
60
|
}))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
66
61
|
id: "2823859047",
|
67
62
|
dynamic: [backgroundColor, wrapperBorderColor, width]
|
@@ -70,7 +65,6 @@ const CalendarContainer = exports.CalendarContainer = /*#__PURE__*/_react.defaul
|
|
70
65
|
CalendarContainer.propTypes = {
|
71
66
|
/** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
|
72
67
|
date: _propTypes.default.string,
|
73
|
-
unfocusable: _propTypes.default.bool,
|
74
68
|
..._calendarTable.CalendarTableProps,
|
75
69
|
..._navigationContainer.NavigationContainerProps
|
76
70
|
};
|
@@ -14,8 +14,7 @@ const CalendarTableCell = _ref => {
|
|
14
14
|
let {
|
15
15
|
day,
|
16
16
|
cellSize,
|
17
|
-
selectedDate
|
18
|
-
unfocusable
|
17
|
+
selectedDate
|
19
18
|
} = _ref;
|
20
19
|
const dayHoverBackgroundColor = _uiConstants.colors.grey200;
|
21
20
|
const selectedDayBackgroundColor = _uiConstants.colors.teal700;
|
@@ -25,7 +24,6 @@ const CalendarTableCell = _ref => {
|
|
25
24
|
className: _style.default.dynamic([["2052411850", [cellSize, cellSize, cellSize, cellSize, _uiConstants.colors.grey900, dayHoverBackgroundColor, _uiConstants.colors.grey300, selectedDayBackgroundColor, _uiConstants.colors.teal600, _uiConstants.colors.teal200, _uiConstants.colors.grey600]]])
|
26
25
|
}, /*#__PURE__*/_react.default.createElement("button", {
|
27
26
|
name: "day",
|
28
|
-
tabIndex: unfocusable ? -1 : 0,
|
29
27
|
className: _style.default.dynamic([["2052411850", [cellSize, cellSize, cellSize, cellSize, _uiConstants.colors.grey900, dayHoverBackgroundColor, _uiConstants.colors.grey300, selectedDayBackgroundColor, _uiConstants.colors.teal600, _uiConstants.colors.teal200, _uiConstants.colors.grey600]]]) + " " + ((0, _classnames.default)('day', {
|
30
28
|
isSelected: selectedDate === (day === null || day === void 0 ? void 0 : day.dateValue),
|
31
29
|
isToday: day.isToday,
|
@@ -47,6 +45,5 @@ CalendarTableCell.propTypes = {
|
|
47
45
|
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
48
46
|
onClick: _propTypes.default.func
|
49
47
|
}),
|
50
|
-
selectedDate: _propTypes.default.string
|
51
|
-
unfocusable: _propTypes.default.bool
|
48
|
+
selectedDate: _propTypes.default.string
|
52
49
|
};
|
@@ -17,8 +17,7 @@ const CalendarTable = _ref => {
|
|
17
17
|
calendarWeekDays,
|
18
18
|
width,
|
19
19
|
cellSize,
|
20
|
-
selectedDate
|
21
|
-
unfocusable
|
20
|
+
selectedDate
|
22
21
|
} = _ref;
|
23
22
|
return /*#__PURE__*/_react.default.createElement("div", {
|
24
23
|
className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]]) + " " + "calendar-table-wrapper"
|
@@ -36,8 +35,7 @@ const CalendarTable = _ref => {
|
|
36
35
|
day: day,
|
37
36
|
key: day === null || day === void 0 ? void 0 : day.dateValue,
|
38
37
|
cellSize: cellSize,
|
39
|
-
width: width
|
40
|
-
unfocusable: unfocusable
|
38
|
+
width: width
|
41
39
|
})))))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
42
40
|
id: "452536960",
|
43
41
|
dynamic: [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]
|
@@ -56,7 +54,6 @@ const CalendarTableProps = exports.CalendarTableProps = {
|
|
56
54
|
}).isRequired).isRequired).isRequired,
|
57
55
|
cellSize: _propTypes.default.string,
|
58
56
|
selectedDate: _propTypes.default.string,
|
59
|
-
unfocusable: _propTypes.default.bool,
|
60
57
|
weekDayLabels: _propTypes.default.arrayOf(_propTypes.default.string),
|
61
58
|
width: _propTypes.default.string
|
62
59
|
};
|
@@ -22,8 +22,7 @@ const NavigationContainer = _ref => {
|
|
22
22
|
nextMonth,
|
23
23
|
nextYear,
|
24
24
|
prevMonth,
|
25
|
-
prevYear
|
26
|
-
unfocusable
|
25
|
+
prevYear
|
27
26
|
} = _ref;
|
28
27
|
const PreviousIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronLeft16 : _uiIcons.IconChevronRight16;
|
29
28
|
const NextIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronRight16 : _uiIcons.IconChevronLeft16;
|
@@ -43,7 +42,6 @@ const NavigationContainer = _ref => {
|
|
43
42
|
"data-test": "calendar-previous-month",
|
44
43
|
"aria-label": `${_index.default.t(`Go to ${prevMonth.label}`)}`,
|
45
44
|
type: "button",
|
46
|
-
tabIndex: unfocusable ? -1 : 0,
|
47
45
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
48
46
|
}, /*#__PURE__*/_react.default.createElement(PreviousIcon, {
|
49
47
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
@@ -59,7 +57,6 @@ const NavigationContainer = _ref => {
|
|
59
57
|
name: "next-month",
|
60
58
|
"aria-label": `${_index.default.t(`Go to ${nextMonth.label}`)}`,
|
61
59
|
type: "button",
|
62
|
-
tabIndex: unfocusable ? -1 : 0,
|
63
60
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
64
61
|
}, /*#__PURE__*/_react.default.createElement(NextIcon, {
|
65
62
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
@@ -72,7 +69,6 @@ const NavigationContainer = _ref => {
|
|
72
69
|
name: "previous-year",
|
73
70
|
"aria-label": `${_index.default.t('Go to previous year')}`,
|
74
71
|
type: "button",
|
75
|
-
tabIndex: unfocusable ? -1 : 0,
|
76
72
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
77
73
|
}, /*#__PURE__*/_react.default.createElement(PreviousIcon, {
|
78
74
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
@@ -88,7 +84,6 @@ const NavigationContainer = _ref => {
|
|
88
84
|
name: "next-year",
|
89
85
|
"aria-label": `${_index.default.t('Go to next year')}`,
|
90
86
|
type: "button",
|
91
|
-
tabIndex: unfocusable ? -1 : 0,
|
92
87
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
93
88
|
}, /*#__PURE__*/_react.default.createElement(NextIcon, {
|
94
89
|
className: _style.default.dynamic([["1327991300", [_uiConstants.spacers.dp4, wrapperBorderColor, headerBackground, _uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
@@ -121,7 +116,6 @@ const NavigationContainerProps = exports.NavigationContainerProps = {
|
|
121
116
|
prevYear: _propTypes.default.shape({
|
122
117
|
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
123
118
|
navigateTo: _propTypes.default.func
|
124
|
-
})
|
125
|
-
unfocusable: _propTypes.default.bool
|
119
|
+
})
|
126
120
|
};
|
127
121
|
NavigationContainer.propTypes = NavigationContainerProps;
|
@@ -47,9 +47,9 @@ const CalendarInput = function () {
|
|
47
47
|
...rest
|
48
48
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
49
49
|
const ref = (0, _react.useRef)();
|
50
|
+
const calendarRef = (0, _react.useRef)();
|
50
51
|
const [open, setOpen] = (0, _react.useState)(false);
|
51
52
|
const [partialDate, setPartialDate] = (0, _react.useState)(date);
|
52
|
-
const excludeRef = (0, _react.useRef)(null);
|
53
53
|
(0, _react.useEffect)(() => setPartialDate(date), [date]);
|
54
54
|
const useDatePickerOptions = (0, _react.useMemo)(() => ({
|
55
55
|
calendar,
|
@@ -58,8 +58,7 @@ const CalendarInput = function () {
|
|
58
58
|
weekDayFormat
|
59
59
|
}), [calendar, locale, numberingSystem, weekDayFormat]);
|
60
60
|
const onChooseDate = (date, validationOptions) => {
|
61
|
-
|
62
|
-
if (clearable && (date === null || date === '')) {
|
61
|
+
if (!date) {
|
63
62
|
parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
|
64
63
|
calendarDateString: null,
|
65
64
|
validation: {
|
@@ -68,12 +67,6 @@ const CalendarInput = function () {
|
|
68
67
|
});
|
69
68
|
return;
|
70
69
|
}
|
71
|
-
|
72
|
-
// ToDo: This is now a workaround for handling choosing from the date picker
|
73
|
-
// where the blur event gets triggered causing a call with undefined first
|
74
|
-
if (date === undefined) {
|
75
|
-
return;
|
76
|
-
}
|
77
70
|
const validation = (0, _multiCalendarDates.validateDateString)(date, validationOptions);
|
78
71
|
parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
|
79
72
|
calendarDateString: date,
|
@@ -101,10 +94,12 @@ const CalendarInput = function () {
|
|
101
94
|
setPartialDate(e.value);
|
102
95
|
};
|
103
96
|
const handleBlur = (_, e) => {
|
104
|
-
|
105
|
-
if (
|
106
|
-
|
97
|
+
var _calendarRef$current;
|
98
|
+
if (e.relatedTarget && (_calendarRef$current = calendarRef.current) !== null && _calendarRef$current !== void 0 && _calendarRef$current.contains(e.relatedTarget)) {
|
99
|
+
return;
|
107
100
|
}
|
101
|
+
onChooseDate(partialDate, validationOptions);
|
102
|
+
setOpen(false);
|
108
103
|
};
|
109
104
|
const onFocus = () => {
|
110
105
|
var _rest$onFocus;
|
@@ -112,23 +107,21 @@ const CalendarInput = function () {
|
|
112
107
|
rest === null || rest === void 0 ? void 0 : (_rest$onFocus = rest.onFocus) === null || _rest$onFocus === void 0 ? void 0 : _rest$onFocus.call(rest);
|
113
108
|
};
|
114
109
|
const languageDirection = (0, _multiCalendarDates.useResolvedDirection)(dir, locale);
|
115
|
-
const calendarProps = (0, _react.useMemo)(() => {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
};
|
131
|
-
}, [cellSize, date, pickerResults, width, languageDirection]);
|
110
|
+
const calendarProps = (0, _react.useMemo)(() => ({
|
111
|
+
date,
|
112
|
+
width,
|
113
|
+
cellSize,
|
114
|
+
isValid: pickerResults.isValid,
|
115
|
+
calendarWeekDays: pickerResults.calendarWeekDays,
|
116
|
+
weekDayLabels: pickerResults.weekDayLabels,
|
117
|
+
currMonth: pickerResults.currMonth,
|
118
|
+
currYear: pickerResults.currYear,
|
119
|
+
nextMonth: pickerResults.nextMonth,
|
120
|
+
nextYear: pickerResults.nextYear,
|
121
|
+
prevMonth: pickerResults.prevMonth,
|
122
|
+
prevYear: pickerResults.prevYear,
|
123
|
+
languageDirection
|
124
|
+
}), [cellSize, date, pickerResults, width, languageDirection]);
|
132
125
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
133
126
|
ref: ref,
|
134
127
|
className: _style.default.dynamic([["423137534", [inputWidth, rest.error || rest.warning ? '36px' : '6px']]]) + " " + "calendar-input-wrapper"
|
@@ -151,21 +144,16 @@ const CalendarInput = function () {
|
|
151
144
|
dataTest: "calendar-clear-button",
|
152
145
|
secondary: true,
|
153
146
|
small: true,
|
154
|
-
onClick: () =>
|
155
|
-
onChooseDate(null);
|
156
|
-
},
|
147
|
+
onClick: () => onChooseDate(null),
|
157
148
|
type: "button"
|
158
149
|
}, _index.default.t('Clear')))), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
|
159
|
-
onBackdropClick: () =>
|
160
|
-
setOpen(false);
|
161
|
-
}
|
150
|
+
onBackdropClick: () => setOpen(false)
|
162
151
|
}, /*#__PURE__*/_react.default.createElement(_popper.Popper, {
|
163
152
|
reference: ref,
|
164
153
|
placement: "bottom-start",
|
165
154
|
modifiers: [offsetModifier]
|
166
155
|
}, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(_calendarContainer.CalendarContainer, _extends({}, calendarProps, {
|
167
|
-
|
168
|
-
unfocusable: true
|
156
|
+
calendarRef: calendarRef
|
169
157
|
}))))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
170
158
|
id: "423137534",
|
171
159
|
dynamic: [inputWidth, rest.error || rest.warning ? '36px' : '6px']
|
@@ -123,22 +123,30 @@ const CalendarWithClearButton = _ref2 => {
|
|
123
123
|
};
|
124
124
|
exports.CalendarWithClearButton = CalendarWithClearButton;
|
125
125
|
function CalendarWithEditiableInput() {
|
126
|
-
const [date, setDate] = (0, _react.useState)('
|
127
|
-
|
126
|
+
const [date, setDate] = (0, _react.useState)('');
|
127
|
+
const [validation, setValidation] = (0, _react.useState)({});
|
128
|
+
const errorProps = {
|
129
|
+
error: !!(validation !== null && validation !== void 0 && validation.error),
|
130
|
+
validationText: validation === null || validation === void 0 ? void 0 : validation.validationText
|
131
|
+
};
|
132
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_calendarInput.CalendarInput, _extends({
|
128
133
|
date: date,
|
129
134
|
calendar: "gregory",
|
130
|
-
onDateSelect:
|
131
|
-
const
|
132
|
-
|
135
|
+
onDateSelect: result => {
|
136
|
+
const {
|
137
|
+
calendarDateString,
|
138
|
+
validation
|
139
|
+
} = result || {};
|
140
|
+
setDate(calendarDateString);
|
141
|
+
setValidation(validation);
|
133
142
|
},
|
134
143
|
onFocus: () => {
|
135
144
|
console.log('focused');
|
136
145
|
},
|
137
|
-
width: "400px"
|
138
|
-
|
139
|
-
maxDate: "2020-07-09",
|
146
|
+
width: "400px"
|
147
|
+
}, errorProps, {
|
140
148
|
clearable: true
|
141
|
-
})));
|
149
|
+
}))));
|
142
150
|
}
|
143
151
|
function CalendarWithStrictValidation() {
|
144
152
|
const [validation, setValidation] = (0, _react.useState)({});
|
@@ -1,5 +1,4 @@
|
|
1
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
2
|
import { colors } from '@dhis2/ui-constants';
|
4
3
|
import PropTypes from 'prop-types';
|
5
4
|
import React, { useMemo } from 'react';
|
@@ -21,8 +20,7 @@ export const CalendarContainer = /*#__PURE__*/React.memo(function CalendarContai
|
|
21
20
|
prevMonth,
|
22
21
|
prevYear,
|
23
22
|
languageDirection,
|
24
|
-
|
25
|
-
unfocusable = false
|
23
|
+
calendarRef
|
26
24
|
} = _ref;
|
27
25
|
const navigationProps = useMemo(() => {
|
28
26
|
return {
|
@@ -42,17 +40,14 @@ export const CalendarContainer = /*#__PURE__*/React.memo(function CalendarContai
|
|
42
40
|
"data-test": "calendar",
|
43
41
|
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
|
44
42
|
}, /*#__PURE__*/React.createElement("div", {
|
45
|
-
ref:
|
43
|
+
ref: calendarRef,
|
46
44
|
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
47
|
-
}, /*#__PURE__*/React.createElement(NavigationContainer,
|
48
|
-
unfocusable: unfocusable
|
49
|
-
})), /*#__PURE__*/React.createElement(CalendarTable, {
|
45
|
+
}, /*#__PURE__*/React.createElement(NavigationContainer, navigationProps), /*#__PURE__*/React.createElement(CalendarTable, {
|
50
46
|
selectedDate: date,
|
51
47
|
calendarWeekDays: calendarWeekDays,
|
52
48
|
weekDayLabels: weekDayLabels,
|
53
49
|
cellSize: cellSize,
|
54
|
-
width: width
|
55
|
-
unfocusable: unfocusable
|
50
|
+
width: width
|
56
51
|
}))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
57
52
|
id: "2823859047",
|
58
53
|
dynamic: [backgroundColor, wrapperBorderColor, width]
|
@@ -61,7 +56,6 @@ export const CalendarContainer = /*#__PURE__*/React.memo(function CalendarContai
|
|
61
56
|
CalendarContainer.propTypes = {
|
62
57
|
/** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
|
63
58
|
date: PropTypes.string,
|
64
|
-
unfocusable: PropTypes.bool,
|
65
59
|
...CalendarTableProps,
|
66
60
|
...NavigationContainerProps
|
67
61
|
};
|
@@ -7,8 +7,7 @@ export const CalendarTableCell = _ref => {
|
|
7
7
|
let {
|
8
8
|
day,
|
9
9
|
cellSize,
|
10
|
-
selectedDate
|
11
|
-
unfocusable
|
10
|
+
selectedDate
|
12
11
|
} = _ref;
|
13
12
|
const dayHoverBackgroundColor = colors.grey200;
|
14
13
|
const selectedDayBackgroundColor = colors.teal700;
|
@@ -18,7 +17,6 @@ export const CalendarTableCell = _ref => {
|
|
18
17
|
className: _JSXStyle.dynamic([["2052411850", [cellSize, cellSize, cellSize, cellSize, colors.grey900, dayHoverBackgroundColor, colors.grey300, selectedDayBackgroundColor, colors.teal600, colors.teal200, colors.grey600]]])
|
19
18
|
}, /*#__PURE__*/React.createElement("button", {
|
20
19
|
name: "day",
|
21
|
-
tabIndex: unfocusable ? -1 : 0,
|
22
20
|
className: _JSXStyle.dynamic([["2052411850", [cellSize, cellSize, cellSize, cellSize, colors.grey900, dayHoverBackgroundColor, colors.grey300, selectedDayBackgroundColor, colors.teal600, colors.teal200, colors.grey600]]]) + " " + (cx('day', {
|
23
21
|
isSelected: selectedDate === (day === null || day === void 0 ? void 0 : day.dateValue),
|
24
22
|
isToday: day.isToday,
|
@@ -39,6 +37,5 @@ CalendarTableCell.propTypes = {
|
|
39
37
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
40
38
|
onClick: PropTypes.func
|
41
39
|
}),
|
42
|
-
selectedDate: PropTypes.string
|
43
|
-
unfocusable: PropTypes.bool
|
40
|
+
selectedDate: PropTypes.string
|
44
41
|
};
|
@@ -10,8 +10,7 @@ export const CalendarTable = _ref => {
|
|
10
10
|
calendarWeekDays,
|
11
11
|
width,
|
12
12
|
cellSize,
|
13
|
-
selectedDate
|
14
|
-
unfocusable
|
13
|
+
selectedDate
|
15
14
|
} = _ref;
|
16
15
|
return /*#__PURE__*/React.createElement("div", {
|
17
16
|
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]]) + " " + "calendar-table-wrapper"
|
@@ -29,8 +28,7 @@ export const CalendarTable = _ref => {
|
|
29
28
|
day: day,
|
30
29
|
key: day === null || day === void 0 ? void 0 : day.dateValue,
|
31
30
|
cellSize: cellSize,
|
32
|
-
width: width
|
33
|
-
unfocusable: unfocusable
|
31
|
+
width: width
|
34
32
|
})))))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
35
33
|
id: "452536960",
|
36
34
|
dynamic: [spacers.dp4, spacers.dp4]
|
@@ -48,7 +46,6 @@ export const CalendarTableProps = {
|
|
48
46
|
}).isRequired).isRequired).isRequired,
|
49
47
|
cellSize: PropTypes.string,
|
50
48
|
selectedDate: PropTypes.string,
|
51
|
-
unfocusable: PropTypes.bool,
|
52
49
|
weekDayLabels: PropTypes.arrayOf(PropTypes.string),
|
53
50
|
width: PropTypes.string
|
54
51
|
};
|
@@ -15,8 +15,7 @@ export const NavigationContainer = _ref => {
|
|
15
15
|
nextMonth,
|
16
16
|
nextYear,
|
17
17
|
prevMonth,
|
18
|
-
prevYear
|
19
|
-
unfocusable
|
18
|
+
prevYear
|
20
19
|
} = _ref;
|
21
20
|
const PreviousIcon = languageDirection === 'ltr' ? IconChevronLeft16 : IconChevronRight16;
|
22
21
|
const NextIcon = languageDirection === 'ltr' ? IconChevronRight16 : IconChevronLeft16;
|
@@ -36,7 +35,6 @@ export const NavigationContainer = _ref => {
|
|
36
35
|
"data-test": "calendar-previous-month",
|
37
36
|
"aria-label": `${i18n.t(`Go to ${prevMonth.label}`)}`,
|
38
37
|
type: "button",
|
39
|
-
tabIndex: unfocusable ? -1 : 0,
|
40
38
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
41
39
|
}, /*#__PURE__*/React.createElement(PreviousIcon, {
|
42
40
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
@@ -52,7 +50,6 @@ export const NavigationContainer = _ref => {
|
|
52
50
|
name: "next-month",
|
53
51
|
"aria-label": `${i18n.t(`Go to ${nextMonth.label}`)}`,
|
54
52
|
type: "button",
|
55
|
-
tabIndex: unfocusable ? -1 : 0,
|
56
53
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
57
54
|
}, /*#__PURE__*/React.createElement(NextIcon, {
|
58
55
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
@@ -65,7 +62,6 @@ export const NavigationContainer = _ref => {
|
|
65
62
|
name: "previous-year",
|
66
63
|
"aria-label": `${i18n.t('Go to previous year')}`,
|
67
64
|
type: "button",
|
68
|
-
tabIndex: unfocusable ? -1 : 0,
|
69
65
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
70
66
|
}, /*#__PURE__*/React.createElement(PreviousIcon, {
|
71
67
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
@@ -81,7 +77,6 @@ export const NavigationContainer = _ref => {
|
|
81
77
|
name: "next-year",
|
82
78
|
"aria-label": `${i18n.t('Go to next year')}`,
|
83
79
|
type: "button",
|
84
|
-
tabIndex: unfocusable ? -1 : 0,
|
85
80
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
86
81
|
}, /*#__PURE__*/React.createElement(NextIcon, {
|
87
82
|
className: _JSXStyle.dynamic([["1327991300", [spacers.dp4, wrapperBorderColor, headerBackground, spacers.dp4, colors.grey600, colors.grey200, colors.grey900, colors.grey300, spacers.dp4, spacers.dp8]]])
|
@@ -113,7 +108,6 @@ export const NavigationContainerProps = {
|
|
113
108
|
prevYear: PropTypes.shape({
|
114
109
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
115
110
|
navigateTo: PropTypes.func
|
116
|
-
})
|
117
|
-
unfocusable: PropTypes.bool
|
111
|
+
})
|
118
112
|
};
|
119
113
|
NavigationContainer.propTypes = NavigationContainerProps;
|
@@ -38,9 +38,9 @@ export const CalendarInput = function () {
|
|
38
38
|
...rest
|
39
39
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
40
40
|
const ref = useRef();
|
41
|
+
const calendarRef = useRef();
|
41
42
|
const [open, setOpen] = useState(false);
|
42
43
|
const [partialDate, setPartialDate] = useState(date);
|
43
|
-
const excludeRef = useRef(null);
|
44
44
|
useEffect(() => setPartialDate(date), [date]);
|
45
45
|
const useDatePickerOptions = useMemo(() => ({
|
46
46
|
calendar,
|
@@ -49,8 +49,7 @@ export const CalendarInput = function () {
|
|
49
49
|
weekDayFormat
|
50
50
|
}), [calendar, locale, numberingSystem, weekDayFormat]);
|
51
51
|
const onChooseDate = (date, validationOptions) => {
|
52
|
-
|
53
|
-
if (clearable && (date === null || date === '')) {
|
52
|
+
if (!date) {
|
54
53
|
parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
|
55
54
|
calendarDateString: null,
|
56
55
|
validation: {
|
@@ -59,12 +58,6 @@ export const CalendarInput = function () {
|
|
59
58
|
});
|
60
59
|
return;
|
61
60
|
}
|
62
|
-
|
63
|
-
// ToDo: This is now a workaround for handling choosing from the date picker
|
64
|
-
// where the blur event gets triggered causing a call with undefined first
|
65
|
-
if (date === undefined) {
|
66
|
-
return;
|
67
|
-
}
|
68
61
|
const validation = validateDateString(date, validationOptions);
|
69
62
|
parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
|
70
63
|
calendarDateString: date,
|
@@ -92,10 +85,12 @@ export const CalendarInput = function () {
|
|
92
85
|
setPartialDate(e.value);
|
93
86
|
};
|
94
87
|
const handleBlur = (_, e) => {
|
95
|
-
|
96
|
-
if (
|
97
|
-
|
88
|
+
var _calendarRef$current;
|
89
|
+
if (e.relatedTarget && (_calendarRef$current = calendarRef.current) !== null && _calendarRef$current !== void 0 && _calendarRef$current.contains(e.relatedTarget)) {
|
90
|
+
return;
|
98
91
|
}
|
92
|
+
onChooseDate(partialDate, validationOptions);
|
93
|
+
setOpen(false);
|
99
94
|
};
|
100
95
|
const onFocus = () => {
|
101
96
|
var _rest$onFocus;
|
@@ -103,23 +98,21 @@ export const CalendarInput = function () {
|
|
103
98
|
rest === null || rest === void 0 ? void 0 : (_rest$onFocus = rest.onFocus) === null || _rest$onFocus === void 0 ? void 0 : _rest$onFocus.call(rest);
|
104
99
|
};
|
105
100
|
const languageDirection = useResolvedDirection(dir, locale);
|
106
|
-
const calendarProps = useMemo(() => {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
};
|
122
|
-
}, [cellSize, date, pickerResults, width, languageDirection]);
|
101
|
+
const calendarProps = useMemo(() => ({
|
102
|
+
date,
|
103
|
+
width,
|
104
|
+
cellSize,
|
105
|
+
isValid: pickerResults.isValid,
|
106
|
+
calendarWeekDays: pickerResults.calendarWeekDays,
|
107
|
+
weekDayLabels: pickerResults.weekDayLabels,
|
108
|
+
currMonth: pickerResults.currMonth,
|
109
|
+
currYear: pickerResults.currYear,
|
110
|
+
nextMonth: pickerResults.nextMonth,
|
111
|
+
nextYear: pickerResults.nextYear,
|
112
|
+
prevMonth: pickerResults.prevMonth,
|
113
|
+
prevYear: pickerResults.prevYear,
|
114
|
+
languageDirection
|
115
|
+
}), [cellSize, date, pickerResults, width, languageDirection]);
|
123
116
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
124
117
|
ref: ref,
|
125
118
|
className: _JSXStyle.dynamic([["423137534", [inputWidth, rest.error || rest.warning ? '36px' : '6px']]]) + " " + "calendar-input-wrapper"
|
@@ -142,21 +135,16 @@ export const CalendarInput = function () {
|
|
142
135
|
dataTest: "calendar-clear-button",
|
143
136
|
secondary: true,
|
144
137
|
small: true,
|
145
|
-
onClick: () =>
|
146
|
-
onChooseDate(null);
|
147
|
-
},
|
138
|
+
onClick: () => onChooseDate(null),
|
148
139
|
type: "button"
|
149
140
|
}, i18n.t('Clear')))), open && /*#__PURE__*/React.createElement(Layer, {
|
150
|
-
onBackdropClick: () =>
|
151
|
-
setOpen(false);
|
152
|
-
}
|
141
|
+
onBackdropClick: () => setOpen(false)
|
153
142
|
}, /*#__PURE__*/React.createElement(Popper, {
|
154
143
|
reference: ref,
|
155
144
|
placement: "bottom-start",
|
156
145
|
modifiers: [offsetModifier]
|
157
146
|
}, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(CalendarContainer, _extends({}, calendarProps, {
|
158
|
-
|
159
|
-
unfocusable: true
|
147
|
+
calendarRef: calendarRef
|
160
148
|
}))))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
161
149
|
id: "423137534",
|
162
150
|
dynamic: [inputWidth, rest.error || rest.warning ? '36px' : '6px']
|
@@ -109,22 +109,30 @@ export const CalendarWithClearButton = _ref2 => {
|
|
109
109
|
}, date !== null && date !== void 0 ? date : 'undefined')));
|
110
110
|
};
|
111
111
|
export function CalendarWithEditiableInput() {
|
112
|
-
const [date, setDate] = useState('
|
113
|
-
|
112
|
+
const [date, setDate] = useState('');
|
113
|
+
const [validation, setValidation] = useState({});
|
114
|
+
const errorProps = {
|
115
|
+
error: !!(validation !== null && validation !== void 0 && validation.error),
|
116
|
+
validationText: validation === null || validation === void 0 ? void 0 : validation.validationText
|
117
|
+
};
|
118
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CalendarInput, _extends({
|
114
119
|
date: date,
|
115
120
|
calendar: "gregory",
|
116
|
-
onDateSelect:
|
117
|
-
const
|
118
|
-
|
121
|
+
onDateSelect: result => {
|
122
|
+
const {
|
123
|
+
calendarDateString,
|
124
|
+
validation
|
125
|
+
} = result || {};
|
126
|
+
setDate(calendarDateString);
|
127
|
+
setValidation(validation);
|
119
128
|
},
|
120
129
|
onFocus: () => {
|
121
130
|
console.log('focused');
|
122
131
|
},
|
123
|
-
width: "400px"
|
124
|
-
|
125
|
-
maxDate: "2020-07-09",
|
132
|
+
width: "400px"
|
133
|
+
}, errorProps, {
|
126
134
|
clearable: true
|
127
|
-
})));
|
135
|
+
}))));
|
128
136
|
}
|
129
137
|
export function CalendarWithStrictValidation() {
|
130
138
|
const [validation, setValidation] = useState({});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dhis2-ui/calendar",
|
3
|
-
"version": "10.0.
|
3
|
+
"version": "10.0.3",
|
4
4
|
"description": "UI Calendar",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -33,15 +33,15 @@
|
|
33
33
|
"styled-jsx": "^4"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@dhis2-ui/button": "10.0.
|
37
|
-
"@dhis2-ui/card": "10.0.
|
38
|
-
"@dhis2-ui/input": "10.0.
|
39
|
-
"@dhis2-ui/layer": "10.0.
|
40
|
-
"@dhis2-ui/popper": "10.0.
|
36
|
+
"@dhis2-ui/button": "10.0.3",
|
37
|
+
"@dhis2-ui/card": "10.0.3",
|
38
|
+
"@dhis2-ui/input": "10.0.3",
|
39
|
+
"@dhis2-ui/layer": "10.0.3",
|
40
|
+
"@dhis2-ui/popper": "10.0.3",
|
41
41
|
"@dhis2/multi-calendar-dates": "2.0.0",
|
42
42
|
"@dhis2/prop-types": "^3.1.2",
|
43
|
-
"@dhis2/ui-constants": "10.0.
|
44
|
-
"@dhis2/ui-icons": "10.0.
|
43
|
+
"@dhis2/ui-constants": "10.0.3",
|
44
|
+
"@dhis2/ui-icons": "10.0.3",
|
45
45
|
"classnames": "^2.3.1",
|
46
46
|
"prop-types": "^15.7.2"
|
47
47
|
},
|