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