@dhis2-ui/calendar 8.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -0
- package/build/cjs/__e2e__/calendarInput.stories.e2e.js +58 -0
- package/build/cjs/calendar/calendar-prop-types.js +24 -0
- package/build/cjs/calendar/calendar-table-cell.js +55 -0
- package/build/cjs/calendar/calendar-table-days-header.js +40 -0
- package/build/cjs/calendar/calendar-table.js +57 -0
- package/build/cjs/calendar/index.js +93 -0
- package/build/cjs/calendar/navigation-container.js +134 -0
- package/build/cjs/calendar-input/index.js +117 -0
- package/build/cjs/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +39 -0
- package/build/cjs/features/supports_ethiopic_calendar.feature +19 -0
- package/build/cjs/features/supports_gregorian_calendar/supports_gregorian_calendar.js +39 -0
- package/build/cjs/features/supports_gregorian_calendar.feature +19 -0
- package/build/cjs/features/supports_islamic_calendar/supports_islamic_calendar.js +18 -0
- package/build/cjs/features/supports_islamic_calendar.feature +5 -0
- package/build/cjs/features/supports_nepali_calendar/supports_nepali_calendar.js +42 -0
- package/build/cjs/features/supports_nepali_calendar.feature +19 -0
- package/build/cjs/index.js +21 -0
- package/build/cjs/locales/en/translations.json +4 -0
- package/build/cjs/locales/index.js +27 -0
- package/build/cjs/stories/calendar.stories.js +66 -0
- package/build/cjs/stories/calendarInput.stories.js +107 -0
- package/build/cjs/stories/calendarStoryWrapper.js +196 -0
- package/build/es/__e2e__/calendarInput.stories.e2e.js +6 -0
- package/build/es/calendar/calendar-prop-types.js +13 -0
- package/build/es/calendar/calendar-table-cell.js +39 -0
- package/build/es/calendar/calendar-table-days-header.js +25 -0
- package/build/es/calendar/calendar-table.js +40 -0
- package/build/es/calendar/index.js +71 -0
- package/build/es/calendar/navigation-container.js +116 -0
- package/build/es/calendar-input/index.js +95 -0
- package/build/es/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +36 -0
- package/build/es/features/supports_ethiopic_calendar.feature +19 -0
- package/build/es/features/supports_gregorian_calendar/supports_gregorian_calendar.js +36 -0
- package/build/es/features/supports_gregorian_calendar.feature +19 -0
- package/build/es/features/supports_islamic_calendar/supports_islamic_calendar.js +15 -0
- package/build/es/features/supports_islamic_calendar.feature +5 -0
- package/build/es/features/supports_nepali_calendar/supports_nepali_calendar.js +39 -0
- package/build/es/features/supports_nepali_calendar.feature +19 -0
- package/build/es/index.js +2 -0
- package/build/es/locales/en/translations.json +4 -0
- package/build/es/locales/index.js +13 -0
- package/build/es/stories/calendar.stories.js +44 -0
- package/build/es/stories/calendarInput.stories.js +84 -0
- package/build/es/stories/calendarStoryWrapper.js +176 -0
- package/package.json +53 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
import _JSXStyle from "styled-jsx/style";
|
2
|
+
import { spacers } from '@dhis2/ui-constants';
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
import React from 'react';
|
5
|
+
import { CalendarTableCell } from './calendar-table-cell.js';
|
6
|
+
import { CalendarTableDaysHeader } from './calendar-table-days-header.js';
|
7
|
+
export const CalendarTable = _ref => {
|
8
|
+
let {
|
9
|
+
weekDayLabels,
|
10
|
+
calendarWeekDays,
|
11
|
+
width,
|
12
|
+
cellSize
|
13
|
+
} = _ref;
|
14
|
+
return /*#__PURE__*/React.createElement("div", {
|
15
|
+
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]]) + " " + "calendar-table-wrapper"
|
16
|
+
}, /*#__PURE__*/React.createElement("table", {
|
17
|
+
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]]) + " " + "calendar-table"
|
18
|
+
}, /*#__PURE__*/React.createElement(CalendarTableDaysHeader, {
|
19
|
+
weekDayLabels: weekDayLabels
|
20
|
+
}), /*#__PURE__*/React.createElement("tbody", {
|
21
|
+
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]])
|
22
|
+
}, calendarWeekDays.map((week, weekIndex) => /*#__PURE__*/React.createElement("tr", {
|
23
|
+
key: "week-".concat(weekIndex + 1),
|
24
|
+
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]])
|
25
|
+
}, week.map(day => /*#__PURE__*/React.createElement(CalendarTableCell, {
|
26
|
+
day: day,
|
27
|
+
key: day === null || day === void 0 ? void 0 : day.calendarDate,
|
28
|
+
cellSize: cellSize,
|
29
|
+
width: width
|
30
|
+
})))))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
31
|
+
id: "452536960",
|
32
|
+
dynamic: [spacers.dp4, spacers.dp4]
|
33
|
+
}, [".calendar-table.__jsx-style-dynamic-selector{border:none;border-collapse:collapse;width:100%;margin-block:".concat(spacers.dp4, ";}"), ".calendar-table.__jsx-style-dynamic-selector tr.__jsx-style-dynamic-selector,.calendar-table.__jsx-style-dynamic-selector td.__jsx-style-dynamic-selector{border:none;}", ".calendar-table-wrapper.__jsx-style-dynamic-selector{padding-inline:".concat(spacers.dp4, ";}")]));
|
34
|
+
};
|
35
|
+
CalendarTable.propTypes = {
|
36
|
+
calendarWeekDays: PropTypes.arrayOf(PropTypes.string),
|
37
|
+
cellSize: PropTypes.string,
|
38
|
+
weekDayLabels: PropTypes.arrayOf(PropTypes.string),
|
39
|
+
width: PropTypes.string
|
40
|
+
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import _JSXStyle from "styled-jsx/style";
|
2
|
+
import { useDatePicker, useResolvedDirection } from '@dhis2/multi-calendar-dates';
|
3
|
+
import { colors } from '@dhis2/ui-constants';
|
4
|
+
import React, { useState } from 'react';
|
5
|
+
import { CalendarProps } from './calendar-prop-types.js';
|
6
|
+
import { CalendarTable } from './calendar-table.js';
|
7
|
+
import { NavigationContainer } from './navigation-container.js';
|
8
|
+
export const Calendar = _ref => {
|
9
|
+
let {
|
10
|
+
onDateSelect,
|
11
|
+
calendar,
|
12
|
+
date,
|
13
|
+
dir,
|
14
|
+
locale,
|
15
|
+
numberingSystem,
|
16
|
+
weekDayFormat,
|
17
|
+
timeZone,
|
18
|
+
width,
|
19
|
+
cellSize
|
20
|
+
} = _ref;
|
21
|
+
const wrapperBorderColor = colors.grey300;
|
22
|
+
const backgroundColor = 'none';
|
23
|
+
const [selectedDateString, setSelectedDateString] = useState(date);
|
24
|
+
const languageDirection = useResolvedDirection(dir, locale);
|
25
|
+
const options = {
|
26
|
+
locale,
|
27
|
+
calendar,
|
28
|
+
timeZone,
|
29
|
+
numberingSystem,
|
30
|
+
weekDayFormat
|
31
|
+
};
|
32
|
+
const pickerOptions = useDatePicker({
|
33
|
+
onDateSelect: result => {
|
34
|
+
const {
|
35
|
+
calendarDateString
|
36
|
+
} = result;
|
37
|
+
setSelectedDateString(calendarDateString);
|
38
|
+
onDateSelect(result);
|
39
|
+
},
|
40
|
+
date: selectedDateString,
|
41
|
+
options
|
42
|
+
});
|
43
|
+
const {
|
44
|
+
calendarWeekDays,
|
45
|
+
weekDayLabels
|
46
|
+
} = pickerOptions;
|
47
|
+
return /*#__PURE__*/React.createElement("div", {
|
48
|
+
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
|
49
|
+
}, /*#__PURE__*/React.createElement("div", {
|
50
|
+
dir: languageDirection,
|
51
|
+
"data-test": "calendar",
|
52
|
+
className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
|
53
|
+
}, /*#__PURE__*/React.createElement(NavigationContainer, {
|
54
|
+
pickerOptions: pickerOptions,
|
55
|
+
languageDirection: languageDirection
|
56
|
+
}), /*#__PURE__*/React.createElement(CalendarTable, {
|
57
|
+
calendarWeekDays: calendarWeekDays,
|
58
|
+
weekDayLabels: weekDayLabels,
|
59
|
+
cellSize: cellSize,
|
60
|
+
width: width
|
61
|
+
})), /*#__PURE__*/React.createElement(_JSXStyle, {
|
62
|
+
id: "2823859047",
|
63
|
+
dynamic: [backgroundColor, wrapperBorderColor, width]
|
64
|
+
}, [".calendar-wrapper.__jsx-style-dynamic-selector{font-family:Roboto,sans-serif;font-weight:400;font-size:14px;background-color:".concat(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 ").concat(wrapperBorderColor, ";border-radius:3px;min-width:").concat(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;}")]));
|
65
|
+
};
|
66
|
+
Calendar.defaultProps = {
|
67
|
+
cellSize: '32px',
|
68
|
+
width: '240px',
|
69
|
+
weekDayFormat: 'narrow'
|
70
|
+
};
|
71
|
+
Calendar.propTypes = CalendarProps;
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import _JSXStyle from "styled-jsx/style";
|
2
|
+
import { colors, spacers } from '@dhis2/ui-constants';
|
3
|
+
import { IconChevronLeft16, IconChevronRight16 } from '@dhis2/ui-icons';
|
4
|
+
import PropTypes from 'prop-types';
|
5
|
+
import React from 'react';
|
6
|
+
import i18n from '../locales/index.js';
|
7
|
+
const chevronColor = colors.grey600;
|
8
|
+
const wrapperBorderColor = colors.grey300;
|
9
|
+
const headerBackground = colors.grey050;
|
10
|
+
export const NavigationContainer = _ref => {
|
11
|
+
let {
|
12
|
+
languageDirection,
|
13
|
+
pickerOptions
|
14
|
+
} = _ref;
|
15
|
+
const PreviousIcon = languageDirection === 'ltr' ? IconChevronLeft16 : IconChevronRight16;
|
16
|
+
const NextIcon = languageDirection === 'ltr' ? IconChevronRight16 : IconChevronLeft16;
|
17
|
+
const {
|
18
|
+
currMonth,
|
19
|
+
currYear,
|
20
|
+
nextMonth,
|
21
|
+
nextYear,
|
22
|
+
prevMonth,
|
23
|
+
prevYear
|
24
|
+
} = pickerOptions;
|
25
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
26
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "navigation-container"
|
27
|
+
}, /*#__PURE__*/React.createElement("div", {
|
28
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "month"
|
29
|
+
}, /*#__PURE__*/React.createElement("div", {
|
30
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "prev"
|
31
|
+
}, /*#__PURE__*/React.createElement("button", {
|
32
|
+
onClick: prevMonth.navigateTo,
|
33
|
+
name: "previous-month",
|
34
|
+
"data-test": "calendar-previous-month",
|
35
|
+
"aria-label": "".concat(i18n.t("Go to ".concat(prevMonth.label))),
|
36
|
+
type: "button",
|
37
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
38
|
+
}, /*#__PURE__*/React.createElement(PreviousIcon, {
|
39
|
+
color: chevronColor,
|
40
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
41
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
42
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "curr"
|
43
|
+
}, /*#__PURE__*/React.createElement("span", {
|
44
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "label"
|
45
|
+
}, currMonth.label)), /*#__PURE__*/React.createElement("div", {
|
46
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "next"
|
47
|
+
}, /*#__PURE__*/React.createElement("button", {
|
48
|
+
onClick: nextMonth.navigateTo,
|
49
|
+
"data-test": "calendar-next-month",
|
50
|
+
name: "next-month",
|
51
|
+
"aria-label": "".concat(i18n.t("Go to ".concat(nextMonth.label))),
|
52
|
+
type: "button",
|
53
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
54
|
+
}, /*#__PURE__*/React.createElement(NextIcon, {
|
55
|
+
color: chevronColor,
|
56
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
57
|
+
})))), /*#__PURE__*/React.createElement("div", {
|
58
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "year"
|
59
|
+
}, /*#__PURE__*/React.createElement("div", {
|
60
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "prev"
|
61
|
+
}, /*#__PURE__*/React.createElement("button", {
|
62
|
+
onClick: prevYear.navigateTo,
|
63
|
+
name: "previous-year",
|
64
|
+
"aria-label": "".concat(i18n.t('Go to previous year')),
|
65
|
+
type: "button",
|
66
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
67
|
+
}, /*#__PURE__*/React.createElement(PreviousIcon, {
|
68
|
+
color: chevronColor,
|
69
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
70
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
71
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "curr"
|
72
|
+
}, /*#__PURE__*/React.createElement("span", {
|
73
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "label"
|
74
|
+
}, currYear.label)), /*#__PURE__*/React.createElement("div", {
|
75
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "next"
|
76
|
+
}, /*#__PURE__*/React.createElement("button", {
|
77
|
+
onClick: nextYear.navigateTo,
|
78
|
+
name: "next-year",
|
79
|
+
"aria-label": "".concat(i18n.t('Go to next year')),
|
80
|
+
type: "button",
|
81
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
82
|
+
}, /*#__PURE__*/React.createElement(NextIcon, {
|
83
|
+
color: chevronColor,
|
84
|
+
className: _JSXStyle.dynamic([["4112940194", [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]]])
|
85
|
+
}))))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
86
|
+
id: "4112940194",
|
87
|
+
dynamic: [spacers.dp4, colors.grey200, spacers.dp36, spacers.dp8, spacers.dp4, wrapperBorderColor, headerBackground]
|
88
|
+
}, ["button.__jsx-style-dynamic-selector{background:none;border:0;}", ".month.__jsx-style-dynamic-selector,.year.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;width:100%;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}", ".month.__jsx-style-dynamic-selector .curr.__jsx-style-dynamic-selector,.year.__jsx-style-dynamic-selector .curr.__jsx-style-dynamic-selector{-webkit-flex:2;-ms-flex:2;flex:2;white-space:nowrap;}", ".prev.__jsx-style-dynamic-selector,.next.__jsx-style-dynamic-selector{-webkit-flex:1;-ms-flex:1;flex:1;text-align:center;}", ".prev.__jsx-style-dynamic-selector button.__jsx-style-dynamic-selector,.next.__jsx-style-dynamic-selector button.__jsx-style-dynamic-selector{padding:".concat(spacers.dp4, ";}"), ".prev.__jsx-style-dynamic-selector:hover button.__jsx-style-dynamic-selector,.next.__jsx-style-dynamic-selector:hover button.__jsx-style-dynamic-selector{background-color:".concat(colors.grey200, ";cursor:pointer;}"), ".label.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:4px 8px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;min-height:16px;}", ".navigation-container.__jsx-style-dynamic-selector{height:".concat(spacers.dp36, ";gap:").concat(spacers.dp8, ";padding:").concat(spacers.dp4, ";display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;border-bottom:1px solid ").concat(wrapperBorderColor, ";background-color:").concat(headerBackground, ";font-size:1.08em;}")]));
|
89
|
+
};
|
90
|
+
NavigationContainer.propTypes = {
|
91
|
+
languageDirection: PropTypes.oneOf(['ltr', 'rtl']),
|
92
|
+
pickerOptions: PropTypes.shape({
|
93
|
+
currMonth: PropTypes.shape({
|
94
|
+
label: PropTypes.string
|
95
|
+
}),
|
96
|
+
currYear: PropTypes.shape({
|
97
|
+
label: PropTypes.string
|
98
|
+
}),
|
99
|
+
nextMonth: PropTypes.shape({
|
100
|
+
label: PropTypes.string,
|
101
|
+
navigateTo: PropTypes.func
|
102
|
+
}),
|
103
|
+
nextYear: PropTypes.shape({
|
104
|
+
label: PropTypes.string,
|
105
|
+
navigateTo: PropTypes.func
|
106
|
+
}),
|
107
|
+
prevMonth: PropTypes.shape({
|
108
|
+
label: PropTypes.string,
|
109
|
+
navigateTo: PropTypes.func
|
110
|
+
}),
|
111
|
+
prevYear: PropTypes.shape({
|
112
|
+
label: PropTypes.string,
|
113
|
+
navigateTo: PropTypes.func
|
114
|
+
})
|
115
|
+
})
|
116
|
+
};
|
@@ -0,0 +1,95 @@
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
|
+
|
3
|
+
import { Card } from '@dhis2-ui/card';
|
4
|
+
import { InputField, InputFieldProps } from '@dhis2-ui/input';
|
5
|
+
import { Layer } from '@dhis2-ui/layer';
|
6
|
+
import { Popper } from '@dhis2-ui/popper';
|
7
|
+
import { getNowInCalendar } from '@dhis2/multi-calendar-dates';
|
8
|
+
import React, { useRef, useState } from 'react';
|
9
|
+
import { CalendarProps } from '../calendar/calendar-prop-types.js';
|
10
|
+
import { Calendar } from '../calendar/index.js';
|
11
|
+
|
12
|
+
const padWithZeroes = function (number) {
|
13
|
+
let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
14
|
+
return String(number).padStart(count, '0');
|
15
|
+
};
|
16
|
+
|
17
|
+
const offsetModifier = {
|
18
|
+
name: 'offset',
|
19
|
+
options: {
|
20
|
+
offset: [0, 2]
|
21
|
+
}
|
22
|
+
};
|
23
|
+
export const CalendarInput = function () {
|
24
|
+
let {
|
25
|
+
onDateSelect,
|
26
|
+
calendar,
|
27
|
+
date,
|
28
|
+
dir,
|
29
|
+
locale,
|
30
|
+
numberingSystem,
|
31
|
+
weekDayFormat,
|
32
|
+
timeZone,
|
33
|
+
width,
|
34
|
+
cellSize,
|
35
|
+
...rest
|
36
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37
|
+
const ref = useRef();
|
38
|
+
const [open, setOpen] = useState(false);
|
39
|
+
const currentDate = getNowInCalendar(calendar, timeZone);
|
40
|
+
const initialDate = date || "".concat(currentDate.eraYear || currentDate.year, "-").concat(padWithZeroes(currentDate.month), "-").concat(padWithZeroes(currentDate.day));
|
41
|
+
const [value, setValue] = useState(initialDate);
|
42
|
+
const calendarProps = React.useMemo(() => {
|
43
|
+
const onDateSelectWrapper = selectedDate => {
|
44
|
+
const {
|
45
|
+
calendarDateString
|
46
|
+
} = selectedDate;
|
47
|
+
setValue(calendarDateString);
|
48
|
+
setOpen(false);
|
49
|
+
onDateSelect === null || onDateSelect === void 0 ? void 0 : onDateSelect(selectedDate);
|
50
|
+
};
|
51
|
+
|
52
|
+
return {
|
53
|
+
onDateSelect: onDateSelectWrapper,
|
54
|
+
calendar,
|
55
|
+
date,
|
56
|
+
dir,
|
57
|
+
locale,
|
58
|
+
numberingSystem,
|
59
|
+
weekDayFormat,
|
60
|
+
timeZone,
|
61
|
+
width,
|
62
|
+
cellSize
|
63
|
+
};
|
64
|
+
}, [calendar, cellSize, date, dir, locale, numberingSystem, onDateSelect, timeZone, weekDayFormat, width]);
|
65
|
+
|
66
|
+
const onFocus = () => {
|
67
|
+
setOpen(true);
|
68
|
+
};
|
69
|
+
|
70
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
71
|
+
ref: ref
|
72
|
+
}, /*#__PURE__*/React.createElement(InputField, _extends({
|
73
|
+
label: "Pick a date"
|
74
|
+
}, rest, {
|
75
|
+
type: "text",
|
76
|
+
onFocus: onFocus,
|
77
|
+
value: value
|
78
|
+
}))), open && /*#__PURE__*/React.createElement(Layer, {
|
79
|
+
onBackdropClick: () => {
|
80
|
+
setOpen(false);
|
81
|
+
}
|
82
|
+
}, /*#__PURE__*/React.createElement(Popper, {
|
83
|
+
reference: ref,
|
84
|
+
placement: "bottom-start",
|
85
|
+
modifiers: [offsetModifier]
|
86
|
+
}, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(Calendar, _extends({}, calendarProps, {
|
87
|
+
date: value
|
88
|
+
}))))));
|
89
|
+
};
|
90
|
+
CalendarInput.defaultProps = {
|
91
|
+
dataTest: 'dhis2-uiwidgets-calendar-inputfield'
|
92
|
+
};
|
93
|
+
CalendarInput.propTypes = { ...CalendarProps,
|
94
|
+
...InputFieldProps
|
95
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { Given, Then, And } from 'cypress-cucumber-preprocessor/steps';
|
2
|
+
Given('an Ethiopic calendar is rendered in {word}', language => {
|
3
|
+
cy.visitStory('CalendarInputTesting', "Ethiopic With ".concat(language));
|
4
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
|
5
|
+
cy.get('[data-test=calendar]').should('be.visible');
|
6
|
+
});
|
7
|
+
Then('days should be rendered in "{word}"', language => {
|
8
|
+
const days = language === 'amharic' ? ['ሰኞ', 'ማክሰ', 'ረቡዕ', 'ሐሙስ', 'ዓርብ', 'ቅዳሜ', 'እሑድ'] : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
9
|
+
days.forEach(day => {
|
10
|
+
cy.contains(day).should('be.visible');
|
11
|
+
});
|
12
|
+
});
|
13
|
+
And('months should be rendered in "{word}" with navigation', language => {
|
14
|
+
const months = language === 'amharic' ? {
|
15
|
+
current: 'ጥቅምት',
|
16
|
+
previous: 'መስከረም',
|
17
|
+
next: 'ኅዳር'
|
18
|
+
} : {
|
19
|
+
current: 'Tekemt',
|
20
|
+
previous: 'Meskerem',
|
21
|
+
next: 'Hedar'
|
22
|
+
};
|
23
|
+
cy.contains(months.current).should('be.visible');
|
24
|
+
cy.get('[data-test="calendar-next-month"]').click();
|
25
|
+
cy.contains(months.next).should('be.visible');
|
26
|
+
cy.get('[data-test="calendar-previous-month"]').click();
|
27
|
+
cy.get('[data-test="calendar-previous-month"]').click();
|
28
|
+
cy.contains(months.previous).should('be.visible');
|
29
|
+
});
|
30
|
+
Then('we should be able to select a day', () => {
|
31
|
+
const date = '2014-02-03';
|
32
|
+
cy.get("[data-test=\"".concat(date, "\"]")).click();
|
33
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', date);
|
34
|
+
cy.get('[data-test="storybook-calendar-result"]').should('have.text', date);
|
35
|
+
cy.get('[data-test="storybook-calendar-result-iso"]').should('have.text', '13 October 2021');
|
36
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: The Calendar renders in the Ethiopic calendar system
|
2
|
+
|
3
|
+
Scenario: Display an Ethiopic calendar in Amharic
|
4
|
+
Given an Ethiopic calendar is rendered in "amharic"
|
5
|
+
Then days should be rendered in "amharic"
|
6
|
+
And months should be rendered in "amharic" with navigation
|
7
|
+
|
8
|
+
Scenario: Select a day in the Ethiopic calendar in Amharic
|
9
|
+
Given an Ethiopic calendar is rendered in "amharic"
|
10
|
+
Then we should be able to select a day
|
11
|
+
|
12
|
+
Scenario: Display an Ethiopic calendar in English
|
13
|
+
Given an Ethiopic calendar is rendered in "english"
|
14
|
+
Then days should be rendered in "english"
|
15
|
+
And months should be rendered in "english" with navigation
|
16
|
+
|
17
|
+
Scenario: Select a day in the Ethiopic calendar in English
|
18
|
+
Given an Ethiopic calendar is rendered in English
|
19
|
+
Then we should be able to select a day
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { Given, Then, And } from 'cypress-cucumber-preprocessor/steps';
|
2
|
+
Given('a Gregorian calendar is rendered in {word}', language => {
|
3
|
+
cy.visitStory('CalendarInputTesting', "Gregorian With ".concat(language));
|
4
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
|
5
|
+
cy.get('[data-test=calendar]').should('be.visible');
|
6
|
+
});
|
7
|
+
Then('days should be rendered in "{word}"', language => {
|
8
|
+
const days = language === 'arabic' ? ['الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت', 'الأحد'] : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
9
|
+
days.forEach(day => {
|
10
|
+
cy.contains(day).should('be.visible');
|
11
|
+
});
|
12
|
+
});
|
13
|
+
And('months should be rendered in "{word}" with navigation', language => {
|
14
|
+
const months = language === 'english' ? {
|
15
|
+
current: 'October',
|
16
|
+
previous: 'September',
|
17
|
+
next: 'November'
|
18
|
+
} : {
|
19
|
+
current: 'أكتوبر',
|
20
|
+
previous: 'سبتمبر',
|
21
|
+
next: 'نوفمبر'
|
22
|
+
};
|
23
|
+
cy.contains(months.current).should('be.visible');
|
24
|
+
cy.get('[data-test="calendar-next-month"]').click();
|
25
|
+
cy.contains(months.next).should('be.visible');
|
26
|
+
cy.get('[data-test="calendar-previous-month"]').click();
|
27
|
+
cy.get('[data-test="calendar-previous-month"]').click();
|
28
|
+
cy.contains(months.previous).should('be.visible');
|
29
|
+
});
|
30
|
+
Then('we should be able to select a day', () => {
|
31
|
+
const date = '2021-10-13';
|
32
|
+
cy.get("[data-test=\"".concat(date, "\"]")).click();
|
33
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', date);
|
34
|
+
cy.get('[data-test="storybook-calendar-result"]').should('have.text', date);
|
35
|
+
cy.get('[data-test="storybook-calendar-result-iso"]').should('have.text', '13 October 2021');
|
36
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: The Calendar renders in the Gregorian calendar system
|
2
|
+
|
3
|
+
Scenario: Display a Gregorian calendar in arabic
|
4
|
+
Given a Gregorian calendar is rendered in "arabic"
|
5
|
+
Then days should be rendered in "arabic"
|
6
|
+
And months should be rendered in "arabic" with navigation
|
7
|
+
|
8
|
+
Scenario: Select a day in the Gregorian calendar in arabic
|
9
|
+
Given a Gregorian calendar is rendered in "arabic"
|
10
|
+
Then we should be able to select a day
|
11
|
+
|
12
|
+
Scenario: Display a Gregorian calendar in English
|
13
|
+
Given a Gregorian calendar is rendered in "english"
|
14
|
+
Then days should be rendered in "english"
|
15
|
+
And months should be rendered in "english" with navigation
|
16
|
+
|
17
|
+
Scenario: Select a day in the Gregorian calendar in English
|
18
|
+
Given a Gregorian calendar is rendered in English
|
19
|
+
Then we should be able to select a day
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Given, Then } from 'cypress-cucumber-preprocessor/steps';
|
2
|
+
Given('an Islamic calendar is rendered with Arabic locale', () => {
|
3
|
+
cy.visitStory('CalendarInputTesting', "Islamic With Arabic");
|
4
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
|
5
|
+
cy.get('[data-test=calendar]').should('be.visible');
|
6
|
+
});
|
7
|
+
Then('days should be rendered in Arabic', () => {
|
8
|
+
cy.contains('الأحد').should('be.visible');
|
9
|
+
cy.contains('السبت').should('be.visible');
|
10
|
+
cy.contains('الجمعة').should('be.visible');
|
11
|
+
cy.contains('الخميس').should('be.visible');
|
12
|
+
cy.contains('الأربعاء').should('be.visible');
|
13
|
+
cy.contains('الثلاثاء').should('be.visible');
|
14
|
+
cy.contains('الاثنين').should('be.visible');
|
15
|
+
});
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { Given, Then, And } from 'cypress-cucumber-preprocessor/steps';
|
2
|
+
Given('a nepali calendar in "{word}" is rendered', language => {
|
3
|
+
cy.visitStory('CalendarInputTesting', "Nepali With ".concat(language));
|
4
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]', {
|
5
|
+
timeout: 10000
|
6
|
+
}).click();
|
7
|
+
cy.get('[data-test=calendar]').should('be.visible');
|
8
|
+
});
|
9
|
+
Then('nepali days should be rendered in "{word}"', language => {
|
10
|
+
const days = language === 'nepali' ? ['आइत', 'सोम', 'सोम', 'बुध', 'बिही', 'शुक्र', 'शनि'] : ['Som', 'Mangl', 'Budha', 'Bihi', 'Shukra', 'Shani', 'Aaita'];
|
11
|
+
days.forEach(day => {
|
12
|
+
cy.contains(day).should('be.visible');
|
13
|
+
});
|
14
|
+
});
|
15
|
+
And('months should be rendered in "{word}" with navigation', language => {
|
16
|
+
//
|
17
|
+
const months = language === 'nepali' ? {
|
18
|
+
current: 'असोज',
|
19
|
+
previous: 'भदौ',
|
20
|
+
next: 'कार्तिक'
|
21
|
+
} : {
|
22
|
+
current: 'Ashwin',
|
23
|
+
previous: 'Bhadra',
|
24
|
+
next: 'Kartik'
|
25
|
+
};
|
26
|
+
cy.contains(months.current).should('be.visible');
|
27
|
+
cy.get('[data-test="calendar-next-month"]').click();
|
28
|
+
cy.contains(months.next).should('be.visible');
|
29
|
+
cy.get('[data-test="calendar-previous-month"]').click();
|
30
|
+
cy.get('[data-test="calendar-previous-month"]').click();
|
31
|
+
cy.contains(months.previous).should('be.visible');
|
32
|
+
});
|
33
|
+
Then('we should be able to select a day', () => {
|
34
|
+
const nepaliDate = '2078-06-27';
|
35
|
+
cy.get("[data-test=\"".concat(nepaliDate, "\"]")).click();
|
36
|
+
cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', nepaliDate);
|
37
|
+
cy.get('[data-test="storybook-calendar-result"]').should('have.text', nepaliDate);
|
38
|
+
cy.get('[data-test="storybook-calendar-result-iso"]').should('have.text', '13 October 2021');
|
39
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: The Calendar renders in Nepali calendar system
|
2
|
+
|
3
|
+
Scenario: Display a Nepali calendar in Nepali
|
4
|
+
Given a nepali calendar in "nepali" is rendered
|
5
|
+
Then nepali days should be rendered in "nepali"
|
6
|
+
And months should be rendered in "nepali" with navigation
|
7
|
+
|
8
|
+
Scenario: Select a day in the Nepali calendar in Nepali
|
9
|
+
Given a nepali calendar in "nepali" is rendered
|
10
|
+
Then we should be able to select a day
|
11
|
+
|
12
|
+
Scenario: Display a Nepali calendar in English
|
13
|
+
Given a nepali calendar in "english" is rendered
|
14
|
+
Then nepali days should be rendered in "english"
|
15
|
+
And months should be rendered in "english" with navigation
|
16
|
+
|
17
|
+
Scenario: Select a day in the Nepali calendar in English
|
18
|
+
Given a nepali calendar in "english" is rendered
|
19
|
+
Then we should be able to select a day
|
@@ -0,0 +1,13 @@
|
|
1
|
+
//------------------------------------------------------------------------------
|
2
|
+
// <auto-generated>
|
3
|
+
// This code was generated by d2-i18n-generate.
|
4
|
+
//
|
5
|
+
// Changes to this file may cause incorrect behavior and will be lost if
|
6
|
+
// the code is regenerated.
|
7
|
+
// </auto-generated>
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
import i18n from '@dhis2/d2-i18n';
|
10
|
+
import enTranslations from './en/translations.json';
|
11
|
+
const namespace = 'default';
|
12
|
+
i18n.addResources('en', namespace, enTranslations);
|
13
|
+
export default i18n;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
|
+
|
3
|
+
import React from 'react';
|
4
|
+
import { Calendar } from '../calendar/index.js';
|
5
|
+
import { CalendarStoryWrapper } from './calendarStoryWrapper.js';
|
6
|
+
const subtitle = "[Experimental] Calendar component is useful for creating a variety of calendars including Ethiopic, Islamic etc..";
|
7
|
+
const description = "\nUse a Calendar where there is a need to let the user select a date.\n\nNote that it requires a parent, like [Box](../?path=/docs/layout-box--default), to define its size.\n\n```js\nimport { Calendar } from '@dhis2/ui'\n```\n";
|
8
|
+
export default {
|
9
|
+
title: 'Calendar',
|
10
|
+
component: Calendar,
|
11
|
+
parameters: {
|
12
|
+
componentSubtitle: subtitle,
|
13
|
+
docs: {
|
14
|
+
description: {
|
15
|
+
component: description
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
};
|
20
|
+
export const Ethiopic = args => {
|
21
|
+
return /*#__PURE__*/React.createElement(CalendarStoryWrapper, _extends({
|
22
|
+
calendar: "ethiopic",
|
23
|
+
locale: "am-et",
|
24
|
+
numberingSystem: "ethi",
|
25
|
+
date: "2014-04-05" // 13th of October 2022
|
26
|
+
,
|
27
|
+
timeZone: "Africa/Khartoum"
|
28
|
+
}, args));
|
29
|
+
};
|
30
|
+
export const Nepali = args => {
|
31
|
+
return /*#__PURE__*/React.createElement(CalendarStoryWrapper, _extends({
|
32
|
+
calendar: "nepali",
|
33
|
+
locale: "ne-NP",
|
34
|
+
date: "2079-06-29" // 13th of October 2022
|
35
|
+
,
|
36
|
+
timeZone: "Africa/Khartoum"
|
37
|
+
}, args));
|
38
|
+
};
|
39
|
+
export const WithAnyCalendar = args => {
|
40
|
+
return /*#__PURE__*/React.createElement(CalendarStoryWrapper, _extends({
|
41
|
+
calendar: "gregory",
|
42
|
+
locale: "en-GB"
|
43
|
+
}, args));
|
44
|
+
};
|