-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(ui): Skeleton 컴포넌트 구현 #178
Merged
+2,536
−5,986
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8aa454e
chore : add radix/theme
Brokyeom b5380ff
chore: install radix-ui/themes
Brokyeom 39ad242
feat: publish Skeleton component
Brokyeom 6ac1665
cs
Brokyeom d88bfc2
Merge branch 'main' into feat/ui-skeleton
Brokyeom 9224838
chore: remove radix-ui/themes
Brokyeom 3801ad1
feat: publish Skeleton Component.
Brokyeom 22f2b31
docs: Add Skeleton Storybook Docs.
Brokyeom 1b23b5d
feat: children 여부에 따라 자동으로 크기 조절, JSDdoc 작성
Brokyeom 23f1a8a
publish storybook
Brokyeom 968efba
fix story name
Brokyeom 7e0b16c
Merge branch 'main' into feat/ui-skeleton
Brokyeom 02bcc5c
chore: upgrade chromatic
Brokyeom 3108849
fix: migrate eslint config file (https://eslint.org/docs/latest/use/c…
Brokyeom 951413c
fix
Brokyeom fb85ded
fix: eslint script and setting
Brokyeom 4521364
fix: file name
Brokyeom 9311c49
Merge branch 'main' into feat/ui-skeleton
Brokyeom 9b97c0e
Merge branch 'main' into feat/ui-skeleton
Brokyeom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sopt-makers/ui': minor | ||
--- | ||
|
||
Add Skeleton Component. |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
files: ['**/*.ts', '**/*.tsx'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
'plugin:storybook/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], | ||
}, | ||
}; |
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
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,37 @@ | ||
import { Skeleton, SkeletonProps, Button as MDSButton, Toggle } from '@sopt-makers/ui'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta: Meta = { | ||
title: 'Components/Skeleton', | ||
component: Skeleton, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<SkeletonProps> = { | ||
render: () => { | ||
return <Skeleton width={300} height={48} variant='default' />; | ||
}, | ||
}; | ||
|
||
export const Circular: StoryObj<SkeletonProps> = { | ||
render: () => { | ||
return <Skeleton width={40} height={40} variant='circular' />; | ||
}, | ||
}; | ||
|
||
export const HasChildren: StoryObj<SkeletonProps> = { | ||
render: () => { | ||
return ( | ||
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}> | ||
<Skeleton> | ||
<MDSButton>버튼버튼버튼</MDSButton> | ||
</Skeleton> | ||
<Skeleton> | ||
<Toggle /> | ||
</Skeleton> | ||
</div> | ||
); | ||
}, | ||
}; |
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,53 @@ | ||
import { forwardRef } from 'react'; | ||
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> { | ||
/** | ||
* ### 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 = 'default', children, ...restProps } = props; | ||
|
||
const styleClass = createSkeletonStyle(variant); | ||
|
||
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
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 @@ | ||
export * from './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,39 @@ | ||
import { colors } from '@sopt-makers/colors'; | ||
import { keyframes, style, globalStyle } 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`, | ||
}); | ||
|
||
export const hasChildren = style({ | ||
maxWidth: 'fit-content', | ||
height: 'auto', | ||
}); | ||
|
||
globalStyle(`${hasChildren} > *`, { | ||
visibility: 'hidden', | ||
}); | ||
|
||
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; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
variant가
circular
인 case와rounded
인 case의 차이가 있을까요?? 지금 variant로 분기되는 스타일이 radius밖에 없어보이는데, 두 case의 radius 값이 동일해서 혹시 다른 차이가 있는지 궁금해요!!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.
cricular
: 높이, 너비가 같은 원형rounded
: 높이, 너비가 다를 경우에 사용되는 스타일 (e.g. button rounded lg)의 용도로 구분해두긴 했습니다. (레퍼런스)
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.
추후에 variant 에 따라서 스타일이 달리질 것을 염두해서 분리해두려는 목적도 있습니다!