mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
59ad48476b
* chore: add boime lint * fix lint * use files ignore * revert change * ignore clarity.js * fix some errors * fix some errors * fix some errors * fix some errors * add yml file * Update clarity.js Signed-off-by: afc163 <afc163@gmail.com> * add npm run lint:biome * add npm run lint:biome * fix test case * fix ts errors * fix ts errors * fix lint and add .lintstagedrc * shorten prop name * chore: update package.json * update biome.json * chore: remove stylelint * chore: useOptionalChain * fix lint * biome format * prettier all code * prettier all code * fix site test --------- Signed-off-by: afc163 <afc163@gmail.com>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 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();
|
|
|
|
let sizeCls = '';
|
|
|
|
switch (size) {
|
|
case 'large':
|
|
sizeCls = 'lg';
|
|
break;
|
|
case 'small':
|
|
sizeCls = 'sm';
|
|
break;
|
|
default:
|
|
// Do nothing
|
|
}
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const warning = devUseWarning('Button.Group');
|
|
|
|
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;
|