@dhis2-ui/calendar 8.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/README.md +10 -0
  2. package/build/cjs/__e2e__/calendarInput.stories.e2e.js +58 -0
  3. package/build/cjs/calendar/calendar-prop-types.js +24 -0
  4. package/build/cjs/calendar/calendar-table-cell.js +55 -0
  5. package/build/cjs/calendar/calendar-table-days-header.js +40 -0
  6. package/build/cjs/calendar/calendar-table.js +57 -0
  7. package/build/cjs/calendar/index.js +93 -0
  8. package/build/cjs/calendar/navigation-container.js +134 -0
  9. package/build/cjs/calendar-input/index.js +117 -0
  10. package/build/cjs/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +39 -0
  11. package/build/cjs/features/supports_ethiopic_calendar.feature +19 -0
  12. package/build/cjs/features/supports_gregorian_calendar/supports_gregorian_calendar.js +39 -0
  13. package/build/cjs/features/supports_gregorian_calendar.feature +19 -0
  14. package/build/cjs/features/supports_islamic_calendar/supports_islamic_calendar.js +18 -0
  15. package/build/cjs/features/supports_islamic_calendar.feature +5 -0
  16. package/build/cjs/features/supports_nepali_calendar/supports_nepali_calendar.js +42 -0
  17. package/build/cjs/features/supports_nepali_calendar.feature +19 -0
  18. package/build/cjs/index.js +21 -0
  19. package/build/cjs/locales/en/translations.json +4 -0
  20. package/build/cjs/locales/index.js +27 -0
  21. package/build/cjs/stories/calendar.stories.js +66 -0
  22. package/build/cjs/stories/calendarInput.stories.js +107 -0
  23. package/build/cjs/stories/calendarStoryWrapper.js +196 -0
  24. package/build/es/__e2e__/calendarInput.stories.e2e.js +6 -0
  25. package/build/es/calendar/calendar-prop-types.js +13 -0
  26. package/build/es/calendar/calendar-table-cell.js +39 -0
  27. package/build/es/calendar/calendar-table-days-header.js +25 -0
  28. package/build/es/calendar/calendar-table.js +40 -0
  29. package/build/es/calendar/index.js +71 -0
  30. package/build/es/calendar/navigation-container.js +116 -0
  31. package/build/es/calendar-input/index.js +95 -0
  32. package/build/es/features/supports_ethiopic_calendar/supports_ethiopic_calendar.js +36 -0
  33. package/build/es/features/supports_ethiopic_calendar.feature +19 -0
  34. package/build/es/features/supports_gregorian_calendar/supports_gregorian_calendar.js +36 -0
  35. package/build/es/features/supports_gregorian_calendar.feature +19 -0
  36. package/build/es/features/supports_islamic_calendar/supports_islamic_calendar.js +15 -0
  37. package/build/es/features/supports_islamic_calendar.feature +5 -0
  38. package/build/es/features/supports_nepali_calendar/supports_nepali_calendar.js +39 -0
  39. package/build/es/features/supports_nepali_calendar.feature +19 -0
  40. package/build/es/index.js +2 -0
  41. package/build/es/locales/en/translations.json +4 -0
  42. package/build/es/locales/index.js +13 -0
  43. package/build/es/stories/calendar.stories.js +44 -0
  44. package/build/es/stories/calendarInput.stories.js +84 -0
  45. package/build/es/stories/calendarStoryWrapper.js +176 -0
  46. package/package.json +53 -0
