Skip to content

Commit ccca386

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

File tree

1 file changed

+137
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)