ant-design/components/dropdown/dropdown-button.tsx
afc163 30fe9918d8
Merge branch 'master' into feature
* master:
  📝 Add bodyStyle and style of Drawer in documentation, #13850
  🐛 Fix Drawer style not working
  🐛 fix markStyle affset style
  Update Santa.jsx
  update changelog
  bump 3.11.6
  revert Christmas egg
  [type] make type of components compatible with ComponentType<P>
  bump 3.11.5
   site: make document side bar sticky
2018-12-25 16:28:50 +08:00

80 lines
2.2 KiB
TypeScript

import * as React from 'react';
import Button from '../button';
import { ButtonHTMLType } from '../button/button';
import { ButtonGroupProps } from '../button/button-group';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import Dropdown, { DropDownProps } from './dropdown';
import classNames from 'classnames';
const ButtonGroup = Button.Group;
type DropdownButtonType = 'primary' | 'ghost' | 'dashed';
export interface DropdownButtonProps extends ButtonGroupProps, DropDownProps {
type?: DropdownButtonType;
htmlType?: ButtonHTMLType;
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
href?: string;
children?: any;
}
export default class DropdownButton extends React.Component<DropdownButtonProps, any> {
static defaultProps = {
placement: 'bottomRight' as DropDownProps['placement'],
type: 'default' as DropdownButtonType,
};
renderButton = ({
getPopupContainer: getContextPopupContainer,
getPrefixCls,
}: ConfigConsumerProps) => {
const {
prefixCls: customizePrefixCls,
type,
disabled,
onClick,
htmlType,
children,
className,
overlay,
trigger,
align,
visible,
onVisibleChange,
placement,
getPopupContainer,
href,
...restProps
} = this.props;
const prefixCls = getPrefixCls('dropdown-button', customizePrefixCls);
const dropdownProps = {
align,
overlay,
disabled,
trigger: disabled ? [] : trigger,
onVisibleChange,
placement,
getPopupContainer: getPopupContainer || getContextPopupContainer,
} as DropDownProps;
if ('visible' in this.props) {
dropdownProps.visible = visible;
}
return (
<ButtonGroup {...restProps} className={classNames(prefixCls, className)}>
<Button type={type} disabled={disabled} onClick={onClick} htmlType={htmlType} href={href}>
{children}
</Button>
<Dropdown {...dropdownProps}>
<Button type={type} icon="ellipsis" />
</Dropdown>
</ButtonGroup>
);
};
render() {
return <ConfigConsumer>{this.renderButton}</ConfigConsumer>;
}
}