@dhis2-ui/calendar 8.11.2 → 8.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) 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 +10 -8
  3. package/build/cjs/calendar/calendar-table.js +5 -2
  4. package/build/cjs/calendar/{index.js → calendar.js} +37 -4
  5. package/build/cjs/calendar/navigation-container.js +6 -6
  6. package/build/cjs/calendar-input/{index.js → calendar-input.js} +34 -22
  7. package/build/cjs/features/supports_calendar_clear_button/supports_calendar_clear_button.js +34 -0
  8. package/build/cjs/features/supports_calendar_clear_button.feature +23 -0
  9. package/build/cjs/index.js +4 -4
  10. package/build/cjs/locales/en/translations.json +2 -1
  11. package/build/cjs/stories/calendar-input.stories.js +129 -0
  12. package/build/cjs/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +9 -5
  13. package/build/cjs/stories/calendar.stories.js +3 -3
  14. package/build/es/__e2e__/calendar-input.stories.e2e.js +19 -0
  15. package/build/es/calendar/calendar-table-cell.js +10 -8
  16. package/build/es/calendar/calendar-table.js +5 -2
  17. package/build/es/calendar/{index.js → calendar.js} +33 -1
  18. package/build/es/calendar/navigation-container.js +6 -6
  19. package/build/es/calendar-input/{index.js → calendar-input.js} +29 -21
  20. package/build/es/features/supports_calendar_clear_button/supports_calendar_clear_button.js +31 -0
  21. package/build/es/features/supports_calendar_clear_button.feature +23 -0
  22. package/build/es/index.js +2 -2
  23. package/build/es/locales/en/translations.json +2 -1
  24. package/build/es/stories/{calendarInput.stories.js → calendar-input.stories.js} +34 -16
  25. package/build/es/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +8 -4
  26. package/build/es/stories/calendar.stories.js +2 -2
  27. package/package.json +8 -7
  28. package/build/cjs/calendar/calendar-prop-types.js +0 -24
  29. package/build/cjs/stories/calendarInput.stories.js +0 -107
  30. package/build/es/__e2e__/calendarInput.stories.e2e.js +0 -6
  31. 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([["1413417644", [cellSize, cellSize, cellSize, cellSize, _uiConstants.spacers.dp2, _uiConstants.colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, _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([["1413417644", [cellSize, cellSize, cellSize, cellSize, _uiConstants.spacers.dp2, _uiConstants.colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, _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
+ id: "1413417644",
40
41
  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
+ }, ["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;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
  };
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
  };
@@ -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;
@@ -109,25 +109,25 @@ NavigationContainer.propTypes = {
109
109
  languageDirection: _propTypes.default.oneOf(['ltr', 'rtl']),
110
110
  pickerOptions: _propTypes.default.shape({
111
111
  currMonth: _propTypes.default.shape({
112
- label: _propTypes.default.string
112
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
113
113
  }),
114
114
  currYear: _propTypes.default.shape({
115
- label: _propTypes.default.string
115
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
116
116
  }),
117
117
  nextMonth: _propTypes.default.shape({
118
- label: _propTypes.default.string,
118
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
119
119
  navigateTo: _propTypes.default.func
120
120
  }),
121
121
  nextYear: _propTypes.default.shape({
122
- label: _propTypes.default.string,
122
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
123
123
  navigateTo: _propTypes.default.func
124
124
  }),
125
125
  prevMonth: _propTypes.default.shape({
126
- label: _propTypes.default.string,
126
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
127
127
  navigateTo: _propTypes.default.func
128
128
  }),
129
129
  prevYear: _propTypes.default.shape({
130
- label: _propTypes.default.string,
130
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
131
131
  navigateTo: _propTypes.default.func
132
132
  })
133
133
  })
@@ -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', todayDate.split('-')[2]);
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
  }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.NepaliWithNepali = exports.NepaliWithEnglish = exports.IslamicWithArabic = exports.GregorianWithEnglish = exports.GregorianWithArabic = exports.EthiopicWithEnglish = exports.EthiopicWithAmharic = exports.CalendarWithClearButton = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _calendarInput = require("../calendar-input/calendar-input.js");
11
+
12
+ var _calendarStoryWrapper = require("./calendar-story-wrapper.js");
13
+
14
+ 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); }
15
+
16
+ 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; }
17
+
18
+ const subtitle = "[Experimental] Calendar Input is a wrapper around Calendar displaying an input that triggers the calendar";
19
+ const description = "\nUse a CalendarInput where there is a need to let the user input a date.\n\nNote that it requires a parent, like [Box](../?path=/docs/layout-box--default), to define its size.\n\n```js\nimport { CalendarInput } from '@dhis2/ui'\n```\n";
20
+ var _default = {
21
+ title: 'CalendarInput',
22
+ component: _calendarInput.CalendarInput,
23
+ parameters: {
24
+ componentSubtitle: subtitle,
25
+ docs: {
26
+ description: {
27
+ component: description
28
+ }
29
+ }
30
+ }
31
+ };
32
+ exports.default = _default;
33
+
34
+ const buildCalendar = _ref => {
35
+ let {
36
+ date,
37
+ locale,
38
+ calendar
39
+ } = _ref;
40
+ return () => /*#__PURE__*/_react.default.createElement(_calendarStoryWrapper.CalendarStoryWrapper, {
41
+ component: _calendarInput.CalendarInput,
42
+ dir: "ltr",
43
+ timeZone: "Africa/Khartoum",
44
+ weekDayFormat: "short",
45
+ date: date,
46
+ locale: locale,
47
+ calendar: calendar
48
+ });
49
+ };
50
+
51
+ const EthiopicWithAmharic = buildCalendar({
52
+ calendar: 'ethiopic',
53
+ locale: 'am-ET',
54
+ date: '2014-02-03' // 13 Oct 2021
55
+
56
+ });
57
+ exports.EthiopicWithAmharic = EthiopicWithAmharic;
58
+ const EthiopicWithEnglish = buildCalendar({
59
+ calendar: 'ethiopic',
60
+ locale: 'en-ET',
61
+ date: '2014-02-03' // 13 Oct 2021
62
+
63
+ });
64
+ exports.EthiopicWithEnglish = EthiopicWithEnglish;
65
+ const NepaliWithNepali = buildCalendar({
66
+ calendar: 'nepali',
67
+ locale: 'ne-NP',
68
+ date: '2078-06-27' // 13 Oct 2021
69
+
70
+ });
71
+ exports.NepaliWithNepali = NepaliWithNepali;
72
+ const NepaliWithEnglish = buildCalendar({
73
+ calendar: 'nepali',
74
+ locale: 'en-NP',
75
+ date: '2078-06-27' // 13 Oct 2021
76
+
77
+ });
78
+ exports.NepaliWithEnglish = NepaliWithEnglish;
79
+ const GregorianWithEnglish = buildCalendar({
80
+ calendar: 'gregorian',
81
+ locale: 'en-CA',
82
+ date: '2021-10-13'
83
+ });
84
+ exports.GregorianWithEnglish = GregorianWithEnglish;
85
+ const GregorianWithArabic = buildCalendar({
86
+ calendar: 'gregorian',
87
+ locale: 'ar-SD',
88
+ date: '2021-10-13'
89
+ });
90
+ exports.GregorianWithArabic = GregorianWithArabic;
91
+
92
+ const IslamicWithArabic = () => {
93
+ return /*#__PURE__*/_react.default.createElement("div", {
94
+ style: {
95
+ direction: 'rtl'
96
+ }
97
+ }, /*#__PURE__*/_react.default.createElement(_calendarStoryWrapper.CalendarStoryWrapper, {
98
+ component: _calendarInput.CalendarInput,
99
+ dir: "rtl",
100
+ timeZone: "Africa/Khartoum",
101
+ weekDayFormat: "short",
102
+ date: "1477-01-13",
103
+ locale: "ar-SD",
104
+ calendar: "islamic-civil",
105
+ clearable: true
106
+ }));
107
+ };
108
+
109
+ exports.IslamicWithArabic = IslamicWithArabic;
110
+
111
+ const CalendarWithClearButton = _ref2 => {
112
+ let {
113
+ calendar = 'gregory',
114
+ date: initialDate = null
115
+ } = _ref2;
116
+ const [date, setDate] = (0, _react.useState)(initialDate);
117
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_calendarInput.CalendarInput, {
118
+ calendar: calendar,
119
+ date: date,
120
+ onDateSelect: date => {
121
+ setDate(date === null || date === void 0 ? void 0 : date.calendarDateString);
122
+ },
123
+ clearable: true
124
+ }), /*#__PURE__*/_react.default.createElement("div", null, "value:", /*#__PURE__*/_react.default.createElement("span", {
125
+ "data-test": "storybook-calendar-date-value"
126
+ }, date !== null && date !== void 0 ? date : 'undefined')));
127
+ };
128
+
129
+ exports.CalendarWithClearButton = CalendarWithClearButton;
@@ -11,7 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
 
14
- var _index = require("../calendar/index.js");
14
+ var _calendar = require("../calendar/calendar.js");
15
15
 
16
16
  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); }
