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: WhiteSelectorButton, DarkSelectorButton 공통 컴포넌트 #46

Merged
merged 6 commits into from
Oct 27, 2023
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
75 changes: 75 additions & 0 deletions src/components/common/DarkSelectorButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import styled from '@emotion/styled'
import { useState } from 'react'

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

type ToggleButtonProps = {
buttonName: string
selectedButtonColor: string
defaultButtonColor?: string
selectedTextColor: string
onClick?: () => void
}

type StyledButtonProps = {
backgroundColor: string
textColor: string
}

const DarkSelectorButton = ({
buttonName,
selectedButtonColor,
defaultButtonColor = palette.WHITE,
selectedTextColor = palette.SECONDARY,
onClick,
}: ToggleButtonProps) => {
const [backgroundColor, setBackgroundColor] = useState(defaultButtonColor)
const [textColor, setTextColor] = useState(palette.SECONDARY) // 텍스트 색상에 대한 state

const handleButtonClick = () => {
setBackgroundColor((prevColor) => {
if (prevColor === defaultButtonColor) {
setTextColor(selectedTextColor)
return selectedButtonColor
} else {
setTextColor(palette.SECONDARY)
return defaultButtonColor
}
})
if (onClick) onClick()
}

return (
<StyledButton
backgroundColor={backgroundColor}
textColor={textColor}
onClick={handleButtonClick}
>
{buttonName}
</StyledButton>
)
}

const StyledButton = styled.button<StyledButtonProps>`
margin: 0 4px;
height: 36px;
padding: 10px 15px 10px 15px;
font-size: 12px;
cursor: pointer;
border: none;
border-radius: 10px;
background-color: ${(props) => props.backgroundColor};
transition: background-color 0.3s;
&:hover {
opacity: 0.9;
}
&:focus {
outline: none;
}
color: ${(props) => props.textColor};
display: inline-block;
vertical-align: middle;
line-height: 1;
`
wukdddang marked this conversation as resolved.
Show resolved Hide resolved

export default DarkSelectorButton
61 changes: 61 additions & 0 deletions src/components/common/WhiteSelectorButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import styled from '@emotion/styled'
import { useState } from 'react'

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

type ToggleButtonProps = {
buttonName: string
selectedButtonColor: string
defaultButtonColor?: string
onClick?: () => void
}

type StyledButtonProps = {
backgroundColor: string
}

const WhiteSelectorButton = ({
buttonName,
selectedButtonColor,
defaultButtonColor = palette.TERTIARY,
onClick,
}: ToggleButtonProps) => {
const [backgroundColor, setBackgroundColor] = useState(defaultButtonColor)

const handleButtonClick = () => {
setBackgroundColor((prevColor) =>
prevColor === defaultButtonColor ? selectedButtonColor : defaultButtonColor,
)
if (onClick) onClick()
}

return (
<StyledButton backgroundColor={backgroundColor} onClick={handleButtonClick}>
{buttonName}
</StyledButton>
)
}

const StyledButton = styled.button<StyledButtonProps>`
margin: 0 4px;
height: 36px;
padding: 10px 15px 10px 15px;
font-size: 12px;
cursor: pointer;
border: none;
border-radius: 10px;
background-color: ${(props) => props.backgroundColor};
transition: background-color 0.3s;
&:hover {
opacity: 0.9;
}
&:focus {
outline: none;
}
color: ${palette.WHITE};
display: inline-block;
vertical-align: middle;
line-height: 1;
`
wukdddang marked this conversation as resolved.
Show resolved Hide resolved

export default WhiteSelectorButton