rox-react-components 0.0.44 → 0.0.46
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/dist/es/Button/Button.js +46 -1
- package/dist/es/Button/index.js +5 -1
- package/dist/es/Button/styles.js +40 -1
- package/dist/es/Card/Card.js +22 -1
- package/dist/es/Card/index.js +5 -1
- package/dist/es/Card/styles.js +18 -1
- package/dist/es/Container/Container.js +20 -1
- package/dist/es/Container/index.js +5 -1
- package/dist/es/Container/styles.js +30 -1
- package/dist/es/Loading/Inner.js +13 -1
- package/dist/es/Loading/Loading.js +67 -1
- package/dist/es/Loading/dom.js +11 -1
- package/dist/es/Loading/index.js +5 -1
- package/dist/es/Loading/styles.js +80 -1
- package/dist/es/Loading/type.js +3 -1
- package/dist/es/Popup/Popup.js +112 -1
- package/dist/es/Popup/index.js +5 -1
- package/dist/es/Popup/styles.js +138 -1
- package/dist/es/ScrollView/ScrollView.js +105 -1
- package/dist/es/ScrollView/index.js +5 -1
- package/dist/es/ScrollView/styles.js +23 -1
- package/dist/es/Swiper/Swiper.js +388 -1
- package/dist/es/Swiper/index.js +5 -1
- package/dist/es/Swiper/styles.js +48 -1
- package/dist/es/hooks/useShow.js +18 -1
- package/dist/es/index.js +9 -1
- package/dist/es/utils.js +69 -1
- package/dist/index.d.ts +4 -3
- package/dist/lib/Button/Button.js +50 -1
- package/dist/lib/Button/index.js +9 -1
- package/dist/lib/Button/styles.js +44 -1
- package/dist/lib/Card/Card.js +26 -1
- package/dist/lib/Card/index.js +9 -1
- package/dist/lib/Card/styles.js +22 -1
- package/dist/lib/Container/Container.js +24 -1
- package/dist/lib/Container/index.js +9 -1
- package/dist/lib/Container/styles.js +34 -1
- package/dist/lib/Loading/Inner.js +17 -1
- package/dist/lib/Loading/Loading.js +71 -1
- package/dist/lib/Loading/dom.js +15 -1
- package/dist/lib/Loading/index.js +9 -1
- package/dist/lib/Loading/styles.js +84 -1
- package/dist/lib/Loading/type.js +5 -1
- package/dist/lib/Popup/Popup.js +116 -1
- package/dist/lib/Popup/index.js +9 -1
- package/dist/lib/Popup/styles.js +143 -1
- package/dist/lib/ScrollView/ScrollView.js +109 -1
- package/dist/lib/ScrollView/index.js +9 -1
- package/dist/lib/ScrollView/styles.js +27 -1
- package/dist/lib/Swiper/Swiper.js +392 -1
- package/dist/lib/Swiper/index.js +9 -1
- package/dist/lib/Swiper/styles.js +52 -1
- package/dist/lib/hooks/useShow.js +22 -1
- package/dist/lib/index.js +23 -1
- package/dist/lib/utils.js +73 -1
- package/package.json +58 -58
package/dist/es/Button/Button.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import { css } from 'aphrodite/no-important';
|
|
3
|
+
import React, { useRef, useMemo, useCallback, useEffect } from 'react';
|
|
4
|
+
import styles from './styles.js';
|
|
5
|
+
|
|
6
|
+
var positions = ['relative', 'absolute', 'fixed'];
|
|
7
|
+
var Button = function (props) {
|
|
8
|
+
var children = props.children, _a = props.style, style = _a === void 0 ? {} : _a, _b = props.block, block = _b === void 0 ? false : _b, _c = props.className, className = _c === void 0 ? '' : _c, _d = props.radius, radius = _d === void 0 ? 4 : _d, _e = props.bg, bg = _e === void 0 ? 'rgba(0,0,0,.7)' : _e, _f = props.color, color = _f === void 0 ? '#ffffff' : _f, onClick = props.onClick, _g = props.wavesColor, wavesColor = _g === void 0 ? 'rgba(255,255,255,.3)' : _g, rest = __rest(props, ["children", "style", "block", "className", "radius", "bg", "color", "onClick", "wavesColor"]);
|
|
9
|
+
var pools = useRef([]);
|
|
10
|
+
var btn_ref = useRef(null);
|
|
11
|
+
var btnStyle = useMemo(function () { return (__assign(__assign({}, style), { overflow: 'hidden', borderRadius: radius + 'px', background: bg, color: color })); }, [style, radius, bg, color]);
|
|
12
|
+
var handleButtonClick = useCallback(function (event) {
|
|
13
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
14
|
+
var target = event.currentTarget;
|
|
15
|
+
var node;
|
|
16
|
+
if (pools.current.length) {
|
|
17
|
+
node = pools.current.shift();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
node = document.createElement('div');
|
|
21
|
+
node.classList.add(css(styles.ripple));
|
|
22
|
+
}
|
|
23
|
+
var rect = target.getBoundingClientRect();
|
|
24
|
+
node.style.width = node.style.height = Math.max(rect.width, rect.height) + 'px';
|
|
25
|
+
node.style.backgroundColor = wavesColor;
|
|
26
|
+
target.appendChild(node);
|
|
27
|
+
var y = event.pageY - rect.top - node.offsetHeight / 2 + 'px';
|
|
28
|
+
var x = event.pageX - rect.left - node.offsetWidth / 2 + 'px';
|
|
29
|
+
node.style.top = y;
|
|
30
|
+
node.style.left = x;
|
|
31
|
+
node.onanimationend = function () {
|
|
32
|
+
target.removeChild(node);
|
|
33
|
+
pools.current.push(node);
|
|
34
|
+
};
|
|
35
|
+
}, [onClick, wavesColor]);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
if (btn_ref.current) {
|
|
38
|
+
var style_1 = getComputedStyle(btn_ref.current);
|
|
39
|
+
if (!positions.includes(style_1.position))
|
|
40
|
+
btn_ref.current.style.position = 'relative';
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
return (React.createElement("button", __assign({}, rest, { className: "".concat(className, " ").concat(css(styles.button), " ").concat(block ? css(styles.block) : ''), style: btnStyle, ref: btn_ref, onClick: handleButtonClick }), children));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { Button as default };
|
package/dist/es/Button/index.js
CHANGED
package/dist/es/Button/styles.js
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
-
import{StyleSheet
|
|
1
|
+
import { StyleSheet } from 'aphrodite/no-important';
|
|
2
|
+
|
|
3
|
+
var rippleKey = {
|
|
4
|
+
to: {
|
|
5
|
+
opacity: 0,
|
|
6
|
+
transform: 'scale(2)',
|
|
7
|
+
'-webkit-transform': 'scale(2)',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
var styles = StyleSheet.create({
|
|
11
|
+
button: {
|
|
12
|
+
border: '1px solid transparent',
|
|
13
|
+
boxSizing: 'border-box',
|
|
14
|
+
padding: '8px 20px',
|
|
15
|
+
cursor: 'pointer',
|
|
16
|
+
outline: 'none',
|
|
17
|
+
':focus': {
|
|
18
|
+
outline: 'none',
|
|
19
|
+
},
|
|
20
|
+
':focus-within': {
|
|
21
|
+
outline: 'none',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
block: {
|
|
25
|
+
display: 'block',
|
|
26
|
+
width: '100%',
|
|
27
|
+
},
|
|
28
|
+
ripple: {
|
|
29
|
+
position: 'absolute',
|
|
30
|
+
borderRadius: '100%',
|
|
31
|
+
pointerEvents: 'none',
|
|
32
|
+
transform: 'scale(0)',
|
|
33
|
+
opacity: 1,
|
|
34
|
+
animationName: [rippleKey],
|
|
35
|
+
animationDuration: '0.4s',
|
|
36
|
+
animationTimingFunction: 'ease-out',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { styles as default };
|
package/dist/es/Card/Card.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import { css } from 'aphrodite/no-important';
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import styles from './styles.js';
|
|
5
|
+
|
|
6
|
+
var initCardProps = {
|
|
7
|
+
expand: false,
|
|
8
|
+
duration: 200,
|
|
9
|
+
};
|
|
10
|
+
var Card = function (props) {
|
|
11
|
+
var _a = __assign(__assign({}, initCardProps), props), duration = _a.duration, expand = _a.expand, children = _a.children;
|
|
12
|
+
var transitionDuration = useMemo(function () { return ({
|
|
13
|
+
transitionDuration: "".concat(duration, "ms"),
|
|
14
|
+
msTransitionDuration: "".concat(duration, "ms"),
|
|
15
|
+
MozTransitionDuration: "".concat(duration, "ms"),
|
|
16
|
+
WebkitTransitionDuration: "".concat(duration, "ms"),
|
|
17
|
+
}); }, [duration]);
|
|
18
|
+
return (React.createElement("div", { style: transitionDuration, className: "".concat(css(styles.collapse), " ").concat(expand ? css(styles.expand) : '') },
|
|
19
|
+
React.createElement("div", { className: css(styles.hide0) }, children)));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { Card as default };
|
package/dist/es/Card/index.js
CHANGED
package/dist/es/Card/styles.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import{StyleSheet
|
|
1
|
+
import { StyleSheet } from 'aphrodite/no-important';
|
|
2
|
+
|
|
3
|
+
var styles = StyleSheet.create({
|
|
4
|
+
collapse: {
|
|
5
|
+
display: 'grid',
|
|
6
|
+
gridTemplateRows: '0fr',
|
|
7
|
+
overflow: 'hidden',
|
|
8
|
+
outline: 'none'
|
|
9
|
+
},
|
|
10
|
+
expand: {
|
|
11
|
+
gridTemplateRows: '1fr',
|
|
12
|
+
},
|
|
13
|
+
hide0: {
|
|
14
|
+
minHeight: 0,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { styles as default };
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import { css } from 'aphrodite/no-important';
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import styles from './styles.js';
|
|
5
|
+
|
|
6
|
+
var initContainerProps = {
|
|
7
|
+
ratio: 1,
|
|
8
|
+
};
|
|
9
|
+
var Container = function (_props) {
|
|
10
|
+
var _a = __assign(__assign({}, initContainerProps), _props), ratio = _a.ratio, children = _a.children;
|
|
11
|
+
var pb = useMemo(function () {
|
|
12
|
+
if (ratio === undefined || ratio === null || ratio <= 0)
|
|
13
|
+
return '100%';
|
|
14
|
+
return 100 / ratio + '%';
|
|
15
|
+
}, [ratio]);
|
|
16
|
+
return (React.createElement("div", { className: css(styles.relative, styles.w_full, styles.h_0, styles.border_box), style: { paddingBottom: pb } },
|
|
17
|
+
React.createElement("div", { className: css(styles.absolute, styles.top_0, styles.left_0, styles.w_full, styles.h_full) }, children)));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { Container as default };
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
import{StyleSheet
|
|
1
|
+
import { StyleSheet } from 'aphrodite/no-important';
|
|
2
|
+
|
|
3
|
+
var styles = StyleSheet.create({
|
|
4
|
+
relative: {
|
|
5
|
+
position: 'relative',
|
|
6
|
+
},
|
|
7
|
+
absolute: {
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
},
|
|
10
|
+
top_0: {
|
|
11
|
+
top: '0px',
|
|
12
|
+
},
|
|
13
|
+
left_0: {
|
|
14
|
+
left: '0px',
|
|
15
|
+
},
|
|
16
|
+
w_full: {
|
|
17
|
+
width: '100%',
|
|
18
|
+
},
|
|
19
|
+
h_full: {
|
|
20
|
+
height: '100%',
|
|
21
|
+
},
|
|
22
|
+
h_0: {
|
|
23
|
+
height: '0px',
|
|
24
|
+
},
|
|
25
|
+
border_box: {
|
|
26
|
+
boxSizing: 'border-box',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export { styles as default };
|
package/dist/es/Loading/Inner.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import { css } from 'aphrodite/no-important';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import styles from './styles.js';
|
|
5
|
+
import { initLoadingStyle } from './type.js';
|
|
6
|
+
|
|
7
|
+
var arr = [{ delay: '0s' }, { delay: '-1.1s' }, { delay: '-1.0s' }, { delay: '-0.9s' }, { delay: '-0.8s' }];
|
|
8
|
+
var Inner = function (props) {
|
|
9
|
+
var style = __assign(__assign({}, initLoadingStyle), props.style);
|
|
10
|
+
return (React.createElement("div", { className: css(styles.inner_box), style: { '--width': style.width, '--height': style.height, '--bg': style.bg, '--margin': style.margin } }, arr.map(function (item, i) { return (React.createElement("div", { key: i, style: { '--delay': item.delay }, className: css(styles.inner_box_item) })); })));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { Inner as default };
|
|
@@ -1 +1,67 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __extends, __assign } from 'tslib';
|
|
2
|
+
import { css } from 'aphrodite/no-important';
|
|
3
|
+
import React, { Component } from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import Inner from './Inner.js';
|
|
6
|
+
import dom from './dom.js';
|
|
7
|
+
import styles from './styles.js';
|
|
8
|
+
|
|
9
|
+
var Loading = /** @class */ (function (_super) {
|
|
10
|
+
__extends(Loading, _super);
|
|
11
|
+
function Loading() {
|
|
12
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
13
|
+
_this.state = {};
|
|
14
|
+
return _this;
|
|
15
|
+
}
|
|
16
|
+
Loading.show = function (options) {
|
|
17
|
+
if (Loading.el)
|
|
18
|
+
return;
|
|
19
|
+
Loading.el = document.createElement('div');
|
|
20
|
+
dom.addClass(Loading.el, css(styles.fixed));
|
|
21
|
+
dom.addClass(document.body, css(styles.page_hide));
|
|
22
|
+
document.body.appendChild(Loading.el);
|
|
23
|
+
createRoot(Loading.el).render(React.createElement(Loading, __assign({}, options, { children: null, visible: true })));
|
|
24
|
+
};
|
|
25
|
+
Loading.hide = function () {
|
|
26
|
+
try {
|
|
27
|
+
dom.removeClass(document.body, css(styles.page_hide));
|
|
28
|
+
if (!Loading.el)
|
|
29
|
+
return;
|
|
30
|
+
document.body.removeChild(Loading.el);
|
|
31
|
+
Loading.el = null;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
dom.removeClass(document.body, css(styles.page_hide));
|
|
35
|
+
Loading.el = null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Loading.prototype.render = function () {
|
|
39
|
+
var _a = this.props, visible = _a.visible, bg = _a.bg, customLoading = _a.customLoading, loadingStyle = _a.loadingStyle, children = _a.children;
|
|
40
|
+
return (React.createElement("div", { className: css(styles.relative, styles.w_full, styles.h_full, styles.border_box) },
|
|
41
|
+
children,
|
|
42
|
+
visible ? (React.createElement("div", { className: css(styles.absolute, styles.top_0, styles.left_0, styles.w_full, styles.h_full, styles.z_99, styles.center), style: { backgroundColor: bg } }, customLoading || React.createElement(Inner, { style: loadingStyle }))) : null));
|
|
43
|
+
};
|
|
44
|
+
Loading.getDerivedStateFromProps = function (props, state) {
|
|
45
|
+
// console.log('getDerivedStateFromProps', props, state)
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
Loading.prototype.getSnapshotBeforeUpdate = function (prevProps, prevState) {
|
|
49
|
+
// console.log('getSnapshotBeforeUpdate', prevProps, prevState)
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
Loading.prototype.componentDidUpdate = function (prevProps, prevState, snapshot) { };
|
|
53
|
+
Loading.prototype.componentWillUnmount = function () {
|
|
54
|
+
// console.log('componentWillUnmount')
|
|
55
|
+
Loading.hide();
|
|
56
|
+
};
|
|
57
|
+
Loading.defaultProps = {
|
|
58
|
+
visible: true,
|
|
59
|
+
bg: 'rgba(0,0,0,.7)',
|
|
60
|
+
customLoading: null,
|
|
61
|
+
loadingStyle: {},
|
|
62
|
+
};
|
|
63
|
+
Loading.el = null;
|
|
64
|
+
return Loading;
|
|
65
|
+
}(Component));
|
|
66
|
+
|
|
67
|
+
export { Loading as default };
|
package/dist/es/Loading/dom.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
function addClass(el, cls) {
|
|
2
|
+
if (el.classList.contains(cls))
|
|
3
|
+
return;
|
|
4
|
+
el.classList.add(cls);
|
|
5
|
+
}
|
|
6
|
+
function removeClass(el, cls) {
|
|
7
|
+
el.classList.remove(cls);
|
|
8
|
+
}
|
|
9
|
+
var dom = { addClass: addClass, removeClass: removeClass };
|
|
10
|
+
|
|
11
|
+
export { dom as default };
|
package/dist/es/Loading/index.js
CHANGED
|
@@ -1 +1,80 @@
|
|
|
1
|
-
import{StyleSheet
|
|
1
|
+
import { StyleSheet } from 'aphrodite/no-important';
|
|
2
|
+
|
|
3
|
+
var keys = {
|
|
4
|
+
'0%, 40%, 100%': {
|
|
5
|
+
transform: 'scaleY(0.4)',
|
|
6
|
+
'-webkit-transform': 'scaleY(0.4)',
|
|
7
|
+
},
|
|
8
|
+
'20%': {
|
|
9
|
+
transform: 'scaleY(1.0)',
|
|
10
|
+
'-webkit-transform': 'scaleY(1.0)',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
var styles = StyleSheet.create({
|
|
14
|
+
relative: {
|
|
15
|
+
position: 'relative',
|
|
16
|
+
},
|
|
17
|
+
center: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
},
|
|
22
|
+
absolute: {
|
|
23
|
+
position: 'absolute',
|
|
24
|
+
},
|
|
25
|
+
top_0: {
|
|
26
|
+
top: '0px',
|
|
27
|
+
},
|
|
28
|
+
left_0: {
|
|
29
|
+
left: '0px',
|
|
30
|
+
},
|
|
31
|
+
w_full: {
|
|
32
|
+
width: '100%',
|
|
33
|
+
},
|
|
34
|
+
h_full: {
|
|
35
|
+
height: '100%',
|
|
36
|
+
},
|
|
37
|
+
border_box: {
|
|
38
|
+
boxSizing: 'border-box',
|
|
39
|
+
},
|
|
40
|
+
z_99: {
|
|
41
|
+
zIndex: 99,
|
|
42
|
+
},
|
|
43
|
+
inner_box: {
|
|
44
|
+
display: 'flex',
|
|
45
|
+
width: '100%',
|
|
46
|
+
height: '100%',
|
|
47
|
+
textAlign: 'center',
|
|
48
|
+
fontSize: '10px',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
},
|
|
52
|
+
inner_box_item: {
|
|
53
|
+
height: 'var(--height)',
|
|
54
|
+
width: 'var(--width)',
|
|
55
|
+
margin: 'var(--margin)',
|
|
56
|
+
backgroundColor: 'var(--bg)',
|
|
57
|
+
animationName: [keys],
|
|
58
|
+
animationDelay: 'var(--delay)',
|
|
59
|
+
animationDuration: '1.2s',
|
|
60
|
+
animationIterationCount: 'infinite',
|
|
61
|
+
},
|
|
62
|
+
fixed: {
|
|
63
|
+
position: 'fixed',
|
|
64
|
+
display: 'flex',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
justifyContent: 'center',
|
|
67
|
+
top: '0',
|
|
68
|
+
left: '0',
|
|
69
|
+
width: '100%',
|
|
70
|
+
height: '100%',
|
|
71
|
+
zIndex: 99,
|
|
72
|
+
},
|
|
73
|
+
page_hide: {
|
|
74
|
+
width: '100%',
|
|
75
|
+
height: '100%',
|
|
76
|
+
overflow: 'hidden',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export { styles as default };
|
package/dist/es/Loading/type.js
CHANGED
package/dist/es/Popup/Popup.js
CHANGED
|
@@ -1 +1,112 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import React, { useRef, useCallback, useEffect, useState, useMemo } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { css } from 'aphrodite/no-important';
|
|
5
|
+
import styles, { animateStyles } from './styles.js';
|
|
6
|
+
|
|
7
|
+
var initPopupProps = {
|
|
8
|
+
visible: false,
|
|
9
|
+
position: 'bottom',
|
|
10
|
+
duration: 200,
|
|
11
|
+
bg: 'rgba(0,0,0,.35)',
|
|
12
|
+
maskClosable: true,
|
|
13
|
+
popupType: 'fade',
|
|
14
|
+
onClose: function () { return null; },
|
|
15
|
+
contentClassName: '',
|
|
16
|
+
contentStyle: {},
|
|
17
|
+
scale: [0.2],
|
|
18
|
+
curve: 'linear'
|
|
19
|
+
};
|
|
20
|
+
function _Popup(props) {
|
|
21
|
+
var bg = props.bg, visible = props.visible, duration = props.duration, inject = props.inject, dispose = props.dispose, maskClosable = props.maskClosable, onClose = props.onClose, children = props.children, position = props.position, contentStyle = props.contentStyle, contentClassName = props.contentClassName, popupType = props.popupType, scale = props.scale, curve = props.curve;
|
|
22
|
+
var _a = useState(visible), tweenAnimation = _a[0], setTweenAnimation = _a[1];
|
|
23
|
+
var _b = useState(false), show = _b[0], setShow = _b[1];
|
|
24
|
+
useEffect(function () {
|
|
25
|
+
setTweenAnimation(visible);
|
|
26
|
+
if (visible) {
|
|
27
|
+
dispose();
|
|
28
|
+
inject();
|
|
29
|
+
setShow(true);
|
|
30
|
+
}
|
|
31
|
+
}, [visible]);
|
|
32
|
+
useEffect(function () {
|
|
33
|
+
return function () {
|
|
34
|
+
setShow(false);
|
|
35
|
+
dispose();
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
var handleMaskClick = useCallback(function () {
|
|
39
|
+
if (!maskClosable)
|
|
40
|
+
return;
|
|
41
|
+
setTweenAnimation(false);
|
|
42
|
+
}, [maskClosable]);
|
|
43
|
+
var handleAnimationEnd = useCallback(function () {
|
|
44
|
+
if (!tweenAnimation) {
|
|
45
|
+
setShow(false);
|
|
46
|
+
onClose();
|
|
47
|
+
dispose();
|
|
48
|
+
}
|
|
49
|
+
}, [tweenAnimation, onClose]);
|
|
50
|
+
var containerStyle = useMemo(function () {
|
|
51
|
+
if (position === 'bottom') {
|
|
52
|
+
return { justifyContent: 'center', alignItems: 'flex-end' };
|
|
53
|
+
}
|
|
54
|
+
if (position === 'top') {
|
|
55
|
+
return { justifyContent: 'center', alignItems: 'flex-start' };
|
|
56
|
+
}
|
|
57
|
+
if (position === 'left') {
|
|
58
|
+
return { justifyContent: 'flex-start', alignItems: 'center' };
|
|
59
|
+
}
|
|
60
|
+
if (position === 'right') {
|
|
61
|
+
return { justifyContent: 'flex-end', alignItems: 'center' };
|
|
62
|
+
}
|
|
63
|
+
if (position === 'center') {
|
|
64
|
+
return { justifyContent: 'center', alignItems: 'center' };
|
|
65
|
+
}
|
|
66
|
+
return {};
|
|
67
|
+
}, [position]);
|
|
68
|
+
var contentAnimationName = useMemo(function () {
|
|
69
|
+
if (popupType === 'slide') {
|
|
70
|
+
if (position === 'top')
|
|
71
|
+
return tweenAnimation ? styles.slide_in_top : styles.slide_out_top;
|
|
72
|
+
if (position === 'bottom')
|
|
73
|
+
return tweenAnimation ? styles.slide_in_bottom : styles.slide_out_bottom;
|
|
74
|
+
if (position === 'left')
|
|
75
|
+
return tweenAnimation ? styles.slide_in_left : styles.slide_out_left;
|
|
76
|
+
if (position === 'right')
|
|
77
|
+
return tweenAnimation ? styles.slide_in_right : styles.slide_out_right;
|
|
78
|
+
}
|
|
79
|
+
else if (popupType === 'scale') {
|
|
80
|
+
if (Array.isArray(scale) && scale.length >= 1) {
|
|
81
|
+
var styles_1 = animateStyles(scale);
|
|
82
|
+
return tweenAnimation ? styles_1.scale_in : styles_1.scale_out;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return tweenAnimation ? styles.fade_in : styles.fade_out;
|
|
86
|
+
}, [popupType, position, tweenAnimation, scale]);
|
|
87
|
+
if (!show)
|
|
88
|
+
return null;
|
|
89
|
+
return (React.createElement("div", { style: __assign({ '--bg': bg, '--duration': duration + 'ms', '--curve': curve }, containerStyle), className: css(styles.container) },
|
|
90
|
+
React.createElement("div", { onClick: handleMaskClick, onAnimationEnd: handleAnimationEnd, className: css(styles.mask, styles.animation_properties, tweenAnimation ? styles.fade_in : styles.fade_out) }),
|
|
91
|
+
React.createElement("div", { style: contentStyle, className: "".concat(contentClassName, " ").concat(css(styles.animation_properties, contentAnimationName)) }, children)));
|
|
92
|
+
}
|
|
93
|
+
function Popup(_props) {
|
|
94
|
+
var props = __assign(__assign({}, initPopupProps), _props);
|
|
95
|
+
var container = useRef(document.createElement('div'));
|
|
96
|
+
var injectBody = useCallback(function () {
|
|
97
|
+
document.body.appendChild(container.current);
|
|
98
|
+
}, []);
|
|
99
|
+
var dispose = useCallback(function () {
|
|
100
|
+
try {
|
|
101
|
+
document.body.removeChild(container.current);
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
}
|
|
105
|
+
}, []);
|
|
106
|
+
useEffect(function () {
|
|
107
|
+
return function () { return dispose(); };
|
|
108
|
+
}, []);
|
|
109
|
+
return createPortal(React.createElement(_Popup, __assign({}, props, { inject: injectBody, dispose: dispose })), container.current);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { Popup as default };
|
package/dist/es/Popup/index.js
CHANGED