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/components/tab/tab.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { forwardRef, memo, useMemo, useContext, useRef, useImperativeHandle } from 'react';
|
|
5
4
|
import { jsx, css } from '@emotion/core';
|
|
@@ -46,51 +45,42 @@ const TabItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
46
45
|
} = useContext(TabContext);
|
|
47
46
|
const ref = useRef(null);
|
|
48
47
|
const isVertical = direction === 'vertical';
|
|
49
|
-
|
|
50
48
|
const _TabButtonCSS = TabButtonCSS(color, isVertical);
|
|
51
|
-
|
|
52
49
|
const _IndicatorCSS = IndicatorCSS(isVertical);
|
|
53
|
-
|
|
54
50
|
const _onClick = event => {
|
|
55
51
|
if (disabled) return;
|
|
56
52
|
onClick ? onClick(event, index) : setTabIndexState(index);
|
|
57
53
|
};
|
|
58
|
-
|
|
59
54
|
useImperativeHandle(reference, () => {
|
|
60
55
|
const currentRef = ref.current || {};
|
|
61
56
|
currentRef.element = ref.current;
|
|
62
|
-
const _instance = {
|
|
57
|
+
const _instance = {
|
|
58
|
+
...action
|
|
63
59
|
}; // methods
|
|
64
|
-
|
|
65
60
|
_instance.__proto__ = {}; // hidden methods
|
|
66
|
-
|
|
67
61
|
currentRef.instance = _instance;
|
|
68
62
|
return currentRef;
|
|
69
63
|
});
|
|
70
64
|
const StartIcon = useMemo(() => {
|
|
71
65
|
let node = startIcon;
|
|
72
|
-
|
|
73
66
|
if (typeof node === 'string') {
|
|
74
67
|
node = jsx(Icon, {
|
|
75
68
|
color: 'currentColor',
|
|
76
69
|
name: startIcon
|
|
77
70
|
});
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
return jsx("span", {
|
|
81
73
|
css: ButtonIconCSS
|
|
82
74
|
}, " ", node, " ");
|
|
83
75
|
}, [startIcon]);
|
|
84
76
|
const EndIcon = useMemo(() => {
|
|
85
77
|
let node = endIcon;
|
|
86
|
-
|
|
87
78
|
if (typeof node === 'string') {
|
|
88
79
|
node = jsx(Icon, {
|
|
89
80
|
color: 'currentColor',
|
|
90
81
|
name: endIcon
|
|
91
82
|
});
|
|
92
83
|
}
|
|
93
|
-
|
|
94
84
|
return jsx("span", {
|
|
95
85
|
css: ButtonIconCSS,
|
|
96
86
|
className: 'end-icon'
|
|
@@ -104,7 +94,8 @@ const TabItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
104
94
|
style: style,
|
|
105
95
|
onClick: _onClick,
|
|
106
96
|
...props
|
|
107
|
-
}, startIcon && StartIcon, jsx(Typography, {
|
|
97
|
+
}, startIcon && StartIcon, jsx(Typography, {
|
|
98
|
+
...labelProps,
|
|
108
99
|
type: level,
|
|
109
100
|
color: 'inherit'
|
|
110
101
|
}, label), children, endIcon && EndIcon, jsx(Ripple, null), jsx("span", {
|
|
@@ -113,7 +104,6 @@ const TabItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
113
104
|
}));
|
|
114
105
|
}, [children, className, color, disabled, endIcon, index, label, level, onClick, props, startIcon, style, isVertical, tabIndexState]);
|
|
115
106
|
}));
|
|
116
|
-
|
|
117
107
|
const TabButtonCSS = (color, isVertical) => css`
|
|
118
108
|
${flexRow};
|
|
119
109
|
${overflowHidden};
|
|
@@ -160,7 +150,6 @@ const TabButtonCSS = (color, isVertical) => css`
|
|
|
160
150
|
}
|
|
161
151
|
}
|
|
162
152
|
`;
|
|
163
|
-
|
|
164
153
|
const IndicatorCSS = isVertical => css`
|
|
165
154
|
${positionAbsolute};
|
|
166
155
|
height: ${isVertical ? '100%' : '4px'};
|
|
@@ -171,7 +160,6 @@ const IndicatorCSS = isVertical => css`
|
|
|
171
160
|
transition: transform 0.2s ease-in-out;
|
|
172
161
|
border-radius: 1px;
|
|
173
162
|
`;
|
|
174
|
-
|
|
175
163
|
const ButtonIconCSS = css`
|
|
176
164
|
${flexRow};
|
|
177
165
|
${alignCenter};
|
|
@@ -195,40 +183,28 @@ TabItem.defaultProps = {
|
|
|
195
183
|
TabItem.propTypes = {
|
|
196
184
|
/** Element to display in Tabs (like label). */
|
|
197
185
|
children: PropTypes.node,
|
|
198
|
-
|
|
199
186
|
/** Class for component. */
|
|
200
187
|
className: PropTypes.string,
|
|
201
|
-
|
|
202
188
|
/** Color for Tabs. */
|
|
203
189
|
color: PropTypes.string,
|
|
204
|
-
|
|
205
190
|
/** If true, the component is disabled. */
|
|
206
191
|
disabled: PropTypes.bool,
|
|
207
|
-
|
|
208
192
|
/** Icon to the right of the button. */
|
|
209
193
|
endIcon: PropTypes.node,
|
|
210
|
-
|
|
211
194
|
/** Index received in position of TabHeaderButton. */
|
|
212
195
|
index: PropTypes.number,
|
|
213
|
-
|
|
214
196
|
/** Data string, if any. */
|
|
215
197
|
label: PropTypes.string,
|
|
216
|
-
|
|
217
198
|
/** [Props](https://core.diginet.com.vn/ui/?path=/docs/typography--title) applied to the `Typography` label. */
|
|
218
199
|
labelProps: PropTypes.object,
|
|
219
|
-
|
|
220
200
|
/** Callback fired when a "click" event is detected. */
|
|
221
201
|
onClick: PropTypes.func,
|
|
222
|
-
|
|
223
202
|
/** Icon to the left of the button. */
|
|
224
203
|
startIcon: PropTypes.node,
|
|
225
|
-
|
|
226
204
|
/** Style inline of component. */
|
|
227
205
|
style: PropTypes.object,
|
|
228
|
-
|
|
229
206
|
/** Any props else. */
|
|
230
207
|
props: PropTypes.any,
|
|
231
|
-
|
|
232
208
|
/**
|
|
233
209
|
* Ref methods.
|
|
234
210
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { forwardRef, memo, useEffect, useRef, useState, useMemo, useImperativeHandle } from 'react';
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
@@ -37,32 +36,24 @@ const hiddenPositions = {
|
|
|
37
36
|
top: '-10000000px'
|
|
38
37
|
}
|
|
39
38
|
};
|
|
40
|
-
|
|
41
39
|
const getScrollTop = () => {
|
|
42
40
|
var _ref, _ref2, _window$pageYOffset;
|
|
43
|
-
|
|
44
41
|
return (_ref = (_ref2 = (_window$pageYOffset = window.pageYOffset) !== null && _window$pageYOffset !== void 0 ? _window$pageYOffset : document.documentElement.scrollTop) !== null && _ref2 !== void 0 ? _ref2 : document.body.scrollTop) !== null && _ref !== void 0 ? _ref : 0;
|
|
45
42
|
};
|
|
46
|
-
|
|
47
43
|
const getScrollLeft = () => {
|
|
48
44
|
var _ref3, _ref4, _window$pageXOffset;
|
|
49
|
-
|
|
50
45
|
return (_ref3 = (_ref4 = (_window$pageXOffset = window.pageXOffset) !== null && _window$pageXOffset !== void 0 ? _window$pageXOffset : document.documentElement.scrollLeft) !== null && _ref4 !== void 0 ? _ref4 : document.body.scrollLeft) !== null && _ref3 !== void 0 ? _ref3 : 0;
|
|
51
46
|
};
|
|
52
|
-
|
|
53
47
|
const getArrowSpacing = (arrow, arrowSize, distance) => {
|
|
54
48
|
const defaultArrowSpacing = arrow ? arrowSize : 0;
|
|
55
49
|
return typeof distance === 'number' ? distance : defaultArrowSpacing;
|
|
56
50
|
};
|
|
57
|
-
|
|
58
51
|
const parseAlignMode = alignMode => {
|
|
59
52
|
if (alignMode.split('-').length > 1) {
|
|
60
53
|
return alignMode.split('-')[1];
|
|
61
54
|
}
|
|
62
|
-
|
|
63
55
|
return 'middle';
|
|
64
56
|
};
|
|
65
|
-
|
|
66
57
|
const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
67
58
|
action = {},
|
|
68
59
|
alignMode,
|
|
@@ -102,9 +93,7 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
102
93
|
const calculateTimeoutRef = useRef(null);
|
|
103
94
|
const hoverTimeoutRef = useRef(null);
|
|
104
95
|
const [open, setOpen] = useState(false);
|
|
105
|
-
|
|
106
96
|
const _MainCSS = MainCSS(backgroundColor, color, size, padding, textAlign);
|
|
107
|
-
|
|
108
97
|
const checkHorizontal = (distance, el, parent) => {
|
|
109
98
|
const {
|
|
110
99
|
left,
|
|
@@ -114,7 +103,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
114
103
|
const deadSpace = Math.min(left, clientW - right);
|
|
115
104
|
return el.offsetWidth + parent.offsetWidth + distance + viewportPadding + deadSpace < clientW;
|
|
116
105
|
};
|
|
117
|
-
|
|
118
106
|
const checkParent = (el, parent) => {
|
|
119
107
|
const {
|
|
120
108
|
bottom,
|
|
@@ -122,11 +110,9 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
122
110
|
} = parent.getBoundingClientRect();
|
|
123
111
|
const bottomOverhang = bottom > window.innerHeight;
|
|
124
112
|
const topOverhang = top < 0;
|
|
125
|
-
|
|
126
113
|
if (topOverhang && bottomOverhang) {
|
|
127
114
|
return true;
|
|
128
115
|
}
|
|
129
|
-
|
|
130
116
|
if (parent.offsetHeight > el.offsetHeight) {
|
|
131
117
|
const halfTargetHeight = parent.offsetHeight / 2;
|
|
132
118
|
const arrowFree = arrowSize + 6;
|
|
@@ -136,21 +122,17 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
136
122
|
const centerToTop = halfTargetHeight - tOAmount;
|
|
137
123
|
return centerToBottom >= arrowFree && centerToTop >= arrowFree;
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
return !bottomOverhang && !topOverhang;
|
|
141
126
|
};
|
|
142
|
-
|
|
143
127
|
const checkArrowOverhang = arrowStyles => {
|
|
144
128
|
const scrollLeft = getScrollLeft();
|
|
145
129
|
const enoughLeft = arrowStyles.position.left - scrollLeft > viewportPadding;
|
|
146
130
|
const enoughRight = arrowStyles.position.left + arrowSize * 2 < scrollLeft + document.documentElement.clientWidth - viewportPadding;
|
|
147
131
|
return !enoughLeft || !enoughRight;
|
|
148
132
|
};
|
|
149
|
-
|
|
150
133
|
const getTooltipMaxWidth = () => {
|
|
151
134
|
return tooltipMaxWidth ? tooltipMaxWidth : typeof document !== 'undefined' ? document.documentElement.clientWidth - viewportPadding * 2 : 300;
|
|
152
135
|
};
|
|
153
|
-
|
|
154
136
|
const getArrowStyles = (direction, el, parent) => {
|
|
155
137
|
if (!parent || !arrow) {
|
|
156
138
|
return {
|
|
@@ -160,7 +142,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
160
142
|
}
|
|
161
143
|
};
|
|
162
144
|
}
|
|
163
|
-
|
|
164
145
|
const parentRect = parent.getBoundingClientRect();
|
|
165
146
|
const halfParentH = parent.offsetHeight / 2;
|
|
166
147
|
const halfParentW = parent.offsetWidth / 2;
|
|
@@ -169,7 +150,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
169
150
|
const arrowSpacing = getArrowSpacing(arrow, arrowSize, distance);
|
|
170
151
|
const border = {};
|
|
171
152
|
const position = {};
|
|
172
|
-
|
|
173
153
|
switch (direction) {
|
|
174
154
|
case 'right':
|
|
175
155
|
border.borderLeft = `${arrowSize}px solid transparent`;
|
|
@@ -179,7 +159,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
179
159
|
position.top = el ? parentRect.top + scrollTop + halfParentH - arrowSize - 1 : '-10000000px';
|
|
180
160
|
position.left = parentRect.right + scrollLeft - arrowSize + 1;
|
|
181
161
|
break;
|
|
182
|
-
|
|
183
162
|
case 'left':
|
|
184
163
|
border.borderRight = `${arrowSize}px solid transparent`;
|
|
185
164
|
border.borderTop = `${arrowSize}px solid transparent`;
|
|
@@ -188,7 +167,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
188
167
|
position.top = el ? parentRect.top + scrollTop + halfParentH - arrowSize - 1 : '-10000000px';
|
|
189
168
|
position.left = parentRect.left + scrollLeft - arrowSpacing - 1;
|
|
190
169
|
break;
|
|
191
|
-
|
|
192
170
|
case 'up':
|
|
193
171
|
border.borderBottom = `${arrowSize}px solid transparent`;
|
|
194
172
|
border.borderLeft = `${arrowSize}px solid transparent`;
|
|
@@ -197,7 +175,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
197
175
|
position.left = el ? parentRect.left + scrollLeft + halfParentW - arrowSize : '-10000000px';
|
|
198
176
|
position.top = parentRect.top + scrollTop - arrowSpacing;
|
|
199
177
|
break;
|
|
200
|
-
|
|
201
178
|
case 'down':
|
|
202
179
|
default:
|
|
203
180
|
border.borderUp = `${arrowSize}px solid transparent`;
|
|
@@ -208,18 +185,15 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
208
185
|
position.top = parentRect.bottom + scrollTop + arrowSpacing + 1 - arrowSize;
|
|
209
186
|
break;
|
|
210
187
|
}
|
|
211
|
-
|
|
212
188
|
return {
|
|
213
189
|
border,
|
|
214
190
|
position
|
|
215
191
|
};
|
|
216
192
|
};
|
|
217
|
-
|
|
218
193
|
const getDirection = (arrowStyles, currentDirection, el, parent, recursive) => {
|
|
219
194
|
if (!parent) {
|
|
220
195
|
return currentDirection;
|
|
221
196
|
}
|
|
222
|
-
|
|
223
197
|
const clientW = document.documentElement.clientWidth;
|
|
224
198
|
const parentRect = parent.getBoundingClientRect();
|
|
225
199
|
const arrowSpacing = getArrowSpacing(arrow, arrowSize, distance);
|
|
@@ -228,72 +202,56 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
228
202
|
const spaceAbove = parentRect.top;
|
|
229
203
|
const enoughBelow = spaceBelow >= wrapperHeight;
|
|
230
204
|
const enoughAbove = spaceAbove >= wrapperHeight;
|
|
231
|
-
|
|
232
205
|
switch (currentDirection) {
|
|
233
206
|
case 'right':
|
|
234
207
|
if (!checkHorizontal(arrowSpacing, el, parent) || !checkParent(el, parent)) {
|
|
235
208
|
return getDirection(arrowStyles, 'down', el, parent, true);
|
|
236
209
|
}
|
|
237
|
-
|
|
238
210
|
if (clientW - parentRect.right < el.offsetWidth + arrowSpacing + viewportPadding) {
|
|
239
211
|
return 'left';
|
|
240
212
|
}
|
|
241
|
-
|
|
242
213
|
return 'right';
|
|
243
|
-
|
|
244
214
|
case 'left':
|
|
245
215
|
if (!checkHorizontal(arrowSpacing, el, parent) || !checkParent(el, parent)) {
|
|
246
216
|
return getDirection(arrowStyles, 'down', el, parent, true);
|
|
247
217
|
}
|
|
248
|
-
|
|
249
218
|
if (parentRect.left < el.offsetWidth + arrowSpacing + viewportPadding) {
|
|
250
219
|
return 'right';
|
|
251
220
|
}
|
|
252
|
-
|
|
253
221
|
return 'left';
|
|
254
|
-
|
|
255
222
|
case 'up':
|
|
256
223
|
if (!recursive && arrowStyles && checkArrowOverhang(arrowStyles)) {
|
|
257
224
|
return getDirection(arrowStyles, 'left', el, parent, true);
|
|
258
225
|
}
|
|
259
|
-
|
|
260
226
|
if (!enoughAbove) {
|
|
261
227
|
if (enoughBelow) {
|
|
262
228
|
return 'down';
|
|
263
229
|
}
|
|
264
|
-
|
|
265
230
|
if (!recursive && arrowStyles && checkHorizontal(arrowSpacing, el, parent)) {
|
|
266
231
|
return getDirection(arrowStyles, 'right', el, parent, true);
|
|
267
232
|
}
|
|
268
233
|
}
|
|
269
|
-
|
|
270
234
|
return 'up';
|
|
271
|
-
|
|
272
235
|
case 'down':
|
|
273
236
|
default:
|
|
274
237
|
if (!recursive && arrowStyles && checkArrowOverhang(arrowStyles)) {
|
|
275
238
|
return getDirection(arrowStyles, 'right', el, parent, true);
|
|
276
239
|
}
|
|
277
|
-
|
|
278
240
|
if (!enoughBelow) {
|
|
279
241
|
if (enoughAbove) {
|
|
280
242
|
return 'up';
|
|
281
243
|
}
|
|
282
|
-
|
|
283
244
|
if (!recursive && arrowStyles && checkHorizontal(arrowSpacing, el, parent)) {
|
|
284
245
|
return getDirection(arrowStyles, 'right', el, parent, true);
|
|
285
246
|
}
|
|
286
247
|
}
|
|
287
|
-
|
|
288
248
|
return 'down';
|
|
289
249
|
}
|
|
290
250
|
};
|
|
291
|
-
|
|
292
251
|
const getVertical = (alignMode, direction, el, parent) => {
|
|
293
252
|
let left = -10000000,
|
|
294
|
-
|
|
253
|
+
top;
|
|
295
254
|
const arrowSpacing = getArrowSpacing(arrow, arrowSize, distance);
|
|
296
|
-
|
|
297
255
|
if (el) {
|
|
298
256
|
const scrollLeft = getScrollLeft();
|
|
299
257
|
const parentRect = parent.getBoundingClientRect();
|
|
@@ -303,7 +261,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
303
261
|
const arrowCenter = parentLeft + halfParentW;
|
|
304
262
|
const arrowLeft = arrowCenter - arrowSize;
|
|
305
263
|
const arrowRight = arrowCenter + arrowSize;
|
|
306
|
-
|
|
307
264
|
if (alignMode === 'start') {
|
|
308
265
|
left = arrow ? Math.min(arrowLeft, parentLeft) : parentLeft;
|
|
309
266
|
} else if (alignMode === 'end') {
|
|
@@ -315,34 +272,28 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
315
272
|
const availableLeft = scrollLeft + viewportPadding;
|
|
316
273
|
left = Math.max(centeredLeft, availableLeft);
|
|
317
274
|
}
|
|
318
|
-
|
|
319
275
|
const rightTooltip = left + tooltipW;
|
|
320
276
|
const rightScreen = document.documentElement.clientWidth + scrollLeft - viewportPadding;
|
|
321
277
|
const rightOverhang = rightTooltip - rightScreen;
|
|
322
|
-
|
|
323
278
|
if (rightOverhang > 0) {
|
|
324
279
|
left -= rightOverhang;
|
|
325
280
|
}
|
|
326
|
-
|
|
327
281
|
if (direction === 'up') {
|
|
328
282
|
top = parentRect.top + getScrollTop() - (el.offsetHeight + arrowSpacing);
|
|
329
283
|
} else {
|
|
330
284
|
top = parentRect.bottom + getScrollTop() + arrowSpacing;
|
|
331
285
|
}
|
|
332
286
|
}
|
|
333
|
-
|
|
334
287
|
return {
|
|
335
288
|
left: left + 'px',
|
|
336
289
|
top: top + 'px'
|
|
337
290
|
};
|
|
338
291
|
};
|
|
339
|
-
|
|
340
292
|
const getHorizontal = (alignMode, direction, el, parent) => {
|
|
341
293
|
let left = -10000000,
|
|
342
|
-
|
|
294
|
+
top = 0;
|
|
343
295
|
const arrowSpacing = getArrowSpacing(arrow, arrowSize, distance);
|
|
344
296
|
const arrowPadding = arrow ? 6 : 0;
|
|
345
|
-
|
|
346
297
|
if (el) {
|
|
347
298
|
const scrollLeft = getScrollLeft();
|
|
348
299
|
const scrollTop = getScrollTop();
|
|
@@ -351,7 +302,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
351
302
|
const halfParentH = parent.offsetHeight / 2;
|
|
352
303
|
const arrowTop = parentTop + halfParentH - arrowSize;
|
|
353
304
|
const arrowBottom = parentRect.top + scrollTop + halfParentH + arrowSize;
|
|
354
|
-
|
|
355
305
|
if (alignMode === 'start') {
|
|
356
306
|
top = arrow ? Math.min(parentTop, arrowTop) : parentTop;
|
|
357
307
|
} else if (alignMode === 'end') {
|
|
@@ -361,56 +311,48 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
361
311
|
const centeredTop = Math.max(parentTop + halfParentH - el.offsetHeight / 2, scrollTop + viewportPadding);
|
|
362
312
|
top = Math.min(centeredTop, arrowTop - arrowPadding);
|
|
363
313
|
}
|
|
364
|
-
|
|
365
314
|
const bottomOverhang = top - scrollTop + el.offsetHeight + viewportPadding - window.innerHeight;
|
|
366
|
-
|
|
367
315
|
if (bottomOverhang > 0) {
|
|
368
316
|
top = Math.max(top - bottomOverhang, arrowBottom + arrowPadding - el.offsetHeight);
|
|
369
317
|
}
|
|
370
|
-
|
|
371
318
|
if (direction === 'right') {
|
|
372
319
|
left = parentRect.right + arrowSpacing + scrollLeft;
|
|
373
320
|
} else {
|
|
374
321
|
left = parentRect.left - arrowSpacing - el.offsetWidth + scrollLeft;
|
|
375
322
|
}
|
|
376
323
|
}
|
|
377
|
-
|
|
378
324
|
return {
|
|
379
325
|
left: left + 'px',
|
|
380
326
|
top: top + 'px'
|
|
381
327
|
};
|
|
382
328
|
};
|
|
383
|
-
|
|
384
329
|
const getPosition = (el, parent) => {
|
|
385
330
|
const align = parseAlignMode(alignMode);
|
|
386
331
|
let trueDirection = direction;
|
|
387
332
|
const maxWidth = getTooltipMaxWidth() + 'px';
|
|
388
333
|
let tooltipPosition, width;
|
|
389
|
-
|
|
390
334
|
if (!forceDirection && el) {
|
|
391
335
|
const arrowStylesForGetDirection = arrow && getArrowStyles(direction, el, parent);
|
|
392
336
|
trueDirection = getDirection(arrowStylesForGetDirection, trueDirection, el, parent, false);
|
|
393
337
|
}
|
|
394
|
-
|
|
395
338
|
if (el) {
|
|
396
339
|
const space = el.style.width ? 0 : 5;
|
|
397
340
|
width = Math.min(el.offsetWidth, parseInt(maxWidth)) + space + 'px';
|
|
398
341
|
tooltipPosition = trueDirection === 'up' || trueDirection === 'down' ? getVertical(align, trueDirection, el, parent) : getHorizontal(align, trueDirection, el, parent);
|
|
399
342
|
}
|
|
400
|
-
|
|
401
343
|
return {
|
|
402
|
-
tooltip: {
|
|
344
|
+
tooltip: {
|
|
345
|
+
...tooltipPosition,
|
|
403
346
|
maxWidth,
|
|
404
347
|
width
|
|
405
348
|
},
|
|
406
349
|
arrow: getArrowStyles(trueDirection, el, parent)
|
|
407
350
|
};
|
|
408
351
|
};
|
|
409
|
-
|
|
410
352
|
const onShowTooltip = (arrow, parent) => {
|
|
411
353
|
if (!tooltipRef.current || !arrowRef.current) return;
|
|
412
354
|
const arrowEl = arrowRef.current,
|
|
413
|
-
|
|
355
|
+
el = tooltipRef.current;
|
|
414
356
|
let positions;
|
|
415
357
|
clearTimeout(calculateTimeoutRef.current);
|
|
416
358
|
calculateTimeoutRef.current = setTimeout(() => {
|
|
@@ -421,7 +363,6 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
421
363
|
Object.assign(el.style, positions.tooltip, {
|
|
422
364
|
opacity: 1
|
|
423
365
|
});
|
|
424
|
-
|
|
425
366
|
if (arrow) {
|
|
426
367
|
Object.assign(arrowEl.style, positions.arrow.border, {
|
|
427
368
|
opacity: 1
|
|
@@ -433,27 +374,23 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
433
374
|
}
|
|
434
375
|
}, hoverDelay);
|
|
435
376
|
};
|
|
436
|
-
|
|
437
377
|
const onHideTooltip = () => {
|
|
438
378
|
if (!tooltipRef.current || !arrowRef.current) return;
|
|
439
379
|
const arrowEl = arrowRef.current,
|
|
440
|
-
|
|
380
|
+
el = tooltipRef.current;
|
|
441
381
|
clearTimeout(hoverTimeoutRef.current);
|
|
442
382
|
hoverTimeoutRef.current = setTimeout(() => {
|
|
443
383
|
Object.assign(el.style, hiddenPositions.tooltip);
|
|
444
384
|
Object.assign(arrowEl.style, hiddenPositions.arrow);
|
|
445
385
|
}, hoverDelay);
|
|
446
386
|
};
|
|
447
|
-
|
|
448
387
|
const setOpenTrue = () => {
|
|
449
388
|
if (disabled) return;
|
|
450
389
|
setOpen(true);
|
|
451
390
|
};
|
|
452
|
-
|
|
453
391
|
const setOpenFalse = () => {
|
|
454
392
|
setOpen(false);
|
|
455
393
|
};
|
|
456
|
-
|
|
457
394
|
useEffect(() => {
|
|
458
395
|
if (open) {
|
|
459
396
|
onShowTooltip(arrow, ref.current);
|
|
@@ -464,11 +401,10 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
464
401
|
useImperativeHandle(reference, () => {
|
|
465
402
|
const currentRef = ref.current || {};
|
|
466
403
|
currentRef.element = ref.current;
|
|
467
|
-
const _instance = {
|
|
404
|
+
const _instance = {
|
|
405
|
+
...action
|
|
468
406
|
}; // methods
|
|
469
|
-
|
|
470
407
|
_instance.__proto__ = {}; // hidden methods
|
|
471
|
-
|
|
472
408
|
currentRef.instance = _instance;
|
|
473
409
|
return currentRef;
|
|
474
410
|
});
|
|
@@ -481,18 +417,19 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
481
417
|
className: IDs.arrow,
|
|
482
418
|
css: ArrowCSS,
|
|
483
419
|
ref: arrowRef,
|
|
484
|
-
style: {
|
|
420
|
+
style: {
|
|
421
|
+
...hiddenPositions.arrow
|
|
485
422
|
}
|
|
486
423
|
}), jsx("span", {
|
|
487
424
|
className: classNames(IDs.main, className),
|
|
488
425
|
css: _MainCSS,
|
|
489
426
|
ref: tooltipRef,
|
|
490
|
-
style: {
|
|
427
|
+
style: {
|
|
428
|
+
...hiddenPositions.tooltip
|
|
491
429
|
}
|
|
492
430
|
}, title));
|
|
493
431
|
return /*#__PURE__*/createPortal(node, document.body);
|
|
494
432
|
}
|
|
495
|
-
|
|
496
433
|
return null;
|
|
497
434
|
}, [backgroundColor, className, color, disableInteractive, hoverDelay, padding, size, textAlign, title, open]);
|
|
498
435
|
return jsx(TagCreatedName, {
|
|
@@ -514,7 +451,6 @@ const ArrowCSS = css`
|
|
|
514
451
|
transition: opacity 0.1s ease-in-out;
|
|
515
452
|
z-index: ${zIndexCORE(5)};
|
|
516
453
|
`;
|
|
517
|
-
|
|
518
454
|
const MainCSS = (backgroundColor, color, size, padding, textAlign) => css`
|
|
519
455
|
${displayInlineBlock};
|
|
520
456
|
${borderBox};
|
|
@@ -531,7 +467,6 @@ const MainCSS = (backgroundColor, color, size, padding, textAlign) => css`
|
|
|
531
467
|
${breakWord};
|
|
532
468
|
z-index: ${zIndexCORE(4)};
|
|
533
469
|
`;
|
|
534
|
-
|
|
535
470
|
Tooltip.defaultProps = {
|
|
536
471
|
alignMode: 'middle',
|
|
537
472
|
arrow: false,
|
|
@@ -554,64 +489,44 @@ Tooltip.defaultProps = {
|
|
|
554
489
|
Tooltip.propTypes = {
|
|
555
490
|
/** alignMode use to set align-items of the tooltip*/
|
|
556
491
|
alignMode: PropTypes.oneOf(['flex-end', 'flex-start', 'middle']),
|
|
557
|
-
|
|
558
492
|
/** If true, adds an arrow to the tooltip. */
|
|
559
493
|
arrow: PropTypes.bool,
|
|
560
|
-
|
|
561
494
|
/** Size of the arrow. */
|
|
562
495
|
arrowSize: PropTypes.number,
|
|
563
|
-
|
|
564
496
|
/** Background color of the tooltip. */
|
|
565
497
|
backgroundColor: PropTypes.string,
|
|
566
|
-
|
|
567
498
|
/** Tooltip reference element. */
|
|
568
499
|
children: PropTypes.node.isRequired,
|
|
569
|
-
|
|
570
500
|
/** Class for component. */
|
|
571
501
|
className: PropTypes.string,
|
|
572
|
-
|
|
573
502
|
/** Color of the title. */
|
|
574
503
|
color: PropTypes.string,
|
|
575
|
-
|
|
576
504
|
/** Direction of the tooltip. */
|
|
577
505
|
direction: PropTypes.oneOf(['down', 'left', 'right', 'up']),
|
|
578
|
-
|
|
579
506
|
/** If `true`, the component is disabled. */
|
|
580
507
|
disabled: PropTypes.bool,
|
|
581
|
-
|
|
582
508
|
/** If `true`, makes a tooltip not interactive, i.e. it will close when the user hovers over the tooltip. */
|
|
583
509
|
disableInteractive: PropTypes.bool,
|
|
584
|
-
|
|
585
510
|
/** Distance between the tooltip and the children. */
|
|
586
511
|
distance: PropTypes.number,
|
|
587
|
-
|
|
588
512
|
/** If `true`, set the static direction of the tooltip. */
|
|
589
513
|
forceDirection: PropTypes.bool,
|
|
590
|
-
|
|
591
514
|
/** The number of milliseconds to wait before showing the tooltip. */
|
|
592
515
|
hoverDelay: PropTypes.number,
|
|
593
|
-
|
|
594
516
|
/** Padding of the title. */
|
|
595
517
|
padding: PropTypes.string,
|
|
596
|
-
|
|
597
518
|
/** The size of the title. */
|
|
598
519
|
size: PropTypes.oneOf(['small', 'medium']),
|
|
599
|
-
|
|
600
520
|
/** Style inline of component. */
|
|
601
521
|
style: PropTypes.object,
|
|
602
|
-
|
|
603
522
|
/** Tag name of the element will be created to contain the children. */
|
|
604
523
|
tagCreatedName: PropTypes.oneOf(['div', 'span']),
|
|
605
|
-
|
|
606
524
|
/** Text align of the title. */
|
|
607
525
|
textAlign: PropTypes.oneOf(['center', 'justify', 'left', 'right']),
|
|
608
|
-
|
|
609
526
|
/** The title to show in tooltip when hover. */
|
|
610
527
|
title: PropTypes.oneOfType([PropTypes.element, PropTypes.string]).isRequired,
|
|
611
|
-
|
|
612
528
|
/** Max width of the tooltip */
|
|
613
529
|
tooltipMaxWidth: PropTypes.number,
|
|
614
|
-
|
|
615
530
|
/** Padding of the viewport with the tooltip */
|
|
616
531
|
viewportPadding: PropTypes.number
|
|
617
532
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createPortal } from 'react-dom';
|
|
2
2
|
import { usePortal } from '../../utils';
|
|
3
|
-
|
|
4
3
|
const Portal = props => {
|
|
5
4
|
const {
|
|
6
5
|
children,
|
|
@@ -9,5 +8,4 @@ const Portal = props => {
|
|
|
9
8
|
const parent = usePortal(id);
|
|
10
9
|
return /*#__PURE__*/createPortal(children, parent);
|
|
11
10
|
};
|
|
12
|
-
|
|
13
11
|
export default Portal;
|