feat: support dropdown prefill

This commit is contained in:
jinhojang6 2024-10-03 14:17:49 +09:00
parent e116d09fc0
commit f5a5037f5b
No known key found for this signature in database
GPG Key ID: 1762F21FE8B543F8
5 changed files with 26 additions and 12 deletions

View File

@ -0,0 +1,5 @@
<svg width="28" height="28" viewBox="0 0 28 28" fill="white"
xmlns="http://www.w3.org/2000/svg">
<path d="M12.9813 16.5L10.6112 14.1299L11.2038 13.5374L12.9813 15.315L16.7963 11.5L17.3888 12.0925L12.9813 16.5Z" fill="black"/>
</svg>

After

Width:  |  Height:  |  Size: 245 B

3
public/assets/check.svg Normal file
View File

@ -0,0 +1,3 @@
<svg width="8" height="6" viewBox="0 0 8 6" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.9813 5.5L0.611237 3.12994L1.20375 2.53742L2.9813 4.31497L6.79627 0.5L7.38878 1.09252L2.9813 5.5Z" fill="black"/>
</svg>

After

Width:  |  Height:  |  Size: 224 B

View File

@ -13,7 +13,9 @@ const Checkbox: React.FC<CustomCheckboxProps> = ({
}) => ( }) => (
<Container> <Container>
<HiddenCheckbox type="checkbox" checked={checked} onChange={onChange} /> <HiddenCheckbox type="checkbox" checked={checked} onChange={onChange} />
<StyledCheckbox isChecked={checked} /> <StyledCheckbox isChecked={checked}>
{checked && <img src="/assets/check.svg" alt="checkmark" />}
</StyledCheckbox>
<LabelText>{label}</LabelText> <LabelText>{label}</LabelText>
</Container> </Container>
) )
@ -39,22 +41,15 @@ const HiddenCheckbox = styled.input`
` `
const StyledCheckbox = styled.span<{ isChecked: boolean }>` const StyledCheckbox = styled.span<{ isChecked: boolean }>`
display: inline-block; display: flex;
align-items: center;
justify-content: center;
border: 1px solid white;
width: 18px; width: 18px;
height: 18px; height: 18px;
background-color: ${({ isChecked }) => (isChecked ? 'white' : 'black')}; background-color: ${({ isChecked }) => (isChecked ? 'white' : 'black')};
border: 1px solid white;
position: relative; position: relative;
margin-right: 10px; margin-right: 10px;
&::after {
content: ${({ isChecked }) => (isChecked ? "'✓'" : "''")};
color: black;
position: absolute;
top: -2px;
left: 2px;
font-size: 14px;
}
` `
const LabelText = styled.span` const LabelText = styled.span`

View File

@ -7,6 +7,7 @@ interface DropdownProps {
options: string[] options: string[]
filterType: string filterType: string
onSelectionChange: (selectedOptions: string[], filterType: string) => void onSelectionChange: (selectedOptions: string[], filterType: string) => void
prefill?: string[]
} }
const Dropdown: React.FC<DropdownProps> = ({ const Dropdown: React.FC<DropdownProps> = ({
@ -14,11 +15,20 @@ const Dropdown: React.FC<DropdownProps> = ({
options, options,
filterType, filterType,
onSelectionChange, onSelectionChange,
prefill = [],
}) => { }) => {
const [selectedOptions, setSelectedOptions] = useState<string[]>([]) const [selectedOptions, setSelectedOptions] = useState<string[]>([])
const [isExpanded, setIsExpanded] = useState(false) const [isExpanded, setIsExpanded] = useState(false)
const dropdownRef = useRef<HTMLDivElement>(null) const dropdownRef = useRef<HTMLDivElement>(null)
// If prefill is provided, set the selected options to the prefill
useEffect(() => {
if (prefill?.length) {
setSelectedOptions(prefill)
}
}, [prefill])
const handleSelect = (option: string) => { const handleSelect = (option: string) => {
let newSelectedOptions = [] let newSelectedOptions = []
if (selectedOptions.includes(option)) { if (selectedOptions.includes(option)) {

View File

@ -74,6 +74,7 @@ const ExploreSection: React.FC<ExploreSectionProps> = () => {
options={ARCHETYPE} options={ARCHETYPE}
onSelectionChange={handleFilterChange} onSelectionChange={handleFilterChange}
filterType="archetype" filterType="archetype"
prefill={ARCHETYPE}
/> />
<Dropdown <Dropdown
title="Comp" title="Comp"