-
Notifications
You must be signed in to change notification settings - Fork 452
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
type: { | ||
type: 'choice', | ||
defaultValue: 'Basic', | ||
options: ['Basic', 'Button', 'Avatar', 'Input', 'Image', 'Node'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be some |
||
}, | ||
active: { | ||
type: 'boolean', | ||
description: 'Show animation effect', | ||
defaultValue: false, | ||
}, | ||
avatar: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be hidden for all types other than |
||
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: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SHould have a |
||
type: 'number', | ||
description: 'Set the row count of paragraph', | ||
hidden: (ps) => !ps.paragraph && ps.type !== 'Basic', | ||
advanced: true, | ||
}, | ||
// SkeletonButtonProps | ||
shapeButton: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does nothing. Also, there's already the |
||
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better use |
||
}, | ||
}, | ||
importPath: "@plasmicpkgs/antd5/skinny/registerSkeleton", | ||
importName: "AntdSkeleton", | ||
}); | ||
} |
There was a problem hiding this comment.
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"