Skip to content

Commit b43c0f4

Browse files
committed
[antd5] add Skeleton component
1 parent 8c2bb25 commit b43c0f4

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import { Skeleton, SkeletonProps } from "antd";
2+
import React from "react";
3+
import { Registerable, registerComponentHelper } from "./utils";
4+
5+
export type AntdSkeletonProps = SkeletonProps & {
6+
type?: "Basic" | "Button" | "Avatar" | "Input" | "Image" | "Node";
7+
};
8+
9+
export function AntdSkeleton(props: AntdSkeletonProps) {
10+
const { type, loading, children } = props;
11+
12+
if (type === "Button") {
13+
return loading ? <Skeleton.Button {...props} /> : children;
14+
}
15+
16+
if (type === "Avatar") {
17+
return loading ? <Skeleton.Avatar {...props} />: children;
18+
}
19+
20+
if (type === "Input") {
21+
return loading ? <Skeleton.Input {...props} /> : children;
22+
}
23+
24+
if (type === "Image") {
25+
return loading ? <Skeleton.Image {...props} /> : children;
26+
}
27+
28+
if (type === "Node") {
29+
return <Skeleton.Node {...props} />;
30+
}
31+
32+
return <Skeleton {...props} />;
33+
}
34+
35+
export const skeletonComponentName = "plasmic-antd5-skeleton";
36+
37+
export function registerSkeleton(loader?: Registerable) {
38+
registerComponentHelper(loader, AntdSkeleton, {
39+
name: skeletonComponentName,
40+
displayName: "Skeleton",
41+
props: {
42+
children: "slot",
43+
type: {
44+
type: "choice",
45+
defaultValueHint: "Basic",
46+
options: ["Basic", "Button","Avatar", "Input", "Image", "Node"],
47+
},
48+
active: {
49+
type: "boolean",
50+
description: "Show animation effect",
51+
hidden: (ps) => ps.type !== "Basic" && ps.type !== "Button" && ps.type !== "Avatar" && ps.type !== "Input",
52+
defaultValueHint: false,
53+
},
54+
avatar: {
55+
type: "boolean",
56+
description: "Show avatar placeholder",
57+
hidden: (ps) => ps.type !== "Basic",
58+
defaultValueHint: false,
59+
},
60+
loading: {
61+
type: "boolean",
62+
description: "Display the skeleton when true",
63+
defaultValueHint: false,
64+
},
65+
paragraph: {
66+
type: "boolean",
67+
description: "Show paragraph placeholder",
68+
hidden: (ps) => ps.type !== "Basic",
69+
defaultValueHint: true,
70+
},
71+
round: {
72+
type: "boolean",
73+
description: "Show paragraph and title radius when true",
74+
hidden: (ps) => ps.type !== "Basic",
75+
defaultValueHint: false,
76+
},
77+
title: {
78+
type: "boolean",
79+
description: "Show title placeholder",
80+
hidden: (ps) => ps.type !== "Basic",
81+
defaultValueHint: true,
82+
},
83+
size: {
84+
type: "choice",
85+
defaultValueHint: "default",
86+
description: `Size of the skeleton for types: Avatar, Button and Input`,
87+
hidden: (ps) => ps.type !== "Avatar" && ps.type !== "Button" && ps.type !== "Input" && ps.avatar !== true,
88+
advanced: true,
89+
options: ["large", "small", "default"],
90+
},
91+
// SkeletonAvatarProps
92+
shape: {
93+
type: "choice",
94+
defaultValueHint: "circle",
95+
description: `Set the shape of avatar`,
96+
hidden: (ps) => ps.type !== "Avatar" && ps.avatar !== true,
97+
advanced: true,
98+
options: ["circle", "square"],
99+
},
100+
// SkeletonTitleProps
101+
widthTitle: {
102+
type: "string",
103+
description: "Width of the title",
104+
hidden: (ps) => !ps.title,
105+
advanced: true,
106+
},
107+
// SkeletonParagraphProps
108+
width: {
109+
type: "array",
110+
description: "Set the width of paragraph. When width is an Array, it can set the width of each row. Otherwise only set the last row width",
111+
hidden: (ps) => !ps.paragraph && ps.type !== "Basic",
112+
advanced: true,
113+
},
114+
rows: {
115+
type: "number",
116+
description: "Set the row count of paragraph",
117+
hidden: (ps) => !ps.paragraph && ps.type !== "Basic",
118+
advanced: true,
119+
},
120+
// SkeletonButtonProps
121+
shapeButton: {
122+
type: "choice",
123+
defaultValueHint: "default",
124+
description: `Set the shape of button`,
125+
hidden: (ps) => ps.type !== "Button",
126+
advanced: true,
127+
options: ["default", "circle", "round", "square"],
128+
},
129+
block: {
130+
type: "boolean",
131+
description: "Option to fit button width to its parent width",
132+
hidden: (ps) => ps.type !== "Button",
133+
defaultValueHint: false,
134+
advanced: true,
135+
},
136+
},
137+
importPath: "@plasmicpkgs/antd5/skinny/registerSkeleton",
138+
importName: "AntdSkeleton",
139+
});
140+
}

0 commit comments

Comments
 (0)