@telefonica/mistica 10.8.1 → 10.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/date-field.js +8 -0
- package/dist/date-time-field.js +8 -0
- package/dist/date-time-picker.d.ts +1 -0
- package/dist/date-time-picker.js +55 -20
- package/dist/date-time-picker.js.flow +1 -0
- package/dist/decimal-field.d.ts +1 -0
- package/dist/decimal-field.js.flow +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.flow +1 -0
- package/dist/month-field.d.ts +9 -0
- package/dist/month-field.js +192 -0
- package/dist/month-field.js.flow +13 -0
- package/dist/text-field-base.js +8 -1
- package/dist/theme.d.ts +1 -0
- package/dist/theme.js +8 -4
- package/dist/theme.js.flow +1 -0
- package/dist/utils/time.d.ts +1 -0
- package/dist/utils/time.js +9 -1
- package/dist/utils/time.js.flow +1 -0
- package/dist-es/date-field.js +7 -0
- package/dist-es/date-time-field.js +7 -0
- package/dist-es/date-time-picker.js +56 -22
- package/dist-es/index.js +1 -0
- package/dist-es/month-field.js +120 -0
- package/dist-es/text-field-base.js +8 -1
- package/dist-es/theme.js +8 -4
- package/dist-es/utils/time.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [10.9.0](https://github.com/Telefonica/mistica-web/compare/v10.8.1...v10.9.0) (2021-10-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **MonthField:** new form field to select months ([#356](https://github.com/Telefonica/mistica-web/issues/356)) ([1a949a5](https://github.com/Telefonica/mistica-web/commit/1a949a5fa4d2f9e7a0141afd7c920741faf36c49))
|
|
7
|
+
|
|
1
8
|
## [10.8.1](https://github.com/Telefonica/mistica-web/compare/v10.8.0...v10.8.1) (2021-10-19)
|
|
2
9
|
|
|
3
10
|
|
package/dist/date-field.js
CHANGED
|
@@ -23,6 +23,8 @@ var _time = require("./utils/time");
|
|
|
23
23
|
|
|
24
24
|
var _hooks = require("./hooks");
|
|
25
25
|
|
|
26
|
+
var _platform = require("./utils/platform");
|
|
27
|
+
|
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
29
|
|
|
28
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -112,6 +114,11 @@ var DateField = function DateField(_ref) {
|
|
|
112
114
|
};
|
|
113
115
|
|
|
114
116
|
var hasNativePicker = React.useMemo(function () {
|
|
117
|
+
if ((0, _platform.isFirefox)()) {
|
|
118
|
+
// disabled in firefox because it shows a close button over the icon and can't be styled
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
return (0, _dom.isInputTypeSupported)('date');
|
|
116
123
|
}, []);
|
|
117
124
|
|
|
@@ -180,6 +187,7 @@ var DateField = function DateField(_ref) {
|
|
|
180
187
|
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
181
188
|
fallback: nativePicker
|
|
182
189
|
}, /*#__PURE__*/React.createElement(ReactDateTimePicker, _extends({}, rest, fieldProps, {
|
|
190
|
+
optional: optional,
|
|
183
191
|
isValidDate: function isValidDate(currentDate) {
|
|
184
192
|
return isInRange((0, _time.getLocalDateString)(currentDate.toDate()));
|
|
185
193
|
}
|
package/dist/date-time-field.js
CHANGED
|
@@ -21,6 +21,8 @@ var _time = require("./utils/time");
|
|
|
21
21
|
|
|
22
22
|
var _iconCalendarRegular = _interopRequireDefault(require("./generated/mistica-icons/icon-calendar-regular"));
|
|
23
23
|
|
|
24
|
+
var _platform = require("./utils/platform");
|
|
25
|
+
|
|
24
26
|
var _hooks = require("./hooks");
|
|
25
27
|
|
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -108,6 +110,11 @@ var FormDateField = function FormDateField(_ref) {
|
|
|
108
110
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
109
111
|
|
|
110
112
|
var hasNativePicker = React.useMemo(function () {
|
|
113
|
+
if ((0, _platform.isFirefox)()) {
|
|
114
|
+
// disabled for firefox because the picker has no option to select time
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
111
118
|
return (0, _dom.isInputTypeSupported)('datetime-local');
|
|
112
119
|
}, []);
|
|
113
120
|
|
|
@@ -182,6 +189,7 @@ var FormDateField = function FormDateField(_ref) {
|
|
|
182
189
|
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
183
190
|
fallback: nativePicker
|
|
184
191
|
}, /*#__PURE__*/React.createElement(ReactDateTimePicker, _extends({}, rest, fieldProps, {
|
|
192
|
+
optional: optional,
|
|
185
193
|
withTime: true,
|
|
186
194
|
isValidDate: function isValidDate(currentDate) {
|
|
187
195
|
return isInRange((0, _time.getLocalDateTimeString)(currentDate.toDate()));
|
|
@@ -5,6 +5,7 @@ export interface DateTimePickerProps extends CommonFormFieldProps {
|
|
|
5
5
|
inputRef: (field: HTMLInputElement | null) => void;
|
|
6
6
|
isValidDate?: (currentDate: Moment.Moment, selectedDate: Moment.Moment) => boolean;
|
|
7
7
|
withTime?: boolean;
|
|
8
|
+
mode?: 'year-month';
|
|
8
9
|
}
|
|
9
10
|
declare const DateTimePicker: React.FC<DateTimePickerProps>;
|
|
10
11
|
export default DateTimePicker;
|
package/dist/date-time-picker.js
CHANGED
|
@@ -27,13 +27,15 @@ var _jss = require("./jss");
|
|
|
27
27
|
|
|
28
28
|
var _hooks = require("./hooks");
|
|
29
29
|
|
|
30
|
+
var _iconCloseRegular = _interopRequireDefault(require("./generated/mistica-icons/icon-close-regular"));
|
|
31
|
+
|
|
30
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
33
|
|
|
32
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
35
|
|
|
34
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
37
|
|
|
36
|
-
var _excluded = ["withTime", "isValidDate"];
|
|
38
|
+
var _excluded = ["withTime", "mode", "isValidDate", "optional"];
|
|
37
39
|
|
|
38
40
|
function _extends() {
|
|
39
41
|
_extends = Object.assign || function (target) {
|
|
@@ -344,7 +346,9 @@ var useStyles = (0, _jss.createUseStyles)(function () {
|
|
|
344
346
|
|
|
345
347
|
var DateTimePicker = function DateTimePicker(_ref) {
|
|
346
348
|
var withTime = _ref.withTime,
|
|
349
|
+
mode = _ref.mode,
|
|
347
350
|
isValidDate = _ref.isValidDate,
|
|
351
|
+
optional = _ref.optional,
|
|
348
352
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
349
353
|
|
|
350
354
|
var _React$useState = React.useState(false),
|
|
@@ -353,20 +357,17 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
353
357
|
setShowPicker = _React$useState2[1];
|
|
354
358
|
|
|
355
359
|
var classes = useStyles();
|
|
360
|
+
|
|
361
|
+
var _useTheme = (0, _hooks.useTheme)(),
|
|
362
|
+
texts = _useTheme.texts;
|
|
363
|
+
|
|
356
364
|
var fieldRef = React.useRef(null);
|
|
357
365
|
|
|
358
366
|
var _useElementDimensions = (0, _hooks.useElementDimensions)(),
|
|
359
367
|
pickerContainerHeight = _useElementDimensions.height,
|
|
360
368
|
pickerContainerRef = _useElementDimensions.ref;
|
|
361
369
|
|
|
362
|
-
var
|
|
363
|
-
var _rest$onFocus;
|
|
364
|
-
|
|
365
|
-
setShowPicker(true);
|
|
366
|
-
(_rest$onFocus = rest.onFocus) === null || _rest$onFocus === void 0 ? void 0 : _rest$onFocus.call(rest, event);
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
var getCalendarContainerStyles = function getCalendarContainerStyles() {
|
|
370
|
+
var getPickerContainerStyles = function getPickerContainerStyles() {
|
|
370
371
|
var _fieldRef$current;
|
|
371
372
|
|
|
372
373
|
var _ref2 = ((_fieldRef$current = fieldRef.current) === null || _fieldRef$current === void 0 ? void 0 : _fieldRef$current.getBoundingClientRect()) || {},
|
|
@@ -399,8 +400,20 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
399
400
|
return value ? new Date(value) : undefined;
|
|
400
401
|
};
|
|
401
402
|
|
|
403
|
+
var formatMoment = function formatMoment(moment) {
|
|
404
|
+
if (withTime) {
|
|
405
|
+
return moment.format('yyyy-MM-DD HH:mm');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (mode === 'year-month') {
|
|
409
|
+
return moment.format('yyyy-MM');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return moment.format('yyyy-MM-DD');
|
|
413
|
+
};
|
|
414
|
+
|
|
402
415
|
var setValue = function setValue(moment) {
|
|
403
|
-
var value = typeof moment === 'string' ? moment : moment
|
|
416
|
+
var value = typeof moment === 'string' ? moment : formatMoment(moment);
|
|
404
417
|
|
|
405
418
|
if (fieldRef.current) {
|
|
406
419
|
var _rest$onChange;
|
|
@@ -410,12 +423,21 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
410
423
|
}
|
|
411
424
|
};
|
|
412
425
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
426
|
+
var renderEndIcon = function renderEndIcon() {
|
|
427
|
+
if (getValue() && optional) {
|
|
428
|
+
return /*#__PURE__*/React.createElement(_iconButton.default, {
|
|
429
|
+
"aria-label": texts.clearButton,
|
|
430
|
+
size: 32,
|
|
431
|
+
onPress: function onPress(event) {
|
|
432
|
+
event.stopPropagation();
|
|
433
|
+
setValue('');
|
|
434
|
+
}
|
|
435
|
+
}, /*#__PURE__*/React.createElement(_iconCloseRegular.default, {
|
|
436
|
+
size: 24
|
|
437
|
+
}));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return /*#__PURE__*/React.createElement(_iconButton.default, {
|
|
419
441
|
"aria-label": "",
|
|
420
442
|
size: 32,
|
|
421
443
|
onPress: function onPress() {
|
|
@@ -423,7 +445,18 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
423
445
|
}
|
|
424
446
|
}, /*#__PURE__*/React.createElement(_iconCalendarRegular.default, {
|
|
425
447
|
size: 24
|
|
426
|
-
}))
|
|
448
|
+
}));
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_textFieldBase.default, _extends({}, rest, {
|
|
452
|
+
style: {
|
|
453
|
+
cursor: 'default'
|
|
454
|
+
},
|
|
455
|
+
required: !optional,
|
|
456
|
+
type: "text",
|
|
457
|
+
autoComplete: "off",
|
|
458
|
+
shrinkLabel: !!getValue(),
|
|
459
|
+
endIcon: renderEndIcon(),
|
|
427
460
|
inputRef: function inputRef(e) {
|
|
428
461
|
var _rest$inputRef;
|
|
429
462
|
|
|
@@ -435,7 +468,7 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
435
468
|
return setShowPicker(true);
|
|
436
469
|
},
|
|
437
470
|
onClick: function onClick() {
|
|
438
|
-
|
|
471
|
+
setShowPicker(true);
|
|
439
472
|
}
|
|
440
473
|
})), showPicker && /*#__PURE__*/React.createElement(_overlay.default, {
|
|
441
474
|
onPress: function onPress(e) {
|
|
@@ -445,11 +478,13 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
445
478
|
disableScroll: true
|
|
446
479
|
}, /*#__PURE__*/React.createElement("div", {
|
|
447
480
|
ref: pickerContainerRef,
|
|
448
|
-
style:
|
|
481
|
+
style: getPickerContainerStyles(),
|
|
449
482
|
className: classes.reactDatePicker
|
|
450
483
|
}, /*#__PURE__*/React.createElement(_reactDatetime.default, {
|
|
451
|
-
|
|
484
|
+
initialViewMode: mode === 'year-month' ? 'months' : undefined,
|
|
485
|
+
dateFormat: mode === 'year-month' ? 'YYYY-MM' : undefined,
|
|
452
486
|
timeFormat: withTime ? 'HH:mm' : false,
|
|
487
|
+
initialValue: getValue(),
|
|
453
488
|
locale: browserLocale,
|
|
454
489
|
input: false,
|
|
455
490
|
onChange: setValue,
|
|
@@ -9,6 +9,7 @@ export type DateTimePickerProps = {|
|
|
|
9
9
|
inputRef: (field: HTMLInputElement | null) => void,
|
|
10
10
|
isValidDate?: (currentDate: Moment, selectedDate: Moment) => boolean,
|
|
11
11
|
withTime?: boolean,
|
|
12
|
+
mode?: "year-month",
|
|
12
13
|
|};
|
|
13
14
|
declare var DateTimePicker: React.ComponentType<DateTimePickerProps>;
|
|
14
15
|
declare export default typeof DateTimePicker;
|
package/dist/decimal-field.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare type DecimalInputProps = any;
|
|
|
12
12
|
export declare const DecimalInput: React.FC<DecimalInputProps>;
|
|
13
13
|
export interface DecimalFieldProps extends CommonFormFieldProps {
|
|
14
14
|
onChangeValue?: (value: string, rawValue: string) => void;
|
|
15
|
+
prefix?: React.ReactNode;
|
|
15
16
|
}
|
|
16
17
|
declare const DecimalField: React.FC<DecimalFieldProps>;
|
|
17
18
|
export default DecimalField;
|
|
@@ -17,6 +17,7 @@ export type DecimalFieldProps = {|
|
|
|
17
17
|
...$Exact<CommonFormFieldProps>,
|
|
18
18
|
|
|
19
19
|
onChangeValue?: (value: string, rawValue: string) => void,
|
|
20
|
+
prefix?: React.Node,
|
|
20
21
|
|};
|
|
21
22
|
declare var DecimalField: React.ComponentType<DecimalFieldProps>;
|
|
22
23
|
declare export default typeof DecimalField;
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export { default as CreditCardExpirationField } from './credit-card-expiration-f
|
|
|
66
66
|
export { default as CreditCardFields } from './credit-card-fields';
|
|
67
67
|
export { default as CvvField } from './cvv-field';
|
|
68
68
|
export { default as DateField } from './date-field';
|
|
69
|
+
export { default as MonthField } from './month-field';
|
|
69
70
|
export { default as DateTimeField } from './date-time-field';
|
|
70
71
|
export { default as IntegerField } from './integer-field';
|
|
71
72
|
export { default as DecimalField } from './decimal-field';
|
package/dist/index.js
CHANGED
|
@@ -635,6 +635,12 @@ Object.defineProperty(exports, "DateField", {
|
|
|
635
635
|
return _dateField.default;
|
|
636
636
|
}
|
|
637
637
|
});
|
|
638
|
+
Object.defineProperty(exports, "MonthField", {
|
|
639
|
+
enumerable: true,
|
|
640
|
+
get: function get() {
|
|
641
|
+
return _monthField.default;
|
|
642
|
+
}
|
|
643
|
+
});
|
|
638
644
|
Object.defineProperty(exports, "DateTimeField", {
|
|
639
645
|
enumerable: true,
|
|
640
646
|
get: function get() {
|
|
@@ -7944,6 +7950,8 @@ var _cvvField = _interopRequireDefault(require("./cvv-field"));
|
|
|
7944
7950
|
|
|
7945
7951
|
var _dateField = _interopRequireDefault(require("./date-field"));
|
|
7946
7952
|
|
|
7953
|
+
var _monthField = _interopRequireDefault(require("./month-field"));
|
|
7954
|
+
|
|
7947
7955
|
var _dateTimeField = _interopRequireDefault(require("./date-time-field"));
|
|
7948
7956
|
|
|
7949
7957
|
var _integerField = _interopRequireDefault(require("./integer-field"));
|
package/dist/index.js.flow
CHANGED
|
@@ -109,6 +109,7 @@ declare export { default as CreditCardExpirationField } from "./credit-card-expi
|
|
|
109
109
|
declare export { default as CreditCardFields } from "./credit-card-fields";
|
|
110
110
|
declare export { default as CvvField } from "./cvv-field";
|
|
111
111
|
declare export { default as DateField } from "./date-field";
|
|
112
|
+
declare export { default as MonthField } from "./month-field";
|
|
112
113
|
declare export { default as DateTimeField } from "./date-time-field";
|
|
113
114
|
declare export { default as IntegerField } from "./integer-field";
|
|
114
115
|
declare export { default as DecimalField } from "./decimal-field";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { CommonFormFieldProps } from './text-field-base';
|
|
3
|
+
export interface DateFieldProps extends CommonFormFieldProps {
|
|
4
|
+
onChangeValue?: (value: string, rawValue: string) => void;
|
|
5
|
+
min?: Date;
|
|
6
|
+
max?: Date;
|
|
7
|
+
}
|
|
8
|
+
declare const DateField: React.FC<DateFieldProps>;
|
|
9
|
+
export default DateField;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _formContext = require("./form-context");
|
|
13
|
+
|
|
14
|
+
var _textFieldBase = _interopRequireDefault(require("./text-field-base"));
|
|
15
|
+
|
|
16
|
+
var _dom = require("./utils/dom");
|
|
17
|
+
|
|
18
|
+
var _environment = require("./utils/environment");
|
|
19
|
+
|
|
20
|
+
var _iconCalendarRegular = _interopRequireDefault(require("./generated/mistica-icons/icon-calendar-regular"));
|
|
21
|
+
|
|
22
|
+
var _time = require("./utils/time");
|
|
23
|
+
|
|
24
|
+
var _hooks = require("./hooks");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
+
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
+
|
|
32
|
+
var _excluded = ["disabled", "error", "helperText", "name", "optional", "validate", "onChange", "onChangeValue", "onBlur", "value", "defaultValue", "min", "max"];
|
|
33
|
+
|
|
34
|
+
function _extends() {
|
|
35
|
+
_extends = Object.assign || function (target) {
|
|
36
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
37
|
+
var source = arguments[i];
|
|
38
|
+
|
|
39
|
+
for (var key in source) {
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
41
|
+
target[key] = source[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return target;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return _extends.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _objectWithoutProperties(source, excluded) {
|
|
53
|
+
if (source == null) return {};
|
|
54
|
+
|
|
55
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
56
|
+
|
|
57
|
+
var key, i;
|
|
58
|
+
|
|
59
|
+
if (Object.getOwnPropertySymbols) {
|
|
60
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
61
|
+
|
|
62
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
63
|
+
key = sourceSymbolKeys[i];
|
|
64
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
65
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
66
|
+
target[key] = source[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
74
|
+
if (source == null) return {};
|
|
75
|
+
var target = {};
|
|
76
|
+
var sourceKeys = Object.keys(source);
|
|
77
|
+
var key, i;
|
|
78
|
+
|
|
79
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
80
|
+
key = sourceKeys[i];
|
|
81
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
82
|
+
target[key] = source[key];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return target;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var ReactDateTimePicker = /*#__PURE__*/React.lazy(function () {
|
|
89
|
+
return import(
|
|
90
|
+
/* webpackChunkName: "date-time-picker" */
|
|
91
|
+
'./date-time-picker');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
var DateField = function DateField(_ref) {
|
|
95
|
+
var disabled = _ref.disabled,
|
|
96
|
+
error = _ref.error,
|
|
97
|
+
helperText = _ref.helperText,
|
|
98
|
+
name = _ref.name,
|
|
99
|
+
optional = _ref.optional,
|
|
100
|
+
validateProp = _ref.validate,
|
|
101
|
+
onChange = _ref.onChange,
|
|
102
|
+
onChangeValueProp = _ref.onChangeValue,
|
|
103
|
+
onBlur = _ref.onBlur,
|
|
104
|
+
value = _ref.value,
|
|
105
|
+
defaultValue = _ref.defaultValue,
|
|
106
|
+
min = _ref.min,
|
|
107
|
+
max = _ref.max,
|
|
108
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
109
|
+
|
|
110
|
+
var processValue = function processValue(value) {
|
|
111
|
+
return value;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var hasNativePicker = React.useMemo(function () {
|
|
115
|
+
return (0, _dom.isInputTypeSupported)('month');
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
var _useTheme = (0, _hooks.useTheme)(),
|
|
119
|
+
texts = _useTheme.texts;
|
|
120
|
+
|
|
121
|
+
var isInRange = function isInRange(value) {
|
|
122
|
+
if (min && value && value < (0, _time.getLocalYearMonthString)(min)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (max && value && value > (0, _time.getLocalYearMonthString)(max)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var validate = function validate(value, rawValue) {
|
|
134
|
+
if (!isInRange(value)) {
|
|
135
|
+
return texts.formDateOutOfRangeError;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return validateProp === null || validateProp === void 0 ? void 0 : validateProp(value, rawValue);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
var onChangeValue = function onChangeValue(value, rawValue) {
|
|
142
|
+
if (isInRange(value)) {
|
|
143
|
+
onChangeValueProp === null || onChangeValueProp === void 0 ? void 0 : onChangeValueProp(value, rawValue);
|
|
144
|
+
} // if not in range, onChangeValue is not called
|
|
145
|
+
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
var fieldProps = (0, _formContext.useFieldProps)({
|
|
149
|
+
name: name,
|
|
150
|
+
value: value,
|
|
151
|
+
defaultValue: defaultValue,
|
|
152
|
+
processValue: processValue,
|
|
153
|
+
helperText: helperText,
|
|
154
|
+
optional: optional,
|
|
155
|
+
error: error,
|
|
156
|
+
disabled: disabled,
|
|
157
|
+
onBlur: onBlur,
|
|
158
|
+
validate: validate,
|
|
159
|
+
onChange: onChange,
|
|
160
|
+
onChangeValue: onChangeValue
|
|
161
|
+
});
|
|
162
|
+
var nativePicker = /*#__PURE__*/React.createElement(_textFieldBase.default, _extends({}, rest, fieldProps, {
|
|
163
|
+
min: min ? (0, _time.getLocalYearMonthString)(min) : undefined,
|
|
164
|
+
max: max ? (0, _time.getLocalYearMonthString)(max) : undefined,
|
|
165
|
+
type: "month",
|
|
166
|
+
endIconOverlay: /*#__PURE__*/React.createElement("div", {
|
|
167
|
+
style: {
|
|
168
|
+
position: 'absolute',
|
|
169
|
+
top: 16,
|
|
170
|
+
right: 16,
|
|
171
|
+
pointerEvents: 'none'
|
|
172
|
+
}
|
|
173
|
+
}, /*#__PURE__*/React.createElement(_iconCalendarRegular.default, null))
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
if (hasNativePicker || (0, _environment.isServerSide)()) {
|
|
177
|
+
return nativePicker;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
181
|
+
fallback: nativePicker
|
|
182
|
+
}, /*#__PURE__*/React.createElement(ReactDateTimePicker, _extends({}, rest, fieldProps, {
|
|
183
|
+
optional: optional,
|
|
184
|
+
isValidDate: function isValidDate(currentDate) {
|
|
185
|
+
return isInRange((0, _time.getLocalYearMonthString)(currentDate.toDate()));
|
|
186
|
+
},
|
|
187
|
+
mode: "year-month"
|
|
188
|
+
})));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
var _default = DateField;
|
|
192
|
+
exports.default = _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { CommonFormFieldProps } from "./text-field-base";
|
|
5
|
+
export type DateFieldProps = {|
|
|
6
|
+
...$Exact<CommonFormFieldProps>,
|
|
7
|
+
|
|
8
|
+
onChangeValue?: (value: string, rawValue: string) => void,
|
|
9
|
+
min?: Date,
|
|
10
|
+
max?: Date,
|
|
11
|
+
|};
|
|
12
|
+
declare var DateField: React.ComponentType<DateFieldProps>;
|
|
13
|
+
declare export default typeof DateField;
|
package/dist/text-field-base.js
CHANGED
|
@@ -315,6 +315,10 @@ var useStyles = (0, _jss.createUseStyles)(function (theme) {
|
|
|
315
315
|
// Chrome: hide value if not valid or focused
|
|
316
316
|
// `opacity: 0` is needed when min/max is set and some parts of the date are disabled
|
|
317
317
|
// be sure to check that case when updating these styles
|
|
318
|
+
'&[type="month"]:not(:valid):not(:focus)::-webkit-datetime-edit': {
|
|
319
|
+
color: 'transparent',
|
|
320
|
+
opacity: 0
|
|
321
|
+
},
|
|
318
322
|
'&[type="date"]:not(:valid):not(:focus)::-webkit-datetime-edit': {
|
|
319
323
|
color: 'transparent',
|
|
320
324
|
opacity: 0
|
|
@@ -325,6 +329,9 @@ var useStyles = (0, _jss.createUseStyles)(function (theme) {
|
|
|
325
329
|
},
|
|
326
330
|
// Firefox: hide value if not valid or focused
|
|
327
331
|
// Only apply when Firefox, otherwise it breaks styles in safari mobile
|
|
332
|
+
'&[type="month"]:not(:valid):not(:focus)': (0, _platform.isFirefox)() ? {
|
|
333
|
+
color: 'transparent'
|
|
334
|
+
} : {},
|
|
328
335
|
'&[type="date"]:not(:valid):not(:focus)': (0, _platform.isFirefox)() ? {
|
|
329
336
|
color: 'transparent'
|
|
330
337
|
} : {},
|
|
@@ -439,7 +446,7 @@ var TextFieldBaseComponent = /*#__PURE__*/React.forwardRef(function (_ref14, ref
|
|
|
439
446
|
var hasLabel = !!label || !rest.required; // this shrinkLabel override is a workaround because I was unable to find a way to hide date
|
|
440
447
|
// and date-time native placeholders when the input is not required
|
|
441
448
|
|
|
442
|
-
var shrinkLabel = shrinkLabelProp || (rest.type === 'date' || rest.type === 'datetime-local') && !rest.required;
|
|
449
|
+
var shrinkLabel = shrinkLabelProp || (rest.type === 'date' || rest.type === 'datetime-local' || rest.type === 'month') && !rest.required;
|
|
443
450
|
var classes = useStyles({
|
|
444
451
|
inputState: inputState,
|
|
445
452
|
error: error,
|
package/dist/theme.d.ts
CHANGED
package/dist/theme.js
CHANGED
|
@@ -96,7 +96,8 @@ var TEXTS_ES = {
|
|
|
96
96
|
menuLabelSuffix: 'menú',
|
|
97
97
|
openNavigationMenu: 'Abrir menú de navegación',
|
|
98
98
|
closeNavigationMenu: 'Cerrar menú de navegación',
|
|
99
|
-
backNavigationBar: 'Atrás'
|
|
99
|
+
backNavigationBar: 'Atrás',
|
|
100
|
+
clearButton: 'Borrar'
|
|
100
101
|
};
|
|
101
102
|
var TEXTS_EN = {
|
|
102
103
|
expirationDatePlaceholder: 'MM/YY',
|
|
@@ -125,7 +126,8 @@ var TEXTS_EN = {
|
|
|
125
126
|
menuLabelSuffix: 'menu',
|
|
126
127
|
openNavigationMenu: 'Open navigation menu',
|
|
127
128
|
closeNavigationMenu: 'Close navigation menu',
|
|
128
|
-
backNavigationBar: 'Back'
|
|
129
|
+
backNavigationBar: 'Back',
|
|
130
|
+
clearButton: 'Clear'
|
|
129
131
|
};
|
|
130
132
|
var TEXTS_DE = {
|
|
131
133
|
expirationDatePlaceholder: 'MM/JJ',
|
|
@@ -154,7 +156,8 @@ var TEXTS_DE = {
|
|
|
154
156
|
menuLabelSuffix: 'Menü',
|
|
155
157
|
openNavigationMenu: 'Navigationsmenü öffnen',
|
|
156
158
|
closeNavigationMenu: 'Navigationsmenü schließen',
|
|
157
|
-
backNavigationBar: 'Zurück'
|
|
159
|
+
backNavigationBar: 'Zurück',
|
|
160
|
+
clearButton: 'Löschen'
|
|
158
161
|
};
|
|
159
162
|
var TEXTS_PT = {
|
|
160
163
|
expirationDatePlaceholder: 'MM/AA',
|
|
@@ -183,7 +186,8 @@ var TEXTS_PT = {
|
|
|
183
186
|
menuLabelSuffix: 'menu',
|
|
184
187
|
openNavigationMenu: 'Abrir menu de navegação',
|
|
185
188
|
closeNavigationMenu: 'Fechar menu de navegação',
|
|
186
|
-
backNavigationBar: 'Voltar'
|
|
189
|
+
backNavigationBar: 'Voltar',
|
|
190
|
+
clearButton: 'Apagar'
|
|
187
191
|
};
|
|
188
192
|
|
|
189
193
|
var getTexts = function getTexts(locale) {
|
package/dist/theme.js.flow
CHANGED
package/dist/utils/time.d.ts
CHANGED
package/dist/utils/time.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getLocalDateTimeString = exports.getLocalDateString = void 0;
|
|
6
|
+
exports.getLocalDateTimeString = exports.getLocalYearMonthString = exports.getLocalDateString = void 0;
|
|
7
7
|
|
|
8
8
|
var getLocalDateString = function getLocalDateString(date) {
|
|
9
9
|
var yyyy = date.getFullYear();
|
|
@@ -14,6 +14,14 @@ var getLocalDateString = function getLocalDateString(date) {
|
|
|
14
14
|
|
|
15
15
|
exports.getLocalDateString = getLocalDateString;
|
|
16
16
|
|
|
17
|
+
var getLocalYearMonthString = function getLocalYearMonthString(date) {
|
|
18
|
+
var yyyy = date.getFullYear();
|
|
19
|
+
var mm = String(date.getMonth() + 1).padStart(2, '0');
|
|
20
|
+
return "".concat(yyyy, "-").concat(mm);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.getLocalYearMonthString = getLocalYearMonthString;
|
|
24
|
+
|
|
17
25
|
var getLocalDateTimeString = function getLocalDateTimeString(date) {
|
|
18
26
|
var h = String(date.getHours()).padStart(2, '0');
|
|
19
27
|
var m = String(date.getMinutes()).padStart(2, '0');
|
package/dist/utils/time.js.flow
CHANGED
package/dist-es/date-field.js
CHANGED
|
@@ -14,6 +14,7 @@ import { isServerSide } from './utils/environment';
|
|
|
14
14
|
import IconCalendarRegular from './generated/mistica-icons/icon-calendar-regular';
|
|
15
15
|
import { getLocalDateString } from './utils/time';
|
|
16
16
|
import { useTheme } from './hooks';
|
|
17
|
+
import { isFirefox } from './utils/platform';
|
|
17
18
|
var ReactDateTimePicker = /*#__PURE__*/React.lazy(function () {
|
|
18
19
|
return import(
|
|
19
20
|
/* webpackChunkName: "date-time-picker" */
|
|
@@ -41,6 +42,11 @@ var DateField = function DateField(_ref) {
|
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
var hasNativePicker = React.useMemo(function () {
|
|
45
|
+
if (isFirefox()) {
|
|
46
|
+
// disabled in firefox because it shows a close button over the icon and can't be styled
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
return isInputTypeSupported('date');
|
|
45
51
|
}, []);
|
|
46
52
|
|
|
@@ -109,6 +115,7 @@ var DateField = function DateField(_ref) {
|
|
|
109
115
|
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
110
116
|
fallback: nativePicker
|
|
111
117
|
}, /*#__PURE__*/React.createElement(ReactDateTimePicker, _extends({}, rest, fieldProps, {
|
|
118
|
+
optional: optional,
|
|
112
119
|
isValidDate: function isValidDate(currentDate) {
|
|
113
120
|
return isInRange(getLocalDateString(currentDate.toDate()));
|
|
114
121
|
}
|
|
@@ -13,6 +13,7 @@ import { isInputTypeSupported } from './utils/dom';
|
|
|
13
13
|
import { isServerSide } from './utils/environment';
|
|
14
14
|
import { getLocalDateTimeString } from './utils/time';
|
|
15
15
|
import IconCalendarRegular from './generated/mistica-icons/icon-calendar-regular';
|
|
16
|
+
import { isFirefox } from './utils/platform';
|
|
16
17
|
import { useTheme } from './hooks';
|
|
17
18
|
var ReactDateTimePicker = /*#__PURE__*/React.lazy(function () {
|
|
18
19
|
return import(
|
|
@@ -37,6 +38,11 @@ var FormDateField = function FormDateField(_ref) {
|
|
|
37
38
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
38
39
|
|
|
39
40
|
var hasNativePicker = React.useMemo(function () {
|
|
41
|
+
if (isFirefox()) {
|
|
42
|
+
// disabled for firefox because the picker has no option to select time
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
return isInputTypeSupported('datetime-local');
|
|
41
47
|
}, []);
|
|
42
48
|
|
|
@@ -111,6 +117,7 @@ var FormDateField = function FormDateField(_ref) {
|
|
|
111
117
|
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
112
118
|
fallback: nativePicker
|
|
113
119
|
}, /*#__PURE__*/React.createElement(ReactDateTimePicker, _extends({}, rest, fieldProps, {
|
|
120
|
+
optional: optional,
|
|
114
121
|
withTime: true,
|
|
115
122
|
isValidDate: function isValidDate(currentDate) {
|
|
116
123
|
return isInRange(getLocalDateTimeString(currentDate.toDate()));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["withTime", "isValidDate"];
|
|
1
|
+
var _excluded = ["withTime", "mode", "isValidDate", "optional"];
|
|
2
2
|
|
|
3
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); }
|
|
4
4
|
|
|
@@ -27,14 +27,15 @@ import { DEFAULT_WIDTH } from './text-field-components';
|
|
|
27
27
|
import IconButton from './icon-button';
|
|
28
28
|
import { cancelEvent, createChangeEvent } from './utils/dom';
|
|
29
29
|
import { createUseStyles } from './jss';
|
|
30
|
-
import { useElementDimensions } from './hooks';
|
|
30
|
+
import { useElementDimensions, useTheme } from './hooks';
|
|
31
|
+
import IconCloseRegular from './generated/mistica-icons/icon-close-regular';
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* Do not use this component!
|
|
33
35
|
* Use DateField or FormDateTimeField
|
|
34
36
|
*
|
|
35
37
|
* This component is a fallback for browsers that don't support datetime-local or date inputs
|
|
36
38
|
*/
|
|
37
|
-
|
|
38
39
|
var browserLocale = navigator.language.toLocaleLowerCase().split('-')[0];
|
|
39
40
|
import(
|
|
40
41
|
/* webpackChunkName: "moment-locale" */
|
|
@@ -223,7 +224,9 @@ var useStyles = createUseStyles(function () {
|
|
|
223
224
|
|
|
224
225
|
var DateTimePicker = function DateTimePicker(_ref) {
|
|
225
226
|
var withTime = _ref.withTime,
|
|
227
|
+
mode = _ref.mode,
|
|
226
228
|
isValidDate = _ref.isValidDate,
|
|
229
|
+
optional = _ref.optional,
|
|
227
230
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
228
231
|
|
|
229
232
|
var _React$useState = React.useState(false),
|
|
@@ -232,20 +235,17 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
232
235
|
setShowPicker = _React$useState2[1];
|
|
233
236
|
|
|
234
237
|
var classes = useStyles();
|
|
238
|
+
|
|
239
|
+
var _useTheme = useTheme(),
|
|
240
|
+
texts = _useTheme.texts;
|
|
241
|
+
|
|
235
242
|
var fieldRef = React.useRef(null);
|
|
236
243
|
|
|
237
244
|
var _useElementDimensions = useElementDimensions(),
|
|
238
245
|
pickerContainerHeight = _useElementDimensions.height,
|
|
239
246
|
pickerContainerRef = _useElementDimensions.ref;
|
|
240
247
|
|
|
241
|
-
var
|
|
242
|
-
var _rest$onFocus;
|
|
243
|
-
|
|
244
|
-
setShowPicker(true);
|
|
245
|
-
(_rest$onFocus = rest.onFocus) === null || _rest$onFocus === void 0 ? void 0 : _rest$onFocus.call(rest, event);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
var getCalendarContainerStyles = function getCalendarContainerStyles() {
|
|
248
|
+
var getPickerContainerStyles = function getPickerContainerStyles() {
|
|
249
249
|
var _fieldRef$current;
|
|
250
250
|
|
|
251
251
|
var _ref2 = ((_fieldRef$current = fieldRef.current) === null || _fieldRef$current === void 0 ? void 0 : _fieldRef$current.getBoundingClientRect()) || {},
|
|
@@ -278,8 +278,20 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
278
278
|
return value ? new Date(value) : undefined;
|
|
279
279
|
};
|
|
280
280
|
|
|
281
|
+
var formatMoment = function formatMoment(moment) {
|
|
282
|
+
if (withTime) {
|
|
283
|
+
return moment.format('yyyy-MM-DD HH:mm');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (mode === 'year-month') {
|
|
287
|
+
return moment.format('yyyy-MM');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return moment.format('yyyy-MM-DD');
|
|
291
|
+
};
|
|
292
|
+
|
|
281
293
|
var setValue = function setValue(moment) {
|
|
282
|
-
var value = typeof moment === 'string' ? moment : moment
|
|
294
|
+
var value = typeof moment === 'string' ? moment : formatMoment(moment);
|
|
283
295
|
|
|
284
296
|
if (fieldRef.current) {
|
|
285
297
|
var _rest$onChange;
|
|
@@ -289,12 +301,21 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
289
301
|
}
|
|
290
302
|
};
|
|
291
303
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
304
|
+
var renderEndIcon = function renderEndIcon() {
|
|
305
|
+
if (getValue() && optional) {
|
|
306
|
+
return /*#__PURE__*/React.createElement(IconButton, {
|
|
307
|
+
"aria-label": texts.clearButton,
|
|
308
|
+
size: 32,
|
|
309
|
+
onPress: function onPress(event) {
|
|
310
|
+
event.stopPropagation();
|
|
311
|
+
setValue('');
|
|
312
|
+
}
|
|
313
|
+
}, /*#__PURE__*/React.createElement(IconCloseRegular, {
|
|
314
|
+
size: 24
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return /*#__PURE__*/React.createElement(IconButton, {
|
|
298
319
|
"aria-label": "",
|
|
299
320
|
size: 32,
|
|
300
321
|
onPress: function onPress() {
|
|
@@ -302,7 +323,18 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
302
323
|
}
|
|
303
324
|
}, /*#__PURE__*/React.createElement(IconCalendarRegular, {
|
|
304
325
|
size: 24
|
|
305
|
-
}))
|
|
326
|
+
}));
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextFieldBase, _extends({}, rest, {
|
|
330
|
+
style: {
|
|
331
|
+
cursor: 'default'
|
|
332
|
+
},
|
|
333
|
+
required: !optional,
|
|
334
|
+
type: "text",
|
|
335
|
+
autoComplete: "off",
|
|
336
|
+
shrinkLabel: !!getValue(),
|
|
337
|
+
endIcon: renderEndIcon(),
|
|
306
338
|
inputRef: function inputRef(e) {
|
|
307
339
|
var _rest$inputRef;
|
|
308
340
|
|
|
@@ -314,7 +346,7 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
314
346
|
return setShowPicker(true);
|
|
315
347
|
},
|
|
316
348
|
onClick: function onClick() {
|
|
317
|
-
|
|
349
|
+
setShowPicker(true);
|
|
318
350
|
}
|
|
319
351
|
})), showPicker && /*#__PURE__*/React.createElement(Overlay, {
|
|
320
352
|
onPress: function onPress(e) {
|
|
@@ -324,11 +356,13 @@ var DateTimePicker = function DateTimePicker(_ref) {
|
|
|
324
356
|
disableScroll: true
|
|
325
357
|
}, /*#__PURE__*/React.createElement("div", {
|
|
326
358
|
ref: pickerContainerRef,
|
|
327
|
-
style:
|
|
359
|
+
style: getPickerContainerStyles(),
|
|
328
360
|
className: classes.reactDatePicker
|
|
329
361
|
}, /*#__PURE__*/React.createElement(Datetime, {
|
|
330
|
-
|
|
362
|
+
initialViewMode: mode === 'year-month' ? 'months' : undefined,
|
|
363
|
+
dateFormat: mode === 'year-month' ? 'YYYY-MM' : undefined,
|
|
331
364
|
timeFormat: withTime ? 'HH:mm' : false,
|
|
365
|
+
initialValue: getValue(),
|
|
332
366
|
locale: browserLocale,
|
|
333
367
|
input: false,
|
|
334
368
|
onChange: setValue,
|
package/dist-es/index.js
CHANGED
|
@@ -68,6 +68,7 @@ export { default as CreditCardExpirationField } from './credit-card-expiration-f
|
|
|
68
68
|
export { default as CreditCardFields } from './credit-card-fields';
|
|
69
69
|
export { default as CvvField } from './cvv-field';
|
|
70
70
|
export { default as DateField } from './date-field';
|
|
71
|
+
export { default as MonthField } from './month-field';
|
|
71
72
|
export { default as DateTimeField } from './date-time-field';
|
|
72
73
|
export { default as IntegerField } from './integer-field';
|
|
73
74
|
export { default as DecimalField } from './decimal-field';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var _excluded = ["disabled", "error", "helperText", "name", "optional", "validate", "onChange", "onChangeValue", "onBlur", "value", "defaultValue", "min", "max"];
|
|
2
|
+
|
|
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); }
|
|
4
|
+
|
|
5
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
6
|
+
|
|
7
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
8
|
+
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { useFieldProps } from './form-context';
|
|
11
|
+
import TextFieldBase from './text-field-base';
|
|
12
|
+
import { isInputTypeSupported } from './utils/dom';
|
|
13
|
+
import { isServerSide } from './utils/environment';
|
|
14
|
+
import IconCalendarRegular from './generated/mistica-icons/icon-calendar-regular';
|
|
15
|
+
import { getLocalYearMonthString } from './utils/time';
|
|
16
|
+
import { useTheme } from './hooks';
|
|
17
|
+
var ReactDateTimePicker = /*#__PURE__*/React.lazy(function () {
|
|
18
|
+
return import(
|
|
19
|
+
/* webpackChunkName: "date-time-picker" */
|
|
20
|
+
'./date-time-picker');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var DateField = function DateField(_ref) {
|
|
24
|
+
var disabled = _ref.disabled,
|
|
25
|
+
error = _ref.error,
|
|
26
|
+
helperText = _ref.helperText,
|
|
27
|
+
name = _ref.name,
|
|
28
|
+
optional = _ref.optional,
|
|
29
|
+
validateProp = _ref.validate,
|
|
30
|
+
onChange = _ref.onChange,
|
|
31
|
+
onChangeValueProp = _ref.onChangeValue,
|
|
32
|
+
onBlur = _ref.onBlur,
|
|
33
|
+
value = _ref.value,
|
|
34
|
+
defaultValue = _ref.defaultValue,
|
|
35
|
+
min = _ref.min,
|
|
36
|
+
max = _ref.max,
|
|
37
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
38
|
+
|
|
39
|
+
var processValue = function processValue(value) {
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var hasNativePicker = React.useMemo(function () {
|
|
44
|
+
return isInputTypeSupported('month');
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
var _useTheme = useTheme(),
|
|
48
|
+
texts = _useTheme.texts;
|
|
49
|
+
|
|
50
|
+
var isInRange = function isInRange(value) {
|
|
51
|
+
if (min && value && value < getLocalYearMonthString(min)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (max && value && value > getLocalYearMonthString(max)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
var validate = function validate(value, rawValue) {
|
|
63
|
+
if (!isInRange(value)) {
|
|
64
|
+
return texts.formDateOutOfRangeError;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return validateProp === null || validateProp === void 0 ? void 0 : validateProp(value, rawValue);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
var onChangeValue = function onChangeValue(value, rawValue) {
|
|
71
|
+
if (isInRange(value)) {
|
|
72
|
+
onChangeValueProp === null || onChangeValueProp === void 0 ? void 0 : onChangeValueProp(value, rawValue);
|
|
73
|
+
} // if not in range, onChangeValue is not called
|
|
74
|
+
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var fieldProps = useFieldProps({
|
|
78
|
+
name: name,
|
|
79
|
+
value: value,
|
|
80
|
+
defaultValue: defaultValue,
|
|
81
|
+
processValue: processValue,
|
|
82
|
+
helperText: helperText,
|
|
83
|
+
optional: optional,
|
|
84
|
+
error: error,
|
|
85
|
+
disabled: disabled,
|
|
86
|
+
onBlur: onBlur,
|
|
87
|
+
validate: validate,
|
|
88
|
+
onChange: onChange,
|
|
89
|
+
onChangeValue: onChangeValue
|
|
90
|
+
});
|
|
91
|
+
var nativePicker = /*#__PURE__*/React.createElement(TextFieldBase, _extends({}, rest, fieldProps, {
|
|
92
|
+
min: min ? getLocalYearMonthString(min) : undefined,
|
|
93
|
+
max: max ? getLocalYearMonthString(max) : undefined,
|
|
94
|
+
type: "month",
|
|
95
|
+
endIconOverlay: /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
style: {
|
|
97
|
+
position: 'absolute',
|
|
98
|
+
top: 16,
|
|
99
|
+
right: 16,
|
|
100
|
+
pointerEvents: 'none'
|
|
101
|
+
}
|
|
102
|
+
}, /*#__PURE__*/React.createElement(IconCalendarRegular, null))
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
if (hasNativePicker || isServerSide()) {
|
|
106
|
+
return nativePicker;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
110
|
+
fallback: nativePicker
|
|
111
|
+
}, /*#__PURE__*/React.createElement(ReactDateTimePicker, _extends({}, rest, fieldProps, {
|
|
112
|
+
optional: optional,
|
|
113
|
+
isValidDate: function isValidDate(currentDate) {
|
|
114
|
+
return isInRange(getLocalYearMonthString(currentDate.toDate()));
|
|
115
|
+
},
|
|
116
|
+
mode: "year-month"
|
|
117
|
+
})));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default DateField;
|
|
@@ -150,6 +150,10 @@ var useStyles = createUseStyles(function (theme) {
|
|
|
150
150
|
// Chrome: hide value if not valid or focused
|
|
151
151
|
// `opacity: 0` is needed when min/max is set and some parts of the date are disabled
|
|
152
152
|
// be sure to check that case when updating these styles
|
|
153
|
+
'&[type="month"]:not(:valid):not(:focus)::-webkit-datetime-edit': {
|
|
154
|
+
color: 'transparent',
|
|
155
|
+
opacity: 0
|
|
156
|
+
},
|
|
153
157
|
'&[type="date"]:not(:valid):not(:focus)::-webkit-datetime-edit': {
|
|
154
158
|
color: 'transparent',
|
|
155
159
|
opacity: 0
|
|
@@ -160,6 +164,9 @@ var useStyles = createUseStyles(function (theme) {
|
|
|
160
164
|
},
|
|
161
165
|
// Firefox: hide value if not valid or focused
|
|
162
166
|
// Only apply when Firefox, otherwise it breaks styles in safari mobile
|
|
167
|
+
'&[type="month"]:not(:valid):not(:focus)': isFirefox() ? {
|
|
168
|
+
color: 'transparent'
|
|
169
|
+
} : {},
|
|
163
170
|
'&[type="date"]:not(:valid):not(:focus)': isFirefox() ? {
|
|
164
171
|
color: 'transparent'
|
|
165
172
|
} : {},
|
|
@@ -274,7 +281,7 @@ var TextFieldBaseComponent = /*#__PURE__*/React.forwardRef(function (_ref14, ref
|
|
|
274
281
|
var hasLabel = !!label || !rest.required; // this shrinkLabel override is a workaround because I was unable to find a way to hide date
|
|
275
282
|
// and date-time native placeholders when the input is not required
|
|
276
283
|
|
|
277
|
-
var shrinkLabel = shrinkLabelProp || (rest.type === 'date' || rest.type === 'datetime-local') && !rest.required;
|
|
284
|
+
var shrinkLabel = shrinkLabelProp || (rest.type === 'date' || rest.type === 'datetime-local' || rest.type === 'month') && !rest.required;
|
|
278
285
|
var classes = useStyles({
|
|
279
286
|
inputState: inputState,
|
|
280
287
|
error: error,
|
package/dist-es/theme.js
CHANGED
|
@@ -34,7 +34,8 @@ var TEXTS_ES = {
|
|
|
34
34
|
menuLabelSuffix: 'menú',
|
|
35
35
|
openNavigationMenu: 'Abrir menú de navegación',
|
|
36
36
|
closeNavigationMenu: 'Cerrar menú de navegación',
|
|
37
|
-
backNavigationBar: 'Atrás'
|
|
37
|
+
backNavigationBar: 'Atrás',
|
|
38
|
+
clearButton: 'Borrar'
|
|
38
39
|
};
|
|
39
40
|
var TEXTS_EN = {
|
|
40
41
|
expirationDatePlaceholder: 'MM/YY',
|
|
@@ -63,7 +64,8 @@ var TEXTS_EN = {
|
|
|
63
64
|
menuLabelSuffix: 'menu',
|
|
64
65
|
openNavigationMenu: 'Open navigation menu',
|
|
65
66
|
closeNavigationMenu: 'Close navigation menu',
|
|
66
|
-
backNavigationBar: 'Back'
|
|
67
|
+
backNavigationBar: 'Back',
|
|
68
|
+
clearButton: 'Clear'
|
|
67
69
|
};
|
|
68
70
|
var TEXTS_DE = {
|
|
69
71
|
expirationDatePlaceholder: 'MM/JJ',
|
|
@@ -92,7 +94,8 @@ var TEXTS_DE = {
|
|
|
92
94
|
menuLabelSuffix: 'Menü',
|
|
93
95
|
openNavigationMenu: 'Navigationsmenü öffnen',
|
|
94
96
|
closeNavigationMenu: 'Navigationsmenü schließen',
|
|
95
|
-
backNavigationBar: 'Zurück'
|
|
97
|
+
backNavigationBar: 'Zurück',
|
|
98
|
+
clearButton: 'Löschen'
|
|
96
99
|
};
|
|
97
100
|
var TEXTS_PT = {
|
|
98
101
|
expirationDatePlaceholder: 'MM/AA',
|
|
@@ -121,7 +124,8 @@ var TEXTS_PT = {
|
|
|
121
124
|
menuLabelSuffix: 'menu',
|
|
122
125
|
openNavigationMenu: 'Abrir menu de navegação',
|
|
123
126
|
closeNavigationMenu: 'Fechar menu de navegação',
|
|
124
|
-
backNavigationBar: 'Voltar'
|
|
127
|
+
backNavigationBar: 'Voltar',
|
|
128
|
+
clearButton: 'Apagar'
|
|
125
129
|
};
|
|
126
130
|
export var getTexts = function getTexts(locale) {
|
|
127
131
|
var lang = locale.toLocaleLowerCase().split(/[-_]/)[0];
|
package/dist-es/utils/time.js
CHANGED
|
@@ -4,6 +4,11 @@ export var getLocalDateString = function getLocalDateString(date) {
|
|
|
4
4
|
var dd = String(date.getDate()).padStart(2, '0');
|
|
5
5
|
return "".concat(yyyy, "-").concat(mm, "-").concat(dd);
|
|
6
6
|
};
|
|
7
|
+
export var getLocalYearMonthString = function getLocalYearMonthString(date) {
|
|
8
|
+
var yyyy = date.getFullYear();
|
|
9
|
+
var mm = String(date.getMonth() + 1).padStart(2, '0');
|
|
10
|
+
return "".concat(yyyy, "-").concat(mm);
|
|
11
|
+
};
|
|
7
12
|
export var getLocalDateTimeString = function getLocalDateTimeString(date) {
|
|
8
13
|
var h = String(date.getHours()).padStart(2, '0');
|
|
9
14
|
var m = String(date.getMinutes()).padStart(2, '0');
|