diff --git a/src/components/Toast/HookSource.md b/src/components/Toast/HookSource.md index 680d789..1a1a9a7 100644 --- a/src/components/Toast/HookSource.md +++ b/src/components/Toast/HookSource.md @@ -1,4 +1,4 @@ -```typescript +```tsx import { ToastDuration, useToast, Toast } from '@yourssu/design-system-react'; const ToastWrapper = () => { @@ -11,7 +11,14 @@ const ToastWrapper = () => { return (
- + {isShowToast && }
); diff --git a/src/components/Toast/Toast.stories.tsx b/src/components/Toast/Toast.stories.tsx index c478976..3824a7e 100644 --- a/src/components/Toast/Toast.stories.tsx +++ b/src/components/Toast/Toast.stories.tsx @@ -1,11 +1,10 @@ -import { Stories, Primary as PrimaryBlock, Controls, Title, Markdown } from '@storybook/blocks'; +import { Primary as PrimaryBlock, Controls, Title, Markdown } from '@storybook/blocks'; import { Meta, StoryObj } from '@storybook/react'; import { useToast } from '@/hooks/useToast'; import HookSource from './HookSource.md?raw'; import { Toast } from './Toast'; -import { ToastDuration } from './Toast.type'; const meta: Meta = { title: 'Component/Toast', @@ -20,18 +19,12 @@ const meta: Meta = {

주의사항

    -
  1. Toast의 width는 Toast 를 감싸는 컴포넌트의 width에 영향을 받습니다.
  2. -
  3. - Toast의 위치는 position: relative 속성이 설정된 가장 가까운 부모 컴포넌트에 의해 - 결정됩니다. -
  4. +
  5. width props 값이 fit-content보다 작을 경우 적용되지 않습니다.

useToast Toast 컴포넌트를 사용하기 위한 Custom Hook입니다. {HookSource} -
- ), }, @@ -41,48 +34,36 @@ export default meta; const ToastStory = ({ ...toastProps }) => { return ( -
-
- short duration toast (1.5s) - -
-
- long duration toast (3s) - -
+
+
); }; -const HookTest = () => { - const toastProps = { - children: 'useToast를 사용한 토스트 메시지', - duration: 'long' as ToastDuration, - }; +const HookTest = ({ ...toastProps }) => { const { showToast, isShowToast } = useToast(); return (
{isShowToast && }
@@ -90,18 +71,25 @@ const HookTest = () => { }; type Story = StoryObj; +export const ToastHook: Story = { + render: HookTest, + args: { + children: 'useToast를 사용한 토스트 메시지', + duration: 'long', + }, +}; export const SingleLine: Story = { args: { children: '토스트 메시지', + duration: 'short', + width: '300px', }, render: ToastStory, }; export const MultiLine: Story = { args: { - children: '줄 수가 두 줄 이상이 되는 토스트 메시지입니다. 좌측 정렬을 해주세요.', + children: '줄 수가 두 줄 이상이 되는 토스트 메시지입니다.\n좌측 정렬을 해주세요.', + duration: 'short', }, render: ToastStory, }; -export const ToastHook: Story = { - render: HookTest, -}; diff --git a/src/components/Toast/Toast.style.ts b/src/components/Toast/Toast.style.ts index 37f7a27..2c3a926 100644 --- a/src/components/Toast/Toast.style.ts +++ b/src/components/Toast/Toast.style.ts @@ -1,9 +1,10 @@ import { css, keyframes, styled } from 'styled-components'; -import { ToastDuration } from './Toast.type'; +import { ToastDuration, ToastProps } from './Toast.type'; interface StyledToastProps { $duration: ToastDuration; + $width: ToastProps['width']; } const SHORT_DURATION = 1.5; @@ -40,22 +41,35 @@ const setToastAnimation = ($duration: ToastDuration) => { }; export const StyledToastWrapper = styled.div` - position: absolute; - bottom: 66px; + position: fixed; + inset: 0px; width: 100%; + height: 100%; padding: 0px 8px; + + display: flex; + justify-content: center; + + pointer-events: none; `; export const StyledToast = styled.div` - opacity: 0; - border-radius: 8px; - width: 100%; - padding: 16px 24px; + position: absolute; + bottom: 66px; + min-width: fit-content; + width: ${({ $width }) => $width}; + max-width: 100%; + display: flex; justify-content: center; + padding: 16px 24px; + opacity: 0; + background-color: ${({ theme }) => theme.color.toastBG}; + border-radius: 8px; color: ${({ theme }) => theme.color.textBright}; ${({ theme }) => theme.typo.body2}; + white-space: pre-line; ${({ $duration }) => setToastAnimation($duration)}; `; diff --git a/src/components/Toast/Toast.tsx b/src/components/Toast/Toast.tsx index 3f7a519..3065180 100644 --- a/src/components/Toast/Toast.tsx +++ b/src/components/Toast/Toast.tsx @@ -1,12 +1,12 @@ import { StyledToast, StyledToastWrapper } from './Toast.style'; import { ToastProps } from './Toast.type'; -export const Toast = ({ children, duration = 'short', ...props }: ToastProps) => { +export const Toast = ({ children, duration = 'short', width, ...props }: ToastProps) => { if (!children) return; return ( - + {children} diff --git a/src/components/Toast/Toast.type.ts b/src/components/Toast/Toast.type.ts index 3d3b12d..aec2e12 100644 --- a/src/components/Toast/Toast.type.ts +++ b/src/components/Toast/Toast.type.ts @@ -5,4 +5,6 @@ export interface ToastProps extends React.HTMLAttributes { children?: React.ReactNode; /** 지속 시간 (1.5s | 3s)*/ duration?: ToastDuration; + /** Toast의 width */ + width?: string; }