@dhis2-ui/calendar 10.0.0-alpha.2 → 10.0.0-alpha.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.CalendarWithClearButton = void 0;
|
7
|
-
exports.CalendarWithEditableInputReactForm = CalendarWithEditableInputReactForm;
|
8
7
|
exports.CalendarWithEditiableInput = CalendarWithEditiableInput;
|
8
|
+
exports.CalendarWithNonStrictValidation = CalendarWithNonStrictValidation;
|
9
|
+
exports.CalendarWithStrictValidation = CalendarWithStrictValidation;
|
9
10
|
exports.default = exports.NepaliWithNepali = exports.NepaliWithEnglish = exports.IslamicWithArabic = exports.GregorianWithEnglish = exports.GregorianWithArabic = exports.EthiopicWithEnglish = exports.EthiopicWithAmharic = void 0;
|
11
|
+
var _button = require("@dhis2-ui/button");
|
10
12
|
var _react = _interopRequireWildcard(require("react"));
|
11
13
|
var _reactFinalForm = require("react-final-form");
|
12
14
|
var _calendarInput = require("../calendar-input/calendar-input.js");
|
@@ -135,12 +137,14 @@ function CalendarWithEditiableInput() {
|
|
135
137
|
clearable: true
|
136
138
|
})));
|
137
139
|
}
|
138
|
-
function
|
140
|
+
function CalendarWithStrictValidation() {
|
139
141
|
const [validation, setValidation] = (0, _react.useState)({});
|
140
142
|
const errored = () => {
|
141
|
-
|
142
|
-
|
143
|
-
|
143
|
+
if (validation.error) {
|
144
|
+
return {
|
145
|
+
calendar: validation.validationText
|
146
|
+
};
|
147
|
+
}
|
144
148
|
};
|
145
149
|
return /*#__PURE__*/_react.default.createElement(_reactFinalForm.Form, {
|
146
150
|
onSubmit: (values, meta) => {
|
@@ -163,6 +167,62 @@ function CalendarWithEditableInputReactForm() {
|
|
163
167
|
}, /*#__PURE__*/_react.default.createElement(_reactFinalForm.Field, {
|
164
168
|
name: "calendar"
|
165
169
|
}, props => /*#__PURE__*/_react.default.createElement(_calendarInput.CalendarInput, _extends({}, props, {
|
170
|
+
label: "Enter a date",
|
171
|
+
helpText: "Date has to be after 2022-11-01",
|
172
|
+
input: props.input,
|
173
|
+
meta: props.meta,
|
174
|
+
editable: true,
|
175
|
+
date: props.input.value,
|
176
|
+
calendar: "gregory"
|
177
|
+
}, validation, {
|
178
|
+
minDate: "2022-11-01",
|
179
|
+
onDateSelect: date => {
|
180
|
+
const validation = {
|
181
|
+
...date.validation,
|
182
|
+
validationText: date.validation.validationCode === 'WRONG_FORMAT' ? 'custom validation message for format' : date.validation.validationText
|
183
|
+
};
|
184
|
+
setValidation(validation);
|
185
|
+
props.input.onChange(date ? date === null || date === void 0 ? void 0 : date.calendarDateString : '');
|
186
|
+
}
|
187
|
+
}))), /*#__PURE__*/_react.default.createElement(_button.Button, {
|
188
|
+
type: "submit",
|
189
|
+
disabled: invalid,
|
190
|
+
onClick: handleSubmit
|
191
|
+
}, "Submit"));
|
192
|
+
});
|
193
|
+
}
|
194
|
+
function CalendarWithNonStrictValidation() {
|
195
|
+
const [validation, setValidation] = (0, _react.useState)({});
|
196
|
+
const errored = () => {
|
197
|
+
if (validation.error) {
|
198
|
+
return {
|
199
|
+
calendar: validation.validationText
|
200
|
+
};
|
201
|
+
}
|
202
|
+
};
|
203
|
+
return /*#__PURE__*/_react.default.createElement(_reactFinalForm.Form, {
|
204
|
+
onSubmit: (values, meta) => {
|
205
|
+
console.log('SUBMITTING', {
|
206
|
+
values,
|
207
|
+
meta
|
208
|
+
});
|
209
|
+
},
|
210
|
+
initialValues: {
|
211
|
+
calendar: '2022-10-12'
|
212
|
+
},
|
213
|
+
validate: errored
|
214
|
+
}, _ref4 => {
|
215
|
+
let {
|
216
|
+
handleSubmit,
|
217
|
+
invalid
|
218
|
+
} = _ref4;
|
219
|
+
return /*#__PURE__*/_react.default.createElement("form", {
|
220
|
+
onSubmit: handleSubmit
|
221
|
+
}, /*#__PURE__*/_react.default.createElement(_reactFinalForm.Field, {
|
222
|
+
name: "calendar"
|
223
|
+
}, props => /*#__PURE__*/_react.default.createElement(_calendarInput.CalendarInput, _extends({}, props, {
|
224
|
+
label: "Enter a date",
|
225
|
+
helpText: "Date has to be after 2022-11-01",
|
166
226
|
input: props.input,
|
167
227
|
meta: props.meta,
|
168
228
|
editable: true,
|
@@ -170,6 +230,7 @@ function CalendarWithEditableInputReactForm() {
|
|
170
230
|
calendar: "gregory"
|
171
231
|
}, validation, {
|
172
232
|
minDate: "2022-11-01",
|
233
|
+
strictValidation: false,
|
173
234
|
onDateSelect: date => {
|
174
235
|
const validation = {
|
175
236
|
...date.validation,
|
@@ -178,7 +239,7 @@ function CalendarWithEditableInputReactForm() {
|
|
178
239
|
setValidation(validation);
|
179
240
|
props.input.onChange(date ? date === null || date === void 0 ? void 0 : date.calendarDateString : '');
|
180
241
|
}
|
181
|
-
}))), /*#__PURE__*/_react.default.createElement(
|
242
|
+
}))), /*#__PURE__*/_react.default.createElement(_button.Button, {
|
182
243
|
type: "submit",
|
183
244
|
disabled: invalid,
|
184
245
|
onClick: handleSubmit
|
@@ -1,4 +1,5 @@
|
|
1
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
|
+
import { Button } from '@dhis2-ui/button';
|
2
3
|
import React, { useState } from 'react';
|
3
4
|
import { Field, Form } from 'react-final-form';
|
4
5
|
import { CalendarInput } from '../calendar-input/calendar-input.js';
|
@@ -122,12 +123,14 @@ export function CalendarWithEditiableInput() {
|
|
122
123
|
clearable: true
|
123
124
|
})));
|
124
125
|
}
|
125
|
-
export function
|
126
|
+
export function CalendarWithStrictValidation() {
|
126
127
|
const [validation, setValidation] = useState({});
|
127
128
|
const errored = () => {
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
if (validation.error) {
|
130
|
+
return {
|
131
|
+
calendar: validation.validationText
|
132
|
+
};
|
133
|
+
}
|
131
134
|
};
|
132
135
|
return /*#__PURE__*/React.createElement(Form, {
|
133
136
|
onSubmit: (values, meta) => {
|
@@ -150,6 +153,62 @@ export function CalendarWithEditableInputReactForm() {
|
|
150
153
|
}, /*#__PURE__*/React.createElement(Field, {
|
151
154
|
name: "calendar"
|
152
155
|
}, props => /*#__PURE__*/React.createElement(CalendarInput, _extends({}, props, {
|
156
|
+
label: "Enter a date",
|
157
|
+
helpText: "Date has to be after 2022-11-01",
|
158
|
+
input: props.input,
|
159
|
+
meta: props.meta,
|
160
|
+
editable: true,
|
161
|
+
date: props.input.value,
|
162
|
+
calendar: "gregory"
|
163
|
+
}, validation, {
|
164
|
+
minDate: "2022-11-01",
|
165
|
+
onDateSelect: date => {
|
166
|
+
const validation = {
|
167
|
+
...date.validation,
|
168
|
+
validationText: date.validation.validationCode === 'WRONG_FORMAT' ? 'custom validation message for format' : date.validation.validationText
|
169
|
+
};
|
170
|
+
setValidation(validation);
|
171
|
+
props.input.onChange(date ? date === null || date === void 0 ? void 0 : date.calendarDateString : '');
|
172
|
+
}
|
173
|
+
}))), /*#__PURE__*/React.createElement(Button, {
|
174
|
+
type: "submit",
|
175
|
+
disabled: invalid,
|
176
|
+
onClick: handleSubmit
|
177
|
+
}, "Submit"));
|
178
|
+
});
|
179
|
+
}
|
180
|
+
export function CalendarWithNonStrictValidation() {
|
181
|
+
const [validation, setValidation] = useState({});
|
182
|
+
const errored = () => {
|
183
|
+
if (validation.error) {
|
184
|
+
return {
|
185
|
+
calendar: validation.validationText
|
186
|
+
};
|
187
|
+
}
|
188
|
+
};
|
189
|
+
return /*#__PURE__*/React.createElement(Form, {
|
190
|
+
onSubmit: (values, meta) => {
|
191
|
+
console.log('SUBMITTING', {
|
192
|
+
values,
|
193
|
+
meta
|
194
|
+
});
|
195
|
+
},
|
196
|
+
initialValues: {
|
197
|
+
calendar: '2022-10-12'
|
198
|
+
},
|
199
|
+
validate: errored
|
200
|
+
}, _ref4 => {
|
201
|
+
let {
|
202
|
+
handleSubmit,
|
203
|
+
invalid
|
204
|
+
} = _ref4;
|
205
|
+
return /*#__PURE__*/React.createElement("form", {
|
206
|
+
onSubmit: handleSubmit
|
207
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
208
|
+
name: "calendar"
|
209
|
+
}, props => /*#__PURE__*/React.createElement(CalendarInput, _extends({}, props, {
|
210
|
+
label: "Enter a date",
|
211
|
+
helpText: "Date has to be after 2022-11-01",
|
153
212
|
input: props.input,
|
154
213
|
meta: props.meta,
|
155
214
|
editable: true,
|
@@ -157,6 +216,7 @@ export function CalendarWithEditableInputReactForm() {
|
|
157
216
|
calendar: "gregory"
|
158
217
|
}, validation, {
|
159
218
|
minDate: "2022-11-01",
|
219
|
+
strictValidation: false,
|
160
220
|
onDateSelect: date => {
|
161
221
|
const validation = {
|
162
222
|
...date.validation,
|
@@ -165,7 +225,7 @@ export function CalendarWithEditableInputReactForm() {
|
|
165
225
|
setValidation(validation);
|
166
226
|
props.input.onChange(date ? date === null || date === void 0 ? void 0 : date.calendarDateString : '');
|
167
227
|
}
|
168
|
-
}))), /*#__PURE__*/React.createElement(
|
228
|
+
}))), /*#__PURE__*/React.createElement(Button, {
|
169
229
|
type: "submit",
|
170
230
|
disabled: invalid,
|
171
231
|
onClick: handleSubmit
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dhis2-ui/calendar",
|
3
|
-
"version": "10.0.0-alpha.
|
3
|
+
"version": "10.0.0-alpha.4",
|
4
4
|
"description": "UI Calendar",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -33,15 +33,15 @@
|
|
33
33
|
"styled-jsx": "^4"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@dhis2-ui/button": "10.0.0-alpha.
|
37
|
-
"@dhis2-ui/card": "10.0.0-alpha.
|
38
|
-
"@dhis2-ui/input": "10.0.0-alpha.
|
39
|
-
"@dhis2-ui/layer": "10.0.0-alpha.
|
40
|
-
"@dhis2-ui/popper": "10.0.0-alpha.
|
36
|
+
"@dhis2-ui/button": "10.0.0-alpha.4",
|
37
|
+
"@dhis2-ui/card": "10.0.0-alpha.4",
|
38
|
+
"@dhis2-ui/input": "10.0.0-alpha.4",
|
39
|
+
"@dhis2-ui/layer": "10.0.0-alpha.4",
|
40
|
+
"@dhis2-ui/popper": "10.0.0-alpha.4",
|
41
41
|
"@dhis2/multi-calendar-dates": "2.0.0-alpha.2",
|
42
42
|
"@dhis2/prop-types": "^3.1.2",
|
43
|
-
"@dhis2/ui-constants": "10.0.0-alpha.
|
44
|
-
"@dhis2/ui-icons": "10.0.0-alpha.
|
43
|
+
"@dhis2/ui-constants": "10.0.0-alpha.4",
|
44
|
+
"@dhis2/ui-icons": "10.0.0-alpha.4",
|
45
45
|
"classnames": "^2.3.1",
|
46
46
|
"prop-types": "^15.7.2"
|
47
47
|
},
|
package/types/index.d.ts
CHANGED
@@ -20,6 +20,11 @@ export interface CalendarProps {
|
|
20
20
|
* the size of a single cell in the table forming the calendar
|
21
21
|
*/
|
22
22
|
cellSize?: string
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Add a "clear" button to delete the selected date
|
26
|
+
*/
|
27
|
+
clearable?: boolean
|
23
28
|
/**
|
24
29
|
* the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601)
|
25
30
|
*/
|
@@ -52,10 +57,7 @@ export interface CalendarProps {
|
|
52
57
|
|
53
58
|
export const Calendar: React.FC<CalendarProps>
|
54
59
|
|
55
|
-
export type CalendarInputProps = Omit<
|
56
|
-
InputFieldProps,
|
57
|
-
'label' | 'type' | 'value'
|
58
|
-
> &
|
60
|
+
export type CalendarInputProps = Omit<InputFieldProps, 'type' | 'value'> &
|
59
61
|
CalendarProps
|
60
62
|
|
61
63
|
export const CalendarInput: React.FC<CalendarInputProps>
|