2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2015-12-02 15:18:15 +08:00
|
|
|
import Button from '../button';
|
2017-06-16 20:28:42 +08:00
|
|
|
import { ButtonGroupProps } from '../button/button-group';
|
2015-12-02 15:18:15 +08:00
|
|
|
import Icon from '../icon';
|
2017-06-20 09:46:23 +08:00
|
|
|
import Dropdown, { DropDownProps } from './dropdown';
|
2016-02-29 18:02:05 +08:00
|
|
|
import classNames from 'classnames';
|
2017-06-20 09:46:23 +08:00
|
|
|
const ButtonGroup = Button.Group;
|
2016-08-19 16:43:32 +08:00
|
|
|
|
2017-06-20 09:46:23 +08:00
|
|
|
export interface DropdownButtonProps extends ButtonGroupProps, DropDownProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
type?: 'primary' | 'ghost' | 'dashed';
|
2016-09-19 11:42:03 +08:00
|
|
|
disabled?: boolean;
|
2017-06-20 09:46:23 +08:00
|
|
|
onClick?: React.MouseEventHandler<any>;
|
2016-12-19 15:19:15 +08:00
|
|
|
children?: any;
|
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 = {
|
2017-04-05 11:17:07 +08:00
|
|
|
placement: 'bottomRight',
|
2016-03-29 14:01:10 +08:00
|
|
|
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-12-19 15:19:15 +08:00
|
|
|
const {
|
2017-06-20 09:46:23 +08:00
|
|
|
type, disabled, onClick, children,
|
|
|
|
prefixCls, className, overlay, trigger, align,
|
|
|
|
visible, onVisibleChange, placement, getPopupContainer,
|
|
|
|
...restProps,
|
2016-12-19 15:19:15 +08:00
|
|
|
} = this.props;
|
2016-11-11 15:26:57 +08:00
|
|
|
|
2016-11-13 15:53:02 +08:00
|
|
|
const dropdownProps = {
|
2016-12-03 17:31:04 +08:00
|
|
|
align,
|
|
|
|
overlay,
|
|
|
|
trigger: disabled ? [] : trigger,
|
|
|
|
onVisibleChange,
|
2017-04-01 18:06:40 +08:00
|
|
|
placement,
|
2017-06-20 09:33:15 +08:00
|
|
|
getPopupContainer,
|
2016-11-13 15:53:02 +08:00
|
|
|
};
|
|
|
|
if ('visible' in this.props) {
|
|
|
|
(dropdownProps as any).visible = visible;
|
|
|
|
}
|
|
|
|
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
2017-06-20 09:46:23 +08:00
|
|
|
<ButtonGroup
|
|
|
|
{...restProps}
|
|
|
|
className={classNames(prefixCls, className)}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
type={type}
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Button>
|
2016-11-13 15:53:02 +08:00
|
|
|
<Dropdown {...dropdownProps}>
|
2016-09-19 11:42:03 +08:00
|
|
|
<Button type={type} disabled={disabled}>
|
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
|
|
|
}
|