@dhis2-ui/calendar 8.11.2 → 8.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/build/cjs/__e2e__/{calendarInput.stories.e2e.js → calendar-input.stories.e2e.js} +21 -3
  2. package/build/cjs/calendar/calendar-table-cell.js +11 -9
  3. package/build/cjs/calendar/calendar-table-days-header.js +5 -5
  4. package/build/cjs/calendar/calendar-table.js +5 -2
  5. package/build/cjs/calendar/{index.js → calendar.js} +37 -4
  6. package/build/cjs/calendar/navigation-container.js +28 -33
  7. package/build/cjs/calendar-input/{index.js → calendar-input.js} +34 -22
  8. package/build/cjs/features/supports_calendar_clear_button/supports_calendar_clear_button.js +34 -0
  9. package/build/cjs/features/supports_calendar_clear_button.feature +23 -0
  10. package/build/cjs/index.js +4 -4
  11. package/build/cjs/locales/en/translations.json +2 -1
  12. package/build/cjs/stories/calendar-input.stories.js +129 -0
  13. package/build/cjs/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +9 -5
  14. package/build/cjs/stories/calendar.stories.js +3 -3
  15. package/build/es/__e2e__/calendar-input.stories.e2e.js +19 -0
  16. package/build/es/calendar/calendar-table-cell.js +12 -10
  17. package/build/es/calendar/calendar-table-days-header.js +5 -5
  18. package/build/es/calendar/calendar-table.js +5 -2
  19. package/build/es/calendar/{index.js → calendar.js} +33 -1
  20. package/build/es/calendar/navigation-container.js +28 -33
  21. package/build/es/calendar-input/{index.js → calendar-input.js} +29 -21
  22. package/build/es/features/supports_calendar_clear_button/supports_calendar_clear_button.js +31 -0
  23. package/build/es/features/supports_calendar_clear_button.feature +23 -0
  24. package/build/es/index.js +2 -2
  25. package/build/es/locales/en/translations.json +2 -1
  26. package/build/es/stories/{calendarInput.stories.js → calendar-input.stories.js} +34 -16
  27. package/build/es/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +8 -4
  28. package/build/es/stories/calendar.stories.js +2 -2
  29. package/package.json +8 -7
  30. package/build/cjs/calendar/calendar-prop-types.js +0 -24
  31. package/build/cjs/stories/calendarInput.stories.js +0 -107
  32. package/build/es/__e2e__/calendarInput.stories.e2e.js +0 -6
  33. package/build/es/calendar/calendar-prop-types.js +0 -13
@@ -0,0 +1,31 @@
1
+ import { Given, Then, And } from 'cypress-cucumber-preprocessor/steps';
2
+ Given('a "{word}" calendar is rendered with a selected date "{word}"', (calendar, initialDate) => {
3
+ cy.visitStory('CalendarInputTesting', 'Test Calendar With Clear Button', {
4
+ qs: {
5
+ initialDate,
6
+ calendar
7
+ }
8
+ });
9
+ cy.get('[data-test="storybook-calendar-date-value"]').should('have.text', initialDate);
10
+ });
11
+ Then('we should be able to clear it', () => {
12
+ cy.get("[data-test=\"calendar-clear-button\"]").click();
13
+ cy.get('[data-test="storybook-calendar-date-value"]').should('have.text', 'undefined');
14
+ });
15
+ And('show the current month afterwards', () => {
16
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
17
+ cy.get('.isToday').should('be.visible');
18
+ });
19
+ And("allow selecting today's date", () => {
20
+ cy.get('.isToday').parent().invoke('attr', 'data-test').then(todayDate => {
21
+ cy.get('.isToday').click();
22
+ cy.get('[data-test="storybook-calendar-date-value"]').should('have.text', todayDate);
23
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"] input').should('have.value', todayDate);
24
+ });
25
+ });
26
+ And('highlight today as the selected date', () => {
27
+ cy.get('[data-test="dhis2-uiwidgets-calendar-inputfield"]').click();
28
+ cy.get('.isToday').parent().invoke('attr', 'data-test').then(todayDate => {
29
+ cy.get('.isSelected').should('have.text', Number(todayDate.split('-')[2]).toString());
30
+ });
31
+ });
@@ -0,0 +1,23 @@
1
+ Feature: The Calendar allows clearing the selection
2
+
3
+ Scenario: Clear the selection in the Gregorian calendar
4
+ Given a "gregory" calendar is rendered with a selected date "2021-10-13"
5
+ Then we should be able to clear it
6
+ And show the current month afterwards
7
+ And allow selecting today's date
8
+ And highlight today as the selected date
9
+
10
+ Scenario: Clear the selection in the Ethiopic calendar
11
+ Given a "ethiopic" calendar is rendered with a selected date "2014-02-03"
12
+ Then we should be able to clear it
13
+ And show the current month afterwards
14
+ And allow selecting today's date
15
+ And highlight today as the selected date
16
+
17
+ Scenario: Clear the selection in the Nepali calendar
18
+ Given a "nepali" calendar is rendered with a selected date "2078-06-27"
19
+ Then we should be able to clear it
20
+ And show the current month afterwards
21
+ And allow selecting today's date
22
+ And highlight today as the selected date
23
+
package/build/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { Calendar } from './calendar/index.js';
2
- export { CalendarInput } from './calendar-input/index.js';
1
+ export { Calendar } from './calendar/calendar.js';
2
+ export { CalendarInput } from './calendar-input/calendar-input.js';
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "Go to previous year": "Go to previous year",
3
- "Go to next year": "Go to next year"
3
+ "Go to next year": "Go to next year",
4
+ "Clear": "Clear"
4
5
  }
