chore: update checkbox style and on click outside handling

This commit is contained in:
jinhojang6 2024-09-28 01:32:31 +09:00
parent 6042d918af
commit 913d5ddf1a
No known key found for this signature in database
GPG Key ID: 1762F21FE8B543F8
3 changed files with 27 additions and 6 deletions

View File

@ -28,8 +28,8 @@ const StyledCheckbox = styled.span<{ isChecked: boolean }>`
content: ${({ isChecked }) => (isChecked ? "'✓'" : "''")};
color: black;
position: absolute;
top: 0;
left: 3px;
top: -2px;
left: 2px;
font-size: 14px;
}
`

View File

@ -1,5 +1,5 @@
import styled from '@emotion/styled'
import React, { useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import Checkbox from './Checkbox' // Import the CustomCheckbox
interface DropdownProps {
@ -15,6 +15,7 @@ const Dropdown: React.FC<DropdownProps> = ({
}) => {
const [selectedOptions, setSelectedOptions] = useState<string[]>([])
const [isExpanded, setIsExpanded] = useState(false)
const dropdownRef = useRef<HTMLDivElement>(null)
const handleSelect = (option: string) => {
let newSelectedOptions = []
@ -41,8 +42,28 @@ const Dropdown: React.FC<DropdownProps> = ({
setIsExpanded(!isExpanded)
}
const handleClickOutside = (event: MouseEvent) => {
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target as Node)
) {
setIsExpanded(false)
}
}
useEffect(() => {
if (isExpanded) {
document.addEventListener('mousedown', handleClickOutside)
} else {
document.removeEventListener('mousedown', handleClickOutside)
}
return () => {
document.removeEventListener('mousedown', handleClickOutside)
}
}, [isExpanded])
return (
<DropdownContainer>
<DropdownContainer ref={dropdownRef}>
<DropdownHeader onClick={toggleDropdown}>
<span>{title}</span>
<Chevron isExpanded={isExpanded}>

View File

@ -1,5 +1,5 @@
import { OperatorDetails } from '@/components/Operator/OperatorDetails'
import { SimilarOperators } from '@/components/Operator/SimilarOperators'
// import { SimilarOperators } from '@/components/Operator/SimilarOperators'
import styled from '@emotion/styled'
import { useRouter } from 'next/router'
import React from 'react'
@ -25,7 +25,7 @@ const ExploreOperator: React.FC<ExploreOperatorProps> = ({ id }) => {
<img src={`/assets/chevron-left.svg`} alt="Share icon" />
</GoBackButton>
<OperatorDetails id={Number(id)} />
<SimilarOperators />
{/* <SimilarOperators /> */}
</Container>
)
}