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

style: useToast 커스텀 훅 제작 #48

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion src/components/common/BottomSheet/RandomMatchingSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AnimatePresence, motion } from 'framer-motion'
import { MouseEvent, useState } from 'react'
import { AiOutlineClose } from 'react-icons/ai'

import RandomMatchingJoinButton from '@/components/common/Buttons/IconButton/RandomMatchingJoin'
import RandomMatchingJoinButton from '@/components/common/Buttons/IconButton/RandomMatchingJoinButton'
import { Text } from '@/components/common/Text'
import { palette } from '@/styles/palette'

Expand Down
158 changes: 0 additions & 158 deletions src/components/common/BottomSheet/index.tsx

This file was deleted.

61 changes: 0 additions & 61 deletions src/components/common/Buttons/IconButton/RandomMatchingJoin.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +0,0 @@
import { BiChevronRight } from 'react-icons/bi'

import { Text, TextWrapper } from '@/components/common/Text'

import { StyleIconButtonWrapper, StyleIconWrapper } from '.'

type RandomMatchingJoinButtonProps = {
isDarkMode: boolean
moveToRandomMatching: () => void
}

const RandomMatchingJoinButton = ({
isDarkMode,
moveToRandomMatching,
}: RandomMatchingJoinButtonProps) => {
const setButtonType = isDarkMode ? 'random-matching-join-dark' : 'random-matching-join'

return (
<StyleIconButtonWrapper
iconButtonType={setButtonType}
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
onClick={moveToRandomMatching}
>
<TextWrapper
style={{
flex: 1,
}}
>
<Text
font={'Body_16'}
fontWeight={500}
letterSpacing={-2}
style={{
width: '100%',
textAlign: 'right',
}}
>
{'매칭방에 접속해주세요!'}
</Text>
</TextWrapper>
<StyleIconWrapper
style={{
margin: '18px 5px 18px 40px',
}}
>
<BiChevronRight
style={{
width: 30,
height: 30,
}}
/>
</StyleIconWrapper>
</StyleIconButtonWrapper>
)
}

export default RandomMatchingJoinButton
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { BiChevronRight } from 'react-icons/bi'

import { Text, TextWrapper } from '@/components/common/Text'

import { StyleIconButtonWrapper, StyleIconWrapper } from '.'

type RandomMatchingJoinButtonProps = {
isDarkMode: boolean
moveToRandomMatching: () => void
}

const RandomMatchingJoinButton = ({
isDarkMode,
moveToRandomMatching,
}: RandomMatchingJoinButtonProps) => {
const setButtonType = isDarkMode ? 'random-matching-join-dark' : 'random-matching-join'

return (
<StyleIconButtonWrapper
iconButtonType={setButtonType}
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
onClick={moveToRandomMatching}
>
<TextWrapper
style={{
flex: 1,
}}
>
<Text
font={'Body_16'}
fontWeight={500}
letterSpacing={-2}
style={{
width: '100%',
textAlign: 'right',
}}
>
{'매칭방에 접속해주세요!'}
</Text>
</TextWrapper>
<StyleIconWrapper
style={{
margin: '18px 5px 18px 40px',
}}
>
<BiChevronRight
style={{
width: 30,
height: 30,
}}
/>
</StyleIconWrapper>
</StyleIconButtonWrapper>
)
}

export default RandomMatchingJoinButton
28 changes: 18 additions & 10 deletions src/components/common/Buttons/NormalButton/NormalButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ import { NormalButtonStyles, NormalButtonType } from './NormalButtonStyles'

const NormalButton = styled.button<{
normalButtonType: NormalButtonType
isDarkMode: boolean
}>`
${({ normalButtonType }) => {
const fontFunc = typo[NormalButtonStyles[normalButtonType].font]
${({ normalButtonType, isDarkMode }) => {
const processedTypeKey = isDarkMode ? `${normalButtonType}-dark` : normalButtonType
const processedType = (
NormalButtonStyles[processedTypeKey as NormalButtonType] ? processedTypeKey : normalButtonType
) as NormalButtonType

console.log(processedType)

const fontFunc = typo[NormalButtonStyles[processedType].font]
return css`
${fontFunc(
NormalButtonStyles[normalButtonType].fontWeight,
NormalButtonStyles[normalButtonType].letterSpacing,
NormalButtonStyles[processedType].fontWeight,
NormalButtonStyles[processedType].letterSpacing,
)}
width: ${NormalButtonStyles[normalButtonType].width}px;
height: ${NormalButtonStyles[normalButtonType].height}px;
color: ${NormalButtonStyles[normalButtonType].fontColor};
background-color: ${NormalButtonStyles[normalButtonType].backgroundColor};
box-shadow: ${NormalButtonStyles[normalButtonType].boxShadow};
border-radius: ${NormalButtonStyles[normalButtonType].borderRadius}px;
width: ${NormalButtonStyles[processedType].width}px;
height: ${NormalButtonStyles[processedType].height}px;
color: ${NormalButtonStyles[processedType].fontColor};
background-color: ${NormalButtonStyles[processedType].backgroundColor};
box-shadow: ${NormalButtonStyles[processedType].boxShadow};
border-radius: ${NormalButtonStyles[processedType].borderRadius}px;
`
}}
`
Expand Down
4 changes: 4 additions & 0 deletions src/components/layouts/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'react-toastify/dist/ReactToastify.css'

import styled from '@emotion/styled'
import { Outlet } from 'react-router-dom'
import { ToastContainer } from 'react-toastify'

import { theme } from '@/styles/theme'

const Layout = () => {
return (
<MainContainer>
<Outlet />
<ToastContainer />
</MainContainer>
)
}
Expand Down
25 changes: 25 additions & 0 deletions src/hooks/useToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ReactNode } from 'react'
import { toast } from 'react-toastify'

type ToastType = 'success' | 'error' | 'info' | 'warning'

type ToastProps = {
message: string | ReactNode
type: ToastType
isDarkMode: boolean
}

export const useToast = () => {
const showToast = ({ message, type, isDarkMode }: ToastProps) => {
toast(message, {
position: 'top-center',
draggable: true,
theme: isDarkMode ? 'dark' : 'light',
type,
})
}

return { showToast }
}

export default useToast