diginet-core-ui 1.3.59-beta.1 → 1.3.59-beta.2
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/button/index.js +13 -13
- package/components/chart/Pie-v2/Sector.js +2 -2
- package/components/chip/attach.js +5 -5
- package/components/form-control/calendar/index.js +16 -16
- package/components/form-control/number-input/index.js +11 -11
- package/components/form-control/number-input/index2.js +21 -14
- package/components/form-control/phone-input/index.js +7 -7
- package/components/progress/circular.js +12 -12
- package/components/transfer/index.js +3 -3
- package/icons/effect.js +15 -15
- package/package.json +1 -1
- package/styles/color-helper.js +103 -103
- package/utils/error/error.js +2 -2
- package/utils/renderIcon.js +5 -5
|
@@ -483,19 +483,19 @@ Button.propTypes = {
|
|
|
483
483
|
/** status loading of button */
|
|
484
484
|
loading: PropTypes.bool,
|
|
485
485
|
|
|
486
|
-
/**
|
|
487
|
-
* ref methods
|
|
488
|
-
*
|
|
489
|
-
* * option(): Gets all UI component properties
|
|
490
|
-
* * Returns value - object
|
|
491
|
-
* * option(optionName): Gets the value of a single property
|
|
492
|
-
* * @param {optionName} - string
|
|
493
|
-
* * Returns value - any
|
|
494
|
-
* * option(optionName, optionValue): Updates the value of a single property
|
|
495
|
-
* * @param {optionName} - string
|
|
496
|
-
* * @param {optionValue} - any
|
|
497
|
-
* * option(options): Updates the values of several properties
|
|
498
|
-
* * @param {options} - object
|
|
486
|
+
/**
|
|
487
|
+
* ref methods
|
|
488
|
+
*
|
|
489
|
+
* * option(): Gets all UI component properties
|
|
490
|
+
* * Returns value - object
|
|
491
|
+
* * option(optionName): Gets the value of a single property
|
|
492
|
+
* * @param {optionName} - string
|
|
493
|
+
* * Returns value - any
|
|
494
|
+
* * option(optionName, optionValue): Updates the value of a single property
|
|
495
|
+
* * @param {optionName} - string
|
|
496
|
+
* * @param {optionValue} - any
|
|
497
|
+
* * option(options): Updates the values of several properties
|
|
498
|
+
* * @param {options} - object
|
|
499
499
|
*/
|
|
500
500
|
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
501
501
|
current: PropTypes.instanceOf(Element)
|
|
@@ -94,8 +94,8 @@ Sector.propTypes = {
|
|
|
94
94
|
onTouchEnd: PropTypes.func,
|
|
95
95
|
onTouchStart: PropTypes.func,
|
|
96
96
|
|
|
97
|
-
/** function displays selected items by custom, example:<br/>
|
|
98
|
-
* renderItem={(data, index) => index + ' - ' + data.name}<br/>
|
|
97
|
+
/** function displays selected items by custom, example:<br/>
|
|
98
|
+
* renderItem={(data, index) => index + ' - ' + data.name}<br/>
|
|
99
99
|
*/
|
|
100
100
|
renderSelectedItem: PropTypes.func,
|
|
101
101
|
path: PropTypes.string.isRequired,
|
|
@@ -156,11 +156,11 @@ const AttachChip = /*#__PURE__*/memo(({
|
|
|
156
156
|
}))), attachView);
|
|
157
157
|
});
|
|
158
158
|
AttachChip.propTypes = {
|
|
159
|
-
/** the file info, such as:<br/>
|
|
160
|
-
* {<br/>
|
|
161
|
-
* URL: https://url.com/pathname,<br/>
|
|
162
|
-
* FileName: file.name,<br/>
|
|
163
|
-
* }
|
|
159
|
+
/** the file info, such as:<br/>
|
|
160
|
+
* {<br/>
|
|
161
|
+
* URL: https://url.com/pathname,<br/>
|
|
162
|
+
* FileName: file.name,<br/>
|
|
163
|
+
* }
|
|
164
164
|
*/
|
|
165
165
|
file: PropTypes.shape({
|
|
166
166
|
URL: PropTypes.string.isRequired,
|
|
@@ -41,8 +41,8 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
41
41
|
limit: 'DGN-UI-Calendar-Day-limit'
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
/**
|
|
45
|
-
* START REFERENCE
|
|
44
|
+
/**
|
|
45
|
+
* START REFERENCE
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
const ref = useRef(null);
|
|
@@ -61,12 +61,12 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
61
61
|
};
|
|
62
62
|
const firstDayOfMax = new Date(new Date(max).setDate(1)).setHours(0, 0, 0, 0);
|
|
63
63
|
const firstDayOfMin = new Date(new Date(min).setDate(1)).setHours(0, 0, 0, 0);
|
|
64
|
-
/**
|
|
65
|
-
* END REFERENCE
|
|
64
|
+
/**
|
|
65
|
+
* END REFERENCE
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
-
/**
|
|
69
|
-
* START FUNCTION
|
|
68
|
+
/**
|
|
69
|
+
* START FUNCTION
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
const onUpdateNavigatorValue = useCallback(value => {
|
|
@@ -152,12 +152,12 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
152
152
|
onUpdateCalendar(time, navigatorRefs, min, max, tableRef.current, activeValue.current, unique, displayAnotherMonth, onDayClick, onUpdateNavigatorValue);
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
|
-
/**
|
|
156
|
-
* END FUNCTION
|
|
155
|
+
/**
|
|
156
|
+
* END FUNCTION
|
|
157
157
|
*/
|
|
158
158
|
|
|
159
|
-
/**
|
|
160
|
-
* START EFFECT
|
|
159
|
+
/**
|
|
160
|
+
* START EFFECT
|
|
161
161
|
*/
|
|
162
162
|
|
|
163
163
|
|
|
@@ -198,12 +198,12 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
198
198
|
onUpdate(activeValue.current);
|
|
199
199
|
}
|
|
200
200
|
}, [onClick, min, max]);
|
|
201
|
-
/**
|
|
202
|
-
* END FUNCTION
|
|
201
|
+
/**
|
|
202
|
+
* END FUNCTION
|
|
203
203
|
*/
|
|
204
204
|
|
|
205
|
-
/**
|
|
206
|
-
* START COMPONENT
|
|
205
|
+
/**
|
|
206
|
+
* START COMPONENT
|
|
207
207
|
*/
|
|
208
208
|
|
|
209
209
|
const tableMemo = jsx("div", {
|
|
@@ -212,8 +212,8 @@ const Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
212
212
|
className: unique.table.table,
|
|
213
213
|
ref: tableRef
|
|
214
214
|
}, renderHeader(unique), jsx("tbody", null)));
|
|
215
|
-
/**
|
|
216
|
-
* END COMPONENT
|
|
215
|
+
/**
|
|
216
|
+
* END COMPONENT
|
|
217
217
|
*/
|
|
218
218
|
|
|
219
219
|
return jsx("div", { ...props,
|
|
@@ -578,23 +578,23 @@ NumberInput.propTypes = {
|
|
|
578
578
|
/** style inline of input in NumberInput component */
|
|
579
579
|
inputStyle: PropTypes.object,
|
|
580
580
|
|
|
581
|
-
/**
|
|
582
|
-
* the format to display value<br/>
|
|
583
|
-
* * function: value => function(value)<br/>
|
|
584
|
-
* * string: Example: '#.###', '# ###', '#.### 2%', '#.### %%'<br/>
|
|
585
|
-
* #: integer part digit<br/>
|
|
586
|
-
* . / '_': separator symbol<br/>
|
|
587
|
-
* %: decimal digit, '2%' === '%%'
|
|
581
|
+
/**
|
|
582
|
+
* the format to display value<br/>
|
|
583
|
+
* * function: value => function(value)<br/>
|
|
584
|
+
* * string: Example: '#.###', '# ###', '#.### 2%', '#.### %%'<br/>
|
|
585
|
+
* #: integer part digit<br/>
|
|
586
|
+
* . / '_': separator symbol<br/>
|
|
587
|
+
* %: decimal digit, '2%' === '%%'
|
|
588
588
|
*/
|
|
589
589
|
format: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
590
590
|
|
|
591
591
|
/** The function to get ref of NumberInput component */
|
|
592
592
|
refs: PropTypes.func,
|
|
593
593
|
|
|
594
|
-
/** validation value, argument can:<br/>
|
|
595
|
-
* * string: the validation rule. Example required.<br/>
|
|
596
|
-
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
597
|
-
* * array: the validation rule list, insist object/string
|
|
594
|
+
/** validation value, argument can:<br/>
|
|
595
|
+
* * string: the validation rule. Example required.<br/>
|
|
596
|
+
* * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
|
|
597
|
+
* * array: the validation rule list, insist object/string
|
|
598
598
|
*/
|
|
599
599
|
validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
|
|
600
600
|
|
|
@@ -15,6 +15,7 @@ const NumberInputRoot = css`
|
|
|
15
15
|
margin-bottom: 20px;
|
|
16
16
|
`;
|
|
17
17
|
const regexValidNumber = /[^0-9.,-]/g;
|
|
18
|
+
const regexNumber = /[^0-9]/g;
|
|
18
19
|
const regexThousandNumber = /(\d)(?=(\d{3})+\b)/g;
|
|
19
20
|
const NumberInput = /*#__PURE__*/forwardRef(({
|
|
20
21
|
viewType,
|
|
@@ -43,12 +44,14 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
43
44
|
onChange,
|
|
44
45
|
onFocus,
|
|
45
46
|
onInput,
|
|
47
|
+
onBlur,
|
|
46
48
|
onKeyDown,
|
|
47
49
|
onKeyUp,
|
|
48
50
|
validates,
|
|
49
51
|
delayOnChange,
|
|
50
52
|
fixedDecimalDigit,
|
|
51
|
-
className
|
|
53
|
+
className,
|
|
54
|
+
maxDigit
|
|
52
55
|
}, reference) => {
|
|
53
56
|
inputRef = inputRef || useRef(null);
|
|
54
57
|
const pos = useRef(null);
|
|
@@ -164,6 +167,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
164
167
|
});
|
|
165
168
|
}
|
|
166
169
|
}
|
|
170
|
+
|
|
171
|
+
onBlur && onBlur(e);
|
|
167
172
|
};
|
|
168
173
|
|
|
169
174
|
const _onKeyDown = e => {
|
|
@@ -184,11 +189,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
184
189
|
|
|
185
190
|
const isNumber = keyCode >= 48 && keyCode <= 57 && shiftKey === false || keyCode >= 96 && keyCode <= 105 || keyCode === 231 && key >= '0' && key <= '9'; // character input type="number"
|
|
186
191
|
|
|
187
|
-
|
|
188
|
-
keyCode > 34 && keyCode < 40 || keyCode ===
|
|
189
|
-
keyCode === 231 && key === '.' || // .
|
|
190
|
-
keyCode === 188 || // ,
|
|
191
|
-
(ctrlKey || metaKey) && (keyCode === 65 || keyCode === 67 || keyCode === 86) || // ctrl + A, ctrl + C, ctrl + V
|
|
192
|
+
let allowKeyTypeNumber = isNumber || keyCode === 8 || // key backspace
|
|
193
|
+
keyCode > 34 && keyCode < 40 || key === thousandSymbol || key === decimalSymbol || (ctrlKey || metaKey) && (keyCode === 65 || keyCode === 67 || keyCode === 86) || // ctrl + A, ctrl + C, ctrl + V
|
|
192
194
|
keyCode === 46 || // key delete
|
|
193
195
|
keyCode === 189 || keyCode === 109 || // -
|
|
194
196
|
keyCode === 9; // tab
|
|
@@ -197,13 +199,10 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
197
199
|
const removeDot = keyCode === 8 && selectionEnd - selectionStart <= 1 && value.charAt(selectionEnd - 1) === thousandSymbol; // Decimal
|
|
198
200
|
// Do not allow the character decimal if decimalDigit is undefined
|
|
199
201
|
|
|
200
|
-
const isDecimalSymbol = decimalSymbol ===
|
|
202
|
+
const isDecimalSymbol = decimalSymbol === key;
|
|
201
203
|
const disabledDecimalSymbol = isDecimalSymbol && !decimalDigit; // Accepts only one decimal separator
|
|
202
204
|
|
|
203
|
-
const decimalExists = value.includes(decimalSymbol) && isDecimalSymbol; //
|
|
204
|
-
|
|
205
|
-
const isThousandSymbol = (!thousandSymbol || thousandSymbol === '.') && (keyCode === 190 || keyCode === 110) || thousandSymbol === ',' && keyCode === 188;
|
|
206
|
-
const disabledThousandSymbol = isThousandSymbol; // Disabled typing input when decimal digit to limit and focus is last
|
|
205
|
+
const decimalExists = value.includes(decimalSymbol) && isDecimalSymbol; // Disabled typing input when decimal digit to limit and focus is last
|
|
207
206
|
|
|
208
207
|
const disabledTypingDecimal = ((_value$split = value.split(decimalSymbol)) === null || _value$split === void 0 ? void 0 : (_value$split$ = _value$split[1]) === null || _value$split$ === void 0 ? void 0 : _value$split$.length) >= decimalDigit && // total number after decimal symbol > {decimalDigit}
|
|
209
208
|
selectionStart === value.length; // the focus is at the end of the string
|
|
@@ -229,9 +228,11 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
229
228
|
} // disabled negative
|
|
230
229
|
|
|
231
230
|
|
|
232
|
-
const disabled180 = (keyCode === 189 || keyCode === 109) && (disabledNegative || value.includes('-')); //
|
|
231
|
+
const disabled180 = (keyCode === 189 || keyCode === 109) && (disabledNegative || value.includes('-')); // disabled max digit
|
|
232
|
+
|
|
233
|
+
const isMaxDigit = maxDigit && (value === null || value === void 0 ? void 0 : value.replace(regexNumber, '').length) === maxDigit && (isNumber || key === thousandSymbol || key === decimalSymbol) && selectionStart === selectionEnd; // Block event if include conditions
|
|
233
234
|
|
|
234
|
-
if (decimalExists ||
|
|
235
|
+
if (decimalExists || removeDot || isNumber && disabledTypingDecimal || disabledDecimalSymbol || !allowKeyTypeNumber || disabled180 || isMaxDigit) {
|
|
235
236
|
e.preventDefault();
|
|
236
237
|
}
|
|
237
238
|
|
|
@@ -415,6 +416,9 @@ NumberInput.propTypes = {
|
|
|
415
416
|
/** on focus function */
|
|
416
417
|
onFocus: PropTypes.func,
|
|
417
418
|
|
|
419
|
+
/** on blur function */
|
|
420
|
+
onBlur: PropTypes.func,
|
|
421
|
+
|
|
418
422
|
/** inputRef of NumberInput component */
|
|
419
423
|
inputRef: PropTypes.any,
|
|
420
424
|
|
|
@@ -428,6 +432,9 @@ NumberInput.propTypes = {
|
|
|
428
432
|
thousandSeparator: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['.', ','])]),
|
|
429
433
|
|
|
430
434
|
/** className of component */
|
|
431
|
-
className: PropTypes.string
|
|
435
|
+
className: PropTypes.string,
|
|
436
|
+
|
|
437
|
+
/** max character is number of NumberInput component */
|
|
438
|
+
maxDigit: PropTypes.number
|
|
432
439
|
};
|
|
433
440
|
export default NumberInput;
|
|
@@ -396,13 +396,13 @@ PhoneInput.propTypes = {
|
|
|
396
396
|
/** on input function */
|
|
397
397
|
onInput: PropTypes.func,
|
|
398
398
|
|
|
399
|
-
/**
|
|
400
|
-
* on change function. Return a object, example:<br/>
|
|
401
|
-
* {<br/>
|
|
402
|
-
* target: {value: "(+84) 123 456 789", ...}<br/>
|
|
403
|
-
* value: 0123456789<br/>
|
|
404
|
-
* countryCode: 84<br/>
|
|
405
|
-
* }
|
|
399
|
+
/**
|
|
400
|
+
* on change function. Return a object, example:<br/>
|
|
401
|
+
* {<br/>
|
|
402
|
+
* target: {value: "(+84) 123 456 789", ...}<br/>
|
|
403
|
+
* value: 0123456789<br/>
|
|
404
|
+
* countryCode: 84<br/>
|
|
405
|
+
* }
|
|
406
406
|
*/
|
|
407
407
|
onChange: PropTypes.func,
|
|
408
408
|
|
|
@@ -65,8 +65,8 @@ const getDimension = size => {
|
|
|
65
65
|
strokeWidth
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
|
-
/**
|
|
69
|
-
* Determinate circular progress
|
|
68
|
+
/**
|
|
69
|
+
* Determinate circular progress
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
|
|
@@ -115,8 +115,8 @@ const Determinate = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
115
115
|
|
|
116
116
|
return angle;
|
|
117
117
|
};
|
|
118
|
-
/**
|
|
119
|
-
* style
|
|
118
|
+
/**
|
|
119
|
+
* style
|
|
120
120
|
*/
|
|
121
121
|
|
|
122
122
|
|
|
@@ -218,8 +218,8 @@ Determinate.propTypes = {
|
|
|
218
218
|
width: PropTypes.number
|
|
219
219
|
};
|
|
220
220
|
export const DeterminateCircularProgress = Determinate;
|
|
221
|
-
/**
|
|
222
|
-
* Indeterminate circular progress
|
|
221
|
+
/**
|
|
222
|
+
* Indeterminate circular progress
|
|
223
223
|
*/
|
|
224
224
|
|
|
225
225
|
const Indeterminate = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
@@ -256,8 +256,8 @@ const Indeterminate = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
256
256
|
stroke-dashoffset: -${r * 124 / 200};
|
|
257
257
|
}
|
|
258
258
|
`;
|
|
259
|
-
/**
|
|
260
|
-
* style
|
|
259
|
+
/**
|
|
260
|
+
* style
|
|
261
261
|
*/
|
|
262
262
|
|
|
263
263
|
|
|
@@ -288,8 +288,8 @@ const Indeterminate = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
288
288
|
stroke-linecap: round;
|
|
289
289
|
stroke-width: ${circleStrokeW};
|
|
290
290
|
`;
|
|
291
|
-
/**
|
|
292
|
-
* component
|
|
291
|
+
/**
|
|
292
|
+
* component
|
|
293
293
|
*/
|
|
294
294
|
|
|
295
295
|
const CircleBackgroundMemo = useMemo(() => jsx("circle", {
|
|
@@ -332,8 +332,8 @@ Indeterminate.propTypes = {
|
|
|
332
332
|
width: PropTypes.number
|
|
333
333
|
};
|
|
334
334
|
export const IndeterminateCircularProgress = Indeterminate;
|
|
335
|
-
/**
|
|
336
|
-
* Circular progress
|
|
335
|
+
/**
|
|
336
|
+
* Circular progress
|
|
337
337
|
*/
|
|
338
338
|
|
|
339
339
|
const CircularProgress = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
@@ -456,9 +456,9 @@ Transfer.propTypes = {
|
|
|
456
456
|
/** field name used for icon display */
|
|
457
457
|
iconExpr: string,
|
|
458
458
|
|
|
459
|
-
/** field name used for text display<br/>
|
|
460
|
-
* Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
461
|
-
* Note: don't use 'id - name', return undefined
|
|
459
|
+
/** field name used for text display<br/>
|
|
460
|
+
* Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
|
|
461
|
+
* Note: don't use 'id - name', return undefined
|
|
462
462
|
*/
|
|
463
463
|
displayExpr: oneOfType([string, array]),
|
|
464
464
|
|
package/icons/effect.js
CHANGED
|
@@ -94,8 +94,8 @@ Icon.propTypes = {
|
|
|
94
94
|
/** name of icon in icons store */
|
|
95
95
|
name: PropTypes.string.isRequired,
|
|
96
96
|
|
|
97
|
-
/** color of icon<br />
|
|
98
|
-
* default: #7F828E
|
|
97
|
+
/** color of icon<br />
|
|
98
|
+
* default: #7F828E
|
|
99
99
|
*/
|
|
100
100
|
color: PropTypes.string,
|
|
101
101
|
|
|
@@ -117,19 +117,19 @@ Icon.propTypes = {
|
|
|
117
117
|
/** have view box if true */
|
|
118
118
|
onClick: PropTypes.func,
|
|
119
119
|
|
|
120
|
-
/**
|
|
121
|
-
* ref methods
|
|
122
|
-
*
|
|
123
|
-
* * option(): Gets all UI component properties
|
|
124
|
-
* * Returns value - object
|
|
125
|
-
* * option(optionName): Gets the value of a single property
|
|
126
|
-
* * @param {optionName} - string
|
|
127
|
-
* * Returns value - any
|
|
128
|
-
* * option(optionName, optionValue): Updates the value of a single property
|
|
129
|
-
* * @param {optionName} - string
|
|
130
|
-
* * @param {optionValue} - any
|
|
131
|
-
* * option(options): Updates the values of several properties
|
|
132
|
-
* * @param {options} - object
|
|
120
|
+
/**
|
|
121
|
+
* ref methods
|
|
122
|
+
*
|
|
123
|
+
* * option(): Gets all UI component properties
|
|
124
|
+
* * Returns value - object
|
|
125
|
+
* * option(optionName): Gets the value of a single property
|
|
126
|
+
* * @param {optionName} - string
|
|
127
|
+
* * Returns value - any
|
|
128
|
+
* * option(optionName, optionValue): Updates the value of a single property
|
|
129
|
+
* * @param {optionName} - string
|
|
130
|
+
* * @param {optionValue} - any
|
|
131
|
+
* * option(options): Updates the values of several properties
|
|
132
|
+
* * @param {options} - object
|
|
133
133
|
*/
|
|
134
134
|
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
135
135
|
current: PropTypes.instanceOf(Element)
|
package/package.json
CHANGED
package/styles/color-helper.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Returns a number whose value is limited to the given range.
|
|
5
|
-
*
|
|
6
|
-
* @param {number} value The value to be clamped
|
|
7
|
-
* @param {number} min The lower boundary of the output range
|
|
8
|
-
* @param {number} max The upper boundary of the output range
|
|
9
|
-
* @returns {number} A number in the range [min, max]
|
|
3
|
+
/**
|
|
4
|
+
* Returns a number whose value is limited to the given range.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} value The value to be clamped
|
|
7
|
+
* @param {number} min The lower boundary of the output range
|
|
8
|
+
* @param {number} max The upper boundary of the output range
|
|
9
|
+
* @returns {number} A number in the range [min, max]
|
|
10
10
|
*/
|
|
11
11
|
const clamp = (value, min = 0, max = 1) => {
|
|
12
12
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -17,11 +17,11 @@ const clamp = (value, min = 0, max = 1) => {
|
|
|
17
17
|
|
|
18
18
|
return Math.min(Math.max(min, value), max);
|
|
19
19
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Converts a color from CSS hex format to CSS rgb format.
|
|
22
|
-
*
|
|
23
|
-
* @param {string} color - Hex color, i.e. #nnn or #nnnnnn
|
|
24
|
-
* @returns {string} A CSS rgb color string
|
|
20
|
+
/**
|
|
21
|
+
* Converts a color from CSS hex format to CSS rgb format.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} color - Hex color, i.e. #nnn or #nnnnnn
|
|
24
|
+
* @returns {string} A CSS rgb color string
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
|
|
@@ -43,11 +43,11 @@ const intToHex = int => {
|
|
|
43
43
|
const hex = int.toString(16);
|
|
44
44
|
return hex.length === 1 ? `0${hex}` : hex;
|
|
45
45
|
};
|
|
46
|
-
/**
|
|
47
|
-
* Converts a color from CSS rgb format to CSS hex format.
|
|
48
|
-
*
|
|
49
|
-
* @param {string} color - RGB color, i.e. rgb(n, n, n)
|
|
50
|
-
* @returns {string} A CSS rgb color string, i.e. #nnnnnn
|
|
46
|
+
/**
|
|
47
|
+
* Converts a color from CSS rgb format to CSS hex format.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} color - RGB color, i.e. rgb(n, n, n)
|
|
50
|
+
* @returns {string} A CSS rgb color string, i.e. #nnnnnn
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
|
|
@@ -61,11 +61,11 @@ export const rgbToHex = color => {
|
|
|
61
61
|
} = decomposeColor(color);
|
|
62
62
|
return `#${values.map(n => intToHex(n)).join('')}`;
|
|
63
63
|
};
|
|
64
|
-
/**
|
|
65
|
-
* Converts a color from CSS rgb format to CSS hex format.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} color - RGBA color, i.e. rgba(n, n, n, f)
|
|
68
|
-
* @returns {string} A CSS rgb A color string, i.e. #nnnnnnnn
|
|
64
|
+
/**
|
|
65
|
+
* Converts a color from CSS rgb format to CSS hex format.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} color - RGBA color, i.e. rgba(n, n, n, f)
|
|
68
|
+
* @returns {string} A CSS rgb A color string, i.e. #nnnnnnnn
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
71
|
export const rgbaToHexA = color => {
|
|
@@ -98,11 +98,11 @@ export const rgbaToHexA = color => {
|
|
|
98
98
|
if (a.length == 1) a = '0' + a;
|
|
99
99
|
return '#' + r + g + b + a;
|
|
100
100
|
};
|
|
101
|
-
/**
|
|
102
|
-
* Converts a color from hsl format to rgb format.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} color - HSL color values
|
|
105
|
-
* @returns {string} rgb color values
|
|
101
|
+
/**
|
|
102
|
+
* Converts a color from hsl format to rgb format.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} color - HSL color values
|
|
105
|
+
* @returns {string} rgb color values
|
|
106
106
|
*/
|
|
107
107
|
|
|
108
108
|
export const hslToRgb = color => {
|
|
@@ -130,13 +130,13 @@ export const hslToRgb = color => {
|
|
|
130
130
|
values: rgb
|
|
131
131
|
});
|
|
132
132
|
};
|
|
133
|
-
/**
|
|
134
|
-
* Returns an object with the type and values of a color.
|
|
135
|
-
*
|
|
136
|
-
* Note: Does not support rgb % values.
|
|
137
|
-
*
|
|
138
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
139
|
-
* @returns {object} - A color object: {type: string, values: number[]}
|
|
133
|
+
/**
|
|
134
|
+
* Returns an object with the type and values of a color.
|
|
135
|
+
*
|
|
136
|
+
* Note: Does not support rgb % values.
|
|
137
|
+
*
|
|
138
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
139
|
+
* @returns {object} - A color object: {type: string, values: number[]}
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
142
|
export const decomposeColor = color => {
|
|
@@ -162,13 +162,13 @@ export const decomposeColor = color => {
|
|
|
162
162
|
values
|
|
163
163
|
};
|
|
164
164
|
};
|
|
165
|
-
/**
|
|
166
|
-
* Converts a color object with type and values to a string.
|
|
167
|
-
*
|
|
168
|
-
* @param {object} color - Decomposed color
|
|
169
|
-
* @param {string} color.type - One of: 'rgb', 'rgba', 'hsl', 'hsla'
|
|
170
|
-
* @param {array} color.values - [n,n,n] or [n,n,n,n]
|
|
171
|
-
* @returns {string} A CSS color string
|
|
165
|
+
/**
|
|
166
|
+
* Converts a color object with type and values to a string.
|
|
167
|
+
*
|
|
168
|
+
* @param {object} color - Decomposed color
|
|
169
|
+
* @param {string} color.type - One of: 'rgb', 'rgba', 'hsl', 'hsla'
|
|
170
|
+
* @param {array} color.values - [n,n,n] or [n,n,n,n]
|
|
171
|
+
* @returns {string} A CSS color string
|
|
172
172
|
*/
|
|
173
173
|
|
|
174
174
|
export const recomposeColor = color => {
|
|
@@ -189,14 +189,14 @@ export const recomposeColor = color => {
|
|
|
189
189
|
|
|
190
190
|
return `${type}(${values.join(', ')})`;
|
|
191
191
|
};
|
|
192
|
-
/**
|
|
193
|
-
* Calculates the contrast ratio between two colors.
|
|
194
|
-
*
|
|
195
|
-
* Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
|
|
196
|
-
*
|
|
197
|
-
* @param {string} foreground - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
198
|
-
* @param {string} background - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
199
|
-
* @returns {number} A contrast ratio value in the range 0 - 21.
|
|
192
|
+
/**
|
|
193
|
+
* Calculates the contrast ratio between two colors.
|
|
194
|
+
*
|
|
195
|
+
* Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
|
|
196
|
+
*
|
|
197
|
+
* @param {string} foreground - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
198
|
+
* @param {string} background - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
199
|
+
* @returns {number} A contrast ratio value in the range 0 - 21.
|
|
200
200
|
*/
|
|
201
201
|
|
|
202
202
|
export const getContrastRatio = (foreground, background) => {
|
|
@@ -204,14 +204,14 @@ export const getContrastRatio = (foreground, background) => {
|
|
|
204
204
|
const lumB = getLuminance(background);
|
|
205
205
|
return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05);
|
|
206
206
|
};
|
|
207
|
-
/**
|
|
208
|
-
* The relative brightness of any point in a color space,
|
|
209
|
-
* normalized to 0 for darkest black and 1 for lightest white.
|
|
210
|
-
*
|
|
211
|
-
* Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
|
|
212
|
-
*
|
|
213
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
214
|
-
* @returns {number} The relative brightness of the color in the range 0 - 1
|
|
207
|
+
/**
|
|
208
|
+
* The relative brightness of any point in a color space,
|
|
209
|
+
* normalized to 0 for darkest black and 1 for lightest white.
|
|
210
|
+
*
|
|
211
|
+
* Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
|
|
212
|
+
*
|
|
213
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
214
|
+
* @returns {number} The relative brightness of the color in the range 0 - 1
|
|
215
215
|
*/
|
|
216
216
|
|
|
217
217
|
export const getLuminance = color => {
|
|
@@ -225,25 +225,25 @@ export const getLuminance = color => {
|
|
|
225
225
|
|
|
226
226
|
return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3));
|
|
227
227
|
};
|
|
228
|
-
/**
|
|
229
|
-
* Darken or lighten a color, depending on its luminance.
|
|
230
|
-
* Light colors are darkened, dark colors are lightened.
|
|
231
|
-
*
|
|
232
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
233
|
-
* @param {number} coefficient=0.15 - multiplier in the range 0 - 1
|
|
234
|
-
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
228
|
+
/**
|
|
229
|
+
* Darken or lighten a color, depending on its luminance.
|
|
230
|
+
* Light colors are darkened, dark colors are lightened.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
233
|
+
* @param {number} coefficient=0.15 - multiplier in the range 0 - 1
|
|
234
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
235
235
|
*/
|
|
236
236
|
|
|
237
237
|
export const emphasize = (color, coefficient = 0.15) => {
|
|
238
238
|
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
239
239
|
};
|
|
240
|
-
/**
|
|
241
|
-
* Set the absolute transparency of a color.
|
|
242
|
-
* Any existing alpha values are overwritten.
|
|
243
|
-
*
|
|
244
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
245
|
-
* @param {number} value - value to set the alpha channel to in the range 0 -1
|
|
246
|
-
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
240
|
+
/**
|
|
241
|
+
* Set the absolute transparency of a color.
|
|
242
|
+
* Any existing alpha values are overwritten.
|
|
243
|
+
*
|
|
244
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
245
|
+
* @param {number} value - value to set the alpha channel to in the range 0 -1
|
|
246
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
247
247
|
*/
|
|
248
248
|
|
|
249
249
|
export const fade = (color, value) => {
|
|
@@ -257,12 +257,12 @@ export const fade = (color, value) => {
|
|
|
257
257
|
color.values[3] = value;
|
|
258
258
|
return recomposeColor(color);
|
|
259
259
|
};
|
|
260
|
-
/**
|
|
261
|
-
* Darkens a color.
|
|
262
|
-
*
|
|
263
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
264
|
-
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
265
|
-
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
260
|
+
/**
|
|
261
|
+
* Darkens a color.
|
|
262
|
+
*
|
|
263
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
264
|
+
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
265
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
266
266
|
*/
|
|
267
267
|
|
|
268
268
|
export const darken = (color, coefficient) => {
|
|
@@ -281,12 +281,12 @@ export const darken = (color, coefficient) => {
|
|
|
281
281
|
|
|
282
282
|
return recomposeColor(color);
|
|
283
283
|
};
|
|
284
|
-
/**
|
|
285
|
-
* Lightens a color.
|
|
286
|
-
*
|
|
287
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
288
|
-
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
289
|
-
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
284
|
+
/**
|
|
285
|
+
* Lightens a color.
|
|
286
|
+
*
|
|
287
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
288
|
+
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
289
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
290
290
|
*/
|
|
291
291
|
|
|
292
292
|
export const lighten = (color, coefficient) => {
|
|
@@ -305,22 +305,22 @@ export const lighten = (color, coefficient) => {
|
|
|
305
305
|
|
|
306
306
|
return recomposeColor(color);
|
|
307
307
|
};
|
|
308
|
-
/**
|
|
309
|
-
* Validate a color string.
|
|
310
|
-
*
|
|
311
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
312
|
-
* @returns {boolean} is a color
|
|
308
|
+
/**
|
|
309
|
+
* Validate a color string.
|
|
310
|
+
*
|
|
311
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
312
|
+
* @returns {boolean} is a color
|
|
313
313
|
*/
|
|
314
314
|
|
|
315
315
|
export const isColor = color => {
|
|
316
316
|
const regex = /(^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$|^(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0|0?\.\d+)\)$|^(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/gim;
|
|
317
317
|
return regex.test(color);
|
|
318
318
|
};
|
|
319
|
-
/**
|
|
320
|
-
* Detect a color string type.
|
|
321
|
-
*
|
|
322
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
323
|
-
* @returns {string | false} color type, string or false
|
|
319
|
+
/**
|
|
320
|
+
* Detect a color string type.
|
|
321
|
+
*
|
|
322
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
323
|
+
* @returns {string | false} color type, string or false
|
|
324
324
|
*/
|
|
325
325
|
|
|
326
326
|
export const detectColor = color => {
|
|
@@ -335,11 +335,11 @@ export const detectColor = color => {
|
|
|
335
335
|
|
|
336
336
|
return null;
|
|
337
337
|
};
|
|
338
|
-
/**
|
|
339
|
-
* Validate a color name.
|
|
340
|
-
*
|
|
341
|
-
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
342
|
-
* @returns {boolean} is a color
|
|
338
|
+
/**
|
|
339
|
+
* Validate a color name.
|
|
340
|
+
*
|
|
341
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
342
|
+
* @returns {boolean} is a color
|
|
343
343
|
*/
|
|
344
344
|
|
|
345
345
|
export const isColorName = color => {
|
|
@@ -347,11 +347,11 @@ export const isColorName = color => {
|
|
|
347
347
|
ctx.fillStyle = color;
|
|
348
348
|
return ctx.fillStyle === '#000000' ? false : ctx.fillStyle;
|
|
349
349
|
};
|
|
350
|
-
/**
|
|
351
|
-
* Convert from #ffffff to rgba()
|
|
352
|
-
* @param hex color - #ffffff
|
|
353
|
-
* @param {number} alpha - 0.5
|
|
354
|
-
* @returns {string} color - rgba()
|
|
350
|
+
/**
|
|
351
|
+
* Convert from #ffffff to rgba()
|
|
352
|
+
* @param hex color - #ffffff
|
|
353
|
+
* @param {number} alpha - 0.5
|
|
354
|
+
* @returns {string} color - rgba()
|
|
355
355
|
*/
|
|
356
356
|
|
|
357
357
|
export const hexToRGBA = (hex, alpha) => {
|
package/utils/error/error.js
CHANGED
package/utils/renderIcon.js
CHANGED
|
@@ -5,11 +5,11 @@ import { jsx } from '@emotion/core';
|
|
|
5
5
|
import { ButtonIcon } from '../components';
|
|
6
6
|
import * as Icons from '../icons';
|
|
7
7
|
import { parseTextToHTML, capitalize } from './';
|
|
8
|
-
/**
|
|
9
|
-
* render icon form source (dynamic type)
|
|
10
|
-
* @param {String|jsx} source data of icon, maybe svg text | image link | name of icon in icons store or a jsx element
|
|
11
|
-
* @param {String} type text to parse text to HTML, img link to use img tag, name to use icon form icons store
|
|
12
|
-
* @param {Object} options properties of Icon component if us type is name {width, height, color, viewBox, ...}
|
|
8
|
+
/**
|
|
9
|
+
* render icon form source (dynamic type)
|
|
10
|
+
* @param {String|jsx} source data of icon, maybe svg text | image link | name of icon in icons store or a jsx element
|
|
11
|
+
* @param {String} type text to parse text to HTML, img link to use img tag, name to use icon form icons store
|
|
12
|
+
* @param {Object} options properties of Icon component if us type is name {width, height, color, viewBox, ...}
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
const renderIcon = (source, type, options = {}) => {
|