Skip to content

Commit

Permalink
feat(ui): center 컴포넌트 개발 (#113)
Browse files Browse the repository at this point in the history
* feat(ui): center 컴포넌트 개발

* feat(ui): center storybook 작성

* chore(ui): 리뷰 반영
  • Loading branch information
lsj0202 authored Dec 27, 2023
1 parent 8b1d4f7 commit 14a037b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/ui/src/Center/Center.stories.tsx
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>
),
};
29 changes: 29 additions & 0 deletions packages/ui/src/Center/index.tsx
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;
`;

0 comments on commit 14a037b

Please sign in to comment.