@dhis2-ui/calendar 8.11.2 → 8.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/build/cjs/__e2e__/{calendarInput.stories.e2e.js → calendar-input.stories.e2e.js} +21 -3
  2. package/build/cjs/calendar/calendar-table-cell.js +11 -9
  3. package/build/cjs/calendar/calendar-table-days-header.js +5 -5
  4. package/build/cjs/calendar/calendar-table.js +5 -2
  5. package/build/cjs/calendar/{index.js → calendar.js} +37 -4
  6. package/build/cjs/calendar/navigation-container.js +28 -33
  7. package/build/cjs/calendar-input/{index.js → calendar-input.js} +34 -22
  8. package/build/cjs/features/supports_calendar_clear_button/supports_calendar_clear_button.js +34 -0
  9. package/build/cjs/features/supports_calendar_clear_button.feature +23 -0
  10. package/build/cjs/index.js +4 -4
  11. package/build/cjs/locales/en/translations.json +2 -1
  12. package/build/cjs/stories/calendar-input.stories.js +129 -0
  13. package/build/cjs/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +9 -5
  14. package/build/cjs/stories/calendar.stories.js +3 -3
  15. package/build/es/__e2e__/calendar-input.stories.e2e.js +19 -0
  16. package/build/es/calendar/calendar-table-cell.js +12 -10
  17. package/build/es/calendar/calendar-table-days-header.js +5 -5
  18. package/build/es/calendar/calendar-table.js +5 -2
  19. package/build/es/calendar/{index.js → calendar.js} +33 -1
  20. package/build/es/calendar/navigation-container.js +28 -33
  21. package/build/es/calendar-input/{index.js → calendar-input.js} +29 -21
  22. package/build/es/features/supports_calendar_clear_button/supports_calendar_clear_button.js +31 -0
  23. package/build/es/features/supports_calendar_clear_button.feature +23 -0
  24. package/build/es/index.js +2 -2
  25. package/build/es/locales/en/translations.json +2 -1
  26. package/build/es/stories/{calendarInput.stories.js → calendar-input.stories.js} +34 -16
  27. package/build/es/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +8 -4
  28. package/build/es/stories/calendar.stories.js +2 -2
  29. package/package.json +8 -7
  30. package/build/cjs/calendar/calendar-prop-types.js +0 -24
  31. package/build/cjs/stories/calendarInput.stories.js +0 -107
  32. package/build/es/__e2e__/calendarInput.stories.e2e.js +0 -6
  33. package/build/es/calendar/calendar-prop-types.js +0 -13
@@ -45,14 +45,32 @@ Object.defineProperty(exports, "NepaliWithNepali", {
45
45
  return _calendarInputStories.NepaliWithNepali;
46
46
  }
47
47
  });
48
- exports.default = void 0;
48
+ exports.default = exports.TestCalendarWithClearButton = void 0;
49
+
50
+ var _react = _interopRequireDefault(require("react"));
49
51
 
50
52
  var _index = require("../index.js");
51
53
 
52
- var _calendarInputStories = require("../stories/calendarInput.stories.js");
54
+ var _calendarInputStories = require("../stories/calendar-input.stories.js");
55
+
56
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
57
 
54
58
  var _default = {
55
59
  title: 'CalendarInputTesting',
56
60
  component: _index.CalendarInput
57
61
  };
58
- exports.default = _default;
62
+ exports.default = _default;
63
+
64
+ const TestCalendarWithClearButton = () => {
65
+ var _params$get, _params$get2;
66
+
67
+ const params = new URLSearchParams(location.search);
68
+ const calendar = (_params$get = params.get('calendar')) !== null && _params$get !== void 0 ? _params$get : 'gregory';
69
+ const initialDate = (_params$get2 = params.get('initialDate')) !== null && _params$get2 !== void 0 ? _params$get2 : null;
70
+ return /*#__PURE__*/_react.default.createElement(_calendarInputStories.CalendarWithClearButton, {
71
+ calendar: calendar,
72
+ date: initialDate
73
+ });
74
+ };
75
+
76
+ exports.TestCalendarWithClearButton = TestCalendarWithClearButton;
@@ -20,25 +20,26 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
20
20
  const CalendarTableCell = _ref => {
21
21
  let {
22
22
  day,
23
- cellSize
23
+ cellSize,
24
+ selectedDate
24
25
  } = _ref;
25
26
  const dayHoverBackgroundColor = _uiConstants.colors.grey200;
26
27
  const selectedDayBackgroundColor = _uiConstants.colors.teal700;
27
28
  return /*#__PURE__*/_react.default.createElement("td", {
28
29
  "data-test": day === null || day === void 0 ? void 0 : day.calendarDate,
29
30
  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
+ 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]]])
31
32
  }, /*#__PURE__*/_react.default.createElement("button", {
32
33
  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,
34
+ 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', {
35
+ isSelected: selectedDate === (day === null || day === void 0 ? void 0 : day.calendarDate),
35
36
  isToday: day.isToday,
36
37
  otherMonth: !day.isInCurrentMonth
37
38
  }) || "")
