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

76 lines
2.0 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2015-12-02 15:18:15 +08:00
import Button from '../button';
import { ButtonHTMLType } from '../button/button';
import { ButtonGroupProps } from '../button/button-group';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
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';
htmlType?: ButtonHTMLType;
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',
2016-07-13 11:14:24 +08:00
};
2018-12-07 20:02:01 +08:00
renderButton = ({
getPopupContainer: getContextPopupContainer,
getPrefixCls,
}: ConfigConsumerProps) => {
2016-12-19 15:19:15 +08:00
const {
prefixCls: customizePrefixCls,
2018-12-07 20:02:01 +08:00
type,
disabled,
onClick,
htmlType,
children,
className,
overlay,
trigger,
align,
visible,
onVisibleChange,
placement,
getPopupContainer,
...restProps
2016-12-19 15:19:15 +08:00
} = this.props;
const prefixCls = getPrefixCls('dropdown-button', customizePrefixCls);
const dropdownProps = {
align,
overlay,
disabled,
trigger: disabled ? [] : trigger,
onVisibleChange,
placement,
2018-11-26 12:06:42 +08:00
getPopupContainer: getPopupContainer || getContextPopupContainer,
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 (
2018-12-07 20:02:01 +08:00
<ButtonGroup {...restProps} className={classNames(prefixCls, className)}>
<Button type={type} disabled={disabled} onClick={onClick} htmlType={htmlType}>
2017-06-20 09:46:23 +08:00
{children}
</Button>
<Dropdown {...dropdownProps}>
<Button type={type} icon="ellipsis" />
</Dropdown>
</ButtonGroup>
);
2018-12-07 20:02:01 +08:00
};
2018-11-26 12:06:42 +08:00
render() {
2018-12-07 20:02:01 +08:00
return <ConfigConsumer>{this.renderButton}</ConfigConsumer>;
2018-11-26 12:06:42 +08:00
}
}