diginet-core-ui 1.4.63 → 1.4.64-beta.2

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.
@@ -0,0 +1,16 @@
1
+ <svg width="39" height="39" viewBox="0 0 39 39" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_2545_43)">
3
+ <path d="M13.9 11.6C14 11.6 14.1 11.5 14.2 11.4L14.6 9.4C14.6 9.3 14.6 9.1 14.4 9.1L13 8.7C12.9 8.4 12.8 8.1 12.7 7.8L13.4 6.6C13.5 6.5 13.4 6.4 13.3 6.3L11.7 5C11.6 4.9 11.5 4.9 11.4 5L10.4 5.9C10.1 5.8 9.7 5.7 9.4 5.7L8.8 4.4C8.7 4.3 8.6 4.2 8.5 4.3L6.5 5C6.4 5 6.3 5.2 6.4 5.3L6.7 6.7C6.5 6.7 6.4 6.9 6.3 7C6.2 7.1 6.1 7.3 6 7.4L4.6 7.3C4.5 7.3 4.4 7.4 4.3 7.5L4 9.6C4 9.7 4 9.9 4.2 9.9L5.5 10.3C5.6 10.6 5.7 10.9 5.8 11.2L5.1 12.4C5 12.5 5.1 12.6 5.2 12.7L6.8 14C6.9 14.1 7 14.1 7.1 14L8.1 13.1C8.4 13.2 8.8 13.3 9.1 13.3L9.7 14.5C9.8 14.6 9.9 14.7 10 14.6L12 14C12.1 14 12.2 13.8 12.2 13.7L11.9 12.3C12 12.2 12.1 12.1 12.3 11.9C12.4 11.8 12.5 11.6 12.6 11.5L13.9 11.6ZM10.7 10.7C10 11.5 8.8 11.6 8 11C7.2 10.3 7.1 9 7.8 8.2C8.5 7.4 9.7 7.3 10.5 8C11.3 8.7 11.4 9.9 10.7 10.7Z" fill="#FF8C00" style="fill:#FF8C00;fill:color(display-p3 1.0000 0.5490 0.0000);fill-opacity:1;"/>
4
+ <path d="M17.7 12.4C17.7 12.3 17.7 12.3 17.6 12.2L16.2 12C16.1 12 16 12 16 12.1L15.7 12.9C15.5 12.9 15.3 13 15.1 13.1L14.4 12.6C14.3 12.6 14.2 12.6 14.2 12.6L13.4 13.6C13.3 13.7 13.3 13.7 13.4 13.8L14 14.5C13.9 14.7 13.9 14.9 13.9 15.1L13.1 15.5C13 15.5 13 15.6 13 15.7L13.4 16.9C13.4 17 13.5 17 13.6 17L14.5 16.8C14.6 16.9 14.6 17 14.7 17C14.8 17 14.9 17.1 15 17.2V18.1C15 18.2 15.1 18.3 15.1 18.3L16.4 18.5C16.5 18.5 16.6 18.5 16.6 18.4L16.9 17.6C17.1 17.6 17.3 17.5 17.5 17.4L18.2 17.9C18.3 17.9 18.4 17.9 18.4 17.9L19.2 16.9C19.3 16.8 19.3 16.7 19.2 16.7L18.6 16C18.7 15.8 18.7 15.6 18.7 15.4L19.5 15C19.6 15 19.6 14.9 19.6 14.8L19.2 13.6C19.2 13.5 19.1 13.5 19 13.5L18.1 13.7C18 13.6 18 13.5 17.9 13.5C17.8 13.4 17.7 13.4 17.6 13.3L17.7 12.4ZM17.1 14.4C17.6 14.8 17.7 15.6 17.2 16.1C16.8 16.6 16 16.7 15.5 16.2C15 15.8 14.9 15 15.4 14.5C15.8 14 16.6 14 17.1 14.4Z" fill="#FF8C00" style="fill:#FF8C00;fill:color(display-p3 1.0000 0.5490 0.0000);fill-opacity:1;"/>
5
+ <path d="M29.4 9.5L20.3 0.4C20 0.1 19.7 0 19.4 0H3.4C1.5 0 0 1.5 0 3.4V35.5C0 37.5 1.5 39 3.4 39H25.6C24.4 38.4 23.4 37.7 22.5 36.7H3.4C2.8 36.7 2.3 36.2 2.3 35.6V3.4C2.3 2.8 2.8 2.3 3.4 2.3H18.3V8C18.3 9.9 19.8 11.4 21.7 11.4H27.4V20.3C28.1 20.1 28.9 20 29.7 20V10.3C29.7 10 29.6 9.7 29.4 9.5ZM21.7 9.1C21.1 9.1 20.6 8.6 20.6 8V3.9L25.8 9.1H21.7Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
6
+ <path d="M21.7 20.7H8C7.4 20.7 6.9 21.2 6.9 21.8C6.9 22.5 7.4 23 8 23H21.7C22.3 23 22.8 22.5 22.8 21.9C22.9 21.2 22.3 20.7 21.7 20.7Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
7
+ <path d="M21.2 25.3C20.8 26 20.5 26.8 20.3 27.6H8C7.4 27.6 6.9 27.1 6.9 26.5C6.9 25.9 7.4 25.4 8 25.4H21.2V25.3Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
8
+ <path d="M17.1 29.9H8C7.4 29.9 6.9 30.4 6.9 31C6.9 31.6 7.4 32.1 8 32.1H17.1C17.7 32.1 18.2 31.6 18.2 31C18.2 30.4 17.8 29.9 17.1 29.9Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
9
+ <path d="M30 21C25 21 21 25 21 30C21 35 25 39 30 39C35 39 39 35 39 30C39 25 35 21 30 21ZM35.6 27.1L30.3 34.3C30 34.8 29.5 35 29 35C28.5 35 28 34.8 27.6 34.4L24.5 31C24 30.5 24 29.6 24.6 29.1C25.1 28.6 26 28.6 26.5 29.2L28.7 31.6L28.8 31.7C28.8 31.7 28.9 31.7 28.9 31.6L33.4 25.5C33.8 24.9 34.7 24.8 35.3 25.2C35.9 25.7 36 26.5 35.6 27.1Z" fill="#1CA261" style="fill:#1CA261;fill:color(display-p3 0.1098 0.6353 0.3804);fill-opacity:1;"/>
10
+ </g>
11
+ <defs>
12
+ <clipPath id="clip0_2545_43">
13
+ <rect width="39" height="39" fill="white" style="fill:white;fill-opacity:1;"/>
14
+ </clipPath>
15
+ </defs>
16
+ </svg>
@@ -0,0 +1,15 @@
1
+ <svg width="39" height="39" viewBox="0 0 39 39" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_2545_24)">
3
+ <path d="M38.7 9.5L29.5 0.4C29.3 0.1 29 0 28.7 0H12.7C10.8 0 9.29999 1.5 9.29999 3.4V9.5C9.39999 9.5 9.49999 9.5 9.59999 9.6L11.6 10.3V3.4C11.6 2.8 12.1 2.3 12.7 2.3H27.5V8C27.5 9.9 29 11.4 30.9 11.4H36.6V35.5C36.6 36.1 36.1 36.6 35.5 36.6H12.7C12.1 36.6 11.6 36.1 11.6 35.5V26.5C11.3 26.5 11.1 26.4 10.8 26.2L9.59999 25.1C9.49999 25.1 9.39999 25.2 9.29999 25.2V35.5C9.29999 37.4 10.8 38.9 12.7 38.9H35.5C37.4 38.9 38.9 37.4 38.9 35.5V10.3C39 10 38.9 9.7 38.7 9.5ZM31 9.1C30.4 9.1 29.9 8.6 29.9 8V3.9L35.1 9.1H31Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
4
+ <path d="M31 20.7H17.3C16.7 20.7 16.2 21.2 16.2 21.8C16.2 22.4 16.7 22.9 17.3 22.9H31C31.6 22.9 32.1 22.4 32.1 21.8C32.1 21.2 31.6 20.7 31 20.7Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
5
+ <path d="M31 25.3H17.3C16.7 25.3 16.2 25.8 16.2 26.4C16.2 27 16.7 27.5 17.3 27.5H31C31.6 27.5 32.1 27 32.1 26.4C32.1 25.8 31.6 25.3 31 25.3Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
6
+ <path d="M26.4 29.9H17.3C16.7 29.9 16.2 30.4 16.2 31C16.2 31.6 16.7 32.1 17.3 32.1H26.4C27 32.1 27.5 31.6 27.5 31C27.5 30.4 27 29.9 26.4 29.9Z" fill="#2680EB" style="fill:#2680EB;fill:color(display-p3 0.1490 0.5020 0.9216);fill-opacity:1;"/>
7
+ <path d="M13 15.3C12.9 15.1 12.7 14.9 12.5 14.7C12.3 14.5 12.1 14.3 12 14.1L12.4 12C12.4 11.8 12.3 11.6 12.2 11.6L9.2 10.5C9 10.4 8.8 10.5 8.7 10.7L7.7 12.6C7.2 12.6 6.7 12.7 6.2 12.9L4.6 11.5C4.4 11.4 4.2 11.4 4.1 11.5L1.7 13.5C1.5 13.6 1.5 13.8 1.6 14L2.7 15.8C2.5 16.3 2.3 16.8 2.2 17.3L0.2 18C0.1 17.9 0 18.1 0 18.3L0.6 21.4C0.6 21.6 0.8 21.7 1 21.7L3.1 21.6C3.2 21.8 3.4 22 3.5 22.2C3.6 22.4 3.9 22.6 4 22.8L3.6 24.9C3.6 25.1 3.7 25.3 3.8 25.3L6.8 26.4C7 26.5 7.2 26.4 7.3 26.2L8.3 24.3C8.8 24.3 9.3 24.2 9.8 24L11.4 25.4C11.6 25.5 11.8 25.5 11.9 25.4L14.3 23.4C14.5 23.3 14.5 23.1 14.4 22.9L13.3 21.1C13.5 20.6 13.7 20.1 13.8 19.6L15.8 18.9C16 18.8 16.1 18.7 16.1 18.4L15.5 15.3C15.5 15.1 15.3 15 15.1 15L13 15.3ZM10 20.7C8.8 21.8 6.9 21.6 5.8 20.4C4.7 19.2 4.9 17.3 6.1 16.2C7.3 15.1 9.2 15.3 10.3 16.5C11.4 17.7 11.2 19.7 10 20.7Z" fill="#FF8C00" style="fill:#FF8C00;fill:color(display-p3 1.0000 0.5490 0.0000);fill-opacity:1;"/>
8
+ <path d="M20 13.3C20.1 13.2 20.3 13.1 20.4 13C20.5 12.9 20.6 12.8 20.8 12.7L22.1 13C22.2 13 22.3 13 22.4 12.8L23.1 10.9C23.1 10.8 23.1 10.7 23 10.6L21.8 10C21.8 9.7 21.7 9.4 21.6 9L22.5 8C22.6 7.9 22.6 7.8 22.5 7.7L21.2 6.2C21 6 20.9 6 20.8 6.1L19.7 6.8C19.4 6.6 19.1 6.5 18.8 6.5L18.4 5.2C18.3 5.1 18.1 5 18 5L16 5.4C15.9 5.4 15.8 5.5 15.8 5.7L15.9 7C15.8 7.1 15.6 7.2 15.5 7.3C15.4 7.4 15.3 7.5 15.1 7.6L13.8 7.3C13.7 7.3 13.6 7.3 13.5 7.5L12.8 9.4C12.8 9.5 12.8 9.6 12.9 9.7L14.1 10.3C14.1 10.6 14.2 10.9 14.3 11.3L13.4 12.3C13.3 12.4 13.3 12.5 13.4 12.6L14.7 14.1C14.8 14.2 14.9 14.2 15 14.1L16.1 13.4C16.4 13.6 16.7 13.7 17 13.7L17.4 15C17.4 15.1 17.6 15.2 17.7 15.2L19.7 14.8C19.8 14.8 19.9 14.7 19.9 14.5L20 13.3ZM16.5 11.3C15.8 10.5 15.9 9.3 16.7 8.7C17.5 8 18.7 8.1 19.3 8.9C19.9 9.7 19.9 10.9 19.1 11.5C18.3 12.1 17.2 12.1 16.5 11.3Z" fill="#FF8C00" style="fill:#FF8C00;fill:color(display-p3 1.0000 0.5490 0.0000);fill-opacity:1;"/>
9
+ </g>
10
+ <defs>
11
+ <clipPath id="clip0_2545_24">
12
+ <rect width="39" height="39" fill="white" style="fill:white;fill-opacity:1;"/>
13
+ </clipPath>
14
+ </defs>
15
+ </svg>
@@ -652,7 +652,7 @@ const renderNavigator = (className, refs, dbLeftFn, leftFn, rightFn, dbRightFn,
652
652
  color: 'primary',
653
653
  type: 'h3',
654
654
  ref: refs.content,
655
- format: ['lowercase']
655
+ format: ['sentence']
656
656
  }))), jsx("div", {
657
657
  className: className.navigator.around
658
658
  }, jsx(ButtonIcon, {
@@ -226,7 +226,7 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
226
226
  * START EFFECT
227
227
  */
228
228
  useEffect(() => {
229
- if (defaultValue && defaultValue !== '' && isValidDate(defaultValue)) {
229
+ if (defaultValue && defaultValue !== '' && isValidDate(defaultValue) && !value) {
230
230
  if (isBeforeLimit(min, defaultValue)) {
231
231
  onUpdate(min);
232
232
  } else if (isAfterLimit(max, defaultValue)) {
@@ -41,8 +41,8 @@ export class DateField {
41
41
  }
42
42
  }
43
43
 
44
- /**
45
- * Pad a number with zeros to the left.
44
+ /**
45
+ * Pad a number with zeros to the left.
46
46
  */
47
47
  const padNumber = (number, length) => {
48
48
  let numberString = String(number);
@@ -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
- const padValue = parseInt(`${field.value || ''}${key}`, 10);
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
@@ -1,9 +1,9 @@
1
1
  import { isValid, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setYear } from 'date-fns';
2
2
  import { useCallback, useEffect, useRef } from 'react';
3
3
 
4
- /**
5
- * https://github.com/facebook/react/issues/14099#issuecomment-440013892
6
- * @param {function} fn
4
+ /**
5
+ * https://github.com/facebook/react/issues/14099#issuecomment-440013892
6
+ * @param {function} fn
7
7
  */
8
8
  export const useEventCallback = fn => {
9
9
  const ref = useRef(fn);
@@ -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
- onChange === null || onChange === void 0 ? void 0 : onChange({
144
- value: isValid(vl) ? formatValue(vl, returnFormat) : String(vl) === 'Invalid Date' ? 'Invalid Date' : vl
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. */
@@ -752,6 +752,7 @@ const DateRangePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, ref
752
752
  }
753
753
  ipRef.current && ipRef.current.blur();
754
754
  updateTempValues([]);
755
+ setOpenState(false);
755
756
  };
756
757
  const onClickOutside = e => {
757
758
  if (ipConRef.current && !ipConRef.current.contains(e.target) && ipRef.current && !ipRef.current.contains(e.target) && pickerRef.current && !pickerRef.current.contains(e.target)) {
@@ -1,13 +1,15 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
3
  import { css, jsx } from '@emotion/core';
4
- import { ButtonIcon, InputBase, Label, Popover, PopoverBody } from "../..";
4
+ import { ButtonIcon, InputBase, Label, Popover, PopoverBody, HelperText } from "../..";
5
5
  import PropTypes from 'prop-types';
6
- import { Fragment, forwardRef, memo, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
6
+ import { Fragment, forwardRef, memo, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, useMemo } from 'react';
7
7
  import { animation, borderColor, displayBlock, overflowHidden, parseHeight, parseMinWidth, positionRelative, scaleX } from "../../../styles/general";
8
8
  import { useTheme } from "../../../theme";
9
9
  import useThemeProps from "../../../theme/utils/useThemeProps";
10
10
  import { classNames, getProp } from "../../../utils";
11
+ const regexBetween = /[^{}]+(?=})/g;
12
+ const regexInclude = /{|}/g;
11
13
  const DropdownBox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
12
14
  if (!reference) reference = useRef(null);
13
15
  const theme = useTheme();
@@ -22,10 +24,14 @@ const DropdownBox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referen
22
24
  });
23
25
  const {
24
26
  action = {},
27
+ allowInput,
25
28
  bgColor: bgColorProp,
26
29
  children,
27
30
  className,
28
31
  delayOnInput,
32
+ disabled,
33
+ displayExpr: displayExprProp,
34
+ error,
29
35
  endIcon,
30
36
  inputProps,
31
37
  inputRef,
@@ -39,10 +45,19 @@ const DropdownBox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referen
39
45
  placeholder,
40
46
  startIcon,
41
47
  style,
42
- value,
43
- viewType
48
+ value: valueProps,
49
+ valueExpr,
50
+ viewType,
51
+ helperTextProps
44
52
  } = props;
53
+ let displayExpr = displayExprProp;
45
54
  const bgColor = typeof bgColorProp === 'string' ? getProp(colors, bgColorProp, bgColorProp) : bgColorProp;
55
+ const ErrorView = useMemo(() => {
56
+ return error ? jsx(HelperText, {
57
+ ...helperTextProps,
58
+ disabled: disabled
59
+ }, error) : null;
60
+ }, [disabled, error, helperTextProps]);
46
61
  const ref = useRef(null);
47
62
  const dropdownBoxRef = useRef(null);
48
63
  const timer = useRef(null);
@@ -85,6 +100,28 @@ const DropdownBox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referen
85
100
  onClosed === null || onClosed === void 0 ? void 0 : onClosed();
86
101
  }
87
102
  };
103
+
104
+ /**
105
+ * Chuyển đổi data thành giá trị cần hiện thị dựa vào displayExpr [string, string object {field} - {field}], renderSelectedItem, displayExpr, valueExpr
106
+ * @param data {object} rowData of dataSource
107
+ * @return {string}
108
+ */
109
+ const displayValue = data => {
110
+ let text = '';
111
+ if (data || data === 0) {
112
+ displayExpr = displayExpr || valueExpr;
113
+ let mask = data === null || data === void 0 ? void 0 : data[displayExpr];
114
+ // convert {id} - {name} to {<data[id]>} - {<data[name]>}
115
+ if (!mask && regexBetween.test(displayExpr)) {
116
+ var _displayExpr;
117
+ mask = (_displayExpr = displayExpr) === null || _displayExpr === void 0 ? void 0 : _displayExpr.replace(regexBetween, _ => (data === null || data === void 0 ? void 0 : data[_]) || '');
118
+ } else if (!mask) {
119
+ mask = typeof data !== 'object' ? data : '';
120
+ }
121
+ text = mask.toString().replace(regexInclude, '');
122
+ }
123
+ return text;
124
+ };
88
125
  useLayoutEffect(() => {
89
126
  if (ref.current) {
90
127
  const {
@@ -130,15 +167,17 @@ const DropdownBox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referen
130
167
  onClick: openOnClickAt === 'icon' ? onTriggerDropdown : null
131
168
  }) : null;
132
169
  };
170
+ const value = displayValue(valueProps);
133
171
  return jsx(Fragment, null, jsx("div", {
134
172
  ref: ref,
135
173
  css: _DropdownBoxRootCSS,
136
- className: classNames('DGN-UI-Dropdown-Box', className),
174
+ className: classNames('DGN-UI-Dropdown-Box', className, error && 'error'),
137
175
  style: style
138
176
  }, label ? jsx(Label, {
139
177
  ...labelProps
140
178
  }, label) : null, jsx(InputBase, {
141
179
  ...inputProps,
180
+ readOnly: !allowInput,
142
181
  style: inputStyle,
143
182
  viewType: viewType,
144
183
  inputRef: inputRef,
@@ -157,7 +196,7 @@ const DropdownBox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referen
157
196
  anchor: ref.current,
158
197
  width: popoverWidth,
159
198
  onClose: closeDropdownBox
160
- }, jsx(PopoverBody, null, children)));
199
+ }, jsx(PopoverBody, null, children)), ErrorView);
161
200
  }));
162
201
  const DropdownBoxRootCSS = (bgColorProp, {
163
202
  colors
@@ -166,6 +205,17 @@ const DropdownBoxRootCSS = (bgColorProp, {
166
205
  ${positionRelative};
167
206
  ${parseMinWidth(150)};
168
207
  ${parseHeight('max-content')};
208
+ &.error {
209
+ .DGN-UI-InputBase {
210
+ ${borderColor(getProp(colors, 'semantic/danger'))};
211
+ &::before {
212
+ ${borderColor(getProp(colors, 'semantic/danger'))};
213
+ }
214
+ &::after {
215
+ ${borderColor(getProp(colors, 'semantic/danger'))};
216
+ }
217
+ }
218
+ }
169
219
  .DGN-UI-InputBase {
170
220
  background: ${bgColorProp ? bgColorProp === true ? getProp(colors, 'fill/disabled') : bgColorProp : 'inherit'} !important;
171
221
  ${openState && css`
@@ -183,20 +233,6 @@ const DropdownBoxCSS = ({
183
233
  margin-top: ${spacing([1])};
184
234
  ${overflowHidden};
185
235
  `;
186
-
187
- // DropdownBox.defaultProps = {
188
- // className: '',
189
- // label: '',
190
- // placeholder: '',
191
- // startIcon: 'Search',
192
- // endIcon: 'ArrowDown',
193
- // openOnClickAt: 'icon',
194
- // viewType: 'underlined',
195
- // inputProps: {},
196
- // delayOnInput: 700,
197
- // zIndex: zIndexCORE(1),
198
- // };
199
-
200
236
  DropdownBox.propTypes = {
201
237
  /** class for dropdown */
202
238
  className: PropTypes.string,
@@ -233,6 +269,12 @@ DropdownBox.propTypes = {
233
269
  /** the function will run after open */
234
270
  onOpened: PropTypes.func,
235
271
  /** the function will run after close */
236
- onClosed: PropTypes.func
272
+ onClosed: PropTypes.func,
273
+ /** Error message displayed below the input. */
274
+ error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
275
+ /** If `true`, the component is disabled. */
276
+ disabled: PropTypes.bool,
277
+ /** If `true`, the input is enable. */
278
+ allowInput: PropTypes.bool
237
279
  };
238
280
  export default DropdownBox;
@@ -49,7 +49,7 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
49
49
  labelProps,
50
50
  max: maxProp,
51
51
  maxDigit,
52
- min,
52
+ min: minProp,
53
53
  nonStyle,
54
54
  onBlur,
55
55
  onChange,
@@ -69,9 +69,12 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
69
69
  viewType
70
70
  } = props;
71
71
  let max = maxProp;
72
+ let min = minProp;
72
73
  let thousandSymbol = thousandSeparator;
73
74
  let decimalSymbol = decimalSymbolProp;
74
75
  let valueProps = valueProp;
76
+ if (!min && min !== 0) min = -Infinity;
77
+ if (!max && max !== 0) max = Infinity;
75
78
  const pos = useRef(null);
76
79
  const ref = useRef(null);
77
80
  const globalRef = useRef({});
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,
@@ -4648,6 +4679,34 @@ export const OneSquare = /*#__PURE__*/memo(({
4648
4679
  fill: fillColor(color)
4649
4680
  }));
4650
4681
  });
4682
+ export const OpenNew = /*#__PURE__*/memo(({
4683
+ width,
4684
+ height,
4685
+ color = 'system/rest',
4686
+ viewBox = false
4687
+ }) => {
4688
+ return viewBox ? /*#__PURE__*/React.createElement("svg", {
4689
+ width: width || 24,
4690
+ height: height || 24,
4691
+ viewBox: "0 0 24 24",
4692
+ fill: "none"
4693
+ }, /*#__PURE__*/React.createElement("path", {
4694
+ fillRule: "evenodd",
4695
+ clipRule: "evenodd",
4696
+ d: "M12 3V5H5V19H19V12H21V19C21 20.1 20.1 21 19 21H5C3.89 21 3 20.1 3 19V5C3 3.9 3.89 3 5 3H12ZM21 3V10H19V6.41016L9.16992 16.2402L7.75977 14.8301L17.5898 5H14V3H21Z",
4697
+ fill: fillColor(color)
4698
+ })) : /*#__PURE__*/React.createElement("svg", {
4699
+ width: width || 18,
4700
+ height: height || 18,
4701
+ viewBox: "0 0 18 18",
4702
+ fill: "none"
4703
+ }, /*#__PURE__*/React.createElement("path", {
4704
+ fillRule: "evenodd",
4705
+ clipRule: "evenodd",
4706
+ d: "M9 0V2H2V16H16V9H18V16C18 17.1 17.1 18 16 18H2C0.89 18 0 17.1 0 16V2C0 0.9 0.89 0 2 0H9ZM18 0V7H16V3.41016L6.16992 13.2402L4.75977 11.8301L14.5898 2H11V0H18Z",
4707
+ fill: fillColor(color)
4708
+ }));
4709
+ });
4651
4710
  export const Undo = /*#__PURE__*/memo(({
4652
4711
  width,
4653
4712
  height,
package/package.json CHANGED
@@ -1,44 +1,78 @@
1
- {
2
- "name": "diginet-core-ui",
3
- "version": "1.4.63",
4
- "description": "The DigiNet core ui",
5
- "homepage": "https://diginet.com.vn",
6
- "main": "index.js",
7
- "scripts": {
8
- "start-js": "react-scripts start --max_old_space_size=4096",
9
- "start": "npx npm-run-all -p start-js",
10
- "build": "GENERATE_SOURCEMAP=false && react-scripts build --env=production --max_old_space_size=8192",
11
- "eject": "react-scripts eject",
12
- "test": "echo \"Error: no test specified\" && exit 1"
13
- },
14
- "dependencies": {
15
- "@emotion/core": "^10.0.35",
16
- "prop-types": "^15.7.2",
17
- "@emotion/css": "^11.11.0",
18
- "@emotion/react": "^11.10.6"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://diginetvn@bitbucket.org/diginetvn/diginet-core-ui.git"
23
- },
24
- "keywords": [
25
- "core ui",
26
- "diginet"
27
- ],
28
- "author": "rocachien",
29
- "contributors": [
30
- {
31
- "name": "Chien Do",
32
- "email": "rocachien@gmail.com"
33
- },
34
- {
35
- "name": "Nhat Tran",
36
- "email": "tranminhnhat1005@gmail.com"
37
- },
38
- {
39
- "name": "Thuan Nguyen",
40
- "email": "nt.thuan.hutech@gmail.com"
41
- }
42
- ],
43
- "license": "MIT"
44
- }
1
+ {
2
+ "name": "diginet-core-ui",
3
+ "version": "1.4.64-beta.2",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "license": "UNLICENSED",
7
+ "scripts": {
8
+ "start": "npm-run-all --parallel start-sb eslint-test",
9
+ "start-sb": "start-storybook -p 9050",
10
+ "build-storybook": "build-storybook -c .storybook -s src",
11
+ "build": "run-script-os",
12
+ "build:windows": "rimraf dist && mkdirp dist/components && npm run compile && sass --style=compressed src/scss:dist/css && xcopy src\\\\assets dist\\\\assets\\ /e /y",
13
+ "build:darwin:linux:default": "rm -rf dist && npm run compile && sass --style=compressed src/scss:dist/css && cp -rf src/assets dist/assets",
14
+ "compile": "babel src --out-dir dist --ignore **/*.stories.js",
15
+ "pack": "npm run build && cp *.md dist/ && npm run version:bump --silent && npm run version:add --silent && cd dist && npm pack",
16
+ "production-keep-version": "npm run build && cp *.md dist/ && cp package.json dist/ && cd dist && npm publish",
17
+ "beta": "npm run build && cp *.md dist/ && cp package.json dist/ && cd dist && npm publish --tag beta",
18
+ "production": "npm run build && cp *.md dist/ && npm run version:bump --silent && npm run version:add --silent && cd dist && npm publish",
19
+ "version:add": "run-script-os",
20
+ "version:add:windows": "cat package.json.tmp | sed \"s/0.0.0/%npm_package_version%/g\" > dist/package.json",
21
+ "version:add:darwin:linux:default": "VERSION=$(npm run version:extract --silent) && cat package.json.tmp | sed \"s/0.0.0/${VERSION}/g\" > dist/package.json",
22
+ "version:bump": "npm version patch --no-git-tag-version --silent",
23
+ "version:extract": "cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]'",
24
+ "test": "echo \"Error: no test specified\" && exit 1",
25
+ "lint": "eslint --fix --config .eslintrc.js \"**/*.js\"",
26
+ "eslint-test": "onchange \"src/**/*.{js,jsx,json}\" -- eslint . --fix",
27
+ "freshtall": "npm cache clean --force && rm -rf node_modules && rm -f package-lock.json && npm install",
28
+ "test-storybook": "test-storybook --url http://localhost:9050",
29
+ "preinstall": "echo {} > package-lock.json"
30
+ },
31
+ "dependencies": {
32
+ "@emotion/core": "^10.0.35",
33
+ "@emotion/css": "^11.11.0",
34
+ "@emotion/react": "^11.10.6",
35
+ "babel-plugin-module-resolver": "^4.1.0",
36
+ "date-fns": "^2.30.0",
37
+ "prop-types": "^15.7.2"
38
+ },
39
+ "lint-staged": {
40
+ "*/**/*.{js,jsx,json}": [
41
+ "prettier --write",
42
+ "git add"
43
+ ]
44
+ },
45
+ "devDependencies": {
46
+ "@babel/cli": "^7.14.3",
47
+ "@babel/plugin-proposal-class-properties": "^7.13.0",
48
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.16.0",
49
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
50
+ "@babel/plugin-proposal-optional-chaining": "^7.14.2",
51
+ "@babel/plugin-proposal-private-methods": "^7.18.6",
52
+ "@babel/plugin-proposal-private-property-in-object": "^7.18.6",
53
+ "@babel/preset-react": "^7.13.13",
54
+ "@storybook/addon-actions": "6.2.9",
55
+ "@storybook/addon-essentials": "6.2.9",
56
+ "@storybook/addon-links": "6.2.9",
57
+ "@storybook/addon-postcss": "^2.0.0",
58
+ "@storybook/react": "6.2.9",
59
+ "@storybook/test-runner": "^0.7.1",
60
+ "autoprefixer": "^10.3.1",
61
+ "babel-loader": "^8.2.2",
62
+ "eslint": "^8.4.1",
63
+ "eslint-plugin-react": "^7.27.1",
64
+ "eslint-plugin-regex": "^1.10.0",
65
+ "husky": "^7.0.4",
66
+ "jest": "^27.5.1",
67
+ "lint-staged": "^12.1.2",
68
+ "mkdirp": "^1.0.4",
69
+ "npm-run-all": "^4.1.5",
70
+ "onchange": "^7.1.0",
71
+ "postcss-flexbugs-fixes": "^5.0.2",
72
+ "react": "^17.0.1",
73
+ "react-dom": "^17.0.1",
74
+ "rimraf": "^3.0.2",
75
+ "run-script-os": "^1.1.6",
76
+ "sass": "1.58.3"
77
+ }
78
+ }
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
@@ -4,11 +4,11 @@ const language = locale.get();
4
4
  const localeName = language === 'en' ? 'en-US' : 'vi-VN';
5
5
  const units = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'];
6
6
 
7
- /**
8
- *
9
- * @param {Date|String|Array} value is a date time
10
- * @param {String} format the input date format
11
- * @param {Boolean} setNow return current time if true
7
+ /**
8
+ *
9
+ * @param {Date|String|Array} value is a date time
10
+ * @param {String} format the input date format
11
+ * @param {Boolean} setNow return current time if true
12
12
  */
13
13
  const getDate = (value, format = 'MM/DD/YYYY', setNow = true) => {
14
14
  if (value) {
@@ -52,11 +52,11 @@ const getMethodOfUnit = unit => {
52
52
  }
53
53
  };
54
54
 
55
- /**
56
- * check 1 value is a date
57
- * @param {Date|String|Array|Number} value the value to check
58
- * @param {String} formatInput the format date to check valid date
59
- * @returns {Boolean} valid date
55
+ /**
56
+ * check 1 value is a date
57
+ * @param {Date|String|Array|Number} value the value to check
58
+ * @param {String} formatInput the format date to check valid date
59
+ * @returns {Boolean} valid date
60
60
  */
61
61
  export const isValidDate = (value, formatInput) => {
62
62
  if (typeof value === 'string' || Array.isArray(value)) {
@@ -69,11 +69,11 @@ export const isValidDate = (value, formatInput) => {
69
69
  return false;
70
70
  };
71
71
 
72
- /**
73
- * get the end of month from month and year or from a date
74
- * @param {Number|String|Date|Array} month the month of year (can also be validated as year) or a value with date type
75
- * @param {Number} year the year (can also be validated as month if arg 1 is year)
76
- * @returns {Number} end day
72
+ /**
73
+ * get the end of month from month and year or from a date
74
+ * @param {Number|String|Date|Array} month the month of year (can also be validated as year) or a value with date type
75
+ * @param {Number} year the year (can also be validated as month if arg 1 is year)
76
+ * @returns {Number} end day
77
77
  */
78
78
  export const getEndDayOfMonth = (month, year) => {
79
79
  if (!year) {
@@ -92,11 +92,11 @@ export const getEndDayOfMonth = (month, year) => {
92
92
  return 'Invalid Date';
93
93
  };
94
94
 
95
- /**
96
- * return a date time follow the concrete format
97
- * @param {Date|String|Array} value is a date time
98
- * @param {String} formatOutput format of date
99
- * @param {Boolean} utc is utc time
95
+ /**
96
+ * return a date time follow the concrete format
97
+ * @param {Date|String|Array} value is a date time
98
+ * @param {String} formatOutput format of date
99
+ * @param {Boolean} utc is utc time
100
100
  */
101
101
  export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
102
102
  if (!value) return formatOutput;
@@ -232,21 +232,21 @@ export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
232
232
  }
233
233
  };
234
234
 
235
- /**
236
- * return a date like moment
237
- * @param {Date|String|Array} value is date time
238
- * @param {String} formatInput format of input date value
239
- * @returns {Object} date
235
+ /**
236
+ * return a date like moment
237
+ * @param {Date|String|Array} value is date time
238
+ * @param {String} formatInput format of input date value
239
+ * @returns {Object} date
240
240
  */
241
241
  const date = (value, formatInput = 'MM/DD/YYYY') => {
242
242
  const originDate = getDate(value, formatInput);
243
243
 
244
- /**
245
- * compare two date time and return a period
246
- * @param {Date|String|Array} date is a date time
247
- * @param {String} unit one of milliseconds|seconds|minutes|hours|days|months|years
248
- * @param {Boolean|Number} floating allow odd numbers
249
- * @returns {Number} distance
244
+ /**
245
+ * compare two date time and return a period
246
+ * @param {Date|String|Array} date is a date time
247
+ * @param {String} unit one of milliseconds|seconds|minutes|hours|days|months|years
248
+ * @param {Boolean|Number} floating allow odd numbers
249
+ * @returns {Number} distance
250
250
  */
251
251
  const diff = (compareDate, unit = 'days', floating = false) => {
252
252
  compareDate = getDate(compareDate);
@@ -295,12 +295,12 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
295
295
  return result.toFixed(floating ? typeof floating === 'number' ? floating : 2 : 0);
296
296
  };
297
297
 
298
- /**
299
- * add or subtract date time
300
- * @param {Number} num the quantity to cal for unit
301
- * @param {String} unit the unit of date/time
302
- * @param {String} operator operator to cal (add/subtract)
303
- * @returns {Object} date
298
+ /**
299
+ * add or subtract date time
300
+ * @param {Number} num the quantity to cal for unit
301
+ * @param {String} unit the unit of date/time
302
+ * @param {String} operator operator to cal (add/subtract)
303
+ * @returns {Object} date
304
304
  */
305
305
  const calculation = (num, unit, operator) => {
306
306
  if (isNaN(num)) {
@@ -311,11 +311,11 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
311
311
  return date(originDate, formatInput);
312
312
  };
313
313
 
314
- /**
315
- * get the moment of time follow unit time
316
- * @param {String} unit the unit of time
317
- * @param {String} moment start|end to get start|end of the moment
318
- * @returns {Object} date
314
+ /**
315
+ * get the moment of time follow unit time
316
+ * @param {String} unit the unit of time
317
+ * @param {String} moment start|end to get start|end of the moment
318
+ * @returns {Object} date
319
319
  */
320
320
  const timeOf = (unit, moment) => {
321
321
  let temp = 1;
@@ -337,12 +337,12 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
337
337
  return date(originDate, formatInput);
338
338
  };
339
339
 
340
- /**
341
- *
342
- * @param {Date|String|Number|Array} compareDate date to calculate moment, undefined will compare with now
343
- * @param {String|Array} unit year|month|day|hour|minute|second|millisecond, allow undefined
344
- * @param {Boolean|Number} floating allow odd numbers
345
- * @returns {String} moments
340
+ /**
341
+ *
342
+ * @param {Date|String|Number|Array} compareDate date to calculate moment, undefined will compare with now
343
+ * @param {String|Array} unit year|month|day|hour|minute|second|millisecond, allow undefined
344
+ * @param {Boolean|Number} floating allow odd numbers
345
+ * @returns {String} moments
346
346
  */
347
347
  const relative = (compareDate, unit, floating) => {
348
348
  compareDate = getDate(compareDate);
@@ -378,17 +378,17 @@ const date = (value, formatInput = 'MM/DD/YYYY') => {
378
378
  };
379
379
  return {
380
380
  value: originDate,
381
- /**
382
- * return a date time follow the concrete format
383
- * @param {String} formatOutput format of date
384
- * @param {Boolean} utc is utc time
381
+ /**
382
+ * return a date time follow the concrete format
383
+ * @param {String} formatOutput format of date
384
+ * @param {Boolean} utc is utc time
385
385
  */
386
386
  format: (formatOutput, utc) => formatDate(originDate, formatOutput, utc),
387
387
  diff,
388
- /**
389
- * check 1 value is a date
390
- * @param {String} formatInput the format date to check valid date
391
- * @returns {Boolean} valid date
388
+ /**
389
+ * check 1 value is a date
390
+ * @param {String} formatInput the format date to check valid date
391
+ * @returns {Boolean} valid date
392
392
  */
393
393
  isValid: () => isValidDate(originDate, formatInput),
394
394
  add: (num, unit) => calculation(num, unit, 'add'),
@@ -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;