diginet-core-ui 1.3.78 → 1.3.79
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/accordion/details.js +2 -6
- package/components/accordion/group.js +2 -9
- package/components/accordion/index.js +2 -15
- package/components/accordion/summary.js +4 -27
- package/components/alert/index.js +98 -137
- package/components/alert/notify.js +97 -166
- package/components/avatar/index.js +4 -63
- package/components/badge/index.js +7 -34
- package/components/button/icon.js +120 -186
- package/components/button/index.js +136 -205
- package/components/button/more.js +0 -12
- package/components/button/ripple-effect.js +46 -44
- package/components/card/body.js +2 -7
- package/components/card/extra.js +2 -7
- package/components/card/footer.js +2 -7
- package/components/card/header.js +2 -7
- package/components/card/index.js +2 -22
- package/components/chart/Pie/Circle.js +0 -1
- package/components/chart/Pie/Sector.js +0 -17
- package/components/chart/Pie/Sectors.js +0 -10
- package/components/chart/Pie/index.js +4 -36
- package/components/chart/Pie-v2/Circle.js +0 -1
- package/components/chart/Pie-v2/Sector.js +0 -13
- package/components/chart/Pie-v2/Sectors.js +0 -20
- package/components/chart/Pie-v2/index.js +11 -38
- package/components/chart/bar/Axis.js +0 -12
- package/components/chart/bar/Bar.js +13 -35
- package/components/chart/bar/Grid.js +0 -18
- package/components/chart/bar/Labels.js +0 -18
- package/components/chart/bar/Points.js +0 -17
- package/components/chart/bar/index.js +6 -26
- package/components/chart/bar-v2/Axis.js +0 -12
- package/components/chart/bar-v2/Bar.js +15 -36
- package/components/chart/bar-v2/Grid.js +0 -18
- package/components/chart/bar-v2/Labels.js +0 -18
- package/components/chart/bar-v2/Points.js +0 -17
- package/components/chart/bar-v2/index.js +6 -26
- package/components/chart/line/Axis.js +4 -16
- package/components/chart/line/Grid.js +2 -19
- package/components/chart/line/Labels.js +0 -18
- package/components/chart/line/Path.js +23 -33
- package/components/chart/line/Point.js +6 -40
- package/components/chart/line/Title.js +0 -3
- package/components/chart/line/index.js +12 -35
- package/components/chart/line-v2/Axis.js +0 -13
- package/components/chart/line-v2/Grid.js +0 -18
- package/components/chart/line-v2/Labels.js +0 -18
- package/components/chart/line-v2/Path.js +23 -33
- package/components/chart/line-v2/Point.js +6 -35
- package/components/chart/line-v2/Title.js +0 -3
- package/components/chart/line-v2/index.js +12 -30
- package/components/check-text/index.js +0 -8
- package/components/check-text/interview-confirmation.js +0 -7
- package/components/check-text/interview-status.js +0 -7
- package/components/chip/attach.js +4 -17
- package/components/chip/index.js +6 -33
- package/components/collapse/index.js +0 -13
- package/components/divider/index.js +0 -8
- package/components/form-control/attachment/index.js +24 -202
- package/components/form-control/calendar/function.js +40 -94
- package/components/form-control/calendar/index.js +5 -30
- package/components/form-control/calendar/range.js +11 -28
- package/components/form-control/checkbox/index.js +4 -37
- package/components/form-control/control/index.js +3 -13
- package/components/form-control/date-picker/index-old.js +18 -0
- package/components/form-control/date-picker/index.js +23 -99
- package/components/form-control/date-range-picker/index.js +86 -221
- package/components/form-control/dropdown/index.js +72 -289
- package/components/form-control/dropdown-box/index.js +6 -35
- package/components/form-control/form/index.js +0 -2
- package/components/form-control/form-group/index.js +1 -6
- package/components/form-control/helper-text/index.js +2 -9
- package/components/form-control/input-base/index.js +218 -399
- package/components/form-control/label/index.js +2 -12
- package/components/form-control/money-input/index.js +43 -132
- package/components/form-control/number-input/index.js +15 -113
- package/components/form-control/number-input/index2.js +78 -119
- package/components/form-control/phone-input/index.js +16 -78
- package/components/form-control/radio/index.js +4 -23
- package/components/form-control/text-input/index.js +33 -256
- package/components/form-control/time-picker/index.js +14 -71
- package/components/form-control/time-picker/swiper.js +21 -73
- package/components/form-control/toggle/index.js +4 -19
- package/components/form-view/helper-text.js +2 -2
- package/components/form-view/index.js +0 -14
- package/components/form-view/input.js +2 -13
- package/components/form-view/label.js +0 -2
- package/components/grid/Col.js +2 -15
- package/components/grid/Container.js +2 -21
- package/components/grid/Row.js +2 -21
- package/components/grid/index.js +2 -43
- package/components/image/index.js +2 -22
- package/components/index.js +62 -31
- package/components/list/list-item-action.js +0 -9
- package/components/list/list-item-icon.js +0 -9
- package/components/list/list-item-text.js +0 -5
- package/components/list/list-item.js +0 -11
- package/components/list/list.js +0 -13
- package/components/list/sub-header.js +0 -4
- package/components/modal/body.js +2 -6
- package/components/modal/footer.js +2 -11
- package/components/modal/header.js +2 -12
- package/components/modal/index.js +2 -10
- package/components/modal/modal.js +11 -52
- package/components/others/extra/index.js +3 -10
- package/components/others/import/index.js +0 -7
- package/components/others/option-wrapper/index.js +4 -7
- package/components/others/scrollbar/index.js +0 -3
- package/components/paging/page-info.js +39 -101
- package/components/paging/page-selector.js +7 -35
- package/components/paging/page-selector2.js +35 -74
- package/components/paper/index.js +0 -11
- package/components/popover/body.js +2 -6
- package/components/popover/footer.js +2 -11
- package/components/popover/header.js +2 -7
- package/components/popover/index.js +39 -123
- package/components/popup/danger_popup.js +0 -19
- package/components/popup/index.js +2 -48
- package/components/popup/proposals_popup.js +10 -49
- package/components/popup/v2/index.js +0 -31
- package/components/progress/circular.js +19 -81
- package/components/progress/linear.js +4 -20
- package/components/rating/index.js +0 -24
- package/components/slider/slider-container.js +3 -40
- package/components/slider/slider-item.js +10 -25
- package/components/status/index.js +2 -16
- package/components/tab/tab-container.js +2 -16
- package/components/tab/tab-header.js +4 -24
- package/components/tab/tab-panel.js +4 -16
- package/components/tab/tab.js +4 -28
- package/components/tooltip/index.js +12 -97
- package/components/tooltip/portal.js +0 -2
- package/components/transfer/index.js +22 -67
- package/components/tree-view/index.js +62 -202
- package/components/typography/index.js +3 -31
- package/global/index.js +0 -8
- package/icons/basic.js +0 -48
- package/icons/effect.js +17 -29
- package/icons/general/clock/clock.js +0 -2
- package/icons/general/color-handler/background.js +0 -2
- package/icons/general/color-handler/text.js +0 -2
- package/icons/general/emoji/emoji.js +0 -2
- package/icons/general/font-properties/bold.js +0 -2
- package/icons/general/font-properties/font-family.js +0 -2
- package/icons/general/font-properties/font-size.js +0 -2
- package/icons/general/font-properties/italic.js +0 -2
- package/icons/general/font-properties/underline.js +0 -2
- package/icons/general/hyperlink/hyperlink.js +0 -2
- package/icons/general/indent/decrease.js +0 -2
- package/icons/general/indent/increase.js +0 -2
- package/icons/general/list/bullets.js +0 -2
- package/icons/general/list/numbering.js +0 -2
- package/icons/general/picture/picture.js +0 -2
- package/icons/general/steps/redo.js +0 -2
- package/icons/general/steps/undo.js +0 -2
- package/icons/general/text-align/center.js +0 -2
- package/icons/general/text-align/justify.js +0 -2
- package/icons/general/text-align/left.js +0 -2
- package/icons/general/text-align/right.js +0 -2
- package/icons/menu/dhr.js +2 -1
- package/icons/menu/index.js +2 -2
- package/icons/menu/v2/index.js +0 -10
- package/package.json +1 -1
- package/readme.md +11 -1
- package/styles/animation.js +15 -58
- package/styles/color-helper.js +24 -54
- package/styles/colors.js +17 -9
- package/styles/general.js +6 -2
- package/styles/typography.js +4 -4
- package/styles/utils.js +2 -2
- package/theme/createBreakpoints.js +7 -18
- package/theme/make-styles.js +2 -5
- package/theme/set-theme.js +3 -6
- package/theme/settings.js +3 -2
- package/theme/theme-provider.js +0 -1
- package/utils/array/array.js +14 -23
- package/utils/classNames.js +0 -5
- package/utils/console.js +0 -6
- package/utils/date.js +13 -82
- package/utils/error/error.js +1 -9
- package/utils/error/errors.js +1 -48
- package/utils/getFileType.js +0 -9
- package/utils/handleBreakpoints.js +0 -5
- package/utils/intersectionObserver.js +0 -5
- package/utils/iterator.js +0 -9
- package/utils/map-parent.js +3 -10
- package/utils/object/extend.js +0 -10
- package/utils/object/object.js +12 -11
- package/utils/parseHTML.js +0 -1
- package/utils/promisify.js +0 -5
- package/utils/randomString.js +0 -7
- package/utils/remove-unicode.js +0 -1
- package/utils/render-portal.js +1 -9
- package/utils/renderHTML.js +4 -6
- package/utils/renderIcon.js +4 -14
- package/utils/sb-template.js +6 -5
- package/utils/string/capitalize.js +0 -1
- package/utils/string/capitalizeSentenceCase.js +0 -2
- package/utils/string/string.js +0 -13
- package/utils/type.js +0 -21
- package/utils/updatePosition.js +4 -5
- package/utils/useDelayUnmount.js +0 -4
- package/utils/useElementSize.js +9 -3
- package/utils/useEventListener.js +12 -6
- package/utils/useInput.js +0 -6
- package/utils/useMediaQuery.js +8 -10
- package/utils/useOnClickOutside.js +0 -2
- package/utils/usePortal.js +3 -10
- package/utils/validate.js +6 -20
package/utils/render-portal.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Children } from 'react';
|
|
|
2
2
|
import { render, createPortal } from 'react-dom';
|
|
3
3
|
import { useTheme } from '../theme';
|
|
4
4
|
const idPortal = 'DGN-UI-Portal',
|
|
5
|
-
|
|
5
|
+
classNameCommon = 'DGN-UI-Portal';
|
|
6
6
|
const {
|
|
7
7
|
zIndex
|
|
8
8
|
} = useTheme();
|
|
@@ -16,13 +16,11 @@ export const getPortal = () => {
|
|
|
16
16
|
};
|
|
17
17
|
export const isLastChildNode = node => {
|
|
18
18
|
if (!node) return false;
|
|
19
|
-
|
|
20
19
|
if (typeof node === 'string') {
|
|
21
20
|
node = document.querySelector(node);
|
|
22
21
|
} else {
|
|
23
22
|
node = node.current || node.target || node;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
const portal = getPortal();
|
|
27
25
|
const length = portal.childNodes.length;
|
|
28
26
|
return length && portal.lastChild.contains(node);
|
|
@@ -34,16 +32,13 @@ export const renderPortal = (node, containers, isCreate = false, options = {}) =
|
|
|
34
32
|
} = options;
|
|
35
33
|
let container = getPortal();
|
|
36
34
|
Object.assign(container, style);
|
|
37
|
-
|
|
38
35
|
if (className) {
|
|
39
36
|
container.classList.add(className);
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
if (containers) {
|
|
43
39
|
containers.classList.add(classNameCommon);
|
|
44
40
|
containers.style.pointerEvents = 'auto';
|
|
45
41
|
container = container.appendChild(containers);
|
|
46
|
-
|
|
47
42
|
if (isCreate) {
|
|
48
43
|
return /*#__PURE__*/createPortal(node, container);
|
|
49
44
|
} else {
|
|
@@ -67,7 +62,6 @@ export const renderPortal = (node, containers, isCreate = false, options = {}) =
|
|
|
67
62
|
parent.classList.add(classNameCommon);
|
|
68
63
|
parent.style.pointerEvents = 'auto';
|
|
69
64
|
container = container.appendChild(parent);
|
|
70
|
-
|
|
71
65
|
if (isCreate) {
|
|
72
66
|
return /*#__PURE__*/createPortal(children, container);
|
|
73
67
|
} else {
|
|
@@ -82,12 +76,10 @@ export const removePortal = node => {
|
|
|
82
76
|
removePortalCommon();
|
|
83
77
|
return true;
|
|
84
78
|
}
|
|
85
|
-
|
|
86
79
|
return false;
|
|
87
80
|
};
|
|
88
81
|
export const removePortalCommon = () => {
|
|
89
82
|
const portals = getPortal();
|
|
90
|
-
|
|
91
83
|
if (!portals.childNodes.length) {
|
|
92
84
|
portals.remove();
|
|
93
85
|
}
|
package/utils/renderHTML.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { jsx } from '@emotion/core';
|
|
5
4
|
import parseTextToHTML from './parseHTML';
|
|
6
|
-
|
|
7
5
|
const renderHTML = (text = null, TagName = 'div', options = {}) => {
|
|
8
6
|
if (text && (text.$$typeof && String(text.$$typeof) === 'Symbol(react.element)' || Array.isArray(text) && text.some(node => node && String(node.$$typeof) === 'Symbol(react.element)'))) {
|
|
9
|
-
return jsx(TagName, {
|
|
7
|
+
return jsx(TagName, {
|
|
8
|
+
...options
|
|
10
9
|
}, text);
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
return jsx(TagName, {
|
|
12
|
+
...options,
|
|
14
13
|
dangerouslySetInnerHTML: {
|
|
15
14
|
__html: parseTextToHTML(String(text))
|
|
16
15
|
}
|
|
17
16
|
});
|
|
18
17
|
};
|
|
19
|
-
|
|
20
18
|
export default renderHTML;
|
package/utils/renderIcon.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { jsx } from '@emotion/core';
|
|
5
4
|
import { ButtonIcon } from '../components';
|
|
@@ -11,53 +10,44 @@ import { parseTextToHTML, capitalize } from './';
|
|
|
11
10
|
* @param {String} type text to parse text to HTML, img link to use img tag, name to use icon form icons store
|
|
12
11
|
* @param {Object} options properties of Icon component if us type is name {width, height, color, viewBox, ...}
|
|
13
12
|
*/
|
|
14
|
-
|
|
15
13
|
const renderIcon = (source, type, options = {}) => {
|
|
16
14
|
if (typeof source === 'string') {
|
|
17
15
|
switch (type) {
|
|
18
16
|
case 'name':
|
|
19
17
|
{
|
|
20
18
|
let IconComp = Icons[capitalize(source)];
|
|
21
|
-
|
|
22
19
|
if (IconComp) {
|
|
23
|
-
return jsx(IconComp, {
|
|
20
|
+
return jsx(IconComp, {
|
|
21
|
+
...options
|
|
24
22
|
});
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
return null;
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
case 'effect':
|
|
31
27
|
return jsx(ButtonIcon, {
|
|
32
28
|
viewType: 'ghost',
|
|
33
29
|
name: source,
|
|
34
30
|
...options
|
|
35
31
|
});
|
|
36
|
-
|
|
37
32
|
case 'link':
|
|
38
33
|
case 'imgLink':
|
|
39
34
|
return jsx("img", {
|
|
40
35
|
src: source,
|
|
41
36
|
...options
|
|
42
37
|
});
|
|
43
|
-
|
|
44
38
|
default:
|
|
45
39
|
if (source.length < 20) {
|
|
46
40
|
const IconComp = Icons[capitalize(source)];
|
|
47
|
-
|
|
48
41
|
if (IconComp) {
|
|
49
|
-
return jsx(IconComp, {
|
|
42
|
+
return jsx(IconComp, {
|
|
43
|
+
...options
|
|
50
44
|
});
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
return null;
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
return parseTextToHTML(source, options.output || options);
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
return source;
|
|
61
52
|
};
|
|
62
|
-
|
|
63
53
|
export default renderIcon;
|
package/utils/sb-template.js
CHANGED
|
@@ -40,7 +40,8 @@ export const Template = ({
|
|
|
40
40
|
${alignMap.get(align)};
|
|
41
41
|
`
|
|
42
42
|
}, [{}, ...propsCustom].map((itemProps, indexProps) => {
|
|
43
|
-
const argsTemp = {
|
|
43
|
+
const argsTemp = {
|
|
44
|
+
...args,
|
|
44
45
|
...itemProps
|
|
45
46
|
};
|
|
46
47
|
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
@@ -48,11 +49,11 @@ export const Template = ({
|
|
|
48
49
|
disabled: disabledTooltip,
|
|
49
50
|
key: indexProps,
|
|
50
51
|
title: JSON.stringify(argsTemp)
|
|
51
|
-
}, /*#__PURE__*/React.createElement(Component, {
|
|
52
|
+
}, /*#__PURE__*/React.createElement(Component, {
|
|
53
|
+
...argsTemp
|
|
52
54
|
}));
|
|
53
55
|
})))));
|
|
54
56
|
};
|
|
55
|
-
|
|
56
57
|
const StoryBookTemplate = ({
|
|
57
58
|
args,
|
|
58
59
|
component,
|
|
@@ -79,7 +80,8 @@ const StoryBookTemplate = ({
|
|
|
79
80
|
key: idx,
|
|
80
81
|
horizontal: horizontal,
|
|
81
82
|
title: title,
|
|
82
|
-
args: {
|
|
83
|
+
args: {
|
|
84
|
+
...args,
|
|
83
85
|
...argsExtra
|
|
84
86
|
},
|
|
85
87
|
component: component,
|
|
@@ -89,7 +91,6 @@ const StoryBookTemplate = ({
|
|
|
89
91
|
});
|
|
90
92
|
})));
|
|
91
93
|
};
|
|
92
|
-
|
|
93
94
|
Template.defaultProps = {
|
|
94
95
|
propsCustom: [],
|
|
95
96
|
disabledTooltip: false,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import capitalize from './capitalize';
|
|
2
2
|
export default function capitalizeSentenceCase(string, separator = ' ') {
|
|
3
3
|
const sentence = string.toLowerCase().split(`${separator}`);
|
|
4
|
-
|
|
5
4
|
for (let i in sentence) {
|
|
6
5
|
sentence[i] = capitalize(sentence[i]);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
return sentence.join(`${separator}`);
|
|
10
8
|
}
|
package/utils/string/string.js
CHANGED
|
@@ -3,46 +3,36 @@ export const encodeHtml = str => {
|
|
|
3
3
|
const encodeRegExp = [new RegExp('&', 'g'), new RegExp('"', 'g'), new RegExp("'", 'g'), new RegExp('<', 'g'), new RegExp('>', 'g')];
|
|
4
4
|
return String(str).replace(encodeRegExp[0], '&').replace(encodeRegExp[1], '"').replace(encodeRegExp[2], ''').replace(encodeRegExp[3], '<').replace(encodeRegExp[4], '>');
|
|
5
5
|
};
|
|
6
|
-
|
|
7
6
|
const splitQuad = raw => {
|
|
8
7
|
switch (typeof raw) {
|
|
9
8
|
case 'string':
|
|
10
9
|
return raw.split(/\s+/, 4);
|
|
11
|
-
|
|
12
10
|
case 'object':
|
|
13
11
|
return [raw.x || raw.h || raw.left, raw.y || raw.v || raw.top, raw.x || raw.h || raw.right, raw.y || raw.v || raw.bottom];
|
|
14
|
-
|
|
15
12
|
case 'number':
|
|
16
13
|
return [raw];
|
|
17
|
-
|
|
18
14
|
default:
|
|
19
15
|
return raw;
|
|
20
16
|
}
|
|
21
17
|
};
|
|
22
|
-
|
|
23
18
|
export const quadToObject = raw => {
|
|
24
19
|
const quad = splitQuad(raw);
|
|
25
20
|
let left = parseInt(quad && quad[0], 10);
|
|
26
21
|
let top = parseInt(quad && quad[1], 10);
|
|
27
22
|
let right = parseInt(quad && quad[2], 10);
|
|
28
23
|
let bottom = parseInt(quad && quad[3], 10);
|
|
29
|
-
|
|
30
24
|
if (!isFinite(left)) {
|
|
31
25
|
left = 0;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
if (!isFinite(top)) {
|
|
35
28
|
top = left;
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
if (!isFinite(right)) {
|
|
39
31
|
right = left;
|
|
40
32
|
}
|
|
41
|
-
|
|
42
33
|
if (!isFinite(bottom)) {
|
|
43
34
|
bottom = top;
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
return {
|
|
47
37
|
top: top,
|
|
48
38
|
right: right,
|
|
@@ -54,12 +44,10 @@ export const format = (template, ...values) => {
|
|
|
54
44
|
if (isFunction(template)) {
|
|
55
45
|
return template(...values);
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
values.forEach((value, index) => {
|
|
59
48
|
if (isString(value)) {
|
|
60
49
|
value = value.replace(/\$/g, '$$$$');
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
const placeholderReg = new RegExp('\\{' + index + '\\}', 'gm');
|
|
64
52
|
template = template.replace(placeholderReg, value);
|
|
65
53
|
});
|
|
@@ -68,7 +56,6 @@ export const format = (template, ...values) => {
|
|
|
68
56
|
export const replaceAll = (() => {
|
|
69
57
|
const quote = str => (str + '').replace(/([+*?.[^\]$(){}><|=!:])/g, '\\$1'); // lgtm[js/incomplete-sanitization]
|
|
70
58
|
|
|
71
|
-
|
|
72
59
|
return (text, searchToken, replacementToken) => text.replace(new RegExp('(' + quote(searchToken) + ')', 'gi'), replacementToken);
|
|
73
60
|
})();
|
|
74
61
|
export const isEmpty = (() => {
|
package/utils/type.js
CHANGED
|
@@ -5,86 +5,65 @@ const types = {
|
|
|
5
5
|
'[object String]': 'string',
|
|
6
6
|
'[object Null]': 'null'
|
|
7
7
|
};
|
|
8
|
-
|
|
9
8
|
const type = object => {
|
|
10
9
|
const typeOfObject = Object.prototype.toString.call(object);
|
|
11
10
|
return typeof object === 'object' ? types[typeOfObject] || 'object' : typeof object;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
const isBoolean = object => {
|
|
15
13
|
return typeof object === 'boolean';
|
|
16
14
|
};
|
|
17
|
-
|
|
18
15
|
const isExponential = value => {
|
|
19
16
|
return isNumeric(value) && value.toString().indexOf('e') !== -1;
|
|
20
17
|
};
|
|
21
|
-
|
|
22
18
|
const isDate = object => {
|
|
23
19
|
return type(object) === 'date';
|
|
24
20
|
};
|
|
25
|
-
|
|
26
21
|
const isDefined = object => {
|
|
27
22
|
return object !== null && object !== undefined;
|
|
28
23
|
};
|
|
29
|
-
|
|
30
24
|
const isFunction = object => {
|
|
31
25
|
return typeof object === 'function';
|
|
32
26
|
};
|
|
33
|
-
|
|
34
27
|
const isString = object => {
|
|
35
28
|
return typeof object === 'string';
|
|
36
29
|
};
|
|
37
|
-
|
|
38
30
|
const isNumeric = object => {
|
|
39
31
|
return typeof object === 'number' && isFinite(object) || !isNaN(object - parseFloat(object));
|
|
40
32
|
};
|
|
41
|
-
|
|
42
33
|
const isObject = object => {
|
|
43
34
|
return type(object) === 'object';
|
|
44
35
|
};
|
|
45
|
-
|
|
46
36
|
const isEmptyObject = object => {
|
|
47
37
|
let property;
|
|
48
|
-
|
|
49
38
|
for (property in object) {
|
|
50
39
|
return false;
|
|
51
40
|
}
|
|
52
|
-
|
|
53
41
|
return true;
|
|
54
42
|
};
|
|
55
|
-
|
|
56
43
|
const isPlainObject = object => {
|
|
57
44
|
if (!object || Object.prototype.toString.call(object) !== '[object Object]') {
|
|
58
45
|
return false;
|
|
59
46
|
}
|
|
60
|
-
|
|
61
47
|
const proto = Object.getPrototypeOf(object);
|
|
62
48
|
const ctor = Object.hasOwnProperty.call(proto, 'constructor') && proto.constructor;
|
|
63
49
|
return typeof ctor === 'function' && Object.toString.call(ctor) === Object.toString.call(Object);
|
|
64
50
|
};
|
|
65
|
-
|
|
66
51
|
const isPrimitive = value => {
|
|
67
52
|
return ['object', 'array', 'function'].indexOf(type(value)) === -1;
|
|
68
53
|
};
|
|
69
|
-
|
|
70
54
|
const isWindow = object => {
|
|
71
55
|
return object != null && object === object.window;
|
|
72
56
|
};
|
|
73
|
-
|
|
74
57
|
const isRenderer = object => {
|
|
75
58
|
return !!(object.jquery || object.dxRenderer);
|
|
76
59
|
};
|
|
77
|
-
|
|
78
60
|
const isPromise = object => {
|
|
79
61
|
return object && isFunction(object.then);
|
|
80
62
|
};
|
|
81
|
-
|
|
82
63
|
const isDeferred = object => {
|
|
83
64
|
return object && isFunction(object.done) && isFunction(object.fail);
|
|
84
65
|
};
|
|
85
|
-
|
|
86
66
|
const isEvent = object => {
|
|
87
67
|
return !!(object && object.preventDefault);
|
|
88
68
|
};
|
|
89
|
-
|
|
90
69
|
export { isBoolean, isExponential, isDate, isDefined, isFunction, isString, isNumeric, isObject, isEmptyObject, isPlainObject, isPrimitive, isWindow, isRenderer, isPromise, isDeferred, type, isEvent };
|
package/utils/updatePosition.js
CHANGED
|
@@ -11,8 +11,8 @@ const updatePosition = (anchorEl, transformEl, cb) => {
|
|
|
11
11
|
} = window;
|
|
12
12
|
const {
|
|
13
13
|
height: nodeHeight
|
|
14
|
-
} = transformEl.getBoundingClientRect();
|
|
15
|
-
|
|
14
|
+
} = transformEl.getBoundingClientRect();
|
|
15
|
+
// Vertical
|
|
16
16
|
if (bottom < 0 || top > innerHeight) {
|
|
17
17
|
cb === null || cb === void 0 ? void 0 : cb();
|
|
18
18
|
} else if (bottom + 4 + nodeHeight > innerHeight) {
|
|
@@ -23,14 +23,13 @@ const updatePosition = (anchorEl, transformEl, cb) => {
|
|
|
23
23
|
}
|
|
24
24
|
} else {
|
|
25
25
|
transformEl.style.top = bottom + 4 + 'px';
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
}
|
|
28
27
|
|
|
28
|
+
// Horizontal
|
|
29
29
|
if (left < 0 || right > innerWidth) {
|
|
30
30
|
cb === null || cb === void 0 ? void 0 : cb();
|
|
31
31
|
} else {
|
|
32
32
|
transformEl.style.left = left + 'px';
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
|
|
36
35
|
export default updatePosition;
|
package/utils/useDelayUnmount.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
|
|
3
2
|
const useDelayUnmount = (isMounted, delayTime) => {
|
|
4
3
|
const [show, setShow] = useState(false);
|
|
5
4
|
useEffect(() => {
|
|
6
5
|
let timeoutId;
|
|
7
|
-
|
|
8
6
|
if (isMounted && !show) {
|
|
9
7
|
setShow(true);
|
|
10
8
|
} else if (!isMounted && show) {
|
|
11
9
|
timeoutId = setTimeout(() => setShow(false), delayTime);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return () => clearTimeout(timeoutId);
|
|
15
12
|
}, [isMounted, delayTime, show]);
|
|
16
13
|
return show;
|
|
17
14
|
};
|
|
18
|
-
|
|
19
15
|
export default useDelayUnmount;
|
package/utils/useElementSize.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { useCallback, useLayoutEffect, useState } from 'react';
|
|
2
|
-
import { useEventListener } from './useEventListener';
|
|
2
|
+
import { useEventListener } from './useEventListener';
|
|
3
|
+
|
|
4
|
+
// Usage:
|
|
3
5
|
// export const Component = () => {
|
|
4
6
|
// const [isVisible, setVisible] = useState(true);
|
|
5
7
|
// const [squareRef, { width, height }] = useElementSize();
|
|
8
|
+
|
|
6
9
|
// const toggleVisibility = () => setVisible(x => !x);
|
|
10
|
+
|
|
7
11
|
// return (
|
|
8
12
|
// <>
|
|
9
13
|
// <p>{`The square width is ${width}px and height ${height}px`}</p>
|
|
10
14
|
// <p>Try, resize your window and-or click on the button.</p>
|
|
15
|
+
|
|
11
16
|
// <button onClick={toggleVisibility}>{isVisible ? 'Hide' : 'Show'} square</button>
|
|
17
|
+
|
|
12
18
|
// {isVisible && (
|
|
13
19
|
// <div
|
|
14
20
|
// ref={squareRef}
|
|
@@ -32,8 +38,8 @@ export const useElementSize = () => {
|
|
|
32
38
|
const [size, setSize] = useState({
|
|
33
39
|
width: 0,
|
|
34
40
|
height: 0
|
|
35
|
-
});
|
|
36
|
-
|
|
41
|
+
});
|
|
42
|
+
// Prevent too many rendering using useCallback
|
|
37
43
|
const handleSize = useCallback(() => {
|
|
38
44
|
setSize({
|
|
39
45
|
width: (ref === null || ref === void 0 ? void 0 : ref.offsetWidth) || 0,
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
// Usage:
|
|
2
4
|
// export const Component = () => {
|
|
3
5
|
// // Define button ref
|
|
4
6
|
// const buttonRef = useRef < HTMLButtonElement > null;
|
|
7
|
+
|
|
5
8
|
// const onScroll = (event: Event) => {
|
|
6
9
|
// console.log("window scrolled!", event);
|
|
7
10
|
// };
|
|
11
|
+
|
|
8
12
|
// const onClick = (event: Event) => {
|
|
9
13
|
// console.log("button clicked!", event);
|
|
10
14
|
// };
|
|
15
|
+
|
|
11
16
|
// // example with window based event
|
|
12
17
|
// useEventListener("scroll", onScroll);
|
|
18
|
+
|
|
13
19
|
// // example with element based event
|
|
14
20
|
// useEventListener("click", onClick, buttonRef);
|
|
21
|
+
|
|
15
22
|
// return (
|
|
16
23
|
// <div style={{ minHeight: "200vh" }}>
|
|
17
24
|
// <button ref={buttonRef}>Click me</button>
|
|
@@ -28,16 +35,15 @@ export const useEventListener = (eventName, handler, element) => {
|
|
|
28
35
|
useEffect(() => {
|
|
29
36
|
// Define the listening target
|
|
30
37
|
const targetElement = (element === null || element === void 0 ? void 0 : element.current) || window;
|
|
31
|
-
|
|
32
38
|
if (!(targetElement && targetElement.addEventListener)) {
|
|
33
39
|
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
40
|
+
}
|
|
36
41
|
|
|
42
|
+
// Create event listener that calls handler function stored in ref
|
|
37
43
|
const eventListener = event => savedHandler.current(event);
|
|
44
|
+
targetElement.addEventListener(eventName, eventListener);
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
// Remove event listener on cleanup
|
|
41
47
|
return () => {
|
|
42
48
|
targetElement.removeEventListener(eventName, eventListener);
|
|
43
49
|
};
|
package/utils/useInput.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
|
|
3
2
|
const useInput = (defaultValue, valueProp, onChange, onInput, delayOnChange) => {
|
|
4
3
|
const [value, setValue] = useState(defaultValue || valueProp);
|
|
5
4
|
const timer = useRef(null);
|
|
@@ -7,24 +6,20 @@ const useInput = (defaultValue, valueProp, onChange, onInput, delayOnChange) =>
|
|
|
7
6
|
useEffect(() => {
|
|
8
7
|
setValue(valueProp);
|
|
9
8
|
}, [valueProp]);
|
|
10
|
-
|
|
11
9
|
const _onChange = e => {
|
|
12
10
|
e.persist();
|
|
13
11
|
if (timer.current) clearTimeout(timer.current);
|
|
14
12
|
timer.current = setTimeout(() => {
|
|
15
13
|
const valueInput = e.target.value || e.value;
|
|
16
14
|
setValue(valueInput);
|
|
17
|
-
|
|
18
15
|
e.reset = () => {
|
|
19
16
|
setValue(valueProp);
|
|
20
17
|
e.target.value = valueProp;
|
|
21
18
|
onInput === null || onInput === void 0 ? void 0 : onInput(e);
|
|
22
19
|
};
|
|
23
|
-
|
|
24
20
|
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
25
21
|
}, delayOnChange);
|
|
26
22
|
};
|
|
27
|
-
|
|
28
23
|
return {
|
|
29
24
|
value,
|
|
30
25
|
setValue,
|
|
@@ -35,5 +30,4 @@ const useInput = (defaultValue, valueProp, onChange, onInput, delayOnChange) =>
|
|
|
35
30
|
}
|
|
36
31
|
};
|
|
37
32
|
};
|
|
38
|
-
|
|
39
33
|
export default useInput;
|
package/utils/useMediaQuery.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
// Usage:
|
|
2
4
|
// export default function Component() {
|
|
3
5
|
// const matches = useMediaQuery('(min-width: 768px)');
|
|
4
6
|
// return <div>{`The view port is ${matches ? 'at least' : 'less than'} 768 pixels wide`}</div>;
|
|
@@ -10,28 +12,25 @@ const useMediaQuery = query => {
|
|
|
10
12
|
if (typeof window !== 'undefined') {
|
|
11
13
|
return window.matchMedia(query).matches;
|
|
12
14
|
}
|
|
13
|
-
|
|
14
15
|
return false;
|
|
15
16
|
};
|
|
16
|
-
|
|
17
17
|
const [matches, setMatches] = useState(getMatches(query));
|
|
18
|
-
|
|
19
18
|
const handleChange = () => {
|
|
20
19
|
setMatches(getMatches(query));
|
|
21
20
|
};
|
|
22
|
-
|
|
23
21
|
useEffect(() => {
|
|
24
|
-
const matchMedia = window.matchMedia(query);
|
|
22
|
+
const matchMedia = window.matchMedia(query);
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// Triggered at the first client-side load and if query changes
|
|
25
|
+
handleChange();
|
|
28
26
|
|
|
27
|
+
// Listen matchMedia
|
|
28
|
+
// TODO: Use `addEventListener` once support for Safari < 14 is dropped
|
|
29
29
|
if (matchMedia.addListener) {
|
|
30
30
|
matchMedia.addListener(handleChange);
|
|
31
31
|
} else {
|
|
32
32
|
matchMedia.addEventListener('change', handleChange);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
34
|
return () => {
|
|
36
35
|
if (matchMedia.removeListener) {
|
|
37
36
|
matchMedia.removeListener(handleChange);
|
|
@@ -42,5 +41,4 @@ const useMediaQuery = query => {
|
|
|
42
41
|
}, [query]);
|
|
43
42
|
return matches;
|
|
44
43
|
};
|
|
45
|
-
|
|
46
44
|
export default useMediaQuery;
|
|
@@ -9,10 +9,8 @@ export default function useOnClickOutside(ref, handler) {
|
|
|
9
9
|
if (!ref.current || ref.current.contains(event.target)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
handler(event);
|
|
14
13
|
};
|
|
15
|
-
|
|
16
14
|
document.addEventListener('mousedown', listener);
|
|
17
15
|
document.addEventListener('touchstart', listener);
|
|
18
16
|
return () => {
|
package/utils/usePortal.js
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Create a element with id
|
|
4
5
|
* @param {string} id
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export const createEl = id => {
|
|
8
8
|
const createdEl = document.createElement('div');
|
|
9
9
|
createdEl.setAttribute('id', id);
|
|
10
10
|
return createdEl;
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Insert into document.body at last
|
|
14
15
|
* @param {Element} rootElem
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
17
|
export const addRootEl = rootElem => {
|
|
18
18
|
document.body.insertBefore(rootElem, document.body.lastElementChild.nextElementSibling);
|
|
19
19
|
};
|
|
20
|
+
|
|
20
21
|
/**
|
|
21
22
|
* Create a portal with id
|
|
22
23
|
* @param {string} id
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
25
|
const usePortal = id => {
|
|
26
26
|
const rootElemRef = useRef(null);
|
|
27
|
-
|
|
28
27
|
const getRootEl = () => {
|
|
29
28
|
if (!rootElemRef.current) {
|
|
30
29
|
rootElemRef.current = document.createElement('div');
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
return rootElemRef.current;
|
|
34
32
|
};
|
|
35
|
-
|
|
36
33
|
useEffect(() => {
|
|
37
34
|
const existingParent = document.querySelector(`#${id}`);
|
|
38
35
|
const parentEl = existingParent || createEl(id);
|
|
39
|
-
|
|
40
36
|
if (!existingParent) {
|
|
41
37
|
addRootEl(parentEl);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
parentEl.appendChild(rootElemRef.current);
|
|
45
40
|
return () => {
|
|
46
41
|
rootElemRef.current.remove();
|
|
47
|
-
|
|
48
42
|
if (parentEl.childNodes.length === -1) {
|
|
49
43
|
parentEl.remove();
|
|
50
44
|
}
|
|
@@ -52,5 +46,4 @@ const usePortal = id => {
|
|
|
52
46
|
}, []);
|
|
53
47
|
return getRootEl();
|
|
54
48
|
};
|
|
55
|
-
|
|
56
49
|
export default usePortal;
|