@dhis2-ui/calendar 9.12.0-alpha.4 → 9.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. package/build/cjs/calendar/calendar-table-cell.js +2 -5
  2. package/build/cjs/calendar/calendar-table.js +5 -9
  3. package/build/cjs/calendar/calendar.js +33 -34
  4. package/build/cjs/calendar/navigation-container.js +56 -58
  5. package/build/cjs/calendar-input/calendar-input.js +34 -136
  6. package/build/cjs/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +1 -0
  7. package/build/cjs/features/supports_gregorian_calendar/supports_gregorian_calendar.js +1 -0
  8. package/build/cjs/features/supports_nepali_calendar/supports_nepali_calendar.js +1 -0
  9. package/build/cjs/stories/calendar-input.prod.stories.js +2 -70
  10. package/build/cjs/stories/calendar-story-wrapper.js +9 -9
  11. package/build/es/calendar/calendar-table-cell.js +2 -5
  12. package/build/es/calendar/calendar-table.js +4 -8
  13. package/build/es/calendar/calendar.js +34 -35
  14. package/build/es/calendar/navigation-container.js +55 -57
  15. package/build/es/calendar-input/calendar-input.js +36 -138
  16. package/build/es/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +1 -0
  17. package/build/es/features/supports_gregorian_calendar/supports_gregorian_calendar.js +1 -0
  18. package/build/es/features/supports_nepali_calendar/supports_nepali_calendar.js +1 -0
  19. package/build/es/stories/calendar-input.prod.stories.js +1 -66
  20. package/build/es/stories/calendar-story-wrapper.js +9 -9
  21. package/package.json +13 -13
  22. package/build/cjs/calendar/calendar-container.js +0 -81
  23. package/build/cjs/calendar-input/__tests__/calendar-input.test.js +0 -46
  24. package/build/es/calendar/calendar-container.js +0 -72
  25. package/build/es/calendar-input/__tests__/calendar-input.test.js +0 -43
@@ -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,117 +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
- strictValidation,
36
- inputWidth,
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 [isIconDisplayed, setIsIconDisplayed] = useState(false);
43
- const excludeRef = useRef(null);
44
- useEffect(() => setPartialDate(date), [date]);
45
- const useDatePickerOptions = useMemo(() => ({
46
- calendar,
47
- locale,
48
- numberingSystem,
49
- weekDayFormat
50
- }), [calendar, locale, numberingSystem, weekDayFormat]);
51
- const pickerResults = useDatePicker({
52
- onDateSelect: result => {
53
- const validated = validateDateString(result.calendarDateString, {
54
- calendar,
55
- format,
56
- minDateString: minDate,
57
- maxDateString: maxDate,
58
- strictValidation
59
- });
60
- setIsIconDisplayed(validated.errorMessage || validated.warningMessage);
36
+ const calendarProps = React.useMemo(() => {
37
+ const onDateSelectWrapper = selectedDate => {
61
38
  setOpen(false);
62
- parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
63
- calendarDateString: result.calendarDateString,
64
- ...validated
65
- });
66
- },
67
- date,
68
- minDate: minDate,
69
- maxDate: maxDate,
70
- strictValidation: strictValidation,
71
- format: format,
72
- options: useDatePickerOptions
73
- });
74
- const handleChange = e => {
75
- setOpen(false);
76
- setPartialDate(e.value);
77
- };
78
- const handleBlur = (_, e) => {
79
- const validated = validateDateString(partialDate, {
80
- calendar,
81
- format,
82
- minDateString: minDate,
83
- maxDateString: maxDate,
84
- strictValidation
85
- });
86
- setIsIconDisplayed(validated.errorMessage || validated.warningMessage);
87
- parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect({
88
- calendarDateString: partialDate,
89
- ...validated
90
- });
91
- if (excludeRef.current && !excludeRef.current.contains(e.relatedTarget)) {
92
- setOpen(false);
93
- }
94
- };
95
- const onFocus = () => {
96
- setOpen(true);
97
- };
98
- const languageDirection = useResolvedDirection(dir, locale);
99
- const calendarProps = useMemo(() => {
39
+ onDateSelect === null || onDateSelect === void 0 ? void 0 : onDateSelect(selectedDate);
40
+ };
100
41
  return {
42
+ onDateSelect: onDateSelectWrapper,
43
+ calendar,
101
44
  date,
45
+ dir,
46
+ locale,
47
+ numberingSystem,
48
+ weekDayFormat,
49
+ timeZone,
102
50
  width,
103
- cellSize,
104
- isValid: pickerResults.isValid,
105
- calendarWeekDays: pickerResults.calendarWeekDays,
106
- weekDayLabels: pickerResults.weekDayLabels,
107
- currMonth: pickerResults.currMonth,
108
- currYear: pickerResults.currYear,
109
- nextMonth: pickerResults.nextMonth,
110
- nextYear: pickerResults.nextYear,
111
- prevMonth: pickerResults.prevMonth,
112
- prevYear: pickerResults.prevYear,
113
- languageDirection
51
+ cellSize
114
52
  };
115
- }, [cellSize, date, pickerResults, width, languageDirection]);
53
+ }, [calendar, cellSize, date, dir, locale, numberingSystem, onDateSelect, timeZone, weekDayFormat, width]);
54
+ const onFocus = () => {
55
+ setOpen(true);
56
+ };
116
57
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
117
58
  ref: ref,
