@rxdrag/website-lib-core 0.0.98 → 0.0.100
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.100",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@types/react-dom": "^19.1.0",
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
|
-
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
28
27
|
"@rxdrag/tsconfig": "0.2.0",
|
|
29
|
-
"@rxdrag/slate-preview": "1.2.63"
|
|
28
|
+
"@rxdrag/slate-preview": "1.2.63",
|
|
29
|
+
"@rxdrag/eslint-config-custom": "0.2.12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@iconify/utils": "^3.0.2",
|
|
@@ -3,7 +3,7 @@ import { forwardRef, useRef, useEffect, useState } from "react";
|
|
|
3
3
|
|
|
4
4
|
export type ToTopProps = {
|
|
5
5
|
className?: string;
|
|
6
|
-
|
|
6
|
+
svg?: string;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export const topIcon = () => (
|
|
@@ -25,28 +25,28 @@ export const topIcon = () => (
|
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
export const ToTop = forwardRef<HTMLDivElement, ToTopProps>((props, ref) => {
|
|
28
|
-
const { className,
|
|
28
|
+
const { className, svg, ...rest } = props;
|
|
29
29
|
const [win, setWin] = useState<Window | null>(null);
|
|
30
30
|
const innerRef = useRef<HTMLDivElement>(null);
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
// 合并外部传入的ref和内部ref
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
if (!innerRef.current) return;
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
// 获取当前元素所在的window
|
|
37
37
|
const currentWin = innerRef.current.ownerDocument.defaultView;
|
|
38
38
|
setWin(currentWin);
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
// 如果外部传入的是ref对象,则设置其current属性
|
|
41
|
-
if (ref && typeof ref ===
|
|
41
|
+
if (ref && typeof ref === "object") {
|
|
42
42
|
ref.current = innerRef.current;
|
|
43
43
|
}
|
|
44
44
|
}, [ref]);
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
const handleClick = () => {
|
|
47
47
|
if (win) {
|
|
48
48
|
win.scrollTo({ top: 0, behavior: "smooth" });
|
|
49
|
-
} else if (typeof window !==
|
|
49
|
+
} else if (typeof window !== "undefined") {
|
|
50
50
|
// 降级处理:如果没有获取到特定window,使用全局window
|
|
51
51
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
52
52
|
}
|
|
@@ -62,7 +62,11 @@ export const ToTop = forwardRef<HTMLDivElement, ToTopProps>((props, ref) => {
|
|
|
62
62
|
{...rest}
|
|
63
63
|
onClick={handleClick}
|
|
64
64
|
>
|
|
65
|
-
{
|
|
65
|
+
{svg ? (
|
|
66
|
+
<div className="contents" dangerouslySetInnerHTML={{ __html: svg }} />
|
|
67
|
+
) : (
|
|
68
|
+
topIcon()
|
|
69
|
+
)}
|
|
66
70
|
</div>
|
|
67
71
|
);
|
|
68
72
|
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import clsx from "clsx"
|
|
2
|
-
import { forwardRef } from "react"
|
|
3
|
-
|
|
4
|
-
export type ToTopProps = {
|
|
5
|
-
className?: string,
|
|
6
|
-
children?: React.ReactNode
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const ToTop = forwardRef<HTMLDivElement, ToTopProps>((
|
|
10
|
-
props, ref) => {
|
|
11
|
-
const { className, children, ...rest } = props
|
|
12
|
-
const handleClick = () => {
|
|
13
|
-
window.scrollTo({ top: 0, behavior: "smooth" })
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return <div
|
|
17
|
-
ref={ref}
|
|
18
|
-
className={
|
|
19
|
-
clsx(
|
|
20
|
-
"fixed bottom-4 right-4 hidden user-select-none scrolled:flex cursor-pointer transition duration-300 ease-in-out z-50",
|
|
21
|
-
className,
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
{...rest}
|
|
25
|
-
onClick={handleClick}
|
|
26
|
-
>
|
|
27
|
-
{
|
|
28
|
-
children || <svg className="h-6 w-6" width="1.5rem" height="1.5rem" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
29
|
-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 15l7-7 7 7" />
|
|
30
|
-
</svg>
|
|
31
|
-
}
|
|
32
|
-
</div>
|
|
33
|
-
})
|