mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-13 13:29:18 +08:00

* feat: add FloatButton * feat: add FloatButton * feat: FloatButton * feat: FloatButton * fix: fix * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * fix: add groupShape * feat: mergeShape * fix: fix * fix: fix style * fix: style fix * fix: fix * fix: style fix * fix: fix * fix: fix * fix: fix * fix: fix style * fix: fix style * fix: fix style * fix: style fix * feat: back-top * fix: style bug fix * fix: fix erroe * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * feat: add useMemo * docs: add docs * fix: bugFix * fix: bugFix * fix: bugfix * fix: style fix * fix: bugfix * test: add test case * fix: style fix * fix: style fix * fix: fix style * fix: fix style * fix: fix trigger action * fix: fix style * feat: add demo * fix: add demo * feat: add docs * fix: style ifx * feat: update maxSize of bundlesize * feat: add animation for group * fix: fix * fix: fix style * fix: fix test case * fix: fix test case * fix: fix type * fix: fix type * fix: update bundlesize * fix: fix * fix: fix style * fix: fix style * fix: updata snap * fix: fix CI * fix: fix style * fix: rename float button motion * fix: fix style * fix: bugFix * fix: fix style * fix: bugFix * fix: update docs * refactor: float button trigger * test: fix test case & update snapshot * fix: delete rest * docs: update demo * test: update snapshot * fix: fix eslint error * test: update snapshot * style: update icon fontSize to 18 * fix: fix style * fix: style fix * fix: test case fix * test: add test case * fix: style fix * test: update snap * fix: style fix * fix: style fix * fix: style fix * docs: demo update * fix: style fix * docs: update demo * test: update snapshot Co-authored-by: 黑雨 <wangning4567@163.com> Co-authored-by: MadCcc <1075746765@qq.com>
109 lines
2.9 KiB
TypeScript
109 lines
2.9 KiB
TypeScript
import classNames from 'classnames';
|
|
import React, { useContext, useMemo } from 'react';
|
|
import type { ConfigConsumerProps } from '../config-provider';
|
|
import BackTop from './BackTop';
|
|
import { ConfigContext } from '../config-provider';
|
|
import useStyle from './style';
|
|
import Tooltip from '../tooltip';
|
|
import Content from './FloatButtonContent';
|
|
import type {
|
|
CompoundedComponent,
|
|
FloatButtonContentProps,
|
|
FloatButtonProps,
|
|
FloatButtonShape,
|
|
} from './interface';
|
|
import Group from './FloatButtonGroup';
|
|
import FloatButtonGroupContext from './context';
|
|
import warning from '../_util/warning';
|
|
|
|
export const floatButtonPrefixCls = 'float-btn';
|
|
|
|
const FloatButton: React.ForwardRefRenderFunction<
|
|
HTMLAnchorElement | HTMLButtonElement,
|
|
FloatButtonProps
|
|
> = (props, ref) => {
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
className,
|
|
type = 'default',
|
|
shape = 'circle',
|
|
icon,
|
|
description,
|
|
tooltip,
|
|
...restProps
|
|
} = props;
|
|
const { getPrefixCls, direction } = useContext<ConfigConsumerProps>(ConfigContext);
|
|
const groupShape = useContext<FloatButtonShape | null>(FloatButtonGroupContext);
|
|
const prefixCls = getPrefixCls(floatButtonPrefixCls, customizePrefixCls);
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
const mergeShape = groupShape || shape;
|
|
|
|
const classString = classNames(
|
|
hashId,
|
|
prefixCls,
|
|
className,
|
|
`${prefixCls}-${type}`,
|
|
`${prefixCls}-${mergeShape}`,
|
|
{
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
},
|
|
);
|
|
|
|
const contentProps = useMemo<FloatButtonContentProps>(
|
|
() => ({ prefixCls, description, icon, type }),
|
|
[prefixCls, description, icon, type],
|
|
);
|
|
|
|
const buttonNode = tooltip ? (
|
|
<Tooltip title={tooltip} placement="left">
|
|
<div className={`${prefixCls}-body`}>
|
|
<Content {...contentProps} />
|
|
</div>
|
|
</Tooltip>
|
|
) : (
|
|
<div className={`${prefixCls}-body`}>
|
|
<Content {...contentProps} />
|
|
</div>
|
|
);
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
warning(
|
|
!(shape === 'circle' && description),
|
|
'FloatButton',
|
|
'supported only when `shape` is `square`. Due to narrow space for text, short sentence is recommended.',
|
|
);
|
|
}
|
|
|
|
return wrapSSR(
|
|
props.href ? (
|
|
<a ref={ref as React.LegacyRef<HTMLAnchorElement>} {...restProps} className={classString}>
|
|
{buttonNode}
|
|
</a>
|
|
) : (
|
|
<button
|
|
ref={ref as React.LegacyRef<HTMLButtonElement>}
|
|
{...restProps}
|
|
className={classString}
|
|
type="button"
|
|
>
|
|
{buttonNode}
|
|
</button>
|
|
),
|
|
);
|
|
};
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
FloatButton.displayName = 'FloatButton';
|
|
}
|
|
|
|
const ForwardFloatButton = React.forwardRef<
|
|
HTMLAnchorElement | HTMLButtonElement,
|
|
FloatButtonProps
|
|
>(FloatButton) as CompoundedComponent;
|
|
|
|
ForwardFloatButton.Group = Group;
|
|
ForwardFloatButton.BackTop = BackTop;
|
|
|
|
export default ForwardFloatButton;
|