Files
FastGPT/packages/web/components/common/MyPopover/index.tsx
Archer a8673344b1 Test add menu (#4887)
* Feature: Add additional dataset options and their descriptions, updat… (#4874)

* Feature: Add additional dataset options and their descriptions, update menu components to support submenu functionality

* Optimize the menu component by removing the sub-menu position attribute, introducing the MyPopover component to support sub-menu functionality, and adding new dataset options and their descriptions in the dataset list.

---------

Co-authored-by: dreamer6680 <146868355@qq.com>

* api dataset tip

* remove invalid code

---------

Co-authored-by: dreamer6680 <1468683855@qq.com>
Co-authored-by: dreamer6680 <146868355@qq.com>
2025-05-25 20:16:03 +08:00

72 lines
1.5 KiB
TypeScript

import React from 'react';
import {
Popover,
PopoverTrigger,
PopoverContent,
useDisclosure,
type PlacementWithLogical,
PopoverArrow,
type PopoverContentProps
} from '@chakra-ui/react';
interface Props extends PopoverContentProps {
Trigger: React.ReactNode;
placement?: PlacementWithLogical;
offset?: [number, number];
trigger?: 'hover' | 'click';
hasArrow?: boolean;
children: (e: { onClose: () => void }) => React.ReactNode;
onCloseFunc?: () => void;
onOpenFunc?: () => void;
closeOnBlur?: boolean;
}
const MyPopover = ({
Trigger,
placement,
offset,
trigger,
hasArrow = true,
children,
onOpenFunc,
onCloseFunc,
closeOnBlur = false,
...props
}: Props) => {
const firstFieldRef = React.useRef(null);
const { onOpen, onClose, isOpen } = useDisclosure();
return (
<Popover
isOpen={isOpen}
initialFocusRef={firstFieldRef}
onOpen={() => {
onOpen();
onOpenFunc && onOpenFunc();
}}
onClose={() => {
onClose();
onCloseFunc && onCloseFunc();
}}
placement={placement}
offset={offset}
closeOnBlur={closeOnBlur}
trigger={trigger}
openDelay={100}
closeDelay={100}
isLazy
lazyBehavior="keepMounted"
autoFocus={false}
>
<PopoverTrigger>{Trigger}</PopoverTrigger>
<PopoverContent {...props}>
{hasArrow && <PopoverArrow />}
{children({ onClose })}
</PopoverContent>
</Popover>
);
};
export default MyPopover;