38
39
  }, 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, ";}")]));
40
+ id: "2052411850",
41
+ dynamic: [cellSize, cellSize, cellSize, cellSize, _uiConstants.colors.grey900, dayHoverBackgroundColor, _uiConstants.colors.grey300, selectedDayBackgroundColor, _uiConstants.colors.teal600, _uiConstants.colors.teal200, _uiConstants.colors.grey600]
42
+ }, ["td.__jsx-style-dynamic-selector{width:".concat(cellSize, ";height:100%;height:").concat(cellSize, ";text-align:center;border:2px solid transparent;padding:0;}"), "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;color:").concat(_uiConstants.colors.grey900, ";}"), "button.__jsx-style-dynamic-selector:hover{background-color:".concat(dayHoverBackgroundColor, ";-webkit-text-decoration:underline;text-decoration:underline;cursor:pointer;}"), "button.__jsx-style-dynamic-selector:active{background-color:".concat(_uiConstants.colors.grey300, ";}"), "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{position:relative;}", "button.isToday.__jsx-style-dynamic-selector::after{content:'';position:absolute;-webkit-transform:translateX(-50%);-ms-transform:translateX(-50%);transform:translateX(-50%);height:4px;width:4px;bottom:2px;left:50%;border-radius:100%;background-color:".concat(_uiConstants.colors.teal600, ";}"), "button.isSelected.isToday.__jsx-style-dynamic-selector::after{background-color:".concat(_uiConstants.colors.teal200, ";}"), "button.otherMonth.__jsx-style-dynamic-selector{color:".concat(_uiConstants.colors.grey600, ";}")]));
42
43
  };
43
44
 
44
45
  exports.CalendarTableCell = CalendarTableCell;
@@ -49,7 +50,8 @@ CalendarTableCell.propTypes = {
49
50
  isInCurrentMonth: _propTypes.default.bool,
50
51
  isSelected: _propTypes.default.bool,
51
52
  isToday: _propTypes.default.bool,
52
- label: _propTypes.default.string,
53
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
53
54
  onClick: _propTypes.default.func
54
- })
55
+ }),
56
+ selectedDate: _propTypes.default.string
55
57
  };
@@ -21,17 +21,17 @@ const CalendarTableDaysHeader = _ref => {
21
21
  } = _ref;
22
22
  const dayNamesColor = _uiConstants.colors.grey700;
23
23
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("thead", {
24
- className: _style.default.dynamic([["275131861", [dayNamesColor]]])
24
+ className: _style.default.dynamic([["1577512909", [dayNamesColor]]])
25
25
  }, /*#__PURE__*/_react.default.createElement("tr", {
26
- className: _style.default.dynamic([["275131861", [dayNamesColor]]])
26
+ className: _style.default.dynamic([["1577512909", [dayNamesColor]]])
27
27
  }, weekDayLabels.map((label, i) => /*#__PURE__*/_react.default.createElement("th", {
28
28
  scope: "col",
29
29
  key: "weekday-".concat(i),
30
- className: _style.default.dynamic([["275131861", [dayNamesColor]]])
30
+ className: _style.default.dynamic([["1577512909", [dayNamesColor]]])
31
31
  }, label)))), /*#__PURE__*/_react.default.createElement(_style.default, {
32
- id: "275131861",
32
+ id: "1577512909",
33
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;}"]));
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;cursor:default;}"), "tr.__jsx-style-dynamic-selector{border:none;}"]));
35
35
  };
36
36
 
37
37
  exports.CalendarTableDaysHeader = CalendarTableDaysHeader;
@@ -24,7 +24,8 @@ const CalendarTable = _ref => {
24
24
  weekDayLabels,
25
25
  calendarWeekDays,
26
26
  width,
27
- cellSize
27
+ cellSize,
28
+ selectedDate
28
29
  } = _ref;
