diginet-core-ui 1.3.35-beta.3 → 1.3.35-beta.7
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/chip/index.js +8 -1
- package/components/form-control/attachment/index.js +1 -0
- package/components/form-control/date-range-picker/index.js +4 -0
- package/components/form-control/dropdown/index.js +81 -40
- package/components/form-control/number-input/index2.js +32 -46
- package/components/form-control/time-picker/index.js +4 -0
- package/components/modal/header.js +63 -65
- package/components/modal/modal.js +84 -130
- package/components/slider/slider-item.js +65 -25
- package/components/typography/index.js +1 -0
- package/icons/basic.js +18 -403
- package/package.json +1 -1
- package/styles/general.js +10 -1
- package/theme/settings.js +3 -2
package/components/chip/index.js
CHANGED
|
@@ -48,6 +48,7 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
48
48
|
disabled,
|
|
49
49
|
readOnly,
|
|
50
50
|
children,
|
|
51
|
+
style,
|
|
51
52
|
...props
|
|
52
53
|
}, reference) => {
|
|
53
54
|
const ref = useRef(null);
|
|
@@ -114,7 +115,8 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
114
115
|
className: size
|
|
115
116
|
}, jsx(Typography, {
|
|
116
117
|
type: size === 'small' ? 'p2' : 'p1',
|
|
117
|
-
color: 'inherit'
|
|
118
|
+
color: 'inherit',
|
|
119
|
+
lineClamp: 1
|
|
118
120
|
}, renderLabel()));
|
|
119
121
|
}, [label, size, startIcon, endIcon, clearAble]);
|
|
120
122
|
const endIconView = useMemo(() => {
|
|
@@ -149,6 +151,7 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
149
151
|
css: ChipRootCSS(onClick, onDbClick, color),
|
|
150
152
|
ref: ref,
|
|
151
153
|
className: ['DGN-UI-Chip', size, className, color && color !== 'default' && color, color && color !== 'default' && viewType, disabled && 'chip--disabled', readOnly && 'chip--readOnly'].join(' ').trim().replace(/\s+/g, ' '),
|
|
154
|
+
style: style,
|
|
152
155
|
onClick: _onClick,
|
|
153
156
|
onDoubleClick: _onDbClick,
|
|
154
157
|
...props
|
|
@@ -272,6 +275,7 @@ const ChipRootCSS = (onClick, onDbClick, color) => css`
|
|
|
272
275
|
Chip.defaultProps = {
|
|
273
276
|
label: '',
|
|
274
277
|
className: '',
|
|
278
|
+
style: {},
|
|
275
279
|
viewType: 'outlined',
|
|
276
280
|
size: 'small',
|
|
277
281
|
clearAble: false
|
|
@@ -284,6 +288,9 @@ Chip.propTypes = {
|
|
|
284
288
|
className: PropTypes.string,
|
|
285
289
|
|
|
286
290
|
/** max length content to display was allowed */
|
|
291
|
+
|
|
292
|
+
/** style inline of component */
|
|
293
|
+
style: PropTypes.object,
|
|
287
294
|
maxLength: PropTypes.number,
|
|
288
295
|
|
|
289
296
|
/** the icon display at head of Chip */
|
|
@@ -1856,6 +1856,7 @@ const Attachment = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1856
1856
|
ref.current.allNewAttached = allNewAttached;
|
|
1857
1857
|
ref.current.attached = attached;
|
|
1858
1858
|
ref.current.clear = clearAllAttached;
|
|
1859
|
+
ref.current.openFileDialog = triggerClickInput;
|
|
1859
1860
|
return ref.current;
|
|
1860
1861
|
});
|
|
1861
1862
|
return jsx("div", { ...props,
|
|
@@ -12,6 +12,10 @@ import { randomString, updatePosition, date as moment, capitalizeSentenceCase, i
|
|
|
12
12
|
import { getGlobal } from '../../../global';
|
|
13
13
|
import { generateCalendarCSS, onUpdateNavigator, renderHeader, renderNavigator } from '../calendar/function';
|
|
14
14
|
import locale from '../../../locale';
|
|
15
|
+
import { useTheme } from '../../../theme';
|
|
16
|
+
const {
|
|
17
|
+
zIndex
|
|
18
|
+
} = useTheme();
|
|
15
19
|
const DateRangePickerV2 = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
16
20
|
actionIconAt,
|
|
17
21
|
controls,
|
|
@@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
|
|
|
8
8
|
import { jsx, css } from '@emotion/core';
|
|
9
9
|
import { Account } from '../../../icons';
|
|
10
10
|
import AvatarDefault from '../../../assets/avatar/default.svg';
|
|
11
|
-
import { InputBase, Chip, CircularProgress, Checkbox, TreeView, HelperText, Label, ButtonIcon } from '../../';
|
|
11
|
+
import { InputBase, Chip, CircularProgress, Checkbox, TreeView, HelperText, Label, ButtonIcon, Typography } from '../../';
|
|
12
12
|
import { mapParent, randomString, updatePosition } from '../../../utils';
|
|
13
13
|
import { getGlobal } from '../../../global';
|
|
14
14
|
import { color as colors } from '../../../styles/colors';
|
|
@@ -101,10 +101,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
101
101
|
formStyle,
|
|
102
102
|
labelProps,
|
|
103
103
|
errorStyle,
|
|
104
|
-
refs,
|
|
105
104
|
children,
|
|
106
105
|
dropdownItemStyle
|
|
107
|
-
},
|
|
106
|
+
}, reference) => {
|
|
108
107
|
const dropdownRef = useRef(null);
|
|
109
108
|
const timerRef = useRef(null);
|
|
110
109
|
const formRef = useRef(null);
|
|
@@ -119,7 +118,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
119
118
|
allowSymbol: false
|
|
120
119
|
}));
|
|
121
120
|
const [openState, setOpenState] = useState(false);
|
|
122
|
-
const [errorState, setErrorState] = useState(error && !valueProp && valueProp !== 0);
|
|
123
121
|
const [showClear, setShowClear] = useState(false);
|
|
124
122
|
|
|
125
123
|
const _isMobile = isMobile.any();
|
|
@@ -845,7 +843,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
845
843
|
clearAble: true,
|
|
846
844
|
onRemove: e => onRemove(e, value),
|
|
847
845
|
style: {
|
|
848
|
-
margin: '3px 0'
|
|
846
|
+
margin: '3px 0',
|
|
847
|
+
width: '100%'
|
|
849
848
|
}
|
|
850
849
|
});
|
|
851
850
|
}
|
|
@@ -1056,7 +1055,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1056
1055
|
clearAble: true,
|
|
1057
1056
|
onRemove: e => onRemove(e, value),
|
|
1058
1057
|
style: {
|
|
1059
|
-
margin: '3px 0'
|
|
1058
|
+
margin: '3px 0',
|
|
1059
|
+
width: '100%'
|
|
1060
1060
|
}
|
|
1061
1061
|
});
|
|
1062
1062
|
}
|
|
@@ -1085,8 +1085,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1085
1085
|
const icon = getIconFromData(data);
|
|
1086
1086
|
const valueWithIcon = jsx(Fragment, null, icon && jsx("div", {
|
|
1087
1087
|
css: DropdownIconCSS
|
|
1088
|
-
}, icon), jsx(
|
|
1089
|
-
|
|
1088
|
+
}, icon), jsx(Typography, {
|
|
1089
|
+
type: 'p1',
|
|
1090
|
+
lineClamp: 1,
|
|
1091
|
+
hoverTooltip: !_isMobile
|
|
1090
1092
|
}, text));
|
|
1091
1093
|
const el = document.createElement('div');
|
|
1092
1094
|
el.style.cssText = 'display: flex; align-items: center; min-height:24px;';
|
|
@@ -1096,17 +1098,43 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1096
1098
|
}
|
|
1097
1099
|
};
|
|
1098
1100
|
|
|
1099
|
-
useImperativeHandle(
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1101
|
+
useImperativeHandle(reference, () => {
|
|
1102
|
+
const currentRef = dropdownRef.current || {};
|
|
1103
|
+
const _instance = {
|
|
1104
|
+
closeDropdown: () => {
|
|
1105
|
+
closeDropdown();
|
|
1106
|
+
},
|
|
1107
|
+
showDropdown: () => {
|
|
1108
|
+
showDropdown();
|
|
1109
|
+
},
|
|
1110
|
+
onClear,
|
|
1111
|
+
setPreviousValue,
|
|
1112
|
+
setValue: value => {
|
|
1113
|
+
if (allValue[unique][allValue[unique].length - 1] !== value) {
|
|
1114
|
+
allValue[unique].push(value);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
setValueIntoInput(value);
|
|
1118
|
+
}
|
|
1119
|
+
}; // methods
|
|
1120
|
+
|
|
1121
|
+
_instance.__proto__ = {}; // hidden methods
|
|
1122
|
+
|
|
1123
|
+
currentRef.instance = _instance; // keep old method
|
|
1124
|
+
|
|
1125
|
+
currentRef.closeDropdown = () => closeDropdown();
|
|
1126
|
+
|
|
1127
|
+
currentRef.showDropdown = () => showDropdown();
|
|
1128
|
+
|
|
1129
|
+
currentRef.onClear = onClear, currentRef.setPreviousValue = setPreviousValue, currentRef.setValue = value => {
|
|
1130
|
+
if (allValue[unique][allValue[unique].length - 1] !== value) {
|
|
1131
|
+
allValue[unique].push(value);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
setValueIntoInput(value);
|
|
1135
|
+
}, currentRef.DOM = dropdownRef.current;
|
|
1136
|
+
return currentRef;
|
|
1137
|
+
});
|
|
1110
1138
|
useEffect(() => {
|
|
1111
1139
|
setShowClear(clearAble && checkHasValue(valueProp) && !disabled && !readOnly && !loading);
|
|
1112
1140
|
}, [clearAble, valueProp, disabled, readOnly, loading]);
|
|
@@ -1126,7 +1154,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1126
1154
|
};
|
|
1127
1155
|
}, [valueObjectDefault]);
|
|
1128
1156
|
useEffect(() => {
|
|
1129
|
-
!!refs && refs(dropdownRef);
|
|
1130
1157
|
allValue[unique] = [];
|
|
1131
1158
|
|
|
1132
1159
|
if (defaultValue !== undefined && JSON.stringify(defaultValue) !== '[]') {
|
|
@@ -1190,9 +1217,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1190
1217
|
};
|
|
1191
1218
|
}
|
|
1192
1219
|
}, [loading]);
|
|
1193
|
-
useEffect(() => {
|
|
1194
|
-
setErrorState(error && (!valueProp && valueProp !== 0 || (valueProp === null || valueProp === void 0 ? void 0 : valueProp.length) === 0));
|
|
1195
|
-
}, [error, valueProp]);
|
|
1196
1220
|
useEffect(() => {
|
|
1197
1221
|
if (valueProp !== undefined && (!boxRef.current || children || JSON.stringify(valueProp) !== JSON.stringify(currentValue[unique]))) {
|
|
1198
1222
|
setValueIntoInput(valueProp);
|
|
@@ -1309,7 +1333,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1309
1333
|
className: ['DGN-UI-Dropdown-Form', openState && 'dropdown-showing'].join(' ').trim().replace(/\s+/g, ' '),
|
|
1310
1334
|
style: formStyle
|
|
1311
1335
|
}, jsx("div", {
|
|
1312
|
-
css: _InputCSS
|
|
1336
|
+
css: _InputCSS,
|
|
1337
|
+
className: 'DGN-UI-Dropdown-Form-Input'
|
|
1313
1338
|
}, multiple ? jsx("div", { ...inputProps,
|
|
1314
1339
|
style: {
|
|
1315
1340
|
cursor: 'text',
|
|
@@ -1367,7 +1392,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1367
1392
|
disabled: disabled || readOnly
|
|
1368
1393
|
})));
|
|
1369
1394
|
}, [viewType, inputProps, inputStyle, multiple, clearAble, onChange, disabled, readOnly, loading, renderSelectedItem, placeholder, itemMultipleSize, openState, showClear]);
|
|
1370
|
-
const errorComp = useMemo(() =>
|
|
1395
|
+
const errorComp = useMemo(() => error && jsx(HelperText, {
|
|
1371
1396
|
disabled: disabled,
|
|
1372
1397
|
style: {
|
|
1373
1398
|
minHeight: '16px',
|
|
@@ -1375,13 +1400,13 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1375
1400
|
top: '100%',
|
|
1376
1401
|
...errorStyle
|
|
1377
1402
|
}
|
|
1378
|
-
}, error), [error,
|
|
1403
|
+
}, error), [error, disabled, errorStyle]);
|
|
1379
1404
|
/* End component */
|
|
1380
1405
|
|
|
1381
1406
|
return jsx(Fragment, null, jsx("div", {
|
|
1382
1407
|
ref: dropdownRef,
|
|
1383
1408
|
css: DropdownRootCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem, loading, showClear),
|
|
1384
|
-
className: ['DGN-UI-Dropdown', className,
|
|
1409
|
+
className: ['DGN-UI-Dropdown', className, error && 'error', loading && 'dgn-dropdown-loading', disabled ? 'disabled' : readOnly && 'readOnly'].join(' ').trim().replace(/\s+/g, ' '),
|
|
1385
1410
|
style: style
|
|
1386
1411
|
}, labelComp, inputComp, errorComp), openState ? /*#__PURE__*/createPortal(showDropdown(), document.body) : null);
|
|
1387
1412
|
}));
|
|
@@ -1389,7 +1414,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1389
1414
|
|
|
1390
1415
|
const InputCSS = (multiple, renderSelectedItem, clearAble) => css`
|
|
1391
1416
|
${flexRow};
|
|
1392
|
-
|
|
1417
|
+
width: 100%;
|
|
1393
1418
|
${!multiple && renderSelectedItem ? `width: calc(100% - 34px${clearAble ? ' - 18px' : ''})` : ''}
|
|
1394
1419
|
`;
|
|
1395
1420
|
|
|
@@ -1401,11 +1426,15 @@ const DropdownIconCSS = css`
|
|
|
1401
1426
|
height: inherit;
|
|
1402
1427
|
margin-right: 8px;
|
|
1403
1428
|
height: 32px;
|
|
1429
|
+
min-height: 32px;
|
|
1404
1430
|
width: 32px;
|
|
1431
|
+
min-width: 32px;
|
|
1405
1432
|
border-radius: 16px;
|
|
1406
1433
|
img {
|
|
1407
1434
|
height: 32px;
|
|
1435
|
+
min-height: 32px;
|
|
1408
1436
|
width: 32px;
|
|
1437
|
+
min-width: 32px;
|
|
1409
1438
|
object-fit: cover;
|
|
1410
1439
|
}
|
|
1411
1440
|
`;
|
|
@@ -1427,8 +1456,7 @@ const DropdownInputCSS = (viewType, multiple, placeholder, itemMultipleSize, ren
|
|
|
1427
1456
|
${flexWrap};
|
|
1428
1457
|
${overflowHidden};
|
|
1429
1458
|
${breakWord};
|
|
1430
|
-
|
|
1431
|
-
${!multiple ? 'min-height: 24px; max-width: 100%; white-space: nowrap;' : ''}
|
|
1459
|
+
${!multiple ? 'min-height: 24px; max-width: 100%;' : ''}
|
|
1432
1460
|
&::after {
|
|
1433
1461
|
${flexRow};
|
|
1434
1462
|
${positionAbsolute};
|
|
@@ -1459,10 +1487,14 @@ const DropdownInputCSS = (viewType, multiple, placeholder, itemMultipleSize, ren
|
|
|
1459
1487
|
min-width: 24px;
|
|
1460
1488
|
` : `
|
|
1461
1489
|
height: 24px;
|
|
1490
|
+
min-height: 24px;
|
|
1462
1491
|
width: 24px;
|
|
1492
|
+
min-width: 24px;
|
|
1463
1493
|
img {
|
|
1464
1494
|
height: 24px;
|
|
1495
|
+
min-height: 24px;
|
|
1465
1496
|
width: 24px;
|
|
1497
|
+
min-width: 24px;
|
|
1466
1498
|
}
|
|
1467
1499
|
`}
|
|
1468
1500
|
}
|
|
@@ -1488,7 +1520,7 @@ const DropdownFormCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1488
1520
|
${alignCenter};
|
|
1489
1521
|
${positionRelative};
|
|
1490
1522
|
${borderBox};
|
|
1491
|
-
|
|
1523
|
+
width: 100%;
|
|
1492
1524
|
padding-bottom: ${multiple ? 1 : 4}px;
|
|
1493
1525
|
padding-top: ${multiple ? 1 : 4}px;
|
|
1494
1526
|
&:not(:focus-within):hover {
|
|
@@ -1543,7 +1575,7 @@ const DropdownFormCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1543
1575
|
${borderRadius4px};
|
|
1544
1576
|
${borderBox};
|
|
1545
1577
|
${border(1, rest)};
|
|
1546
|
-
|
|
1578
|
+
width: 100%;
|
|
1547
1579
|
min-height: 40px;
|
|
1548
1580
|
&:not(:focus-within):hover {
|
|
1549
1581
|
background-color: ${hover};
|
|
@@ -1648,7 +1680,6 @@ const DropdownRootCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1648
1680
|
${displayBlock};
|
|
1649
1681
|
${positionRelative};
|
|
1650
1682
|
margin-bottom: 20px;
|
|
1651
|
-
/* min-width: 150px; */
|
|
1652
1683
|
height: max-content;
|
|
1653
1684
|
&.error {
|
|
1654
1685
|
.css-${DropdownFormCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem).name} {
|
|
@@ -1663,8 +1694,6 @@ const DropdownRootCSS = (viewType, multiple, placeholder, itemMultipleSize, rend
|
|
|
1663
1694
|
}
|
|
1664
1695
|
&.dgn-dropdown-loading,
|
|
1665
1696
|
&.disabled {
|
|
1666
|
-
${pointerEventsNone};
|
|
1667
|
-
${userSelectNone};
|
|
1668
1697
|
.css-${DropdownFormCSS(viewType, multiple, placeholder, itemMultipleSize, renderSelectedItem).name} {
|
|
1669
1698
|
border-color: ${systemDisabled};
|
|
1670
1699
|
.css-${IconCSS(viewType, loading, showClear).name} {
|
|
@@ -1864,9 +1893,6 @@ Dropdown.propTypes = {
|
|
|
1864
1893
|
/** The array of elements that appear in the dropdown */
|
|
1865
1894
|
dataSource: PropTypes.array,
|
|
1866
1895
|
|
|
1867
|
-
/** The function to get ref of Dropdown component */
|
|
1868
|
-
refs: PropTypes.func,
|
|
1869
|
-
|
|
1870
1896
|
/** function displays items by custom<br/>
|
|
1871
1897
|
* renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
|
|
1872
1898
|
* --> such as: displayExpr={'name - role'}
|
|
@@ -1895,7 +1921,22 @@ Dropdown.propTypes = {
|
|
|
1895
1921
|
/** the contents in Dropdown box (Exp: TreeView) */
|
|
1896
1922
|
children: PropTypes.node,
|
|
1897
1923
|
|
|
1898
|
-
/**
|
|
1899
|
-
|
|
1924
|
+
/**
|
|
1925
|
+
* ref methods
|
|
1926
|
+
*
|
|
1927
|
+
* how to get component element? ref.current
|
|
1928
|
+
*
|
|
1929
|
+
* how to call method? ref.current.instance.{method}
|
|
1930
|
+
*
|
|
1931
|
+
* * showDropdown(): Show dropdown
|
|
1932
|
+
* * closeDropdown(): Close dropdown
|
|
1933
|
+
* * onClear(): Clear selected value
|
|
1934
|
+
* * setPreviousValue(): Set value to previous value
|
|
1935
|
+
* * setValue(value): Set value of dropdown
|
|
1936
|
+
* * @param {value} - string || number || array
|
|
1937
|
+
*/
|
|
1938
|
+
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
1939
|
+
current: PropTypes.instanceOf(Element)
|
|
1940
|
+
})])
|
|
1900
1941
|
};
|
|
1901
1942
|
export default Dropdown;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import { useState, useRef, forwardRef, useMemo, useCallback, useEffect } from 'react';
|
|
4
|
+
import { useState, useRef, forwardRef, useMemo, useCallback, useEffect, useImperativeHandle } from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { jsx, css } from '@emotion/core';
|
|
7
7
|
import locale from '../../../locale';
|
|
@@ -16,6 +16,7 @@ const NumberInputRoot = css`
|
|
|
16
16
|
margin-bottom: 20px;
|
|
17
17
|
`;
|
|
18
18
|
const regexValidNumber = /[^0-9.,-]/g;
|
|
19
|
+
const regexThousandNumber = /(\d)(?=(\d{3})+\b)/g;
|
|
19
20
|
const NumberInput = /*#__PURE__*/forwardRef(({
|
|
20
21
|
viewType,
|
|
21
22
|
required,
|
|
@@ -33,22 +34,14 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
33
34
|
placeholder,
|
|
34
35
|
startIcon,
|
|
35
36
|
endIcon,
|
|
36
|
-
valueTypeReturn,
|
|
37
|
-
autoComplete,
|
|
38
37
|
autoFocus,
|
|
39
38
|
disabled,
|
|
40
39
|
readOnly,
|
|
41
|
-
refs,
|
|
42
40
|
inputRef,
|
|
43
41
|
inputProps,
|
|
44
|
-
iconStyle,
|
|
45
42
|
inputStyle,
|
|
46
|
-
labelProps,
|
|
47
|
-
errorProps,
|
|
48
43
|
error,
|
|
49
|
-
format,
|
|
50
44
|
onChange,
|
|
51
|
-
onBlur,
|
|
52
45
|
onFocus,
|
|
53
46
|
onInput,
|
|
54
47
|
onKeyDown,
|
|
@@ -56,13 +49,15 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
56
49
|
validates,
|
|
57
50
|
delayOnChange,
|
|
58
51
|
fixedDecimalDigit,
|
|
59
|
-
|
|
52
|
+
className
|
|
60
53
|
}, reference) => {
|
|
61
54
|
inputRef = inputRef || useRef(null);
|
|
62
55
|
const pos = useRef(null);
|
|
63
56
|
const ref = useRef(null);
|
|
64
57
|
const globalRef = useRef({});
|
|
65
|
-
const [value, setValue] = useState(defaultValue);
|
|
58
|
+
const [value, setValue] = useState(defaultValue); // nếu không cho nhập số âm mà max là âm thì remove giá trị max
|
|
59
|
+
|
|
60
|
+
if (max < 0 && disabledNegative) max = null;
|
|
66
61
|
|
|
67
62
|
if (thousandSymbol) {
|
|
68
63
|
thousandSymbol = useMemo(() => {
|
|
@@ -109,7 +104,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
109
104
|
pos.current = 2;
|
|
110
105
|
}
|
|
111
106
|
|
|
112
|
-
number[0] = (_number2 = number) === null || _number2 === void 0 ? void 0 : _number2[0].replace(
|
|
107
|
+
number[0] = (_number2 = number) === null || _number2 === void 0 ? void 0 : _number2[0].replace(regexThousandNumber, '$1' + thousandSymbol); // add thousand symbol to number
|
|
113
108
|
|
|
114
109
|
if (!decimalDigit) number.length = 1;else if (number[1]) number[1] = (_number$ = number[1]) === null || _number$ === void 0 ? void 0 : _number$.slice(0, decimalDigit || 0);
|
|
115
110
|
number = number.join(decimalSymbol); // keep focus position
|
|
@@ -121,7 +116,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
121
116
|
}
|
|
122
117
|
|
|
123
118
|
return number;
|
|
124
|
-
}, [decimalSymbol, value]);
|
|
119
|
+
}, [decimalSymbol, max, value]);
|
|
125
120
|
/**
|
|
126
121
|
* Convert money to format number
|
|
127
122
|
* @param vl {string} - value
|
|
@@ -145,6 +140,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
145
140
|
var _e$target$value;
|
|
146
141
|
|
|
147
142
|
let valueT = (_e$target$value = e.target.value) !== null && _e$target$value !== void 0 ? _e$target$value : e.value;
|
|
143
|
+
if (disabledNegative && Number(valueT || 0) < 0) return;
|
|
148
144
|
valueT = parseNumberToMoney(valueT);
|
|
149
145
|
const returnValue = convertMoneyToNumber(valueT);
|
|
150
146
|
e.value = globalRef.current.value = !isNaN(parseFloat(returnValue)) ? parseFloat(returnValue) : null;
|
|
@@ -194,7 +190,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
194
190
|
keyCode === 188 || // ,
|
|
195
191
|
(ctrlKey || metaKey) && (keyCode === 65 || keyCode === 67 || keyCode === 86) || // ctrl + A, ctrl + C, ctrl + V
|
|
196
192
|
keyCode === 46 || // key delete
|
|
197
|
-
keyCode === 189
|
|
193
|
+
keyCode === 189 || // -
|
|
194
|
+
keyCode === 9; // tab
|
|
198
195
|
// The key is delete (|| remove) and focus after the thousand digit
|
|
199
196
|
|
|
200
197
|
const removeDot = keyCode === 8 && selectionEnd - selectionStart <= 1 && value.charAt(selectionEnd - 1) === thousandSymbol; // Decimal
|
|
@@ -252,12 +249,25 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
252
249
|
useEffect(() => {
|
|
253
250
|
var _valueProps;
|
|
254
251
|
|
|
255
|
-
if (typeof valueProps !== 'undefined')
|
|
252
|
+
if (typeof valueProps !== 'undefined') if (disabledNegative && Number(valueProps || 0) < 0) {
|
|
253
|
+
// nếu không cho nhập số âm mà value đầu vào là âm thì reset value về 0
|
|
254
|
+
valueProps = clamp(0, min, max);
|
|
255
|
+
}
|
|
256
|
+
setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
|
|
256
257
|
}, [valueProps]);
|
|
258
|
+
useImperativeHandle(reference, () => {
|
|
259
|
+
const currentRef = ref.current || {};
|
|
260
|
+
const _instance = {}; // methods
|
|
261
|
+
|
|
262
|
+
_instance.__proto__ = {}; // hidden methods
|
|
263
|
+
|
|
264
|
+
currentRef.instance = _instance;
|
|
265
|
+
return currentRef;
|
|
266
|
+
});
|
|
257
267
|
return jsx("div", {
|
|
258
268
|
ref: ref,
|
|
259
269
|
css: NumberInputRoot,
|
|
260
|
-
|
|
270
|
+
className: ['DGN-UI-NumberInput', className].join(' ').trim().replace(/\s+/g, ' ')
|
|
261
271
|
}, !!label && jsx(Label, {
|
|
262
272
|
required: required,
|
|
263
273
|
disabled: disabled
|
|
@@ -315,15 +325,13 @@ NumberInput.defaultProps = {
|
|
|
315
325
|
decimalDigit: 0,
|
|
316
326
|
thousandSeparator: false,
|
|
317
327
|
min: -Infinity,
|
|
318
|
-
max: Infinity
|
|
328
|
+
max: Infinity,
|
|
329
|
+
className: ''
|
|
319
330
|
};
|
|
320
331
|
NumberInput.propTypes = {
|
|
321
332
|
/** the type of border you want to display */
|
|
322
333
|
viewType: PropTypes.oneOf(['underlined', 'outlined']),
|
|
323
334
|
|
|
324
|
-
/** the type of value which you want to return */
|
|
325
|
-
valueTypeReturn: PropTypes.oneOf(['number', 'string']),
|
|
326
|
-
|
|
327
335
|
/** separator symbol */
|
|
328
336
|
decimalSymbol: PropTypes.oneOf([',', '.']),
|
|
329
337
|
|
|
@@ -354,9 +362,6 @@ NumberInput.propTypes = {
|
|
|
354
362
|
/** error for input */
|
|
355
363
|
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
356
364
|
|
|
357
|
-
/** type auto complete of input (like new-password) */
|
|
358
|
-
autoComplete: PropTypes.string,
|
|
359
|
-
|
|
360
365
|
/** icon at start */
|
|
361
366
|
startIcon: PropTypes.any,
|
|
362
367
|
|
|
@@ -387,25 +392,6 @@ NumberInput.propTypes = {
|
|
|
387
392
|
/** style inline of input in NumberInput component */
|
|
388
393
|
inputStyle: PropTypes.object,
|
|
389
394
|
|
|
390
|
-
/** any props of label in NumberInput component */
|
|
391
|
-
labelProps: PropTypes.object,
|
|
392
|
-
|
|
393
|
-
/** any props of error in NumberInput component */
|
|
394
|
-
errorProps: PropTypes.object,
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* the format to display value<br/>
|
|
398
|
-
* * function: value => function(value)<br/>
|
|
399
|
-
* * string: Example: '#.###', '# ###', '#.### 2%', '#.### %%'<br/>
|
|
400
|
-
* #: integer part digit<br/>
|
|
401
|
-
* . / '_': separator symbol<br/>
|
|
402
|
-
* %: decimal digit, '2%' === '%%'
|
|
403
|
-
*/
|
|
404
|
-
format: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
405
|
-
|
|
406
|
-
/** The function to get ref of NumberInput component */
|
|
407
|
-
refs: PropTypes.func,
|
|
408
|
-
|
|
409
395
|
/** validation value, argument can:<br/>
|
|
410
396
|
* * string: the validation rule. Example required.<br/>
|
|
411
397
|
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
@@ -425,9 +411,6 @@ NumberInput.propTypes = {
|
|
|
425
411
|
/** on change function */
|
|
426
412
|
onChange: PropTypes.func,
|
|
427
413
|
|
|
428
|
-
/** on blur function */
|
|
429
|
-
onBlur: PropTypes.func,
|
|
430
|
-
|
|
431
414
|
/** on focus function */
|
|
432
415
|
onFocus: PropTypes.func,
|
|
433
416
|
|
|
@@ -441,6 +424,9 @@ NumberInput.propTypes = {
|
|
|
441
424
|
delayOnChange: PropTypes.number,
|
|
442
425
|
|
|
443
426
|
/** inputRef of delayOnChange component */
|
|
444
|
-
thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])])
|
|
427
|
+
thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])]),
|
|
428
|
+
|
|
429
|
+
/** className of component */
|
|
430
|
+
className: PropTypes.string
|
|
445
431
|
};
|
|
446
432
|
export default NumberInput;
|
|
@@ -9,6 +9,10 @@ import { randomString, useOnClickOutside } from '../../../utils';
|
|
|
9
9
|
import theme from '../../../theme/settings';
|
|
10
10
|
import Swiper from './swiper';
|
|
11
11
|
import { typography } from '../../../styles/typography';
|
|
12
|
+
import { useTheme } from '../../../theme';
|
|
13
|
+
const {
|
|
14
|
+
zIndex
|
|
15
|
+
} = useTheme();
|
|
12
16
|
|
|
13
17
|
const formatDimension = x => {
|
|
14
18
|
const regexPercent = /^\d+%$/;
|