diginet-core-ui 1.3.69 → 1.3.70
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/checkbox/index.js +15 -4
- package/components/form-control/money-input/index.js +7 -3
- package/components/form-control/number-input/index2.js +26 -22
- package/components/form-control/phone-input/index.js +13 -9
- package/components/form-control/radio/index.js +15 -6
- package/components/form-control/text-input/index.js +7 -3
- package/components/form-control/toggle/index.js +17 -5
- package/components/paging/page-info.js +23 -23
- package/components/paging/page-selector2.js +23 -23
- package/components/tooltip/index.js +68 -72
- package/package.json +1 -1
- package/readme.md +9 -0
- package/utils/sb-teamplate.js +104 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
4
|
import { css, jsx } from '@emotion/core';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
-
import { forwardRef, memo, useEffect, useRef, useState, useImperativeHandle } from 'react';
|
|
6
|
+
import React, { forwardRef, memo, useEffect, useRef, useState, useImperativeHandle } from 'react';
|
|
7
7
|
import { Typography } from '../..';
|
|
8
8
|
import { alignCenter, alignStart, borderBox, cursorPointer, displayBlock, flexRow, positionAbsolute, positionRelative, cursorNoDrop, parseWidthHeight } from '../../../styles/general';
|
|
9
9
|
import { randomString } from '../../../utils';
|
|
@@ -20,7 +20,10 @@ const {
|
|
|
20
20
|
pressed: clFillPressed
|
|
21
21
|
},
|
|
22
22
|
disabled: clDisabled,
|
|
23
|
-
formal2: clFormal2
|
|
23
|
+
formal2: clFormal2,
|
|
24
|
+
semantic: {
|
|
25
|
+
danger: clDanger
|
|
26
|
+
}
|
|
24
27
|
},
|
|
25
28
|
spacing
|
|
26
29
|
} = theme;
|
|
@@ -45,6 +48,7 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
45
48
|
width,
|
|
46
49
|
labelProps,
|
|
47
50
|
stopPropagation,
|
|
51
|
+
required,
|
|
48
52
|
...props
|
|
49
53
|
}, reference) => {
|
|
50
54
|
if (!inputRef) {
|
|
@@ -150,7 +154,11 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
150
154
|
},
|
|
151
155
|
color: disabled ? clDisabled : '',
|
|
152
156
|
...labelProps
|
|
153
|
-
}, children || label
|
|
157
|
+
}, jsx(React.Fragment, null, children || label, required && jsx("span", {
|
|
158
|
+
style: {
|
|
159
|
+
color: disabled ? clDisabled : clDanger
|
|
160
|
+
}
|
|
161
|
+
}, "*"))))));
|
|
154
162
|
}));
|
|
155
163
|
|
|
156
164
|
const CheckBoxSquareCSS = (width, clMain) => css`
|
|
@@ -330,6 +338,9 @@ Checkbox.propTypes = {
|
|
|
330
338
|
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
331
339
|
|
|
332
340
|
/** The value of input */
|
|
333
|
-
value: PropTypes.any
|
|
341
|
+
value: PropTypes.any,
|
|
342
|
+
|
|
343
|
+
/** If `true`, the label will indicate that the checkbox is required. */
|
|
344
|
+
required: PropTypes.bool
|
|
334
345
|
};
|
|
335
346
|
export default Checkbox;
|
|
@@ -124,6 +124,7 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
124
124
|
prefix,
|
|
125
125
|
suffix,
|
|
126
126
|
labelProps,
|
|
127
|
+
helperTextProps,
|
|
127
128
|
...props
|
|
128
129
|
}, reference) => {
|
|
129
130
|
const ref = useRef(null);
|
|
@@ -445,9 +446,9 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
445
446
|
onKeyDown: onKeyDownHandler,
|
|
446
447
|
onKeyUp: onKeyUp,
|
|
447
448
|
onPaste: onPasteHandler
|
|
448
|
-
}), isError && jsx(HelperText, {
|
|
449
|
+
}), isError && jsx(HelperText, { ...helperTextProps,
|
|
449
450
|
disabled: disabled
|
|
450
|
-
}, error), !isError && validateResult && jsx(HelperText, {
|
|
451
|
+
}, error), !isError && validateResult && jsx(HelperText, { ...helperTextProps,
|
|
451
452
|
disabled: disabled
|
|
452
453
|
}, validateResult));
|
|
453
454
|
}));
|
|
@@ -585,6 +586,9 @@ MoneyInput.propTypes = {
|
|
|
585
586
|
inputRef: PropTypes.any,
|
|
586
587
|
|
|
587
588
|
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
588
|
-
labelProps: PropTypes.object
|
|
589
|
+
labelProps: PropTypes.object,
|
|
590
|
+
|
|
591
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) of helper text. */
|
|
592
|
+
helperTextProps: PropTypes.object
|
|
589
593
|
};
|
|
590
594
|
export default MoneyInput;
|
|
@@ -53,7 +53,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
53
53
|
className,
|
|
54
54
|
maxDigit,
|
|
55
55
|
autoWidth,
|
|
56
|
-
labelProps
|
|
56
|
+
labelProps,
|
|
57
|
+
helperTextProps
|
|
57
58
|
}, reference) => {
|
|
58
59
|
inputRef = inputRef || useRef(null);
|
|
59
60
|
const pos = useRef(null);
|
|
@@ -79,13 +80,13 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
79
80
|
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
|
80
81
|
|
|
81
82
|
if (valueProps || valueProps === 0) valueProps = clamp(valueProps, min, max);
|
|
82
|
-
/**
|
|
83
|
-
* Convert number to format money
|
|
84
|
-
* @param vl {number} - value
|
|
85
|
-
* @type {function(*): number}
|
|
86
|
-
* @return {string}
|
|
87
|
-
* @example 1200300.123 => 1,200,300.123
|
|
88
|
-
* @example 1200300,123 => 1.200.300,123
|
|
83
|
+
/**
|
|
84
|
+
* Convert number to format money
|
|
85
|
+
* @param vl {number} - value
|
|
86
|
+
* @type {function(*): number}
|
|
87
|
+
* @return {string}
|
|
88
|
+
* @example 1200300.123 => 1,200,300.123
|
|
89
|
+
* @example 1200300,123 => 1.200.300,123
|
|
89
90
|
*/
|
|
90
91
|
|
|
91
92
|
const parseNumberToMoney = useCallback((vl, isNumber) => {
|
|
@@ -119,13 +120,13 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
119
120
|
|
|
120
121
|
return number;
|
|
121
122
|
}, [decimalSymbol, max, value]);
|
|
122
|
-
/**
|
|
123
|
-
* Convert money to format number
|
|
124
|
-
* @param vl {string} - value
|
|
125
|
-
* @type {function(*): number}
|
|
126
|
-
* @return {number}
|
|
127
|
-
* @example 1,200,300.123 => 1200300.123
|
|
128
|
-
* @example 1.200.300,123 => 1200300.123
|
|
123
|
+
/**
|
|
124
|
+
* Convert money to format number
|
|
125
|
+
* @param vl {string} - value
|
|
126
|
+
* @type {function(*): number}
|
|
127
|
+
* @return {number}
|
|
128
|
+
* @example 1,200,300.123 => 1200300.123
|
|
129
|
+
* @example 1.200.300,123 => 1200300.123
|
|
129
130
|
*/
|
|
130
131
|
|
|
131
132
|
const convertMoneyToNumber = useCallback((vl, isNumber) => {
|
|
@@ -305,9 +306,9 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
305
306
|
});
|
|
306
307
|
},
|
|
307
308
|
onBlur: e => _onBlur(e)
|
|
308
|
-
}), !!error && jsx(HelperText, {
|
|
309
|
+
}), !!error && jsx(HelperText, { ...helperTextProps,
|
|
309
310
|
disabled: disabled
|
|
310
|
-
}, error), !error && validateResult && jsx(HelperText, {
|
|
311
|
+
}, error), !error && validateResult && jsx(HelperText, { ...helperTextProps,
|
|
311
312
|
disabled: disabled
|
|
312
313
|
}, validateResult));
|
|
313
314
|
});
|
|
@@ -397,10 +398,10 @@ NumberInput.propTypes = {
|
|
|
397
398
|
/** style inline of input in NumberInput component */
|
|
398
399
|
inputStyle: PropTypes.object,
|
|
399
400
|
|
|
400
|
-
/** validation value, argument can:<br/>
|
|
401
|
-
* * string: the validation rule. Example required.<br/>
|
|
402
|
-
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
403
|
-
* * array: the validation rule list, insist object/string
|
|
401
|
+
/** validation value, argument can:<br/>
|
|
402
|
+
* * string: the validation rule. Example required.<br/>
|
|
403
|
+
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
404
|
+
* * array: the validation rule list, insist object/string
|
|
404
405
|
*/
|
|
405
406
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
406
407
|
|
|
@@ -444,6 +445,9 @@ NumberInput.propTypes = {
|
|
|
444
445
|
autoWidth: PropTypes.bool,
|
|
445
446
|
|
|
446
447
|
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
447
|
-
labelProps: PropTypes.object
|
|
448
|
+
labelProps: PropTypes.object,
|
|
449
|
+
|
|
450
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) of helper text. */
|
|
451
|
+
helperTextProps: PropTypes.object
|
|
448
452
|
};
|
|
449
453
|
export default NumberInput;
|
|
@@ -43,6 +43,7 @@ const PhoneInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
43
43
|
onKeyDown,
|
|
44
44
|
onKeyUp,
|
|
45
45
|
labelProps,
|
|
46
|
+
helperTextProps,
|
|
46
47
|
...props
|
|
47
48
|
}, reference) => {
|
|
48
49
|
const ref = useRef(null);
|
|
@@ -324,7 +325,7 @@ const PhoneInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
324
325
|
startIconProps: {
|
|
325
326
|
className: 'non-effect'
|
|
326
327
|
}
|
|
327
|
-
}), !!error && jsx(HelperText, {
|
|
328
|
+
}), !!error && jsx(HelperText, { ...helperTextProps,
|
|
328
329
|
disabled: disabled
|
|
329
330
|
}, error));
|
|
330
331
|
}));
|
|
@@ -397,13 +398,13 @@ PhoneInput.propTypes = {
|
|
|
397
398
|
/** on input function */
|
|
398
399
|
onInput: PropTypes.func,
|
|
399
400
|
|
|
400
|
-
/**
|
|
401
|
-
* on change function. Return a object, example:<br/>
|
|
402
|
-
* {<br/>
|
|
403
|
-
* target: {value: "(+84) 123 456 789", ...}<br/>
|
|
404
|
-
* value: 0123456789<br/>
|
|
405
|
-
* countryCode: 84<br/>
|
|
406
|
-
* }
|
|
401
|
+
/**
|
|
402
|
+
* on change function. Return a object, example:<br/>
|
|
403
|
+
* {<br/>
|
|
404
|
+
* target: {value: "(+84) 123 456 789", ...}<br/>
|
|
405
|
+
* value: 0123456789<br/>
|
|
406
|
+
* countryCode: 84<br/>
|
|
407
|
+
* }
|
|
407
408
|
*/
|
|
408
409
|
onChange: PropTypes.func,
|
|
409
410
|
|
|
@@ -417,6 +418,9 @@ PhoneInput.propTypes = {
|
|
|
417
418
|
inputRef: PropTypes.any,
|
|
418
419
|
|
|
419
420
|
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
|
|
420
|
-
labelProps: PropTypes.object
|
|
421
|
+
labelProps: PropTypes.object,
|
|
422
|
+
|
|
423
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) of helper text. */
|
|
424
|
+
helperTextProps: PropTypes.object
|
|
421
425
|
};
|
|
422
426
|
export default PhoneInput;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
4
|
import { css, jsx } from '@emotion/core';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
-
import { forwardRef, memo, useState, useRef, useEffect, useMemo } from 'react';
|
|
6
|
+
import React, { forwardRef, memo, useState, useRef, useEffect, useMemo } from 'react';
|
|
7
7
|
import theme from '../../../theme/settings';
|
|
8
8
|
import { randomString } from '../../../utils';
|
|
9
9
|
import Typography from './../../typography';
|
|
@@ -18,7 +18,10 @@ const {
|
|
|
18
18
|
active: clSystemActive,
|
|
19
19
|
rest: clSystemRest
|
|
20
20
|
},
|
|
21
|
-
disabled: clDisabled
|
|
21
|
+
disabled: clDisabled,
|
|
22
|
+
semantic: {
|
|
23
|
+
danger: clDanger
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
} = theme;
|
|
24
27
|
const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
@@ -36,6 +39,7 @@ const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
36
39
|
inputRef,
|
|
37
40
|
inputProps,
|
|
38
41
|
labelProps,
|
|
42
|
+
required,
|
|
39
43
|
...props
|
|
40
44
|
}, ref) => {
|
|
41
45
|
if (!inputRef) {
|
|
@@ -94,7 +98,11 @@ const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
94
98
|
color: disabled ? clDisabled : '',
|
|
95
99
|
type: 'p1',
|
|
96
100
|
...labelProps
|
|
97
|
-
}, label !== null && label !== void 0 ? label : value
|
|
101
|
+
}, jsx(React.Fragment, null, label !== null && label !== void 0 ? label : value, required && jsx("span", {
|
|
102
|
+
style: {
|
|
103
|
+
color: disabled ? clDisabled : clDanger
|
|
104
|
+
}
|
|
105
|
+
}, "*")))));
|
|
98
106
|
}, [disabled, onChange, readOnly, checkedState]);
|
|
99
107
|
}));
|
|
100
108
|
const formCheckCSS = css`
|
|
@@ -167,8 +175,6 @@ Radio.defaultProps = {
|
|
|
167
175
|
disabled: false,
|
|
168
176
|
readOnly: false,
|
|
169
177
|
defaultChecked: false,
|
|
170
|
-
label: '',
|
|
171
|
-
value: '',
|
|
172
178
|
className: '',
|
|
173
179
|
width: 20,
|
|
174
180
|
labelProps: {}
|
|
@@ -213,6 +219,9 @@ Radio.propTypes = {
|
|
|
213
219
|
readOnly: PropTypes.bool,
|
|
214
220
|
|
|
215
221
|
/** Props for Typography of label. */
|
|
216
|
-
labelProps: PropTypes.object
|
|
222
|
+
labelProps: PropTypes.object,
|
|
223
|
+
|
|
224
|
+
/** If `true`, the label will indicate that the Radio is required. */
|
|
225
|
+
required: PropTypes.bool
|
|
217
226
|
};
|
|
218
227
|
export default Radio;
|
|
@@ -67,6 +67,7 @@ const TextInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
67
67
|
onPaste,
|
|
68
68
|
validates,
|
|
69
69
|
autoWidth,
|
|
70
|
+
helperTextProps,
|
|
70
71
|
...props
|
|
71
72
|
}, reference) => {
|
|
72
73
|
const ref = useRef(null);
|
|
@@ -367,10 +368,10 @@ const TextInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
367
368
|
onKeyUp: onKeyUp,
|
|
368
369
|
onPaste: onPaste,
|
|
369
370
|
value: valueProp
|
|
370
|
-
}), isError && jsx(HelperText, {
|
|
371
|
+
}), isError && jsx(HelperText, { ...helperTextProps,
|
|
371
372
|
disabled: disabled,
|
|
372
373
|
status: status
|
|
373
|
-
}, error), !isError && validateResult && jsx(HelperText, {
|
|
374
|
+
}, error), !isError && validateResult && jsx(HelperText, { ...helperTextProps,
|
|
374
375
|
disabled: disabled
|
|
375
376
|
}, validateResult));
|
|
376
377
|
}));
|
|
@@ -510,6 +511,9 @@ TextInput.propTypes = {
|
|
|
510
511
|
autoWidth: PropTypes.bool,
|
|
511
512
|
|
|
512
513
|
/** If `true`, a textarea element is rendered. */
|
|
513
|
-
multiline: PropTypes.bool
|
|
514
|
+
multiline: PropTypes.bool,
|
|
515
|
+
|
|
516
|
+
/** [Props](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) of helper text. */
|
|
517
|
+
helperTextProps: PropTypes.object
|
|
514
518
|
};
|
|
515
519
|
export default TextInput;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
4
|
import { css, jsx } from '@emotion/core';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
-
import { forwardRef, memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import React, { forwardRef, memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
import theme from '../../../theme/settings';
|
|
8
8
|
import generateRandom from '../../../utils/randomString';
|
|
9
9
|
import Typography from '../../typography';
|
|
@@ -23,7 +23,10 @@ const {
|
|
|
23
23
|
primary: clPrimary,
|
|
24
24
|
hover: clHover,
|
|
25
25
|
disabled: clDisabled,
|
|
26
|
-
white: clWhite
|
|
26
|
+
white: clWhite,
|
|
27
|
+
semantic: {
|
|
28
|
+
danger: clDanger
|
|
29
|
+
}
|
|
27
30
|
},
|
|
28
31
|
spacing
|
|
29
32
|
} = theme;
|
|
@@ -42,6 +45,7 @@ const Toggle = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
42
45
|
inputProps,
|
|
43
46
|
lineClamp,
|
|
44
47
|
hoverTooltip,
|
|
48
|
+
required,
|
|
45
49
|
...props
|
|
46
50
|
}, ref) => {
|
|
47
51
|
if (!inputRef) {
|
|
@@ -180,7 +184,11 @@ const Toggle = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
180
184
|
hoverTooltip: hoverTooltip,
|
|
181
185
|
lineClamp: lineClamp || null,
|
|
182
186
|
mapping: 'label'
|
|
183
|
-
},
|
|
187
|
+
}, jsx(React.Fragment, null, label, required && jsx("span", {
|
|
188
|
+
style: {
|
|
189
|
+
color: disabled ? clDisabled : clDanger
|
|
190
|
+
}
|
|
191
|
+
}, "*"))))), [disabled, onChange, checkedState, readOnly]);
|
|
184
192
|
}));
|
|
185
193
|
Toggle.defaultProps = {
|
|
186
194
|
disabled: false,
|
|
@@ -191,7 +199,8 @@ Toggle.defaultProps = {
|
|
|
191
199
|
id: '',
|
|
192
200
|
width: 40,
|
|
193
201
|
height: 20,
|
|
194
|
-
lineClamp: null
|
|
202
|
+
lineClamp: null,
|
|
203
|
+
required: false
|
|
195
204
|
};
|
|
196
205
|
Toggle.propTypes = {
|
|
197
206
|
/** * If `true`, the component is disabled. */
|
|
@@ -235,6 +244,9 @@ Toggle.propTypes = {
|
|
|
235
244
|
* @param {object} event The event source of the callback.
|
|
236
245
|
* You can pull out the new checked state by accessing `event.target.checked` (boolean).
|
|
237
246
|
*/
|
|
238
|
-
onChange: PropTypes.func
|
|
247
|
+
onChange: PropTypes.func,
|
|
248
|
+
|
|
249
|
+
/** If `true`, the label will indicate that the checkbox is required. */
|
|
250
|
+
required: PropTypes.bool
|
|
239
251
|
};
|
|
240
252
|
export default Toggle;
|
|
@@ -589,23 +589,23 @@ PagingInfo.propTypes = {
|
|
|
589
589
|
/** Callback fired when quantity on per page changed. */
|
|
590
590
|
onChangePerPage: PropTypes.func,
|
|
591
591
|
|
|
592
|
-
/**
|
|
593
|
-
* Callback fired when page number is changing.
|
|
594
|
-
*
|
|
595
|
-
* * prevPage: Page before changed
|
|
596
|
-
* * newPage: Page after changed
|
|
597
|
-
* * cancel(value): Function cancel change page
|
|
598
|
-
* * @param {value} - bool
|
|
592
|
+
/**
|
|
593
|
+
* Callback fired when page number is changing.
|
|
594
|
+
*
|
|
595
|
+
* * prevPage: Page before changed
|
|
596
|
+
* * newPage: Page after changed
|
|
597
|
+
* * cancel(value): Function cancel change page
|
|
598
|
+
* * @param {value} - bool
|
|
599
599
|
*/
|
|
600
600
|
onChangingPage: PropTypes.func,
|
|
601
601
|
|
|
602
|
-
/**
|
|
603
|
-
* Callback fired when quantity on item per page is changing.
|
|
604
|
-
*
|
|
605
|
-
* * prevPerPage: Items per page before changed
|
|
606
|
-
* * newPerPage: Items per page after changed
|
|
607
|
-
* * cancel(value): Function cancel change items per page
|
|
608
|
-
* * @param {value} - bool
|
|
602
|
+
/**
|
|
603
|
+
* Callback fired when quantity on item per page is changing.
|
|
604
|
+
*
|
|
605
|
+
* * prevPerPage: Items per page before changed
|
|
606
|
+
* * newPerPage: Items per page after changed
|
|
607
|
+
* * cancel(value): Function cancel change items per page
|
|
608
|
+
* * @param {value} - bool
|
|
609
609
|
*/
|
|
610
610
|
onChangingPerPage: PropTypes.func,
|
|
611
611
|
|
|
@@ -618,15 +618,15 @@ PagingInfo.propTypes = {
|
|
|
618
618
|
/** Compact type for mobile. */
|
|
619
619
|
typeShort: PropTypes.bool,
|
|
620
620
|
|
|
621
|
-
/**
|
|
622
|
-
* ref methods (ref.current.instance.*method*)
|
|
623
|
-
*
|
|
624
|
-
* * onChangePage(page): Change page number
|
|
625
|
-
* * @param {page} - number
|
|
626
|
-
* * onChangePerPage(per): Change quantity on per page
|
|
627
|
-
* * @param {per} - number
|
|
628
|
-
* * setTotalItems(items): Set total items
|
|
629
|
-
* * @param {items} - number
|
|
621
|
+
/**
|
|
622
|
+
* ref methods (ref.current.instance.*method*)
|
|
623
|
+
*
|
|
624
|
+
* * onChangePage(page): Change page number
|
|
625
|
+
* * @param {page} - number
|
|
626
|
+
* * onChangePerPage(per): Change quantity on per page
|
|
627
|
+
* * @param {per} - number
|
|
628
|
+
* * setTotalItems(items): Set total items
|
|
629
|
+
* * @param {items} - number
|
|
630
630
|
*/
|
|
631
631
|
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
632
632
|
current: PropTypes.instanceOf(Element)
|
|
@@ -368,23 +368,23 @@ PagingSelector.propTypes = {
|
|
|
368
368
|
/** Callback fired when quantity on per page changed. */
|
|
369
369
|
onChangePerPage: PropTypes.func,
|
|
370
370
|
|
|
371
|
-
/**
|
|
372
|
-
* Callback fired when page number is changing.
|
|
373
|
-
*
|
|
374
|
-
* * prevPage: Page before changed
|
|
375
|
-
* * newPage: Page after changed
|
|
376
|
-
* * cancel(value): Function cancel change page
|
|
377
|
-
* * @param {value} - bool
|
|
371
|
+
/**
|
|
372
|
+
* Callback fired when page number is changing.
|
|
373
|
+
*
|
|
374
|
+
* * prevPage: Page before changed
|
|
375
|
+
* * newPage: Page after changed
|
|
376
|
+
* * cancel(value): Function cancel change page
|
|
377
|
+
* * @param {value} - bool
|
|
378
378
|
*/
|
|
379
379
|
onChangingPage: PropTypes.func,
|
|
380
380
|
|
|
381
|
-
/**
|
|
382
|
-
* Callback fired when quantity on item per page is changing.
|
|
383
|
-
*
|
|
384
|
-
* * prevPerPage: Items per page before changed
|
|
385
|
-
* * newPerPage: Items per page after changed
|
|
386
|
-
* * cancel(value): Function cancel change items per page
|
|
387
|
-
* * @param {value} - bool
|
|
381
|
+
/**
|
|
382
|
+
* Callback fired when quantity on item per page is changing.
|
|
383
|
+
*
|
|
384
|
+
* * prevPerPage: Items per page before changed
|
|
385
|
+
* * newPerPage: Items per page after changed
|
|
386
|
+
* * cancel(value): Function cancel change items per page
|
|
387
|
+
* * @param {value} - bool
|
|
388
388
|
*/
|
|
389
389
|
onChangingPerPage: PropTypes.func,
|
|
390
390
|
|
|
@@ -394,15 +394,15 @@ PagingSelector.propTypes = {
|
|
|
394
394
|
/** Total items. */
|
|
395
395
|
totalItems: PropTypes.number,
|
|
396
396
|
|
|
397
|
-
/**
|
|
398
|
-
* ref methods (ref.current.instance.*method*)
|
|
399
|
-
*
|
|
400
|
-
* * onChangePage(page): Change page number
|
|
401
|
-
* * @param {page} - number
|
|
402
|
-
* * onChangePerPage(per): Change quantity on per page
|
|
403
|
-
* * @param {per} - number
|
|
404
|
-
* * setTotalItems(items): Set total items
|
|
405
|
-
* * @param {items} - number
|
|
397
|
+
/**
|
|
398
|
+
* ref methods (ref.current.instance.*method*)
|
|
399
|
+
*
|
|
400
|
+
* * onChangePage(page): Change page number
|
|
401
|
+
* * @param {page} - number
|
|
402
|
+
* * onChangePerPage(per): Change quantity on per page
|
|
403
|
+
* * @param {per} - number
|
|
404
|
+
* * setTotalItems(items): Set total items
|
|
405
|
+
* * @param {items} - number
|
|
406
406
|
*/
|
|
407
407
|
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
408
408
|
current: PropTypes.instanceOf(Element)
|
|
@@ -6,26 +6,24 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
import { createPortal } from 'react-dom';
|
|
7
7
|
import { randomString } from '../../utils';
|
|
8
8
|
import { jsx, css } from '@emotion/core';
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import { borderBox, borderRadius4px, displayInlineBlock, positionAbsolute, userSelectNone } from '../../styles/general';
|
|
9
|
+
import { borderBox, borderRadius4px, displayInlineBlock, flexRow, parseHeight, positionAbsolute, positionRelative, userSelectNone } from '../../styles/general';
|
|
10
|
+
import theme from '../../theme/settings';
|
|
12
11
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
colors: {
|
|
13
|
+
system: {
|
|
14
|
+
white
|
|
15
|
+
},
|
|
16
|
+
fill: {
|
|
17
|
+
tooltip: fillTooltip
|
|
18
|
+
}
|
|
19
19
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
20
|
+
typography: {
|
|
21
|
+
paragraph2,
|
|
22
|
+
paragraph3
|
|
23
|
+
},
|
|
24
|
+
zIndex: zIndexCORE
|
|
25
|
+
} = theme;
|
|
25
26
|
const defaultViewPadding = 4;
|
|
26
|
-
const {
|
|
27
|
-
zIndex
|
|
28
|
-
} = useTheme();
|
|
29
27
|
|
|
30
28
|
const getScrollTop = () => {
|
|
31
29
|
var _ref, _ref2, _window$pageYOffset;
|
|
@@ -85,7 +83,7 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
85
83
|
};
|
|
86
84
|
const [open, setOpen] = useState(false);
|
|
87
85
|
const arrowRef = useRef(null);
|
|
88
|
-
const
|
|
86
|
+
const ref = useRef(null);
|
|
89
87
|
const tooltipRef = useRef(null);
|
|
90
88
|
const hiddenPositions = {
|
|
91
89
|
tooltip: {
|
|
@@ -452,33 +450,28 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
452
450
|
|
|
453
451
|
useEffect(() => {
|
|
454
452
|
if (open) {
|
|
455
|
-
onShowTooltip(arrow,
|
|
453
|
+
onShowTooltip(arrow, ref.current);
|
|
456
454
|
} else {
|
|
457
455
|
onHideTooltip();
|
|
458
456
|
}
|
|
459
457
|
}, [open]);
|
|
460
|
-
useImperativeHandle(reference, () => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
_instance.__proto__ = {}; // hidden methods
|
|
465
|
-
|
|
466
|
-
currentRef.instance = _instance;
|
|
467
|
-
return currentRef;
|
|
468
|
-
});
|
|
458
|
+
useImperativeHandle(reference, () => ({
|
|
459
|
+
element: ref.current,
|
|
460
|
+
instance: {}
|
|
461
|
+
}));
|
|
469
462
|
const renderTooltip = useMemo(() => {
|
|
470
463
|
if (open && title) {
|
|
471
464
|
const node = jsx("div", {
|
|
472
465
|
className: 'DGN-UI-Portal DGN-Tooltip'
|
|
473
466
|
}, jsx("span", {
|
|
474
467
|
className: IDs.arrow,
|
|
475
|
-
css:
|
|
468
|
+
css: ArrowCSS,
|
|
476
469
|
ref: arrowRef,
|
|
477
470
|
style: { ...hiddenPositions.arrow
|
|
478
471
|
}
|
|
479
472
|
}), jsx("span", {
|
|
480
473
|
className: [IDs.main, className].join(' ').trim().replace(/\s+/g, ' '),
|
|
481
|
-
css:
|
|
474
|
+
css: MainCSS(backgroundColor, color, size, padding, textAlign),
|
|
482
475
|
ref: tooltipRef,
|
|
483
476
|
style: { ...hiddenPositions.tooltip
|
|
484
477
|
}
|
|
@@ -489,15 +482,10 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
489
482
|
return null;
|
|
490
483
|
}, [open, title, backgroundColor, color, size, padding, textAlign]);
|
|
491
484
|
return jsx(TagCreatedName, {
|
|
492
|
-
ref:
|
|
485
|
+
ref: ref,
|
|
486
|
+
css: ContainerCSS,
|
|
493
487
|
className: IDs.container,
|
|
494
|
-
style:
|
|
495
|
-
boxSizing: 'border-box',
|
|
496
|
-
height: 'max-content',
|
|
497
|
-
width: 'max-content',
|
|
498
|
-
position: 'relative',
|
|
499
|
-
...style
|
|
500
|
-
},
|
|
488
|
+
style: style,
|
|
501
489
|
onMouseEnter: setOpenTrue,
|
|
502
490
|
onMouseLeave: setOpenFalse,
|
|
503
491
|
onFocus: setOpenTrue,
|
|
@@ -505,22 +493,29 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
505
493
|
...props
|
|
506
494
|
}, children, renderTooltip);
|
|
507
495
|
}));
|
|
508
|
-
const
|
|
509
|
-
${
|
|
510
|
-
${
|
|
496
|
+
const ContainerCSS = css`
|
|
497
|
+
${flexRow};
|
|
498
|
+
${positionRelative};
|
|
499
|
+
${borderBox};
|
|
500
|
+
${parseHeight('max-content')};
|
|
501
|
+
width: auto;
|
|
502
|
+
`;
|
|
503
|
+
const ArrowCSS = css`
|
|
504
|
+
${positionAbsolute};
|
|
505
|
+
${userSelectNone};
|
|
511
506
|
height: 0;
|
|
512
507
|
opacity: 0;
|
|
513
508
|
transition: opacity 0.1s ease-in-out;
|
|
514
509
|
width: 0;
|
|
515
|
-
z-index: ${
|
|
510
|
+
z-index: ${zIndexCORE(5)};
|
|
516
511
|
`;
|
|
517
512
|
|
|
518
|
-
const
|
|
519
|
-
${displayInlineBlock}
|
|
520
|
-
${borderBox}
|
|
521
|
-
${positionAbsolute}
|
|
522
|
-
${userSelectNone}
|
|
523
|
-
${borderRadius4px}
|
|
513
|
+
const MainCSS = (backgroundColor, color, size, padding, textAlign) => css`
|
|
514
|
+
${displayInlineBlock};
|
|
515
|
+
${borderBox};
|
|
516
|
+
${positionAbsolute};
|
|
517
|
+
${userSelectNone};
|
|
518
|
+
${borderRadius4px};
|
|
524
519
|
${size === 'small' ? paragraph3 : paragraph2};
|
|
525
520
|
background-color: ${backgroundColor};
|
|
526
521
|
color: ${color};
|
|
@@ -529,7 +524,7 @@ const mainCSS = (backgroundColor, color, size, padding, textAlign) => css`
|
|
|
529
524
|
opacity: 0;
|
|
530
525
|
transition: opacity 0.1s ease-in-out;
|
|
531
526
|
word-wrap: break-word;
|
|
532
|
-
z-index: ${
|
|
527
|
+
z-index: ${zIndexCORE(4)};
|
|
533
528
|
`;
|
|
534
529
|
|
|
535
530
|
Tooltip.defaultProps = {
|
|
@@ -547,67 +542,68 @@ Tooltip.defaultProps = {
|
|
|
547
542
|
textAlign: 'center',
|
|
548
543
|
viewportPadding: defaultViewPadding,
|
|
549
544
|
className: '',
|
|
550
|
-
disabled: false
|
|
545
|
+
disabled: false,
|
|
546
|
+
style: {}
|
|
551
547
|
};
|
|
552
548
|
Tooltip.propTypes = {
|
|
553
549
|
/** alignMode use to set align-items of the tooltip*/
|
|
554
550
|
alignMode: PropTypes.oneOf(['flex-end', 'flex-start', 'middle']),
|
|
555
551
|
|
|
556
|
-
/**
|
|
552
|
+
/** If true, adds an arrow to the tooltip. */
|
|
557
553
|
arrow: PropTypes.bool,
|
|
558
554
|
|
|
559
|
-
/**
|
|
555
|
+
/** Size of the arrow. */
|
|
560
556
|
arrowSize: PropTypes.number,
|
|
561
557
|
|
|
562
|
-
/**
|
|
558
|
+
/** Background color of the tooltip. */
|
|
563
559
|
backgroundColor: PropTypes.string,
|
|
564
560
|
|
|
565
|
-
/**
|
|
561
|
+
/** Tooltip reference element. */
|
|
566
562
|
children: PropTypes.node.isRequired,
|
|
567
563
|
|
|
568
|
-
/**
|
|
564
|
+
/** Class for component. */
|
|
565
|
+
className: PropTypes.string,
|
|
566
|
+
|
|
567
|
+
/** Color of the title. */
|
|
569
568
|
color: PropTypes.string,
|
|
570
569
|
|
|
571
|
-
/**
|
|
570
|
+
/** Direction of the tooltip. */
|
|
572
571
|
direction: PropTypes.oneOf(['down', 'left', 'right', 'up']),
|
|
573
572
|
|
|
574
573
|
/** If `true`, the component is disabled. */
|
|
575
574
|
disabled: PropTypes.bool,
|
|
576
575
|
|
|
577
|
-
/**
|
|
576
|
+
/** Distance between the tooltip and the children. */
|
|
578
577
|
distance: PropTypes.number,
|
|
579
578
|
|
|
580
|
-
/**
|
|
581
|
-
size: PropTypes.oneOf(['small', 'medium']),
|
|
582
|
-
|
|
583
|
-
/** forceDirection use to set the static direction of the tooltip */
|
|
579
|
+
/** If `true`, set the static direction of the tooltip. */
|
|
584
580
|
forceDirection: PropTypes.bool,
|
|
585
581
|
|
|
586
|
-
/**
|
|
582
|
+
/** The number of milliseconds to wait before showing the tooltip. */
|
|
587
583
|
hoverDelay: PropTypes.number,
|
|
588
584
|
|
|
589
|
-
/**
|
|
585
|
+
/** Padding of the title. */
|
|
590
586
|
padding: PropTypes.string,
|
|
591
587
|
|
|
592
|
-
/**
|
|
593
|
-
|
|
588
|
+
/** The size of the title. */
|
|
589
|
+
size: PropTypes.oneOf(['small', 'medium']),
|
|
594
590
|
|
|
595
|
-
/**
|
|
596
|
-
|
|
591
|
+
/** Style inline of component. */
|
|
592
|
+
style: PropTypes.object,
|
|
597
593
|
|
|
598
|
-
/**
|
|
594
|
+
/** Tag name of the element will be created to contain the children. */
|
|
599
595
|
tagCreatedName: PropTypes.oneOf(['div', 'span']),
|
|
600
596
|
|
|
601
|
-
/**
|
|
597
|
+
/** Text align of the title. */
|
|
602
598
|
textAlign: PropTypes.oneOf(['center', 'justify', 'left', 'right']),
|
|
603
599
|
|
|
604
|
-
/** The title to show in tooltip when hover */
|
|
600
|
+
/** The title to show in tooltip when hover. */
|
|
605
601
|
title: PropTypes.oneOfType([PropTypes.element, PropTypes.string]).isRequired,
|
|
606
602
|
|
|
607
|
-
/**
|
|
603
|
+
/** Max width of the tooltip */
|
|
608
604
|
tooltipMaxWidth: PropTypes.number,
|
|
609
605
|
|
|
610
|
-
/**
|
|
606
|
+
/** Padding of the viewport with the tooltip */
|
|
611
607
|
viewportPadding: PropTypes.number
|
|
612
608
|
};
|
|
613
609
|
export default Tooltip;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -38,6 +38,15 @@ npm test
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Changelog
|
|
41
|
+
## 1.3.70
|
|
42
|
+
- \[Changed\]: Checkbox – Add prop required
|
|
43
|
+
- \[Changed\]: Radio – Add prop required
|
|
44
|
+
- \[Changed\]: Toggle – Add prop required
|
|
45
|
+
- \[Changed\]: Storybook – Add template storybook
|
|
46
|
+
- \[Changed\]: MoneyInput, NumberInput, PhoneInput, TextInput – Add helperTextProps
|
|
47
|
+
- \[Fixed\]: Tooltip – Add display flex
|
|
48
|
+
- \[Fixed\]: Checkbox – Fix bug not show value when label is empty string
|
|
49
|
+
|
|
41
50
|
## 1.3.69
|
|
42
51
|
- \[Fixed\]: DatePicker – Fix not show placeholder
|
|
43
52
|
- \[Fixed\]: DatePicker – Fix set value when select date
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { css, js } from '@emotion/core';
|
|
3
|
+
import { Col, Row, Tooltip, Typography } from '../components/index';
|
|
4
|
+
import { useTheme } from '../theme';
|
|
5
|
+
import { flexWrap, flexRow, alignCenter } from '../styles/general';
|
|
6
|
+
import { ImportComp } from '../components/others/import/index.stories';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
const {
|
|
9
|
+
spacing
|
|
10
|
+
} = useTheme();
|
|
11
|
+
export const Template = ({
|
|
12
|
+
title,
|
|
13
|
+
args,
|
|
14
|
+
propsCustom,
|
|
15
|
+
disabledTooltip,
|
|
16
|
+
component: Component,
|
|
17
|
+
horizontal
|
|
18
|
+
} = props) => {
|
|
19
|
+
return /*#__PURE__*/React.createElement(Row, {
|
|
20
|
+
style: {
|
|
21
|
+
padding: spacing(2)
|
|
22
|
+
}
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Col, {
|
|
24
|
+
xs: 12
|
|
25
|
+
}, /*#__PURE__*/React.createElement(Row, null, title && /*#__PURE__*/React.createElement(Col, {
|
|
26
|
+
xs: 12
|
|
27
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
28
|
+
type: 'title1',
|
|
29
|
+
color: 'primary'
|
|
30
|
+
}, title)), /*#__PURE__*/React.createElement(Col, {
|
|
31
|
+
xs: 12,
|
|
32
|
+
style: {
|
|
33
|
+
gap: spacing(2)
|
|
34
|
+
},
|
|
35
|
+
css: css`
|
|
36
|
+
${horizontal ? flexRow : ''};
|
|
37
|
+
${flexWrap};
|
|
38
|
+
${alignCenter}
|
|
39
|
+
`
|
|
40
|
+
}, [{}, ...propsCustom].map((itemProps, indexProps) => {
|
|
41
|
+
const argsTemp = { ...args,
|
|
42
|
+
...itemProps
|
|
43
|
+
};
|
|
44
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
45
|
+
tooltipMaxWidth: 200,
|
|
46
|
+
disabled: disabledTooltip,
|
|
47
|
+
key: indexProps,
|
|
48
|
+
title: JSON.stringify(argsTemp)
|
|
49
|
+
}, /*#__PURE__*/React.createElement(Component, { ...argsTemp
|
|
50
|
+
}));
|
|
51
|
+
})))));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const StoryBookTemplate = ({
|
|
55
|
+
args,
|
|
56
|
+
component,
|
|
57
|
+
propsCustom,
|
|
58
|
+
listItem,
|
|
59
|
+
componentName
|
|
60
|
+
} = props) => {
|
|
61
|
+
return /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
|
|
62
|
+
xs: 12
|
|
63
|
+
}, /*#__PURE__*/React.createElement(ImportComp, {
|
|
64
|
+
components: componentName
|
|
65
|
+
})), /*#__PURE__*/React.createElement(Col, {
|
|
66
|
+
xs: 12
|
|
67
|
+
}, listItem.map((propsItem, idx) => {
|
|
68
|
+
const {
|
|
69
|
+
horizontal,
|
|
70
|
+
title,
|
|
71
|
+
argsExtra,
|
|
72
|
+
propsCustom: itemPropsCustom
|
|
73
|
+
} = propsItem;
|
|
74
|
+
return /*#__PURE__*/React.createElement(Template, {
|
|
75
|
+
key: idx,
|
|
76
|
+
horizontal: horizontal,
|
|
77
|
+
title: title,
|
|
78
|
+
args: { ...args,
|
|
79
|
+
...argsExtra
|
|
80
|
+
},
|
|
81
|
+
component: component,
|
|
82
|
+
propsCustom: [...(propsCustom || []), ...(itemPropsCustom || [])]
|
|
83
|
+
});
|
|
84
|
+
})));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
Template.defaultProps = {
|
|
88
|
+
propsCustom: [],
|
|
89
|
+
disabledTooltip: false
|
|
90
|
+
};
|
|
91
|
+
Template.propTypes = {
|
|
92
|
+
title: PropTypes.string.isRequired,
|
|
93
|
+
args: PropTypes.object,
|
|
94
|
+
propsCustom: PropTypes.array,
|
|
95
|
+
disabledTooltip: PropTypes.bool,
|
|
96
|
+
horizontal: PropTypes.bool
|
|
97
|
+
};
|
|
98
|
+
StoryBookTemplate.propTypes = {
|
|
99
|
+
componentName: PropTypes.string.isRequired,
|
|
100
|
+
args: PropTypes.object,
|
|
101
|
+
propsCustom: PropTypes.array,
|
|
102
|
+
listItem: PropTypes.array
|
|
103
|
+
};
|
|
104
|
+
export default StoryBookTemplate;
|