-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import type { HTMLAttributes, ReactNode } from 'react'; | ||
import type { HTMLAttributes } from 'react'; | ||
import { forwardRef } from 'react'; | ||
import { root } from './style.css'; | ||
import createSkeletonStyle from './utils'; | ||
|
||
export interface SkeletonProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> { | ||
children: ReactNode; | ||
export interface SkeletonProps extends HTMLAttributes<HTMLSpanElement> { | ||
width: number | string; | ||
height: number | string; | ||
variant: 'circular' | 'rectangular' | 'rounded' | 'text'; | ||
animation: 'pulse' | 'wave'; | ||
variant: 'default' | 'circular' | 'rounded'; | ||
} | ||
|
||
export const Skeleton = forwardRef<HTMLSpanElement, SkeletonProps>((props, forwardedRef) => { | ||
const { children, ...restProps } = props; | ||
const { width, height, variant, ...restProps } = props; | ||
|
||
return ( | ||
<span ref={forwardedRef} {...restProps}> | ||
{children} | ||
</span> | ||
); | ||
const style = createSkeletonStyle(variant); | ||
|
||
return <span className={`${root} ${style}`} ref={forwardedRef} style={{ width, height }} {...restProps} />; | ||
}); | ||
|
||
Skeleton.displayName = 'Skeleton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { SkeletonVariant } from './types'; | ||
|
||
const SkeletonBorderRadius: Record<SkeletonVariant, string> = { | ||
default: '12px', | ||
circular: '100%', | ||
rounded: '100%', | ||
}; | ||
|
||
export default SkeletonBorderRadius; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { colors } from '@sopt-makers/colors'; | ||
import { keyframes, style } from '@vanilla-extract/css'; | ||
import { createSprinkles, defineProperties } from '@vanilla-extract/sprinkles'; | ||
import SkeletonBorderRadius from './constants'; | ||
|
||
const pulseKeyframe = keyframes({ | ||
'0%': { | ||
opacity: 1, | ||
}, | ||
|
||
'50%': { | ||
opacity: 0.4, | ||
}, | ||
|
||
'100%': { | ||
opacity: 1, | ||
}, | ||
}); | ||
|
||
export const root = style({ | ||
display: 'block', | ||
backgroundColor: colors.gray700, | ||
animation: `${pulseKeyframe} 2s ease-in-out 0.5s infinite`, | ||
}); | ||
|
||
const sprinkleProperties = defineProperties({ | ||
properties: { | ||
borderRadius: SkeletonBorderRadius, | ||
}, | ||
}); | ||
|
||
export const sprinkles = createSprinkles(sprinkleProperties); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type SkeletonVariant = 'default' | 'circular' | 'rounded'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { sprinkles } from './style.css'; | ||
import type { SkeletonVariant } from './types'; | ||
|
||
const createSkeletonStyle = (variant: SkeletonVariant) => { | ||
return sprinkles({ borderRadius: variant }); | ||
}; | ||
|
||
export default createSkeletonStyle; |