mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-15 21:48:29 +02:00

Some checks failed
✅ test / test-react-legacy (push) Failing after 53s
✅ test / test-node (push) Failing after 55s
✅ test / test-react-latest-dist (push) Has been skipped
✅ test / test lib/es module (push) Failing after 55s
👁️ Visual Regression Persist Start / test image (push) Failing after 56s
Publish Any Commit / build (push) Failing after 55s
🔀 Sync mirror to Gitee / mirror (push) Has been skipped
✅ test / lint (push) Failing after 55s
✅ test / test-react-latest (push) Failing after 58s
✅ test / test-coverage (push) Has been skipped
✅ test / build (push) Failing after 55s
* chore: fix biome error * fix * fix again * revert
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
|
|
import { devUseWarning } from '../_util/warning';
|
|
import { ConfigContext } from '../config-provider';
|
|
import type { SizeType } from '../config-provider/SizeContext';
|
|
import { useToken } from '../theme/internal';
|
|
|
|
export interface ButtonGroupProps {
|
|
size?: SizeType;
|
|
style?: React.CSSProperties;
|
|
className?: string;
|
|
prefixCls?: string;
|
|
children?: React.ReactNode;
|
|
}
|
|
|
|
export const GroupSizeContext = React.createContext<SizeType>(undefined);
|
|
|
|
const ButtonGroup: React.FC<ButtonGroupProps> = (props) => {
|
|
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
|
|
|
const { prefixCls: customizePrefixCls, size, className, ...others } = props;
|
|
const prefixCls = getPrefixCls('btn-group', customizePrefixCls);
|
|
|
|
const [, , hashId] = useToken();
|
|
|
|
const sizeCls = React.useMemo<string>(() => {
|
|
switch (size) {
|
|
case 'large':
|
|
return 'lg';
|
|
case 'small':
|
|
return 'sm';
|
|
default:
|
|
return '';
|
|
}
|
|
}, [size]);
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const warning = devUseWarning('Button.Group');
|
|
|
|
warning.deprecated(false, 'Button.Group', 'Space.Compact');
|
|
warning(!size || ['large', 'small', 'middle'].includes(size), 'usage', 'Invalid prop `size`.');
|
|
}
|
|
|
|
const classes = classNames(
|
|
prefixCls,
|
|
{
|
|
[`${prefixCls}-${sizeCls}`]: sizeCls,
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
},
|
|
className,
|
|
hashId,
|
|
);
|
|
|
|
return (
|
|
<GroupSizeContext.Provider value={size}>
|
|
<div {...others} className={classes} />
|
|
</GroupSizeContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default ButtonGroup;
|