@@ -1,8 +1,6 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React from 'react';
4
- import { CalendarInput } from '../calendar-input/index.js';
5
- import { CalendarStoryWrapper } from './calendarStoryWrapper.js';
1
+ import React, { useState } from 'react';
2
+ import { CalendarInput } from '../calendar-input/calendar-input.js';
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";
7
5
  const description = "\nUse a CalendarInput where there is a need to let the user input a date.\n\nNote that it requires a parent, like [Box](../?path=/docs/layout-box--default), to define its size.\n\n```js\nimport { CalendarInput } from '@dhis2/ui'\n```\n";
8
6
  export default {
@@ -69,16 +67,36 @@ export const GregorianWithArabic = buildCalendar({
69
67
  locale: 'ar-SD',
70
68
  date: '2021-10-13'
71
69
  });
72
- export const IslamicWithArabic = buildCalendar({
73
- calendar: 'islamic-civil',
74
- locale: 'ar-SD',
75
- date: '2015-01-13'
76
- });
77
- export const WithAnyCalendar = args => {
78
- return /*#__PURE__*/React.createElement(CalendarStoryWrapper, _extends({
79
- calendarInput: true,
70
+ export const IslamicWithArabic = () => {
71
+ return /*#__PURE__*/React.createElement("div", {
72
+ style: {
73
+ direction: 'rtl'
74
+ }
75
+ }, /*#__PURE__*/React.createElement(CalendarStoryWrapper, {
76
+ component: CalendarInput,
77
+ dir: "rtl",
78
+ timeZone: "Africa/Khartoum",
79
+ weekDayFormat: "short",
80
+ date: "1477-01-13",
81
+ locale: "ar-SD",
80
82
  calendar: "islamic-civil",
81
- locale: "en",
82
- timeZone: "Africa/Khartoum"
83
- }, args));
83
+ clearable: true
84
+ }));
85
+ };
86
+ export const CalendarWithClearButton = _ref2 => {
87
+ let {
88
+ calendar = 'gregory',
89
+ date: initialDate = null
90
+ } = _ref2;
91
+ const [date, setDate] = useState(initialDate);
92
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CalendarInput, {
93
+ calendar: calendar,
94
+ date: date,
95
+ onDateSelect: date => {
96
+ setDate(date === null || date === void 0 ? void 0 : date.calendarDateString);
97
+ },
98
+ clearable: true
99
+ }), /*#__PURE__*/React.createElement("div", null, "value:", /*#__PURE__*/React.createElement("span", {
100
+ "data-test": "storybook-calendar-date-value"
101
+ }, date !== null && date !== void 0 ? date : 'undefined')));
84
102
  };
@@ -3,12 +3,14 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
3
3
  import { constants } from '@dhis2/multi-calendar-dates';
4
4
  import PropTypes from 'prop-types';
5
5
  import React, { useState } from 'react';
6
- import { Calendar } from '../calendar/index.js';
6
+ import { Calendar } from '../calendar/calendar.js';
7
7
  const {
8
8
  calendars,
9
9
  numberingSystems
10
10
  } = constants;
