@dhis2-ui/calendar 8.11.2 → 8.12.0
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/__e2e__/{calendarInput.stories.e2e.js → calendar-input.stories.e2e.js} +21 -3
- package/build/cjs/calendar/calendar-table-cell.js +10 -8
- package/build/cjs/calendar/calendar-table.js +5 -2
- package/build/cjs/calendar/{index.js → calendar.js} +37 -4
- package/build/cjs/calendar/navigation-container.js +6 -6
- package/build/cjs/calendar-input/{index.js → calendar-input.js} +34 -22
- package/build/cjs/features/supports_calendar_clear_button/supports_calendar_clear_button.js +34 -0
- package/build/cjs/features/supports_calendar_clear_button.feature +23 -0
- package/build/cjs/index.js +4 -4
- package/build/cjs/locales/en/translations.json +2 -1
- package/build/cjs/stories/calendar-input.stories.js +129 -0
- package/build/cjs/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +9 -5
- package/build/cjs/stories/calendar.stories.js +3 -3
- package/build/es/__e2e__/calendar-input.stories.e2e.js +19 -0
- package/build/es/calendar/calendar-table-cell.js +10 -8
- package/build/es/calendar/calendar-table.js +5 -2
- package/build/es/calendar/{index.js → calendar.js} +33 -1
- package/build/es/calendar/navigation-container.js +6 -6
- package/build/es/calendar-input/{index.js → calendar-input.js} +29 -21
- package/build/es/features/supports_calendar_clear_button/supports_calendar_clear_button.js +31 -0
- package/build/es/features/supports_calendar_clear_button.feature +23 -0
- package/build/es/index.js +2 -2
- package/build/es/locales/en/translations.json +2 -1
- package/build/es/stories/{calendarInput.stories.js → calendar-input.stories.js} +34 -16
- package/build/es/stories/{calendarStoryWrapper.js → calendar-story-wrapper.js} +8 -4
- package/build/es/stories/calendar.stories.js +2 -2
- package/package.json +8 -7
- package/build/cjs/calendar/calendar-prop-types.js +0 -24
- package/build/cjs/stories/calendarInput.stories.js +0 -107
- package/build/es/__e2e__/calendarInput.stories.e2e.js +0 -6
- package/build/es/calendar/calendar-prop-types.js +0 -13
@@ -6,25 +6,26 @@ import React from 'react';
|
|
6
6
|
export const CalendarTableCell = _ref => {
|
7
7
|
let {
|
8
8
|
day,
|
9
|
-
cellSize
|
9
|
+
cellSize,
|
10
|
+
selectedDate
|
10
11
|
} = _ref;
|
11
12
|
const dayHoverBackgroundColor = colors.grey200;
|
12
13
|
const selectedDayBackgroundColor = colors.teal700;
|
13
14
|
return /*#__PURE__*/React.createElement("td", {
|
14
15
|
"data-test": day === null || day === void 0 ? void 0 : day.calendarDate,
|
15
16
|
onClick: day.onClick,
|
16
|
-
className: _JSXStyle.dynamic([["
|
17
|
+
className: _JSXStyle.dynamic([["1413417644", [cellSize, cellSize, cellSize, cellSize, spacers.dp2, colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, colors.grey600]]])
|
17
18
|
}, /*#__PURE__*/React.createElement("button", {
|
18
19
|
name: "day",
|
19
|
-
className: _JSXStyle.dynamic([["
|
20
|
-
isSelected: day.
|
20
|
+
className: _JSXStyle.dynamic([["1413417644", [cellSize, cellSize, cellSize, cellSize, spacers.dp2, colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, colors.grey600]]]) + " " + (cx('day', {
|
21
|
+
isSelected: selectedDate === (day === null || day === void 0 ? void 0 : day.calendarDate),
|
21
22
|
isToday: day.isToday,
|
22
23
|
otherMonth: !day.isInCurrentMonth
|
23
24
|
}) || "")
|
24
25
|
}, day.label), /*#__PURE__*/React.createElement(_JSXStyle, {
|
25
|
-
id: "
|
26
|
+
id: "1413417644",
|
26
27
|
dynamic: [cellSize, cellSize, cellSize, cellSize, spacers.dp2, colors.grey900, dayHoverBackgroundColor, selectedDayBackgroundColor, colors.grey600]
|
27
|
-
}, ["td.__jsx-style-dynamic-selector{width:".concat(cellSize, ";height:100%;height:").concat(cellSize, ";text-align:center;border:2px solid transparent;}"), "td.__jsx-style-dynamic-selector span.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;padding:2px 2px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border:2px solid transparent;min-width:16px;}", "button.__jsx-style-dynamic-selector{border:0;overflow:hidden;width:".concat(cellSize, ";height:").concat(cellSize, ";border:2px solid transparent;border-radius:3px;background:none;margin:").concat(spacers.dp2, ";color:").concat(colors.grey900, ";}"), "button.__jsx-style-dynamic-selector:hover{background-color:".concat(dayHoverBackgroundColor, ";-webkit-text-decoration:underline;text-decoration:underline;}"), "button.isSelected.__jsx-style-dynamic-selector,button.otherMonth.isSelected.__jsx-style-dynamic-selector{background-color:".concat(selectedDayBackgroundColor, ";color:white;}"), "button.isToday.__jsx-style-dynamic-selector{-webkit-text-decoration:underline;text-decoration:underline;}", "button.otherMonth.__jsx-style-dynamic-selector{color:".concat(colors.grey600, ";}")]));
|
28
|
+
}, ["td.__jsx-style-dynamic-selector{width:".concat(cellSize, ";height:100%;height:").concat(cellSize, ";text-align:center;border:2px solid transparent;padding:0;}"), "td.__jsx-style-dynamic-selector span.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;padding:2px 2px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border:2px solid transparent;min-width:16px;}", "button.__jsx-style-dynamic-selector{border:0;overflow:hidden;width:".concat(cellSize, ";height:").concat(cellSize, ";border:2px solid transparent;border-radius:3px;background:none;margin:").concat(spacers.dp2, ";color:").concat(colors.grey900, ";}"), "button.__jsx-style-dynamic-selector:hover{background-color:".concat(dayHoverBackgroundColor, ";-webkit-text-decoration:underline;text-decoration:underline;}"), "button.isSelected.__jsx-style-dynamic-selector,button.otherMonth.isSelected.__jsx-style-dynamic-selector{background-color:".concat(selectedDayBackgroundColor, ";color:white;}"), "button.isToday.__jsx-style-dynamic-selector{-webkit-text-decoration:underline;text-decoration:underline;}", "button.otherMonth.__jsx-style-dynamic-selector{color:".concat(colors.grey600, ";}")]));
|
28
29
|
};
|
29
30
|
CalendarTableCell.propTypes = {
|
30
31
|
cellSize: PropTypes.string,
|
@@ -33,7 +34,8 @@ CalendarTableCell.propTypes = {
|
|
33
34
|
isInCurrentMonth: PropTypes.bool,
|
34
35
|
isSelected: PropTypes.bool,
|
35
36
|
isToday: PropTypes.bool,
|
36
|
-
label: PropTypes.string,
|
37
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
37
38
|
onClick: PropTypes.func
|
38
|
-
})
|
39
|
+
}),
|
40
|
+
selectedDate: PropTypes.string
|
39
41
|
};
|
@@ -9,7 +9,8 @@ export const CalendarTable = _ref => {
|
|
9
9
|
weekDayLabels,
|
10
10
|
calendarWeekDays,
|
11
11
|
width,
|
12
|
-
cellSize
|
12
|
+
cellSize,
|
13
|
+
selectedDate
|
13
14
|
} = _ref;
|
14
15
|
return /*#__PURE__*/React.createElement("div", {
|
15
16
|
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]]) + " " + "calendar-table-wrapper"
|
@@ -23,6 +24,7 @@ export const CalendarTable = _ref => {
|
|
23
24
|
key: "week-".concat(weekIndex + 1),
|
24
25
|
className: _JSXStyle.dynamic([["452536960", [spacers.dp4, spacers.dp4]]])
|
25
26
|
}, week.map(day => /*#__PURE__*/React.createElement(CalendarTableCell, {
|
27
|
+
selectedDate: selectedDate,
|
26
28
|
day: day,
|
27
29
|
key: day === null || day === void 0 ? void 0 : day.calendarDate,
|
28
30
|
cellSize: cellSize,
|
@@ -38,11 +40,12 @@ CalendarTable.propTypes = {
|
|
38
40
|
isInCurrentMonth: PropTypes.bool,
|
39
41
|
isSelected: PropTypes.bool,
|
40
42
|
isToday: PropTypes.bool,
|
41
|
-
label: PropTypes.string,
|
43
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
42
44
|
zdt: PropTypes.object,
|
43
45
|
onClick: PropTypes.func
|
44
46
|
}).isRequired).isRequired).isRequired,
|
45
47
|
cellSize: PropTypes.string,
|
48
|
+
selectedDate: PropTypes.string,
|
46
49
|
weekDayLabels: PropTypes.arrayOf(PropTypes.string),
|
47
50
|
width: PropTypes.string
|
48
51
|
};
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
2
2
|
import { useDatePicker, useResolvedDirection } from '@dhis2/multi-calendar-dates';
|
3
3
|
import { colors } from '@dhis2/ui-constants';
|
4
|
+
import PropTypes from 'prop-types';
|
4
5
|
import React, { useState } from 'react';
|
5
|
-
import { CalendarProps } from './calendar-prop-types.js';
|
6
6
|
import { CalendarTable } from './calendar-table.js';
|
7
7
|
import { NavigationContainer } from './navigation-container.js';
|
8
8
|
export const Calendar = _ref => {
|
@@ -54,6 +54,7 @@ export const Calendar = _ref => {
|
|
54
54
|
pickerOptions: pickerOptions,
|
55
55
|
languageDirection: languageDirection
|
56
56
|
}), /*#__PURE__*/React.createElement(CalendarTable, {
|
57
|
+
selectedDate: selectedDateString,
|
57
58
|
calendarWeekDays: calendarWeekDays,
|
58
59
|
weekDayLabels: weekDayLabels,
|
59
60
|
cellSize: cellSize,
|
@@ -68,4 +69,35 @@ Calendar.defaultProps = {
|
|
68
69
|
width: '240px',
|
69
70
|
weekDayFormat: 'narrow'
|
70
71
|
};
|
72
|
+
export const CalendarProps = {
|
73
|
+
/** 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 */
|
74
|
+
calendar: PropTypes.any.isRequired,
|
75
|
+
|
76
|
+
/** 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` */
|
77
|
+
onDateSelect: PropTypes.func.isRequired,
|
78
|
+
|
79
|
+
/** the size of a single cell in the table forming the calendar */
|
80
|
+
cellSize: PropTypes.string,
|
81
|
+
|
82
|
+
/** the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601) */
|
83
|
+
date: PropTypes.string,
|
84
|
+
|
85
|
+
/** the direction of the library - internally the library will use rtl for rtl-languages but this can be overridden here for more control */
|
86
|
+
dir: PropTypes.oneOf(['ltr', 'rtl']),
|
87
|
+
|
88
|
+
/** 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) */
|
89
|
+
locale: PropTypes.string,
|
90
|
+
|
91
|
+
/** numbering system to use - full list here https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/numberingSystems.ts */
|
92
|
+
numberingSystem: PropTypes.string,
|
93
|
+
|
94
|
+
/** the timeZone to use */
|
95
|
+
timeZone: PropTypes.string,
|
96
|
+
|
97
|
+
/** the format to display for the week day, i.e. Monday (long), Mon (short), M (narrow) */
|
98
|
+
weekDayFormat: PropTypes.oneOf(['narrow', 'short', 'long']),
|
99
|
+
|
100
|
+
/** the width of the calendar component */
|
101
|
+
width: PropTypes.string
|
102
|
+
};
|
71
103
|
Calendar.propTypes = CalendarProps;
|
@@ -91,25 +91,25 @@ NavigationContainer.propTypes = {
|
|
91
91
|
languageDirection: PropTypes.oneOf(['ltr', 'rtl']),
|
92
92
|
pickerOptions: PropTypes.shape({
|
93
93
|
currMonth: PropTypes.shape({
|
94
|
-
label: PropTypes.string
|
94
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
95
95
|
}),
|
96
96
|
currYear: PropTypes.shape({
|
97
|
-
label: PropTypes.string
|
97
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
98
98
|
}),
|
99
99
|
nextMonth: PropTypes.shape({
|
100
|
-
label: PropTypes.string,
|
100
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
101
101
|
navigateTo: PropTypes.func
|
102
102
|
}),
|
103
103
|
nextYear: PropTypes.shape({
|
104
|
-
label: PropTypes.string,
|
104
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
105
105
|
navigateTo: PropTypes.func
|
106
106
|
}),
|
107
107
|
prevMonth: PropTypes.shape({
|
108
|
-
label: PropTypes.string,
|
108
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
109
109
|
navigateTo: PropTypes.func
|
110
110
|
}),
|
111
111
|
prevYear: PropTypes.shape({
|
112
|
-
label: PropTypes.string,
|
112
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
113
113
|
navigateTo: PropTypes.func
|
114
114
|
})
|
115
115
|
})
|
@@ -1,19 +1,16 @@
|
|
1
|
+
import _JSXStyle from "styled-jsx/style";
|
2
|
+
|
1
3
|
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
4
|
|
5
|
+
import { Button } from '@dhis2-ui/button';
|
3
6
|
import { Card } from '@dhis2-ui/card';
|
4
7
|
import { InputField, InputFieldProps } from '@dhis2-ui/input';
|
5
8
|
import { Layer } from '@dhis2-ui/layer';
|
6
9
|
import { Popper } from '@dhis2-ui/popper';
|
7
|
-
import
|
10
|
+
import cx from 'classnames';
|
8
11
|
import React, { useRef, useState } from 'react';
|
9
|
-
import { CalendarProps } from '../calendar/calendar
|
10
|
-
import
|
11
|
-
|
12
|
-
const padWithZeroes = function (number) {
|
13
|
-
let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
14
|
-
return String(number).padStart(count, '0');
|
15
|
-
};
|
16
|
-
|
12
|
+
import { Calendar, CalendarProps } from '../calendar/calendar.js';
|
13
|
+
import i18n from '../locales/index.js';
|
17
14
|
const offsetModifier = {
|
18
15
|
name: 'offset',
|
19
16
|
options: {
|
@@ -32,19 +29,13 @@ export const CalendarInput = function () {
|
|
32
29
|
timeZone,
|
33
30
|
width,
|
34
31
|
cellSize,
|
32
|
+
clearable,
|
35
33
|
...rest
|
36
34
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37
35
|
const ref = useRef();
|
38
36
|
const [open, setOpen] = useState(false);
|
39
|
-
const currentDate = getNowInCalendar(calendar, timeZone);
|
40
|
-
const initialDate = date || "".concat(currentDate.eraYear || currentDate.year, "-").concat(padWithZeroes(currentDate.month), "-").concat(padWithZeroes(currentDate.day));
|
41
|
-
const [value, setValue] = useState(initialDate);
|
42
37
|
const calendarProps = React.useMemo(() => {
|
43
38
|
const onDateSelectWrapper = selectedDate => {
|
44
|
-
const {
|
45
|
-
calendarDateString
|
46
|
-
} = selectedDate;
|
47
|
-
setValue(calendarDateString);
|
48
39
|
setOpen(false);
|
49
40
|
onDateSelect === null || onDateSelect === void 0 ? void 0 : onDateSelect(selectedDate);
|
50
41
|
};
|
@@ -68,14 +59,29 @@ export const CalendarInput = function () {
|
|
68
59
|
};
|
69
60
|
|
70
61
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
71
|
-
ref: ref
|
62
|
+
ref: ref,
|
63
|
+
className: "jsx-862452676" + " " + "calendar-input-wrapper"
|
72
64
|
}, /*#__PURE__*/React.createElement(InputField, _extends({
|
73
65
|
label: "Pick a date"
|
74
66
|
}, rest, {
|
75
67
|
type: "text",
|
76
68
|
onFocus: onFocus,
|
77
|
-
value:
|
78
|
-
}))
|
69
|
+
value: date
|
70
|
+
})), clearable && /*#__PURE__*/React.createElement("div", {
|
71
|
+
className: "jsx-862452676" + " " + (cx('calendar-clear-button', {
|
72
|
+
// ToDo: this is a workaround to show the clear button in the correct place when an icon is shown.
|
73
|
+
// Long-term, we should abstract and share the logic multi-select uses for the input-wrapper
|
74
|
+
// https://dhis2.atlassian.net/browse/DHIS2-14848
|
75
|
+
'with-icon': rest.valid || rest.error || rest.warning || rest.loading,
|
76
|
+
'with-dense-wrapper': rest.dense
|
77
|
+
}) || "")
|
78
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
79
|
+
dataTest: "calendar-clear-button",
|
80
|
+
secondary: true,
|
81
|
+
small: true,
|
82
|
+
onClick: () => calendarProps.onDateSelect(null),
|
83
|
+
type: "button"
|
84
|
+
}, i18n.t('Clear')))), open && /*#__PURE__*/React.createElement(Layer, {
|
79
85
|
onBackdropClick: () => {
|
80
86
|
setOpen(false);
|
81
87
|
}
|
@@ -84,8 +90,10 @@ export const CalendarInput = function () {
|
|
84
90
|
placement: "bottom-start",
|
85
91
|
modifiers: [offsetModifier]
|
86
92
|
}, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(Calendar, _extends({}, calendarProps, {
|
87
|
-
date:
|
88
|
-
})))))
|
93
|
+
date: date
|
94
|
+
}))))), /*#__PURE__*/React.createElement(_JSXStyle, {
|
95
|
+
id: "862452676"
|
96
|
+
}, [".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;}"]));
|
89
97
|
};
|
90
98
|
CalendarInput.defaultProps = {
|
91
99
|
dataTest: 'dhis2-uiwidgets-calendar-inputfield'
|
@@ -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', todayDate.split('-')[2]);
|
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/
|
2
|
-
export { CalendarInput } from './calendar-input/
|
1
|
+
export { Calendar } from './calendar/calendar.js';
|
2
|
+
export { CalendarInput } from './calendar-input/calendar-input.js';
|
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import
|
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 =
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
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/
|
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:
|
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/
|
5
|
-
import { CalendarStoryWrapper } from './
|
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.
|
3
|
+
"version": "8.12.0",
|
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/
|
35
|
-
"@dhis2-ui/
|
36
|
-
"@dhis2-ui/
|
37
|
-
"@dhis2-ui/
|
34
|
+
"@dhis2-ui/button": "8.12.0",
|
35
|
+
"@dhis2-ui/card": "8.12.0",
|
36
|
+
"@dhis2-ui/input": "8.12.0",
|
37
|
+
"@dhis2-ui/layer": "8.12.0",
|
38
|
+
"@dhis2-ui/popper": "8.12.0",
|
38
39
|
"@dhis2/multi-calendar-dates": "1.0.0-alpha.18",
|
39
40
|
"@dhis2/prop-types": "^3.1.2",
|
40
|
-
"@dhis2/ui-constants": "8.
|
41
|
-
"@dhis2/ui-icons": "8.
|
41
|
+
"@dhis2/ui-constants": "8.12.0",
|
42
|
+
"@dhis2/ui-icons": "8.12.0",
|
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
|
-
};
|