import React, { useRef, memo, useContext } from 'react'; import CloseOutlined from '@ant-design/icons/CloseOutlined'; import FileTextOutlined from '@ant-design/icons/FileTextOutlined'; import classNames from 'classnames'; import CSSMotion from 'rc-motion'; import useMergedState from 'rc-util/lib/hooks/useMergedState'; import FloatButton, { floatButtonPrefixCls } from './FloatButton'; import type { ConfigConsumerProps } from '../config-provider'; import { ConfigContext } from '../config-provider'; import { FloatButtonGroupProvider } from './context'; import type { FloatButtonGroupProps } from './interface'; import useStyle from './style'; const FloatButtonGroup: React.FC = (props) => { const { prefixCls: customizePrefixCls, className, style, shape = 'circle', type = 'default', icon = , closeIcon = , description, trigger, children, onOpenChange, } = props; const { direction, getPrefixCls } = useContext(ConfigContext); const prefixCls = getPrefixCls(floatButtonPrefixCls, customizePrefixCls); const [wrapSSR, hashId] = useStyle(prefixCls); const groupPrefixCls = `${prefixCls}-group`; const groupCls = classNames(groupPrefixCls, hashId, className, { [`${groupPrefixCls}-rtl`]: direction === 'rtl', [`${groupPrefixCls}-${shape}`]: shape, [`${groupPrefixCls}-${shape}-shadow`]: !trigger, }); const wrapperCls = classNames(hashId, `${groupPrefixCls}-wrap`); const [open, setOpen] = useMergedState(false, { value: props.open }); const clickAction = useRef>({}); const hoverAction = useRef>({}); if (trigger === 'click') { clickAction.current = { onClick() { setOpen((prevState) => { onOpenChange?.(!prevState); return !prevState; }); }, }; } if (trigger === 'hover') { hoverAction.current = { onMouseEnter() { setOpen(true); onOpenChange?.(true); }, onMouseLeave() { setOpen(false); onOpenChange?.(false); }, }; } return wrapSSR(
{trigger && ['click', 'hover'].includes(trigger) ? ( <> {({ className: motionClassName }) => (
{children}
)}
) : ( children )}
, ); }; export default memo(FloatButtonGroup);