Skip to content
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]: #1 Modal 전역 상태관리 #31

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import PWABadge from '~/PWABadge'
import { router } from '~/router'
import GlobalStyle from '~/styles/globalStyle'
Expand Down Expand Up @@ -28,6 +29,7 @@
<RouterProvider router={router} />
</MobileWrapper>
<PWABadge />
<ModalContainer />

Check failure on line 32 in src/App.tsx

View workflow job for this annotation

GitHub Actions / lighthouse

Cannot find name 'ModalContainer'.
</ThemeProvider>
</HelmetProvider>
</>
Expand Down
8 changes: 8 additions & 0 deletions src/modals/ModalContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as S from './styles'
import { useModalStore } from '@stores/modalStore'

Check failure on line 2 in src/modals/ModalContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lighthouse

Cannot find module '@stores/modalStore' or its corresponding type declarations.

export default function ModalContainer() {
const { modalList } = useModalStore()

return <>{modalList.length ? <S.ModalWrapper>{...modalList}</S.ModalWrapper> : null}</>

Check failure on line 7 in src/modals/ModalContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lighthouse

JSX spread child must be an array type.
}
11 changes: 11 additions & 0 deletions src/modals/ModalContainer/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { styled } from 'styled-components'

export const ModalWrapper = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100dvw;
height: 100dvh;
background-color: rgba(0, 0, 0, 0.4);
z-index: 999;
`
22 changes: 22 additions & 0 deletions src/stores/modalStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ReactNode } from 'react'
import { create } from 'zustand'

interface ModalStore {
modalList: ReactNode[]
pushModal: (modal: ReactNode) => void
popModal: () => void
clearModal: () => void
}

export const useModalStore = create<ModalStore>(set => ({
modalList: [],
pushModal: modal =>
set(state => ({
modalList: [...state.modalList, modal],
})),
popModal: () =>
set(state => ({
modalList: state.modalList.slice(0, -1),
})),
clearModal: () => set({ modalList: [] }),
}))
Loading