clxx 2.1.2 → 2.1.4
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/LICENSE +20 -20
- package/README.md +768 -35
- package/build/Ago/index.d.ts +0 -1
- package/build/Alert/Wrapper.d.ts +0 -1
- package/build/Alert/Wrapper.js +12 -12
- package/build/Alert/index.js +2 -2
- package/build/AutoGrid/index.js +16 -21
- package/build/AutoGrid/style.d.ts +5 -5
- package/build/CarouselNotice/index.d.ts +0 -1
- package/build/CarouselNotice/index.js +6 -6
- package/build/CarouselNotice/style.d.ts +6 -1
- package/build/CarouselNotice/style.js +7 -7
- package/build/Clickable/index.d.ts +5 -5
- package/build/Clickable/index.js +11 -8
- package/build/Container/index.d.ts +2 -2
- package/build/Container/index.js +85 -60
- package/build/Countdowner/index.d.ts +3 -3
- package/build/Countdowner/index.js +18 -11
- package/build/Dialog/Wrapper.d.ts +0 -1
- package/build/Dialog/Wrapper.js +7 -10
- package/build/Dialog/style.d.ts +15 -10
- package/build/Dialog/style.js +88 -88
- package/build/Effect/useInterval.d.ts +1 -1
- package/build/Effect/useInterval.js +1 -1
- package/build/Effect/useUpdate.d.ts +1 -1
- package/build/Effect/useUpdate.js +1 -1
- package/build/Effect/useWindowResize.d.ts +4 -2
- package/build/Effect/useWindowResize.js +28 -11
- package/build/Flex/index.d.ts +0 -1
- package/build/Indicator/index.js +22 -23
- package/build/Indicator/style.d.ts +6 -1
- package/build/Indicator/style.js +7 -7
- package/build/Loading/Wrapper.js +2 -2
- package/build/Loading/style.d.ts +12 -2
- package/build/Loading/style.js +14 -14
- package/build/Overlay/index.d.ts +1 -1
- package/build/Overlay/index.js +41 -37
- package/build/SafeArea/index.d.ts +1 -2
- package/build/SafeArea/index.js +6 -6
- package/build/ScrollView/index.d.ts +1 -1
- package/build/ScrollView/index.js +111 -27
- package/build/Toast/Toast.js +4 -4
- package/build/Toast/style.d.ts +42 -12
- package/build/Toast/style.js +54 -54
- package/build/index.d.ts +3 -0
- package/build/index.js +3 -0
- package/build/utils/Countdown.d.ts +3 -1
- package/build/utils/Countdown.js +5 -2
- package/build/utils/createApp.d.ts +14 -13
- package/build/utils/createApp.js +58 -42
- package/build/utils/cssUtil.d.ts +2 -2
- package/build/utils/cssUtil.js +24 -13
- package/build/utils/defaultScroll.d.ts +0 -1
- package/build/utils/defaultScroll.js +8 -5
- package/build/utils/is.d.ts +23 -4
- package/build/utils/is.js +97 -15
- package/build/utils/jsonp.js +2 -2
- package/build/utils/request.js +12 -2
- package/package.json +15 -12
- package/test/README.md +16 -0
- package/test/eslint.config.js +29 -0
- package/test/index.html +13 -0
- package/test/jsconfig.json +8 -0
- package/test/package.json +27 -0
- package/test/public/vite.svg +1 -0
- package/test/src/ago/index.jsx +30 -0
- package/test/src/alert/index.jsx +111 -0
- package/test/src/autogrid/index.css +0 -0
- package/test/src/autogrid/index.jsx +26 -0
- package/test/src/carouse-notice/index.jsx +59 -0
- package/test/src/clickable/index.css +21 -0
- package/test/src/clickable/index.jsx +39 -0
- package/test/src/countdown/index.jsx +95 -0
- package/test/src/dialog/index.jsx +104 -0
- package/test/src/dialog/index.module.css +5 -0
- package/test/src/image-picker/index.css +0 -0
- package/test/src/image-picker/index.jsx +88 -0
- package/test/src/index/index.jsx +46 -0
- package/test/src/index.css +49 -0
- package/test/src/index.jsx +31 -0
- package/test/src/indicator/index.jsx +25 -0
- package/test/src/loading/index.jsx +36 -0
- package/test/src/overlay/index.jsx +31 -0
- package/test/src/privacy/index.css +13 -0
- package/test/src/privacy/index.jsx +34 -0
- package/test/src/scrollview/index.css +10 -0
- package/test/src/scrollview/index.jsx +52 -0
- package/test/src/toast/index.jsx +86 -0
- package/test/vite.config.js +15 -0
package/build/Dialog/style.js
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
1
|
import { css, keyframes } from "@emotion/react";
|
|
2
|
-
const maskShow = keyframes `
|
|
3
|
-
from {
|
|
4
|
-
opacity: 0;
|
|
5
|
-
}
|
|
6
|
-
to {
|
|
7
|
-
opacity: 1;
|
|
8
|
-
}
|
|
2
|
+
const maskShow = keyframes `
|
|
3
|
+
from {
|
|
4
|
+
opacity: 0;
|
|
5
|
+
}
|
|
6
|
+
to {
|
|
7
|
+
opacity: 1;
|
|
8
|
+
}
|
|
9
9
|
`;
|
|
10
|
-
export const maskHide = keyframes `
|
|
11
|
-
from {
|
|
12
|
-
opacity: 1;
|
|
13
|
-
}
|
|
14
|
-
to {
|
|
15
|
-
opacity: 0;
|
|
16
|
-
}
|
|
10
|
+
export const maskHide = keyframes `
|
|
11
|
+
from {
|
|
12
|
+
opacity: 1;
|
|
13
|
+
}
|
|
14
|
+
to {
|
|
15
|
+
opacity: 0;
|
|
16
|
+
}
|
|
17
17
|
`;
|
|
18
|
-
const pullUpShow = keyframes `
|
|
19
|
-
from {
|
|
20
|
-
transform: translateY(100%);
|
|
21
|
-
}
|
|
22
|
-
to {
|
|
23
|
-
transform: translateY(0);
|
|
24
|
-
}
|
|
18
|
+
const pullUpShow = keyframes `
|
|
19
|
+
from {
|
|
20
|
+
transform: translateY(100%);
|
|
21
|
+
}
|
|
22
|
+
to {
|
|
23
|
+
transform: translateY(0);
|
|
24
|
+
}
|
|
25
25
|
`;
|
|
26
|
-
const pullUpHide = keyframes `
|
|
27
|
-
from {
|
|
28
|
-
transform: translateY(0);
|
|
29
|
-
}
|
|
30
|
-
to {
|
|
31
|
-
transform: translateY(100%);
|
|
32
|
-
}
|
|
26
|
+
const pullUpHide = keyframes `
|
|
27
|
+
from {
|
|
28
|
+
transform: translateY(0);
|
|
29
|
+
}
|
|
30
|
+
to {
|
|
31
|
+
transform: translateY(100%);
|
|
32
|
+
}
|
|
33
33
|
`;
|
|
34
|
-
const pullDownShow = keyframes `
|
|
35
|
-
from {
|
|
36
|
-
transform: translateY(-100%);
|
|
37
|
-
}
|
|
38
|
-
to {
|
|
39
|
-
transform: translateY(0);
|
|
40
|
-
}
|
|
34
|
+
const pullDownShow = keyframes `
|
|
35
|
+
from {
|
|
36
|
+
transform: translateY(-100%);
|
|
37
|
+
}
|
|
38
|
+
to {
|
|
39
|
+
transform: translateY(0);
|
|
40
|
+
}
|
|
41
41
|
`;
|
|
42
|
-
const pullDownHide = keyframes `
|
|
43
|
-
from {
|
|
44
|
-
transform: translateY(0);
|
|
45
|
-
}
|
|
46
|
-
to {
|
|
47
|
-
transform: translateY(-100%);
|
|
48
|
-
}
|
|
42
|
+
const pullDownHide = keyframes `
|
|
43
|
+
from {
|
|
44
|
+
transform: translateY(0);
|
|
45
|
+
}
|
|
46
|
+
to {
|
|
47
|
+
transform: translateY(-100%);
|
|
48
|
+
}
|
|
49
49
|
`;
|
|
50
|
-
const pullLeftShow = keyframes `
|
|
51
|
-
from {
|
|
52
|
-
transform: translateX(100%);
|
|
53
|
-
}
|
|
54
|
-
to {
|
|
55
|
-
transform: translateX(0);
|
|
56
|
-
}
|
|
50
|
+
const pullLeftShow = keyframes `
|
|
51
|
+
from {
|
|
52
|
+
transform: translateX(100%);
|
|
53
|
+
}
|
|
54
|
+
to {
|
|
55
|
+
transform: translateX(0);
|
|
56
|
+
}
|
|
57
57
|
`;
|
|
58
|
-
const pullLeftHide = keyframes `
|
|
59
|
-
from {
|
|
60
|
-
transform: translateX(0);
|
|
61
|
-
}
|
|
62
|
-
to {
|
|
63
|
-
transform: translateX(100%);
|
|
64
|
-
}
|
|
58
|
+
const pullLeftHide = keyframes `
|
|
59
|
+
from {
|
|
60
|
+
transform: translateX(0);
|
|
61
|
+
}
|
|
62
|
+
to {
|
|
63
|
+
transform: translateX(100%);
|
|
64
|
+
}
|
|
65
65
|
`;
|
|
66
|
-
const pullRightShow = keyframes `
|
|
67
|
-
from {
|
|
68
|
-
transform: translateX(-100%);
|
|
69
|
-
}
|
|
70
|
-
to {
|
|
71
|
-
transform: translateX(0);
|
|
72
|
-
}
|
|
66
|
+
const pullRightShow = keyframes `
|
|
67
|
+
from {
|
|
68
|
+
transform: translateX(-100%);
|
|
69
|
+
}
|
|
70
|
+
to {
|
|
71
|
+
transform: translateX(0);
|
|
72
|
+
}
|
|
73
73
|
`;
|
|
74
|
-
const pullRightHide = keyframes `
|
|
75
|
-
from {
|
|
76
|
-
transform: translateX(0);
|
|
77
|
-
}
|
|
78
|
-
to {
|
|
79
|
-
transform: translateX(-100%);
|
|
80
|
-
}
|
|
74
|
+
const pullRightHide = keyframes `
|
|
75
|
+
from {
|
|
76
|
+
transform: translateX(0);
|
|
77
|
+
}
|
|
78
|
+
to {
|
|
79
|
+
transform: translateX(-100%);
|
|
80
|
+
}
|
|
81
81
|
`;
|
|
82
|
-
const centerShow = keyframes `
|
|
83
|
-
from {
|
|
84
|
-
transform: scale(0.8);
|
|
85
|
-
opacity: 0;
|
|
86
|
-
}
|
|
87
|
-
to {
|
|
88
|
-
transform: scale(1);
|
|
89
|
-
opacity: 1;
|
|
90
|
-
}
|
|
82
|
+
const centerShow = keyframes `
|
|
83
|
+
from {
|
|
84
|
+
transform: scale(0.8);
|
|
85
|
+
opacity: 0;
|
|
86
|
+
}
|
|
87
|
+
to {
|
|
88
|
+
transform: scale(1);
|
|
89
|
+
opacity: 1;
|
|
90
|
+
}
|
|
91
91
|
`;
|
|
92
|
-
const centerHide = keyframes `
|
|
93
|
-
from {
|
|
94
|
-
transform: scale(1);
|
|
95
|
-
opacity: 1;
|
|
96
|
-
}
|
|
97
|
-
to {
|
|
98
|
-
transform: scale(0.8);
|
|
99
|
-
opacity: 0;
|
|
100
|
-
}
|
|
92
|
+
const centerHide = keyframes `
|
|
93
|
+
from {
|
|
94
|
+
transform: scale(1);
|
|
95
|
+
opacity: 1;
|
|
96
|
+
}
|
|
97
|
+
to {
|
|
98
|
+
transform: scale(0.8);
|
|
99
|
+
opacity: 0;
|
|
100
|
+
}
|
|
101
101
|
`;
|
|
102
102
|
export function getAnimation(type, status) {
|
|
103
103
|
const animation = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useInterval(callback:
|
|
1
|
+
export declare function useInterval(callback: () => void, delay?: number | null): void;
|
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* 窗口尺寸变化时触发(包括屏幕旋转)
|
|
4
|
+
* 注意:移动端 resize 事件通常只在旋转屏幕时触发,频率很低,不需要防抖
|
|
5
|
+
*
|
|
6
|
+
* @param onResize 窗口尺寸变化时的回调函数
|
|
5
7
|
*/
|
|
6
8
|
export function useWindowResize(onResize) {
|
|
7
|
-
const
|
|
8
|
-
//
|
|
9
|
-
|
|
9
|
+
const callbackRef = useRef(onResize);
|
|
10
|
+
// 每次渲染都更新回调引用,避免闭包陈旧
|
|
11
|
+
callbackRef.current = onResize;
|
|
10
12
|
useEffect(() => {
|
|
11
|
-
const callback = () =>
|
|
13
|
+
const callback = () => callbackRef.current();
|
|
14
|
+
// 监听窗口大小变化
|
|
12
15
|
window.addEventListener("resize", callback);
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
// 监听屏幕方向变化(使用现代 API)
|
|
17
|
+
const mediaQuery = window.matchMedia("(orientation: portrait)");
|
|
18
|
+
// 现代浏览器使用 change 事件
|
|
19
|
+
if (mediaQuery.addEventListener) {
|
|
20
|
+
mediaQuery.addEventListener("change", callback);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// 降级处理:旧浏览器使用 addListener
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
mediaQuery.addListener(callback);
|
|
15
26
|
}
|
|
16
27
|
return () => {
|
|
17
28
|
window.removeEventListener("resize", callback);
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
// 清理 orientation 监听器
|
|
30
|
+
if (mediaQuery.removeEventListener) {
|
|
31
|
+
mediaQuery.removeEventListener("change", callback);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// 降级处理
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
mediaQuery.removeListener(callback);
|
|
20
37
|
}
|
|
21
38
|
};
|
|
22
|
-
}, []);
|
|
39
|
+
}, []); // 空依赖数组,因为使用了 ref
|
|
23
40
|
}
|
package/build/Flex/index.d.ts
CHANGED
package/build/Indicator/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
13
|
import { css } from '@emotion/react';
|
|
14
|
+
import React from 'react';
|
|
14
15
|
import { adaptive, normalizeUnit } from '../utils/cssUtil';
|
|
15
16
|
import { getBarChangeKeyFrames } from './style';
|
|
16
17
|
/**
|
|
@@ -20,32 +21,30 @@ import { getBarChangeKeyFrames } from './style';
|
|
|
20
21
|
export function Indicator(props) {
|
|
21
22
|
const { size, rounded = true, barWidth = 7, barHeight = 28, barColor = '#fff', barCount = 12, duration = 600, containerStyle } = props, attributes = __rest(props, ["size", "rounded", "barWidth", "barHeight", "barColor", "barCount", "duration", "containerStyle"]);
|
|
22
23
|
const radius = rounded ? barWidth / 2 : 0;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
// 使用 useMemo 缓存 barList,避免每次渲染都重新生成
|
|
25
|
+
const barList = React.useMemo(() => {
|
|
26
|
+
const bars = [];
|
|
27
|
+
for (let i = 0; i < barCount; i++) {
|
|
28
|
+
bars.push(_jsx("rect", { x: (100 - barWidth) / 2, y: "0", rx: radius, ry: radius, width: barWidth, height: barHeight, transform: `rotate(${(360 / barCount) * i}, 50, 50)`, css: {
|
|
29
|
+
animationDelay: `${-(duration * (barCount - i)) / barCount}ms`,
|
|
30
|
+
} }, i));
|
|
31
|
+
}
|
|
32
|
+
return bars;
|
|
33
|
+
}, [barCount, barWidth, barHeight, radius, duration]);
|
|
34
|
+
// 使用 useMemo 缓存样式,避免每次都重新计算
|
|
35
|
+
const style = React.useMemo(() => [
|
|
30
36
|
{
|
|
31
37
|
fontSize: 0,
|
|
32
38
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
width: unitSize,
|
|
38
|
-
height: unitSize,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// 容器尺寸未传时,这里是默认的尺寸
|
|
43
|
-
style.push(adaptive({
|
|
39
|
+
typeof size !== 'undefined' ? {
|
|
40
|
+
width: normalizeUnit(size),
|
|
41
|
+
height: normalizeUnit(size),
|
|
42
|
+
} : adaptive({
|
|
44
43
|
width: 60,
|
|
45
44
|
height: 60,
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const svgStyle = css({
|
|
45
|
+
})
|
|
46
|
+
], [size]);
|
|
47
|
+
const svgStyle = React.useMemo(() => css({
|
|
49
48
|
width: '100%',
|
|
50
49
|
height: '100%',
|
|
51
50
|
rect: {
|
|
@@ -55,6 +54,6 @@ export function Indicator(props) {
|
|
|
55
54
|
animationTimingFunction: 'linear',
|
|
56
55
|
animationIterationCount: 'infinite',
|
|
57
56
|
},
|
|
58
|
-
});
|
|
59
|
-
return (_jsx("div", Object.assign({ css: [style, containerStyle] }, attributes, { children: _jsx("svg",
|
|
57
|
+
}), [barColor, duration]);
|
|
58
|
+
return (_jsx("div", Object.assign({ css: [style, containerStyle] }, attributes, { children: _jsx("svg", { viewBox: "0 0 100 100", css: svgStyle, children: barList }) })));
|
|
60
59
|
}
|
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
* 获取转圈每一条bar的过渡动画
|
|
3
3
|
* @param color
|
|
4
4
|
*/
|
|
5
|
-
export declare function getBarChangeKeyFrames(color: string):
|
|
5
|
+
export declare function getBarChangeKeyFrames(color: string): {
|
|
6
|
+
name: string;
|
|
7
|
+
styles: string;
|
|
8
|
+
anim: 1;
|
|
9
|
+
toString: () => string;
|
|
10
|
+
} & string;
|
package/build/Indicator/style.js
CHANGED
|
@@ -4,12 +4,12 @@ import { keyframes } from '@emotion/react';
|
|
|
4
4
|
* @param color
|
|
5
5
|
*/
|
|
6
6
|
export function getBarChangeKeyFrames(color) {
|
|
7
|
-
return keyframes `
|
|
8
|
-
from {
|
|
9
|
-
fill: ${color};
|
|
10
|
-
}
|
|
11
|
-
to {
|
|
12
|
-
fill: transparent;
|
|
13
|
-
}
|
|
7
|
+
return keyframes `
|
|
8
|
+
from {
|
|
9
|
+
fill: ${color};
|
|
10
|
+
}
|
|
11
|
+
to {
|
|
12
|
+
fill: transparent;
|
|
13
|
+
}
|
|
14
14
|
`;
|
|
15
15
|
}
|
package/build/Loading/Wrapper.js
CHANGED
|
@@ -33,10 +33,10 @@ export function Wrapper(props) {
|
|
|
33
33
|
};
|
|
34
34
|
let box;
|
|
35
35
|
if (hint && typeof hint === 'string') {
|
|
36
|
-
box = (_jsxs(RowCenter,
|
|
36
|
+
box = (_jsxs(RowCenter, { css: [style.boxCommon, style.boxWithExtra, animation, containerStyle], onAnimationEnd: animationEnd, children: [_jsx(Indicator, Object.assign({}, indicatorProps)), _jsx("div", { css: style.hint, children: hint })] }));
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
box = (_jsx(RowCenter,
|
|
39
|
+
box = (_jsx(RowCenter, { css: [style.boxCommon, style.box, animation, containerStyle], onAnimationEnd: animationEnd, children: _jsx(Indicator, Object.assign({}, indicatorProps)) }));
|
|
40
40
|
}
|
|
41
41
|
return _jsx(Overlay, Object.assign({}, overlayProps, { children: box }));
|
|
42
42
|
}
|
package/build/Loading/style.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { Interpolation, Theme } from "@emotion/react";
|
|
2
|
-
export declare const LoadingShow:
|
|
3
|
-
|
|
2
|
+
export declare const LoadingShow: {
|
|
3
|
+
name: string;
|
|
4
|
+
styles: string;
|
|
5
|
+
anim: 1;
|
|
6
|
+
toString: () => string;
|
|
7
|
+
} & string;
|
|
8
|
+
export declare const LoadingHide: {
|
|
9
|
+
name: string;
|
|
10
|
+
styles: string;
|
|
11
|
+
anim: 1;
|
|
12
|
+
toString: () => string;
|
|
13
|
+
} & string;
|
|
4
14
|
export declare const style: Record<string, Interpolation<Theme>>;
|
package/build/Loading/style.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { keyframes } from "@emotion/react";
|
|
2
2
|
import { adaptive } from "../utils/cssUtil";
|
|
3
|
-
export const LoadingShow = keyframes `
|
|
4
|
-
from {
|
|
5
|
-
opacity: 0;
|
|
6
|
-
}
|
|
7
|
-
to {
|
|
8
|
-
opacity: 1;
|
|
9
|
-
}
|
|
3
|
+
export const LoadingShow = keyframes `
|
|
4
|
+
from {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
}
|
|
7
|
+
to {
|
|
8
|
+
opacity: 1;
|
|
9
|
+
}
|
|
10
10
|
`;
|
|
11
|
-
export const LoadingHide = keyframes `
|
|
12
|
-
from {
|
|
13
|
-
opacity: 1;
|
|
14
|
-
}
|
|
15
|
-
to {
|
|
16
|
-
opacity: 0;
|
|
17
|
-
}
|
|
11
|
+
export const LoadingHide = keyframes `
|
|
12
|
+
from {
|
|
13
|
+
opacity: 1;
|
|
14
|
+
}
|
|
15
|
+
to {
|
|
16
|
+
opacity: 0;
|
|
17
|
+
}
|
|
18
18
|
`;
|
|
19
19
|
export const style = {
|
|
20
20
|
boxCommon: adaptive({
|
package/build/Overlay/index.d.ts
CHANGED
package/build/Overlay/index.js
CHANGED
|
@@ -10,17 +10,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
|
-
import { useEffect, useLayoutEffect, useRef, useState } from
|
|
14
|
-
import { createPortal } from
|
|
15
|
-
import { getContextValue } from
|
|
16
|
-
import { useWindowResize } from
|
|
13
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
14
|
+
import { createPortal } from "react-dom";
|
|
15
|
+
import { getContextValue } from "../context";
|
|
16
|
+
import { useWindowResize } from "../Effect/useWindowResize";
|
|
17
17
|
/**
|
|
18
18
|
* 覆盖层,可以作为通用遮罩
|
|
19
19
|
* @param props
|
|
20
20
|
* @returns
|
|
21
21
|
*/
|
|
22
22
|
export function Overlay(props) {
|
|
23
|
-
const { children, outside = false, centerContent = true, fullScreen = true, maskColor =
|
|
23
|
+
const { children, outside = false, centerContent = true, fullScreen = true, maskColor = "rgba(0, 0, 0, .6)" } = props, extra = __rest(props, ["children", "outside", "centerContent", "fullScreen", "maskColor"]);
|
|
24
24
|
const [mount, setMount] = useState(null);
|
|
25
25
|
const [innerWidth, setInnerWidth] = useState(window.innerWidth);
|
|
26
26
|
// 这里是为了修复一个非挂载状态触发resize事件的bug
|
|
@@ -32,7 +32,7 @@ export function Overlay(props) {
|
|
|
32
32
|
}, []);
|
|
33
33
|
useLayoutEffect(() => {
|
|
34
34
|
if (outside) {
|
|
35
|
-
const div = document.createElement(
|
|
35
|
+
const div = document.createElement("div");
|
|
36
36
|
document.body.appendChild(div);
|
|
37
37
|
setMount(div);
|
|
38
38
|
return () => {
|
|
@@ -40,45 +40,49 @@ export function Overlay(props) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
}, [outside]);
|
|
43
|
-
// 页面大小变化时,innerWidth也会更新
|
|
43
|
+
// 页面大小变化时,innerWidth 也会更新
|
|
44
44
|
useWindowResize(() => {
|
|
45
45
|
if (!isUnmount.current) {
|
|
46
46
|
setInnerWidth(window.innerWidth);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
const ctx = getContextValue();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
width =
|
|
50
|
+
// 使用 useMemo 缓存样式计算,避免每次渲染都重新计算
|
|
51
|
+
const style = useMemo(() => {
|
|
52
|
+
const styles = [];
|
|
53
|
+
// 如果是全屏,设置全屏样式
|
|
54
|
+
if (fullScreen) {
|
|
55
|
+
// 获取宽度
|
|
56
|
+
let width = innerWidth;
|
|
57
|
+
if (width >= ctx.maxDocWidth) {
|
|
58
|
+
width = ctx.maxDocWidth;
|
|
59
|
+
}
|
|
60
|
+
else if (width <= ctx.minDocWidth) {
|
|
61
|
+
width = ctx.minDocWidth;
|
|
62
|
+
}
|
|
63
|
+
styles.push({
|
|
64
|
+
zIndex: 9999,
|
|
65
|
+
position: "fixed",
|
|
66
|
+
top: 0,
|
|
67
|
+
left: "50%",
|
|
68
|
+
marginLeft: `-${width / 2}px`,
|
|
69
|
+
width: `${width}px`,
|
|
70
|
+
height: "100%",
|
|
71
|
+
maxWidth: `${ctx.maxDocWidth}px`,
|
|
72
|
+
minWidth: `${ctx.minDocWidth}px`,
|
|
73
|
+
backgroundColor: maskColor,
|
|
74
|
+
});
|
|
57
75
|
}
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
// 如果内容居中,设置内容居中样式
|
|
77
|
+
if (centerContent) {
|
|
78
|
+
styles.push({
|
|
79
|
+
display: "flex",
|
|
80
|
+
alignItems: "center",
|
|
81
|
+
justifyContent: "center",
|
|
82
|
+
});
|
|
60
83
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
position: 'fixed',
|
|
64
|
-
top: 0,
|
|
65
|
-
left: '50%',
|
|
66
|
-
marginLeft: `-${width / 2}px`,
|
|
67
|
-
width: `${width}px`,
|
|
68
|
-
height: '100%',
|
|
69
|
-
maxWidth: `${ctx.maxDocWidth}px`,
|
|
70
|
-
minWidth: `${ctx.minDocWidth}px`,
|
|
71
|
-
backgroundColor: maskColor,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
// 如果内容居中,设置内容居中有样式
|
|
75
|
-
if (centerContent) {
|
|
76
|
-
style.push({
|
|
77
|
-
display: 'flex',
|
|
78
|
-
alignItems: 'center',
|
|
79
|
-
justifyContent: 'center',
|
|
80
|
-
});
|
|
81
|
-
}
|
|
84
|
+
return styles;
|
|
85
|
+
}, [fullScreen, innerWidth, ctx.maxDocWidth, ctx.minDocWidth, maskColor, centerContent]);
|
|
82
86
|
const content = (_jsx("div", Object.assign({ css: style }, extra, { children: children })));
|
|
83
87
|
/**
|
|
84
88
|
* 如果是挂载到当前位置,直接返回
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export interface SafeAreaProps extends React.HTMLProps<HTMLDivElement> {
|
|
3
2
|
children?: React.ReactNode;
|
|
4
|
-
type
|
|
3
|
+
type?: "top" | "bottom";
|
|
5
4
|
}
|
|
6
5
|
export declare function SafeArea(props: SafeAreaProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
package/build/SafeArea/index.js
CHANGED
|
@@ -10,12 +10,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
|
-
import { useViewport } from
|
|
13
|
+
import { useViewport } from "../Effect/useViewport";
|
|
14
14
|
export function SafeArea(props) {
|
|
15
|
-
const { children, type =
|
|
16
|
-
useViewport({ viewportFit:
|
|
17
|
-
let boxCss;
|
|
18
|
-
if (type ===
|
|
15
|
+
const { children, type = "bottom" } = props, extra = __rest(props, ["children", "type"]);
|
|
16
|
+
useViewport({ viewportFit: "cover" });
|
|
17
|
+
let boxCss = {};
|
|
18
|
+
if (type === "top") {
|
|
19
19
|
boxCss = {
|
|
20
20
|
height: [
|
|
21
21
|
`constant(safe-area-inset-top, 0)`,
|
|
@@ -23,7 +23,7 @@ export function SafeArea(props) {
|
|
|
23
23
|
],
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
else if (type ===
|
|
26
|
+
else if (type === "bottom") {
|
|
27
27
|
boxCss = {
|
|
28
28
|
height: [
|
|
29
29
|
`constant(safe-area-inset-bottom, 0)`,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/** @jsx jsx */
|
|
3
2
|
import { SerializedStyles } from "@emotion/react";
|
|
4
3
|
import * as CSS from "csstype";
|
|
@@ -20,6 +19,7 @@ export interface ScrollViewProps extends Omit<React.HTMLProps<HTMLDivElement>, "
|
|
|
20
19
|
showLoading?: boolean;
|
|
21
20
|
loadingContent?: React.ReactNode;
|
|
22
21
|
onScroll?: (event: ScrollEvent) => void;
|
|
22
|
+
scrollThrottle?: number;
|
|
23
23
|
containerStyle?: SerializedStyles;
|
|
24
24
|
wrapperStyle?: SerializedStyles;
|
|
25
25
|
loadingStyle?: SerializedStyles;
|