mirror of
https://github.com/acid-info/logos-ordinals-dashboard.git
synced 2025-02-05 10:04:28 +00:00
chore: update checkbox style and on click outside handling
This commit is contained in:
parent
6042d918af
commit
913d5ddf1a
@ -28,8 +28,8 @@ const StyledCheckbox = styled.span<{ isChecked: boolean }>`
|
|||||||
content: ${({ isChecked }) => (isChecked ? "'✓'" : "''")};
|
content: ${({ isChecked }) => (isChecked ? "'✓'" : "''")};
|
||||||
color: black;
|
color: black;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: -2px;
|
||||||
left: 3px;
|
left: 2px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
import React, { useState } from 'react'
|
import React, { useEffect, useRef, useState } from 'react'
|
||||||
import Checkbox from './Checkbox' // Import the CustomCheckbox
|
import Checkbox from './Checkbox' // Import the CustomCheckbox
|
||||||
|
|
||||||
interface DropdownProps {
|
interface DropdownProps {
|
||||||
@ -15,6 +15,7 @@ const Dropdown: React.FC<DropdownProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
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 handleSelect = (option: string) => {
|
const handleSelect = (option: string) => {
|
||||||
let newSelectedOptions = []
|
let newSelectedOptions = []
|
||||||
@ -41,8 +42,28 @@ const Dropdown: React.FC<DropdownProps> = ({
|
|||||||
setIsExpanded(!isExpanded)
|
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 (
|
return (
|
||||||
<DropdownContainer>
|
<DropdownContainer ref={dropdownRef}>
|
||||||
<DropdownHeader onClick={toggleDropdown}>
|
<DropdownHeader onClick={toggleDropdown}>
|
||||||
<span>{title}</span>
|
<span>{title}</span>
|
||||||
<Chevron isExpanded={isExpanded}>
|
<Chevron isExpanded={isExpanded}>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { OperatorDetails } from '@/components/Operator/OperatorDetails'
|
import { OperatorDetails } from '@/components/Operator/OperatorDetails'
|
||||||
import { SimilarOperators } from '@/components/Operator/SimilarOperators'
|
// import { SimilarOperators } from '@/components/Operator/SimilarOperators'
|
||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
@ -25,7 +25,7 @@ const ExploreOperator: React.FC<ExploreOperatorProps> = ({ id }) => {
|
|||||||
<img src={`/assets/chevron-left.svg`} alt="Share icon" />
|
<img src={`/assets/chevron-left.svg`} alt="Share icon" />
|
||||||
</GoBackButton>
|
</GoBackButton>
|
||||||
<OperatorDetails id={Number(id)} />
|
<OperatorDetails id={Number(id)} />
|
||||||
<SimilarOperators />
|
{/* <SimilarOperators /> */}
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user