import * as React from 'react'; import classNames from 'classnames'; import { SizeType } from '../config-provider/SizeContext'; import { ConfigContext } from '../config-provider'; import devWarning from '../_util/devWarning'; import { useToken } from '../_util/theme'; export interface ButtonGroupProps { size?: SizeType; style?: React.CSSProperties; className?: string; prefixCls?: string; children?: React.ReactNode; } export const GroupSizeContext = React.createContext(undefined); const ButtonGroup: React.FC = props => { const { getPrefixCls, direction } = React.useContext(ConfigContext); const { prefixCls: customizePrefixCls, size, className, ...others } = props; const prefixCls = getPrefixCls('btn-group', customizePrefixCls); // Here we only need hashId const [, , hashId] = useToken(); // large => lg // small => sm let sizeCls = ''; switch (size) { case 'large': sizeCls = 'lg'; break; case 'small': sizeCls = 'sm'; break; case 'middle': case undefined: break; default: devWarning(!size, 'Button.Group', 'Invalid prop `size`.'); } const classes = classNames( prefixCls, { [`${prefixCls}-${sizeCls}`]: sizeCls, [`${prefixCls}-rtl`]: direction === 'rtl', }, className, hashId, ); return (
); }; export default ButtonGroup;