Skip to content

Commit

Permalink
feat(skeleton): add width and height props to set the skeleton size (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasaarcoverde authored Aug 26, 2024
2 parents 661874b + ef9ff16 commit 31a5232
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
24 changes: 23 additions & 1 deletion packages/shoreline/src/components/skeleton/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type CSSProperty, style } from '@vtex/shoreline-utils'
import type { ComponentPropsWithoutRef } from 'react'
import { forwardRef } from 'react'

Expand All @@ -9,13 +10,24 @@ import { forwardRef } from 'react'
*/
export const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>(
function Skeleton(props, ref) {
const { shape = 'rect', ...otherProps } = props
const {
shape = 'rect',
width = '100%',
height = '100%',
style: styleObject = {},
...otherProps
} = props

return (
<div
data-sl-skeleton
data-sl-skeleton-shape={shape}
ref={ref}
style={style({
'--sl-skeleton-width': width,
'--sl-skeleton-height': height,
...styleObject,
})}
{...otherProps}
/>
)
Expand All @@ -28,6 +40,16 @@ export interface SkeletonOptions {
* @default rect
*/
shape?: 'circle' | 'rect'
/**
* CSS width
* @default '100%'
*/
width?: CSSProperty.Width
/**
* CSS height
* @default '100%'
*/
height?: CSSProperty.Height
}

export type SkeletonProps = SkeletonOptions & ComponentPropsWithoutRef<'div'>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default {
export function Show() {
return (
<div>
<Skeleton style={{ width: 200, height: 200 }} />
<Skeleton shape="circle" style={{ width: 200, height: 200 }} />
<Skeleton width="200px" height="200px" />
<Skeleton shape="circle" width="200px" height="200px" />
</div>
)
}
8 changes: 6 additions & 2 deletions packages/shoreline/src/themes/sunrise/components/skeleton.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
}

[data-sl-skeleton] {
--sl-skeleton-width: 100%;
--sl-skeleton-height: 100%;

display: block;
position: relative;
width: 100%;
height: 100%;
width: var(--sl-skeleton-width);
height: var(--sl-skeleton-height);
background: var(--sl-bg-base-soft);
overflow: hidden;

&::after {
animation: sl-keyframes-pulse 2s ease-in-out 0.5s infinite;
background: var(--sl-bg-muted-pressed);
Expand Down

0 comments on commit 31a5232

Please sign in to comment.