17
17
 
@@ -27,6 +27,8 @@ const {
27
27
  } = _multiCalendarDates.constants;
28
28
 
29
29
  const CalendarStoryWrapper = props => {
30
+ var _selectedDate$calenda;
31
+
30
32
  const {
31
33
  calendar,
32
34
  locale,
@@ -41,7 +43,9 @@ const CalendarStoryWrapper = props => {
41
43
  const [selectedDirection, setSelectedDirection] = (0, _react.useState)(dir);
42
44
  const [selectedWeekFormat, setWeekDayFormat] = (0, _react.useState)(weekDayFormat);
43
45
  const [selectedLocale, setLocale] = (0, _react.useState)(locale);
44
- const [selectedDate, setSelectedDate] = (0, _react.useState)();
46
+ const [selectedDate, setSelectedDate] = (0, _react.useState)({
47
+ calendarDateString: date
48
+ });
45
49
 
46
50
  const changeCalendar = _ref => {
47
51
  let {
@@ -155,7 +159,7 @@ const CalendarStoryWrapper = props => {
155
159
  calendar: selectedCalendar,
156
160
  dir: selectedDirection,
157
161
  locale: selectedLocale,
158
- date: date,
162
+ date: selectedDate.calendarDateString,
159
163
  onDateSelect: date => {
160
164
  setSelectedDate(date);
161
165
  },
@@ -174,7 +178,7 @@ const CalendarStoryWrapper = props => {
174
178
  "data-test": "storybook-calendar-result"
175
179
  }, selectedDate.calendarDateString)), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("label", null, "iso date: "), /*#__PURE__*/_react.default.createElement("span", {
176
180
  "data-test": "storybook-calendar-result-iso"
177
- }, selectedDate.calendarDate.withCalendar('iso8601').toLocaleString('en-GB', {
181
+ }, (_selectedDate$calenda = selectedDate.calendarDate) === null || _selectedDate$calenda === void 0 ? void 0 : _selectedDate$calenda.withCalendar('iso8601').toLocaleString('en-GB', {
178
182
  dateStyle: 'long'
179
183
  }))), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("label", null, "callback:"), JSON.stringify(selectedDate, null, 2))))));
