@dhis2-ui/calendar 9.12.0-alpha.3 → 9.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,8 +14,7 @@ const CalendarTableCell = _ref => {
14
14
  let {
15
15
  day,
16
16
  cellSize,
17
- selectedDate,
18
- unfocusable
17
+ selectedDate
19
18
  } = _ref;
20
19
  const dayHoverBackgroundColor = _uiConstants.colors.grey200;
21
20
  const selectedDayBackgroundColor = _uiConstants.colors.teal700;
@@ -25,7 +24,6 @@ const CalendarTableCell = _ref => {
25
24
  className: _style.default.dynamic([["2052411850", [cellSize, cellSize, cellSize, cellSize, _uiConstants.colors.grey900, dayHoverBackgroundColor, _uiConstants.colors.grey300, selectedDayBackgroundColor, _uiConstants.colors.teal600, _uiConstants.colors.teal200, _uiConstants.colors.grey600]]])
26
25
  }, /*#__PURE__*/_react.default.createElement("button", {
27
26
  name: "day",
28
- tabIndex: unfocusable ? -1 : 0,
29
27
  className: _style.default.dynamic([["2052411850", [cellSize, cellSize, cellSize, cellSize, _uiConstants.colors.grey900, dayHoverBackgroundColor, _uiConstants.colors.grey300, selectedDayBackgroundColor, _uiConstants.colors.teal600, _uiConstants.colors.teal200, _uiConstants.colors.grey600]]]) + " " + ((0, _classnames.default)('day', {
30
28
  isSelected: selectedDate === (day === null || day === void 0 ? void 0 : day.calendarDate),
31
29
  isToday: day.isToday,
@@ -47,6 +45,5 @@ CalendarTableCell.propTypes = {
47
45
  label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
48
46
  onClick: _propTypes.default.func
49
47
  }),
50
- selectedDate: _propTypes.default.string,
51
- unfocusable: _propTypes.default.bool
48
+ selectedDate: _propTypes.default.string
52
49
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CalendarTableProps = exports.CalendarTable = void 0;
6
+ exports.CalendarTable = void 0;
7
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
8
8
  var _uiConstants = require("@dhis2/ui-constants");
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -17,8 +17,7 @@ const CalendarTable = _ref => {
17
17
  calendarWeekDays,
18
18
  width,
19
19
  cellSize,
20
- selectedDate,
21
- unfocusable
20
+ selectedDate
22
21
  } = _ref;
23
22
  return /*#__PURE__*/_react.default.createElement("div", {
24
23
  className: _style.default.dynamic([["452536960", [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]]]) + " " + "calendar-table-wrapper"
@@ -36,15 +35,14 @@ const CalendarTable = _ref => {
36
35
  day: day,
37
36
  key: day === null || day === void 0 ? void 0 : day.calendarDate,
38
37
  cellSize: cellSize,
39
- width: width,
40
- unfocusable: unfocusable
38
+ width: width
41
39
  })))))), /*#__PURE__*/_react.default.createElement(_style.default, {
42
40
  id: "452536960",
43
41
  dynamic: [_uiConstants.spacers.dp4, _uiConstants.spacers.dp4]
44
42
  }, [`.calendar-table.__jsx-style-dynamic-selector{border:none;border-collapse:collapse;width:100%;margin-block:${_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:${_uiConstants.spacers.dp4};}`]));
45
43
  };
46
44
  exports.CalendarTable = CalendarTable;
