2016-09-19 11:42:03 +08:00
|
|
|
import 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';
|
|
|
|
import Dropdown from './dropdown';
|
|
|
|
const ButtonGroup = Button.Group;
|
2016-02-29 18:02:05 +08:00
|
|
|
import classNames from 'classnames';
|
2016-08-19 16:43:32 +08:00
|
|
|
|
2017-06-16 20:28:42 +08:00
|
|
|
export interface DropdownButtonProps extends ButtonGroupProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
type?: 'primary' | 'ghost' | 'dashed';
|
|
|
|
onClick?: React.MouseEventHandler<any>;
|
|
|
|
trigger?: ('click' | 'hover')[];
|
|
|
|
align?: any;
|
2016-08-19 16:43:32 +08:00
|
|
|
overlay: React.ReactNode;
|
|
|
|
visible?: boolean;
|
2016-09-19 11:42:03 +08:00
|
|
|
disabled?: boolean;
|
2016-08-19 16:43:32 +08:00
|
|
|
onVisibleChange?: (visible: boolean) => void;
|
2016-12-19 15:19:15 +08:00
|
|
|
children?: any;
|
2017-04-01 18:06:40 +08:00
|
|
|
placement?: 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight';
|
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 {
|
|
|
|
type, overlay, trigger, align, children, className, onClick, prefixCls,
|
2017-04-01 18:06:40 +08:00
|
|
|
disabled, visible, onVisibleChange, placement, ...restProps,
|
2016-12-19 15:19:15 +08:00
|
|
|
} = this.props;
|
2016-11-30 10:20:23 +08:00
|
|
|
const cls = classNames(prefixCls, className);
|
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,
|
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 (
|
2016-02-29 18:02:05 +08:00
|
|
|
<ButtonGroup {...restProps} className={cls}>
|
2016-09-19 11:42:03 +08:00
|
|
|
<Button type={type} onClick={onClick} disabled={disabled}>{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
|
|
|
}
|