diginet-core-ui 1.4.63 → 1.4.64
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/components/form-control/date-input/DateField.js +1 -1
- package/components/form-control/date-input/index.js +21 -2
- package/components/form-control/date-input/utils.js +1 -1
- package/components/form-control/date-picker/index.js +13 -4
- package/icons/basic.js +31 -0
- package/package.json +1 -1
- package/readme.md +3 -0
- package/utils/date.js +10 -0
|
@@ -158,7 +158,7 @@ export const useDateField = (format, localize, date) => {
|
|
|
158
158
|
minute,
|
|
159
159
|
second
|
|
160
160
|
} = dateField;
|
|
161
|
-
const date = new Date(year || 0, typeof month === 'number' ? month - 1 : 0,
|
|
161
|
+
const date = new Date(year || 0, typeof month === 'number' ? Math.max(0, month - 1) : 0,
|
|
162
162
|
// The default day is 1 when the value is null, otherwise it becomes the last day of the month.
|
|
163
163
|
day || 1, hour || 0, minute || 0, second || 0);
|
|
164
164
|
if (typeof type === 'undefined' || typeof value === 'undefined') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
+
import { useEffect } from 'react';
|
|
3
4
|
import { css, jsx } from '@emotion/core';
|
|
4
5
|
import { HelperText, Label } from "../..";
|
|
5
6
|
import { getGlobal } from "../../../global";
|
|
@@ -8,12 +9,19 @@ import PropTypes from 'prop-types';
|
|
|
8
9
|
import { forwardRef, memo, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
9
10
|
import { cursorNotAllowed, displayBlock, positionRelative } from "../../../styles/general";
|
|
10
11
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
11
|
-
import { classNames, refType as ref, useControlled } from "../../../utils";
|
|
12
|
+
import { classNames, refType as ref, useControlled, parseDateByFormat } from "../../../utils";
|
|
12
13
|
import UncontrolledInputBase from "../input-base/UncontrolledInputBase";
|
|
13
14
|
import useDateInputState from "./useDateInputState";
|
|
14
15
|
import useIsFocused from "./useIsFocused";
|
|
15
16
|
import useKeyboardInputEvent from "./useKeyboardInputEvent";
|
|
16
17
|
import { getInputSelectedState, isFieldFullValue, useEventCallback, useInputSelection, validateDateTime } from "./utils";
|
|
18
|
+
const usePrevious = value => {
|
|
19
|
+
const ref = useRef();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
ref.current = value;
|
|
22
|
+
}, [value]);
|
|
23
|
+
return ref.current;
|
|
24
|
+
};
|
|
17
25
|
const DateInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
18
26
|
if (!reference) reference = useRef(null);
|
|
19
27
|
|
|
@@ -57,6 +65,7 @@ const DateInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference
|
|
|
57
65
|
selectionStart: 0,
|
|
58
66
|
selectionEnd: 0
|
|
59
67
|
});
|
|
68
|
+
const selectedStateOld = usePrevious(selectedState) || {};
|
|
60
69
|
const isError = !!error;
|
|
61
70
|
const isEnabled = !readOnly && !disabled;
|
|
62
71
|
useImperativeHandle(reference, () => {
|
|
@@ -124,15 +133,25 @@ const DateInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference
|
|
|
124
133
|
setSelectionRange(state.selectionStart, state.selectionEnd);
|
|
125
134
|
});
|
|
126
135
|
const onSegmentValueChangeWithNumericKeys = useEventCallback(event => {
|
|
136
|
+
var _inputRef$current;
|
|
127
137
|
const input = event.target;
|
|
128
138
|
const key = event.key;
|
|
129
139
|
const pattern = selectedState.selectedPattern;
|
|
130
140
|
if (!pattern) {
|
|
131
141
|
return;
|
|
132
142
|
}
|
|
143
|
+
const displayDate = ((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) || '';
|
|
144
|
+
const dataDisplayVal = parseDateByFormat(displayDate, formatStr) || [];
|
|
145
|
+
const patternName = Object.keys(dataDisplayVal).find(name => name.includes(pattern));
|
|
146
|
+
const valDisplay = (dataDisplayVal === null || dataDisplayVal === void 0 ? void 0 : dataDisplayVal[patternName]) || '';
|
|
133
147
|
const field = getDateField(pattern);
|
|
134
148
|
const value = parseInt(key, 10);
|
|
135
|
-
|
|
149
|
+
// * If Date or Month ['DD', 'MM'];
|
|
150
|
+
// * If current display value has two number and first num is 0
|
|
151
|
+
// * If current value !== 0
|
|
152
|
+
// * And Already finish text month or date
|
|
153
|
+
// ===> Not chain the previous num
|
|
154
|
+
const padValue = ['DD', 'MM'].includes(patternName) && valDisplay.length === 2 && valDisplay[0] === '0' && key !== 0 && (selectedStateOld.selectedPattern || '').toUpperCase() !== pattern ? Number(key) : parseInt(`${field.value || ''}${key}`, 10);
|
|
136
155
|
let newValue = value;
|
|
137
156
|
|
|
138
157
|
// Check if the value entered by the user is a valid date
|
|
@@ -217,7 +217,7 @@ export const modifyDate = (date, type, value) => {
|
|
|
217
217
|
case 'year':
|
|
218
218
|
return setYear(date, value);
|
|
219
219
|
case 'month':
|
|
220
|
-
return setMonth(date, value - 1);
|
|
220
|
+
return setMonth(date, Math.max(0, value - 1));
|
|
221
221
|
case 'day':
|
|
222
222
|
return setDate(date, value);
|
|
223
223
|
case 'hour':
|
|
@@ -106,19 +106,24 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
106
106
|
value: valueProp,
|
|
107
107
|
viewType,
|
|
108
108
|
onBlur,
|
|
109
|
+
delayOnChange: delayOnChangeProp,
|
|
109
110
|
...other
|
|
110
111
|
} = props;
|
|
111
112
|
const dateLocale = locale.get();
|
|
112
113
|
const displayFormat = (_getDateFormats = getDateFormats(dateLocale, minZoom)) !== null && _getDateFormats !== void 0 ? _getDateFormats : displayFormatProp;
|
|
113
114
|
const returnFormat = (_pickerReturnFormat$g = pickerReturnFormat.get(minZoom)) !== null && _pickerReturnFormat$g !== void 0 ? _pickerReturnFormat$g : returnFormatProp;
|
|
114
115
|
const placeholder = placeholderProp !== null && placeholderProp !== void 0 ? placeholderProp : displayFormat;
|
|
116
|
+
const renderDateInputCondition = useDateInput && minZoom !== 'quarter' && !min && !max || true;
|
|
117
|
+
const delayOnChange = delayOnChangeProp || renderDateInputCondition ? typeof delayOnChangeProp === 'number' ? delayOnChangeProp : getGlobal('delayOnInput') : 0;
|
|
115
118
|
const [value, setValue] = useControlled(parseValueToDate(valueProp), parseValueToDate(defaultValue));
|
|
116
119
|
const [openPickerState, setOpenPickerState] = useState(false);
|
|
120
|
+
const defaultVal = useRef(valueProp);
|
|
117
121
|
const ipRef = useRef(null);
|
|
118
122
|
const ref = useRef(null);
|
|
119
123
|
const focusedValue = useRef(null);
|
|
120
124
|
const pickerRef = useRef(null);
|
|
121
125
|
const buttonCarlendarRef = useRef(null);
|
|
126
|
+
const timer = useRef(null);
|
|
122
127
|
const isError = !!error && (!value || !isValid(value));
|
|
123
128
|
const _DatePickerRoot = DatePickerRoot();
|
|
124
129
|
const _IconAreaCSS = IconAreaCSS();
|
|
@@ -140,9 +145,12 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
140
145
|
const vl = (e === null || e === void 0 ? void 0 : e.value) || e;
|
|
141
146
|
closePicker();
|
|
142
147
|
setValue(vl);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
if (timer.current) clearTimeout(timer.current);
|
|
149
|
+
timer.current = setTimeout(() => {
|
|
150
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
151
|
+
value: isValid(vl) ? formatValue(vl, returnFormat) : String(vl) === 'Invalid Date' ? defaultVal.current : vl
|
|
152
|
+
});
|
|
153
|
+
}, delayOnChange);
|
|
146
154
|
};
|
|
147
155
|
const onCalendarClick = e => {
|
|
148
156
|
!controls ? onChangeValue(e) : focusedValue.current = e === null || e === void 0 ? void 0 : e.value;
|
|
@@ -224,7 +232,6 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
224
232
|
return null;
|
|
225
233
|
} else return parse(value, lowerCaseDayYear(returnFormat), new Date());
|
|
226
234
|
}, [value]);
|
|
227
|
-
const renderDateInputCondition = useDateInput && minZoom !== 'quarter' && !min && !max || true;
|
|
228
235
|
return jsx(Fragment, null, jsx("div", {
|
|
229
236
|
ref: ref,
|
|
230
237
|
css: _DatePickerRoot,
|
|
@@ -339,6 +346,8 @@ DatePicker.propTypes = {
|
|
|
339
346
|
controls: PropTypes.bool,
|
|
340
347
|
/** The default value of the component. */
|
|
341
348
|
defaultValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.object]),
|
|
349
|
+
/** The number of milliseconds to wait before call onChange. */
|
|
350
|
+
delayOnChange: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
|
|
342
351
|
/** If `true`, the form control will be disabled. */
|
|
343
352
|
disabled: PropTypes.bool,
|
|
344
353
|
/** Format to display value. */
|
package/icons/basic.js
CHANGED
|
@@ -1182,6 +1182,37 @@ export const Block = /*#__PURE__*/memo(({
|
|
|
1182
1182
|
fill: fillColor(color)
|
|
1183
1183
|
}));
|
|
1184
1184
|
});
|
|
1185
|
+
export const BloodMinus = /*#__PURE__*/memo(({
|
|
1186
|
+
width,
|
|
1187
|
+
height,
|
|
1188
|
+
color = 'system/rest',
|
|
1189
|
+
viewBox = false
|
|
1190
|
+
}) => {
|
|
1191
|
+
if (viewBox) {
|
|
1192
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
1193
|
+
width: width || 24,
|
|
1194
|
+
height: height || 24,
|
|
1195
|
+
viewBox: "0 0 24 24",
|
|
1196
|
+
fill: "none"
|
|
1197
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
1198
|
+
fillRule: "evenodd",
|
|
1199
|
+
clipRule: "evenodd",
|
|
1200
|
+
d: "M6.64325 19.2933C5.21442 17.8221 4.5 15.9911 4.5 13.8001C4.5 12.2487 5.12083 10.5484 6.3625 8.69905C7.60417 6.84972 9.48333 4.83472 12 2.65405C14.5167 4.83472 16.3958 6.84972 17.6375 8.69905C18.8792 10.5484 19.5 12.2487 19.5 13.8001C19.5 15.9911 18.785 17.8221 17.355 19.2933C15.925 20.7645 14.1394 21.5001 11.9983 21.5001C9.85708 21.5001 8.07208 20.7645 6.64325 19.2933ZM8 15H16V13H8V15Z",
|
|
1201
|
+
fill: fillColor(color)
|
|
1202
|
+
}));
|
|
1203
|
+
}
|
|
1204
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
1205
|
+
width: width || 15,
|
|
1206
|
+
height: height || 19,
|
|
1207
|
+
viewBox: "0 0 15 19",
|
|
1208
|
+
fill: "none"
|
|
1209
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
1210
|
+
fillRule: "evenodd",
|
|
1211
|
+
clipRule: "evenodd",
|
|
1212
|
+
d: "M2.14325 16.6392C0.714417 15.1681 0 13.337 0 11.146C0 9.59467 0.620833 7.89433 1.8625 6.045C3.10417 4.19567 4.98333 2.18067 7.5 0C10.0167 2.18067 11.8958 4.19567 13.1375 6.045C14.3792 7.89433 15 9.59467 15 11.146C15 13.337 14.285 15.1681 12.855 16.6392C11.425 18.1104 9.63942 18.846 7.49825 18.846C5.35708 18.846 3.57208 18.1104 2.14325 16.6392ZM3.5 12.3459H11.5V10.3459H3.5V12.3459Z",
|
|
1213
|
+
fill: fillColor(color)
|
|
1214
|
+
}));
|
|
1215
|
+
});
|
|
1185
1216
|
export const Cake = /*#__PURE__*/memo(({
|
|
1186
1217
|
width,
|
|
1187
1218
|
height,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -41,6 +41,9 @@ npm test
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
## Changelog
|
|
44
|
+
## 1.4.64
|
|
45
|
+
- \[Added\]: Icon – Add Icon BloodMinus
|
|
46
|
+
- \[Changed\]: DatePicker - Allow manual input for the DatePicker (default value shows "Invalid Date" when typing) + add a "delayOnChange" prop.
|
|
44
47
|
|
|
45
48
|
## 1.4.63
|
|
46
49
|
- \[Added\]: Icon – Add IconMenu MHRP39N0029
|
package/utils/date.js
CHANGED
|
@@ -398,4 +398,14 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
|
|
|
398
398
|
relative
|
|
399
399
|
};
|
|
400
400
|
};
|
|
401
|
+
export const parseDateByFormat = (dateStr, format) => {
|
|
402
|
+
const separators = /[-/]/;
|
|
403
|
+
const dateParts = dateStr.split(separators);
|
|
404
|
+
const formatParts = format.split(separators);
|
|
405
|
+
const result = {};
|
|
406
|
+
formatParts.forEach((part, index) => {
|
|
407
|
+
result[part] = dateParts[index] === part ? '' : dateParts[index];
|
|
408
|
+
});
|
|
409
|
+
return result;
|
|
410
|
+
};
|
|
401
411
|
export default date;
|