29
30
  return /*#__PURE__*/_react.default.createElement("div", {
30
31
  className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]]) + " " + "calendar-table-wrapper"
@@ -38,6 +39,7 @@ const CalendarTable = _ref => {
38
39
  key: "week-".concat(weekIndex + 1),
39
40
  className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]])
40
41
  }, week.map(day => /*#__PURE__*/_react.default.createElement(_calendarTableCell.CalendarTableCell, {
42
+ selectedDate: selectedDate,
41
43
  day: day,
42
44
  key: day === null || day === void 0 ? void 0 : day.calendarDate,
43
45
  cellSize: cellSize,
@@ -55,11 +57,12 @@ CalendarTable.propTypes = {
55
57
  isInCurrentMonth: _propTypes.default.bool,
56
58
  isSelected: _propTypes.default.bool,
57
59
  isToday: _propTypes.default.bool,
58
- label: _propTypes.default.string,
60
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
59
61
  zdt: _propTypes.default.object,
60
62
  onClick: _propTypes.default.func
61
63
  }).isRequired).isRequired).isRequired,
62
64
  cellSize: _propTypes.default.string,
65
+ selectedDate: _propTypes.default.string,
63
66
  weekDayLabels: _propTypes.default.arrayOf(_propTypes.default.string),
64
67
  width: _propTypes.default.string
65
68
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Calendar = void 0;
6
+ exports.CalendarProps = exports.Calendar = void 0;
7
7
 
8
8
  var _style = _interopRequireDefault(require("styled-jsx/style"));
9
9
 
@@ -11,9 +11,9 @@ var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
11
11
 
12
12
  var _uiConstants = require("@dhis2/ui-constants");
13
13
 
14
- var _react = _interopRequireWildcard(require("react"));
14
+ var _propTypes = _interopRequireDefault(require("prop-types"));
15
15
 
16
- var _calendarPropTypes = require("./calendar-prop-types.js");
16
+ var _react = _interopRequireWildcard(require("react"));
17
17
 
18
18
  var _calendarTable = require("./calendar-table.js");
19
19
 
@@ -74,6 +74,7 @@ const Calendar = _ref => {
74
74
  pickerOptions: pickerOptions,
75
75
  languageDirection: languageDirection
76
76
  }), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
77
+ selectedDate: selectedDateString,
77
78
  calendarWeekDays: calendarWeekDays,
78
79
  weekDayLabels: weekDayLabels,
79
80
  cellSize: cellSize,
@@ -90,4 +91,36 @@ Calendar.defaultProps = {
90
91
  width: '240px',
91
92
  weekDayFormat: 'narrow'
92
93
  };
93
- Calendar.propTypes = _calendarPropTypes.CalendarProps;
94
+ const CalendarProps = {
95
+ /** the calendar to use such gregory, ethiopic, nepali - full supported list here: https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/calendars.ts */
96
+ calendar: _propTypes.default.any.isRequired,
97
+
98
+ /** Called with signature `(null)` \|\| `({ dateCalendarString: string, dateCalendar: Temporal.ZonedDateTime })` with `dateCalendarString` being the stringified date in the specified calendar in the format `yyyy-MM-dd` */
99
+ onDateSelect: _propTypes.default.func.isRequired,
100
+
101
+ /** the size of a single cell in the table forming the calendar */
102
+ cellSize: _propTypes.default.string,
103
+
104
+ /** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
105
+ date: _propTypes.default.string,
106
+
107
+ /** the direction of the library - internally the library will use rtl for rtl-languages but this can be overridden here for more control */
108
+ dir: _propTypes.default.oneOf(['ltr', 'rtl']),
109
+
110
+ /** any valid locale - if none provided, the internal library will fallback to the user locale (more info here: https://github.com/dhis2/multi-calendar-dates/blob/main/src/hooks/internal/useResolvedLocaleOptions.ts#L15) */
111
+ locale: _propTypes.default.string,
112
+
113
+ /** numbering system to use - full list here https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/numberingSystems.ts */
114
+ numberingSystem: _propTypes.default.string,
115
+
116
+ /** the timeZone to use */
117
+ timeZone: _propTypes.default.string,
118
+
119
+ /** the format to display for the week day, i.e. Monday (long), Mon (short), M (narrow) */
120
+ weekDayFormat: _propTypes.default.oneOf(['narrow', 'short', 'long']),
121
+
122
+ /** the width of the calendar component */
123
+ width: _propTypes.default.string
124
+ };
125
+ exports.CalendarProps = CalendarProps;
126
+ Calendar.propTypes = CalendarProps;
@@ -19,7 +19,6 @@ var _index = _interopRequireDefault(require("../locales/index.js"));
19
19
 
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
22
- const chevronColor = _uiConstants.colors.grey600;
23
22
  const wrapperBorderColor = _uiConstants.colors.grey300;
