diginet-core-ui 1.3.67 → 1.3.68
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/avatar/index.js +19 -19
- package/components/badge/index.js +5 -5
- package/components/button/icon.js +21 -21
- package/components/button/index.js +13 -13
- package/components/form-control/attachment/index.js +21 -21
- package/components/form-control/calendar/function.js +113 -113
- package/components/form-control/input-base/index.js +47 -10
- package/components/form-control/money-input/index.js +6 -2
- package/components/form-control/number-input/index2.js +13 -4
- package/components/form-control/phone-input/index.js +6 -2
- package/components/form-control/text-input/index.js +13 -3
- package/components/paging/page-info.js +285 -101
- package/components/paging/page-selector2.js +95 -56
- package/components/popover/index.js +21 -21
- package/icons/effect.js +15 -15
- package/package.json +1 -1
- package/readme.md +6 -0
- package/styles/utils.js +10 -10
- package/utils/classNames.js +30 -0
- package/utils/index.js +1 -0
- package/utils/useInput.js +1 -8
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { memo, useState, useRef, useEffect, useMemo, forwardRef, useImperativeHandle } from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { jsx, css } from '@emotion/core';
|
|
7
|
+
import OptionWrapper from '../others/option-wrapper';
|
|
7
8
|
import { getGlobal } from '../../global';
|
|
8
9
|
import theme from '../../theme/settings';
|
|
9
10
|
import { alignCenter, borderBox, flexRow, parseHeight } from '../../styles/general';
|
|
@@ -40,6 +41,7 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
40
41
|
className,
|
|
41
42
|
currentPage,
|
|
42
43
|
hideEllipsis,
|
|
44
|
+
hideWithPage,
|
|
43
45
|
id,
|
|
44
46
|
itemsPerPage,
|
|
45
47
|
onChangePage,
|
|
@@ -62,7 +64,11 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
62
64
|
}] = useElementSize();
|
|
63
65
|
const lastPage = getLastPage(totalItemsState, itemsPerPageState);
|
|
64
66
|
|
|
65
|
-
const _onChangePage = async (
|
|
67
|
+
const _onChangePage = async ({
|
|
68
|
+
page,
|
|
69
|
+
e,
|
|
70
|
+
changeBy
|
|
71
|
+
}) => {
|
|
66
72
|
let disablePrev = false;
|
|
67
73
|
let disableNext = false; // If last page = 1. Disable all
|
|
68
74
|
|
|
@@ -81,16 +87,22 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
81
87
|
disablePrev = true;
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
setDisablePrevState(disablePrev);
|
|
91
|
+
setDisableNextState(disableNext);
|
|
92
|
+
if (page === currentPageState) return;
|
|
93
|
+
|
|
94
|
+
if (onChangingPage) {
|
|
85
95
|
const event = { ...e,
|
|
86
96
|
cancel: false,
|
|
87
97
|
prevPage: currentPageState,
|
|
88
|
-
newPage: page
|
|
98
|
+
newPage: page,
|
|
99
|
+
changeBy: changeBy
|
|
89
100
|
};
|
|
90
101
|
await onChangingPage(event);
|
|
91
102
|
|
|
92
103
|
if (event.cancel) {
|
|
93
104
|
if (e !== null && e !== void 0 && e.reset) e.reset();
|
|
105
|
+
currentPageRef.current = currentPageState;
|
|
94
106
|
setCurrentPageState(currentPageState);
|
|
95
107
|
return;
|
|
96
108
|
}
|
|
@@ -98,12 +110,11 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
98
110
|
|
|
99
111
|
currentPageRef.current = page;
|
|
100
112
|
setCurrentPageState(page);
|
|
101
|
-
|
|
102
|
-
setDisableNextState(disableNext);
|
|
103
|
-
if (onChangePage && !isInit) onChangePage(page);
|
|
113
|
+
if (onChangePage) onChangePage(page);
|
|
104
114
|
};
|
|
105
115
|
|
|
106
116
|
const _onChangePerPage = async per => {
|
|
117
|
+
if (per === itemsPerPageState) return;
|
|
107
118
|
const lastPage = getLastPage(totalItemsState, per);
|
|
108
119
|
per = parseInt(per, 10);
|
|
109
120
|
let disableNext = false; // If last page = 1. Disable all
|
|
@@ -125,9 +136,13 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
138
|
|
|
128
|
-
currentPageRef.current = 0;
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
setItemsPerPageState(per); // currentPageRef.current = 0;
|
|
140
|
+
// setCurrentPageState(0);
|
|
141
|
+
|
|
142
|
+
_onChangePage({
|
|
143
|
+
page: 0
|
|
144
|
+
});
|
|
145
|
+
|
|
131
146
|
setDisablePrevState(true);
|
|
132
147
|
setDisableNextState(disableNext);
|
|
133
148
|
if (onChangePerPage) onChangePerPage(per);
|
|
@@ -137,48 +152,43 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
137
152
|
setTotalItemsState(totalItems);
|
|
138
153
|
}, [totalItems]);
|
|
139
154
|
useEffect(() => {
|
|
140
|
-
|
|
141
|
-
clearTimeout(timer.current);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
timer.current = setTimeout(() => {
|
|
145
|
-
_onChangePage(currentPageState !== null && currentPageState !== void 0 ? currentPageState : 0, true);
|
|
146
|
-
}, delayOnInput);
|
|
147
|
-
}, [totalItemsState, itemsPerPageState]);
|
|
148
|
-
useEffect(() => {
|
|
149
|
-
setItemsPerPageState(itemsPerPage);
|
|
155
|
+
_onChangePerPage(itemsPerPage);
|
|
150
156
|
}, [itemsPerPage]);
|
|
151
157
|
useEffect(() => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
timer.current = setTimeout(() => {
|
|
159
|
-
_onChangePage(currentPage, true);
|
|
160
|
-
}, delayOnInput);
|
|
158
|
+
_onChangePage({
|
|
159
|
+
page: currentPage,
|
|
160
|
+
changeBy: 'currentPage'
|
|
161
|
+
});
|
|
161
162
|
}, [currentPage]);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
_onChangePage({
|
|
165
|
+
page: totalItemsState / itemsPerPageState < currentPageState - 1 ? 0 : currentPageState,
|
|
166
|
+
changeBy: 'totalItems'
|
|
167
|
+
});
|
|
168
|
+
}, [totalItemsState]);
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
_onChangePage({
|
|
171
|
+
page: totalItemsState / itemsPerPageState < currentPageState - 1 ? 0 : currentPageState,
|
|
172
|
+
changeBy: 'itemsPerPage'
|
|
173
|
+
});
|
|
174
|
+
}, [itemsPerPageState]);
|
|
175
|
+
useImperativeHandle(reference, () => ({
|
|
176
|
+
element: ref.current,
|
|
177
|
+
instance: {
|
|
178
|
+
onChangePage: page => _onChangePage({
|
|
179
|
+
page: page,
|
|
180
|
+
changeBy: 'ref'
|
|
181
|
+
}),
|
|
166
182
|
onChangePerPage: per => _onChangePerPage(per),
|
|
167
183
|
setTotalItems: items => setTotalItemsState(items)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
currentRef.onChangePerPage = per => _onChangePerPage(per);
|
|
177
|
-
|
|
178
|
-
currentRef.setTotalItems = items => setTotalItemsState(items);
|
|
179
|
-
|
|
180
|
-
return currentRef;
|
|
181
|
-
});
|
|
184
|
+
},
|
|
185
|
+
onChangePage: page => _onChangePage({
|
|
186
|
+
page: page,
|
|
187
|
+
changeBy: 'ref'
|
|
188
|
+
}),
|
|
189
|
+
onChangePerPage: per => _onChangePerPage(per),
|
|
190
|
+
setTotalItems: items => setTotalItemsState(items)
|
|
191
|
+
}));
|
|
182
192
|
|
|
183
193
|
const renderButton = (key, page, isSelected, customDisplay) => {
|
|
184
194
|
if (page >= lastPage || page < 0) return;
|
|
@@ -192,17 +202,35 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
192
202
|
style: {
|
|
193
203
|
fontWeight: 'normal'
|
|
194
204
|
},
|
|
195
|
-
onClick: e => page !== currentPageState && _onChangePage(
|
|
205
|
+
onClick: e => page !== currentPageState && _onChangePage({
|
|
206
|
+
page: page,
|
|
207
|
+
e: e
|
|
208
|
+
})
|
|
196
209
|
}, customDisplay || page + 1);
|
|
197
210
|
};
|
|
198
211
|
|
|
212
|
+
const checkShowSelector = () => {
|
|
213
|
+
switch (hideWithPage) {
|
|
214
|
+
case 'empty':
|
|
215
|
+
return totalItemsState !== 0;
|
|
216
|
+
|
|
217
|
+
case 'single':
|
|
218
|
+
return totalItemsState / itemsPerPageState > 1;
|
|
219
|
+
|
|
220
|
+
case 'none':
|
|
221
|
+
default:
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
199
226
|
return useMemo(() => {
|
|
200
227
|
const count = componentWidth >= 368 ? 10 : componentWidth >= 208 ? 5 : 1;
|
|
201
|
-
const pageArr = Array
|
|
228
|
+
const pageArr = [...Array(count).keys()];
|
|
202
229
|
const halfArrLength = Math.floor(count / 2);
|
|
203
230
|
const quarterArrLength = Math.floor(count / 2.5);
|
|
204
231
|
const showEllipsis = !hideEllipsis && count !== lastPage && count >= 5;
|
|
205
|
-
|
|
232
|
+
const showSelector = checkShowSelector();
|
|
233
|
+
return showSelector && jsx("div", {
|
|
206
234
|
css: PageSelectorCSS,
|
|
207
235
|
ref: node => {
|
|
208
236
|
ref.current = node;
|
|
@@ -218,14 +246,17 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
218
246
|
name: 'ArrowLeft',
|
|
219
247
|
disabled: disablePrevState,
|
|
220
248
|
onClick: e => {
|
|
221
|
-
currentPageRef.current = currentPageRef.current - 1;
|
|
249
|
+
currentPageRef.current = currentPageRef.current === 0 ? 0 : currentPageRef.current - 1;
|
|
222
250
|
|
|
223
251
|
if (timer.current) {
|
|
224
252
|
clearTimeout(timer.current);
|
|
225
253
|
}
|
|
226
254
|
|
|
227
255
|
timer.current = setTimeout(() => {
|
|
228
|
-
_onChangePage(
|
|
256
|
+
_onChangePage({
|
|
257
|
+
page: currentPageRef.current,
|
|
258
|
+
e: e
|
|
259
|
+
});
|
|
229
260
|
}, delayOnInput);
|
|
230
261
|
}
|
|
231
262
|
}), pageArr.map((_, idx) => {
|
|
@@ -278,18 +309,21 @@ const PagingSelector = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
278
309
|
name: 'ArrowRight',
|
|
279
310
|
disabled: disableNextState,
|
|
280
311
|
onClick: e => {
|
|
281
|
-
currentPageRef.current = currentPageRef.current + 1;
|
|
312
|
+
currentPageRef.current = currentPageRef.current === lastPage ? lastPage : currentPageRef.current + 1;
|
|
282
313
|
|
|
283
314
|
if (timer.current) {
|
|
284
315
|
clearTimeout(timer.current);
|
|
285
316
|
}
|
|
286
317
|
|
|
287
318
|
timer.current = setTimeout(() => {
|
|
288
|
-
_onChangePage(
|
|
319
|
+
_onChangePage({
|
|
320
|
+
page: currentPageRef.current,
|
|
321
|
+
e: e
|
|
322
|
+
});
|
|
289
323
|
}, delayOnInput);
|
|
290
324
|
}
|
|
291
325
|
}));
|
|
292
|
-
}, [id, style, className, hideEllipsis, totalItemsState, itemsPerPageState, currentPageState, disablePrevState, disableNextState, componentWidth]);
|
|
326
|
+
}, [id, style, className, hideEllipsis, hideWithPage, totalItemsState, itemsPerPageState, currentPageState, disablePrevState, disableNextState, componentWidth]);
|
|
293
327
|
}));
|
|
294
328
|
const PageSelectorCSS = css`
|
|
295
329
|
${flexRow};
|
|
@@ -309,7 +343,8 @@ PagingSelector.defaultProps = {
|
|
|
309
343
|
className: '',
|
|
310
344
|
totalItems: 0,
|
|
311
345
|
currentPage: 0,
|
|
312
|
-
hideEllipsis: false
|
|
346
|
+
hideEllipsis: false,
|
|
347
|
+
hideWithPage: 'none'
|
|
313
348
|
};
|
|
314
349
|
PagingSelector.propTypes = {
|
|
315
350
|
/** Class for component. */
|
|
@@ -321,6 +356,9 @@ PagingSelector.propTypes = {
|
|
|
321
356
|
/** If `true`, hide ellipsis. */
|
|
322
357
|
hideEllipsis: PropTypes.bool,
|
|
323
358
|
|
|
359
|
+
/** Hidden mode for page selector. */
|
|
360
|
+
hideWithPage: PropTypes.oneOf(['none', 'empty', 'single']),
|
|
361
|
+
|
|
324
362
|
/** The quantity of items per page. */
|
|
325
363
|
itemsPerPage: PropTypes.number,
|
|
326
364
|
|
|
@@ -370,4 +408,5 @@ PagingSelector.propTypes = {
|
|
|
370
408
|
current: PropTypes.instanceOf(Element)
|
|
371
409
|
})])
|
|
372
410
|
};
|
|
373
|
-
export
|
|
411
|
+
export { PagingSelector };
|
|
412
|
+
export default OptionWrapper(PagingSelector);
|
|
@@ -488,9 +488,9 @@ Popover.propTypes = {
|
|
|
488
488
|
/** An HTML element, or a function that returns one. It's used to set the position of the popover. */
|
|
489
489
|
anchor: PropTypes.oneOfType([PropTypes.instanceOf(Element), PropTypes.func, PropTypes.object, PropTypes.node]),
|
|
490
490
|
|
|
491
|
-
/**
|
|
492
|
-
* This is the point on the anchor where the popover's anchor will attach to.
|
|
493
|
-
* Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
|
|
491
|
+
/**
|
|
492
|
+
* This is the point on the anchor where the popover's anchor will attach to.
|
|
493
|
+
* Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
|
|
494
494
|
*/
|
|
495
495
|
anchorOrigin: PropTypes.shape({
|
|
496
496
|
horizontal: PropTypes.oneOf(['center', 'left', 'right']),
|
|
@@ -509,14 +509,14 @@ Popover.propTypes = {
|
|
|
509
509
|
/** If `true`, click outside will close component. */
|
|
510
510
|
clickOutsideToClose: PropTypes.bool,
|
|
511
511
|
|
|
512
|
-
/**
|
|
513
|
-
* Direction when Popover shown.
|
|
514
|
-
* Note: This prop will overwrite anchorOrigin & transformOrigin.
|
|
515
|
-
*
|
|
516
|
-
* * top: anchorOrigin: { vertical: 'top', horizontal: 'center' }, transformOrigin: { vertical: 'bottom', horizontal: 'center' }
|
|
517
|
-
* * left: anchorOrigin: { vertical: 'center', horizontal: 'left' }, transformOrigin: { vertical: 'center', horizontal: 'right' }
|
|
518
|
-
* * right: anchorOrigin: { vertical: 'center', horizontal: 'right' }, transformOrigin: { vertical: 'center', horizontal: 'left' }
|
|
519
|
-
* * right: anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'center' }
|
|
512
|
+
/**
|
|
513
|
+
* Direction when Popover shown.
|
|
514
|
+
* Note: This prop will overwrite anchorOrigin & transformOrigin.
|
|
515
|
+
*
|
|
516
|
+
* * top: anchorOrigin: { vertical: 'top', horizontal: 'center' }, transformOrigin: { vertical: 'bottom', horizontal: 'center' }
|
|
517
|
+
* * left: anchorOrigin: { vertical: 'center', horizontal: 'left' }, transformOrigin: { vertical: 'center', horizontal: 'right' }
|
|
518
|
+
* * right: anchorOrigin: { vertical: 'center', horizontal: 'right' }, transformOrigin: { vertical: 'center', horizontal: 'left' }
|
|
519
|
+
* * right: anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'center' }
|
|
520
520
|
*/
|
|
521
521
|
direction: PropTypes.oneOf(['top', 'left', 'right', 'bottom']),
|
|
522
522
|
|
|
@@ -532,9 +532,9 @@ Popover.propTypes = {
|
|
|
532
532
|
/** Style inline of component. */
|
|
533
533
|
style: PropTypes.object,
|
|
534
534
|
|
|
535
|
-
/**
|
|
536
|
-
* This is the point on the popover which will attach to the anchor's origin.
|
|
537
|
-
* Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
|
|
535
|
+
/**
|
|
536
|
+
* This is the point on the popover which will attach to the anchor's origin.
|
|
537
|
+
* Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
|
|
538
538
|
*/
|
|
539
539
|
transformOrigin: PropTypes.shape({
|
|
540
540
|
horizontal: PropTypes.oneOf(['center', 'left', 'right']),
|
|
@@ -547,13 +547,13 @@ Popover.propTypes = {
|
|
|
547
547
|
/** Config z-index of the component. */
|
|
548
548
|
zIndex: PropTypes.number,
|
|
549
549
|
|
|
550
|
-
/**
|
|
551
|
-
* ref methods (ref.current.instance.*method*)
|
|
552
|
-
*
|
|
553
|
-
* * show: Show popover
|
|
554
|
-
* * close: Close popover
|
|
555
|
-
* * setPosition(element): Set position of popover
|
|
556
|
-
* * @param {element} - element
|
|
550
|
+
/**
|
|
551
|
+
* ref methods (ref.current.instance.*method*)
|
|
552
|
+
*
|
|
553
|
+
* * show: Show popover
|
|
554
|
+
* * close: Close popover
|
|
555
|
+
* * setPosition(element): Set position of popover
|
|
556
|
+
* * @param {element} - element
|
|
557
557
|
*/
|
|
558
558
|
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
559
559
|
current: PropTypes.instanceOf(Element)
|
package/icons/effect.js
CHANGED
|
@@ -89,8 +89,8 @@ Icon.propTypes = {
|
|
|
89
89
|
/** name of icon in icons store */
|
|
90
90
|
name: PropTypes.string.isRequired,
|
|
91
91
|
|
|
92
|
-
/** color of icon<br />
|
|
93
|
-
* default: #7F828E
|
|
92
|
+
/** color of icon<br />
|
|
93
|
+
* default: #7F828E
|
|
94
94
|
*/
|
|
95
95
|
color: PropTypes.string,
|
|
96
96
|
|
|
@@ -112,19 +112,19 @@ Icon.propTypes = {
|
|
|
112
112
|
/** have view box if true */
|
|
113
113
|
onClick: PropTypes.func,
|
|
114
114
|
|
|
115
|
-
/**
|
|
116
|
-
* ref methods
|
|
117
|
-
*
|
|
118
|
-
* * option(): Gets all UI component properties
|
|
119
|
-
* * Returns value - object
|
|
120
|
-
* * option(optionName): Gets the value of a single property
|
|
121
|
-
* * @param {optionName} - string
|
|
122
|
-
* * Returns value - any
|
|
123
|
-
* * option(optionName, optionValue): Updates the value of a single property
|
|
124
|
-
* * @param {optionName} - string
|
|
125
|
-
* * @param {optionValue} - any
|
|
126
|
-
* * option(options): Updates the values of several properties
|
|
127
|
-
* * @param {options} - object
|
|
115
|
+
/**
|
|
116
|
+
* ref methods
|
|
117
|
+
*
|
|
118
|
+
* * option(): Gets all UI component properties
|
|
119
|
+
* * Returns value - object
|
|
120
|
+
* * option(optionName): Gets the value of a single property
|
|
121
|
+
* * @param {optionName} - string
|
|
122
|
+
* * Returns value - any
|
|
123
|
+
* * option(optionName, optionValue): Updates the value of a single property
|
|
124
|
+
* * @param {optionName} - string
|
|
125
|
+
* * @param {optionValue} - any
|
|
126
|
+
* * option(options): Updates the values of several properties
|
|
127
|
+
* * @param {options} - object
|
|
128
128
|
*/
|
|
129
129
|
reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
130
130
|
current: PropTypes.instanceOf(Element)
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -38,6 +38,12 @@ npm test
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Changelog
|
|
41
|
+
## 1.3.68
|
|
42
|
+
- \[Changed\]: PagingInfo – Update design
|
|
43
|
+
- \[Changed\]: InputBase – Add func auto scale width, apply for NumberInput, TextInput
|
|
44
|
+
- \[Changed\]: PagingSelector – Update functions in PagingSelector
|
|
45
|
+
- \[Changed\]: NumberInput, MoneyInput, PhoneInput – Add prop labelProps
|
|
46
|
+
|
|
41
47
|
## 1.3.67
|
|
42
48
|
- \[Added\]: Icon – ListAlt, PersonSetting, Undo, ViewHeadline
|
|
43
49
|
- \[Changed\]: OptionWrapper – Update OptionWrapper
|
package/styles/utils.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { color as colors } from './colors';
|
|
2
|
-
/**
|
|
3
|
-
* Parse to pixel
|
|
4
|
-
*
|
|
5
|
-
* @param {number} vl
|
|
6
|
-
* @returns {string}
|
|
2
|
+
/**
|
|
3
|
+
* Parse to pixel
|
|
4
|
+
*
|
|
5
|
+
* @param {number} vl
|
|
6
|
+
* @returns {string}
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export const parseToPixel = vl => {
|
|
10
10
|
if (!vl) return '1px';
|
|
11
11
|
return typeof vl === 'string' ? vl : `${vl}px`;
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Get color from CORE colors
|
|
15
|
-
*
|
|
16
|
-
* @param {string} cl
|
|
17
|
-
* @returns {string}
|
|
13
|
+
/**
|
|
14
|
+
* Get color from CORE colors
|
|
15
|
+
*
|
|
16
|
+
* @param {string} cl
|
|
17
|
+
* @returns {string}
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
export const getColor = cl => {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const hasOwn = {}.hasOwnProperty;
|
|
2
|
+
|
|
3
|
+
const classNames = (...args) => {
|
|
4
|
+
args = args.flat();
|
|
5
|
+
let classes = [];
|
|
6
|
+
|
|
7
|
+
for (let i = 0; i < args.length; i++) {
|
|
8
|
+
let arg = args[i];
|
|
9
|
+
if (!arg) continue;
|
|
10
|
+
let argType = typeof arg;
|
|
11
|
+
|
|
12
|
+
if (argType === 'string' || argType === 'number') {
|
|
13
|
+
classes.push(arg);
|
|
14
|
+
} else if (argType === 'object') {
|
|
15
|
+
if (arg.toString === Object.prototype.toString) {
|
|
16
|
+
for (let key in arg) {
|
|
17
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
18
|
+
classes.push(key);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
classes.push(arg.toString());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return classes.join(' ');
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default classNames;
|
package/utils/index.js
CHANGED
|
@@ -19,4 +19,5 @@ export { default as useOnClickOutside } from './useOnClickOutside';
|
|
|
19
19
|
export { default as usePortal } from './usePortal';
|
|
20
20
|
export * from './validate';
|
|
21
21
|
export { default as onValidate } from './validate';
|
|
22
|
+
export { default as classNames } from './classNames';
|
|
22
23
|
export default utils;
|
package/utils/useInput.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { useState, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
const useInput =
|
|
4
|
-
let {
|
|
5
|
-
defaultValue,
|
|
6
|
-
valueProp,
|
|
7
|
-
delayOnChange,
|
|
8
|
-
onChange,
|
|
9
|
-
onInput
|
|
10
|
-
} = props || {};
|
|
3
|
+
const useInput = (defaultValue, valueProp, onChange, onInput, delayOnChange) => {
|
|
11
4
|
const [value, setValue] = useState(defaultValue || valueProp);
|
|
12
5
|
const timer = useRef(null);
|
|
13
6
|
delayOnChange = Number(delayOnChange || 0);
|