2016-07-07 20:25:03 +08:00
|
|
|
import * as React from 'react';
|
2015-12-02 15:18:15 +08:00
|
|
|
import Button from '../button';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import Dropdown from './dropdown';
|
|
|
|
const ButtonGroup = Button.Group;
|
2016-02-29 18:02:05 +08:00
|
|
|
import classNames from 'classnames';
|
2016-06-22 13:18:43 +08:00
|
|
|
import splitObject from '../_util/splitObject';
|
2016-08-19 16:43:32 +08:00
|
|
|
|
|
|
|
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;
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls?: string;
|
2016-08-19 16:43:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class DropdownButton extends React.Component<DropdownButtonProps, any> {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
align: {
|
|
|
|
points: ['tr', 'br'],
|
|
|
|
overlay: {
|
|
|
|
adjustX: 1,
|
|
|
|
adjustY: 1,
|
|
|
|
},
|
|
|
|
offset: [0, 4],
|
|
|
|
targetOffset: [0, 0],
|
|
|
|
},
|
|
|
|
type: 'default',
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls: 'ant-dropdown-button',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2015-12-02 15:18:15 +08:00
|
|
|
render() {
|
2016-09-14 16:18:33 +08:00
|
|
|
const [{ type, overlay, trigger, align, children, className, onClick, prefixCls }, restProps] =
|
|
|
|
splitObject(this.props,
|
|
|
|
['type', 'overlay', 'trigger', 'align', 'children', 'className', 'onClick', 'prefixCls']);
|
2016-02-29 18:02:05 +08:00
|
|
|
const cls = classNames({
|
2016-09-14 16:18:33 +08:00
|
|
|
[prefixCls]: true,
|
2016-06-28 17:18:20 +08:00
|
|
|
[className]: !!className,
|
2016-02-29 18:02:05 +08:00
|
|
|
});
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
2016-02-29 18:02:05 +08:00
|
|
|
<ButtonGroup {...restProps} className={cls}>
|
2016-04-18 17:23:22 +08:00
|
|
|
<Button type={type} onClick={onClick}>{children}</Button>
|
2016-02-29 18:02:05 +08:00
|
|
|
<Dropdown align={align} overlay={overlay} trigger={trigger}>
|
|
|
|
<Button type={type}>
|
2016-01-07 14:21:29 +08:00
|
|
|
<Icon type="down" />
|
|
|
|
</Button>
|
|
|
|
</Dropdown>
|
|
|
|
</ButtonGroup>
|
|
|
|
);
|
2015-12-02 15:18:15 +08:00
|
|
|
}
|
2016-03-18 10:31:25 +08:00
|
|
|
}
|