118
- className: _JSXStyle.dynamic([["1003597543", [inputWidth, isIconDisplayed ? '36px' : '6px']]]) + " " + "calendar-input-wrapper"
59
+ className: "jsx-862452676" + " " + "calendar-input-wrapper"
119
60
  }, /*#__PURE__*/React.createElement(InputField, _extends({
120
61
  label: i18n.t('Pick a date')
121
62
  }, rest, {
63
+ dataTest: dataTest,
122
64
  type: "text",
123
65
  onFocus: onFocus,
124
- value: partialDate,
125
- onChange: handleChange,
126
- onBlur: handleBlur,
127
- validationText: pickerResults.errorMessage || pickerResults.warningMessage,
128
- error: !!pickerResults.errorMessage,
129
- warning: !!pickerResults.warningMessage,
130
- inputWidth: inputWidth
66
+ value: date
131
67
  })), clearable && /*#__PURE__*/React.createElement("div", {
132
- className: _JSXStyle.dynamic([["1003597543", [inputWidth, isIconDisplayed ? '36px' : '6px']]]) + " " + (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
133
72
  'with-icon': rest.valid || rest.error || rest.warning || rest.loading,
134
73
  'with-dense-wrapper': rest.dense
135
74
  }) || "")
@@ -137,10 +76,7 @@ export const CalendarInput = function () {
137
76
  dataTest: "calendar-clear-button",
138
77
  secondary: true,
139
78
  small: true,
140
- onClick: () => {
141
- parentOnDateSelect === null || parentOnDateSelect === void 0 ? void 0 : parentOnDateSelect(null);
142
- setIsIconDisplayed(false);
143
- },
79
+ onClick: () => calendarProps.onDateSelect(null),
144
80
  type: "button"
145
81
  }, i18n.t('Clear')))), open && /*#__PURE__*/React.createElement(Layer, {
146
82
  onBackdropClick: () => {
@@ -150,51 +86,13 @@ export const CalendarInput = function () {
150
86
  reference: ref,
151
87
  placement: "bottom-start",
152
88
  modifiers: [offsetModifier]
153
- }, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(CalendarContainer, _extends({}, calendarProps, {
154
- excludedRef: excludeRef,
155
- unfocusable: true
89
+ }, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(Calendar, _extends({}, calendarProps, {
90
+ date: date
156
91
  }))))), /*#__PURE__*/React.createElement(_JSXStyle, {
157
- id: "1003597543",
158
- dynamic: [inputWidth, isIconDisplayed ? '36px' : '6px']
159
- }, [`.calendar-input-wrapper.__jsx-style-dynamic-selector{position:relative;width:${inputWidth};}`, `.calendar-clear-button.__jsx-style-dynamic-selector{position:absolute;inset-inline-end:${isIconDisplayed ? '36px' : '6px'};-webkit-inset-block-start:27px;-ms-intb-rlock-start:27px;inset-block-start:27px;}`, ".calendar-clear-button.with-icon.__jsx-style-dynamic-selector{inset-inline-end:36px;}", ".calendar-clear-button.with-dense-wrapper.__jsx-style-dynamic-selector{-webkit-inset-block-start:23px;-ms-intb-rlock-start:23px;inset-block-start:23px;}"]));
160
- };
161
- CalendarInput.defaultProps = {
162
- dataTest: 'dhis2-uiwidgets-calendar-inputfield',
163
- cellSize: '32px',
164
- width: '300px',
165
- 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;}"]));
166
94
  };
