-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(ui): center 컴포넌트 개발 * feat(ui): center storybook 작성 * chore(ui): 리뷰 반영
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { Center as CenterComponent } from '.'; | ||
|
||
type Center = typeof CenterComponent; | ||
|
||
const meta: Meta<Center> = { | ||
argTypes: { | ||
tag: { | ||
control: 'select', | ||
option: ['div', 'span', 'button'], | ||
}, | ||
}, | ||
component: CenterComponent, | ||
title: 'Components/Center', | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<Center> = { | ||
render: (args) => ( | ||
<CenterComponent {...args}> | ||
<div style={{ width: '80px', height: '80px', backgroundColor: 'pink' }} /> | ||
</CenterComponent> | ||
), | ||
}; |
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,29 @@ | ||
import styled from '@emotion/styled'; | ||
import type { ElementType, ForwardedRef, HTMLAttributes } from 'react'; | ||
import { forwardRef } from 'react'; | ||
|
||
export type CenterProps = { | ||
tag?: ElementType; | ||
width?: string; | ||
height?: string; | ||
} & HTMLAttributes<HTMLDivElement>; | ||
|
||
export const Center = forwardRef(function Center( | ||
{ tag = 'div', children, width = '100%', height = '100%', ...props }: CenterProps, | ||
ref: ForwardedRef<HTMLDivElement> | ||
) { | ||
return ( | ||
<StyledCenter ref={ref} as={tag} width={width} height={height} {...props}> | ||
{children} | ||
</StyledCenter> | ||
); | ||
}); | ||
|
||
const StyledCenter = styled.div<CenterProps>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: ${({ width }) => width}; | ||
height: ${({ height }) => height}; | ||
text-align: center; | ||
`; |