diginet-core-ui 1.4.21 → 1.4.23-beta.1
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/assets/images/menu/dhr/MHRP39N0020.svg +9 -0
- package/assets/images/menu/dhr/MHRP39N0021.svg +7 -0
- package/assets/images/menu/eo/WEO76LIS0005.svg +6 -0
- package/assets/images/menu/eo/WEO76LIS0006.svg +14 -0
- package/assets/images/menu/eo/WEO76LIS0007.svg +19 -0
- package/assets/images/menu/eo/WEO76REQ0003.svg +15 -0
- package/components/accordion/details.js +12 -14
- package/components/accordion/group.js +12 -14
- package/components/accordion/index.js +36 -38
- package/components/accordion/summary.js +50 -51
- package/components/chip/index.js +61 -69
- package/components/form-control/calendar/function.js +1 -1
- package/components/form-control/date-input/DateField.js +189 -0
- package/components/form-control/date-input/index.js +301 -0
- package/components/form-control/date-input/useControlled.js +14 -0
- package/components/form-control/date-input/useDateInputState.js +132 -0
- package/components/form-control/date-input/useIsFocused.js +20 -0
- package/components/form-control/date-input/useKeyboardInputEvent.js +41 -0
- package/components/form-control/date-input/utils.js +286 -0
- package/components/form-control/date-picker/index.js +143 -422
- package/components/form-control/dropdown/index.js +259 -602
- package/components/form-control/input-base/UncontrolledInputBase.js +451 -0
- package/components/form-control/number-input/index2.js +4 -1
- package/components/form-control/time-picker/v2/index.js +792 -0
- package/components/image/index.js +22 -24
- package/components/index.js +2 -1
- package/components/modal/body.js +9 -11
- package/components/modal/footer.js +8 -10
- package/components/modal/header.js +27 -25
- package/components/modal/modal.js +33 -32
- package/components/tab/tab-container.js +57 -49
- package/components/tab/tab-header.js +72 -65
- package/components/tab/tab-panel.js +38 -32
- package/components/tab/tab.js +69 -61
- package/global/index.js +4 -0
- package/icons/effect.js +63 -58
- package/package.json +65 -33
- package/readme.md +17 -4
- package/theme/settings.js +78 -0
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { css, jsx } from '@emotion/core';
|
|
4
|
-
import { Button, ButtonIcon, HelperText, InputBase, Label, Tooltip } from "../..";
|
|
4
|
+
import { Button, ButtonIcon, DateInput, HelperText, InputBase, Label, Popover, Tooltip } from "../..";
|
|
5
|
+
import { format, isValid, parse } from 'date-fns';
|
|
6
|
+
import { enUS, vi } from 'date-fns/locale';
|
|
5
7
|
import { getGlobal } from "../../../global";
|
|
6
8
|
import locale from "../../../locale";
|
|
7
9
|
import PropTypes from 'prop-types';
|
|
8
|
-
import { forwardRef, memo,
|
|
9
|
-
import {
|
|
10
|
-
import { bgColor, borderRadius4px, cursorPointer, displayBlock, displayFlex, displayNone, flexRow, itemsCenter, justifyEnd, left, parseMaxWidth, parseMinWidth, parseWidthHeight, positionFixed, scale, top, z } from "../../../styles/general";
|
|
10
|
+
import { Fragment, forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { cursorNotAllowed, displayBlock, displayFlex, flexRow, itemsCenter, justifyEnd, positionRelative } from "../../../styles/general";
|
|
11
12
|
import { useTheme } from "../../../theme";
|
|
12
|
-
import { capitalizeSentenceCase, date as moment, randomString, updatePosition, getProp } from "../../../utils";
|
|
13
|
-
import CalendarComp from "../calendar";
|
|
14
|
-
import { isValidDate } from "../calendar/function";
|
|
15
|
-
import ControlComp from "../control";
|
|
16
13
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
14
|
+
import { capitalizeSentenceCase, classNames, isValidDate } from "../../../utils";
|
|
15
|
+
import Calendar from "../calendar";
|
|
16
|
+
import useControlled from "../date-input/useControlled";
|
|
17
|
+
import { lowerCaseDayYear } from "../date-input/utils";
|
|
18
|
+
const unique = {
|
|
19
|
+
footer: 'DGN-UI-DatePicker-Footer',
|
|
20
|
+
cancel: 'DGN-UI-DatePicker-cancel',
|
|
21
|
+
confirm: 'DGN-UI-DatePicker-confirm',
|
|
22
|
+
icon: 'DGN-UI-DatePicker-Icon'
|
|
23
|
+
};
|
|
17
24
|
const confirmText = getGlobal(['confirm']);
|
|
18
25
|
const cancelText = getGlobal(['cancel']);
|
|
19
|
-
const formatValue = (value, format, utc = false) => {
|
|
20
|
-
return moment(value).format(format, utc);
|
|
21
|
-
};
|
|
22
26
|
const viDisplayFormat = new Map([['year', 'YYYY'], ['quarter', 'Q-YYYY'], ['month', 'MM-YYYY']]);
|
|
23
27
|
const pickerReturnFormat = new Map([['year', 'YYYY'], ['quarter', 'YYYY-Q'], ['month', 'YYYY-MM']]);
|
|
28
|
+
const parseValueToDate = valueProp => {
|
|
29
|
+
if (valueProp === '') return null;
|
|
30
|
+
return isValidDate(valueProp) ? new Date(valueProp) : valueProp;
|
|
31
|
+
};
|
|
24
32
|
const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
25
33
|
var _ref, _pickerReturnFormat$g, _ipRef$current, _ipRef$current2;
|
|
26
34
|
if (!reference) reference = useRef(null);
|
|
27
35
|
const theme = useTheme();
|
|
28
|
-
const {
|
|
29
|
-
colors,
|
|
30
|
-
zIndex
|
|
31
|
-
} = theme;
|
|
32
36
|
|
|
33
37
|
// props priority: `inProps` > `themeDefaultProps`
|
|
34
38
|
const props = useThemeProps({
|
|
@@ -38,6 +42,7 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
38
42
|
const {
|
|
39
43
|
action = {},
|
|
40
44
|
actionIconAt,
|
|
45
|
+
className,
|
|
41
46
|
clearAble,
|
|
42
47
|
controls,
|
|
43
48
|
defaultValue,
|
|
@@ -62,285 +67,108 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
62
67
|
returnFormat: returnFormatProp,
|
|
63
68
|
style,
|
|
64
69
|
textAlign,
|
|
70
|
+
useDateInput,
|
|
65
71
|
value: valueProp,
|
|
66
72
|
viewType,
|
|
73
|
+
onBlur,
|
|
67
74
|
...other
|
|
68
75
|
} = props;
|
|
69
|
-
const
|
|
76
|
+
const dateLocale = locale.get();
|
|
77
|
+
const displayFormat = (_ref = dateLocale === 'vi' ? viDisplayFormat.get(minZoom) : pickerReturnFormat.get(minZoom)) !== null && _ref !== void 0 ? _ref : displayFormatProp;
|
|
70
78
|
const returnFormat = (_pickerReturnFormat$g = pickerReturnFormat.get(minZoom)) !== null && _pickerReturnFormat$g !== void 0 ? _pickerReturnFormat$g : returnFormatProp;
|
|
71
79
|
const placeholder = placeholderProp !== null && placeholderProp !== void 0 ? placeholderProp : displayFormat;
|
|
72
|
-
const [
|
|
73
|
-
|
|
74
|
-
}));
|
|
75
|
-
const unique = {
|
|
76
|
-
disabled: 'DGN-UI-DatePicker-disabled',
|
|
77
|
-
error: 'DGN-UI-DatePicker-error',
|
|
78
|
-
focus: 'DGN-UI-DatePicker-focus',
|
|
79
|
-
footer: 'DGN-UI-DatePicker-Footer',
|
|
80
|
-
cancel: 'DGN-UI-DatePicker-cancel',
|
|
81
|
-
confirm: 'DGN-UI-DatePicker-confirm',
|
|
82
|
-
backGr: 'DGN-UI-DatePicker-Background',
|
|
83
|
-
icon: 'DGN-UI-DatePicker-Icon',
|
|
84
|
-
picker: `DGN-UI-DatePicker-Picker-${id}`,
|
|
85
|
-
portal: 'DGN-UI-Portal'
|
|
86
|
-
};
|
|
87
|
-
const calRef = useRef(null);
|
|
88
|
-
const footerRef = useRef(null);
|
|
89
|
-
const iconRef = useRef(null);
|
|
90
|
-
const ipConRef = useRef(null);
|
|
80
|
+
const [value, setValue] = useControlled(parseValueToDate(valueProp), parseValueToDate(defaultValue));
|
|
81
|
+
const [openPickerState, setOpenPickerState] = useState(false);
|
|
91
82
|
const ipRef = useRef(null);
|
|
92
83
|
const ref = useRef(null);
|
|
93
|
-
const displayValue = useRef();
|
|
94
84
|
const focusedValue = useRef(null);
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
85
|
+
const pickerRef = useRef(null);
|
|
86
|
+
const buttonCarlendarRef = useRef(null);
|
|
87
|
+
const isError = !!error && (!value || !isValid(value));
|
|
88
|
+
const _DatePickerRoot = DatePickerRoot();
|
|
89
|
+
const _IconAreaCSS = IconAreaCSS();
|
|
99
90
|
const _ControlContainerCSS = ControlContainerCSS(theme);
|
|
100
|
-
const handleDisplayValue = useCallback(value => {
|
|
101
|
-
displayValue.current = new Date(value);
|
|
102
|
-
setDisplayValue();
|
|
103
|
-
}, [displayValue]);
|
|
104
|
-
const handleFocusedValue = useCallback(value => {
|
|
105
|
-
focusedValue.current = new Date(value);
|
|
106
|
-
setFocusedValue();
|
|
107
|
-
}, [focusedValue]);
|
|
108
|
-
const setButtonState = () => {
|
|
109
|
-
if (!footerRef.current || focusedValue.current === undefined || !isValidDate(focusedValue.current)) return;
|
|
110
|
-
const isEqual = focusedValue.current === null || Date.parse(new Date(focusedValue.current)) === Date.parse(new Date(displayValue.current));
|
|
111
|
-
footerRef.current.querySelector(`.${unique.cancel}`).disabled = isEqual;
|
|
112
|
-
footerRef.current.querySelector(`.${unique.confirm}`).disabled = isEqual;
|
|
113
|
-
};
|
|
114
91
|
const onConfirm = () => {
|
|
115
|
-
displayValue.current = focusedValue.current;
|
|
116
|
-
setButtonState();
|
|
117
92
|
onChangeValue({
|
|
118
93
|
value: focusedValue.current
|
|
119
94
|
});
|
|
120
95
|
closePicker();
|
|
121
96
|
};
|
|
122
97
|
const onCancel = () => {
|
|
123
|
-
focusedValue.current = null;
|
|
124
|
-
setButtonState();
|
|
125
98
|
closePicker();
|
|
126
99
|
};
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
100
|
+
const formatValue = (value, formatStr) => {
|
|
101
|
+
// return moment(value).format(format, utc = false);
|
|
102
|
+
return format(value, lowerCaseDayYear(formatStr), {
|
|
103
|
+
locale: dateLocale === 'vi' ? vi : enUS
|
|
104
|
+
});
|
|
130
105
|
};
|
|
131
106
|
const onChangeValue = e => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
!!onChange && onChange({
|
|
138
|
-
value: formatValue(e.value, returnFormat)
|
|
107
|
+
const vl = (e === null || e === void 0 ? void 0 : e.value) || e;
|
|
108
|
+
closePicker();
|
|
109
|
+
setValue(vl);
|
|
110
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
111
|
+
value: isValid(vl) ? formatValue(vl, returnFormat) : String(vl) === 'Invalid Date' ? 'Invalid Date' : vl
|
|
139
112
|
});
|
|
140
113
|
};
|
|
141
114
|
const onCalendarClick = e => {
|
|
142
|
-
|
|
143
|
-
controls ? setButtonState() : onChangeValue(e);
|
|
144
|
-
};
|
|
145
|
-
const getPickerStyle = () => {
|
|
146
|
-
const {
|
|
147
|
-
innerHeight,
|
|
148
|
-
innerWidth
|
|
149
|
-
} = window;
|
|
150
|
-
const {
|
|
151
|
-
left,
|
|
152
|
-
height,
|
|
153
|
-
top,
|
|
154
|
-
width
|
|
155
|
-
} = ipConRef.current.getBoundingClientRect();
|
|
156
|
-
const pickerHeight = controls ? 310 : 256;
|
|
157
|
-
let style = {};
|
|
158
|
-
style.top = top + height + 4;
|
|
159
|
-
style.transformOrigin = '50% 20%';
|
|
160
|
-
if (style.top + pickerHeight > innerHeight) {
|
|
161
|
-
if (top - pickerHeight > 0) {
|
|
162
|
-
style.top = top - pickerHeight - 4;
|
|
163
|
-
style.transformOrigin = '50% 80%';
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return PickerCSS.picker(style, left + 400 > innerWidth ? innerWidth - 400 : left, width, colors).styles;
|
|
167
|
-
};
|
|
168
|
-
const createBackground = () => {
|
|
169
|
-
let background = document.getElementById(unique.backGr);
|
|
170
|
-
if (!background) {
|
|
171
|
-
background = document.createElement('div');
|
|
172
|
-
background.id = unique.backGr;
|
|
173
|
-
background.classList.add(unique.portal, unique.backGr);
|
|
174
|
-
document.body.appendChild(background);
|
|
175
|
-
}
|
|
176
|
-
background.style.cssText = PickerCSS.backGr(theme);
|
|
177
|
-
return background;
|
|
178
|
-
};
|
|
179
|
-
const createPicker = () => {
|
|
180
|
-
const picker = document.createElement('div');
|
|
181
|
-
picker.id = unique.picker;
|
|
182
|
-
picker.style.cssText = getPickerStyle();
|
|
183
|
-
return picker;
|
|
184
|
-
};
|
|
185
|
-
const pressESCHandler = event => {
|
|
186
|
-
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
187
|
-
onClickOutside({
|
|
188
|
-
target: null
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
const onScroll = () => {
|
|
193
|
-
const node = document.getElementById(unique.picker);
|
|
194
|
-
if (!ipConRef.current || !node) {
|
|
195
|
-
window.removeEventListener('scroll', onScroll);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
updatePosition(ipConRef.current, node, closePicker);
|
|
199
|
-
};
|
|
200
|
-
const onResize = () => {
|
|
201
|
-
if (!ref.current) return;
|
|
202
|
-
const {
|
|
203
|
-
width
|
|
204
|
-
} = ref.current.getBoundingClientRect();
|
|
205
|
-
const node = document.getElementById(unique.picker);
|
|
206
|
-
if (node) {
|
|
207
|
-
node.style.width = width + 'px';
|
|
208
|
-
}
|
|
209
|
-
onScroll();
|
|
115
|
+
!controls ? onChangeValue(e) : focusedValue.current = e === null || e === void 0 ? void 0 : e.value;
|
|
210
116
|
};
|
|
211
117
|
const openPicker = () => {
|
|
212
|
-
|
|
213
|
-
const picker = createPicker();
|
|
214
|
-
render(jsx(CalendarComp, {
|
|
215
|
-
ref: calRef,
|
|
216
|
-
actions: controls && footerMemo,
|
|
217
|
-
defaultValue: displayValue.current,
|
|
218
|
-
value: focusedValue.current,
|
|
219
|
-
max: max,
|
|
220
|
-
min: min,
|
|
221
|
-
minZoom: minZoom,
|
|
222
|
-
maxZoom: maxZoom,
|
|
223
|
-
displayAnotherMonth: displayAnotherMonth,
|
|
224
|
-
onClick: onCalendarClick
|
|
225
|
-
}), backGr.appendChild(picker));
|
|
226
|
-
setTimeout(() => {
|
|
227
|
-
Object.assign(picker.style, {
|
|
228
|
-
...PickerCSS.active
|
|
229
|
-
});
|
|
230
|
-
window.addEventListener('resize', onResize);
|
|
231
|
-
window.addEventListener('scroll', onScroll);
|
|
232
|
-
document.addEventListener('mousedown', onClickOutside);
|
|
233
|
-
if (pressESCToClose) {
|
|
234
|
-
document.addEventListener('keydown', pressESCHandler);
|
|
235
|
-
}
|
|
236
|
-
setButtonState();
|
|
237
|
-
});
|
|
118
|
+
setOpenPickerState(true);
|
|
238
119
|
};
|
|
239
120
|
const closePicker = () => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const picker = backGr.querySelector(`#${unique.picker}`);
|
|
243
|
-
if (!picker) return;
|
|
244
|
-
Object.assign(picker.style, {
|
|
245
|
-
...PickerCSS.remove
|
|
246
|
-
});
|
|
247
|
-
if (pressESCToClose) {
|
|
248
|
-
document.removeEventListener('keydown', pressESCHandler);
|
|
249
|
-
}
|
|
250
|
-
document.removeEventListener('mousedown', onClickOutside);
|
|
251
|
-
window.removeEventListener('scroll', onScroll);
|
|
252
|
-
window.removeEventListener('resize', onResize);
|
|
253
|
-
setTimeout(() => {
|
|
254
|
-
backGr.remove();
|
|
255
|
-
}, 200);
|
|
256
|
-
if (ipConRef.current) {
|
|
257
|
-
ipConRef.current.classList.remove(unique.focus);
|
|
258
|
-
ipConRef.current.style.zIndex = null;
|
|
259
|
-
}
|
|
260
|
-
// iconRef.current && onSwap(true);
|
|
261
|
-
ipRef.current && ipRef.current.blur();
|
|
262
|
-
};
|
|
263
|
-
const onSwap = open => {
|
|
264
|
-
const t = iconRef.current.childNodes[+open];
|
|
265
|
-
if (open) {
|
|
266
|
-
Object.assign(t.style, {
|
|
267
|
-
...hiddenStyle
|
|
268
|
-
});
|
|
269
|
-
Object.assign(t.previousSibling.style, {
|
|
270
|
-
...activeStyle
|
|
271
|
-
});
|
|
272
|
-
setTimeout(() => {
|
|
273
|
-
t.previousSibling.style.pointerEvents = null;
|
|
274
|
-
}, 200);
|
|
275
|
-
} else {
|
|
276
|
-
Object.assign(t.style, {
|
|
277
|
-
...hiddenStyle
|
|
278
|
-
});
|
|
279
|
-
Object.assign(t.nextSibling.style, {
|
|
280
|
-
...activeStyle
|
|
281
|
-
});
|
|
282
|
-
setTimeout(() => {
|
|
283
|
-
t.nextSibling.style.pointerEvents = null;
|
|
284
|
-
}, 200);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
const onInputFocus = () => {
|
|
288
|
-
const el = ipConRef.current;
|
|
289
|
-
if (!el.classList.contains(unique.focus)) {
|
|
290
|
-
el.classList.add(unique.focus);
|
|
291
|
-
el.style.zIndex = zIndex(2);
|
|
292
|
-
openPicker();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
const onClickOutside = e => {
|
|
296
|
-
if (ipConRef.current && !ipConRef.current.contains(e.target) && ipRef.current && !ipRef.current.contains(e.target) && calRef.current && !calRef.current.contains(e.target)) {
|
|
297
|
-
controls ? onCancel() : closePicker();
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
const triggerFocus = () => {
|
|
301
|
-
if (!ipConRef.current.classList.contains(unique.focus)) {
|
|
302
|
-
ipRef.current.focus();
|
|
303
|
-
} else {
|
|
304
|
-
onClickOutside({
|
|
305
|
-
target: null
|
|
306
|
-
});
|
|
121
|
+
if (pickerRef.current) {
|
|
122
|
+
setOpenPickerState(false);
|
|
307
123
|
}
|
|
124
|
+
if (ipRef.current) onBlur === null || onBlur === void 0 ? void 0 : onBlur(ipRef.current);
|
|
308
125
|
};
|
|
309
126
|
const onClear = () => {
|
|
310
127
|
if (!clearAble && !ipRef.current) return;
|
|
311
|
-
|
|
128
|
+
onChangeValue(null);
|
|
312
129
|
focusedValue.current = null;
|
|
313
|
-
setButtonState();
|
|
314
|
-
const e = {
|
|
315
|
-
value: null
|
|
316
|
-
};
|
|
317
|
-
!!onChange && onChange(e);
|
|
318
|
-
onSwap(true);
|
|
319
130
|
};
|
|
131
|
+
const _onBlur = e => {
|
|
132
|
+
if (ipRef.current && (e === null || e === void 0 ? void 0 : e.relatedTarget) !== buttonCarlendarRef.current) {
|
|
133
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(ipRef.current);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
const vl = parseValueToDate(valueProp);
|
|
138
|
+
setValue(vl);
|
|
139
|
+
}, [valueProp]);
|
|
140
|
+
useImperativeHandle(reference, () => {
|
|
141
|
+
const currentRef = ref.current || {};
|
|
142
|
+
const _instance = {
|
|
143
|
+
...action
|
|
144
|
+
}; // methods
|
|
145
|
+
_instance.__proto__ = {}; // hidden methods
|
|
146
|
+
currentRef.instance = _instance;
|
|
147
|
+
return currentRef;
|
|
148
|
+
});
|
|
320
149
|
const iconComp = jsx("div", {
|
|
321
|
-
css: _IconAreaCSS
|
|
322
|
-
|
|
323
|
-
}, jsx(ButtonIcon, {
|
|
324
|
-
disabled: disabled || readOnly,
|
|
325
|
-
viewType: 'ghost',
|
|
326
|
-
onClick: triggerFocus,
|
|
327
|
-
className: `${unique.icon} ${unique.icon}-accept`,
|
|
328
|
-
viewBox: true,
|
|
329
|
-
name: 'Calendar'
|
|
330
|
-
}), jsx(ButtonIcon, {
|
|
150
|
+
css: _IconAreaCSS
|
|
151
|
+
}, clearAble && value ? jsx(ButtonIcon, {
|
|
331
152
|
disabled: disabled || readOnly,
|
|
332
153
|
viewType: 'ghost',
|
|
333
154
|
onClick: onClear,
|
|
334
155
|
className: `${unique.icon} ${unique.icon}-cancel`,
|
|
335
156
|
viewBox: true,
|
|
336
157
|
name: 'Close'
|
|
158
|
+
}) : null, jsx(ButtonIcon, {
|
|
159
|
+
ref: buttonCarlendarRef,
|
|
160
|
+
disabled: disabled || readOnly,
|
|
161
|
+
viewType: 'ghost',
|
|
162
|
+
onClick: openPicker,
|
|
163
|
+
className: `${unique.icon} ${unique.icon}-accept`,
|
|
164
|
+
viewBox: true,
|
|
165
|
+
name: 'Calendar'
|
|
337
166
|
}));
|
|
338
167
|
const endIcon = actionIconAt === 'end' && iconComp;
|
|
339
168
|
const startIcon = actionIconAt === 'start' && iconComp;
|
|
340
169
|
const footerMemo = jsx("div", {
|
|
341
170
|
css: _ControlContainerCSS,
|
|
342
|
-
className: unique.footer
|
|
343
|
-
ref: footerRef
|
|
171
|
+
className: unique.footer
|
|
344
172
|
}, jsx(Button, {
|
|
345
173
|
className: unique.cancel,
|
|
346
174
|
onClick: onCancel
|
|
@@ -349,133 +177,46 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
349
177
|
className: unique.confirm,
|
|
350
178
|
onClick: onConfirm
|
|
351
179
|
}, confirmText));
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
};
|
|
363
|
-
}, []);
|
|
364
|
-
useEffect(() => {
|
|
365
|
-
if (value && isValidDate(value)) {
|
|
366
|
-
handleFocusedValue(value);
|
|
367
|
-
handleDisplayValue(value);
|
|
368
|
-
setInputValue({
|
|
369
|
-
value: displayValue.current
|
|
370
|
-
});
|
|
371
|
-
setButtonState();
|
|
372
|
-
closePicker();
|
|
373
|
-
} else if (defaultValue && isValidDate(defaultValue)) {
|
|
374
|
-
handleFocusedValue(defaultValue);
|
|
375
|
-
handleDisplayValue(defaultValue);
|
|
376
|
-
setInputValue({
|
|
377
|
-
value: displayValue.current
|
|
378
|
-
});
|
|
379
|
-
setButtonState();
|
|
380
|
-
closePicker();
|
|
381
|
-
} else {
|
|
382
|
-
if (ipRef.current) ipRef.current.value = '';
|
|
383
|
-
if (clearAble) {
|
|
384
|
-
onSwap(true);
|
|
385
|
-
}
|
|
386
|
-
setButtonState();
|
|
387
|
-
closePicker();
|
|
388
|
-
}
|
|
180
|
+
const renderedValue = useMemo(() => {
|
|
181
|
+
if (isValidDate(value)) return capitalizeSentenceCase(formatValue(value, displayFormat));
|
|
182
|
+
return value;
|
|
183
|
+
}, [value, displayFormat]);
|
|
184
|
+
const valueDateInput = useMemo(() => {
|
|
185
|
+
if (value && isValid(value)) {
|
|
186
|
+
return value;
|
|
187
|
+
} else if (value === null) {
|
|
188
|
+
return null;
|
|
189
|
+
} else return parse(value, lowerCaseDayYear(returnFormat), new Date());
|
|
389
190
|
}, [value]);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}, [valueProp]);
|
|
393
|
-
useEffect(() => {
|
|
394
|
-
if (!readOnly) {
|
|
395
|
-
ipRef.current.addEventListener('focus', onInputFocus);
|
|
396
|
-
}
|
|
397
|
-
return () => {
|
|
398
|
-
if (!ipRef.current) return;
|
|
399
|
-
if (!readOnly) {
|
|
400
|
-
ipRef.current.removeEventListener('focus', onInputFocus);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
}, [onChange]);
|
|
404
|
-
useEffect(() => {
|
|
405
|
-
if (ipRef.current.value !== '') {
|
|
406
|
-
const e = {
|
|
407
|
-
value: focusedValue.current || displayValue.current
|
|
408
|
-
};
|
|
409
|
-
setInputValue(e, displayFormat);
|
|
410
|
-
}
|
|
411
|
-
if (disabled) {
|
|
412
|
-
iconRef.current.childNodes[0].style.pointerEvents = 'none';
|
|
413
|
-
closePicker();
|
|
414
|
-
} else if (!readOnly) {
|
|
415
|
-
ipRef.current.addEventListener('focus', onInputFocus);
|
|
416
|
-
} else {
|
|
417
|
-
iconRef.current.childNodes[0].style.pointerEvents = 'none';
|
|
418
|
-
closePicker();
|
|
419
|
-
}
|
|
420
|
-
return () => {
|
|
421
|
-
if (!iconRef.current || !ipRef.current) return;
|
|
422
|
-
if (disabled) {
|
|
423
|
-
iconRef.current.childNodes[0].style.pointerEvents = null;
|
|
424
|
-
} else if (!readOnly) {
|
|
425
|
-
ipRef.current.removeEventListener('focus', onInputFocus);
|
|
426
|
-
} else {
|
|
427
|
-
iconRef.current.childNodes[0].style.pointerEvents = null;
|
|
428
|
-
}
|
|
429
|
-
closePicker();
|
|
430
|
-
};
|
|
431
|
-
}, [actionIconAt, clearAble, controls, disabled, displayFormat, displayAnotherMonth, max, min, minZoom, maxZoom, readOnly, returnFormat, viewType]);
|
|
432
|
-
useImperativeHandle(reference, () => {
|
|
433
|
-
const currentRef = ref.current || {};
|
|
434
|
-
const _instance = {
|
|
435
|
-
...action,
|
|
436
|
-
get: () => {
|
|
437
|
-
return ref.current;
|
|
438
|
-
},
|
|
439
|
-
getInputContainer: () => {
|
|
440
|
-
return ipConRef.current;
|
|
441
|
-
},
|
|
442
|
-
getInput: () => {
|
|
443
|
-
return ipRef.current;
|
|
444
|
-
},
|
|
445
|
-
getCalendar: () => {
|
|
446
|
-
return calRef.current;
|
|
447
|
-
},
|
|
448
|
-
getIcon: () => {
|
|
449
|
-
return iconRef.current;
|
|
450
|
-
}
|
|
451
|
-
}; // methods
|
|
452
|
-
_instance.__proto__ = {}; // hidden methods
|
|
453
|
-
currentRef.instance = _instance;
|
|
454
|
-
currentRef.get = () => ref.current;
|
|
455
|
-
currentRef.getInputContainer = () => ipConRef.current;
|
|
456
|
-
currentRef.getInput = () => ipRef.current;
|
|
457
|
-
currentRef.getCalendar = () => calRef.current;
|
|
458
|
-
currentRef.getIcon = () => iconRef.current;
|
|
459
|
-
return currentRef;
|
|
460
|
-
});
|
|
461
|
-
return jsx(ControlComp, {
|
|
462
|
-
...other,
|
|
463
|
-
disabled: disabled,
|
|
464
|
-
error: isError,
|
|
191
|
+
const renderDateInputCondition = useDateInput && minZoom !== 'quarter' && !min && !max;
|
|
192
|
+
return jsx(Fragment, null, jsx("div", {
|
|
465
193
|
ref: ref,
|
|
466
|
-
|
|
194
|
+
css: _DatePickerRoot,
|
|
195
|
+
className: classNames('DGN-UI-DatePicker', className, disabled && 'disabled'),
|
|
196
|
+
style: style,
|
|
197
|
+
...other
|
|
467
198
|
}, label ? jsx(Label, {
|
|
468
199
|
disabled: disabled,
|
|
469
200
|
required: required,
|
|
470
201
|
...labelProps
|
|
471
202
|
}, label) : null, jsx(Tooltip, {
|
|
472
203
|
title: (ipRef === null || ipRef === void 0 ? void 0 : (_ipRef$current = ipRef.current) === null || _ipRef$current === void 0 ? void 0 : _ipRef$current.clientWidth) < 200 ? ipRef === null || ipRef === void 0 ? void 0 : (_ipRef$current2 = ipRef.current) === null || _ipRef$current2 === void 0 ? void 0 : _ipRef$current2.value : ''
|
|
473
|
-
}, jsx(
|
|
204
|
+
}, renderDateInputCondition ? jsx(DateInput, {
|
|
205
|
+
inputRef: ipRef,
|
|
206
|
+
disabled: disabled,
|
|
207
|
+
readOnly: readOnly,
|
|
208
|
+
viewType: viewType,
|
|
209
|
+
startIcon: startIcon,
|
|
210
|
+
endIcon: endIcon,
|
|
211
|
+
format: displayFormat,
|
|
212
|
+
value: valueDateInput,
|
|
213
|
+
onBlur: _onBlur,
|
|
214
|
+
onChange: onChangeValue
|
|
215
|
+
}) : jsx(InputBase, {
|
|
474
216
|
inputProps: {
|
|
475
217
|
placeholder: !readOnly && !disabled ? placeholder : '',
|
|
476
218
|
...inputProps
|
|
477
219
|
},
|
|
478
|
-
ref: ipConRef,
|
|
479
220
|
inputRef: ipRef,
|
|
480
221
|
disabled: disabled,
|
|
481
222
|
viewType: viewType,
|
|
@@ -486,42 +227,46 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
486
227
|
startIcon: startIcon,
|
|
487
228
|
endIcon: endIcon,
|
|
488
229
|
onKeyDown: e => e.preventDefault(),
|
|
489
|
-
readOnly: true
|
|
230
|
+
readOnly: true,
|
|
231
|
+
value: renderedValue,
|
|
232
|
+
onFocus: openPicker
|
|
490
233
|
})), isError ? jsx(HelperText, {
|
|
491
234
|
...errorProps,
|
|
492
|
-
style: {
|
|
493
|
-
minHeight: 16,
|
|
494
|
-
position: 'absolute',
|
|
495
|
-
top: '100%'
|
|
496
|
-
},
|
|
497
235
|
disabled: disabled
|
|
498
|
-
}, error) : null)
|
|
236
|
+
}, error) : null), jsx(Popover, {
|
|
237
|
+
css: PopoverCSS,
|
|
238
|
+
ref: pickerRef,
|
|
239
|
+
open: openPickerState,
|
|
240
|
+
anchor: ref.current,
|
|
241
|
+
pressESCToClose: pressESCToClose,
|
|
242
|
+
onClose: closePicker
|
|
243
|
+
}, jsx(Calendar, {
|
|
244
|
+
actions: controls && footerMemo,
|
|
245
|
+
value: value,
|
|
246
|
+
max: max,
|
|
247
|
+
min: min,
|
|
248
|
+
minZoom: minZoom,
|
|
249
|
+
maxZoom: maxZoom,
|
|
250
|
+
displayAnotherMonth: displayAnotherMonth,
|
|
251
|
+
onClick: onCalendarClick
|
|
252
|
+
})));
|
|
499
253
|
}));
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
254
|
+
const PopoverCSS = css`
|
|
255
|
+
.DGN-UI-Calendar {
|
|
256
|
+
box-shadow: none;
|
|
257
|
+
}
|
|
258
|
+
`;
|
|
259
|
+
const DatePickerRoot = () => css`
|
|
260
|
+
${displayBlock};
|
|
261
|
+
${positionRelative};
|
|
262
|
+
&.disabled {
|
|
263
|
+
${cursorNotAllowed};
|
|
264
|
+
}
|
|
265
|
+
`;
|
|
266
|
+
const IconAreaCSS = () => css`
|
|
510
267
|
${displayFlex};
|
|
511
268
|
${flexRow};
|
|
512
269
|
${itemsCenter};
|
|
513
|
-
color: inherit;
|
|
514
|
-
.${unique.icon} {
|
|
515
|
-
${displayNone};
|
|
516
|
-
${cursorPointer};
|
|
517
|
-
opacity: 0;
|
|
518
|
-
transition: display 50ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, opacity 300ms cubic-bezier(0.4, 0, 0.2, 1) 50ms;
|
|
519
|
-
will-change: display, opacity;
|
|
520
|
-
}
|
|
521
|
-
.${unique.icon}-accept {
|
|
522
|
-
${displayBlock};
|
|
523
|
-
opacity: 1;
|
|
524
|
-
}
|
|
525
270
|
`;
|
|
526
271
|
const ControlContainerCSS = ({
|
|
527
272
|
spacing
|
|
@@ -531,36 +276,6 @@ const ControlContainerCSS = ({
|
|
|
531
276
|
${justifyEnd};
|
|
532
277
|
margin: ${spacing([0, 4, 4])};
|
|
533
278
|
`;
|
|
534
|
-
const PickerCSS = {
|
|
535
|
-
backGr: ({
|
|
536
|
-
zIndex
|
|
537
|
-
}) => `background-color: transparent; top: 0px; bottom: 0px; left: 0px; right: 0px; pointer-events: auto; position: fixed; z-index: ${zIndex(1)};`,
|
|
538
|
-
picker: (position, positionLeft, width, colors) => css`
|
|
539
|
-
${positionFixed};
|
|
540
|
-
${borderRadius4px};
|
|
541
|
-
${bgColor(getProp(colors, 'system/standard'))};
|
|
542
|
-
${parseWidthHeight(width, 'max-content')};
|
|
543
|
-
${parseMinWidth(window.innerWidth <= 599 ? 280 : 400)};
|
|
544
|
-
${parseMaxWidth(400)};
|
|
545
|
-
${scale(0)};
|
|
546
|
-
${left(positionLeft)};
|
|
547
|
-
${top(position.top)};
|
|
548
|
-
transform-origin: ${position.transformOrigin};
|
|
549
|
-
opacity: 0;
|
|
550
|
-
transform: scale(0);
|
|
551
|
-
transition: opacity 120ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, transform 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
552
|
-
${z(2)};
|
|
553
|
-
`,
|
|
554
|
-
active: {
|
|
555
|
-
opacity: 1,
|
|
556
|
-
transform: 'scale(1)'
|
|
557
|
-
},
|
|
558
|
-
remove: {
|
|
559
|
-
opacity: 0,
|
|
560
|
-
pointerEvents: 'none',
|
|
561
|
-
transform: 'scale(0)'
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
279
|
|
|
565
280
|
// DatePicker.defaultProps = {
|
|
566
281
|
// actionIconAt: 'end',
|
|
@@ -580,6 +295,8 @@ const PickerCSS = {
|
|
|
580
295
|
DatePicker.propTypes = {
|
|
581
296
|
/** Action icons position. */
|
|
582
297
|
actionIconAt: PropTypes.oneOf(['end', 'start']),
|
|
298
|
+
/** CSS class for the component. */
|
|
299
|
+
className: PropTypes.string,
|
|
583
300
|
/** Display the clear icon if true. */
|
|
584
301
|
clearAble: PropTypes.bool,
|
|
585
302
|
/** If `true`, the calendar will have a footer controls. */
|
|
@@ -606,6 +323,8 @@ DatePicker.propTypes = {
|
|
|
606
323
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.object]),
|
|
607
324
|
/** Max value of date picker. */
|
|
608
325
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.object]),
|
|
326
|
+
/** Callback fired when the input is blurred. */
|
|
327
|
+
onBlur: PropTypes.func,
|
|
609
328
|
/** A callback function when value input change. */
|
|
610
329
|
onChange: PropTypes.func,
|
|
611
330
|
/** Hints for input. */
|
|
@@ -622,6 +341,8 @@ DatePicker.propTypes = {
|
|
|
622
341
|
style: PropTypes.object,
|
|
623
342
|
/** Text align of the input. */
|
|
624
343
|
textAlign: PropTypes.oneOf(['center', 'end', 'start']),
|
|
344
|
+
/** If `true`, lets users select a date with the keyboard. */
|
|
345
|
+
useDateInput: PropTypes.bool,
|
|
625
346
|
/** Value of the component. */
|
|
626
347
|
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.array, PropTypes.object]),
|
|
627
348
|
/** View type of the form control. */
|