47
- const CalendarTableProps = exports.CalendarTableProps = {
45
+ CalendarTable.propTypes = {
48
46
  calendarWeekDays: _propTypes.default.arrayOf(_propTypes.default.arrayOf(_propTypes.default.shape({
49
47
  calendarDate: _propTypes.default.string,
50
48
  isInCurrentMonth: _propTypes.default.bool,
@@ -56,8 +54,6 @@ const CalendarTableProps = exports.CalendarTableProps = {
56
54
  }).isRequired).isRequired).isRequired,
57
55
  cellSize: _propTypes.default.string,
58
56
  selectedDate: _propTypes.default.string,
59
- unfocusable: _propTypes.default.bool,
60
57
  weekDayLabels: _propTypes.default.arrayOf(_propTypes.default.string),
61
58
  width: _propTypes.default.string
62
- };
63
- CalendarTable.propTypes = CalendarTableProps;
59
+ };
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CalendarProps = exports.Calendar = void 0;
7
+ var _style = _interopRequireDefault(require("styled-jsx/style"));
7
8
  var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
9
+ var _uiConstants = require("@dhis2/ui-constants");
8
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
11
  var _react = _interopRequireWildcard(require("react"));
10
- var _calendarContainer = require("./calendar-container.js");
12
+ var _calendarTable = require("./calendar-table.js");
13
+ var _navigationContainer = require("./navigation-container.js");
11
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -19,11 +22,13 @@ const Calendar = _ref => {
19
22
  dir,
20
23
  locale,
21
24
  numberingSystem,
22
- weekDayFormat,
25
+ weekDayFormat = 'narrow',
23
26
  timeZone,
24
- width,
25
- cellSize
27
+ width = '240px',
28
+ cellSize = '32px'
26
29
  } = _ref;
30
+ const wrapperBorderColor = _uiConstants.colors.grey300;
31
+ const backgroundColor = 'none';
27
32
  const [selectedDateString, setSelectedDateString] = (0, _react.useState)(date);
28
33
  const languageDirection = (0, _multiCalendarDates.useResolvedDirection)(dir, locale);
29
34
  const options = {
@@ -33,7 +38,7 @@ const Calendar = _ref => {
33
38
  numberingSystem,
34
39
  weekDayFormat
35
40
  };
36
- const pickerResults = (0, _multiCalendarDates.useDatePicker)({
41
+ const pickerOptions = (0, _multiCalendarDates.useDatePicker)({
37
42
  onDateSelect: result => {
38
43
  const {
39
44
  calendarDateString
@@ -44,37 +49,31 @@ const Calendar = _ref => {
44
49
  date: selectedDateString,
45
50
  options
46
51
  });
47
- const calendarProps = (0, _react.useMemo)(() => {
48
- return {
49
- date,
50
- dir,
51
- locale,
52
- width,
53
- cellSize,
54
- // minDate,
55
- // maxDate,
56
- // validation, // todo: clarify how we use validation props (and format) in Calendar (not CalendarInput)
57
- // format,
58
- isValid: pickerResults.isValid,
59
- calendarWeekDays: pickerResults.calendarWeekDays,
60
- weekDayLabels: pickerResults.weekDayLabels,
61
- currMonth: pickerResults.currMonth,
62
- currYear: pickerResults.currYear,
63
- nextMonth: pickerResults.nextMonth,
64
- nextYear: pickerResults.nextYear,
65
- prevMonth: pickerResults.prevMonth,
66
- prevYear: pickerResults.prevYear,
67
- languageDirection
68
- };
69
- }, [cellSize, date, dir, locale, pickerResults, width, languageDirection]);
70
- return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_calendarContainer.CalendarContainer, calendarProps));
52
+ const {
53
+ calendarWeekDays,
54
+ weekDayLabels
55
+ } = pickerOptions;
56
+ return /*#__PURE__*/_react.default.createElement("div", {
57
+ className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
58
+ }, /*#__PURE__*/_react.default.createElement("div", {
59
+ dir: languageDirection,
60
+ "data-test": "calendar",
61
+ className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
62
+ }, /*#__PURE__*/_react.default.createElement(_navigationContainer.NavigationContainer, {
63
+ pickerOptions: pickerOptions,
64
+ languageDirection: languageDirection
65
+ }), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
66
+ selectedDate: selectedDateString,
67
+ calendarWeekDays: calendarWeekDays,
68
+ weekDayLabels: weekDayLabels,
69
+ cellSize: cellSize,
70
+ width: width
71
+ })), /*#__PURE__*/_react.default.createElement(_style.default, {
72
+ id: "2823859047",
73
+ dynamic: [backgroundColor, wrapperBorderColor, width]
74
+ }, [`.calendar-wrapper.__jsx-style-dynamic-selector{font-family:Roboto,sans-serif;font-weight:400;font-size:14px;background-color:${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 ${wrapperBorderColor};border-radius:3px;min-width:${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;}`]));
71
75
  };
72
76
  exports.Calendar = Calendar;
73
- Calendar.defaultProps = {
74
- cellSize: '32px',
75
- width: '240px',
76
- weekDayFormat: 'narrow'
77
- };
78
77
  const CalendarProps = exports.CalendarProps = {
79
78
  /** 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 */
80
79
  calendar: _propTypes.default.any.isRequired,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.NavigationContainerProps = exports.NavigationContainer = void 0;
6
+ exports.NavigationContainer = void 0;
7
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
8
8
  var _uiConstants = require("@dhis2/ui-constants");
9
9
  var _uiIcons = require("@dhis2/ui-icons");
@@ -17,16 +17,18 @@ const NavigationContainer = _ref => {
17
17
  var _currYear$label;
18
18
  let {
19
19
  languageDirection,
20
+ pickerOptions
21
+ } = _ref;
22
+ const PreviousIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronLeft16 : _uiIcons.IconChevronRight16;
23
+ const NextIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronRight16 : _uiIcons.IconChevronLeft16;
24
+ const {
20
25
  currMonth,
21
26
  currYear,
22
27
  nextMonth,
23
28
  nextYear,
24
29
  prevMonth,
25
- prevYear,
26
- unfocusable
27
- } = _ref;
28
- const PreviousIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronLeft16 : _uiIcons.IconChevronRight16;
29
- const NextIcon = languageDirection === 'ltr' ? _uiIcons.IconChevronRight16 : _uiIcons.IconChevronLeft16;
30
+ prevYear
31
+ } = pickerOptions;
30
32
 
31
33
  // Ethiopic years - when localised to English - add the era (i.e. 2015 ERA1), which is redundant in practice (like writing AD for gregorian years)
32
34
  // there is an ongoing discussion in JS-Temporal polyfill whether the era should be included or not, but for our case, it's safer to remove it
@@ -43,7 +45,6 @@ const NavigationContainer = _ref => {
43
45
  "data-test": "calendar-previous-month",
44
46
  "aria-label": `${_index.default.t(`Go to ${prevMonth.label}`)}`,
45
47
  type: "button",
46
- tabIndex: unfocusable ? -1 : 0,
47
48
  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]]])
