2
0

(editor) Improve variables popover click detection

This commit is contained in:
Baptiste Arnaud
2023-02-16 17:09:02 +01:00
parent d805ea9c10
commit 618eb8a882
2 changed files with 23 additions and 9 deletions

View File

@ -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

View File

@ -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,
}, },
}), }),
], ],