diginet-core-ui 1.4.53 → 1.4.54
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/form-control/attachment/index.js +21 -21
- package/components/form-control/date-input/useDateInputState.js +3 -5
- package/components/form-control/date-picker/index.js +27 -7
- package/components/form-control/date-range-picker/index.js +6 -6
- package/components/form-control/dropdown/index.js +4 -1
- package/components/form-control/money-input/index.js +60 -2
- package/components/paging/page-info.js +34 -34
- package/components/tree-view/index.js +81 -45
- package/global/index.js +80 -0
- package/icons/basic.js +24 -0
- package/locale/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +7 -0
- package/theme/settings.js +4 -3
- package/utils/getLang.js +69 -0
- package/utils/index.js +1 -0
|
@@ -1442,17 +1442,17 @@ Attachment.propTypes = {
|
|
|
1442
1442
|
allowSort: PropTypes.bool,
|
|
1443
1443
|
/** Class for component. */
|
|
1444
1444
|
className: PropTypes.string,
|
|
1445
|
-
/** List attachment:<br />
|
|
1446
|
-
* [{<br />
|
|
1447
|
-
* "AttachmentID": "ATT2U8O7YPTF1KSNCW3X",<br />
|
|
1448
|
-
* "URL": "https://apricot.diginet.com.vn/cdn-dev/file/demo.jpg",<br />
|
|
1449
|
-
* "FileName": "8a07bee1eeff17a14eee.jpg",<br />
|
|
1450
|
-
* "FileSize": 248837,<br />
|
|
1451
|
-
* "KeyID": "W39OAD3YGLCWAQKV1D6PGEKNW4RLGVTZTUWLYEVFQ2QG8AOCXW",<br />
|
|
1452
|
-
* "CreateUserID": "LEMONADMIN",<br />
|
|
1453
|
-
* "CreateDate": "2020-08-24T11:54:04.307Z",<br />
|
|
1454
|
-
* "UserName": "Quản trị hệ thống"<br />
|
|
1455
|
-
* }, ...]
|
|
1445
|
+
/** List attachment:<br />
|
|
1446
|
+
* [{<br />
|
|
1447
|
+
* "AttachmentID": "ATT2U8O7YPTF1KSNCW3X",<br />
|
|
1448
|
+
* "URL": "https://apricot.diginet.com.vn/cdn-dev/file/demo.jpg",<br />
|
|
1449
|
+
* "FileName": "8a07bee1eeff17a14eee.jpg",<br />
|
|
1450
|
+
* "FileSize": 248837,<br />
|
|
1451
|
+
* "KeyID": "W39OAD3YGLCWAQKV1D6PGEKNW4RLGVTZTUWLYEVFQ2QG8AOCXW",<br />
|
|
1452
|
+
* "CreateUserID": "LEMONADMIN",<br />
|
|
1453
|
+
* "CreateDate": "2020-08-24T11:54:04.307Z",<br />
|
|
1454
|
+
* "UserName": "Quản trị hệ thống"<br />
|
|
1455
|
+
* }, ...]
|
|
1456
1456
|
*/
|
|
1457
1457
|
data: PropTypes.array,
|
|
1458
1458
|
/** The message to display when deleting files. */
|
|
@@ -1483,16 +1483,16 @@ Attachment.propTypes = {
|
|
|
1483
1483
|
onChange: PropTypes.func,
|
|
1484
1484
|
/** Download attached event, if not it will use default. */
|
|
1485
1485
|
onDownload: PropTypes.func,
|
|
1486
|
-
/**
|
|
1487
|
-
* event when removed file(s)
|
|
1488
|
-
*
|
|
1489
|
-
* return data: {<br/>
|
|
1490
|
-
* attached: [Files] (insist old and all new files )<br/>
|
|
1491
|
-
* allNewAttached: [Files]<br/>
|
|
1492
|
-
* oldAttached: [Files]<br/>
|
|
1493
|
-
* removedAttached: [Files]<br/>
|
|
1494
|
-
* element: [NodeList (just removed)]<br/>
|
|
1495
|
-
* }
|
|
1486
|
+
/**
|
|
1487
|
+
* event when removed file(s)
|
|
1488
|
+
*
|
|
1489
|
+
* return data: {<br/>
|
|
1490
|
+
* attached: [Files] (insist old and all new files )<br/>
|
|
1491
|
+
* allNewAttached: [Files]<br/>
|
|
1492
|
+
* oldAttached: [Files]<br/>
|
|
1493
|
+
* removedAttached: [Files]<br/>
|
|
1494
|
+
* element: [NodeList (just removed)]<br/>
|
|
1495
|
+
* }
|
|
1496
1496
|
*/
|
|
1497
1497
|
onRemove: PropTypes.func,
|
|
1498
1498
|
/** View attached event, if not it will use default. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import { addDays, addHours, addMinutes, addMonths, addSeconds, addYears,
|
|
3
|
-
import { enUS, vi } from 'date-fns/locale';
|
|
2
|
+
import { addDays, addHours, addMinutes, addMonths, addSeconds, addYears, isLastDayOfMonth, isValid, lastDayOfMonth } from 'date-fns';
|
|
4
3
|
import { getGlobal } from "../../../global";
|
|
5
4
|
import { capitalize } from "../../../utils";
|
|
6
5
|
import { patternMap, useDateField } from "./DateField";
|
|
7
6
|
import { lowerCaseDayYear } from "./utils";
|
|
7
|
+
import { parseDateString } from "../../../utils/getLang";
|
|
8
8
|
export const useDateInputState = ({
|
|
9
9
|
formatStr,
|
|
10
10
|
locale,
|
|
@@ -95,9 +95,7 @@ export const useDateInputState = ({
|
|
|
95
95
|
};
|
|
96
96
|
const toControlledDateString = () => {
|
|
97
97
|
if (date && isValid(date)) {
|
|
98
|
-
return
|
|
99
|
-
locale: locale === 'vi' ? vi : enUS
|
|
100
|
-
});
|
|
98
|
+
return parseDateString(date, lowerCaseDayYear(formatStr), locale);
|
|
101
99
|
}
|
|
102
100
|
// if date is not valid, return uncontrolled date string
|
|
103
101
|
return toDateString();
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { css, jsx } from '@emotion/core';
|
|
4
4
|
import { Button, ButtonIcon, DateInput, HelperText, InputBase, Label, Popover, Tooltip } from "../..";
|
|
5
|
-
import {
|
|
6
|
-
import { enUS, vi } from 'date-fns/locale';
|
|
5
|
+
import { isValid, parse } from 'date-fns';
|
|
7
6
|
import { getGlobal } from "../../../global";
|
|
8
7
|
import locale from "../../../locale";
|
|
9
8
|
import PropTypes from 'prop-types';
|
|
@@ -14,6 +13,7 @@ import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
|
14
13
|
import { capitalizeSentenceCase, classNames, isValidDate, useControlled } from "../../../utils";
|
|
15
14
|
import Calendar from "../calendar";
|
|
16
15
|
import { lowerCaseDayYear } from "../date-input/utils";
|
|
16
|
+
import { parseDateString } from "../../../utils/getLang";
|
|
17
17
|
const unique = {
|
|
18
18
|
footer: 'DGN-UI-DatePicker-Footer',
|
|
19
19
|
cancel: 'DGN-UI-DatePicker-cancel',
|
|
@@ -23,6 +23,10 @@ const unique = {
|
|
|
23
23
|
const confirmText = getGlobal(['confirm']);
|
|
24
24
|
const cancelText = getGlobal(['cancel']);
|
|
25
25
|
const viDisplayFormat = new Map([['year', 'YYYY'], ['quarter', 'Q-YYYY'], ['month', 'MM-YYYY']]);
|
|
26
|
+
const zhDisplayFormat = new Map([['year', 'YYYY年'], ['quarter', 'YYYY年第Q季度'], ['month', 'YYYY年MM月']]);
|
|
27
|
+
const enDisplayFormat = new Map([['year', 'YYYY'], ['quarter', 'YYYY [Q]Q'],
|
|
28
|
+
// Exp: 2025 Q1
|
|
29
|
+
['month', 'MM/YYYY']]);
|
|
26
30
|
const pickerReturnFormat = new Map([['year', 'YYYY'], ['quarter', 'YYYY-Q'], ['month', 'YYYY-MM']]);
|
|
27
31
|
const parseValueToDate = valueProp => {
|
|
28
32
|
if (!valueProp) return null;else if (isValidDate(valueProp)) {
|
|
@@ -42,8 +46,26 @@ const parseValueToDate = valueProp => {
|
|
|
42
46
|
return valueProp;
|
|
43
47
|
}
|
|
44
48
|
};
|
|
49
|
+
const getDateFormats = (locale, minZoom) => {
|
|
50
|
+
let formatMap;
|
|
51
|
+
switch (locale) {
|
|
52
|
+
case 'vi':
|
|
53
|
+
formatMap = viDisplayFormat;
|
|
54
|
+
break;
|
|
55
|
+
case 'zh':
|
|
56
|
+
formatMap = zhDisplayFormat;
|
|
57
|
+
break;
|
|
58
|
+
case 'en':
|
|
59
|
+
formatMap = enDisplayFormat;
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
formatMap = pickerReturnFormat; // fallback
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return formatMap.get(minZoom);
|
|
66
|
+
};
|
|
45
67
|
const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
46
|
-
var
|
|
68
|
+
var _getDateFormats, _pickerReturnFormat$g, _ipRef$current, _ipRef$current2;
|
|
47
69
|
if (!reference) reference = useRef(null);
|
|
48
70
|
const theme = useTheme();
|
|
49
71
|
|
|
@@ -87,7 +109,7 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
87
109
|
...other
|
|
88
110
|
} = props;
|
|
89
111
|
const dateLocale = locale.get();
|
|
90
|
-
const displayFormat = (
|
|
112
|
+
const displayFormat = (_getDateFormats = getDateFormats(dateLocale, minZoom)) !== null && _getDateFormats !== void 0 ? _getDateFormats : displayFormatProp;
|
|
91
113
|
const returnFormat = (_pickerReturnFormat$g = pickerReturnFormat.get(minZoom)) !== null && _pickerReturnFormat$g !== void 0 ? _pickerReturnFormat$g : returnFormatProp;
|
|
92
114
|
const placeholder = placeholderProp !== null && placeholderProp !== void 0 ? placeholderProp : displayFormat;
|
|
93
115
|
const [value, setValue] = useControlled(parseValueToDate(valueProp), parseValueToDate(defaultValue));
|
|
@@ -112,9 +134,7 @@ const DatePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
112
134
|
};
|
|
113
135
|
const formatValue = (value, formatStr) => {
|
|
114
136
|
// return moment(value).format(format, utc = false);
|
|
115
|
-
return
|
|
116
|
-
locale: dateLocale === 'vi' ? vi : enUS
|
|
117
|
-
});
|
|
137
|
+
return parseDateString(value, lowerCaseDayYear(formatStr), dateLocale);
|
|
118
138
|
};
|
|
119
139
|
const onChangeValue = e => {
|
|
120
140
|
const vl = (e === null || e === void 0 ? void 0 : e.value) || e;
|
|
@@ -262,8 +262,8 @@ const DateRangePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, ref
|
|
|
262
262
|
tableData = [],
|
|
263
263
|
weekDateFirst = getDateOfWeek(firstDay),
|
|
264
264
|
weekDateLast = getDateOfWeek(lastDay);
|
|
265
|
-
/**
|
|
266
|
-
* days of previous month
|
|
265
|
+
/**
|
|
266
|
+
* days of previous month
|
|
267
267
|
*/
|
|
268
268
|
for (let i = weekDateFirst; i > 0; i--) {
|
|
269
269
|
const day = Date.parse(new Date(time.getFullYear(), time.getMonth(), 1));
|
|
@@ -275,8 +275,8 @@ const DateRangePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, ref
|
|
|
275
275
|
className: unique.day.day
|
|
276
276
|
})));
|
|
277
277
|
}
|
|
278
|
-
/**
|
|
279
|
-
* days of current month
|
|
278
|
+
/**
|
|
279
|
+
* days of current month
|
|
280
280
|
*/
|
|
281
281
|
for (let i = 0; i < lastDate; i++) {
|
|
282
282
|
const day = new Date(time.getFullYear(), time.getMonth(), i + 1);
|
|
@@ -302,8 +302,8 @@ const DateRangePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, ref
|
|
|
302
302
|
type: 'h6'
|
|
303
303
|
}, i + 1)));
|
|
304
304
|
}
|
|
305
|
-
/**
|
|
306
|
-
* days of next month
|
|
305
|
+
/**
|
|
306
|
+
* days of next month
|
|
307
307
|
*/
|
|
308
308
|
for (let i = 0; i < 13 - weekDateLast; i++) {
|
|
309
309
|
const day = Date.parse(new Date(time.getFullYear(), time.getMonth() + 1, 0));
|
|
@@ -294,6 +294,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
294
294
|
* @return {boolean}
|
|
295
295
|
*/
|
|
296
296
|
const handleRenderBySearch = (text = '') => {
|
|
297
|
+
if (text === null || text === undefined) text = '';
|
|
297
298
|
if (typeof text !== 'string') text = text.toString();
|
|
298
299
|
if (!txtSearch) return true;
|
|
299
300
|
if (searchMode === 'startswith') {
|
|
@@ -436,6 +437,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
436
437
|
}, items !== null && items !== void 0 && items.length ? items : EmptyDataText);
|
|
437
438
|
};
|
|
438
439
|
const mapTreeView = () => {
|
|
440
|
+
console.log('here');
|
|
439
441
|
return jsx("div", {
|
|
440
442
|
css: _DropdownListCSS,
|
|
441
443
|
ref: dropdownListRef,
|
|
@@ -459,7 +461,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
459
461
|
parentID: treeViewParentID,
|
|
460
462
|
value: typeof currentValue[unique] === 'string' ? [currentValue[unique]] : currentValue[unique],
|
|
461
463
|
onChange: (e, value) => onChangeValue(e, '', multiple ? value : e.value),
|
|
462
|
-
renderItem: renderItem
|
|
464
|
+
renderItem: renderItem,
|
|
465
|
+
isInDropdown: true
|
|
463
466
|
}) : EmptyDataText);
|
|
464
467
|
};
|
|
465
468
|
|
|
@@ -10,6 +10,7 @@ import { forwardRef, memo, useEffect, useImperativeHandle, useRef } from 'react'
|
|
|
10
10
|
import { displayBlock, positionRelative } from "../../../styles/general";
|
|
11
11
|
import useThemeProps from "../../../theme/utils/useThemeProps";
|
|
12
12
|
import { onValidate } from "../../../utils";
|
|
13
|
+
import { getThousandSeparatorByCountry } from "../../../utils/getLang";
|
|
13
14
|
const num2WordsVi = function () {
|
|
14
15
|
let t = ['không', 'một', 'hai', 'ba', 'bốn', 'năm', 'sáu', 'bảy', 'tám', 'chín'],
|
|
15
16
|
r = function (r, n) {
|
|
@@ -72,6 +73,61 @@ const num2WordsEn = n => {
|
|
|
72
73
|
if (n === '0') return 'zero';
|
|
73
74
|
return comp(chunk(3))(reverse)(arr(n)).map(makeGroup).map(thousand).filter(comp(not)(isEmpty)).reverse().join(' ');
|
|
74
75
|
};
|
|
76
|
+
const num2WordsZh = (() => {
|
|
77
|
+
const t = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
78
|
+
const units = ['', '十', '百', '千'];
|
|
79
|
+
const bigUnits = ['', '万', '亿', '兆'];
|
|
80
|
+
const readSection = num => {
|
|
81
|
+
let str = '';
|
|
82
|
+
let zero = true;
|
|
83
|
+
for (let i = 0; i < 4 && num > 0; i++) {
|
|
84
|
+
const digit = num % 10;
|
|
85
|
+
if (digit === 0) {
|
|
86
|
+
if (!zero) {
|
|
87
|
+
zero = true;
|
|
88
|
+
str = t[0] + str;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
zero = false;
|
|
92
|
+
str = t[digit] + units[i] + str;
|
|
93
|
+
}
|
|
94
|
+
num = Math.floor(num / 10);
|
|
95
|
+
}
|
|
96
|
+
return str;
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
convert: num => {
|
|
100
|
+
if (num === 0) return t[0];
|
|
101
|
+
let str = '';
|
|
102
|
+
let unitPos = 0;
|
|
103
|
+
let needZero = false;
|
|
104
|
+
while (num > 0) {
|
|
105
|
+
const section = num % 10000;
|
|
106
|
+
if (section === 0) {
|
|
107
|
+
if (needZero) {
|
|
108
|
+
str = t[0] + str;
|
|
109
|
+
needZero = false;
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
const sectionStr = readSection(section) + bigUnits[unitPos];
|
|
113
|
+
str = sectionStr + str;
|
|
114
|
+
needZero = true;
|
|
115
|
+
}
|
|
116
|
+
num = Math.floor(num / 10000);
|
|
117
|
+
unitPos++;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Special cases
|
|
121
|
+
str = str.replace(/^一十/, '十'); // "一十X" => "十X"
|
|
122
|
+
return str;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
})();
|
|
126
|
+
const converters = {
|
|
127
|
+
vi: num2WordsVi,
|
|
128
|
+
en: num2WordsEn,
|
|
129
|
+
zh: num2WordsZh
|
|
130
|
+
};
|
|
75
131
|
const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
76
132
|
if (!reference) reference = useRef(null);
|
|
77
133
|
|
|
@@ -126,7 +182,7 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
126
182
|
isPaste: false,
|
|
127
183
|
clipboardText: ''
|
|
128
184
|
});
|
|
129
|
-
const separatorSymbol = typeof thousandSeparator === 'string' ? thousandSeparator : locale.get()
|
|
185
|
+
const separatorSymbol = typeof thousandSeparator === 'string' ? thousandSeparator : getThousandSeparatorByCountry(locale.get());
|
|
130
186
|
const decimalSymbol = separatorSymbol === '.' ? ',' : '.';
|
|
131
187
|
const thousandSeparatorPattern = new RegExp(`[0-9]|Backspace|Delete|Arrow|Home|End|Tab${decimalDigit === 0 ? '' : '|\\' + decimalSymbol}${disabledNegative ? '' : '|-'}`);
|
|
132
188
|
const isError = !!error && !value && value !== 0;
|
|
@@ -350,7 +406,9 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
350
406
|
if (convertToWords && !decimalDigit && (disabled || readOnly)) {
|
|
351
407
|
let valueConverted = getGlobal('helperInvalid');
|
|
352
408
|
if (Number.isInteger(number)) {
|
|
353
|
-
|
|
409
|
+
const currentLocale = locale.get();
|
|
410
|
+
const converter = converters[currentLocale] || num2WordsVi; // fallback VN
|
|
411
|
+
valueConverted = converter.convert(number);
|
|
354
412
|
}
|
|
355
413
|
inputRef.current.value = parseValueWithFix(valueConverted);
|
|
356
414
|
} else {
|
|
@@ -533,22 +533,22 @@ PagingInfo.propTypes = {
|
|
|
533
533
|
onChangePage: PropTypes.func,
|
|
534
534
|
/** Callback fired when quantity on per page changed. */
|
|
535
535
|
onChangePerPage: PropTypes.func,
|
|
536
|
-
/**
|
|
537
|
-
* Callback fired when page number is changing.
|
|
538
|
-
*
|
|
539
|
-
* * prevPage: Page before changed
|
|
540
|
-
* * newPage: Page after changed
|
|
541
|
-
* * cancel(value): Function cancel change page
|
|
542
|
-
* * @param {value} - bool
|
|
536
|
+
/**
|
|
537
|
+
* Callback fired when page number is changing.
|
|
538
|
+
*
|
|
539
|
+
* * prevPage: Page before changed
|
|
540
|
+
* * newPage: Page after changed
|
|
541
|
+
* * cancel(value): Function cancel change page
|
|
542
|
+
* * @param {value} - bool
|
|
543
543
|
*/
|
|
544
544
|
onChangingPage: PropTypes.func,
|
|
545
|
-
/**
|
|
546
|
-
* Callback fired when quantity on item per page is changing.
|
|
547
|
-
*
|
|
548
|
-
* * prevPerPage: Items per page before changed
|
|
549
|
-
* * newPerPage: Items per page after changed
|
|
550
|
-
* * cancel(value): Function cancel change items per page
|
|
551
|
-
* * @param {value} - bool
|
|
545
|
+
/**
|
|
546
|
+
* Callback fired when quantity on item per page is changing.
|
|
547
|
+
*
|
|
548
|
+
* * prevPerPage: Items per page before changed
|
|
549
|
+
* * newPerPage: Items per page after changed
|
|
550
|
+
* * cancel(value): Function cancel change items per page
|
|
551
|
+
* * @param {value} - bool
|
|
552
552
|
*/
|
|
553
553
|
onChangingPerPage: PropTypes.func,
|
|
554
554
|
/** Style inline of component. */
|
|
@@ -557,26 +557,26 @@ PagingInfo.propTypes = {
|
|
|
557
557
|
totalItems: PropTypes.number,
|
|
558
558
|
/** Compact type for mobile. */
|
|
559
559
|
typeShort: PropTypes.bool
|
|
560
|
-
/**
|
|
561
|
-
* ref methods (ref.current.instance.*method*)
|
|
562
|
-
*
|
|
563
|
-
* * onChangePage(page): Change page number
|
|
564
|
-
* * @param {page} - number
|
|
565
|
-
* * onChangePerPage(per): Change quantity on per page
|
|
566
|
-
* * @param {per} - number
|
|
567
|
-
* * setTotalItems(items): Set total items
|
|
568
|
-
* * @param {items} - number
|
|
569
|
-
*
|
|
570
|
-
* * option(): Gets all UI component properties
|
|
571
|
-
* * Returns value - object
|
|
572
|
-
* * option(optionName): Gets the value of a single property
|
|
573
|
-
* * @param {optionName} - string
|
|
574
|
-
* * Returns value - any
|
|
575
|
-
* * option(optionName, optionValue): Updates the value of a single property
|
|
576
|
-
* * @param {optionName} - string
|
|
577
|
-
* * @param {optionValue} - any
|
|
578
|
-
* * option(options): Updates the values of several properties
|
|
579
|
-
* * @param {options} - object
|
|
560
|
+
/**
|
|
561
|
+
* ref methods (ref.current.instance.*method*)
|
|
562
|
+
*
|
|
563
|
+
* * onChangePage(page): Change page number
|
|
564
|
+
* * @param {page} - number
|
|
565
|
+
* * onChangePerPage(per): Change quantity on per page
|
|
566
|
+
* * @param {per} - number
|
|
567
|
+
* * setTotalItems(items): Set total items
|
|
568
|
+
* * @param {items} - number
|
|
569
|
+
*
|
|
570
|
+
* * option(): Gets all UI component properties
|
|
571
|
+
* * Returns value - object
|
|
572
|
+
* * option(optionName): Gets the value of a single property
|
|
573
|
+
* * @param {optionName} - string
|
|
574
|
+
* * Returns value - any
|
|
575
|
+
* * option(optionName, optionValue): Updates the value of a single property
|
|
576
|
+
* * @param {optionName} - string
|
|
577
|
+
* * @param {optionValue} - any
|
|
578
|
+
* * option(options): Updates the values of several properties
|
|
579
|
+
* * @param {options} - object
|
|
580
580
|
*/
|
|
581
581
|
};
|
|
582
582
|
export { PagingInfo };
|
|
@@ -54,6 +54,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
54
54
|
showSelectedItems,
|
|
55
55
|
value: valueProp,
|
|
56
56
|
valueExpr,
|
|
57
|
+
isInDropdown: isInDropDownProps,
|
|
57
58
|
...other
|
|
58
59
|
} = props;
|
|
59
60
|
let searchDelayTime = searchDelayTimeProp;
|
|
@@ -69,7 +70,10 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
69
70
|
allowNumber: false,
|
|
70
71
|
allowSymbol: false
|
|
71
72
|
}));
|
|
72
|
-
const
|
|
73
|
+
const [isChanged, setIsChanged] = useState(false);
|
|
74
|
+
const [isChecked, setIsChecked] = useState(false);
|
|
75
|
+
const [isInDropdown, setIsInDropdown] = useState(isInDropDownProps);
|
|
76
|
+
const _TreeViewRootCSS = TreeViewRootCSS(theme, isInDropdown);
|
|
73
77
|
const determinateCheckbox = (input, determinate) => {
|
|
74
78
|
if (multipleValueMode === 'multiple' || disabledRelevantValue) {
|
|
75
79
|
input.classList[determinate ? 'add' : 'remove']('determinate');
|
|
@@ -212,7 +216,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
212
216
|
el.firstChild.firstChild.lastChild.firstChild.firstChild.firstChild.classList[isChecked ? 'add' : 'remove']('disabled');
|
|
213
217
|
el.firstChild.firstChild.lastChild.firstChild.firstChild.firstChild.disabled = isChecked;
|
|
214
218
|
Array.from(el.childNodes).forEach(e => {
|
|
215
|
-
e.classList[isChecked ? 'add' : 'remove']('
|
|
219
|
+
e.classList[isChecked ? 'add' : 'remove']('disabled');
|
|
216
220
|
});
|
|
217
221
|
} else {
|
|
218
222
|
el.firstChild.firstChild.firstChild.firstChild.disabled = isChecked;
|
|
@@ -233,12 +237,14 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
233
237
|
const checkbox = node.firstChild.firstChild.lastChild.firstChild.firstChild.firstChild;
|
|
234
238
|
if (checkbox) {
|
|
235
239
|
var _node$querySelectorAl;
|
|
236
|
-
// Trường hợp phải set về false để xét các input đã check không bao gồm node này
|
|
237
|
-
checkbox.firstChild.checked = isChecked;
|
|
238
240
|
const mustDisabled = !!((_node$querySelectorAl = node.querySelectorAll('input:checked')) !== null && _node$querySelectorAl !== void 0 && _node$querySelectorAl.length);
|
|
239
|
-
//
|
|
240
|
-
checkbox.firstChild.checked =
|
|
241
|
+
// // Trường hợp phải set về false để xét các input đã check không bao gồm node này
|
|
242
|
+
checkbox.firstChild.checked = isChecked;
|
|
241
243
|
determinateCheckbox(checkbox.firstChild, !mustDisabled);
|
|
244
|
+
setTimeout(() => {
|
|
245
|
+
// Nếu có ít nhất một input con được check thì phải checked cho input này
|
|
246
|
+
checkbox.firstChild.checked = mustDisabled;
|
|
247
|
+
}, 200);
|
|
242
248
|
node.classList[mustDisabled || isChecked ? 'add' : 'remove']('disabled');
|
|
243
249
|
checkbox.classList[mustDisabled || isChecked ? 'add' : 'remove']('disabled');
|
|
244
250
|
Array.from(node.childNodes).forEach(e => {
|
|
@@ -347,6 +353,8 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
347
353
|
} else {
|
|
348
354
|
currentValue[unique][value] = checked;
|
|
349
355
|
if (disabledRelevantValue) {
|
|
356
|
+
setIsChanged(!isChanged);
|
|
357
|
+
setIsChecked(checked);
|
|
350
358
|
// Disabled/Enabled parent and children node
|
|
351
359
|
if (!currentTarget.classList.contains('non-child')) {
|
|
352
360
|
handleDisabledChildren(currentTarget.nextElementSibling, checked);
|
|
@@ -619,7 +627,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
619
627
|
return jsx("div", {
|
|
620
628
|
className: classNames('TreeView-Item', 'non-child', focusClass),
|
|
621
629
|
style: {
|
|
622
|
-
paddingLeft: 34 + 16 * level
|
|
630
|
+
paddingLeft: multipleValueMode === 'single' && !parentID ? 16 : 34 + 16 * level
|
|
623
631
|
},
|
|
624
632
|
onClick: multiple || selectBox || onChange ? e => onClickHandler(e, data) : undefined,
|
|
625
633
|
key: index,
|
|
@@ -634,6 +642,14 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
634
642
|
})) : null, renderContent(data, keyArr, index));
|
|
635
643
|
};
|
|
636
644
|
useEffect(() => {
|
|
645
|
+
if (isInDropdown === false) {
|
|
646
|
+
var _Array$from;
|
|
647
|
+
const treeViewNode = (_Array$from = Array.from(document.getElementsByClassName('DGN-UI-TreeView'))) === null || _Array$from === void 0 ? void 0 : _Array$from[0];
|
|
648
|
+
const treeViewParentNode = treeViewNode === null || treeViewNode === void 0 ? void 0 : treeViewNode.parentNode;
|
|
649
|
+
if (treeViewParentNode && treeViewParentNode !== null && treeViewParentNode !== void 0 && treeViewParentNode.className.includes('DGN-Dropdown-List')) {
|
|
650
|
+
setIsInDropdown(true);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
637
653
|
currentValue[unique] = {};
|
|
638
654
|
return () => {
|
|
639
655
|
currentValue[unique] = null;
|
|
@@ -687,17 +703,32 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
687
703
|
}
|
|
688
704
|
};
|
|
689
705
|
} else if (disabledRelevantValue) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
if (
|
|
693
|
-
|
|
706
|
+
setTimeout(() => {
|
|
707
|
+
Array.from(ref.current.querySelectorAll('.TreeView-Item.non-child, .DGN-UI-Accordion')).forEach(el => {
|
|
708
|
+
if (el.firstChild.querySelector('input').checked) {
|
|
709
|
+
if (!el.classList.contains('non-child')) {
|
|
710
|
+
handleDisabledChildren(el, true);
|
|
711
|
+
}
|
|
712
|
+
handleDisabledParent(el.parentNode, true);
|
|
694
713
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
});
|
|
714
|
+
});
|
|
715
|
+
}, 200);
|
|
698
716
|
}
|
|
699
717
|
}
|
|
700
718
|
}, []);
|
|
719
|
+
useEffect(() => {
|
|
720
|
+
if (value && multiple) {
|
|
721
|
+
if (disabledRelevantValue) {
|
|
722
|
+
setTimeout(() => {
|
|
723
|
+
Array.from(ref.current.querySelectorAll('.TreeView-Item.non-child, .DGN-UI-Accordion')).forEach(el => {
|
|
724
|
+
if (el.firstChild.querySelector('input').checked) {
|
|
725
|
+
handleDisabledParent(el.parentNode, isChecked);
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}, [isChanged, isChecked]);
|
|
701
732
|
useEffect(() => {
|
|
702
733
|
if (selectAllRef.current) {
|
|
703
734
|
checkedSelectAllCheckbox();
|
|
@@ -793,7 +824,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference)
|
|
|
793
824
|
const TreeViewRootCSS = ({
|
|
794
825
|
colors,
|
|
795
826
|
spacing
|
|
796
|
-
}) => css`
|
|
827
|
+
}, isInDD) => css`
|
|
797
828
|
${displayBlock};
|
|
798
829
|
${positionRelative};
|
|
799
830
|
.DGN-UI-Accordion {
|
|
@@ -806,6 +837,12 @@ const TreeViewRootCSS = ({
|
|
|
806
837
|
&.focus {
|
|
807
838
|
${bgColor(getProp(colors, 'fill/focus'))};
|
|
808
839
|
}
|
|
840
|
+
&.disabled {
|
|
841
|
+
.TreeView-Item {
|
|
842
|
+
${textColor(getProp(colors, 'system/disabled'))};
|
|
843
|
+
}
|
|
844
|
+
${bgColor(getProp(colors, 'system/white'))};
|
|
845
|
+
}
|
|
809
846
|
.Accordion-Icon-Root {
|
|
810
847
|
${displayFlex};
|
|
811
848
|
${flexRow};
|
|
@@ -833,7 +870,7 @@ const TreeViewRootCSS = ({
|
|
|
833
870
|
.TreeView-Content {
|
|
834
871
|
${displayBlock};
|
|
835
872
|
${positionRelative};
|
|
836
|
-
${parseMaxHeight(240)};
|
|
873
|
+
${isInDD ? parseMaxHeight(240) : parseHeight('100%')};
|
|
837
874
|
${overflowYScroll};
|
|
838
875
|
&::-webkit-scrollbar {
|
|
839
876
|
${borderRadius(4)};
|
|
@@ -904,35 +941,34 @@ const TreeViewRootCSS = ({
|
|
|
904
941
|
}
|
|
905
942
|
}
|
|
906
943
|
`;
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
//
|
|
910
|
-
//
|
|
911
|
-
//
|
|
912
|
-
//
|
|
913
|
-
//
|
|
914
|
-
//
|
|
915
|
-
//
|
|
916
|
-
//
|
|
917
|
-
//
|
|
918
|
-
//
|
|
919
|
-
//
|
|
920
|
-
//
|
|
921
|
-
//
|
|
922
|
-
//
|
|
923
|
-
//
|
|
924
|
-
//
|
|
925
|
-
//
|
|
926
|
-
//
|
|
927
|
-
//
|
|
928
|
-
//
|
|
929
|
-
//
|
|
930
|
-
//
|
|
931
|
-
//
|
|
932
|
-
//
|
|
933
|
-
//
|
|
934
|
-
|
|
935
|
-
|
|
944
|
+
TreeView.defaultProps = {
|
|
945
|
+
isInDropdown: false
|
|
946
|
+
// allowSearch: false,
|
|
947
|
+
// autoExpandToResult: true,
|
|
948
|
+
// className: '',
|
|
949
|
+
// dataSource: [],
|
|
950
|
+
// disabled: false,
|
|
951
|
+
// disabledBoldResult: false,
|
|
952
|
+
// disabledRelevantValue: false,
|
|
953
|
+
// displayExpr: 'name',
|
|
954
|
+
// expand: false,
|
|
955
|
+
// expandIcon: 'ArrowDown',
|
|
956
|
+
// id: 'id',
|
|
957
|
+
// multiple: false,
|
|
958
|
+
// multipleValueMode: 'multiple',
|
|
959
|
+
// parentID: 'parentID',
|
|
960
|
+
// renderAsyncFromLevel: 2,
|
|
961
|
+
// renderAsyncWithLength: 200,
|
|
962
|
+
// searchMode: 'contains',
|
|
963
|
+
// searchProps: {},
|
|
964
|
+
// selectAll: false,
|
|
965
|
+
// selectAllLabel: getGlobal('selectAll'),
|
|
966
|
+
// selectBox: false,
|
|
967
|
+
// showChildrenOfResult: false,
|
|
968
|
+
// showSelectedItems: false,
|
|
969
|
+
// value: [],
|
|
970
|
+
// valueExpr: '',
|
|
971
|
+
};
|
|
936
972
|
TreeView.propTypes = {
|
|
937
973
|
/** If `true`, display input box search. */
|
|
938
974
|
allowSearch: PropTypes.bool,
|
package/global/index.js
CHANGED
|
@@ -161,6 +161,86 @@ const globalObject = {
|
|
|
161
161
|
inputPlaceholder: 'Type something',
|
|
162
162
|
dropdownPlaceholder: 'Select'
|
|
163
163
|
},
|
|
164
|
+
zh: {
|
|
165
|
+
agree: '同意',
|
|
166
|
+
cancel: '取消',
|
|
167
|
+
close: '关闭',
|
|
168
|
+
confirm: '确认',
|
|
169
|
+
error: '错误',
|
|
170
|
+
unknownError: '未知错误',
|
|
171
|
+
no: '否',
|
|
172
|
+
noDataText: '无数据',
|
|
173
|
+
notify: '通知',
|
|
174
|
+
ok: '确定',
|
|
175
|
+
showLess: '收起',
|
|
176
|
+
showMore: '展开',
|
|
177
|
+
yes: '是',
|
|
178
|
+
warning: '警告',
|
|
179
|
+
// attachment
|
|
180
|
+
dropFileHere: '将文件拖到此处',
|
|
181
|
+
deleteNotifyText: '您确定要删除此附件吗?',
|
|
182
|
+
attachText: '附件',
|
|
183
|
+
noFileText: '无附件',
|
|
184
|
+
byName: '按名称',
|
|
185
|
+
byType: '按类型',
|
|
186
|
+
bySize: '按大小',
|
|
187
|
+
byDate: '按日期',
|
|
188
|
+
byOwner: '按所有者',
|
|
189
|
+
errorDefault: {
|
|
190
|
+
maxFile: ' 超过允许的数量!',
|
|
191
|
+
maxSize: ' 文件过大!',
|
|
192
|
+
fileType: ' 文件格式不正确!',
|
|
193
|
+
existingFile: ' 已经添加!'
|
|
194
|
+
},
|
|
195
|
+
// Paging
|
|
196
|
+
lineNumber: '每页条数',
|
|
197
|
+
total: '总计',
|
|
198
|
+
// Transfer
|
|
199
|
+
choices: '可选',
|
|
200
|
+
chosen: '已选',
|
|
201
|
+
selected: '已选择',
|
|
202
|
+
// Date Picker
|
|
203
|
+
helperInvalid: '无效',
|
|
204
|
+
helperValid: '有效',
|
|
205
|
+
label: '时间',
|
|
206
|
+
weekdaysLong: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
|
|
207
|
+
weekdaysShort: ['一', '二', '三', '四', '五', '六', '日'],
|
|
208
|
+
// Daterange Picker
|
|
209
|
+
today: '今天',
|
|
210
|
+
yesterday: '昨天',
|
|
211
|
+
thisWeek: '本周',
|
|
212
|
+
thisMonth: '本月',
|
|
213
|
+
// Time Picker
|
|
214
|
+
months: {
|
|
215
|
+
full: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
|
|
216
|
+
notFull: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
|
|
217
|
+
},
|
|
218
|
+
days: {
|
|
219
|
+
full: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
|
|
220
|
+
notFull: ['日', '一', '二', '三', '四', '五', '六']
|
|
221
|
+
},
|
|
222
|
+
night: '夜',
|
|
223
|
+
day: '日',
|
|
224
|
+
month: '月',
|
|
225
|
+
year: '年',
|
|
226
|
+
save: '保存',
|
|
227
|
+
now: '现在',
|
|
228
|
+
// Localize
|
|
229
|
+
selectAll: '全选',
|
|
230
|
+
thisFieldIsRequired: '此字段为必填项',
|
|
231
|
+
validate: {
|
|
232
|
+
isEmail: '邮箱无效',
|
|
233
|
+
isNotEmptyString: '不能为空',
|
|
234
|
+
isNotEmptyObject: '必须包含至少一个属性',
|
|
235
|
+
isNotEmptyArray: '必须包含至少一个元素',
|
|
236
|
+
invalidInput: '输入值不正确',
|
|
237
|
+
max: '超过允许的最大值',
|
|
238
|
+
min: '未达到允许的最小值',
|
|
239
|
+
required: '此字段为必填项'
|
|
240
|
+
},
|
|
241
|
+
inputPlaceholder: '请输入内容',
|
|
242
|
+
dropdownPlaceholder: '请选择'
|
|
243
|
+
},
|
|
164
244
|
//Global variable
|
|
165
245
|
delayOnInput: 500,
|
|
166
246
|
maxSizeUpload: Infinity
|
package/icons/basic.js
CHANGED
|
@@ -1454,6 +1454,30 @@ export const Category = /*#__PURE__*/memo(({
|
|
|
1454
1454
|
fill: fillColor(color)
|
|
1455
1455
|
}));
|
|
1456
1456
|
});
|
|
1457
|
+
export const Camera = /*#__PURE__*/memo(({
|
|
1458
|
+
width,
|
|
1459
|
+
height,
|
|
1460
|
+
color = 'system/rest',
|
|
1461
|
+
viewBox = false
|
|
1462
|
+
}) => {
|
|
1463
|
+
return viewBox ? /*#__PURE__*/React.createElement("svg", {
|
|
1464
|
+
width: width || 24,
|
|
1465
|
+
height: height || 24,
|
|
1466
|
+
viewBox: "0 0 24 24",
|
|
1467
|
+
fill: "none"
|
|
1468
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
1469
|
+
d: "M16.8301 4H20C21.1 4 22 4.9 22 6V18C22 19.1 21.1 20 20 20H4C2.9 20 2 19.1 2 18V6C2 4.9 2.9 4 4 4H7.16992L9 2H15L16.8301 4ZM12 7C9.24 7 7 9.24 7 12C7 14.76 9.24 17 12 17C14.76 17 17 14.76 17 12C17 9.24 14.76 7 12 7ZM12 9C13.6569 9 15 10.3431 15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12C9 10.3431 10.3431 9 12 9Z",
|
|
1470
|
+
fill: fillColor(color)
|
|
1471
|
+
})) : /*#__PURE__*/React.createElement("svg", {
|
|
1472
|
+
width: width || 20,
|
|
1473
|
+
height: height || 18,
|
|
1474
|
+
viewBox: "0 0 20 18",
|
|
1475
|
+
fill: "none"
|
|
1476
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
1477
|
+
d: "M14.8301 2H18C19.1 2 20 2.9 20 4V16C20 17.1 19.1 18 18 18H2C0.9 18 0 17.1 0 16V4C0 2.9 0.9 2 2 2H5.16992L7 0H13L14.8301 2ZM10 5C7.24 5 5 7.24 5 10C5 12.76 7.24 15 10 15C12.76 15 15 12.76 15 10C15 7.24 12.76 5 10 5ZM10 7C11.6569 7 13 8.34315 13 10C13 11.6569 11.6569 13 10 13C8.34315 13 7 11.6569 7 10C7 8.34315 8.34315 7 10 7Z",
|
|
1478
|
+
fill: fillColor(color)
|
|
1479
|
+
}));
|
|
1480
|
+
});
|
|
1457
1481
|
export const CenterFocus = /*#__PURE__*/memo(({
|
|
1458
1482
|
width,
|
|
1459
1483
|
height,
|
package/locale/index.js
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -42,6 +42,13 @@ npm test
|
|
|
42
42
|
|
|
43
43
|
## Changelog
|
|
44
44
|
|
|
45
|
+
## 1.4.54
|
|
46
|
+
- \[Added\]: Icon – Add Icon Camera
|
|
47
|
+
- \[Fixed\]: Treeview - Fix bug Treeview keeps the search bar visible while scrolling
|
|
48
|
+
- \[Fixed\]: Dropdown – Fix Dropdown treeview size
|
|
49
|
+
- \[Added\]: Paging, TextInput, Label, Dropdown,... – Update Chinese language
|
|
50
|
+
|
|
51
|
+
|
|
45
52
|
## 1.4.53
|
|
46
53
|
- \[Added\]: Icon – Add IconMenu MHRP09N0036, MHRP09N0037
|
|
47
54
|
- \[Added\]: Icon – Add IconMenu MHRP25N0009
|
package/theme/settings.js
CHANGED
|
@@ -3,6 +3,7 @@ import { font } from "../styles/font";
|
|
|
3
3
|
import { typography as typographies } from "../styles/typography";
|
|
4
4
|
import createTheme from "./createTheme";
|
|
5
5
|
import locale from "../locale";
|
|
6
|
+
import { getFormatDateByCountry, getDecimalSymbolByCountry } from "../utils/getLang";
|
|
6
7
|
// import { getGlobal } from 'global';
|
|
7
8
|
const {
|
|
8
9
|
fontSize,
|
|
@@ -345,7 +346,7 @@ const settings = {
|
|
|
345
346
|
className: '',
|
|
346
347
|
disabled: false,
|
|
347
348
|
error: '',
|
|
348
|
-
format: locale.get()
|
|
349
|
+
format: getFormatDateByCountry(locale.get()),
|
|
349
350
|
label: '',
|
|
350
351
|
readOnly: false,
|
|
351
352
|
required: false,
|
|
@@ -360,7 +361,7 @@ const settings = {
|
|
|
360
361
|
controls: false,
|
|
361
362
|
disabled: false,
|
|
362
363
|
displayAnotherMonth: true,
|
|
363
|
-
displayFormat: locale.get()
|
|
364
|
+
displayFormat: getFormatDateByCountry(locale.get()),
|
|
364
365
|
pressESCToClose: true,
|
|
365
366
|
readOnly: false,
|
|
366
367
|
required: false,
|
|
@@ -596,7 +597,7 @@ const settings = {
|
|
|
596
597
|
autoFocus: false,
|
|
597
598
|
className: '',
|
|
598
599
|
decimalDigit: Infinity,
|
|
599
|
-
decimalSymbol: locale.get()
|
|
600
|
+
decimalSymbol: getDecimalSymbolByCountry(locale.get()),
|
|
600
601
|
disabled: false,
|
|
601
602
|
disabledNegative: false,
|
|
602
603
|
endIcon: '',
|
package/utils/getLang.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { format } from 'date-fns';
|
|
2
|
+
import { lowerCaseDayYear } from "../components/form-control/date-input/utils";
|
|
3
|
+
import { enUS, zhCN, vi, ja } from 'date-fns/locale';
|
|
4
|
+
const getFormatDateByCountry = (lang, isDateFns = false) => {
|
|
5
|
+
let result = '';
|
|
6
|
+
switch (lang) {
|
|
7
|
+
case 'en':
|
|
8
|
+
result = isDateFns ? enUS : 'MM/DD/YYYY';
|
|
9
|
+
break;
|
|
10
|
+
case 'zh':
|
|
11
|
+
result = isDateFns ? zhCN : 'YYYY/MM/DD';
|
|
12
|
+
break;
|
|
13
|
+
case 'ja':
|
|
14
|
+
result = isDateFns ? ja : 'YYYY/MM/DD';
|
|
15
|
+
break;
|
|
16
|
+
case 'vi':
|
|
17
|
+
result = isDateFns ? vi : 'DD/MM/YYYY';
|
|
18
|
+
break;
|
|
19
|
+
default:
|
|
20
|
+
result = 'DD/MM/YYYY';
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const parseDateString = (date, formatStr, locale) => {
|
|
26
|
+
return format(date, lowerCaseDayYear(formatStr), {
|
|
27
|
+
locale: getFormatDateByCountry(locale, true)
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const getDecimalSymbolByCountry = lang => {
|
|
31
|
+
let result = '';
|
|
32
|
+
switch (lang) {
|
|
33
|
+
case 'vi': // Việt Nam
|
|
34
|
+
case 'de': // Đức
|
|
35
|
+
case 'fr': // Pháp
|
|
36
|
+
case 'it': // Ý
|
|
37
|
+
case 'es': // Tây Ban Nha
|
|
38
|
+
case 'ru':
|
|
39
|
+
// Nga
|
|
40
|
+
result = ','; // Dấu phẩy làm thập phân
|
|
41
|
+
break;
|
|
42
|
+
case 'en': // Anh, Mỹ
|
|
43
|
+
case 'zh': // Trung Quốc
|
|
44
|
+
case 'ja': // Nhật Bản
|
|
45
|
+
default:
|
|
46
|
+
result = '.'; // Dấu chấm làm thập phân
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const getThousandSeparatorByCountry = lang => {
|
|
52
|
+
switch (lang) {
|
|
53
|
+
case 'vi': // Việt Nam
|
|
54
|
+
case 'de': // Đức
|
|
55
|
+
case 'es':
|
|
56
|
+
// Tây Ban Nha
|
|
57
|
+
return '.';
|
|
58
|
+
case 'fr':
|
|
59
|
+
// Pháp
|
|
60
|
+
return '\u00A0';
|
|
61
|
+
// space không ngắt
|
|
62
|
+
case 'en': // Anh, Mỹ
|
|
63
|
+
case 'zh': // Trung Quốc
|
|
64
|
+
case 'ja': // Nhật
|
|
65
|
+
default:
|
|
66
|
+
return ',';
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export { getFormatDateByCountry, parseDateString, getDecimalSymbolByCountry, getThousandSeparatorByCountry };
|