1
0
mirror of https://github.com/vercel/commerce.git synced 2025-07-27 20:21:22 +00:00
Files
.vscode
assets
components
auth
cart
common
icons
product
ui
Button
Container
Grid
Hero
Input
Link
LoadingDots
Logo
Marquee
Modal
Sidebar
Skeleton
Skeleton.module.css
Skeleton.tsx
index.ts
Text
README.md
context.tsx
index.ts
wishlist
config
docs
framework
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
commerce/components/ui/Skeleton/Skeleton.tsx
2020-10-15 12:13:07 -03:00

58 lines
1.2 KiB
TypeScript

import React, { CSSProperties } from 'react'
import cn from 'classnames'
import px from '@lib/to-pixels'
import s from './Skeleton.module.css'
interface Props {
width?: string | number
height?: string | number
boxHeight?: string | number
style?: CSSProperties
show?: boolean
block?: boolean
className?: string
}
const Skeleton: React.FC<Props> = ({
style,
width,
height,
children,
className,
show = true,
boxHeight = height,
}) => {
// Automatically calculate the size if there are children
// and no fixed sizes are specified
const shouldAutoSize = !!children && !(width || height)
// Defaults
width = width || 24
height = height || 24
boxHeight = boxHeight || height
return (
<span
className={cn(s.skeleton, className, {
[s.show]: show,
[s.wrapper]: shouldAutoSize,
[s.loaded]: !shouldAutoSize && !!children,
})}
style={
shouldAutoSize
? {}
: {
minWidth: px(width),
minHeight: px(height),
marginBottom: `calc(${px(boxHeight)} - ${px(height)})`,
...style,
}
}
>
{children}
</span>
)
}
export default Skeleton