diginet-core-ui 1.3.35-beta.6 → 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.
@@ -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,
@@ -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
- ...props
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(/(\d)(?=(\d{3})+\b)/g, '$1' + thousandSymbol); // add thousand symbol to number
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;
@@ -253,12 +249,25 @@ const NumberInput = /*#__PURE__*/forwardRef(({
253
249
  useEffect(() => {
254
250
  var _valueProps;
255
251
 
256
- if (typeof valueProps !== 'undefined') setValue(parseNumberToMoney((_valueProps = valueProps) === null || _valueProps === void 0 ? void 0 : _valueProps.toString().replace(regexValidNumber, ''), true));
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));
257
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
+ });
258
267
  return jsx("div", {
259
268
  ref: ref,
260
269
  css: NumberInputRoot,
261
- ...props
270
+ className: ['DGN-UI-NumberInput', className].join(' ').trim().replace(/\s+/g, ' ')
262
271
  }, !!label && jsx(Label, {
263
272
  required: required,
264
273
  disabled: disabled
@@ -316,15 +325,13 @@ NumberInput.defaultProps = {
316
325
  decimalDigit: 0,
317
326
  thousandSeparator: false,
318
327
  min: -Infinity,
319
- max: Infinity
328
+ max: Infinity,
329
+ className: ''
320
330
  };
321
331
  NumberInput.propTypes = {
322
332
  /** the type of border you want to display */
323
333
  viewType: PropTypes.oneOf(['underlined', 'outlined']),
324
334
 
325
- /** the type of value which you want to return */
326
- valueTypeReturn: PropTypes.oneOf(['number', 'string']),
327
-
328
335
  /** separator symbol */
329
336
  decimalSymbol: PropTypes.oneOf([',', '.']),
330
337
 
@@ -355,9 +362,6 @@ NumberInput.propTypes = {
355
362
  /** error for input */
356
363
  error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
357
364
 
358
- /** type auto complete of input (like new-password) */
359
- autoComplete: PropTypes.string,
360
-
361
365
  /** icon at start */
362
366
  startIcon: PropTypes.any,
363
367
 
@@ -388,25 +392,6 @@ NumberInput.propTypes = {
388
392
  /** style inline of input in NumberInput component */
389
393
  inputStyle: PropTypes.object,
390
394
 
391
- /** any props of label in NumberInput component */
392
- labelProps: PropTypes.object,
393
-
394
- /** any props of error in NumberInput component */
395
- errorProps: PropTypes.object,
396
-
397
- /**
398
- * the format to display value<br/>
399
- * * function: value => function(value)<br/>
400
- * * string: Example: '#.###', '# ###', '#.### 2%', '#.### %%'<br/>
401
- * &nbsp;&nbsp;&nbsp;&nbsp;#: integer part digit<br/>
402
- * &nbsp;&nbsp;&nbsp;&nbsp;. / '_': separator symbol<br/>
403
- * &nbsp;&nbsp;&nbsp;&nbsp;%: decimal digit, '2%' === '%%'
404
- */
405
- format: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
406
-
407
- /** The function to get ref of NumberInput component */
408
- refs: PropTypes.func,
409
-
410
395
  /** validation value, argument can:<br/>
411
396
  * * string: the validation rule. Example required.<br/>
412
397
  * * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
@@ -426,9 +411,6 @@ NumberInput.propTypes = {
426
411
  /** on change function */
427
412
  onChange: PropTypes.func,
428
413
 
429
- /** on blur function */
430
- onBlur: PropTypes.func,
431
-
432
414
  /** on focus function */
433
415
  onFocus: PropTypes.func,
434
416
 
@@ -442,6 +424,9 @@ NumberInput.propTypes = {
442
424
  delayOnChange: PropTypes.number,
443
425
 
444
426
  /** inputRef of delayOnChange component */
445
- thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])])
427
+ thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])]),
428
+
429
+ /** className of component */
430
+ className: PropTypes.string
446
431
  };
447
432
  export default NumberInput;
@@ -1,102 +1,100 @@
1
1
  /** @jsxRuntime classic */
2
2
 
3
3
  /** @jsx jsx */
4
- import { memo, useMemo, useEffect, useContext, useRef, forwardRef } from 'react';
4
+ import { memo, useMemo, useContext, useRef, forwardRef, useImperativeHandle } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import ModalContext from './context';
8
- import { brand22 } from '../../styles/colors';
9
8
  import { ButtonIcon, Typography } from '../';
9
+ import { alignCenter, borderBox, flexRow, justifyBetween, positionRelative } from '../../styles/general';
10
+ import { color as colors } from '../../styles/colors';
11
+ const {
12
+ fill: {
13
+ headerbar
14
+ }
15
+ } = colors;
10
16
  const ModalHeader = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
11
17
  title,
12
18
  className,