11
11
  export const CalendarStoryWrapper = props => {
12
+ var _selectedDate$calenda;
13
+
12
14
  const {
13
15
  calendar,
14
16
  locale,
@@ -23,7 +25,9 @@ export const CalendarStoryWrapper = props => {
23
25
  const [selectedDirection, setSelectedDirection] = useState(dir);
24
26
  const [selectedWeekFormat, setWeekDayFormat] = useState(weekDayFormat);
25
27
  const [selectedLocale, setLocale] = useState(locale);
26
- const [selectedDate, setSelectedDate] = useState();
28
+ const [selectedDate, setSelectedDate] = useState({
29
+ calendarDateString: date
30
+ });
27
31
 
28
32
  const changeCalendar = _ref => {
29
33
  let {
@@ -137,7 +141,7 @@ export const CalendarStoryWrapper = props => {
137
141
  calendar: selectedCalendar,
138
142
  dir: selectedDirection,
139
143
  locale: selectedLocale,
140
- date: date,
144
+ date: selectedDate.calendarDateString,
141
145
  onDateSelect: date => {
142
146
  setSelectedDate(date);
143
147
  },
@@ -156,7 +160,7 @@ export const CalendarStoryWrapper = props => {
156
160
  "data-test": "storybook-calendar-result"
157
161
  }, selectedDate.calendarDateString)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "iso date: "), /*#__PURE__*/React.createElement("span", {
158
162
  "data-test": "storybook-calendar-result-iso"
159
- }, selectedDate.calendarDate.withCalendar('iso8601').toLocaleString('en-GB', {
163
+ }, (_selectedDate$calenda = selectedDate.calendarDate) === null || _selectedDate$calenda === void 0 ? void 0 : _selectedDate$calenda.withCalendar('iso8601').toLocaleString('en-GB', {
160
164
  dateStyle: 'long'
161
165
  }))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "callback:"), JSON.stringify(selectedDate, null, 2))))));
162
166
  };
@@ -1,8 +1,8 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import React from 'react';
4
- import { Calendar } from '../calendar/index.js';
5
- import { CalendarStoryWrapper } from './calendarStoryWrapper.js';
4
+ import { Calendar } from '../calendar/calendar.js';
5
+ import { CalendarStoryWrapper } from './calendar-story-wrapper.js';
6
6
  const subtitle = "[Experimental] Calendar component is useful for creating a variety of calendars including Ethiopic, Islamic etc..";
7
7
  const description = "\nUse a Calendar where there is a need to let the user select a date.\n\nNote that it requires a parent, like [Box](../?path=/docs/layout-box--default), to define its size.\n\n```js\nimport { Calendar } from '@dhis2/ui'\n```\n";
8
8
  export default {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/calendar",
3
- "version": "8.11.2",
3
+ "version": "8.12.1",
4
4
  "description": "UI Calendar",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,14 +31,15 @@
31
31
  "styled-jsx": "^4"
32
32
  },
