-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: Snackbar 컴포넌트 구현 및 스토리 작성
- Loading branch information
Showing
11 changed files
with
160 additions
and
15 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
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
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
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,46 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import Snackbar from '.' | ||
import useUIStore from '@/store/useUIStore' | ||
import { SNACKBAR_TYPE } from '@/constants/snackbar' | ||
|
||
const meta: Meta<typeof Snackbar> = { | ||
title: 'components/Snackbar', | ||
component: Snackbar, | ||
tags: ['autodocs'], | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof Snackbar> | ||
|
||
export const Default: Story = { | ||
render: () => { | ||
const { showSnackbar } = useUIStore() | ||
const buttons = [ | ||
{ type: 'commentAdd', text: '댓글 등록' }, | ||
{ type: 'commentEdit', text: '댓글 수정' }, | ||
{ type: 'commentDelete', text: '댓글 삭제' }, | ||
{ type: 'commentReport', text: '댓글 신고' }, | ||
{ type: 'commentBlock', text: '댓글 차단' }, | ||
{ type: 'bookmarkAdd', text: '용어 북마크' }, | ||
] | ||
return ( | ||
<> | ||
<div className="h-48 flex flex-col"> | ||
<div className="flex gap-2"> | ||
{buttons.map((button, idx) => ( | ||
<button | ||
key={idx} | ||
onClick={() => showSnackbar(button.type as SNACKBAR_TYPE)} | ||
className="w-fit p-2 bg-white rounded-lg" | ||
> | ||
{button.text} | ||
</button> | ||
))} | ||
</div> | ||
<Snackbar /> | ||
</div> | ||
</> | ||
) | ||
}, | ||
} |
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,31 @@ | ||
'use client' | ||
import { SNACKBAR } from '@/constants/snackbar' | ||
import useUIStore from '@/store/useUIStore' | ||
import { useEffect } from 'react' | ||
|
||
export default function Snackbar() { | ||
const { snackbarType, showSnackbar } = useUIStore() | ||
|
||
useEffect(() => { | ||
showSnackbar(snackbarType) | ||
const timer = setTimeout(() => { | ||
showSnackbar(null) | ||
}, 2500) | ||
|
||
return () => clearTimeout(timer) | ||
}, [snackbarType, showSnackbar]) | ||
|
||
if (!snackbarType) return null | ||
return ( | ||
<div className="fixed bottom-10 left-1/2 transform -translate-x-1/2 w-full max-w-[430px]"> | ||
<div className="flex justify-between items-center bg-gray-600 text-center py-4 px-7 rounded-lg mx-4 animate-fade-in"> | ||
<p className="text-onSurface-300 text-sub2"> | ||
{SNACKBAR[snackbarType].text} | ||
</p> | ||
<p className="text-sub3 text-primary-400"> | ||
{SNACKBAR[snackbarType].actionText} | ||
</p> | ||
</div> | ||
</div> | ||
) | ||
} |
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
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,35 @@ | ||
export type SNACKBAR_TYPE = | ||
| 'commentAdd' | ||
| 'commentEdit' | ||
| 'commentDelete' | ||
| 'commentBlock' | ||
| 'commentReport' | ||
| 'bookmarkAdd' | ||
|
||
export const SNACKBAR: Record< | ||
SNACKBAR_TYPE, | ||
{ text: string; actionText?: string } | ||
> = { | ||
commentAdd: { | ||
text: '댓글이 등록되었어요', | ||
}, | ||
commentEdit: { | ||
text: '댓글이 수정되었어요', | ||
}, | ||
commentDelete: { | ||
text: '댓글이 삭제되었어요', | ||
}, | ||
|
||
commentBlock: { | ||
text: '댓글이 차단되었어요', | ||
actionText: '실행취소', | ||
}, | ||
|
||
commentReport: { | ||
text: '댓글이 신고되었어요', | ||
}, | ||
bookmarkAdd: { | ||
text: '⭐️ 별별 저장소에 등록되었어요', | ||
actionText: '저장소 가기', | ||
}, | ||
} |
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,19 @@ | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function useSnackbarAction() { | ||
const router = useRouter() | ||
|
||
const undoCommentBlock = () => { | ||
alert('댓글 차단 실행 취소') | ||
} | ||
|
||
const goToBookmark = () => { | ||
alert('저장소 보러가기') | ||
router.push('/bookmarks') | ||
} | ||
|
||
return [ | ||
{ type: 'commentBlock', onClick: undoCommentBlock }, | ||
{ type: 'bookmarkAdd', onClick: goToBookmark }, | ||
] | ||
} |
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
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
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