ant-design/components/dropdown/dropdown-button.tsx

64 lines
1.6 KiB
TypeScript
Raw Normal View History

import React from 'react';
2015-12-02 15:18:15 +08:00
import Button from '../button';
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';
import classNames from 'classnames';
2017-06-20 09:46:23 +08:00
const ButtonGroup = Button.Group;
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';
disabled?: boolean;
2017-06-20 09:46:23 +08:00
onClick?: React.MouseEventHandler<any>;
2016-12-19 15:19:15 +08:00
children?: any;
}
export default class DropdownButton extends React.Component<DropdownButtonProps, any> {
static defaultProps = {
placement: 'bottomRight',
type: 'default',
prefixCls: 'ant-dropdown-button',
2016-07-13 11:14:24 +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;
const dropdownProps = {
align,
overlay,
trigger: disabled ? [] : trigger,
onVisibleChange,
placement,
getPopupContainer,
};
if ('visible' in this.props) {
(dropdownProps as any).visible = visible;
}
return (
2017-06-20 09:46:23 +08:00
<ButtonGroup
{...restProps}
className={classNames(prefixCls, className)}
>
<Button
type={type}
disabled={disabled}
onClick={onClick}
>
{children}
</Button>
<Dropdown {...dropdownProps}>
<Button type={type} disabled={disabled}>
<Icon type="down" />
</Button>
</Dropdown>
</ButtonGroup>
);
2015-12-02 15:18:15 +08:00
}
}