48
49
  }, /*#__PURE__*/_react.default.createElement(PreviousIcon, {
49
50
  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]]])
@@ -59,7 +60,6 @@ const NavigationContainer = _ref => {
59
60
  name: "next-month",
60
61
  "aria-label": `${_index.default.t(`Go to ${nextMonth.label}`)}`,
61
62
  type: "button",
62
- tabIndex: unfocusable ? -1 : 0,
63
63
  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]]])
64
64
  }, /*#__PURE__*/_react.default.createElement(NextIcon, {
65
65
  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]]])
@@ -72,7 +72,6 @@ const NavigationContainer = _ref => {
72
72
  name: "previous-year",
73
73
  "aria-label": `${_index.default.t('Go to previous year')}`,
74
74
  type: "button",
75
- tabIndex: unfocusable ? -1 : 0,
76
75
  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]]])
77
76
  }, /*#__PURE__*/_react.default.createElement(PreviousIcon, {
78
77
  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]]])
@@ -88,7 +87,6 @@ const NavigationContainer = _ref => {
88
87
  name: "next-year",
89
88
  "aria-label": `${_index.default.t('Go to next year')}`,
90
89
  type: "button",
91
- tabIndex: unfocusable ? -1 : 0,
92
90
  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]]])
93
91
  }, /*#__PURE__*/_react.default.createElement(NextIcon, {
94
92
  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,30 +96,30 @@ const NavigationContainer = _ref => {
98
96
  }, ["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:${_uiConstants.spacers.dp4};height:24px;width:24px;color:${_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:${_uiConstants.colors.grey200};color:${_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:${_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:${_uiConstants.spacers.dp8};padding:${_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 ${wrapperBorderColor};background-color:${headerBackground};font-size:1.08em;}`]));
99
97
  };
100
98
  exports.NavigationContainer = NavigationContainer;
101
- const NavigationContainerProps = exports.NavigationContainerProps = {
102
- currMonth: _propTypes.default.shape({
103
- label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
104
- }),
105
- currYear: _propTypes.default.shape({
106
- label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
107
- }),
99
+ NavigationContainer.propTypes = {
108
100
  languageDirection: _propTypes.default.oneOf(['ltr', 'rtl']),
109
- nextMonth: _propTypes.default.shape({
110
- label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
111
- navigateTo: _propTypes.default.func
112
- }),
113
- nextYear: _propTypes.default.shape({
114
- label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
115
- navigateTo: _propTypes.default.func
116
- }),
117
- prevMonth: _propTypes.default.shape({
118
- label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
119
- navigateTo: _propTypes.default.func
120
- }),
121
- prevYear: _propTypes.default.shape({
122
- label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
123
- navigateTo: _propTypes.default.func
124
- }),
125
- unfocusable: _propTypes.default.bool
126
- };
127
- NavigationContainer.propTypes = NavigationContainerProps;
101
+ pickerOptions: _propTypes.default.shape({
102
+ currMonth: _propTypes.default.shape({
103
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
104
+ }),
105
+ currYear: _propTypes.default.shape({
106
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
107
+ }),
108
+ nextMonth: _propTypes.default.shape({
109
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
110
+ navigateTo: _propTypes.default.func
111
+ }),
112
+ nextYear: _propTypes.default.shape({
113
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
114
+ navigateTo: _propTypes.default.func
115
+ }),
116
+ prevMonth: _propTypes.default.shape({
117
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
118
+ navigateTo: _propTypes.default.func
119
+ }),
120
+ prevYear: _propTypes.default.shape({
121
+ label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
122
+ navigateTo: _propTypes.default.func
123
+ })
124
+ })
125
+ };
@@ -5,16 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.CalendarInput = void 0;
7
7
  var _style = _interopRequireDefault(require("styled-jsx/style"));
8
- var _multiCalendarDates = require("@dhis2/multi-calendar-dates");
9
8
  var _button = require("@dhis2-ui/button");
10
9
  var _card = require("@dhis2-ui/card");
11
10
  var _input = require("@dhis2-ui/input");
12
11
  var _layer = require("@dhis2-ui/layer");
13
12
  var _popper = require("@dhis2-ui/popper");
14
13
  var _classnames = _interopRequireDefault(require("classnames"));
15
- var _propTypes = _interopRequireDefault(require("prop-types"));
16
14
  var _react = _interopRequireWildcard(require("react"));
17
- var _calendarContainer = require("../calendar/calendar-container.js");
15
+ var _calendar = require("../calendar/calendar.js");
18
16
  var _index = _interopRequireDefault(require("../locales/index.js"));
19
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -28,103 +26,58 @@ const offsetModifier = {
28
26
  };
29
27
  const CalendarInput = function () {
30
28
  let {
31
- onDateSelect: parentOnDateSelect,
29
+ onDateSelect,
32
30
  calendar,
33
31
  date,
34
32
  dir,
35
33
  locale,
36
34
  numberingSystem,
37
35
  weekDayFormat,
36
+ timeZone,
38
37
  width,
39
38
  cellSize,
40
39
  clearable,
41
- minDate,
42
- maxDate,
43
- format,
44
- // todo: props and types for format and validation
45
- strictValidation,
40
+ dataTest = 'dhis2-uiwidgets-calendar-inputfield',
46
41
  ...rest
47
42
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
48
43
  const ref = (0, _react.useRef)();
49
44
  const [open, setOpen] = (0, _react.useState)(false);
50
- const [partialDate, setPartialDate] = (0, _react.useState)(date);
51
- const excludeRef = (0, _react.useRef)(null);
52
- (0, _react.useEffect)(() => setPartialDate(date), [date]);
53
- const useDatePickerOptions = (0, _react.useMemo)(() => ({
54
- calendar,
55
- locale,
56
- numberingSystem,
57
- weekDayFormat
58
- }), [calendar, locale, numberingSystem, weekDayFormat]);
59
- const pickerResults = (0, _multiCalendarDates.useDatePicker)({
60
- onDateSelect: result => {
45
+ const calendarProps = _react.default.useMemo(() => {
46
+ const onDateSelectWrapper = selectedDate => {
61
47
  setOpen(false);
62
- parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect(result);
63
- },
64
- date,
65
- minDate: minDate,
66
- maxDate: maxDate,
67
- strictValidation: strictValidation,
68
- format: format,
69
- options: useDatePickerOptions
70
- });
71
- const handleChange = e => {
72
- setOpen(false);
73
- setPartialDate(e.value);
74
- };
75
- const handleBlur = (_, e) => {
76
- const validated = (0, _multiCalendarDates.validateDateString)(partialDate, {
77
- calendar,
78
- format,
79
- minDateString: minDate,
80
- maxDateString: maxDate,
81
- strictValidation
82
- });
83
- parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
84
- calendarDateString: partialDate,
85
- ...validated
86
- });
87
- if (excludeRef.current && !excludeRef.current.contains(e.relatedTarget)) {
88
- setOpen(false);
89
- }
90
- };
91
- const onFocus = () => {
92
- setOpen(true);
93
- };
94
- const languageDirection = (0, _multiCalendarDates.useResolvedDirection)(dir, locale);
95
- const calendarProps = (0, _react.useMemo)(() => {
48
+ onDateSelect === null || onDateSelect === void 0 ? void 0 : onDateSelect(selectedDate);
49
+ };
96
50
  return {
51
+ onDateSelect: onDateSelectWrapper,
52
+ calendar,
97
53
  date,
54
+ dir,
55
+ locale,
56
+ numberingSystem,
57
+ weekDayFormat,
58
+ timeZone,
98
59
  width,
99
- cellSize,
100
- isValid: pickerResults.isValid,
101
- calendarWeekDays: pickerResults.calendarWeekDays,
102
- weekDayLabels: pickerResults.weekDayLabels,
103
- currMonth: pickerResults.currMonth,
104
- currYear: pickerResults.currYear,
105
- nextMonth: pickerResults.nextMonth,
106
- nextYear: pickerResults.nextYear,
107
- prevMonth: pickerResults.prevMonth,
108
- prevYear: pickerResults.prevYear,
109
- languageDirection
60
+ cellSize
110
61
  };
111
- }, [cellSize, date, pickerResults, width, languageDirection]);
62
+ }, [calendar, cellSize, date, dir, locale, numberingSystem, onDateSelect, timeZone, weekDayFormat, width]);
63
+ const onFocus = () => {
64
+ setOpen(true);
65
+ };
112
66
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
113
67
  ref: ref,
114
- className: "jsx-633677374" + " " + "calendar-input-wrapper"
68
+ className: "jsx-862452676" + " " + "calendar-input-wrapper"
115
69
  }, /*#__PURE__*/_react.default.createElement(_input.InputField, _extends({
116
70
  label: _index.default.t('Pick a date')
117
71
  }, rest, {
72
+ dataTest: dataTest,
118
73
  type: "text",
119
74
  onFocus: onFocus,
120
- value: partialDate,
121
- onChange: handleChange,
122
- onBlur: handleBlur,
123
- validationText: pickerResults.errorMessage || pickerResults.warningMessage,
124
- error: !!pickerResults.errorMessage,
125
- warning: !!pickerResults.warningMessage
75
+ value: date
126
76
  })), clearable && /*#__PURE__*/_react.default.createElement("div", {
127
- className: "jsx-633677374" + " " + ((0, _classnames.default)('calendar-clear-button', {
77
+ className: "jsx-862452676" + " " + ((0, _classnames.default)('calendar-clear-button', {
78
+ // ToDo: this is a workaround to show the clear button in the correct place when an icon is shown.
79
+ // Long-term, we should abstract and share the logic multi-select uses for the input-wrapper
80
+ // https://dhis2.atlassian.net/browse/DHIS2-14848
128
81
  'with-icon': rest.valid || rest.error || rest.warning || rest.loading,
129
82
  'with-dense-wrapper': rest.dense
130
83
  }) || "")
@@ -132,9 +85,7 @@ const CalendarInput = function () {
132
85
  dataTest: "calendar-clear-button",
133
86
  secondary: true,
134
87
  small: true,
135
- onClick: () => {
136
- parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect(null);
137
- },
88
+ onClick: () => calendarProps.onDateSelect(null),
138
89
  type: "button"
139
90
  }, _index.default.t('Clear')))), open && /*#__PURE__*/_react.default.createElement(_layer.Layer, {
140
91
  onBackdropClick: () => {
@@ -144,49 +95,14 @@ const CalendarInput = function () {
144
95
  reference: ref,
145
96
  placement: "bottom-start",
146
97
  modifiers: [offsetModifier]
147
- }, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(_calendarContainer.CalendarContainer, _extends({}, calendarProps, {
148
- excludedRef: excludeRef,
149
- unfocusable: true
98
+ }, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(_calendar.Calendar, _extends({}, calendarProps, {
99
+ date: date
150
100
  }))))), /*#__PURE__*/_react.default.createElement(_style.default, {
151
- id: "633677374"
152
- }, [".calendar-input-wrapper.jsx-633677374{position:relative;}", ".calendar-clear-button.jsx-633677374{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-633677374{inset-inline-end:36px;}", ".calendar-clear-button.with-dense-wrapper.jsx-633677374{-webkit-inset-block-start:23px;-ms-intb-rlock-start:23px;inset-block-start:23px;}"]));
101
+ id: "862452676"
102
+ }, [".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;}"]));
153
103
  };
