diginet-core-ui 1.4.54 → 1.4.55-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/MHRM09N1401.svg +14 -0
- package/assets/images/menu/dhr/MHRM09N1402.svg +15 -0
- package/assets/images/menu/dhr/MHRM21N0001.svg +13 -0
- package/components/accordion/details.js +1 -1
- package/components/accordion/group.js +1 -1
- package/components/accordion/index.js +1 -1
- package/components/accordion/summary.js +1 -1
- package/components/alert/index.js +1 -1
- package/components/alert/notify.js +1 -1
- package/components/avatar/index.js +2 -2
- package/components/badge/index.js +1 -1
- package/components/breadcrumb/index.js +1 -1
- package/components/button/icon.js +1 -1
- package/components/button/index.js +1 -1
- package/components/button/more.js +16 -7
- package/components/button/ripple-effect.js +1 -1
- package/components/card/body.js +1 -1
- package/components/card/extra.js +1 -1
- package/components/card/footer.js +1 -1
- package/components/card/header.js +1 -1
- package/components/card/index.js +1 -1
- package/components/chart/Pie/Circle.js +1 -1
- package/components/chart/Pie/Sector.js +1 -1
- package/components/chart/Pie/index.js +1 -1
- package/components/chart/Pie-v2/Circle.js +1 -1
- package/components/chart/Pie-v2/Sector.js +1 -1
- package/components/chart/Pie-v2/index.js +1 -1
- package/components/chart/bar/Bar.js +1 -1
- package/components/chart/bar/index.js +1 -1
- package/components/chart/bar-v2/Bar.js +1 -1
- package/components/chart/bar-v2/index.js +1 -1
- package/components/chart/line/index.js +1 -1
- package/components/chart/line-v2/index.js +1 -1
- package/components/check-text/index.js +1 -1
- package/components/check-text/interview-confirmation.js +1 -1
- package/components/check-text/interview-status.js +1 -1
- package/components/chip/index.js +1 -1
- package/components/collapse/index.js +1 -1
- package/components/divider/index.js +1 -1
- package/components/form-control/attachment/index.js +22 -22
- package/components/form-control/calendar/function.js +1 -1
- package/components/form-control/calendar/index.js +2 -2
- package/components/form-control/calendar/range.js +1 -1
- package/components/form-control/checkbox/index.js +1 -1
- package/components/form-control/control/index.js +1 -1
- package/components/form-control/date-input/index.js +1 -1
- package/components/form-control/date-picker/index.js +1 -1
- package/components/form-control/date-range-picker/index.js +273 -38
- package/components/form-control/dropdown/index.js +77 -54
- package/components/form-control/dropdown-box/index.js +64 -22
- package/components/form-control/form-group/index.js +1 -1
- package/components/form-control/helper-text/index.js +1 -1
- package/components/form-control/input-base/UncontrolledInputBase.js +1 -1
- package/components/form-control/input-base/index.js +1 -1
- package/components/form-control/label/index.js +1 -1
- package/components/form-control/money-input/index.js +1 -1
- package/components/form-control/number-input/index2.js +23 -20
- package/components/form-control/password-input/index.js +1 -1
- package/components/form-control/phone-input/index.js +1 -1
- package/components/form-control/radio/index.js +1 -1
- package/components/form-control/text-input/index.js +1 -1
- package/components/form-control/time-picker/index.js +1 -1
- package/components/form-control/time-picker/v2/index.js +1 -1
- package/components/form-control/toggle/index.js +1 -1
- package/components/form-view/input.js +1 -1
- package/components/grid/index.js +1 -1
- package/components/image/index.js +1 -1
- package/components/list/list-item-action.js +1 -1
- package/components/list/list-item-icon.js +1 -1
- package/components/list/list-item-text.js +1 -1
- package/components/list/list-item.js +1 -1
- package/components/list/list.js +1 -1
- package/components/list/sub-header.js +1 -1
- package/components/modal/body.js +1 -1
- package/components/modal/footer.js +1 -1
- package/components/modal/header.js +1 -1
- package/components/modal/index.js +1 -1
- package/components/modal/modal.js +1 -1
- package/components/others/option-wrapper/index.js +1 -1
- package/components/paging/page-info.js +35 -35
- package/components/paging/page-selector.js +1 -1
- package/components/paper/index.js +1 -1
- package/components/popover/body.js +1 -1
- package/components/popover/footer.js +1 -1
- package/components/popover/header.js +1 -1
- package/components/popover/index.js +14 -14
- package/components/popup/index.js +1 -1
- package/components/popup/v2/index.js +1 -1
- package/components/progress/circular.js +1 -1
- package/components/progress/linear.js +1 -1
- package/components/rating/index.js +1 -1
- package/components/skeleton/index.js +1 -1
- package/components/slider/slider-container.js +1 -1
- package/components/slider/slider-item.js +1 -1
- package/components/status/index.js +1 -1
- package/components/tab/tab-container.js +1 -1
- package/components/tab/tab-header.js +1 -1
- package/components/tab/tab-panel.js +1 -1
- package/components/tab/tab.js +1 -1
- package/components/tooltip/index.js +1 -1
- package/components/transfer/index.js +1 -1
- package/components/tree-view/index.js +1 -1
- package/components/typography/index.js +1 -1
- package/global/index.js +3 -0
- package/icons/basic.js +134 -0
- package/icons/effect.js +1 -1
- package/icons/menu/v2/index.js +1 -1
- package/package.json +78 -44
- package/readme.md +10 -0
|
@@ -47,7 +47,7 @@ const uniqBy = (arr, iteratee) => {
|
|
|
47
47
|
return true;
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
|
-
const Dropdown = /*#__PURE__*/memo(
|
|
50
|
+
const Dropdown = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
51
51
|
if (!reference) reference = useRef(null);
|
|
52
52
|
const theme = useTheme();
|
|
53
53
|
const {
|
|
@@ -63,6 +63,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
63
63
|
action = {},
|
|
64
64
|
allowInput,
|
|
65
65
|
allowSearch,
|
|
66
|
+
allowDuplicateValue,
|
|
66
67
|
children,
|
|
67
68
|
className,
|
|
68
69
|
clearAble,
|
|
@@ -112,7 +113,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
112
113
|
valueObjectDefault,
|
|
113
114
|
viewType,
|
|
114
115
|
defaultValue,
|
|
115
|
-
disabled
|
|
116
|
+
disabled,
|
|
117
|
+
selectAll,
|
|
118
|
+
selectAllLabel
|
|
116
119
|
} = props;
|
|
117
120
|
const selectBox = multiple && selectBoxProp === undefined ? true : selectBoxProp;
|
|
118
121
|
const searchExpr = typeof searchExprProp === 'string' ? [searchExprProp] : searchExprProp;
|
|
@@ -176,6 +179,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
176
179
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox, theme);
|
|
177
180
|
const _DropdownRootCSS = DropdownRootCSS(_DropdownFormCSS.name, _DropdownInputCSS.name, theme);
|
|
178
181
|
const _CheckBoxCSS = CheckBoxCSS(theme);
|
|
182
|
+
const handleDataSource = data => {
|
|
183
|
+
let dataCustom = (data !== undefined ? data : dataSource) || [];
|
|
184
|
+
return selectAll ? [{
|
|
185
|
+
[valueExpr]: 'all'
|
|
186
|
+
}, ...dataCustom] : dataCustom;
|
|
187
|
+
};
|
|
179
188
|
|
|
180
189
|
/* Start handler */
|
|
181
190
|
const setShowDropdown = () => {
|
|
@@ -288,10 +297,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
288
297
|
});
|
|
289
298
|
};
|
|
290
299
|
|
|
291
|
-
/**
|
|
292
|
-
* So sánh text đầu vào cáo map với txtSearch
|
|
293
|
-
* @param text
|
|
294
|
-
* @return {boolean}
|
|
300
|
+
/**
|
|
301
|
+
* So sánh text đầu vào cáo map với txtSearch
|
|
302
|
+
* @param text
|
|
303
|
+
* @return {boolean}
|
|
295
304
|
*/
|
|
296
305
|
const handleRenderBySearch = (text = '') => {
|
|
297
306
|
if (text === null || text === undefined) text = '';
|
|
@@ -304,24 +313,28 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
304
313
|
} else return text.toLowerCase().includes(txtSearch.toLowerCase());
|
|
305
314
|
};
|
|
306
315
|
|
|
307
|
-
/**
|
|
308
|
-
* 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
|
|
309
|
-
* @param data {object} rowData of dataSource
|
|
310
|
-
* @return {string}
|
|
316
|
+
/**
|
|
317
|
+
* 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
|
|
318
|
+
* @param data {object} rowData of dataSource
|
|
319
|
+
* @return {string}
|
|
311
320
|
*/
|
|
312
321
|
const displayValue = data => {
|
|
313
322
|
let text = '';
|
|
323
|
+
let isReplace = true;
|
|
314
324
|
if (data || data === 0) {
|
|
315
325
|
displayExpr = displayExpr || valueExpr;
|
|
316
326
|
let mask = data === null || data === void 0 ? void 0 : data[displayExpr];
|
|
317
327
|
// convert {id} - {name} to {<data[id]>} - {<data[name]>}
|
|
318
|
-
if (
|
|
328
|
+
if (selectAll && (data === null || data === void 0 ? void 0 : data[valueExpr]) === 'all') {
|
|
329
|
+
isReplace = false;
|
|
330
|
+
text = selectAllLabel || getGlobal('selectAll');
|
|
331
|
+
} else if (!mask && regexBetween.test(displayExpr)) {
|
|
319
332
|
var _displayExpr;
|
|
320
333
|
mask = (_displayExpr = displayExpr) === null || _displayExpr === void 0 ? void 0 : _displayExpr.replace(regexBetween, _ => (data === null || data === void 0 ? void 0 : data[_]) || '');
|
|
321
334
|
} else if (!mask) {
|
|
322
335
|
mask = typeof data !== 'object' ? data : '';
|
|
323
336
|
}
|
|
324
|
-
text = mask.toString().replace(regexInclude, '');
|
|
337
|
+
if (isReplace) text = mask.toString().replace(regexInclude, '');
|
|
325
338
|
}
|
|
326
339
|
return text;
|
|
327
340
|
};
|
|
@@ -389,7 +402,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
389
402
|
type: 'p1'
|
|
390
403
|
}, displayText);
|
|
391
404
|
if (multiple && selectBox) {
|
|
392
|
-
|
|
405
|
+
let checked = valueMulti.includes(value);
|
|
406
|
+
if (selectAll && value === 'all') checked = selectAll && value === 'all' && valueMulti.length > 0;
|
|
393
407
|
const isMaximumSelection = maximumSelectionLength === (valueMulti === null || valueMulti === void 0 ? void 0 : valueMulti.length);
|
|
394
408
|
itemDisabled = itemDisabled || isMaximumSelection && !checked;
|
|
395
409
|
items.push(jsx("div", {
|
|
@@ -402,6 +416,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
402
416
|
},
|
|
403
417
|
tabIndex: -1
|
|
404
418
|
}, jsx(Checkbox, {
|
|
419
|
+
determinate: !(selectAll && (data === null || data === void 0 ? void 0 : data[valueExpr]) === 'all' && (valueMulti || []).length !== (dataSourceState || []).length - 1),
|
|
405
420
|
css: _CheckBoxCSS,
|
|
406
421
|
forTreeView: true,
|
|
407
422
|
checked: checked,
|
|
@@ -437,7 +452,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
437
452
|
}, items !== null && items !== void 0 && items.length ? items : EmptyDataText);
|
|
438
453
|
};
|
|
439
454
|
const mapTreeView = () => {
|
|
440
|
-
console.log('here');
|
|
441
455
|
return jsx("div", {
|
|
442
456
|
css: _DropdownListCSS,
|
|
443
457
|
ref: dropdownListRef,
|
|
@@ -639,7 +653,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
639
653
|
const total = data && data.total ? data.total : data === null || data === void 0 ? void 0 : data.length;
|
|
640
654
|
setTotalState(total);
|
|
641
655
|
}
|
|
642
|
-
setDataSourceState(isReset ? rows : dataSourceState.concat(rows));
|
|
656
|
+
setDataSourceState(handleDataSource(isReset ? rows : dataSourceState.concat(rows)));
|
|
643
657
|
}
|
|
644
658
|
};
|
|
645
659
|
setLoadingState(true);
|
|
@@ -703,8 +717,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
703
717
|
} else if (multiple) {
|
|
704
718
|
if (!Array.isArray(currentValue[unique])) currentValue[unique] = [];
|
|
705
719
|
// const newValueArr = [...currentValue[unique]];
|
|
706
|
-
|
|
707
|
-
if (
|
|
720
|
+
let newValueArrState = [...valueMulti];
|
|
721
|
+
if (selectAll && value === 'all') {
|
|
722
|
+
newValueArrState = e !== null && e !== void 0 && e.value ? dataSourceState.flatMap(item => (item === null || item === void 0 ? void 0 : item[valueExpr]) === 'all' ? [] : [item === null || item === void 0 ? void 0 : item[valueExpr]]) : [];
|
|
723
|
+
} else if (!newValueArrState.some(v => JSON.stringify(v) === JSON.stringify(value))) {
|
|
708
724
|
// newValueArr.push(value);
|
|
709
725
|
newValueArrState.push(value);
|
|
710
726
|
} else {
|
|
@@ -717,7 +733,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
717
733
|
data
|
|
718
734
|
});
|
|
719
735
|
} else {
|
|
720
|
-
|
|
736
|
+
// biến allowDuplicateValue chỉ dùng trong trường hợp đặc biệt ID 300034
|
|
737
|
+
const isChanged = allowDuplicateValue ? allowDuplicateValue : currentValue[unique] !== value;
|
|
721
738
|
if (isChanged) {
|
|
722
739
|
if (valueProp === undefined) {
|
|
723
740
|
allValue[unique].push(value);
|
|
@@ -914,7 +931,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
914
931
|
setTotalState(total);
|
|
915
932
|
}, [total]);
|
|
916
933
|
useEffect(() => {
|
|
917
|
-
setDataSourceState(dataSource || []);
|
|
934
|
+
setDataSourceState(handleDataSource(dataSource || []));
|
|
918
935
|
}, [dataSource]);
|
|
919
936
|
useEffect(() => {
|
|
920
937
|
setShowClear(clearAble && checkHasValue(valueProp !== null && valueProp !== void 0 ? valueProp : defaultValue) && !disabled && !readOnly && !loadingState);
|
|
@@ -1708,6 +1725,8 @@ Dropdown.propTypes = {
|
|
|
1708
1725
|
}),
|
|
1709
1726
|
/** If `true`, the input box for searching will be displayed. */
|
|
1710
1727
|
allowSearch: PropTypes.bool,
|
|
1728
|
+
/** If `true`, click on same item will add its value instead of remove it (better not use this, only for specific situation). */
|
|
1729
|
+
allowDuplicateValue: PropTypes.bool,
|
|
1711
1730
|
/** If `true`, the input value will be added when user hit Enter. */
|
|
1712
1731
|
allowInput: PropTypes.bool,
|
|
1713
1732
|
/** The content to be displayed inside the Dropdown box, such as TreeView. */
|
|
@@ -1724,9 +1743,9 @@ Dropdown.propTypes = {
|
|
|
1724
1743
|
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1725
1744
|
/** If `true`, the component is disabled. */
|
|
1726
1745
|
disabled: PropTypes.bool,
|
|
1727
|
-
/** The field name used for displaying text in the dropdown list.<br/>
|
|
1728
|
-
* Examples: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
1729
|
-
* Note: Do not use 'id - name', as it will return undefined.
|
|
1746
|
+
/** The field name used for displaying text in the dropdown list.<br/>
|
|
1747
|
+
* Examples: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
1748
|
+
* Note: Do not use 'id - name', as it will return undefined.
|
|
1730
1749
|
*/
|
|
1731
1750
|
displayExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1732
1751
|
/** Inline style for dropdown items. */
|
|
@@ -1735,14 +1754,14 @@ Dropdown.propTypes = {
|
|
|
1735
1754
|
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
1736
1755
|
/** Props applied to the [HelperText](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) element. */
|
|
1737
1756
|
helperTextProps: PropTypes.object,
|
|
1738
|
-
/** The field name used for displaying icons.<br/>
|
|
1739
|
-
* Example:<br/>
|
|
1740
|
-
* string: 'icon'<br/>
|
|
1741
|
-
* object: {<br/>
|
|
1742
|
-
* key: 'icon',<br/>
|
|
1743
|
-
* prefix: 'https://imglink.com',<br/>
|
|
1744
|
-
* suffix: '.jpg'<br/>
|
|
1745
|
-
* }
|
|
1757
|
+
/** The field name used for displaying icons.<br/>
|
|
1758
|
+
* Example:<br/>
|
|
1759
|
+
* string: 'icon'<br/>
|
|
1760
|
+
* object: {<br/>
|
|
1761
|
+
* key: 'icon',<br/>
|
|
1762
|
+
* prefix: 'https://imglink.com',<br/>
|
|
1763
|
+
* suffix: '.jpg'<br/>
|
|
1764
|
+
* }
|
|
1746
1765
|
*/
|
|
1747
1766
|
iconExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
|
1748
1767
|
key: PropTypes.string,
|
|
@@ -1776,8 +1795,8 @@ Dropdown.propTypes = {
|
|
|
1776
1795
|
onChange: PropTypes.func,
|
|
1777
1796
|
/** Callback function fired when the dropdown is closed. */
|
|
1778
1797
|
onClosed: PropTypes.func,
|
|
1779
|
-
/** Callback function fired when the input value changes.<br/>
|
|
1780
|
-
* If undefined, the filter function will run (default behavior).
|
|
1798
|
+
/** Callback function fired when the input value changes.<br/>
|
|
1799
|
+
* If undefined, the filter function will run (default behavior).
|
|
1781
1800
|
*/
|
|
1782
1801
|
onInput: PropTypes.func,
|
|
1783
1802
|
/** Callback function fired when a key is pressed down in the input. */
|
|
@@ -1790,27 +1809,31 @@ Dropdown.propTypes = {
|
|
|
1790
1809
|
placeholder: PropTypes.string,
|
|
1791
1810
|
/** If `true`, the component is read-only. */
|
|
1792
1811
|
readOnly: PropTypes.bool,
|
|
1793
|
-
/** Function used for custom rendering of items.<br/>
|
|
1794
|
-
* Example: `(data, index) => data.name + ' - ' + data.role`<br/>
|
|
1795
|
-
* This can be used as an alternative to `displayExpr`
|
|
1812
|
+
/** Function used for custom rendering of items.<br/>
|
|
1813
|
+
* Example: `(data, index) => data.name + ' - ' + data.role`<br/>
|
|
1814
|
+
* This can be used as an alternative to `displayExpr`
|
|
1796
1815
|
*/
|
|
1797
1816
|
renderItem: PropTypes.func,
|
|
1798
|
-
/** Function or field name used to display selected items.<br/>
|
|
1799
|
-
* Example: `(data, index) => index + ' - ' + data.name`<br/>
|
|
1817
|
+
/** Function or field name used to display selected items.<br/>
|
|
1818
|
+
* Example: `(data, index) => index + ' - ' + data.name`<br/>
|
|
1800
1819
|
*/
|
|
1801
1820
|
renderSelectedItem: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
1802
1821
|
/** If `true`, the label will indicate that the input is required. */
|
|
1803
1822
|
required: PropTypes.bool,
|
|
1804
|
-
/**
|
|
1805
|
-
* Duration to wait after entering search content before triggering a search.<br/>
|
|
1806
|
-
* Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
|
|
1807
|
-
* If `true`, the default delayOnInput will be used.
|
|
1823
|
+
/**
|
|
1824
|
+
* Duration to wait after entering search content before triggering a search.<br/>
|
|
1825
|
+
* Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
|
|
1826
|
+
* If `true`, the default delayOnInput will be used.
|
|
1808
1827
|
*/
|
|
1809
1828
|
searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
1810
1829
|
/** Specifies the field name or expression used to compare values with the search string. */
|
|
1811
1830
|
searchExpr: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
|
|
1812
1831
|
/** Specifies the comparison operation used to search items. */
|
|
1813
1832
|
searchMode: PropTypes.oneOf(['contains', 'startswith', 'equals']),
|
|
1833
|
+
/** If `true`, show select all check box. */
|
|
1834
|
+
selectAll: PropTypes.bool,
|
|
1835
|
+
/** The content display for label of checkbox select all */
|
|
1836
|
+
selectAllLabel: PropTypes.string,
|
|
1814
1837
|
/** If `true`, checkboxes will be shown next to each dropdown item. */
|
|
1815
1838
|
selectBox: PropTypes.bool,
|
|
1816
1839
|
/** Inline style for the component. */
|
|
@@ -1831,19 +1854,19 @@ Dropdown.propTypes = {
|
|
|
1831
1854
|
valueObjectDefault: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
1832
1855
|
/** The variant to use. */
|
|
1833
1856
|
viewType: PropTypes.oneOf(['underlined', 'outlined', 'none'])
|
|
1834
|
-
/**
|
|
1835
|
-
* ref methods
|
|
1836
|
-
*
|
|
1837
|
-
* how to get component element? ref.current
|
|
1838
|
-
*
|
|
1839
|
-
* how to call method? ref.current.instance.{method}
|
|
1840
|
-
*
|
|
1841
|
-
* * showDropdown(): Show dropdown
|
|
1842
|
-
* * closeDropdown(): Close dropdown
|
|
1843
|
-
* * onClear(): Clear selected value
|
|
1844
|
-
* * setPreviousValue(): Set value to previous value
|
|
1845
|
-
* * setValue(value): Set value of dropdown
|
|
1846
|
-
* * @param {value} - string || number || array
|
|
1857
|
+
/**
|
|
1858
|
+
* ref methods
|
|
1859
|
+
*
|
|
1860
|
+
* how to get component element? ref.current
|
|
1861
|
+
*
|
|
1862
|
+
* how to call method? ref.current.instance.{method}
|
|
1863
|
+
*
|
|
1864
|
+
* * showDropdown(): Show dropdown
|
|
1865
|
+
* * closeDropdown(): Close dropdown
|
|
1866
|
+
* * onClear(): Clear selected value
|
|
1867
|
+
* * setPreviousValue(): Set value to previous value
|
|
1868
|
+
* * setValue(value): Set value of dropdown
|
|
1869
|
+
* * @param {value} - string || number || array
|
|
1847
1870
|
*/
|
|
1848
1871
|
};
|
|
1849
1872
|
export default Dropdown;
|
|
@@ -1,14 +1,16 @@
|
|
|
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
|
|
11
|
+
const regexBetween = /[^{}]+(?=})/g;
|
|
12
|
+
const regexInclude = /{|}/g;
|
|
13
|
+
const DropdownBox = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
12
14
|
if (!reference) reference = useRef(null);
|
|
13
15
|
const theme = useTheme();
|
|
14
16
|
const {
|
|
@@ -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
|
-
|
|
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;
|
|
@@ -4,7 +4,7 @@ import { css, jsx } from '@emotion/core';
|
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import { Children, forwardRef, memo, useEffect, useImperativeHandle, useRef } from 'react';
|
|
6
6
|
import { useTheme } from "../../../theme";
|
|
7
|
-
const FormGroup = /*#__PURE__*/memo(
|
|
7
|
+
const FormGroup = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(({
|
|
8
8
|
fullWidth,
|
|
9
9
|
oneHelperText,
|
|
10
10
|
marginRight,
|
|
@@ -9,7 +9,7 @@ import { useTheme } from "../../../theme";
|
|
|
9
9
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
10
10
|
import { classNames, getProp } from "../../../utils";
|
|
11
11
|
const colorMap = new Map([['default', 'semantic/danger'], ['success', 'semantic/success'], ['warning', 'semantic/warning'], ['danger', 'semantic/danger'], ['info', 'semantic/info']]);
|
|
12
|
-
const HelperText = /*#__PURE__*/memo(
|
|
12
|
+
const HelperText = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
13
13
|
if (!reference) reference = useRef(null);
|
|
14
14
|
const theme = useTheme();
|
|
15
15
|
const {
|
|
@@ -9,7 +9,7 @@ import { bgColor, border, borderBottom, borderBottomColor, borderColor, borderNo
|
|
|
9
9
|
import { useTheme } from "../../../theme";
|
|
10
10
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
11
11
|
import { classNames, refType as ref, getProp } from "../../../utils";
|
|
12
|
-
const UncontrolledInputBase = /*#__PURE__*/memo(
|
|
12
|
+
const UncontrolledInputBase = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
13
13
|
if (!reference) reference = useRef(null);
|
|
14
14
|
const theme = useTheme();
|
|
15
15
|
const {
|
|
@@ -9,7 +9,7 @@ import { bgColor, bgTransparent, border, borderBottom, borderBottomColor, border
|
|
|
9
9
|
import { useTheme } from "../../../theme";
|
|
10
10
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
11
11
|
import { classNames, refType as ref, useInput, getProp } from "../../../utils";
|
|
12
|
-
const InputBase = /*#__PURE__*/memo(
|
|
12
|
+
const InputBase = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
13
13
|
if (!reference) reference = useRef(null);
|
|
14
14
|
const theme = useTheme();
|
|
15
15
|
const {
|
|
@@ -9,7 +9,7 @@ import { flexRow, parseMinHeight, typographyTypes } from "../../../styles/genera
|
|
|
9
9
|
import { useTheme } from "../../../theme";
|
|
10
10
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
11
11
|
import { classNames, getProp } from "../../../utils";
|
|
12
|
-
const Label = /*#__PURE__*/memo(
|
|
12
|
+
const Label = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
13
13
|
if (!reference) reference = useRef(null);
|
|
14
14
|
const theme = useTheme();
|
|
15
15
|
const {
|
|
@@ -128,7 +128,7 @@ const converters = {
|
|
|
128
128
|
en: num2WordsEn,
|
|
129
129
|
zh: num2WordsZh
|
|
130
130
|
};
|
|
131
|
-
const MoneyInput = /*#__PURE__*/memo(
|
|
131
|
+
const MoneyInput = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
132
132
|
if (!reference) reference = useRef(null);
|
|
133
133
|
|
|
134
134
|
// props priority: `inProps` > `themeDefaultProps`
|
|
@@ -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({});
|
|
@@ -95,13 +98,13 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
95
98
|
|
|
96
99
|
// if (valueProps || valueProps === 0) valueProps = clamp(valueProps, min, max);
|
|
97
100
|
|
|
98
|
-
/**
|
|
99
|
-
* Convert number to format money
|
|
100
|
-
* @param vl {number} - value
|
|
101
|
-
* @type {function}
|
|
102
|
-
* @return {string}
|
|
103
|
-
* @example 1200300.123 => 1,200,300.123
|
|
104
|
-
* @example 1200300,123 => 1.200.300,123
|
|
101
|
+
/**
|
|
102
|
+
* Convert number to format money
|
|
103
|
+
* @param vl {number} - value
|
|
104
|
+
* @type {function}
|
|
105
|
+
* @return {string}
|
|
106
|
+
* @example 1200300.123 => 1,200,300.123
|
|
107
|
+
* @example 1200300,123 => 1.200.300,123
|
|
105
108
|
*/
|
|
106
109
|
const parseNumberToMoney = useCallback((vl, isNumber) => {
|
|
107
110
|
var _number, _number2, _number$, _number3;
|
|
@@ -149,13 +152,13 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
149
152
|
return number;
|
|
150
153
|
}, [decimalSymbol, max, value, decimalDigit, fixedDecimalDigit]);
|
|
151
154
|
|
|
152
|
-
/**
|
|
153
|
-
* Convert money to format number
|
|
154
|
-
* @param vl {string} - value
|
|
155
|
-
* @type {function}
|
|
156
|
-
* @return {number}
|
|
157
|
-
* @example 1,200,300.123 => 1200300.123
|
|
158
|
-
* @example 1.200.300,123 => 1200300.123
|
|
155
|
+
/**
|
|
156
|
+
* Convert money to format number
|
|
157
|
+
* @param vl {string} - value
|
|
158
|
+
* @type {function}
|
|
159
|
+
* @return {number}
|
|
160
|
+
* @example 1,200,300.123 => 1200300.123
|
|
161
|
+
* @example 1.200.300,123 => 1200300.123
|
|
159
162
|
*/
|
|
160
163
|
const convertMoneyToNumber = useCallback((vl, isNumber) => {
|
|
161
164
|
var _number4, _number4$toString, _number4$toString$rep, _number4$toString$rep2, _number4$toString$rep3;
|
|
@@ -167,7 +170,7 @@ const NumberInput = /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
|
167
170
|
}, [decimalSymbol]);
|
|
168
171
|
const _onInput = useCallback((e, flag) => {
|
|
169
172
|
var _e$target$value;
|
|
170
|
-
let valueT = (_e$target$value = e.target.value) !== null && _e$target$value !== void 0 ? _e$target$value : e.value;
|
|
173
|
+
let valueT = eval((_e$target$value = e.target.value) !== null && _e$target$value !== void 0 ? _e$target$value : e.value);
|
|
171
174
|
if (disabledNegative && Number(valueT || 0) < 0) return;
|
|
172
175
|
valueT = parseNumberToMoney(valueT);
|
|
173
176
|
const returnValue = convertMoneyToNumber(valueT);
|
|
@@ -490,10 +493,10 @@ NumberInput.propTypes = {
|
|
|
490
493
|
style: PropTypes.object,
|
|
491
494
|
/** Thousand separator character. */
|
|
492
495
|
thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])]),
|
|
493
|
-
/** Validation value, argument can:<br/>
|
|
494
|
-
* * string: the validation rule. Example required.<br/>
|
|
495
|
-
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
496
|
-
* * array: the validation rule list, insist object/string
|
|
496
|
+
/** Validation value, argument can:<br/>
|
|
497
|
+
* * string: the validation rule. Example required.<br/>
|
|
498
|
+
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
499
|
+
* * array: the validation rule list, insist object/string
|
|
497
500
|
*/
|
|
498
501
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
499
502
|
/** The value of the input element, required for a controlled component. */
|
|
@@ -8,7 +8,7 @@ import { cursorNotAllowed, displayBlock, positionRelative } from "../../../style
|
|
|
8
8
|
import { useTheme } from "../../../theme";
|
|
9
9
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
10
10
|
import { classNames, onValidate, refType as ref } from "../../../utils";
|
|
11
|
-
const PasswordInput = /*#__PURE__*/memo(
|
|
11
|
+
const PasswordInput = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
12
12
|
if (!reference) reference = useRef(null);
|
|
13
13
|
const theme = useTheme();
|
|
14
14
|
|
|
@@ -8,7 +8,7 @@ import { boxBorder, cursorNoDrop, cursorPointer, displayBlock, displayNone, posi
|
|
|
8
8
|
import { useTheme } from "../../../theme";
|
|
9
9
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
10
10
|
import { classNames, getProp, randomString } from "../../../utils";
|
|
11
|
-
const Radio = /*#__PURE__*/memo(
|
|
11
|
+
const Radio = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
12
12
|
if (!reference) reference = useRef(null);
|
|
13
13
|
const theme = useTheme();
|
|
14
14
|
const {
|
|
@@ -8,7 +8,7 @@ import { cursorNotAllowed, displayBlock, positionRelative } from "../../../style
|
|
|
8
8
|
import { useTheme } from "../../../theme";
|
|
9
9
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
10
10
|
import { classNames, onValidate, refType as ref } from "../../../utils";
|
|
11
|
-
const TextInput = /*#__PURE__*/memo(
|
|
11
|
+
const TextInput = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
12
12
|
if (!reference) reference = useRef(null);
|
|
13
13
|
const theme = useTheme();
|
|
14
14
|
|
|
@@ -9,7 +9,7 @@ import { bgColor, border, borderColor, borderNone, borderRadius4px, displayFlex,
|
|
|
9
9
|
import { useTheme } from "../../../../theme";
|
|
10
10
|
import useThemeProps from "../../../../theme/utils/useThemeProps";
|
|
11
11
|
import { classNames, date, getProp, hexToRGBA } from "../../../../utils";
|
|
12
|
-
const TimePicker = /*#__PURE__*/memo(
|
|
12
|
+
const TimePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, reference) => {
|
|
13
13
|
if (!reference) reference = useRef(null);
|
|
14
14
|
|
|
15
15
|
// props priority: `inProps` > `themeDefaultProps`
|