2020-12-17 16:37:36 -07:00
|
|
|
import {
|
|
|
|
IconButton,
|
|
|
|
Popover,
|
|
|
|
PopoverTrigger,
|
|
|
|
PopoverArrow,
|
|
|
|
PopoverCloseButton,
|
|
|
|
PopoverBody,
|
|
|
|
PopoverContent,
|
|
|
|
} from '@chakra-ui/react';
|
2020-11-29 01:25:48 -07:00
|
|
|
import { FiSearch } from '@meronex/icons/fi';
|
2020-12-17 16:37:36 -07:00
|
|
|
import { ResolvedTarget } from '~/components';
|
|
|
|
import { useLGState } from '~/hooks';
|
2020-11-29 01:25:48 -07:00
|
|
|
|
2020-12-17 16:37:36 -07:00
|
|
|
import type { TSubmitButton } from './types';
|
2020-11-29 01:25:48 -07:00
|
|
|
|
2020-12-17 16:37:36 -07:00
|
|
|
export const SubmitButton = (props: TSubmitButton) => {
|
|
|
|
const { children, handleChange, ...rest } = props;
|
|
|
|
const { btnLoading, resolvedIsOpen, resolvedClose } = useLGState();
|
2020-11-29 01:25:48 -07:00
|
|
|
|
2020-12-17 16:37:36 -07:00
|
|
|
function handleClose(): void {
|
|
|
|
btnLoading.set(false);
|
|
|
|
resolvedClose();
|
|
|
|
}
|
2020-11-29 01:25:48 -07:00
|
|
|
|
|
|
|
return (
|
2020-12-17 16:37:36 -07:00
|
|
|
<>
|
|
|
|
<Popover isOpen={resolvedIsOpen.value} onClose={handleClose} closeOnBlur={false}>
|
|
|
|
<PopoverTrigger>
|
|
|
|
<IconButton
|
|
|
|
size="lg"
|
|
|
|
width={16}
|
|
|
|
type="submit"
|
|
|
|
icon={<FiSearch />}
|
|
|
|
title="Submit Query"
|
|
|
|
aria-label="Submit Query"
|
|
|
|
colorScheme="primary"
|
|
|
|
isLoading={btnLoading.value}
|
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
</PopoverTrigger>
|
|
|
|
<PopoverContent>
|
|
|
|
<PopoverArrow />
|
|
|
|
<PopoverCloseButton />
|
|
|
|
<PopoverBody p={6}>
|
|
|
|
{resolvedIsOpen.value && <ResolvedTarget setTarget={handleChange} />}
|
|
|
|
</PopoverBody>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
|
|
|
</>
|
2020-11-29 01:25:48 -07:00
|
|
|
);
|
2020-12-17 16:37:36 -07:00
|
|
|
};
|