167
95
  CalendarInput.propTypes = {
168
- /** 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 */
169
- calendar: PropTypes.any.isRequired,
170
- /** 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` */
171
- onDateSelect: PropTypes.func.isRequired,
172
- /** the size of a single cell in the table forming the calendar */
173
- cellSize: PropTypes.string,
174
- /** Whether the clear button is displayed */
175
- clearable: PropTypes.bool,
176
- /** 'data-test' attribute of `InputField` component */
177
- dataTest: PropTypes.string,
178
- /** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
179
- date: PropTypes.string,
180
- /** the direction of the library - internally the library will use rtl for rtl-languages but this can be overridden here for more control */
181
- dir: PropTypes.oneOf(['ltr', 'rtl']),
182
- /** The date format to use either `YYYY-MM-DD` or `DD-MM-YYYY` */
183
- format: PropTypes.oneOf(['YYYY-MM-DD', 'DD-MM-YYYY']),
184
- /** the width of input field */
185
- inputWidth: PropTypes.string,
186
- /** 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) */
187
- locale: PropTypes.string,
188
- /** The maximum selectable date */
189
- maxDate: PropTypes.string,
190
- /** The minimum selectable date */
191
- minDate: PropTypes.string,
192
- /** numbering system to use - full list here https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/numberingSystems.ts */
193
- numberingSystem: PropTypes.string,
194
- /** Whether to use strict validation by showing errors for out-of-range dates when enabled (default), and warnings when disabled */
195
- strictValidation: PropTypes.bool,
196
- /** the format to display for the week day, i.e. Monday (long), Mon (short), M (narrow) */
197
- weekDayFormat: PropTypes.oneOf(['narrow', 'short', 'long']),
198
- /** the width of the calendar component */
199
- width: PropTypes.string
96
+ ...CalendarProps,
97
+ ...InputFieldProps
200
98
  };
@@ -35,4 +35,5 @@ Then('we should be able to select a day', () => {
35
35
  cy.get(`[data-test="${date}"]`).click();
36
36
  cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', date);
37
37
  cy.get('[data-test="storybook-calendar-result"]').should('have.text', date);
38
+ cy.get('[data-test="storybook-calendar-result-iso"]').should('have.text', '13 October 2021');
38
39
  });
@@ -32,4 +32,5 @@ Then('we should be able to select a day', () => {
32
32
  cy.get(`[data-test="${date}"]`).click();
33
33
  cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', date);
34
34
  cy.get('[data-test="storybook-calendar-result"]').should('have.text', date);
35
+ cy.get('[data-test="storybook-calendar-result-iso"]').should('have.text', '13 October 2021');
35
36
  });
