♿ (editor) Improve variables popover click detection
This commit is contained in:
@ -1,39 +1,53 @@
|
|||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverTrigger,
|
|
||||||
Flex,
|
Flex,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
IconButton,
|
IconButton,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
IconButtonProps,
|
IconButtonProps,
|
||||||
|
useDisclosure,
|
||||||
|
PopoverAnchor,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { UserIcon } from '@/components/icons'
|
import { UserIcon } from '@/components/icons'
|
||||||
import { Variable } from 'models'
|
import { Variable } from 'models'
|
||||||
import React from 'react'
|
import React, { useRef } from 'react'
|
||||||
import { VariableSearchInput } from '@/components/VariableSearchInput'
|
import { VariableSearchInput } from '@/components/VariableSearchInput'
|
||||||
|
import { useOutsideClick } from '@/hooks/useOutsideClick'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onSelectVariable: (variable: Pick<Variable, 'name' | 'id'>) => void
|
onSelectVariable: (variable: Pick<Variable, 'name' | 'id'>) => void
|
||||||
} & Omit<IconButtonProps, 'aria-label'>
|
} & Omit<IconButtonProps, 'aria-label'>
|
||||||
|
|
||||||
export const VariablesButton = ({ onSelectVariable, ...props }: Props) => {
|
export const VariablesButton = ({ onSelectVariable, ...props }: Props) => {
|
||||||
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
||||||
|
const popoverRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
useOutsideClick({
|
||||||
|
ref: popoverRef,
|
||||||
|
handler: onClose,
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover isLazy placement="bottom-end" gutter={0}>
|
<Popover isLazy placement="bottom-end" gutter={0} isOpen={isOpen}>
|
||||||
<PopoverTrigger>
|
<PopoverAnchor>
|
||||||
<Flex>
|
<Flex>
|
||||||
<Tooltip label="Insert a variable">
|
<Tooltip label="Insert a variable">
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label={'Insert a variable'}
|
aria-label={'Insert a variable'}
|
||||||
icon={<UserIcon />}
|
icon={<UserIcon />}
|
||||||
pos="relative"
|
pos="relative"
|
||||||
|
onClick={onOpen}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Flex>
|
</Flex>
|
||||||
</PopoverTrigger>
|
</PopoverAnchor>
|
||||||
<PopoverContent w="full">
|
<PopoverContent w="full" ref={popoverRef}>
|
||||||
<VariableSearchInput
|
<VariableSearchInput
|
||||||
onSelectVariable={onSelectVariable}
|
onSelectVariable={(variable) => {
|
||||||
|
onClose()
|
||||||
|
onSelectVariable(variable)
|
||||||
|
}}
|
||||||
placeholder="Search for a variable"
|
placeholder="Search for a variable"
|
||||||
shadow="lg"
|
shadow="lg"
|
||||||
autoFocus
|
autoFocus
|
||||||
|
@ -27,8 +27,8 @@ export const platePlugins = createPlugins(
|
|||||||
url.startsWith('https:') ||
|
url.startsWith('https:') ||
|
||||||
url.startsWith('mailto:') ||
|
url.startsWith('mailto:') ||
|
||||||
url.startsWith('tel:') ||
|
url.startsWith('tel:') ||
|
||||||
url.startsWith('sms:') ||
|
url.startsWith('sms:'),
|
||||||
(url.startsWith('{{') && url.endsWith('}}')),
|
forceSubmit: true,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user