154
104
  exports.CalendarInput = CalendarInput;
155
- CalendarInput.defaultProps = {
156
- dataTest: 'dhis2-uiwidgets-calendar-inputfield',
157
- cellSize: '32px',
158
- width: '240px',
159
- weekDayFormat: 'narrow'
160
- };
161
105
  CalendarInput.propTypes = {
162
- /** 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 */
163
- calendar: _propTypes.default.any.isRequired,
164
- /** 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` */
165
- onDateSelect: _propTypes.default.func.isRequired,
166
- /** the size of a single cell in the table forming the calendar */
167
- cellSize: _propTypes.default.string,
168
- /** Whether the clear button is displayed */
169
- clearable: _propTypes.default.bool,
170
- /** 'data-test' attribute of `InputField` component */
171
- dataTest: _propTypes.default.string,
172
- /** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
173
- date: _propTypes.default.string,
174
- /** the direction of the library - internally the library will use rtl for rtl-languages but this can be overridden here for more control */
175
- dir: _propTypes.default.oneOf(['ltr', 'rtl']),
176
- /** The date format to use either `YYYY-MM-DD` or `DD-MM-YYYY` */
177
- format: _propTypes.default.oneOf(['YYYY-MM-DD', 'DD-MM-YYYY']),
178
- /** 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) */
179
- locale: _propTypes.default.string,
180
- /** The maximum selectable date */
181
- maxDate: _propTypes.default.string,
182
- /** The minimum selectable date */
183
- minDate: _propTypes.default.string,
184
- /** numbering system to use - full list here https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/numberingSystems.ts */
185
- numberingSystem: _propTypes.default.string,
186
- /** Whether to use strict validation by showing errors for out-of-range dates when enabled (default), and warnings when disabled */
187
- strictValidation: _propTypes.default.bool,
188
- /** the format to display for the week day, i.e. Monday (long), Mon (short), M (narrow) */
189
- weekDayFormat: _propTypes.default.oneOf(['narrow', 'short', 'long']),
190
- /** the width of the calendar component */
191
- width: _propTypes.default.string
106
+ ..._calendar.CalendarProps,
107
+ ..._input.InputFieldProps
192
108
  };