24
23
  const headerBackground = _uiConstants.colors.grey050;
25
24
 
@@ -39,69 +38,65 @@ const NavigationContainer = _ref => {
39
38
  prevYear
40
39
  } = pickerOptions;
41
40
  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"
41
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "navigation-container"
43
42
  }, /*#__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"
43
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "month"
45
44
  }, /*#__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"
45
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "prev"
47
46
  }, /*#__PURE__*/_react.default.createElement("button", {
48
47
  onClick: prevMonth.navigateTo,
49
48
  name: "previous-month",
50
49
  "data-test": "calendar-previous-month",
51
50
  "aria-label": "".concat(_index.default.t("Go to ".concat(prevMonth.label))),
52
51
  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]]])
52
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
54
53
  }, /*#__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]]])
54
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
57
55
  }))), /*#__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"
56
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "curr"
59
57
  }, /*#__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"
58
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "label"
61
59
  }, 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"
60
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "next"
63
61
  }, /*#__PURE__*/_react.default.createElement("button", {
64
62
  onClick: nextMonth.navigateTo,
65
63
  "data-test": "calendar-next-month",
66
64
  name: "next-month",
67
65
  "aria-label": "".concat(_index.default.t("Go to ".concat(nextMonth.label))),
68
66
  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]]])
67
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
70
68
  }, /*#__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]]])
69
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
73
70
  })))), /*#__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"
71
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "year"
75
72
  }, /*#__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"
73
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "prev"
77
74
  }, /*#__PURE__*/_react.default.createElement("button", {
78
75
  onClick: prevYear.navigateTo,
79
76
  name: "previous-year",
80
77
  "aria-label": "".concat(_index.default.t('Go to previous year')),
81
78
  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]]])
79
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
83
80
  }, /*#__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]]])
81
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
86
82
  }))), /*#__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"
83
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "curr"
88
84
  }, /*#__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"
85
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "label"
90
86
  }, 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"
87
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]]) + " " + "next"
92
88
  }, /*#__PURE__*/_react.default.createElement("button", {
93
89
  onClick: nextYear.navigateTo,
94
90
  name: "next-year",
95
91
  "aria-label": "".concat(_index.default.t('Go to next year')),
96
92
  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]]])
