mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 09:49:57 +08:00
5191b85b96
* fix: type updated from any, and comments removed #15930 * refactor: removed unnecessary comments, created helper for button * fix: cleanupTimer * fix: import fixed * Update components/button/button.tsx Co-authored-by: afc163 <afc163@gmail.com> * Update components/dropdown/dropdown-button.tsx Co-authored-by: afc163 <afc163@gmail.com> Co-authored-by: afc163 <afc163@gmail.com>
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import classNames from 'classnames';
|
|
import * as React from 'react';
|
|
import { ConfigContext } from '../config-provider';
|
|
import type { SizeType } from '../config-provider/SizeContext';
|
|
import { useToken } from '../theme/internal';
|
|
import warning from '../_util/warning';
|
|
|
|
export interface ButtonGroupProps {
|
|
size?: SizeType;
|
|
style?: React.CSSProperties;
|
|
className?: string;
|
|
prefixCls?: string;
|
|
children?: React.ReactNode;
|
|
}
|
|
|
|
export const GroupSizeContext = React.createContext<SizeType | undefined>(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();
|
|
|
|
let sizeCls = '';
|
|
|
|
switch (size) {
|
|
case 'large':
|
|
sizeCls = 'lg';
|
|
break;
|
|
case 'small':
|
|
sizeCls = 'sm';
|
|
break;
|
|
case 'middle':
|
|
case undefined:
|
|
break;
|
|
default:
|
|
warning(!size, 'Button.Group', '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;
|