buster/web/src/components/features/ShareMenu/ShareMenu.tsx

56 lines
1.6 KiB
TypeScript
Raw Normal View History

'use client';
import React, { PropsWithChildren } from 'react';
2025-01-31 07:29:06 +08:00
import { PopoverProps } from 'antd';
2025-02-20 10:53:49 +08:00
import { AppPopover } from '@/components/ui/tooltip/AppPopover';
import { AppTooltip } from '@/components/ui/tooltip';
import { useMemoizedFn } from 'ahooks';
2025-02-07 05:31:46 +08:00
import { BusterShare, ShareAssetType } from '@/api/asset_interfaces';
2025-01-31 07:29:06 +08:00
import { ShareMenuContent } from './ShareMenuContent';
2025-02-07 05:31:46 +08:00
import { isShareMenuVisible } from './publicHelpers';
export const ShareMenu: React.FC<
PropsWithChildren<{
placement?: PopoverProps['placement'];
2025-02-07 05:31:46 +08:00
shareAssetConfig: BusterShare | null;
2025-01-31 07:29:06 +08:00
assetId: string;
2025-02-01 02:04:49 +08:00
assetType: ShareAssetType;
}>
2025-02-01 06:21:50 +08:00
> = ({ children, shareAssetConfig, assetId, assetType, placement = 'bottomLeft' }) => {
const [isOpen, setIsOpen] = React.useState(false);
const onOpenChange = useMemoizedFn((v: boolean) => {
setIsOpen(v);
});
2025-02-07 05:31:46 +08:00
const showShareMenu = shareAssetConfig && isShareMenuVisible(shareAssetConfig);
if (!showShareMenu) {
return null;
}
2025-02-07 05:31:46 +08:00
const permission = shareAssetConfig?.permission;
return (
<AppPopover
2025-02-07 05:31:46 +08:00
trigger={['click']}
destroyTooltipOnHide
placement={placement}
onOpenChange={onOpenChange}
content={
2025-02-07 05:31:46 +08:00
shareAssetConfig ? (
<ShareMenuContent
shareAssetConfig={shareAssetConfig}
assetId={assetId}
assetType={assetType}
permission={permission}
/>
) : null
}>
2025-03-02 13:49:10 +08:00
<AppTooltip title={!isOpen ? 'Share item' : ''}>
2025-02-07 05:31:46 +08:00
<div className="flex">{children}</div>
</AppTooltip>
</AppPopover>
);
};