Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[antd5] add Skeleton component #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 216 additions & 0 deletions plasmicpkgs/antd5/src/registerSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import { Skeleton, SkeletonProps } from "antd";
import React from "react";
import { Registerable, registerComponentHelper } from "./utils";

export type AntdSkeletonProps = SkeletonProps & {
type?: 'Basic' | 'Button' | 'Avatar' | 'Input' | 'Image' | 'Node'
width?: string | number | (string | number)[]
widthTitle?: string
rows?: number
shape?: 'circle' | 'square'
size?: 'large' | 'small' | 'default'
customClassName?: string
}

export function AntdSkeleton(props: AntdSkeletonProps) {
const {
type,
paragraph,
avatar,
title,
shape,
size,
loading,
width,
widthTitle,
rows,
className: rootClassName,
customClassName,
children,
} = props

if (type === 'Button') {
return loading ? (
<Skeleton.Button
{...props}
rootClassName={rootClassName}
className={customClassName}
/>
) : (
children
)
}

if (type === 'Avatar') {
return loading ? (
<Skeleton.Avatar
{...props}
rootClassName={rootClassName}
className={customClassName}
/>
) : (
children
)
}

if (type === 'Input') {
return loading ? (
<Skeleton.Input
{...props}
rootClassName={rootClassName}
className={customClassName}
/>
) : (
children
)
}

if (type === 'Image') {
return loading ? (
<Skeleton.Image
{...props}
rootClassName={rootClassName}
className={customClassName}
/>
) : (
children
)
}

if (type === 'Node') {
return (
<Skeleton.Node
{...props}
rootClassName={props.className}
className={customClassName}
/>
)
}

return (
<Skeleton
{...props}
paragraph={paragraph ? { rows, width } : false}
avatar={avatar ? { shape, size } : false}
title={title ? { width: widthTitle, className: customClassName } : false}
rootClassName={rootClassName}
className={customClassName}
/>
)
}

export const skeletonComponentName = "plasmic-antd5-skeleton";

export function registerSkeleton(loader?: Registerable) {
registerComponentHelper(loader, AntdSkeleton, {
name: skeletonComponentName,
displayName: 'Skeleton',
props: {
children: 'slot',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be hidden when type !== "Node"

type: {
type: 'choice',
defaultValue: 'Basic',
options: ['Basic', 'Button', 'Avatar', 'Input', 'Image', 'Node'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some helpText for Node type (e.g. please use the children slot to add a node)

},
active: {
type: 'boolean',
description: 'Show animation effect',
defaultValue: false,
},
avatar: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avatar placeholder needs some margin on top and left

type: 'boolean',
description: 'Show avatar placeholder',
hidden: (ps) => ps.type !== 'Basic',
defaultValue: false,
},
loading: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be true by default, so that when you drag the Skeleton to the canvas, it shows something.

type: 'boolean',
description: 'Display the skeleton when true',
defaultValue: false,
},
paragraph: {
type: 'boolean',
description: 'Show paragraph placeholder',
hidden: (ps) => ps.type !== 'Basic',
defaultValue: true,
},
round: {
type: 'boolean',
description: 'Show paragraph and title radius when true',
hidden: (ps) => ps.type !== 'Basic',
defaultValue: false,
},
title: {
type: 'boolean',
description: 'Show title placeholder',
hidden: (ps) => ps.type !== 'Basic',
defaultValue: true,
},
size: {
type: 'choice',
defaultValue: 'default',
description: `Size of the skeleton for types: Avatar, Button and Input`,
hidden: (ps) =>
ps.type !== 'Avatar' &&
ps.type !== 'Button' &&
ps.type !== 'Input' &&
ps.avatar !== true,
advanced: true,
options: ['large', 'small', 'default'],
},
// SkeletonAvatarProps
shape: {
type: 'choice',
defaultValue: 'circle',
description: `Set the shape of avatar`,
hidden: (ps) => ps.type !== 'Avatar' && ps.avatar !== true,
advanced: true,
options: ['circle', 'square'],
},
// SkeletonTitleProps
widthTitle: {
type: 'string',
description: 'Width of the title',
hidden: (ps) => !ps.title,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be hidden for all types other than Basic

advanced: true,
},
// SkeletonParagraphProps
width: {
type: 'array',
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',
hidden: (ps) => !ps.paragraph && ps.type !== 'Basic',
advanced: true,
},
rows: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHould have a defaultValueHint of 1

type: 'number',
description: 'Set the row count of paragraph',
hidden: (ps) => !ps.paragraph && ps.type !== 'Basic',
advanced: true,
},
// SkeletonButtonProps
shapeButton: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does nothing. Also, there's already the shape prop that works for this purpose

type: 'choice',
defaultValue: 'default',
description: `Set the shape of button`,
hidden: (ps) => ps.type !== 'Button',
advanced: true,
options: ['default', 'circle', 'round', 'square'],
},
block: {
type: 'boolean',
description: 'Option to fit button width to its parent width',
hidden: (ps) => ps.type !== 'Button' && ps.type !== 'Input',
defaultValue: false,
advanced: true,
},
customClassName: {
type: 'string',
displayName: 'Class Name',
description: 'Custom class name for Node skeleton for custom styling',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use class prop type for this.

},
},
importPath: "@plasmicpkgs/antd5/skinny/registerSkeleton",
importName: "AntdSkeleton",
});
}