diginet-core-ui 1.4.2 → 1.4.3
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.
|
@@ -332,10 +332,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
332
332
|
// }
|
|
333
333
|
// };
|
|
334
334
|
|
|
335
|
-
/**
|
|
336
|
-
* So sánh text đầu vào cáo map với txtSearch
|
|
337
|
-
* @param text
|
|
338
|
-
* @return {boolean}
|
|
335
|
+
/**
|
|
336
|
+
* So sánh text đầu vào cáo map với txtSearch
|
|
337
|
+
* @param text
|
|
338
|
+
* @return {boolean}
|
|
339
339
|
*/
|
|
340
340
|
const handleRenderBySearch = (text = '') => {
|
|
341
341
|
if (typeof text !== 'string') text = text.toString();
|
|
@@ -347,10 +347,10 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
347
347
|
} else return text.toLowerCase().includes(txtSearch.toLowerCase());
|
|
348
348
|
};
|
|
349
349
|
|
|
350
|
-
/**
|
|
351
|
-
* 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
|
|
352
|
-
* @param data {object} rowData of dataSource
|
|
353
|
-
* @return {string}
|
|
350
|
+
/**
|
|
351
|
+
* 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
|
|
352
|
+
* @param data {object} rowData of dataSource
|
|
353
|
+
* @return {string}
|
|
354
354
|
*/
|
|
355
355
|
const displayValue = data => {
|
|
356
356
|
let text = '';
|
|
@@ -1758,9 +1758,9 @@ Dropdown.propTypes = {
|
|
|
1758
1758
|
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1759
1759
|
/** If `true`, the component is disabled. */
|
|
1760
1760
|
disabled: PropTypes.bool,
|
|
1761
|
-
/** Field name used for text display in dropdown list.<br/>
|
|
1762
|
-
* Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
1763
|
-
* Note: don't use 'id - name', return undefined
|
|
1761
|
+
/** Field name used for text display in dropdown list.<br/>
|
|
1762
|
+
* Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
1763
|
+
* Note: don't use 'id - name', return undefined
|
|
1764
1764
|
*/
|
|
1765
1765
|
displayExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
|
1766
1766
|
/** Style inline of dropdown items. */
|
|
@@ -1769,14 +1769,14 @@ Dropdown.propTypes = {
|
|
|
1769
1769
|
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
1770
1770
|
/** Props applied to the [HelperText](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) element. */
|
|
1771
1771
|
helperTextProps: PropTypes.object,
|
|
1772
|
-
/** Field name used for icon display.<br/>
|
|
1773
|
-
* Example:<br/>
|
|
1774
|
-
* string: 'icon'<br/>
|
|
1775
|
-
* object: {<br/>
|
|
1776
|
-
* key: 'icon',<br/>
|
|
1777
|
-
* prefix: 'https://imglink.com',<br/>
|
|
1778
|
-
* suffix: '.jpg'<br/>
|
|
1779
|
-
* }
|
|
1772
|
+
/** Field name used for icon display.<br/>
|
|
1773
|
+
* Example:<br/>
|
|
1774
|
+
* string: 'icon'<br/>
|
|
1775
|
+
* object: {<br/>
|
|
1776
|
+
* key: 'icon',<br/>
|
|
1777
|
+
* prefix: 'https://imglink.com',<br/>
|
|
1778
|
+
* suffix: '.jpg'<br/>
|
|
1779
|
+
* }
|
|
1780
1780
|
*/
|
|
1781
1781
|
iconExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
|
1782
1782
|
key: PropTypes.string,
|
|
@@ -1810,8 +1810,8 @@ Dropdown.propTypes = {
|
|
|
1810
1810
|
onChange: PropTypes.func,
|
|
1811
1811
|
/** Callback fired when dropdown closed. */
|
|
1812
1812
|
onClosed: PropTypes.func,
|
|
1813
|
-
/** Callback fired when the input value changes.<br/>
|
|
1814
|
-
* if undefined: the filter function will run (default)
|
|
1813
|
+
/** Callback fired when the input value changes.<br/>
|
|
1814
|
+
* if undefined: the filter function will run (default)
|
|
1815
1815
|
*/
|
|
1816
1816
|
onInput: PropTypes.func,
|
|
1817
1817
|
/** Callback fired when key down input */
|
|
@@ -1822,21 +1822,21 @@ Dropdown.propTypes = {
|
|
|
1822
1822
|
placeholder: PropTypes.string,
|
|
1823
1823
|
/** If `true`, the component is read-only. */
|
|
1824
1824
|
readOnly: PropTypes.bool,
|
|
1825
|
-
/** Function displays items by custom.<br/>
|
|
1826
|
-
* renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
|
|
1827
|
-
* --> such as: displayExpr={'name - role'}
|
|
1825
|
+
/** Function displays items by custom.<br/>
|
|
1826
|
+
* renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
|
|
1827
|
+
* --> such as: displayExpr={'name - role'}
|
|
1828
1828
|
*/
|
|
1829
1829
|
renderItem: PropTypes.func,
|
|
1830
|
-
/** Function or field name used for display selected items, example:<br/>
|
|
1831
|
-
* renderSelectedItem={(data, index) => index + ' - ' + data.name}<br/>
|
|
1830
|
+
/** Function or field name used for display selected items, example:<br/>
|
|
1831
|
+
* renderSelectedItem={(data, index) => index + ' - ' + data.name}<br/>
|
|
1832
1832
|
*/
|
|
1833
1833
|
renderSelectedItem: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
1834
1834
|
/** If `true`, the label will indicate that the input is required. */
|
|
1835
1835
|
required: PropTypes.bool,
|
|
1836
|
-
/**
|
|
1837
|
-
* Duration wait enter search content on search.<br/>
|
|
1838
|
-
* Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
|
|
1839
|
-
* If `true`, used default delayOnInput.
|
|
1836
|
+
/**
|
|
1837
|
+
* Duration wait enter search content on search.<br/>
|
|
1838
|
+
* Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
|
|
1839
|
+
* If `true`, used default delayOnInput.
|
|
1840
1840
|
*/
|
|
1841
1841
|
searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
1842
1842
|
/** Specifies a data object's field name or an expression whose value is compared to the search string. */
|
|
@@ -1863,19 +1863,19 @@ Dropdown.propTypes = {
|
|
|
1863
1863
|
valueObjectDefault: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
1864
1864
|
/**The variant to use. */
|
|
1865
1865
|
viewType: PropTypes.oneOf(['underlined', 'outlined', 'none'])
|
|
1866
|
-
/**
|
|
1867
|
-
* ref methods
|
|
1868
|
-
*
|
|
1869
|
-
* how to get component element? ref.current
|
|
1870
|
-
*
|
|
1871
|
-
* how to call method? ref.current.instance.{method}
|
|
1872
|
-
*
|
|
1873
|
-
* * showDropdown(): Show dropdown
|
|
1874
|
-
* * closeDropdown(): Close dropdown
|
|
1875
|
-
* * onClear(): Clear selected value
|
|
1876
|
-
* * setPreviousValue(): Set value to previous value
|
|
1877
|
-
* * setValue(value): Set value of dropdown
|
|
1878
|
-
* * @param {value} - string || number || array
|
|
1866
|
+
/**
|
|
1867
|
+
* ref methods
|
|
1868
|
+
*
|
|
1869
|
+
* how to get component element? ref.current
|
|
1870
|
+
*
|
|
1871
|
+
* how to call method? ref.current.instance.{method}
|
|
1872
|
+
*
|
|
1873
|
+
* * showDropdown(): Show dropdown
|
|
1874
|
+
* * closeDropdown(): Close dropdown
|
|
1875
|
+
* * onClear(): Clear selected value
|
|
1876
|
+
* * setPreviousValue(): Set value to previous value
|
|
1877
|
+
* * setValue(value): Set value of dropdown
|
|
1878
|
+
* * @param {value} - string || number || array
|
|
1879
1879
|
*/
|
|
1880
1880
|
};
|
|
1881
1881
|
|
|
@@ -12,7 +12,10 @@ const regexNumber = /[^0-9]/g;
|
|
|
12
12
|
const regexThousandNumber = /(\d)(?=(\d{3})+\b)/g;
|
|
13
13
|
|
|
14
14
|
// Clamp number between two values with the following line:
|
|
15
|
-
const clamp = (num, min, max) =>
|
|
15
|
+
const clamp = (num, min, max) => {
|
|
16
|
+
var _Math$min;
|
|
17
|
+
return (_Math$min = Math.min(Math.max(num, min), max)) !== null && _Math$min !== void 0 ? _Math$min : '';
|
|
18
|
+
};
|
|
16
19
|
const NumberInput = /*#__PURE__*/forwardRef(({
|
|
17
20
|
action = {},
|
|
18
21
|
autoFocus,
|
|
@@ -93,11 +96,16 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
93
96
|
}
|
|
94
97
|
} = inputRef;
|
|
95
98
|
let number = convertMoneyToNumber(vl, isNumber);
|
|
96
|
-
|
|
97
|
-
if (
|
|
99
|
+
|
|
100
|
+
// if (disabledNegative && Number(number || 0) < 0) number = clamp(number, min, max);
|
|
101
|
+
// if (typeof max !== 'undefined' && Number(number) > max) number = Math.min(number, max);
|
|
102
|
+
if (!number || isNaN(number)) return number;else if (number.toString().substr(-1) !== '.') {
|
|
103
|
+
number = clamp(number, min, max);
|
|
104
|
+
}
|
|
98
105
|
|
|
99
106
|
// number = Currency.format(number);
|
|
100
|
-
if (!number) return number;
|
|
107
|
+
// if (!number) return number;
|
|
108
|
+
|
|
101
109
|
number = (_number = number) === null || _number === void 0 ? void 0 : _number.toString().split('.');
|
|
102
110
|
if (number.length === 2 && !number[0]) {
|
|
103
111
|
number[0] = '0';
|
|
@@ -137,6 +145,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
137
145
|
valueT = parseNumberToMoney(valueT);
|
|
138
146
|
const returnValue = convertMoneyToNumber(valueT);
|
|
139
147
|
e.value = globalRef.current.value = !isNaN(parseFloat(returnValue)) ? parseFloat(returnValue) : null;
|
|
148
|
+
// e.target.value = globalRef.current.valueString = valueT || '';
|
|
149
|
+
// globalRef.current.returnValue = returnValue || '';
|
|
140
150
|
e.target.value = globalRef.current.valueString = valueT || '';
|
|
141
151
|
globalRef.current.returnValue = returnValue || '';
|
|
142
152
|
onInput === null || onInput === void 0 ? void 0 : onInput(e);
|
|
@@ -224,7 +234,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
224
234
|
}
|
|
225
235
|
|
|
226
236
|
// disabled negative
|
|
227
|
-
const disabled180 = (keyCode === 189 || keyCode === 109) && (disabledNegative || value.includes('-'));
|
|
237
|
+
// const disabled180 = (keyCode === 189 || keyCode === 109) && (disabledNegative || value.includes('-'));
|
|
238
|
+
const disabled180 = (keyCode === 189 || keyCode === 109) && (min === 0 || value.includes('-'));
|
|
228
239
|
|
|
229
240
|
// disabled max digit
|
|
230
241
|
const isMaxDigit = maxDigit && (value === null || value === void 0 ? void 0 : value.replace(regexNumber, '').length) === maxDigit && (isNumber || key === thousandSymbol || key === decimalSymbol) && selectionStart === selectionEnd;
|
|
@@ -246,12 +257,18 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
246
257
|
}
|
|
247
258
|
}, [value]);
|
|
248
259
|
useEffect(() => {
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
260
|
+
// if (typeof valueProps !== 'undefined')
|
|
261
|
+
// if (disabledNegative && Number(valueProps || 0) < 0) {
|
|
262
|
+
if (!isNaN(valueProps) || !isNaN(value)) {
|
|
263
|
+
var _valueProps;
|
|
264
|
+
if (min === 0 && Number(valueProps || 0) < 0) {
|
|
265
|
+
// nếu không cho nhập số âm mà value đầu vào là âm thì reset value về 0
|
|
266
|
+
valueProps = clamp(0, min, max);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// setValue(parseNumberToMoney(valueProps?.toString().replace(regexValidNumber, ''), true));
|
|
270
|
+
setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
|
|
253
271
|
}
|
|
254
|
-
setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
|
|
255
272
|
}, [valueProps]);
|
|
256
273
|
useImperativeHandle(reference, () => {
|
|
257
274
|
const currentRef = ref.current || {};
|
|
@@ -327,7 +344,7 @@ const NumberInputRoot = css`
|
|
|
327
344
|
NumberInput.defaultProps = {
|
|
328
345
|
autoFocus: false,
|
|
329
346
|
className: '',
|
|
330
|
-
decimalDigit:
|
|
347
|
+
decimalDigit: Infinity,
|
|
331
348
|
decimalSymbol: locale.get() === 'vi' ? ',' : '.',
|
|
332
349
|
disabled: false,
|
|
333
350
|
disabledNegative: false,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -38,6 +38,9 @@ npm test
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Changelog
|
|
41
|
+
## 1.4.3
|
|
42
|
+
- \[Fixed\]: NumberInput – Fix bug arrow keydown, back, check min, max
|
|
43
|
+
|
|
41
44
|
## 1.4.2
|
|
42
45
|
- \[Changed\]: Dropdown – Add action loadData
|
|
43
46
|
- \[Fixed\]: Dropdown – Fix bug search filter data when using remote; Fix bug not render invalid html tag
|
package/styles/sx/index.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { css } from '@emotion/core';
|
|
2
|
+
import { getSpacing } from "../general";
|
|
2
3
|
import { handleBreakpoints } from "../../utils";
|
|
3
|
-
const cssKeyMap = new Map([['display', 'display']]);
|
|
4
|
+
const cssKeyMap = new Map([['display', 'display'], ['padding', 'padding']]);
|
|
5
|
+
const parsePropValue = (cssKey, propValue) => {
|
|
6
|
+
switch (cssKey) {
|
|
7
|
+
case 'padding':
|
|
8
|
+
return `${cssKey}: ${getSpacing(propValue)}`;
|
|
9
|
+
default:
|
|
10
|
+
return `${cssKey}: ${propValue};`;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
4
13
|
const sx = prop => {
|
|
5
14
|
if (typeof prop !== 'object' || Array.isArray(prop) || prop === null) return null;
|
|
6
15
|
let sxStyleCSS = '';
|
|
7
16
|
Object.keys(prop).forEach(key => {
|
|
8
17
|
const cssKey = cssKeyMap.get(key);
|
|
9
18
|
if (!cssKey) return null;
|
|
10
|
-
sxStyleCSS += handleBreakpoints(prop[key], propValue =>
|
|
11
|
-
if (propValue) {
|
|
12
|
-
return `
|
|
13
|
-
${cssKey}: ${propValue};
|
|
14
|
-
`;
|
|
15
|
-
}
|
|
16
|
-
return '';
|
|
17
|
-
});
|
|
19
|
+
sxStyleCSS += handleBreakpoints(prop[key], propValue => propValue ? parsePropValue(cssKey, propValue) : '');
|
|
18
20
|
});
|
|
19
21
|
return css`
|
|
20
22
|
${sxStyleCSS}
|
package/utils/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { default as getFileType } from "./getFileType";
|
|
|
7
7
|
export { default as handleBreakpoints } from "./handleBreakpoints";
|
|
8
8
|
export { default as hexToRGBA } from "./hexToRGBA";
|
|
9
9
|
export { default as isMobile } from "./isMobile";
|
|
10
|
+
export { default as isUndefined } from "./isUndefined";
|
|
10
11
|
export { default as mapParent } from "./map-parent";
|
|
11
12
|
export { default as onValidate } from "./validate";
|
|
12
13
|
export { default as parseTextToHTML } from "./parseHTML";
|