@@ -36,4 +36,5 @@ Then('we should be able to select a day', () => {
36
36
  cy.get(`[data-test="${nepaliDate}"]`).click();
37
37
  cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', nepaliDate);
38
38
  cy.get('[data-test="storybook-calendar-result"]').should('have.text', nepaliDate);
39
+ cy.get('[data-test="storybook-calendar-result-iso"]').should('have.text', '13 October 2021');
39
40
  });
@@ -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,67 +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
- date: date,
114
- calendar: "gregory",
115
- onDateSelect: selectedDate => {
116
- const date = selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.calendarDateString;
117
- setDate(date);
118
- },
119
- width: "400px",
120
- minDate: "2020-07-01",
121
- maxDate: "2020-07-09",
122
- clearable: true
123
- })));
124
- }
125
- export function CalendarWithEditiableInputReactForm() {
126
- const [calendarError, setCalendarError] = useState(undefined);
127
- const errored = () => {
128
- return {
129
- calendar: calendarError
130
- };
131
- };
132
- return /*#__PURE__*/React.createElement(Form, {
133
- onSubmit: (values, meta) => {
134
- console.log('SUBMITTING', {
135
- values,
136
- meta
137
- });
138
- },
139
- initialValues: {
140
- calendar: '2022-10-12'
141
- },
142
- validate: errored
143
- }, _ref3 => {
144
- let {
145
- handleSubmit
146
- } = _ref3;
147
- return /*#__PURE__*/React.createElement("form", {
148
- onSubmit: handleSubmit
149
- }, /*#__PURE__*/React.createElement(Field, {
150
- name: "calendar"
151
- }, props => /*#__PURE__*/React.createElement(CalendarInput, _extends({}, props, {
152
- input: props.input,
153
- meta: props.meta,
154
- editable: true,
155
- date: props.input.value,
156
- calendar: "gregory",
157
- onDateSelect: date => {
158
- if (!date.isValid) {
159
- setCalendarError(date.errorMessage);
160
- } else {
161
- setCalendarError(undefined);
162
- }
163
- props.input.onChange(date ? date === null || date === void 0 ? void 0 : date.calendarDateString : '');
164
- },
165
- timeZone: 'UTC'
166
- }))), /*#__PURE__*/React.createElement("button", {
167
- type: "submit",
168
- disabled: false,
169
- onClick: handleSubmit
170
- }, "Submit"));
171
- });
172
- }
107
+ };
@@ -8,14 +8,15 @@ const {
8
8
  numberingSystems
9
9
  } = constants;
10
10
  export const CalendarStoryWrapper = props => {
11
+ var _selectedDate$calenda;
11
12
  const {
12
- calendar,
13
+ calendar = 'gregory',
13
14
  locale,
14
15
  timeZone,
15
16
  dir,
16
- component: Component,
17
+ component: Component = Calendar,
17
18
  date,
18
- weekDayFormat
19
+ weekDayFormat = 'narrow'
19
20
  } = props;
20
21
  const [selectedCalendar, setSelectedCalendar] = useState(calendar);
21
22
  const [selectedNumberingSystem, setSelectedNumberingSystem] = useState();
@@ -148,12 +149,11 @@ export const CalendarStoryWrapper = props => {
148
149
  }
149
150
  }, /*#__PURE__*/React.createElement("div", null, selectedDate && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "calendar date: "), /*#__PURE__*/React.createElement("span", {
150
151
  "data-test": "storybook-calendar-result"
151
- }, selectedDate.calendarDateString)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "callback:"), JSON.stringify(selectedDate, null, 2))))));
152
- };
153
- CalendarStoryWrapper.defaultProps = {
154
- calendar: 'gregorian',
155
- component: Calendar,
156
- weekDayFormat: 'narrow'
152
+ }, selectedDate.calendarDateString)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "iso date: "), /*#__PURE__*/React.createElement("span", {
153
+ "data-test": "storybook-calendar-result-iso"
154
+ }, (_selectedDate$calenda = selectedDate.calendarDate) === null || _selectedDate$calenda === void 0 ? void 0 : _selectedDate$calenda.withCalendar('iso8601').toLocaleString('en-GB', {
155
+ dateStyle: 'long'
156
+ }))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "callback:"), JSON.stringify(selectedDate, null, 2))))));
157
157
  };
