-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature/BAR-37] 토스트 컴포넌트 개발 #16
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
83d386b
feat: grid, flex에서 style 관련된 요소는 모두 className을 통해 들어오도록 변경
miro-ring 1c29a77
feat: deps 룰 제거
miro-ring 8f47476
feat: toastStore 작성
miro-ring dc9f984
feat: Toast 컴포넌트 작성
miro-ring 1035aa0
feat: Toast 테스트 환경 구축
miro-ring 9ac2157
feat: 토스트 사용 형태 변경
miro-ring 6671fe1
feat: 토스트 스토리 반영
miro-ring 7858553
feat: clearInterval 추가
miro-ring d8e015a
feat: recipe를 사용하는 형태로 변경
miro-ring 03eb959
feat: deps lint rule 추가
miro-ring e7ee68c
refactor: message 변경
miro-ring 27b0475
feat: 잘못 추가된 파일 제거
miro-ring 6d2b8eb
feat: 두 종류의 토스트 duration 반영
miro-ring 2f85851
feat: toast story 작성
miro-ring adc1cb0
fix: lintstage 실행시 bash 추가
miro-ring 96d1358
refactor: 스토리명 변경
miro-ring c7ee38a
feat: style 사용 변경
miro-ring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"*.{js,jsx,ts,tsx}": ["prettier --write", "eslint --fix"], | ||
"*.{ts,tsx}": "tsc --noEmit" | ||
"*.{ts,tsx}": "bash -c tsc --noEmit" | ||
} |
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import type { NextPage } from 'next'; | ||
|
||
const HomePage: NextPage = () => { | ||
return <>바로</>; | ||
const HomePage = () => { | ||
return <div>바로</div>; | ||
}; | ||
|
||
export default HomePage; |
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,61 @@ | ||
import { useEffect } from 'react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { TOAST_DURATION_TIME } from '@/src/models/toastModel'; | ||
import { useToast } from '@/src/stores/toastStore'; | ||
|
||
import Toast from './Toast'; | ||
|
||
const meta: Meta<typeof Toast> = { | ||
title: 'Toast', | ||
component: Toast, | ||
decorators: [ | ||
(Story) => ( | ||
<div style={{ height: '500px' }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Toast>; | ||
|
||
export const Basic: Story = { | ||
render: function Render() { | ||
const { showToast } = useToast(); | ||
|
||
useEffect(() => { | ||
showToast({ message: '테스트', type: TOAST_DURATION_TIME.SHOW }); | ||
|
||
const interval = setInterval( | ||
() => showToast({ message: '테스트', type: TOAST_DURATION_TIME.SHOW }), | ||
TOAST_DURATION_TIME.SHOW + 1000, | ||
); | ||
|
||
return () => clearInterval(interval); | ||
}, [showToast]); | ||
|
||
return <Toast />; | ||
}, | ||
}; | ||
|
||
export const WithAction: Story = { | ||
render: function Render() { | ||
const { showToast } = useToast(); | ||
|
||
useEffect(() => { | ||
showToast({ message: '테스트', type: TOAST_DURATION_TIME.ACTION }); | ||
|
||
const interval = setInterval( | ||
() => | ||
showToast({ message: '테스트', type: TOAST_DURATION_TIME.ACTION }), | ||
TOAST_DURATION_TIME.ACTION + 1000, | ||
); | ||
|
||
return () => clearInterval(interval); | ||
}, [showToast]); | ||
|
||
return <Toast />; | ||
}, | ||
}; |
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,29 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useToast } from '@/src/stores/toastStore'; | ||
|
||
import * as styles from './style.css'; | ||
|
||
const Toast = () => { | ||
const { toastData, hideToast } = useToast(); | ||
|
||
const { message, type, isToastVisible } = toastData; | ||
|
||
useEffect(() => { | ||
let timer; | ||
|
||
if (isToastVisible) { | ||
timer = setTimeout(() => hideToast(), type); | ||
} | ||
|
||
return () => clearTimeout(timer); | ||
}, [hideToast, isToastVisible, type]); | ||
|
||
return ( | ||
<div className={styles.toast({ isActive: isToastVisible })} role="alert"> | ||
<span>{message}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Toast; |
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,36 @@ | ||
import { recipe } from '@vanilla-extract/recipes'; | ||
|
||
import { sprinkles } from '@/src/styles/sprinkles.css'; | ||
import { theme } from '@/src/styles/theme.css'; | ||
import { modalLayer } from '@/src/styles/utils.css'; | ||
|
||
export const toast = recipe({ | ||
base: [ | ||
modalLayer, | ||
sprinkles({ | ||
typography: '14/Body/Regular', | ||
}), | ||
{ | ||
backgroundColor: theme.colors['Dim/70'], | ||
position: 'fixed', | ||
color: theme.colors['Grey/White'], | ||
bottom: 0, | ||
left: '50%', | ||
transform: 'translateX(-50%) translateY(30px)', | ||
borderRadius: '6px', | ||
textAlign: 'center', | ||
padding: '23px 32px', | ||
transition: 'transform 400ms ease, opacity 400ms', | ||
opacity: 0, | ||
pointerEvents: 'none', | ||
}, | ||
], | ||
variants: { | ||
isActive: { | ||
true: { | ||
opacity: 1, | ||
transform: 'translateX(-50%) translateY(-30px)', | ||
}, | ||
}, | ||
}, | ||
}); |
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,7 @@ | ||
export const TOAST_DURATION_TIME = { | ||
SHOW: 3500, | ||
ACTION: 5000, | ||
} as const; | ||
|
||
export type ToastDurationTime = | ||
(typeof TOAST_DURATION_TIME)[keyof typeof TOAST_DURATION_TIME]; |
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,55 @@ | ||
import { createStore } from 'zustand'; | ||
import { shallow } from 'zustand/shallow'; | ||
import { useStoreWithEqualityFn as useStore } from 'zustand/traditional'; | ||
|
||
import { | ||
TOAST_DURATION_TIME, | ||
type ToastDurationTime, | ||
} from '../models/toastModel'; | ||
|
||
interface ToastData { | ||
message: string; | ||
type: ToastDurationTime; | ||
} | ||
|
||
interface ToastState { | ||
isToastVisible: boolean; | ||
} | ||
|
||
interface State { | ||
toastData: ToastData & ToastState; | ||
} | ||
|
||
interface Action { | ||
showToast: (data: ToastData) => void; | ||
hideToast: () => void; | ||
} | ||
|
||
const INITIAL_TOAST_DATA = { | ||
message: '', | ||
type: TOAST_DURATION_TIME.SHOW, | ||
isToastVisible: false, | ||
}; | ||
|
||
export const toastStore = createStore<State & Action>((set, get) => ({ | ||
toastData: INITIAL_TOAST_DATA, | ||
showToast: (data) => set({ toastData: { ...data, isToastVisible: true } }), | ||
hideToast: () => { | ||
set({ toastData: { ...get().toastData, isToastVisible: false } }); | ||
}, | ||
})); | ||
|
||
const useToastStore = <T>( | ||
selector: (state: State & Action) => T, | ||
equals?: (a: T, b: T) => boolean, | ||
) => useStore(toastStore, selector, equals); | ||
|
||
export const useToast = () => | ||
useToastStore( | ||
(state) => ({ | ||
toastData: state.toastData, | ||
showToast: state.showToast, | ||
hideToast: state.hideToast, | ||
}), | ||
shallow, | ||
); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create가 아니라 createStore는 어떤 걸까요..? 문서에서 찾지 못했어요ㅜㅜ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/pmndrs/zustand?tab=readme-ov-file#using-zustand-without-react
요쪽에 내용이 있습니다!