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

62 lines
1.5 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2015-12-02 15:18:15 +08:00
import Button from '../button';
import { ButtonGroupProps } from '../button/button-group';
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;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
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,
disabled,
trigger: disabled ? [] : trigger,
onVisibleChange,
placement,
getPopupContainer,
2018-05-21 21:02:03 +08:00
} as DropDownProps;
if ('visible' in this.props) {
2018-05-21 21:02:03 +08:00
dropdownProps.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} icon="ellipsis" />
</Dropdown>
</ButtonGroup>
);
2015-12-02 15:18:15 +08:00
}
}