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: CustomSelectorButton 공통 컴포넌트 #71

Merged
merged 12 commits into from
Nov 8, 2023
1 change: 1 addition & 0 deletions src/components/common/BusinessCardContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const CameraIcon = styled.img`
width: 38px;
height: 38px;
`

const UploadLabel = styled.label`
cursor: pointer;
`
Expand Down
24 changes: 12 additions & 12 deletions src/components/common/CustomSelectorButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import { palette } from '@/styles/palette'
type CustomSelectorButtonProps = {
isDarkMode: boolean
buttonName: string
onClick: (selected: boolean) => void
isButtonClicked: (selected: boolean) => void
onRemove: () => void
isButtonselected: boolean
maxLengthReached: boolean
isButtonSelected: boolean
isMaxLengthReached: boolean
}

const CustomSelectorButton = ({
isDarkMode,
buttonName,
onClick,
isButtonClicked,
onRemove,
isButtonselected: propIsButtonSelected,
maxLengthReached,
isButtonSelected: propIsButtonSelected,
isMaxLengthReached,
}: CustomSelectorButtonProps) => {
const defaultSettings = isDarkMode
? {
Expand All @@ -40,12 +40,12 @@ const CustomSelectorButton = ({
}, [propIsButtonSelected])

const handleButtonClick = () => {
if (maxLengthReached && !isButtonSelected) {
onClick && onClick(true)
if (isMaxLengthReached && !isButtonSelected) {
isButtonClicked && isButtonClicked(true)
return
}
setIsButtonSelected((prevState) => !prevState)
if (onClick) onClick(!isButtonSelected)
if (isButtonClicked) isButtonClicked(!isButtonSelected)
}

return (
Expand All @@ -61,7 +61,7 @@ const CustomSelectorButton = ({
>
{buttonName}
</StyledButton>
<RemoveButton onClick={onRemove}>
<StyledRemoveButton onClick={onRemove}>
<TiDelete
style={{
position: 'relative',
Expand All @@ -73,7 +73,7 @@ const CustomSelectorButton = ({
color: isDarkMode ? palette.GRAY300 : palette.BLACK,
}}
/>
</RemoveButton>
</StyledRemoveButton>
</StyledButtonWrapper>
)
}
Expand All @@ -83,7 +83,7 @@ const StyledButtonWrapper = styled.div`
align-items: center;
`

const RemoveButton = styled.button`
const StyledRemoveButton = styled.button`
margin-left: 8px;
background-color: transparent;
border: none;
Expand Down
6 changes: 3 additions & 3 deletions src/components/common/SelectorButtonContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ const SelectorButtonContainer = ({
key={index}
isDarkMode={isDarkMode}
buttonName={name}
onClick={(isSelected) => handleCustomButtonClick(isSelected)}
isButtonClicked={(isSelected) => handleCustomButtonClick(isSelected)}
onRemove={() => handleCustomButtonRemove(name)}
maxLengthReached={selectedCount >= maxLength}
isButtonselected={false}
isMaxLengthReached={selectedCount >= maxLength}
isButtonSelected={false}
/>
))}
{showAlert && (
Expand Down