import React, { useState } from "react" import ClickAwayListener from "react-click-away-listener" import { Center, Flex, Text } from "@chakra-ui/react" import { Icon } from "../Icon/Icon" export const SettingsMenu = (props) => { 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(() => { setShow(true) }, []) const hideMenu = React.useCallback(() => { setShow(false) }, []) const basePadding = React.useMemo(() => { return 4 }, []) const types = React.useMemo(() => { const ret = [ { label: "any", icon: "any" }, "object", "array", "string", "number", "boolean", ] return ret }, []) const onChangeType = React.useCallback( (type) => { props?.onChangeType?.(type) }, [props?.onChangeType] ) const onDelete = React.useCallback( (type) => { props?.onDelete?.() }, [props?.onDelete] ) const iconSize = 10 return (
{!props?.readonly && ( Types )} {!props?.readonly && types.map((type, idx) => { const ret = ( div": { background: "greys.light", }, }} cursor="pointer" onClick={() => onChangeType(type?.key || type)} paddingY={1} > {type?.label || type?.key || type} ) return ret })} {!props?.readonly && ( Recycle )}
) }