ant-design/components/dropdown/dropdown-button.tsx
马斯特 a25ec29fb8 refactor: 保证所有的tsx和less都正确使用prefix (#3024)
* refactor: extract prefix cls as less variable

* refactor: apply ant icon prefix cls in less files

* refactor: all components support prefixCls props
2016-09-14 16:18:33 +08:00

55 lines
1.5 KiB
TypeScript

import * as React from 'react';
import Button from '../button';
import Icon from '../icon';
import Dropdown from './dropdown';
const ButtonGroup = Button.Group;
import classNames from 'classnames';
import splitObject from '../_util/splitObject';
export interface DropdownButtonProps {
type?: 'primary' | 'ghost' | 'dash';
onClick?: React.FormEventHandler;
trigger?: 'click' | 'hover';
overlay: React.ReactNode;
visible?: boolean;
onVisibleChange?: (visible: boolean) => void;
style?: React.CSSProperties;
prefixCls?: string;
}
export default class DropdownButton extends React.Component<DropdownButtonProps, any> {
static defaultProps = {
align: {
points: ['tr', 'br'],
overlay: {
adjustX: 1,
adjustY: 1,
},
offset: [0, 4],
targetOffset: [0, 0],
},
type: 'default',
prefixCls: 'ant-dropdown-button',
};
render() {
const [{ type, overlay, trigger, align, children, className, onClick, prefixCls }, restProps] =
splitObject(this.props,
['type', 'overlay', 'trigger', 'align', 'children', 'className', 'onClick', 'prefixCls']);
const cls = classNames({
[prefixCls]: true,
[className]: !!className,
});
return (
<ButtonGroup {...restProps} className={cls}>
<Button type={type} onClick={onClick}>{children}</Button>
<Dropdown align={align} overlay={overlay} trigger={trigger}>
<Button type={type}>
<Icon type="down" />
</Button>
</Dropdown>
</ButtonGroup>
);
}
}