2016-09-19 11:42:03 +08:00
|
|
|
import 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-08-19 16:43:32 +08:00
|
|
|
|
|
|
|
export interface DropdownButtonProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
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;
|
|
|
|
style?: React.CSSProperties;
|
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 = {
|
|
|
|
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-12-19 15:19:15 +08:00
|
|
|
const {
|
|
|
|
type, overlay, trigger, align, children, className, onClick, prefixCls,
|
|
|
|
disabled, visible, onVisibleChange, ...restProps,
|
|
|
|
} = 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,
|
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
|
|
|
}
|