33
33
  "dependencies": {
34
- "@dhis2-ui/card": "8.11.2",
35
- "@dhis2-ui/input": "8.11.2",
36
- "@dhis2-ui/layer": "8.11.2",
37
- "@dhis2-ui/popper": "8.11.2",
34
+ "@dhis2-ui/button": "8.12.1",
35
+ "@dhis2-ui/card": "8.12.1",
36
+ "@dhis2-ui/input": "8.12.1",
37
+ "@dhis2-ui/layer": "8.12.1",
38
+ "@dhis2-ui/popper": "8.12.1",
38
39
  "@dhis2/multi-calendar-dates": "1.0.0-alpha.18",
39
40
  "@dhis2/prop-types": "^3.1.2",
40
- "@dhis2/ui-constants": "8.11.2",
41
- "@dhis2/ui-icons": "8.11.2",
41
+ "@dhis2/ui-constants": "8.12.1",
42
+ "@dhis2/ui-icons": "8.12.1",
42
43
  "classnames": "^2.3.1",
43
44
  "prop-types": "^15.7.2"
44
45
  },
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CalendarProps = void 0;
7
-
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const CalendarProps = {
13
- calendar: _propTypes.default.any.isRequired,
14
- cellSize: _propTypes.default.string,
15
- date: _propTypes.default.string,
16
- dir: _propTypes.default.oneOf(['ltr', 'rtl']),
17
- locale: _propTypes.default.string,
18
- numberingSystem: _propTypes.default.string,
19
- timeZone: _propTypes.default.string,
20
- weekDayFormat: _propTypes.default.string,
21
- width: _propTypes.default.string,
22
- onDateSelect: _propTypes.default.func
23
- };
24
- exports.CalendarProps = CalendarProps;
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.WithAnyCalendar = exports.NepaliWithNepali = exports.NepaliWithEnglish = exports.IslamicWithArabic = exports.GregorianWithEnglish = exports.GregorianWithArabic = exports.EthiopicWithEnglish = exports.EthiopicWithAmharic = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _index = require("../calendar-input/index.js");
11
-
12
- var _calendarStoryWrapper = require("./calendarStoryWrapper.js");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
-
18
- const subtitle = "[Experimental] Calendar Input is a wrapper around Calendar displaying an input that triggers the calendar";
19
- const description = "\nUse a CalendarInput where there is a need to let the user input a date.\n\nNote that it requires a parent, like [Box](../?path=/docs/layout-box--default), to define its size.\n\n```js\nimport { CalendarInput } from '@dhis2/ui'\n```\n";
20
- var _default = {
21
- title: 'CalendarInput',
22
- component: _index.CalendarInput,
23
- parameters: {
24
- componentSubtitle: subtitle,
25
- docs: {
26
- description: {
27
- component: description
28
- }
29
- }
30
- }
31
- };
32
- exports.default = _default;
33
-
34
- const buildCalendar = _ref => {
35
- let {
36
- date,
37
- locale,
38
- calendar
39
- } = _ref;
40
- return () => /*#__PURE__*/_react.default.createElement(_calendarStoryWrapper.CalendarStoryWrapper, {
41
- component: _index.CalendarInput,
42
- dir: "ltr",
43
- timeZone: "Africa/Khartoum",
44
- weekDayFormat: "short",
45
- date: date,
46
- locale: locale,
47
- calendar: calendar
48
- });
49
- };
50
-
51
- const EthiopicWithAmharic = buildCalendar({
52
- calendar: 'ethiopic',
53
- locale: 'am-ET',
54
- date: '2014-02-03' // 13 Oct 2021
55
-
56
- });
57
- exports.EthiopicWithAmharic = EthiopicWithAmharic;
58
- const EthiopicWithEnglish = buildCalendar({
59
- calendar: 'ethiopic',
60
- locale: 'en-ET',
61
- date: '2014-02-03' // 13 Oct 2021
62
-
63
- });
64
- exports.EthiopicWithEnglish = EthiopicWithEnglish;
65
- const NepaliWithNepali = buildCalendar({
66
- calendar: 'nepali',
67
- locale: 'ne-NP',
68
- date: '2078-06-27' // 13 Oct 2021
69
-
70
- });
71
- exports.NepaliWithNepali = NepaliWithNepali;
72
- const NepaliWithEnglish = buildCalendar({
73
- calendar: 'nepali',
74
- locale: 'en-NP',
75
- date: '2078-06-27' // 13 Oct 2021
76
-
77
- });
78
- exports.NepaliWithEnglish = NepaliWithEnglish;
79
- const GregorianWithEnglish = buildCalendar({
80
- calendar: 'gregorian',
81
- locale: 'en-CA',
82
- date: '2021-10-13'
83
- });
84
- exports.GregorianWithEnglish = GregorianWithEnglish;
85
- const GregorianWithArabic = buildCalendar({
86
- calendar: 'gregorian',
87
- locale: 'ar-SD',
88
- date: '2021-10-13'
89
- });
90
- exports.GregorianWithArabic = GregorianWithArabic;
91
- const IslamicWithArabic = buildCalendar({
92
- calendar: 'islamic-civil',
93
- locale: 'ar-SD',
94
- date: '2015-01-13'
95
- });
96
- exports.IslamicWithArabic = IslamicWithArabic;
97
-
98
- const WithAnyCalendar = args => {
99
- return /*#__PURE__*/_react.default.createElement(_calendarStoryWrapper.CalendarStoryWrapper, _extends({
100
- calendarInput: true,
101
- calendar: "islamic-civil",
102
- locale: "en",
103
- timeZone: "Africa/Khartoum"
104
- }, args));
105
- };
106
-
107
- exports.WithAnyCalendar = WithAnyCalendar;
@@ -1,6 +0,0 @@
1
- import { CalendarInput as component } from '../index.js';
2
- export default {
3
- title: 'CalendarInputTesting',
4
- component
5
- };
6
- export { EthiopicWithAmharic, EthiopicWithEnglish, NepaliWithEnglish, NepaliWithNepali, GregorianWithArabic, GregorianWithEnglish, IslamicWithArabic } from '../stories/calendarInput.stories.js';
@@ -1,13 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- export const CalendarProps = {
3
- calendar: PropTypes.any.isRequired,
4
- cellSize: PropTypes.string,
5
- date: PropTypes.string,
6
- dir: PropTypes.oneOf(['ltr', 'rtl']),
7
- locale: PropTypes.string,
8
- numberingSystem: PropTypes.string,
9
- timeZone: PropTypes.string,
10
- weekDayFormat: PropTypes.string,
11
- width: PropTypes.string,
12
- onDateSelect: PropTypes.func
13
- };