-
- 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;
}