Skip to content

Commit

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

* feat(ui): confirm storybook 작성

* refactor(ui): 코드 간소화
  • Loading branch information
SEOKKAMONI authored Dec 27, 2023
1 parent 1f132fb commit 8b1d4f7
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 20 deletions.
18 changes: 9 additions & 9 deletions packages/design-token/src/themes/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export type Fonts = typeof fonts;
export type FontKeys = keyof typeof fonts;

export const fonts = {
h1: `font-size: 32px; font-weight: 700; line-height: 140%;`,
h2: `font-size: 24px; font-weight: 600; line-height: 140%;`,
h3: `font-size: 20px; font-weight: 600; line-height: 140%;`,
h4: `font-size: 18px; font-weight: 500; line-height: 140%;`,
body1: `font-size: 16px; font-weight: 500; line-height: 140%;`,
body2: `font-size: 14px; font-weight: 500; line-height: 140%;`,
body3: `font-size: 12px; font-weight: 500; line-height: 140%;`,
h1: `font-size: 32px; font-weight: 600; line-height: 140%;`,
h2: `font-size: 24px; font-weight: 500; line-height: 140%;`,
h3: `font-size: 20px; font-weight: 500; line-height: 140%;`,
h4: `font-size: 18px; font-weight: 400; line-height: 140%;`,
body1: `font-size: 16px; font-weight: 400; line-height: 140%;`,
body2: `font-size: 14px; font-weight: 400; line-height: 140%;`,
body3: `font-size: 12px; font-weight: 400; line-height: 140%;`,
p1: `font-size: 16px; font-weight: 400; line-height: 140%;`,
p2: `font-size: 14px; font-weight: 500; line-height: 140%;`,
p3: `font-size: 12px; font-weight: 500; line-height: 140%;`,
p2: `font-size: 14px; font-weight: 400; line-height: 140%;`,
p3: `font-size: 12px; font-weight: 400; line-height: 140%;`,
} as const;
9 changes: 5 additions & 4 deletions packages/ui/src/Button/GhostButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ const StyledGhostButton = styled.button<GhostButtonProps>`
display: flex;
justify-content: center;
align-items: center;
border-radius: 16px;
padding: 0px 16px;
border-radius: 8px;
cursor: 'pointer';
color: ${({ theme }) => theme.colors.white};
background-color: ${({ theme }) => theme.colors.gray500};
color: ${({ theme }) => theme.colors.black};
background-color: ${({ theme }) => theme.colors.gray200};
width: ${({ width }) => width};
${({ size }) => size && getButtonSize[size]}
&:hover {
background-color: ${({ theme }) => theme.colors.gray400};
background-color: ${({ theme }) => theme.colors.gray300};
}
`;
3 changes: 2 additions & 1 deletion packages/ui/src/Button/PrimaryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const StyledPrimaryButton = styled.button<PrimaryButtonProps>`
display: flex;
justify-content: center;
align-items: center;
border-radius: 16px;
padding: 0px 16px;
border-radius: 8px;
color: ${({ theme, disabled }) =>
disabled ? theme.colors.gray400 : theme.colors.white};
background-color: ${({ theme, disabled }) =>
Expand Down
56 changes: 56 additions & 0 deletions packages/ui/src/Confirm/Confirm.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { Meta, StoryObj } from '@storybook/react';
import { useState } from 'react';
import { Confirm as ConfirmComponent } from '.';

type Confirm = typeof ConfirmComponent;

const meta: Meta<Confirm> = {
component: ConfirmComponent,
title: 'Components/Confirm',
};

export default meta;

export const Default: StoryObj<Confirm> = {
args: {
title: '제목입니다.',
description: '설명입니다.',
isOpen: false,
},
render: (args) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [isOpen, setIsOpen] = useState(false);

return (
<>
<ConfirmComponent
{...args}
isOpen={isOpen}
onClose={() => {
setIsOpen(false);
}}
onConfirm={() => {
setIsOpen(false);
}}
>
<button
type="button"
onClick={() => {
setIsOpen(false);
}}
>
Close!
</button>
</ConfirmComponent>
<button
type="button"
onClick={() => {
setIsOpen(true);
}}
>
Open!
</button>
</>
);
},
};
86 changes: 86 additions & 0 deletions packages/ui/src/Confirm/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import type { ForwardedRef, ReactNode } from 'react';
import { forwardRef } from 'react';
import { Button } from '../Button';
import { Modal } from '../Modal';
import { Stack } from '../Stack';
import { Text } from '../Text';

type ConfirmProps = {
isOpen: boolean;
onClose: VoidFunction;
onConfirm: VoidFunction;
closeButtonText?: string;
confirmButtonText?: string;
title: string;
description?: string;
width?: string;
height?: string;
children: ReactNode;
};

export const Confirm = forwardRef(function Confirm(
{
isOpen,
onClose,
onConfirm,
closeButtonText = '취소',
confirmButtonText = '확인',
title,
description,
width = '600px',
height = 'auto',
children,
...props
}: ConfirmProps,
ref: ForwardedRef<HTMLDivElement>
) {
return (
<StyledConfirm ref={ref} isOpen={isOpen} width={width} height={height} {...props}>
<StyledConfirmHeader spacing={8} hasContent={Boolean(children)}>
<Text styleType="h2">{title}</Text>
{description && (
<Text styleType="p3" color="gray600">
{description}
</Text>
)}
</StyledConfirmHeader>
{children && <StyledConfirmContent>{children}</StyledConfirmContent>}
<StyledConfirmFooter>
<Stack direction="horizontal" spacing={16}>
<Button onClick={onClose} styleType="ghost" size="small">
{closeButtonText}
</Button>
<Button onClick={onConfirm} styleType="primary" size="small">
{confirmButtonText}
</Button>
</Stack>
</StyledConfirmFooter>
</StyledConfirm>
);
});

const StyledConfirm = styled(Modal)`
display: flex;
flex-direction: column;
justify-content: space-between;
`;

const StyledConfirmHeader = styled(Stack)<{ hasContent: boolean }>`
align-items: flex-start;
padding-bottom: 20px;
${({ theme, hasContent }) => css`
border-bottom: 1px solid ${hasContent && theme.colors.gray200};
`}
`;

const StyledConfirmContent = styled.div`
padding: 20px 0;
`;

const StyledConfirmFooter = styled.div`
display: flex;
align-items: center;
justify-content: flex-end;
`;
8 changes: 4 additions & 4 deletions packages/ui/src/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Input = forwardRef(function Input(
return (
<StyledInputWrapper width={width}>
{label && (
<Text color="gray600" styleType="p2">
<Text color="gray600" styleType="p3">
{label}
</Text>
)}
Expand All @@ -31,7 +31,7 @@ export const Input = forwardRef(function Input(
{bottomText && (
<Text
color={hasError ? 'red' : 'gray600'}
styleType="p2"
styleType="p3"
style={{ marginTop: '4px' }}
>
{bottomText}
Expand All @@ -56,7 +56,7 @@ const StyledInput = styled.input<InputProps>`
padding-right: 16px;
outline: none;
${({ theme, hasError }) => css`
border: 1px solid ${hasError ? theme.colors.red : theme.colors.gray400};
border: 1.5px solid ${hasError ? theme.colors.red : theme.colors.gray400};
background-color: ${theme.colors.white};
color: ${theme.colors.black};
caret-color: ${theme.colors.primary};
Expand All @@ -65,7 +65,7 @@ const StyledInput = styled.input<InputProps>`
color: ${theme.colors.gray500};
}
&:focus {
border: 1px solid ${hasError ? theme.colors.red : theme.colors.primary};
border: 1.5px solid ${hasError ? theme.colors.red : theme.colors.primary};
}
`}
`;
4 changes: 2 additions & 2 deletions packages/ui/src/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ModalProps = {
};

export const Modal = forwardRef(function Modal(
{ isOpen, width = '600px', height = 'auto', children, ...props }: ModalProps,
{ isOpen, width = '450px', height = 'auto', children, ...props }: ModalProps,
ref: ForwardedRef<HTMLDivElement>
) {
return (
Expand Down Expand Up @@ -42,7 +42,7 @@ const StyledDIM = styled.div`
const StyledModal = styled.div<{ width: string; height: string }>`
width: ${({ width }) => width};
height: ${({ height }) => height};
min-height: 350px;
min-height: 250px;
background-color: ${({ theme }) => theme.colors.white};
padding: 36px;
border-radius: 16px;
Expand Down

0 comments on commit 8b1d4f7

Please sign in to comment.