@rxdrag/website-lib-core 0.0.78 → 0.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.79",
|
|
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/tsconfig": "0.2.0",
|
|
28
27
|
"@rxdrag/slate-preview": "1.2.61",
|
|
29
|
-
"@rxdrag/eslint-config-custom": "0.2.12"
|
|
28
|
+
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
29
|
+
"@rxdrag/tsconfig": "0.2.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@iconify/utils": "^3.0.2",
|
|
@@ -4,19 +4,23 @@ import { iconList } from "./socials";
|
|
|
4
4
|
import clsx from "clsx";
|
|
5
5
|
|
|
6
6
|
export type ShareProps = {
|
|
7
|
-
socials?: string[]
|
|
8
|
-
size?: "xs" | "sm" | "md" | "lg" | "xl"
|
|
9
|
-
className?: string
|
|
10
|
-
|
|
7
|
+
socials?: string[];
|
|
8
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
9
|
+
className?: string;
|
|
10
|
+
classNames?: {
|
|
11
|
+
item?: string;
|
|
12
|
+
itemIcon?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
11
15
|
|
|
12
16
|
function getPageDetails() {
|
|
13
|
-
if (typeof window ===
|
|
17
|
+
if (typeof window === "undefined") {
|
|
14
18
|
return null;
|
|
15
19
|
}
|
|
16
20
|
const details = {
|
|
17
21
|
url: window?.location?.href,
|
|
18
22
|
title: document?.title || "null",
|
|
19
|
-
description:
|
|
23
|
+
description: "null", // 默认为空字符串
|
|
20
24
|
};
|
|
21
25
|
|
|
22
26
|
const descriptionMetaTag = document.querySelector('meta[name="description"]');
|
|
@@ -27,43 +31,56 @@ function getPageDetails() {
|
|
|
27
31
|
return details;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export const Share = forwardRef<HTMLDivElement, ShareProps>(
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
export const Share = forwardRef<HTMLDivElement, ShareProps>(
|
|
35
|
+
(props: ShareProps, ref) => {
|
|
36
|
+
const { className, classNames, ...rest } = props;
|
|
37
|
+
const [socialList, setSolicalList] = useState<IconListType>();
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
const details = getPageDetails();
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setSolicalList(iconList);
|
|
43
|
+
}, [props.socials]);
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
// 生成每个社交媒体的分享链接
|
|
46
|
+
const generateLink = (key: string) => {
|
|
47
|
+
const social = iconList[key];
|
|
48
|
+
if (!social) return "#";
|
|
49
|
+
return social.url(
|
|
50
|
+
details?.url || "",
|
|
51
|
+
details?.title,
|
|
52
|
+
details?.description
|
|
53
|
+
);
|
|
54
|
+
};
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
return (
|
|
57
|
+
<div ref={ref} className={clsx("flex items-center", className)} {...rest}>
|
|
58
|
+
<div className="flex space-x-3">
|
|
59
|
+
{Object.keys(socialList || {}).map((key) => (
|
|
60
|
+
<a
|
|
61
|
+
key={key}
|
|
62
|
+
href={generateLink(key)}
|
|
63
|
+
target="_blank"
|
|
64
|
+
rel="noopener noreferrer"
|
|
65
|
+
title={`Share on ${iconList[key].title}`}
|
|
66
|
+
className={clsx(
|
|
67
|
+
"flex h-6 w-6 items-center justify-center text-gray-400 hover:text-gray-500",
|
|
68
|
+
classNames?.item
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
<svg
|
|
72
|
+
className={clsx("w-5 h-5", classNames?.itemIcon)}
|
|
73
|
+
fill="currentColor"
|
|
74
|
+
viewBox="0 0 24 24"
|
|
75
|
+
focusable="false"
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
>
|
|
78
|
+
{iconList[key].path}
|
|
79
|
+
</svg>
|
|
80
|
+
</a>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
66
83
|
</div>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
);
|