93
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
98
94
  }, /*#__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]]])
95
+ className: _style.default.dynamic([["3883083596", [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]]])
101
96
  }))))), /*#__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;}")]));
97
+ id: "3883083596",
98
+ dynamic: [_uiConstants.spacers.dp4, _uiConstants.colors.grey600, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey300, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, wrapperBorderColor, headerBackground]
99
+ }, ["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;cursor:default;}", ".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, ";height:24px;width:24px;color:").concat(_uiConstants.colors.grey600, ";border-radius:3px;}"), ".prev.__jsx-style-dynamic-selector button.__jsx-style-dynamic-selector svg.__jsx-style-dynamic-selector,.next.__jsx-style-dynamic-selector button.__jsx-style-dynamic-selector svg.__jsx-style-dynamic-selector{width:16px;height:16px;}", ".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, ";color:").concat(_uiConstants.colors.grey900, ";cursor:pointer;}"), ".prev.__jsx-style-dynamic-selector button.__jsx-style-dynamic-selector:active,.next.__jsx-style-dynamic-selector button.__jsx-style-dynamic-selector:active{background-color:".concat(_uiConstants.colors.grey300, ";}"), ".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{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
100
  };
106
101
 
107
102
  exports.NavigationContainer = NavigationContainer;
@@ -109,25 +104,25 @@ NavigationContainer.propTypes = {
109
104
  languageDirection: _propTypes.default.oneOf(['ltr', 'rtl']),
110
105
  pickerOptions: _propTypes.default.shape({
111
106
  currMonth: _propTypes.default.shape({
112
- label: _propTypes.default.string
107
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
113
108
  }),
114
109
  currYear: _propTypes.default.shape({
115
- label: _propTypes.default.string
110
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
116
111
  }),
117
112
  nextMonth: _propTypes.default.shape({
118
- label: _propTypes.default.string,
113
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
119
114
  navigateTo: _propTypes.default.func
120
115
  }),
121
116
  nextYear: _propTypes.default.shape({
122
- label: _propTypes.default.string,
117
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
123
118
  navigateTo: _propTypes.default.func
124
119
  }),
125
120
  prevMonth: _propTypes.default.shape({
126
- label: _propTypes.default.string,
121
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
127
122
  navigateTo: _propTypes.default.func
128
123
  }),
129
124
  prevYear: _propTypes.default.shape({
130
- label: _propTypes.default.string,
125
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
131
126
  navigateTo: _propTypes.default.func
132
127
  })
133
128
  })
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.CalendarInput = void 0;
7
7
 
8
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
+
10
+ var _button = require("@dhis2-ui/button");
11
+
8
12
  var _card = require("@dhis2-ui/card");
9
13
 
10
14
  var _input = require("@dhis2-ui/input");
@@ -13,24 +17,21 @@ var _layer = require("@dhis2-ui/layer");
13
17
 
14
18
  var _popper = require("@dhis2-ui/popper");
15
19
 
16
- var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
20
+ var _classnames = _interopRequireDefault(require("classnames"));
17
21
 
18
22
  var _react = _interopRequireWildcard(require("react"));
19
23
 
20
- var _calendarPropTypes = require("../calendar/calendar-prop-types.js");
24
+ var _calendar = require("../calendar/calendar.js");
21
25
 
22
- var _index = require("../calendar/index.js");
26
+ var _index = _interopRequireDefault(require("../locales/index.js"));
23
27
 
24
28
  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
29
 
26
30
  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
31
 
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); }
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
33
 
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
+ 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); }
34
35
 
35
36
  const offsetModifier = {
36
37
  name: 'offset',
@@ -51,20 +52,14 @@ const CalendarInput = function () {
51
52
  timeZone,
52
53
  width,
53
54
  cellSize,
55
+ clearable,
54
56
  ...rest
55
57
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
58
  const ref = (0, _react.useRef)();
57
59
  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
60
 
62
61
  const calendarProps = _react.default.useMemo(() => {
63
62
  const onDateSelectWrapper = selectedDate => {
64
- const {
65
- calendarDateString
66
- } = selectedDate;
67
- setValue(calendarDateString);
68
63
  setOpen(false);
69
64
  onDateSelect === null || onDateSelect === void 0 ? void 0 : onDateSelect(selectedDate);
70
65
  };
@@ -88,14 +83,29 @@ const CalendarInput = function () {
88
83
  };
89
84
 
90
85
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
91
- ref: ref
86
+ ref: ref,
87
+ className: "jsx-862452676" + " " + "calendar-input-wrapper"
92
88
  }, /*#__PURE__*/_react.default.createElement(_input.InputField, _extends({
93
89
  label: "Pick a date"
94
90
  }, rest, {
95
91
  type: "text",
96
92
  onFocus: onFocus,
97
- value: value
98
- }))), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
93
+ value: date
94
+ })), clearable && /*#__PURE__*/_react.default.createElement("div", {
95
+ className: "jsx-862452676" + " " + ((0, _classnames.default)('calendar-clear-button', {
96
+ // ToDo: this is a workaround to show the clear button in the correct place when an icon is shown.
97
+ // Long-term, we should abstract and share the logic multi-select uses for the input-wrapper
98
+ // https://dhis2.atlassian.net/browse/DHIS2-14848
99
+ 'with-icon': rest.valid || rest.error || rest.warning || rest.loading,
100
+ 'with-dense-wrapper': rest.dense
101
+ }) || "")
102
+ }, /*#__PURE__*/_react.default.createElement(_button.Button, {
103
+ dataTest: "calendar-clear-button",
104
+ secondary: true,
105
+ small: true,
106
+ onClick: () => calendarProps.onDateSelect(null),
107
+ type: "button"
108
+ }, _index.default.t('Clear')))), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
99
109
  onBackdropClick: () => {
100
110
  setOpen(false);
101
111
  }
