-
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.
feat: children 여부에 따라 자동으로 크기 조절, JSDdoc 작성
- Loading branch information
Showing
2 changed files
with
51 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,20 +1,53 @@ | ||
import type { HTMLAttributes } from 'react'; | ||
import { forwardRef } from 'react'; | ||
import { root } from './style.css'; | ||
import type { HTMLAttributes } from 'react'; | ||
import { root, hasChildren } from './style.css'; | ||
import createSkeletonStyle from './utils'; | ||
import type { SkeletonVariant } from './types'; | ||
|
||
export interface SkeletonProps extends HTMLAttributes<HTMLSpanElement> { | ||
width: number | string; | ||
height: number | string; | ||
variant: 'default' | 'circular' | 'rounded'; | ||
/** | ||
* ### Skeleton의 너비를 수동으로 지정할 떄 사용합니다. | ||
*/ | ||
width?: number | string; | ||
/** | ||
* ### Skeleton의 높이를 수동으로 지정할 떄 사용합니다. | ||
*/ | ||
height?: number | string; | ||
/** | ||
* ### `default` | `circular` | `rounded` 의 세 가지 값을 가집니다. | ||
* @example | ||
* default - borderRadius : '12px' | ||
* circular && rounded - borderRadius: '100%' | ||
*/ | ||
variant?: SkeletonVariant; | ||
/** | ||
* ### children prop을 사용할 경우 스켈레톤의 사이즈가 자식 요소에 맞춰집니다. | ||
* @example | ||
* ```tsx | ||
* // width: 'fit-content', height: 'auto' | ||
* <Skeleton> | ||
* <Toggle /> | ||
* </Skeleton> | ||
* ``` | ||
*/ | ||
children?: React.ReactNode; | ||
} | ||
|
||
export const Skeleton = forwardRef<HTMLSpanElement, SkeletonProps>((props, forwardedRef) => { | ||
const { width, height, variant, ...restProps } = props; | ||
const { width, height, variant = 'default', children, ...restProps } = props; | ||
|
||
const style = createSkeletonStyle(variant); | ||
const styleClass = createSkeletonStyle(variant); | ||
|
||
return <span className={`${root} ${style}`} ref={forwardedRef} style={{ width, height }} {...restProps} />; | ||
return ( | ||
<span | ||
className={`${root} ${styleClass} ${children ? hasChildren : ''}`} | ||
ref={forwardedRef} | ||
style={{ width, height }} | ||
{...restProps} | ||
> | ||
{children} | ||
</span> | ||
); | ||
}); | ||
|
||
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