@dhis2-ui/calendar 8.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/README.md +10 -0
  2. package/build/cjs/__e2e__/calendarInput.stories.e2e.js +58 -0
  3. package/build/cjs/calendar/calendar-prop-types.js +24 -0
  4. package/build/cjs/calendar/calendar-table-cell.js +55 -0
  5. package/build/cjs/calendar/calendar-table-days-header.js +40 -0
  6. package/build/cjs/calendar/calendar-table.js +57 -0
  7. package/build/cjs/calendar/index.js +93 -0
  8. package/build/cjs/calendar/navigation-container.js +134 -0
  9. package/build/cjs/calendar-input/index.js +117 -0
  10. package/build/cjs/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +39 -0
  11. package/build/cjs/features/supports_ethiopic_calendar.feature +19 -0
  12. package/build/cjs/features/supports_gregorian_calendar/supports_gregorian_calendar.js +39 -0
  13. package/build/cjs/features/supports_gregorian_calendar.feature +19 -0
  14. package/build/cjs/features/supports_islamic_calendar/supports_islamic_calendar.js +18 -0
  15. package/build/cjs/features/supports_islamic_calendar.feature +5 -0
  16. package/build/cjs/features/supports_nepali_calendar/supports_nepali_calendar.js +42 -0
  17. package/build/cjs/features/supports_nepali_calendar.feature +19 -0
  18. package/build/cjs/index.js +21 -0
  19. package/build/cjs/locales/en/translations.json +4 -0
  20. package/build/cjs/locales/index.js +27 -0
  21. package/build/cjs/stories/calendar.stories.js +66 -0
  22. package/build/cjs/stories/calendarInput.stories.js +107 -0
  23. package/build/cjs/stories/calendarStoryWrapper.js +196 -0
  24. package/build/es/__e2e__/calendarInput.stories.e2e.js +6 -0
  25. package/build/es/calendar/calendar-prop-types.js +13 -0
  26. package/build/es/calendar/calendar-table-cell.js +39 -0
  27. package/build/es/calendar/calendar-table-days-header.js +25 -0
  28. package/build/es/calendar/calendar-table.js +40 -0
  29. package/build/es/calendar/index.js +71 -0
  30. package/build/es/calendar/navigation-container.js +116 -0
  31. package/build/es/calendar-input/index.js +95 -0
  32. package/build/es/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +36 -0
  33. package/build/es/features/supports_ethiopic_calendar.feature +19 -0
  34. package/build/es/features/supports_gregorian_calendar/supports_gregorian_calendar.js +36 -0
  35. package/build/es/features/supports_gregorian_calendar.feature +19 -0
  36. package/build/es/features/supports_islamic_calendar/supports_islamic_calendar.js +15 -0
  37. package/build/es/features/supports_islamic_calendar.feature +5 -0
  38. package/build/es/features/supports_nepali_calendar/supports_nepali_calendar.js +39 -0
  39. package/build/es/features/supports_nepali_calendar.feature +19 -0
  40. package/build/es/index.js +2 -0
  41. package/build/es/locales/en/translations.json +4 -0
  42. package/build/es/locales/index.js +13 -0
  43. package/build/es/stories/calendar.stories.js +44 -0
  44. package/build/es/stories/calendarInput.stories.js +84 -0
  45. package/build/es/stories/calendarStoryWrapper.js +176 -0
  46. package/package.json +53 -0
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ > :warning:
2
+ > This is currently considered internal, please use `@dhis2/ui`.
3
+ >
4
+ > See the [Getting started
5
+ > guide](https://github.com/dhis2/ui/blob/master/docs/getting-started.md)
6
+ > for more information.
7
+
8
+ ToDo
9
+
10
+ For usage instructions see [the documentation for this component](https://ui.dhis2.nu/components/calendar).
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "EthiopicWithAmharic", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _calendarInputStories.EthiopicWithAmharic;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "EthiopicWithEnglish", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _calendarInputStories.EthiopicWithEnglish;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "GregorianWithArabic", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _calendarInputStories.GregorianWithArabic;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "GregorianWithEnglish", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _calendarInputStories.GregorianWithEnglish;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "IslamicWithArabic", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _calendarInputStories.IslamicWithArabic;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "NepaliWithEnglish", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _calendarInputStories.NepaliWithEnglish;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "NepaliWithNepali", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _calendarInputStories.NepaliWithNepali;
46
+ }
47
+ });
48
+ exports.default = void 0;
49
+
50
+ var _index = require("../index.js");
51
+
52
+ var _calendarInputStories = require("../stories/calendarInput.stories.js");
53
+
54
+ var _default = {
55
+ title: 'CalendarInputTesting',
56
+ component: _index.CalendarInput
57
+ };
58
+ exports.default = _default;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CalendarProps = void 0;
7
+
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const CalendarProps = {
13
+ calendar: _propTypes.default.any.isRequired,
14
+ cellSize: _propTypes.default.string,
15
+ date: _propTypes.default.string,
16
+ dir: _propTypes.default.oneOf(['ltr', 'rtl']),
17
+ locale: _propTypes.default.string,
18
+ numberingSystem: _propTypes.default.string,
19
+ timeZone: _propTypes.default.string,
20
+ weekDayFormat: _propTypes.default.string,
21
+ width: _propTypes.default.string,
22
+ onDateSelect: _propTypes.default.func
23
+ };
24
+ exports.CalendarProps = CalendarProps;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CalendarTableCell = void 0;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _uiConstants = require("@dhis2/ui-constants");
11
+
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _react = _interopRequireDefault(require("react"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const CalendarTableCell = _ref => {
21
+ let {
22
+ day,
23
+ cellSize
24
+ } = _ref;
25
+ const dayHoverBackgroundColor = _uiConstants.colors.grey200;
26
+ const selectedDayBackgroundColor = _uiConstants.colors.teal700;
27
+ return /*#__PURE__*/_react.default.createElement("td", {
28
+ "data-test": day === null || day === void 0 ? void 0 : day.calendarDate,
29
+ onClick: day.onClick,
30
+ className: _style.default.dynamic([["86824133", [cellSize, cellSize, cellSize, cellSize, _uiConstants.spacers.dp2, _uiConstants.colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, _uiConstants.colors.grey600]]])
31
+ }, /*#__PURE__*/_react.default.createElement("button", {
32
+ name: "day",
33
+ className: _style.default.dynamic([["86824133", [cellSize, cellSize, cellSize, cellSize, _uiConstants.spacers.dp2, _uiConstants.colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, _uiConstants.colors.grey600]]]) + " " + ((0, _classnames.default)('day', {
34
+ isSelected: day.isSelected,
35
+ isToday: day.isToday,
36
+ otherMonth: !day.isInCurrentMonth
37
+ }) || "")
38
+ }, day.label), /*#__PURE__*/_react.default.createElement(_style.default, {
39
+ id: "86824133",
40
+ dynamic: [cellSize, cellSize, cellSize, cellSize, _uiConstants.spacers.dp2, _uiConstants.colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, _uiConstants.colors.grey600]
41
+ }, ["td.__jsx-style-dynamic-selector{width:".concat(cellSize, ";height:100%;height:").concat(cellSize, ";text-align:center;border:2px solid transparent;}"), "td.__jsx-style-dynamic-selector span.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;padding:2px 2px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border:2px solid transparent;min-width:16px;}", "button.__jsx-style-dynamic-selector{border:0;overflow:hidden;width:".concat(cellSize, ";height:").concat(cellSize, ";border:2px solid transparent;border-radius:3px;background:none;margin:").concat(_uiConstants.spacers.dp2, ";color:").concat(_uiConstants.colors.grey900, ";}"), "button.__jsx-style-dynamic-selector:hover{background-color:".concat(dayHoverBackgroundColor, ";-webkit-text-decoration:underline;text-decoration:underline;}"), "button.isSelected.__jsx-style-dynamic-selector,button.otherMonth.isSelected.__jsx-style-dynamic-selector{background-color:".concat(selectedDayBackgroundColor, ";color:white;}"), "button.isToday.__jsx-style-dynamic-selector{-webkit-text-decoration:underline;text-decoration:underline;}", "button.otherMonth.__jsx-style-dynamic-selector{color:".concat(_uiConstants.colors.grey600, ";}")]));
42
+ };
43
+
44
+ exports.CalendarTableCell = CalendarTableCell;
45
+ CalendarTableCell.propTypes = {
46
+ cellSize: _propTypes.default.string,
47
+ day: _propTypes.default.shape({
48
+ calendarDate: _propTypes.default.string,
49
+ isInCurrentMonth: _propTypes.default.bool,
50
+ isSelected: _propTypes.default.bool,
51
+ isToday: _propTypes.default.bool,
52
+ label: _propTypes.default.string,
53
+ onClick: _propTypes.default.func
54
+ })
55
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CalendarTableDaysHeader = void 0;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _uiConstants = require("@dhis2/ui-constants");
11
+
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ const CalendarTableDaysHeader = _ref => {
19
+ let {
20
+ weekDayLabels
21
+ } = _ref;
22
+ const dayNamesColor = _uiConstants.colors.grey700;
23
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("thead", {
24
+ className: _style.default.dynamic([["275131861", [dayNamesColor]]])
25
+ }, /*#__PURE__*/_react.default.createElement("tr", {
26
+ className: _style.default.dynamic([["275131861", [dayNamesColor]]])
27
+ }, weekDayLabels.map((label, i) => /*#__PURE__*/_react.default.createElement("th", {
28
+ scope: "col",
29
+ key: "weekday-".concat(i),
30
+ className: _style.default.dynamic([["275131861", [dayNamesColor]]])
31
+ }, label)))), /*#__PURE__*/_react.default.createElement(_style.default, {
32
+ id: "275131861",
33
+ dynamic: [dayNamesColor]
34
+ }, ["th.__jsx-style-dynamic-selector{color:".concat(dayNamesColor, ";font-weight:300;font-style:normal;padding:8px 8px;background:none;font-size:0.85em;border:none;}"), "tr.__jsx-style-dynamic-selector{border:none;}"]));
35
+ };
36
+
37
+ exports.CalendarTableDaysHeader = CalendarTableDaysHeader;
38
+ CalendarTableDaysHeader.propTypes = {
39
+ weekDayLabels: _propTypes.default.arrayOf(_propTypes.default.string)
40
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CalendarTable = void 0;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _uiConstants = require("@dhis2/ui-constants");
11
+
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ var _calendarTableCell = require("./calendar-table-cell.js");
17
+
18
+ var _calendarTableDaysHeader = require("./calendar-table-days-header.js");
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ const CalendarTable = _ref => {
23
+ let {
24
+ weekDayLabels,
25
+ calendarWeekDays,
26
+ width,
27
+ cellSize
28
+ } = _ref;
29
+ return /*#__PURE__*/_react.default.createElement("div", {
30
+ className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]]) + " " + "calendar-table-wrapper"
31
+ }, /*#__PURE__*/_react.default.createElement("table", {
32
+ className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]]) + " " + "calendar-table"
33
+ }, /*#__PURE__*/_react.default.createElement(_calendarTableDaysHeader.CalendarTableDaysHeader, {
34
+ weekDayLabels: weekDayLabels
35
+ }), /*#__PURE__*/_react.default.createElement("tbody", {
36
+ className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]])
37
+ }, calendarWeekDays.map((week, weekIndex) => /*#__PURE__*/_react.default.createElement("tr", {
38
+ key: "week-".concat(weekIndex + 1),
39
+ className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]])
40
+ }, week.map(day => /*#__PURE__*/_react.default.createElement(_calendarTableCell.CalendarTableCell, {
41
+ day: day,
42
+ key: day === null || day === void 0 ? void 0 : day.calendarDate,
43
+ cellSize: cellSize,
44
+ width: width
45
+ })))))), /*#__PURE__*/_react.default.createElement(_style.default, {
46
+ id: "452536960",
47
+ dynamic: [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]
48
+ }, [".calendar-table.__jsx-style-dynamic-selector{border:none;border-collapse:collapse;width:100%;margin-block:".concat(_uiConstants.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(_uiConstants.spacers.dp4, ";}")]));
49
+ };
50
+
51
+ exports.CalendarTable = CalendarTable;
52
+ CalendarTable.propTypes = {
53
+ calendarWeekDays: _propTypes.default.arrayOf(_propTypes.default.string),
54
+ cellSize: _propTypes.default.string,
55
+ weekDayLabels: _propTypes.default.arrayOf(_propTypes.default.string),
56
+ width: _propTypes.default.string
57
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Calendar = void 0;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
11
+
12
+ var _uiConstants = require("@dhis2/ui-constants");
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ var _calendarPropTypes = require("./calendar-prop-types.js");
17
+
18
+ var _calendarTable = require("./calendar-table.js");
19
+
20
+ var _navigationContainer = require("./navigation-container.js");
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ const Calendar = _ref => {
29
+ let {
30
+ onDateSelect,
31
+ calendar,
32
+ date,
33
+ dir,
34
+ locale,
35
+ numberingSystem,
36
+ weekDayFormat,
37
+ timeZone,
38
+ width,
39
+ cellSize
40
+ } = _ref;
41
+ const wrapperBorderColor = _uiConstants.colors.grey300;
42
+ const backgroundColor = 'none';
43
+ const [selectedDateString, setSelectedDateString] = (0, _react.useState)(date);
44
+ const languageDirection = (0, _multiCalendarDates.useResolvedDirection)(dir, locale);
45
+ const options = {
46
+ locale,
47
+ calendar,
48
+ timeZone,
49
+ numberingSystem,
50
+ weekDayFormat
51
+ };
52
+ const pickerOptions = (0, _multiCalendarDates.useDatePicker)({
53
+ onDateSelect: result => {
54
+ const {
55
+ calendarDateString
56
+ } = result;
57
+ setSelectedDateString(calendarDateString);
58
+ onDateSelect(result);
59
+ },
60
+ date: selectedDateString,
61
+ options
62
+ });
63
+ const {
64
+ calendarWeekDays,
65
+ weekDayLabels
66
+ } = pickerOptions;
67
+ return /*#__PURE__*/_react.default.createElement("div", {
68
+ className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
69
+ }, /*#__PURE__*/_react.default.createElement("div", {
70
+ dir: languageDirection,
71
+ "data-test": "calendar",
72
+ className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
73
+ }, /*#__PURE__*/_react.default.createElement(_navigationContainer.NavigationContainer, {
74
+ pickerOptions: pickerOptions,
75
+ languageDirection: languageDirection
76
+ }), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
77
+ calendarWeekDays: calendarWeekDays,
78
+ weekDayLabels: weekDayLabels,
79
+ cellSize: cellSize,
80
+ width: width
81
+ })), /*#__PURE__*/_react.default.createElement(_style.default, {
82
+ id: "2823859047",
83
+ dynamic: [backgroundColor, wrapperBorderColor, width]
84
+ }, [".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;}")]));
85
+ };
86
+
87
+ exports.Calendar = Calendar;
88
+ Calendar.defaultProps = {
89
+ cellSize: '32px',
90
+ width: '240px',
91
+ weekDayFormat: 'narrow'
92
+ };
93
+ Calendar.propTypes = _calendarPropTypes.CalendarProps;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NavigationContainer = void 0;
7
+
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _uiConstants = require("@dhis2/ui-constants");
11
+
12
+ var _uiIcons = require("@dhis2/ui-icons");
13
+
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
+
16
+ var _react = _interopRequireDefault(require("react"));
17
+
18
+ var _index = _interopRequireDefault(require("../locales/index.js"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ const chevronColor = _uiConstants.colors.grey600;
23
+ const wrapperBorderColor = _uiConstants.colors.grey300;
24
+ const headerBackground = _uiConstants.colors.grey050;
25
+
26
+ const NavigationContainer = _ref => {
27
+ let {
28
+ languageDirection,
29
+ pickerOptions
30
+ } = _ref;
31
+ const PreviousIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronLeft16 : _uiIcons.IconChevronRight16;
32
+ const NextIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronRight16 : _uiIcons.IconChevronLeft16;
33
+ const {
34
+ currMonth,
35
+ currYear,
36
+ nextMonth,
37
+ nextYear,
38
+ prevMonth,
39
+ prevYear
40
+ } = pickerOptions;
41
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
42
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "navigation-container"
43
+ }, /*#__PURE__*/_react.default.createElement("div", {
44
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "month"
45
+ }, /*#__PURE__*/_react.default.createElement("div", {
46
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "prev"
47
+ }, /*#__PURE__*/_react.default.createElement("button", {
48
+ onClick: prevMonth.navigateTo,
49
+ name: "previous-month",
50
+ "data-test": "calendar-previous-month",
51
+ "aria-label": "".concat(_index.default.t("Go to ".concat(prevMonth.label))),
52
+ type: "button",
53
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
54
+ }, /*#__PURE__*/_react.default.createElement(PreviousIcon, {
55
+ color: chevronColor,
56
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
57
+ }))), /*#__PURE__*/_react.default.createElement("div", {
58
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "curr"
59
+ }, /*#__PURE__*/_react.default.createElement("span", {
60
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "label"
61
+ }, currMonth.label)), /*#__PURE__*/_react.default.createElement("div", {
62
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "next"
63
+ }, /*#__PURE__*/_react.default.createElement("button", {
64
+ onClick: nextMonth.navigateTo,
65
+ "data-test": "calendar-next-month",
66
+ name: "next-month",
67
+ "aria-label": "".concat(_index.default.t("Go to ".concat(nextMonth.label))),
68
+ type: "button",
69
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
70
+ }, /*#__PURE__*/_react.default.createElement(NextIcon, {
71
+ color: chevronColor,
72
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
73
+ })))), /*#__PURE__*/_react.default.createElement("div", {
74
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "year"
75
+ }, /*#__PURE__*/_react.default.createElement("div", {
76
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "prev"
77
+ }, /*#__PURE__*/_react.default.createElement("button", {
78
+ onClick: prevYear.navigateTo,
79
+ name: "previous-year",
80
+ "aria-label": "".concat(_index.default.t('Go to previous year')),
81
+ type: "button",
82
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
83
+ }, /*#__PURE__*/_react.default.createElement(PreviousIcon, {
84
+ color: chevronColor,
85
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
86
+ }))), /*#__PURE__*/_react.default.createElement("div", {
87
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "curr"
88
+ }, /*#__PURE__*/_react.default.createElement("span", {
89
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "label"
90
+ }, currYear.label)), /*#__PURE__*/_react.default.createElement("div", {
91
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "next"
92
+ }, /*#__PURE__*/_react.default.createElement("button", {
93
+ onClick: nextYear.navigateTo,
94
+ name: "next-year",
95
+ "aria-label": "".concat(_index.default.t('Go to next year')),
96
+ type: "button",
97
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
98
+ }, /*#__PURE__*/_react.default.createElement(NextIcon, {
99
+ color: chevronColor,
100
+ className: _style.default.dynamic([["4112940194", [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
101
+ }))))), /*#__PURE__*/_react.default.createElement(_style.default, {
102
+ id: "4112940194",
103
+ dynamic: [_uiConstants.spacers.dp4, _uiConstants.colors.grey200, _uiConstants.spacers.dp36, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]
104
+ }, ["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(_uiConstants.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(_uiConstants.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(_uiConstants.spacers.dp36, ";gap:").concat(_uiConstants.spacers.dp8, ";padding:").concat(_uiConstants.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;}")]));
105
+ };
106
+
107
+ exports.NavigationContainer = NavigationContainer;
108
+ NavigationContainer.propTypes = {
109
+ languageDirection: _propTypes.default.oneOf(['ltr', 'rtl']),
110
+ pickerOptions: _propTypes.default.shape({
111
+ currMonth: _propTypes.default.shape({
112
+ label: _propTypes.default.string
113
+ }),
114
+ currYear: _propTypes.default.shape({
115
+ label: _propTypes.default.string
116
+ }),
117
+ nextMonth: _propTypes.default.shape({
118
+ label: _propTypes.default.string,
119
+ navigateTo: _propTypes.default.func
120
+ }),
121
+ nextYear: _propTypes.default.shape({
122
+ label: _propTypes.default.string,
123
+ navigateTo: _propTypes.default.func
124
+ }),
125
+ prevMonth: _propTypes.default.shape({
126
+ label: _propTypes.default.string,
127
+ navigateTo: _propTypes.default.func
128
+ }),
129
+ prevYear: _propTypes.default.shape({
130
+ label: _propTypes.default.string,
131
+ navigateTo: _propTypes.default.func
132
+ })
133
+ })
134
+ };
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CalendarInput = void 0;
7
+
8
+ var _card = require("@dhis2-ui/card");
9
+
10
+ var _input = require("@dhis2-ui/input");
11
+
12
+ var _layer = require("@dhis2-ui/layer");
13
+
14
+ var _popper = require("@dhis2-ui/popper");
15
+
16
+ var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
17
+
18
+ var _react = _interopRequireWildcard(require("react"));
19
+
20
+ var _calendarPropTypes = require("../calendar/calendar-prop-types.js");
21
+
22
+ var _index = require("../calendar/index.js");
23
+
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
+
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+
28
+ 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); }
29
+
30
+ const padWithZeroes = function (number) {
31
+ let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
32
+ return String(number).padStart(count, '0');
33
+ };
34
+
35
+ const offsetModifier = {
36
+ name: 'offset',
37
+ options: {
38
+ offset: [0, 2]
39
+ }
40
+ };
41
+
42
+ const CalendarInput = function () {
43
+ let {
44
+ onDateSelect,
45
+ calendar,
46
+ date,
47
+ dir,
48
+ locale,
49
+ numberingSystem,
50
+ weekDayFormat,
51
+ timeZone,
52
+ width,
53
+ cellSize,
54
+ ...rest
55
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
+ const ref = (0, _react.useRef)();
57
+ const [open, setOpen] = (0, _react.useState)(false);
58
+ const currentDate = (0, _multiCalendarDates.getNowInCalendar)(calendar, timeZone);
59
+ const initialDate = date || "".concat(currentDate.eraYear || currentDate.year, "-").concat(padWithZeroes(currentDate.month), "-").concat(padWithZeroes(currentDate.day));
60
+ const [value, setValue] = (0, _react.useState)(initialDate);
61
+
62
+ const calendarProps = _react.default.useMemo(() => {
63
+ const onDateSelectWrapper = selectedDate => {
64
+ const {
65
+ calendarDateString
66
+ } = selectedDate;
67
+ setValue(calendarDateString);
68
+ setOpen(false);
69
+ onDateSelect === null || onDateSelect === void 0 ? void 0 : onDateSelect(selectedDate);
70
+ };
71
+
72
+ return {
73
+ onDateSelect: onDateSelectWrapper,
74
+ calendar,
75
+ date,
76
+ dir,
77
+ locale,
78
+ numberingSystem,
79
+ weekDayFormat,
80
+ timeZone,
81
+ width,
82
+ cellSize
83
+ };
84
+ }, [calendar, cellSize, date, dir, locale, numberingSystem, onDateSelect, timeZone, weekDayFormat, width]);
85
+
86
+ const onFocus = () => {
87
+ setOpen(true);
88
+ };
89
+
90
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
91
+ ref: ref
92
+ }, /*#__PURE__*/_react.default.createElement(_input.InputField, _extends({
93
+ label: "Pick a date"
94
+ }, rest, {
95
+ type: "text",
96
+ onFocus: onFocus,
97
+ value: value
98
+ }))), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
99
+ onBackdropClick: () => {
100
+ setOpen(false);
101
+ }
102
+ }, /*#__PURE__*/_react.default.createElement(_popper.Popper, {
103
+ reference: ref,
104
+ placement: "bottom-start",
105
+ modifiers: [offsetModifier]
106
+ }, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(_index.Calendar, _extends({}, calendarProps, {
107
+ date: value
108
+ }))))));
109
+ };
110
+
111
+ exports.CalendarInput = CalendarInput;
112
+ CalendarInput.defaultProps = {
113
+ dataTest: 'dhis2-uiwidgets-calendar-inputfield'
114
+ };
115
+ CalendarInput.propTypes = { ..._calendarPropTypes.CalendarProps,
116
+ ..._input.InputFieldProps
117
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _steps = require("cypress-cucumber-preprocessor/steps");
4
+
5
+ (0, _steps.Given)('an Ethiopic calendar is rendered in {word}', language => {
6
+ cy.visitStory('CalendarInputTesting', "Ethiopic With ".concat(language));
7
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
8
+ cy.get('[data-test=calendar]').should('be.visible');
9
+ });
10
+ (0, _steps.Then)('days should be rendered in "{word}"', language => {
11
+ const days = language === 'amharic' ? ['ሰኞ', 'ማክሰ', 'ረቡዕ', 'ሐሙስ', 'ዓርብ', 'ቅዳሜ', 'እሑድ'] : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
12
+ days.forEach(day => {
13
+ cy.contains(day).should('be.visible');
14
+ });
15
+ });
16
+ (0, _steps.And)('months should be rendered in "{word}" with navigation', language => {
17
+ const months = language === 'amharic' ? {
18
+ current: 'ጥቅምት',
19
+ previous: 'መስከረም',
20
+ next: 'ኅዳር'
21
+ } : {
22
+ current: 'Tekemt',
23
+ previous: 'Meskerem',
24
+ next: 'Hedar'
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
+ (0, _steps.Then)('we should be able to select a day', () => {
34
+ const date = '2014-02-03';
35
+ cy.get("[data-test=\"".concat(date, "\"]")).click();
36
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', date);
37
+ cy.get('[data-test="storybook-calendar-result"]').should('have.text', date);
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 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