@@ -103,15 +113,17 @@ const CalendarInput = function () {
103
113
  reference: ref,
104
114
  placement: "bottom-start",
105
115
  modifiers: [offsetModifier]
106
- }, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(_index.Calendar, _extends({}, calendarProps, {
107
- date: value
108
- }))))));
116
+ }, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(_calendar.Calendar, _extends({}, calendarProps, {
117
+ date: date
118
+ }))))), /*#__PURE__*/_react.default.createElement(_style.default, {
119
+ id: "862452676"
120
+ }, [".calendar-input-wrapper.jsx-862452676{position:relative;}", ".calendar-clear-button.jsx-862452676{position:absolute;inset-inline-end:6px;-webkit-inset-block-start:27px;-ms-intb-rlock-start:27px;inset-block-start:27px;}", ".calendar-clear-button.with-icon.jsx-862452676{inset-inline-end:36px;}", ".calendar-clear-button.with-dense-wrapper.jsx-862452676{-webkit-inset-block-start:23px;-ms-intb-rlock-start:23px;inset-block-start:23px;}"]));
109
121
  };
110
122
 
111
123
  exports.CalendarInput = CalendarInput;
112
124
  CalendarInput.defaultProps = {
113
125
  dataTest: 'dhis2-uiwidgets-calendar-inputfield'
114
126
  };
115
- CalendarInput.propTypes = { ..._calendarPropTypes.CalendarProps,
127
+ CalendarInput.propTypes = { ..._calendar.CalendarProps,
116
128
  ..._input.InputFieldProps
117
129
  };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _steps = require("cypress-cucumber-preprocessor/steps");
4
+
5
+ (0, _steps.Given)('a "{word}" calendar is rendered with a selected date "{word}"', (calendar, initialDate) => {
6
+ cy.visitStory('CalendarInputTesting', 'Test Calendar With Clear Button', {
7
+ qs: {
8
+ initialDate,
9
+ calendar
10
+ }
11
+ });
12
+ cy.get('[data-test="storybook-calendar-date-value"]').should('have.text', initialDate);
13
+ });
14
+ (0, _steps.Then)('we should be able to clear it', () => {
15
+ cy.get("[data-test=\"calendar-clear-button\"]").click();
16
+ cy.get('[data-test="storybook-calendar-date-value"]').should('have.text', 'undefined');
17
+ });
18
+ (0, _steps.And)('show the current month afterwards', () => {
19
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
20
+ cy.get('.isToday').should('be.visible');
21
+ });
22
+ (0, _steps.And)("allow selecting today's date", () => {
23
+ cy.get('.isToday').parent().invoke('attr', 'data-test').then(todayDate => {
24
+ cy.get('.isToday').click();
25
+ cy.get('[data-test="storybook-calendar-date-value"]').should('have.text', todayDate);
26
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', todayDate);
27
+ });
28
+ });
29
+ (0, _steps.And)('highlight today as the selected date', () => {
30
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
31
+ cy.get('.isToday').parent().invoke('attr', 'data-test').then(todayDate => {
32
+ cy.get('.isSelected').should('have.text', Number(todayDate.split('-')[2]).toString());
33
+ });
34
+ });
@@ -0,0 +1,23 @@
1
+ Feature: The Calendar allows clearing the selection
2
+
3
+ Scenario: Clear the selection in the Gregorian calendar
4
+ Given a "gregory" calendar is rendered with a selected date "2021-10-13"
5
+ Then we should be able to clear it
6
+ And show the current month afterwards
7
+ And allow selecting today's date
8
+ And highlight today as the selected date
9
+
10
+ Scenario: Clear the selection in the Ethiopic calendar
11
+ Given a "ethiopic" calendar is rendered with a selected date "2014-02-03"
12
+ Then we should be able to clear it
13
+ And show the current month afterwards
14
+ And allow selecting today's date
15
+ And highlight today as the selected date
16
+
17
+ Scenario: Clear the selection in the Nepali calendar
18
+ Given a "nepali" calendar is rendered with a selected date "2078-06-27"
19
+ Then we should be able to clear it
20
+ And show the current month afterwards
21
+ And allow selecting today's date
22
+ And highlight today as the selected date
23
+
@@ -6,16 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "Calendar", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _index.Calendar;
9
+ return _calendar.Calendar;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "CalendarInput", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _index2.CalendarInput;
15
+ return _calendarInput.CalendarInput;
16
16
  }
17
17
  });
18
18
 
19
- var _index = require("./calendar/index.js");
19
+ var _calendar = require("./calendar/calendar.js");
20
20
 
21
- var _index2 = require("./calendar-input/index.js");
21
+ var _calendarInput = require("./calendar-input/calendar-input.js");
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "Go to previous year": "Go to previous year",
3
- "Go to next year": "Go to next year"
3
+ "Go to next year": "Go to next year",
4
+ "Clear": "Clear"
4
5
  }