158
158
  CalendarStoryWrapper.propTypes = {
159
159
  calendar: PropTypes.string.isRequired,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/calendar",
3
- "version": "9.12.0-alpha.4",
3
+ "version": "9.13.0",
4
4
  "description": "UI Calendar",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,20 +28,20 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@dhis2/d2-i18n": "^1",
31
- "react": "^16.13",
32
- "react-dom": "^16.13",
31
+ "react": "^16.13 || ^18",
32
+ "react-dom": "^16.13 || ^18",
33
33
  "styled-jsx": "^4"
34
34
  },
35
35
  "dependencies": {
36
- "@dhis2-ui/button": "9.12.0-alpha.4",
37
- "@dhis2-ui/card": "9.12.0-alpha.4",
38
- "@dhis2-ui/input": "9.12.0-alpha.4",
39
- "@dhis2-ui/layer": "9.12.0-alpha.4",
40
- "@dhis2-ui/popper": "9.12.0-alpha.4",
41
- "@dhis2/multi-calendar-dates": "1.3.0",
36
+ "@dhis2-ui/button": "9.13.0",
37
+ "@dhis2-ui/card": "9.13.0",
38
+ "@dhis2-ui/input": "9.13.0",
39
+ "@dhis2-ui/layer": "9.13.0",
40
+ "@dhis2-ui/popper": "9.13.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.4",
44
- "@dhis2/ui-icons": "9.12.0-alpha.4",
43
+ "@dhis2/ui-constants": "9.13.0",
44
+ "@dhis2/ui-icons": "9.13.0",
45
45
  "classnames": "^2.3.1",
46
46
  "prop-types": "^15.7.2"
47
47
  },
@@ -51,8 +51,8 @@
51
51
  ],
52
52
  "devDependencies": {
53
53
  "@dhis2/d2-i18n": "^1.1.0",
54
- "react": "16.13",
55
- "react-dom": "16.13",
54
+ "react": "^18.3.1",
55
+ "react-dom": "^18.3.1",
56
56
  "styled-jsx": "^4.0.1"
57
57
  },