@@ -3,17 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CalendarWithClearButton = void 0;
7
- exports.CalendarWithEditiableInput = CalendarWithEditiableInput;
8
- exports.CalendarWithEditiableInputReactForm = CalendarWithEditiableInputReactForm;
9
- exports.default = exports.NepaliWithNepali = exports.NepaliWithEnglish = exports.IslamicWithArabic = exports.GregorianWithEnglish = exports.GregorianWithArabic = exports.EthiopicWithEnglish = exports.EthiopicWithAmharic = void 0;
6
+ exports.default = exports.NepaliWithNepali = exports.NepaliWithEnglish = exports.IslamicWithArabic = exports.GregorianWithEnglish = exports.GregorianWithArabic = exports.EthiopicWithEnglish = exports.EthiopicWithAmharic = exports.CalendarWithClearButton = void 0;
10
7
  var _react = _interopRequireWildcard(require("react"));
11
- var _reactFinalForm = require("react-final-form");
12
8
  var _calendarInput = require("../calendar-input/calendar-input.js");
13
9
  var _calendarStoryWrapper = require("./calendar-story-wrapper.js");
14
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
17
12
  const subtitle = `[Experimental] Calendar Input is a wrapper around Calendar displaying an input that triggers the calendar`;
18
13
  const description = `
19
14
  Use a CalendarInput where there is a need to let the user input a date.
@@ -119,68 +114,4 @@ const CalendarWithClearButton = _ref2 => {
119
114
  "data-test": "storybook-calendar-date-value"
120
115
  }, date !== null && date !== void 0 ? date : 'undefined')));
121
116
  };
122
- exports.CalendarWithClearButton = CalendarWithClearButton;
123
- function CalendarWithEditiableInput() {
124
- const [date, setDate] = (0, _react.useState)('2020-07-03');
125
- return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_calendarInput.CalendarInput, {
126
- editable: true,
127
- date: date,
128
- calendar: "gregory",
129
- onDateSelect: selectedDate => {
130
- const date = selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.calendarDateString;
131
- setDate(date);
132
- },
133
- width: '700px',
134
- inputWidth: "900px",
135
- minDate: '2020-07-01',
136
- maxDate: '2020-07-09'
137
- })));
138
- }
139
- function CalendarWithEditiableInputReactForm() {
140
- const [calendarError, setCalendarError] = (0, _react.useState)(undefined);
141
- const errored = () => {
142
- return {
143
- calendar: calendarError
144
- };
145
- };
146
- return /*#__PURE__*/_react.default.createElement(_reactFinalForm.Form, {
147
- onSubmit: (values, meta) => {
148
- console.log('SUBMITTING', {
149
- values,
150
- meta
151
- });
152
- },
153
- initialValues: {
154
- calendar: '2022-10-12'
155
- },
156
- validate: errored
157
- }, _ref3 => {
158
- let {
159
- handleSubmit
160
- } = _ref3;
161
- return /*#__PURE__*/_react.default.createElement("form", {
162
- onSubmit: handleSubmit
163
- }, /*#__PURE__*/_react.default.createElement(_reactFinalForm.Field, {
164
- name: "calendar"
165
- }, props => /*#__PURE__*/_react.default.createElement(_calendarInput.CalendarInput, _extends({}, props, {
166
- input: props.input,
167
- meta: props.meta,
168
- editable: true,
169
- date: props.input.value,
170
- calendar: "gregory",
171
- onDateSelect: date => {
172
- if (!date.isValid) {
173
- setCalendarError(date.errorMessage);
174
- } else {
175
- setCalendarError(undefined);
176
- }
177
- props.input.onChange(date ? date === null || date === void 0 ? void 0 : date.calendarDateString : '');
178
- },
179
- timeZone: 'UTC'
180
- }))), /*#__PURE__*/_react.default.createElement("button", {
181
- type: "submit",
182
- disabled: false,
183
- onClick: handleSubmit
184
- }, "Submit"));
185
- });
186
- }
117
+ exports.CalendarWithClearButton = CalendarWithClearButton;
@@ -19,13 +19,13 @@ const {
19
19
  const CalendarStoryWrapper = props => {
20
20
  var _selectedDate$calenda;
21
21
  const {
22
- calendar,
22
+ calendar = 'gregory',
23
23
  locale,
24
24
  timeZone,
25
25
  dir,
26
- component: Component,
26
+ component: Component = _calendar.Calendar,
27
27
  date,
28
- weekDayFormat
28
+ weekDayFormat = 'narrow'
29
29
  } = props;
30
30
  const [selectedCalendar, setSelectedCalendar] = (0, _react.useState)(calendar);
31
31
  const [selectedNumberingSystem, setSelectedNumberingSystem] = (0, _react.useState)();
@@ -165,11 +165,6 @@ const CalendarStoryWrapper = props => {
165
165
  }))), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("label", null, "callback:"), JSON.stringify(selectedDate, null, 2))))));
166
166
  };
167
167
  exports.CalendarStoryWrapper = CalendarStoryWrapper;
168
- CalendarStoryWrapper.defaultProps = {
169
- calendar: 'gregorian',
170
- component: _calendar.Calendar,
171
- weekDayFormat: 'narrow'
172
- };
173
168
  CalendarStoryWrapper.propTypes = {
174
169
  calendar: _propTypes.default.string.isRequired,
175
170
  component: _propTypes.default.elementType.isRequired,