deepsea-components 5.7.0 → 5.7.2
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/README.md +23 -23
- package/dist/cjs/components/AutoFit.js +3 -1
- package/dist/cjs/components/AutoFit.js.map +2 -2
- package/dist/cjs/components/AutoScroll.js +16 -1
- package/dist/cjs/components/AutoScroll.js.map +2 -2
- package/dist/cjs/components/AutoSizeTextarea.js.map +1 -1
- package/dist/cjs/components/CircleText.js +31 -2
- package/dist/cjs/components/CircleText.js.map +2 -2
- package/dist/cjs/components/CopyButton.js.map +1 -1
- package/dist/cjs/components/Echart.js.map +2 -2
- package/dist/cjs/components/Flow.js +56 -3
- package/dist/cjs/components/Flow.js.map +2 -2
- package/dist/cjs/components/FormLabel.js.map +1 -1
- package/dist/cjs/components/HlsPlayer.js.map +1 -1
- package/dist/cjs/components/InfiniteScroll.js +15 -1
- package/dist/cjs/components/InfiniteScroll.js.map +2 -2
- package/dist/cjs/components/InputFile.js.map +1 -1
- package/dist/cjs/components/LoopSwiper.js +23 -2
- package/dist/cjs/components/LoopSwiper.js.map +2 -2
- package/dist/cjs/components/Ring.js +13 -1
- package/dist/cjs/components/Ring.js.map +2 -2
- package/dist/cjs/components/Scroll.js.map +2 -2
- package/dist/cjs/components/SectionRing.js +3 -1
- package/dist/cjs/components/SectionRing.js.map +2 -2
- package/dist/cjs/components/Skeleton.js.map +2 -2
- package/dist/cjs/components/Title.js.map +2 -2
- package/dist/cjs/components/TransitionBox.js +9 -1
- package/dist/cjs/components/TransitionBox.js.map +2 -2
- package/dist/cjs/components/TransitionNum.js.map +1 -1
- package/dist/cjs/components/Trapezium.js.map +1 -1
- package/dist/cjs/utils/getReactVersion.js.map +1 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/esm/components/AutoFit.js +9 -9
- package/dist/esm/components/AutoFit.js.map +1 -1
- package/dist/esm/components/AutoScroll.js.map +1 -1
- package/dist/esm/components/AutoSizeTextarea.js +2 -2
- package/dist/esm/components/AutoSizeTextarea.js.map +1 -1
- package/dist/esm/components/CircleText.js.map +1 -1
- package/dist/esm/components/CopyButton.js.map +1 -1
- package/dist/esm/components/Echart.js.map +1 -1
- package/dist/esm/components/Flow.js.map +1 -1
- package/dist/esm/components/FormLabel.js +2 -2
- package/dist/esm/components/FormLabel.js.map +1 -1
- package/dist/esm/components/HlsPlayer.js.map +1 -1
- package/dist/esm/components/InfiniteScroll.js +4 -4
- package/dist/esm/components/InfiniteScroll.js.map +1 -1
- package/dist/esm/components/InputFile.js.map +1 -1
- package/dist/esm/components/LoopSwiper.js.map +1 -1
- package/dist/esm/components/Ring.js.map +1 -1
- package/dist/esm/components/Scroll.js.map +1 -1
- package/dist/esm/components/SectionRing.js.map +1 -1
- package/dist/esm/components/Skeleton.js.map +1 -1
- package/dist/esm/components/Title.js.map +1 -1
- package/dist/esm/components/TransitionBox.js.map +1 -1
- package/dist/esm/components/TransitionNum.js.map +1 -1
- package/dist/esm/components/Trapezium.js.map +1 -1
- package/dist/esm/utils/getReactVersion.js.map +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/AutoFit.tsx +103 -101
- package/src/components/AutoScroll.tsx +148 -132
- package/src/components/AutoSizeTextarea.tsx +49 -49
- package/src/components/CircleText.tsx +81 -56
- package/src/components/CopyButton.tsx +29 -29
- package/src/components/Echart.tsx +67 -44
- package/src/components/Flow.tsx +270 -214
- package/src/components/FormLabel.tsx +38 -38
- package/src/components/HlsPlayer.tsx +34 -34
- package/src/components/InfiniteScroll.tsx +161 -135
- package/src/components/InputFile.tsx +234 -234
- package/src/components/LoopSwiper.tsx +125 -101
- package/src/components/Ring.tsx +30 -19
- package/src/components/Scroll.tsx +96 -95
- package/src/components/SectionRing.tsx +39 -36
- package/src/components/Skeleton.tsx +47 -46
- package/src/components/Title.tsx +23 -24
- package/src/components/TransitionBox.tsx +44 -36
- package/src/components/TransitionNum.tsx +54 -54
- package/src/components/Trapezium.tsx +59 -59
- package/src/utils/getReactVersion.ts +7 -7
- package/src/utils/index.ts +33 -33
|
@@ -1,135 +1,161 @@
|
|
|
1
|
-
import { css } from "@emotion/css"
|
|
2
|
-
import { useSize } from "ahooks"
|
|
3
|
-
import { clsx } from "deepsea-tools"
|
|
4
|
-
import { ComponentProps, CSSProperties, forwardRef, MouseEvent as ReactMouseEvent, useEffect, useImperativeHandle, useRef } from "react"
|
|
5
|
-
|
|
6
|
-
export type InfiniteScrollProps = ComponentProps<"div"> & {
|
|
7
|
-
/**
|
|
8
|
-
* 滚动的方向
|
|
9
|
-
* @default "vertical"
|
|
10
|
-
*/
|
|
11
|
-
direction?: "vertical" | "horizontal"
|
|
12
|
-
/** 渲染 children 的容器的类名 */
|
|
13
|
-
containerClassName?: string
|
|
14
|
-
/** 渲染 children 的容器的样式 */
|
|
15
|
-
containerStyle?: CSSProperties
|
|
16
|
-
/**
|
|
17
|
-
* 两个 children 容器之间的间距
|
|
18
|
-
* @default 0
|
|
19
|
-
*/
|
|
20
|
-
gap?: number
|
|
21
|
-
/** 一个周期的时间,单位:毫秒 */
|
|
22
|
-
duration: number
|
|
23
|
-
/** 是否将 gap 的距离也加入 overflow 的计算 */
|
|
24
|
-
withGap?: boolean
|
|
25
|
-
/** 尺寸刚好相同时,是否视为溢出 */
|
|
26
|
-
withEqual?: boolean
|
|
27
|
-
/** 鼠标移入时,是否停止动画 */
|
|
28
|
-
pauseOnHover?: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 无限滚动的组件
|
|
33
|
-
* 子元素会内置的容器中被渲染两次,首尾相连,形成无限滚动的效果
|
|
34
|
-
* 但是,如果内部检测到并没有溢出,那么不会渲染两次,并且没有动画
|
|
35
|
-
*/
|
|
36
|
-
export const InfiniteScroll = forwardRef<HTMLDivElement, InfiniteScrollProps>((props, ref) => {
|
|
37
|
-
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
import { css } from "@emotion/css"
|
|
2
|
+
import { useSize } from "ahooks"
|
|
3
|
+
import { clsx } from "deepsea-tools"
|
|
4
|
+
import { ComponentProps, CSSProperties, forwardRef, MouseEvent as ReactMouseEvent, useEffect, useImperativeHandle, useRef } from "react"
|
|
5
|
+
|
|
6
|
+
export type InfiniteScrollProps = ComponentProps<"div"> & {
|
|
7
|
+
/**
|
|
8
|
+
* 滚动的方向
|
|
9
|
+
* @default "vertical"
|
|
10
|
+
*/
|
|
11
|
+
direction?: "vertical" | "horizontal"
|
|
12
|
+
/** 渲染 children 的容器的类名 */
|
|
13
|
+
containerClassName?: string
|
|
14
|
+
/** 渲染 children 的容器的样式 */
|
|
15
|
+
containerStyle?: CSSProperties
|
|
16
|
+
/**
|
|
17
|
+
* 两个 children 容器之间的间距
|
|
18
|
+
* @default 0
|
|
19
|
+
*/
|
|
20
|
+
gap?: number
|
|
21
|
+
/** 一个周期的时间,单位:毫秒 */
|
|
22
|
+
duration: number
|
|
23
|
+
/** 是否将 gap 的距离也加入 overflow 的计算 */
|
|
24
|
+
withGap?: boolean
|
|
25
|
+
/** 尺寸刚好相同时,是否视为溢出 */
|
|
26
|
+
withEqual?: boolean
|
|
27
|
+
/** 鼠标移入时,是否停止动画 */
|
|
28
|
+
pauseOnHover?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 无限滚动的组件
|
|
33
|
+
* 子元素会内置的容器中被渲染两次,首尾相连,形成无限滚动的效果
|
|
34
|
+
* 但是,如果内部检测到并没有溢出,那么不会渲染两次,并且没有动画
|
|
35
|
+
*/
|
|
36
|
+
export const InfiniteScroll = forwardRef<HTMLDivElement, InfiniteScrollProps>((props, ref) => {
|
|
37
|
+
const {
|
|
38
|
+
className,
|
|
39
|
+
direction = "vertical",
|
|
40
|
+
children,
|
|
41
|
+
containerClassName,
|
|
42
|
+
containerStyle,
|
|
43
|
+
gap = 0,
|
|
44
|
+
duration,
|
|
45
|
+
withGap,
|
|
46
|
+
withEqual,
|
|
47
|
+
pauseOnHover,
|
|
48
|
+
onMouseEnter,
|
|
49
|
+
onMouseLeave,
|
|
50
|
+
...rest
|
|
51
|
+
} = props
|
|
52
|
+
|
|
53
|
+
const wrapper = useRef<HTMLDivElement>(null)
|
|
54
|
+
const wrapperSize = useSize(wrapper)
|
|
55
|
+
|
|
56
|
+
const ele = useRef<HTMLDivElement>(null)
|
|
57
|
+
|
|
58
|
+
useImperativeHandle(ref, () => wrapper.current as HTMLDivElement, [wrapper.current])
|
|
59
|
+
|
|
60
|
+
const container = useRef<HTMLDivElement>(null)
|
|
61
|
+
const containerSize = useSize(container)
|
|
62
|
+
|
|
63
|
+
function bigger(containerSize: number, wrapperSize: number) {
|
|
64
|
+
return withEqual ? containerSize + (withGap ? gap : 0) >= wrapperSize : containerSize + (withGap ? gap : 0) > wrapperSize
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const overflow =
|
|
68
|
+
wrapperSize && containerSize
|
|
69
|
+
? direction === "vertical"
|
|
70
|
+
? bigger(containerSize.height, wrapperSize.height)
|
|
71
|
+
: bigger(containerSize.width, wrapperSize.width)
|
|
72
|
+
: false
|
|
73
|
+
|
|
74
|
+
const animation = useRef<Animation | undefined>(undefined)
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!wrapperSize || !containerSize || !overflow) return
|
|
78
|
+
animation.current = ele.current?.animate(
|
|
79
|
+
{
|
|
80
|
+
transform:
|
|
81
|
+
direction === "vertical"
|
|
82
|
+
? [`translateY(0)`, `translateY(-${containerSize.height + gap}px)`]
|
|
83
|
+
: [`translateX(0)`, `translateX(-${containerSize.width + gap}px)`],
|
|
84
|
+
},
|
|
85
|
+
{ duration, iterations: Infinity },
|
|
86
|
+
)
|
|
87
|
+
return () => animation.current?.cancel()
|
|
88
|
+
}, [wrapperSize, containerSize, overflow, direction, duration])
|
|
89
|
+
|
|
90
|
+
function enter(e: ReactMouseEvent<HTMLDivElement, MouseEvent>) {
|
|
91
|
+
if (pauseOnHover) animation.current?.pause()
|
|
92
|
+
onMouseEnter?.(e)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function leave(e: ReactMouseEvent<HTMLDivElement, MouseEvent>) {
|
|
96
|
+
if (pauseOnHover) animation.current?.play()
|
|
97
|
+
onMouseLeave?.(e)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!pauseOnHover && animation.current?.playState === "paused") animation.current?.play()
|
|
102
|
+
}, [animation.current, pauseOnHover])
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
ref={wrapper}
|
|
107
|
+
className={clsx(
|
|
108
|
+
css`
|
|
109
|
+
position: relative;
|
|
110
|
+
${direction === "vertical" ? "overflow-y: hidden;" : "overflow-x: hidden;"}
|
|
111
|
+
`,
|
|
112
|
+
className,
|
|
113
|
+
)}
|
|
114
|
+
onMouseEnter={enter}
|
|
115
|
+
onMouseLeave={leave}
|
|
116
|
+
{...rest}
|
|
117
|
+
>
|
|
118
|
+
<div
|
|
119
|
+
ref={ele}
|
|
120
|
+
style={{
|
|
121
|
+
position: "absolute",
|
|
122
|
+
width: direction === "vertical" ? "100%" : containerSize && (overflow ? containerSize.width * 2 + gap : containerSize.width),
|
|
123
|
+
height: direction === "horizontal" ? "100%" : containerSize && (overflow ? containerSize.height * 2 + gap : containerSize.width),
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
<div
|
|
127
|
+
ref={container}
|
|
128
|
+
className={clsx(
|
|
129
|
+
css`
|
|
130
|
+
position: absolute;
|
|
131
|
+
left: 0;
|
|
132
|
+
top: 0;
|
|
133
|
+
${direction === "vertical" ? "width: 100%;" : "height: 100%;"}
|
|
134
|
+
`,
|
|
135
|
+
containerClassName,
|
|
136
|
+
)}
|
|
137
|
+
style={containerStyle}
|
|
138
|
+
>
|
|
139
|
+
{children}
|
|
140
|
+
</div>
|
|
141
|
+
{overflow && (
|
|
142
|
+
<div
|
|
143
|
+
ref={container}
|
|
144
|
+
className={clsx(
|
|
145
|
+
css`
|
|
146
|
+
position: absolute;
|
|
147
|
+
right: 0;
|
|
148
|
+
bottom: 0;
|
|
149
|
+
${direction === "vertical" ? "width: 100%;" : "height: 100%;"}
|
|
150
|
+
`,
|
|
151
|
+
containerClassName,
|
|
152
|
+
)}
|
|
153
|
+
style={containerStyle}
|
|
154
|
+
>
|
|
155
|
+
{children}
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
)
|
|
161
|
+
})
|