@@ -0,0 +1,84 @@
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';
6
+ const subtitle = "[Experimental] Calendar Input is a wrapper around Calendar displaying an input that triggers the calendar";
7
+ 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
+ export default {
9
+ title: 'CalendarInput',
10
+ component: CalendarInput,
11
+ parameters: {
12
+ componentSubtitle: subtitle,
13
+ docs: {
14
+ description: {
15
+ component: description
16
+ }
17
+ }
18
+ }
19
+ };
20
+
21
+ const buildCalendar = _ref => {
22
+ let {
23
+ date,
24
+ locale,
25
+ calendar
26
+ } = _ref;
27
+ return () => /*#__PURE__*/React.createElement(CalendarStoryWrapper, {
28
+ component: CalendarInput,
29
+ dir: "ltr",
30
+ timeZone: "Africa/Khartoum",
31
+ weekDayFormat: "short",
32
+ date: date,
33
+ locale: locale,
34
+ calendar: calendar
35
+ });
36
+ };
37
+
38
+ export const EthiopicWithAmharic = buildCalendar({
39
+ calendar: 'ethiopic',
40
+ locale: 'am-ET',
41
+ date: '2014-02-03' // 13 Oct 2021
42
+
43
+ });
44
+ export const EthiopicWithEnglish = buildCalendar({
45
+ calendar: 'ethiopic',
46
+ locale: 'en-ET',
47
+ date: '2014-02-03' // 13 Oct 2021
48
+
49
+ });
50
+ export const NepaliWithNepali = buildCalendar({
51
+ calendar: 'nepali',
52
+ locale: 'ne-NP',
53
+ date: '2078-06-27' // 13 Oct 2021
54
+
55
+ });
56
+ export const NepaliWithEnglish = buildCalendar({
57
+ calendar: 'nepali',
58
+ locale: 'en-NP',
59
+ date: '2078-06-27' // 13 Oct 2021
60
+
61
+ });
62
+ export const GregorianWithEnglish = buildCalendar({
63
+ calendar: 'gregorian',
64
+ locale: 'en-CA',
65
+ date: '2021-10-13'
66
+ });
67
+ export const GregorianWithArabic = buildCalendar({
68
+ calendar: 'gregorian',
69
+ locale: 'ar-SD',
70
+ date: '2021-10-13'
71
+ });
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,
80
+ calendar: "islamic-civil",
81
+ locale: "en",
82
+ timeZone: "Africa/Khartoum"
83
+ }, args));
84
+ };
@@ -0,0 +1,176 @@
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 { constants } from '@dhis2/multi-calendar-dates';
4
+ import PropTypes from 'prop-types';
5
+ import React, { useState } from 'react';
6
+ import { Calendar } from '../calendar/index.js';
7
+ const {
8
+ calendars,
9
+ numberingSystems
10
+ } = constants;
11
+ export const CalendarStoryWrapper = props => {
12
+ const {
13
+ calendar,
14
+ locale,
15
+ timeZone,
16
+ dir,
17
+ component: Component,
18
+ date,
19
+ weekDayFormat
20
+ } = props;
21
+ const [selectedCalendar, setSelectedCalendar] = useState(calendar);
22
+ const [selectedNumberingSystem, setSelectedNumberingSystem] = useState();
23
+ const [selectedDirection, setSelectedDirection] = useState(dir);
24
+ const [selectedWeekFormat, setWeekDayFormat] = useState(weekDayFormat);
25
+ const [selectedLocale, setLocale] = useState(locale);
26
+ const [selectedDate, setSelectedDate] = useState();
27
+
28
+ const changeCalendar = _ref => {
29
+ let {
30
+ target: {
31
+ value
32
+ }
33
+ } = _ref;
34
+ setSelectedCalendar(value);
35
+ };
36
+
37
+ const changeNumberingSystem = _ref2 => {
38
+ let {
39
+ target: {
40
+ value
41
+ }
42
+ } = _ref2;
43
+
44
+ if (value === '-1') {
45
+ setSelectedNumberingSystem(null);
46
+ } else {
47
+ setSelectedNumberingSystem(value);
48
+ }
49
+ };
50
+
51
+ const changeDirection = _ref3 => {
52
+ let {
53
+ target: {
54
+ value
55
+ }
56
+ } = _ref3;
57
+ setSelectedDirection(value);
58
+ };
59
+
60
+ const changeWeekFormat = _ref4 => {
61
+ let {
62
+ target: {
63
+ value
64
+ }
65
+ } = _ref4;
66
+ setWeekDayFormat(value);
67
+ };
68
+
69
+ const onLocaleChanged = _ref5 => {
70
+ let {
71
+ target: {
72
+ value
73
+ }
74
+ } = _ref5;
75
+ setLocale(value);
76
+ };
77
+
78
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
79
+ style: {
80
+ fontSize: '0.8em',
81
+ marginBottom: 20,
82
+ gap: 5,
83
+ display: 'flex',
84
+ alignItems: 'center'
85
+ }
86
+ }, /*#__PURE__*/React.createElement("div", null, "Options"), /*#__PURE__*/React.createElement("input", {
87
+ defaultValue: locale,
88
+ placeholder: "locale",
89
+ onBlur: onLocaleChanged
90
+ }), /*#__PURE__*/React.createElement("select", {
91
+ onChange: changeCalendar,
92
+ value: selectedCalendar
93
+ }, /*#__PURE__*/React.createElement("option", {
94
+ disabled: true,
95
+ key: calendar,
96
+ value: "-1"
97
+ }, "Select calendar"), calendars.map(calendar => {
98
+ return /*#__PURE__*/React.createElement("option", {
99
+ value: calendar,
100
+ key: calendar
101
+ }, calendar);
102
+ })), /*#__PURE__*/React.createElement("select", {
103
+ onChange: changeNumberingSystem,
104
+ value: selectedNumberingSystem
105
+ }, /*#__PURE__*/React.createElement("option", {
106
+ disabled: true,
107
+ key: calendar,
108
+ value: "-1"
109
+ }, "Select numbering system"), numberingSystems.map(system => {
110
+ return /*#__PURE__*/React.createElement("option", {
111
+ value: system,
112
+ key: system
113
+ }, system);
114
+ })), /*#__PURE__*/React.createElement("select", {
115
+ onChange: changeDirection,
116
+ value: selectedDirection
117
+ }, /*#__PURE__*/React.createElement("option", {
118
+ disabled: true,
119
+ value: "-1"
120
+ }, "Select direction"), /*#__PURE__*/React.createElement("option", {
121
+ value: "ltr"
122
+ }, "Left-To-Right"), /*#__PURE__*/React.createElement("option", {
123
+ value: "rtl"
124
+ }, "Right-To-Left")), /*#__PURE__*/React.createElement("select", {
125
+ onChange: changeWeekFormat,
126
+ value: selectedWeekFormat
127
+ }, /*#__PURE__*/React.createElement("option", {
128
+ disabled: true,
129
+ value: "-1"
130
+ }, "Select format"), /*#__PURE__*/React.createElement("option", {
131
+ value: "narrow"
132
+ }, "narrow"), /*#__PURE__*/React.createElement("option", {
133
+ value: "short"
134
+ }, "short"), /*#__PURE__*/React.createElement("option", {
135
+ value: "long"
136
+ }, "long"))), /*#__PURE__*/React.createElement(Component, _extends({}, props, {
137
+ calendar: selectedCalendar,
138
+ dir: selectedDirection,
139
+ locale: selectedLocale,
140
+ date: date,
141
+ onDateSelect: date => {
142
+ setSelectedDate(date);
143
+ },
144
+ timeZone: timeZone,
145
+ weekDayFormat: selectedWeekFormat,
146
+ numberingSystem: selectedNumberingSystem
147
+ })), /*#__PURE__*/React.createElement("div", {
148
+ style: {
149
+ marginTop: 10,
150
+ gap: 5,
151
+ fontSize: '12px',
152
+ display: 'flex',
153
+ flexDirection: 'column'
154
+ }
155
+ }, /*#__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", {
156
+ "data-test": "storybook-calendar-result"
157
+ }, selectedDate.calendarDateString)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "iso date: "), /*#__PURE__*/React.createElement("span", {
158
+ "data-test": "storybook-calendar-result-iso"
159
+ }, selectedDate.calendarDate.withCalendar('iso8601').toLocaleString('en-GB', {
160
+ dateStyle: 'long'
161
+ }))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "callback:"), JSON.stringify(selectedDate, null, 2))))));
162
+ };
163
+ CalendarStoryWrapper.defaultProps = {
164
+ calendar: 'gregorian',
165
+ component: Calendar,
166
+ weekDayFormat: 'narrow'
167
+ };
168
+ CalendarStoryWrapper.propTypes = {
169
+ calendar: PropTypes.string.isRequired,
170
+ component: PropTypes.elementType.isRequired,
171
+ date: PropTypes.string,
172
+ dir: PropTypes.oneOf(['ltr', 'rtl']),
173
+ locale: PropTypes.string,
174
+ timeZone: PropTypes.string,
175
+ weekDayFormat: PropTypes.string
176
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@dhis2-ui/calendar",
3
+ "version": "8.8.0",
4
+ "description": "UI Calendar",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/dhis2/ui.git",
8
+ "directory": "components/calendar"
9
+ },
10
+ "homepage": "https://github.com/dhis2/ui#readme",
11
+ "license": "BSD-3-Clause",
12
+ "private": false,
13
+ "main": "./build/cjs/index.js",
14
+ "module": "./build/es/index.js",
15
+ "exports": {
16
+ "import": "./build/es/index.js",
17
+ "require": "./build/cjs/index.js"
18
+ },
19
+ "sideEffects": false,
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "start": "start-storybook -c ../../storybook/config --port 5000",
25
+ "build": "d2-app-scripts build",
26
+ "test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
27
+ },
28
+ "peerDependencies": {
29
+ "react": "^16.8",
30
+ "react-dom": "^16.8",
31
+ "styled-jsx": "^4"
32
+ },
33
+ "dependencies": {
34
+ "@dhis2-ui/card": "8.8.0",
35
+ "@dhis2-ui/input": "8.8.0",
36
+ "@dhis2-ui/layer": "8.8.0",
37
+ "@dhis2-ui/popper": "8.8.0",
38
+ "@dhis2/multi-calendar-dates": "1.0.0-alpha.17",
39
+ "@dhis2/prop-types": "^3.1.2",
40
+ "@dhis2/ui-constants": "8.8.0",
41
+ "@dhis2/ui-icons": "8.8.0",
42
+ "classnames": "^2.3.1",
43
+ "prop-types": "^15.7.2"
44
+ },
45
+ "files": [
46
+ "build"
47
+ ],
48
+ "devDependencies": {
49
+ "react": "16.13",
50
+ "react-dom": "16.13",
51
+ "styled-jsx": "^4.0.1"
52
+ }
53
+ }