180
184
  };
@@ -182,7 +186,7 @@ const CalendarStoryWrapper = props => {
182
186
  exports.CalendarStoryWrapper = CalendarStoryWrapper;
183
187
  CalendarStoryWrapper.defaultProps = {
184
188
  calendar: 'gregorian',
185
- component: _index.Calendar,
189
+ component: _calendar.Calendar,
186
190
  weekDayFormat: 'narrow'
187
191
  };
188
192
  CalendarStoryWrapper.propTypes = {
@@ -7,9 +7,9 @@ exports.default = exports.WithAnyCalendar = exports.Nepali = exports.Ethiopic =
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
- var _index = require("../calendar/index.js");
10
+ var _calendar = require("../calendar/calendar.js");
11
11
 
12
- var _calendarStoryWrapper = require("./calendarStoryWrapper.js");
12
+ var _calendarStoryWrapper = require("./calendar-story-wrapper.js");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
@@ -19,7 +19,7 @@ const subtitle = "[Experimental] Calendar component is useful for creating a var
19
19
  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";
20
20
  var _default = {
21
21
  title: 'Calendar',
22
- component: _index.Calendar,
22
+ component: _calendar.Calendar,
23
23
  parameters: {
24
24
  componentSubtitle: subtitle,
25
25
  docs: {
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { CalendarInput as component } from '../index.js';
3
+ import { CalendarWithClearButton } from '../stories/calendar-input.stories.js';
4
+ export default {
5
+ title: 'CalendarInputTesting',
6
+ component
7
+ };
8
+ export { EthiopicWithAmharic, EthiopicWithEnglish, NepaliWithEnglish, NepaliWithNepali, GregorianWithArabic, GregorianWithEnglish, IslamicWithArabic } from '../stories/calendar-input.stories.js';
9
+ export const TestCalendarWithClearButton = () => {
10
+ var _params$get, _params$get2;
11
+
12
+ const params = new URLSearchParams(location.search);
13
+ const calendar = (_params$get = params.get('calendar')) !== null && _params$get !== void 0 ? _params$get : 'gregory';
14
+ const initialDate = (_params$get2 = params.get('initialDate')) !== null && _params$get2 !== void 0 ? _params$get2 : null;
15
+ return /*#__PURE__*/React.createElement(CalendarWithClearButton, {
16
+ calendar: calendar,
17
+ date: initialDate
18
+ });
19
+ };