feat: feature/mvp-sprint-1 Made settings menu more user friendly
This commit is contained in:
parent
813b5cf68a
commit
d82863ff88
@ -1,10 +1,42 @@
|
|||||||
import React, { useState } from "react"
|
import React, { useState } from "react"
|
||||||
|
import ClickAwayListener from "react-click-away-listener"
|
||||||
import { Center, Flex, Text } from "@chakra-ui/react"
|
import { Center, Flex, Text } from "@chakra-ui/react"
|
||||||
|
|
||||||
import { Icon } from "../Icon/Icon"
|
import { Icon } from "../Icon/Icon"
|
||||||
|
|
||||||
export const SettingsMenu = (props) => {
|
export const SettingsMenu = (props) => {
|
||||||
const [show, setShow] = useState(false)
|
const [show, setShow] = useState(false)
|
||||||
|
const hideRef = React.useRef(null)
|
||||||
|
const [opacity, setOpacity] = React.useState(props?.opacity === 0 ? 0 : 1)
|
||||||
|
|
||||||
|
const opacityRef = React.useRef(null)
|
||||||
|
|
||||||
|
const waitTime = 1555
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
clearInterval(opacityRef?.current)
|
||||||
|
if (props?.opacity) {
|
||||||
|
setOpacity(props?.opacity)
|
||||||
|
} else {
|
||||||
|
opacityRef.current = setInterval(() => {
|
||||||
|
setOpacity(props?.opacity)
|
||||||
|
setShow(false)
|
||||||
|
}, waitTime)
|
||||||
|
}
|
||||||
|
}, [props?.opacity])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (show || props?.opacity) {
|
||||||
|
clearInterval(hideRef?.current)
|
||||||
|
}
|
||||||
|
}, [show, props?.opacity])
|
||||||
|
|
||||||
|
const maybeHide = React.useCallback(() => {
|
||||||
|
clearInterval(hideRef?.current)
|
||||||
|
hideRef.current = setTimeout(() => {
|
||||||
|
setShow(false)
|
||||||
|
}, waitTime)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const showMenu = React.useCallback(() => {
|
const showMenu = React.useCallback(() => {
|
||||||
setShow(true)
|
setShow(true)
|
||||||
@ -46,21 +78,22 @@ export const SettingsMenu = (props) => {
|
|||||||
const iconSize = 10
|
const iconSize = 10
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<ClickAwayListener onClickAway={hideMenu}>
|
||||||
<Center
|
<Center
|
||||||
position="relative"
|
position="relative"
|
||||||
// width="100%"
|
// width="100%"
|
||||||
paddingRight={36}
|
paddingRight={36}
|
||||||
opacity={props?.opacity}
|
opacity={opacity}
|
||||||
cursor="pointer"
|
|
||||||
transition={props?.transition || "all 0.2s ease-in-out"}
|
transition={props?.transition || "all 0.2s ease-in-out"}
|
||||||
onMouseEnter={showMenu}
|
onMouseEnter={showMenu}
|
||||||
onMouseLeave={hideMenu}
|
onMouseLeave={maybeHide}
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
paddingLeft={1}
|
paddingLeft={1}
|
||||||
// opacity={showContextIcon ? 1 : 0}
|
// opacity={showContextIcon ? 1 : 0}
|
||||||
transition="all 0.2s ease-in-out"
|
cursor="pointer"
|
||||||
// onClick={deleteValue}
|
// onClick={deleteValue}
|
||||||
|
transition="all 0.2s ease-in-out"
|
||||||
>
|
>
|
||||||
<Icon name="wizard" size={7}></Icon>
|
<Icon name="wizard" size={7}></Icon>
|
||||||
</Flex>
|
</Flex>
|
||||||
@ -85,10 +118,12 @@ export const SettingsMenu = (props) => {
|
|||||||
<Flex
|
<Flex
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
flexDirection="row"
|
flexDirection="row"
|
||||||
_hover={{
|
paddingRight={basePadding * 2}
|
||||||
background: "greys.light",
|
paddingLeft={basePadding * 1}
|
||||||
}}
|
// _hover={{
|
||||||
paddingX={basePadding * 1}
|
// background: "greys.light",
|
||||||
|
// }}
|
||||||
|
// paddingX={basePadding * 1}
|
||||||
paddingY={basePadding / 2}
|
paddingY={basePadding / 2}
|
||||||
>
|
>
|
||||||
<Icon marginBottom="-2px" name="cyclone" size={iconSize}></Icon>
|
<Icon marginBottom="-2px" name="cyclone" size={iconSize}></Icon>
|
||||||
@ -114,6 +149,7 @@ export const SettingsMenu = (props) => {
|
|||||||
background: "greys.light",
|
background: "greys.light",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
cursor="pointer"
|
||||||
onClick={() => onChangeType(type?.key || type)}
|
onClick={() => onChangeType(type?.key || type)}
|
||||||
paddingY={1}
|
paddingY={1}
|
||||||
>
|
>
|
||||||
@ -121,7 +157,8 @@ export const SettingsMenu = (props) => {
|
|||||||
alignItems="center"
|
alignItems="center"
|
||||||
flexDirection="row"
|
flexDirection="row"
|
||||||
width="100%"
|
width="100%"
|
||||||
paddingX={basePadding * 2}
|
paddingRight={basePadding * 4}
|
||||||
|
paddingLeft={basePadding * 2}
|
||||||
paddingY={basePadding / 2}
|
paddingY={basePadding / 2}
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
@ -145,6 +182,7 @@ export const SettingsMenu = (props) => {
|
|||||||
_hover={{
|
_hover={{
|
||||||
background: "greys.light",
|
background: "greys.light",
|
||||||
}}
|
}}
|
||||||
|
cursor="pointer"
|
||||||
onClick={onDelete}
|
onClick={onDelete}
|
||||||
paddingX={basePadding * 1}
|
paddingX={basePadding * 1}
|
||||||
paddingY={basePadding / 2}
|
paddingY={basePadding / 2}
|
||||||
@ -158,5 +196,6 @@ export const SettingsMenu = (props) => {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Center>
|
</Center>
|
||||||
|
</ClickAwayListener>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user