mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 00:09:39 +08:00
0c3ba124b4
* type: delete visible & code optimization * add PureBackTop * fix: update snap * fix: cov * fix: add istanbul ignore * fix * feat: use visibilityHeight=0 replace visible=true * snap * cov * test case * test case * fix * fix cov * fix test * simplify code * rename function
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
/* eslint-disable react/no-array-index-key */
|
|
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
import FloatButton, { floatButtonPrefixCls } from './FloatButton';
|
|
import FloatButtonGroup from './FloatButtonGroup';
|
|
import BackTop from './BackTop';
|
|
import type { FloatButtonProps, FloatButtonGroupProps } from './interface';
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
export interface PureFloatButtonProps extends Omit<FloatButtonProps, 'target'> {
|
|
backTop?: boolean;
|
|
}
|
|
|
|
export interface PurePanelProps
|
|
extends PureFloatButtonProps,
|
|
Omit<FloatButtonGroupProps, 'children'> {
|
|
/** Convert to FloatGroup when configured */
|
|
items?: PureFloatButtonProps[];
|
|
}
|
|
|
|
const PureFloatButton: React.FC<PureFloatButtonProps> = ({ backTop, ...props }) =>
|
|
backTop ? <BackTop {...props} visibilityHeight={0} /> : <FloatButton {...props} />;
|
|
|
|
function PurePanel({ className, items, ...props }: PurePanelProps) {
|
|
const { prefixCls: customizePrefixCls } = props;
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
const prefixCls = getPrefixCls(floatButtonPrefixCls, customizePrefixCls);
|
|
const pureCls = `${prefixCls}-pure`;
|
|
|
|
if (items) {
|
|
return (
|
|
<FloatButtonGroup className={classNames(className, pureCls)} {...props}>
|
|
{items.map((item, index) => (
|
|
<PureFloatButton key={index} {...item} />
|
|
))}
|
|
</FloatButtonGroup>
|
|
);
|
|
}
|
|
|
|
return <PureFloatButton className={classNames(className, pureCls)} {...props} />;
|
|
}
|
|
|
|
export default React.memo(PurePanel);
|