13
19
  children,
14
20
  style,
15
- refs,
16
- ...props
17
- }, ref) => {
18
- if (!ref) {
19
- ref = useRef(null);
20
- }
21
-
21
+ showClose
22
+ }, reference) => {
22
23
  const modal = useContext(ModalContext);
23
- const ModalHeaderBox = css`
24
- display: flex;
25
- position: relative;
26
- background-color: ${brand22};
27
- width: 100%;
28
- height: 56px;
29
- padding: 16px 24px;
30
- margin-bottom: 2px;
31
- align-items: center;
32
- justify-content: space-between;
33
- border-radius: 4px 4px 0px 0px;
34
- box-sizing: border-box;
35
- box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
36
- cursor: ${modal.onMoveModal ? 'move' : 'inherit'};
37
- order: 1;
38
- `;
39
- const HeaderTitle = css`
40
- display: flex;
41
- position: relative;
42
- align-items: center;
43
- width: calc(100% - 40px);
44
- `;
45
- const ClearIconBox = css`
46
- display: flex;
47
- position: relative;
48
- width: 24px;
49
- height: 24px;
50
- justify-content: center;
51
- align-items: center;
52
- margin-left: 16px;
53
- `;
54
- useEffect(() => {
55
- !!refs && refs(ref);
56
- }, []);
57
- const Header = useMemo(() => jsx("div", {
58
- css: ModalHeaderBox,
59
- className: 'DGN-UI-Modal-Header ' + className,
60
- ...props,
24
+ const ref = useRef(null);
25
+
26
+ const _ModalHeaderCSS = ModalHeaderCSS(modal);
27
+
28
+ useImperativeHandle(reference, () => {
29
+ const currentRef = ref.current || {};
30
+ const _instance = {}; // methods
31
+
32
+ _instance.__proto__ = {}; // hidden methods
33
+
34
+ currentRef.instance = _instance;
35
+ return currentRef;
36
+ });
37
+ return useMemo(() => jsx("div", {
38
+ css: _ModalHeaderCSS,
39
+ className: ['DGN-UI-Modal-Header', className].join(' ').trim().replace(/\s+/g, ' '),
61
40
  style: style,
62
41
  onMouseDown: modal.onMoveModal,
63
42
  ref: ref
64
- }, jsx("div", {
65
- css: HeaderTitle
66
43
  }, jsx(Typography, {
67
44
  type: 'h3',
68
45
  style: {
69
46
  whiteSpace: 'nowrap',
70
47
  overflow: 'hidden',
71
- textOverflow: 'ellipsis'
48
+ textOverflow: 'ellipsis',
49
+ width: '100%'
72
50
  }
73
- }, children ? children : title)), jsx("div", {
74
- css: ClearIconBox
75
- }, jsx(ButtonIcon, {
51
+ }, children ? children : title), showClose && jsx(ButtonIcon, {
76
52
  viewType: 'ghost',
77
- name: 'close',
53
+ name: 'Close',
54
+ style: {
55
+ marginLeft: 16
56
+ },
78
57
  onClick: modal.close
79
- }))), [children, title, style]);
80
- return Header;
58
+ })), [children, title, style, className, showClose]);
81
59
  }));
60
+
61
+ const ModalHeaderCSS = modal => css`
62
+ ${flexRow};
63
+ ${positionRelative};
64
+ ${justifyBetween};
65
+ ${alignCenter};
66
+ ${borderBox};
67
+ background-color: ${headerbar};
68
+ width: 100%;
69
+ height: 56px;
70
+ padding: 16px 24px;
71
+ margin-bottom: 2px;
72
+ border-radius: 4px 4px 0px 0px;
73
+ box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
74
+ cursor: ${modal.onMoveModal ? 'move' : 'inherit'};
75
+ order: 1;
76
+ `;
77
+
82
78
  ModalHeader.defaultProps = {
83
79
  title: '',
84
- className: ''
80
+ className: '',
81
+ style: {},
82
+ showClose: true
85
83
  };
86
84
  ModalHeader.propTypes = {
87
- /** customize style inline */
85
+ /** style inline of component */
88
86
  style: PropTypes.object,
89
87
 
90
- /** class of ModalHeader */
88
+ /** class for component */
91
89
  className: PropTypes.string,
92
90
 
93
- /** get modal header ref by function */
94
- refs: PropTypes.func,
91
+ /** content for header (not work when have children) */
92
+ title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
95
93
 
96
- /** title for header */
97
- title: PropTypes.node,
94
+ /** content in header (priority) */
95
+ children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
98
96
 
99
- /** child content in header (like title) */
100
- children: PropTypes.node
97
+ /** show close modal button */
98
+ showClose: PropTypes.bool
101
99
  };
102
100
  export default ModalHeader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.35-beta.6",
3
+ "version": "1.3.35-beta.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",