58
58
  "types": "types"
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CalendarContainer = void 0;
7
- var _style = _interopRequireDefault(require("styled-jsx/style"));
8
- var _uiConstants = require("@dhis2/ui-constants");
9
- var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _calendarTable = require("./calendar-table.js");
12
- var _navigationContainer = require("./navigation-container.js");
13
- 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); }
14
- 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; }
15
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
- const wrapperBorderColor = _uiConstants.colors.grey300;
18
- const backgroundColor = 'none';
19
- const CalendarContainer = exports.CalendarContainer = /*#__PURE__*/_react.default.memo(function CalendarContainer(_ref) {
20
- let {
21
- date,
22
- width,
23
- cellSize,
24
- calendarWeekDays,
25
- weekDayLabels,
26
- currMonth,
27
- currYear,
28
- nextMonth,
29
- nextYear,
30
- prevMonth,
31
- prevYear,
32
- languageDirection,
33
- excludedRef,
34
- unfocusable
35
- } = _ref;
36
- const navigationProps = (0, _react.useMemo)(() => {
37
- return {
38
- currMonth,
39
- currYear,
40
- nextMonth,
41
- nextYear,
42
- prevMonth,
43
- prevYear,
44
- languageDirection
45
- };
46
- }, [currMonth, currYear, languageDirection, nextMonth, nextYear, prevMonth, prevYear]);
47
- return /*#__PURE__*/_react.default.createElement("div", {
48
- className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
49
- }, /*#__PURE__*/_react.default.createElement("div", {
50
- dir: languageDirection,
51
- "data-test": "calendar",
52
- className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
53
- }, /*#__PURE__*/_react.default.createElement("div", {
54
- ref: excludedRef,
55
- className: _style.default.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
56
- }, /*#__PURE__*/_react.default.createElement(_navigationContainer.NavigationContainer, _extends({}, navigationProps, {
57
- unfocusable: unfocusable
58
- })), /*#__PURE__*/_react.default.createElement(_calendarTable.CalendarTable, {
59
- selectedDate: date,
60
- calendarWeekDays: calendarWeekDays,
61
- weekDayLabels: weekDayLabels,
62
- cellSize: cellSize,
63
- width: width,
64
- unfocusable: unfocusable
65
- }))), /*#__PURE__*/_react.default.createElement(_style.default, {
66
- id: "2823859047",
67
- dynamic: [backgroundColor, wrapperBorderColor, width]
68
- }, [`.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;}`]));
69
- });
70
- CalendarContainer.defaultProps = {
71
- cellSize: '32px',
72
- width: '240px',
73
- unfocusable: false
74
- };
75
- CalendarContainer.propTypes = {
76
- /** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
77
- date: _propTypes.default.string,
78
- unfocusable: _propTypes.default.bool,
79
- ..._calendarTable.CalendarTableProps,
80
- ..._navigationContainer.NavigationContainerProps
81
- };
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("@testing-library/react");
4
- var _react2 = _interopRequireDefault(require("react"));
5
- var _calendarInput = require("../calendar-input.js");
6
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
- describe('Calendar Input', () => {
8
- it('allow selection of a date through the calendar widget', async () => {
9
- const onDateSelectMock = jest.fn();
10
- const screen = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_calendarInput.CalendarInput, {
11
- calendar: "gregory",
12
- onDateSelect: onDateSelectMock
13
- }));
14
- const dateInput = (0, _react.within)(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
15
- _react.fireEvent.focus(dateInput);
16
- const calendar = await screen.findByTestId('calendar');
17
- expect(calendar).toBeInTheDocument();
18
- const todayString = new Date().toISOString().slice(0, -14);
19
- const today = (0, _react.within)(calendar).getByTestId(todayString);
20
- _react.fireEvent.click(today);
21
- await (0, _react.waitFor)(() => {
22
- expect(calendar).not.toBeInTheDocument();
23
- });
24
- expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
25
- calendarDateString: todayString
26
- }));
27
- });
28
- it('allow selection of a date through the input', async () => {
29
- const onDateSelectMock = jest.fn();
30
- const screen = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_calendarInput.CalendarInput, {
31
- calendar: "gregory",
32
- onDateSelect: onDateSelectMock
33
- }));
34
- const dateInputString = '2024/10/12';
35
- const dateInput = (0, _react.within)(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
36
- _react.fireEvent.change(dateInput, {
37
- target: {
38
- value: dateInputString
39
- }
40
- });
41
- _react.fireEvent.blur(dateInput);
42
- expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
43
- calendarDateString: dateInputString
44
- }));
45
- });
46
- });
@@ -1,72 +0,0 @@
1
- import _JSXStyle from "styled-jsx/style";
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 { colors } from '@dhis2/ui-constants';
4
- import PropTypes from 'prop-types';
5
- import React, { useMemo } from 'react';
6
- import { CalendarTable, CalendarTableProps } from './calendar-table.js';
7
- import { NavigationContainer, NavigationContainerProps } from './navigation-container.js';
8
- const wrapperBorderColor = colors.grey300;
9
- const backgroundColor = 'none';
10
- export const CalendarContainer = /*#__PURE__*/React.memo(function CalendarContainer(_ref) {
11
- let {
12
- date,
13
- width,
14
- cellSize,
15
- calendarWeekDays,
16
- weekDayLabels,
17
- currMonth,
18
- currYear,
19
- nextMonth,
20
- nextYear,
21
- prevMonth,
22
- prevYear,
23
- languageDirection,
24
- excludedRef,
25
- unfocusable
26
- } = _ref;
27
- const navigationProps = useMemo(() => {
28
- return {
29
- currMonth,
30
- currYear,
31
- nextMonth,
32
- nextYear,
33
- prevMonth,
34
- prevYear,
35
- languageDirection
36
- };
37
- }, [currMonth, currYear, languageDirection, nextMonth, nextYear, prevMonth, prevYear]);
38
- return /*#__PURE__*/React.createElement("div", {
39
- className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
40
- }, /*#__PURE__*/React.createElement("div", {
41
- dir: languageDirection,
42
- "data-test": "calendar",
43
- className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]]) + " " + "calendar-wrapper"
44
- }, /*#__PURE__*/React.createElement("div", {
45
- ref: excludedRef,
46
- className: _JSXStyle.dynamic([["2823859047", [backgroundColor, wrapperBorderColor, width]]])
47
- }, /*#__PURE__*/React.createElement(NavigationContainer, _extends({}, navigationProps, {
48
- unfocusable: unfocusable
49
- })), /*#__PURE__*/React.createElement(CalendarTable, {
50
- selectedDate: date,
51
- calendarWeekDays: calendarWeekDays,
52
- weekDayLabels: weekDayLabels,
53
- cellSize: cellSize,
54
- width: width,
55
- unfocusable: unfocusable
56
- }))), /*#__PURE__*/React.createElement(_JSXStyle, {
57
- id: "2823859047",
58
- dynamic: [backgroundColor, wrapperBorderColor, width]
59
- }, [`.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;}`]));
60
- });
61
- CalendarContainer.defaultProps = {
62
- cellSize: '32px',
63
- width: '240px',
64
- unfocusable: false
65
- };
66
- CalendarContainer.propTypes = {
67
- /** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
68
- date: PropTypes.string,
69
- unfocusable: PropTypes.bool,
70
- ...CalendarTableProps,
71
- ...NavigationContainerProps
72
- };
@@ -1,43 +0,0 @@
1
- import { fireEvent, render, waitFor, within } from '@testing-library/react';
2
- import React from 'react';
3
- import { CalendarInput } from '../calendar-input.js';
4
- describe('Calendar Input', () => {
5
- it('allow selection of a date through the calendar widget', async () => {
6
- const onDateSelectMock = jest.fn();
7
- const screen = render( /*#__PURE__*/React.createElement(CalendarInput, {
8
- calendar: "gregory",
9
- onDateSelect: onDateSelectMock
10
- }));
11
- const dateInput = within(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
12
- fireEvent.focus(dateInput);
13
- const calendar = await screen.findByTestId('calendar');
14
- expect(calendar).toBeInTheDocument();
15
- const todayString = new Date().toISOString().slice(0, -14);
16
- const today = within(calendar).getByTestId(todayString);
17
- fireEvent.click(today);
18
- await waitFor(() => {
19
- expect(calendar).not.toBeInTheDocument();
20
- });
21
- expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
22
- calendarDateString: todayString
23
- }));
24
- });
25
- it('allow selection of a date through the input', async () => {
26
- const onDateSelectMock = jest.fn();
27
- const screen = render( /*#__PURE__*/React.createElement(CalendarInput, {
28
- calendar: "gregory",
29
- onDateSelect: onDateSelectMock
30
- }));
31
- const dateInputString = '2024/10/12';
32
- const dateInput = within(screen.getByTestId('dhis2-uicore-input')).getByRole('textbox');
33
- fireEvent.change(dateInput, {
34
- target: {
35
- value: dateInputString
36
- }
37
- });
38
- fireEvent.blur(dateInput);
39
- expect(onDateSelectMock).toHaveBeenCalledWith(expect.objectContaining({
40
- calendarDateString: dateInputString
41
- }));
42
- });
43
- });