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

62 lines
1.7 KiB
TypeScript
Raw Normal View History

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;
import classNames from 'classnames';
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;
overlay: React.ReactNode;
visible?: boolean;
disabled?: boolean;
onVisibleChange?: (visible: boolean) => void;
style?: React.CSSProperties;
2016-12-19 15:19:15 +08:00
children?: any;
placement?: 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight';
}
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 {
type, overlay, trigger, align, children, className, onClick, prefixCls,
disabled, visible, onVisibleChange, placement, ...restProps,
2016-12-19 15:19:15 +08:00
} = this.props;
const cls = classNames(prefixCls, className);
const dropdownProps = {
align,
overlay,
trigger: disabled ? [] : trigger,
onVisibleChange,
placement,
};
if ('visible' in this.props) {
(dropdownProps as any).visible = visible;
}
return (
<ButtonGroup {...restProps} className={cls}>
<Button type={type} onClick={onClick} disabled={disabled}>{children}</Button>
<Dropdown {...dropdownProps}>
<Button type={type} disabled={disabled}>
<Icon type="down" />
</Button>
</Dropdown>
</ButtonGroup>
);
2015-12-02 15:18:15 +08:00
}
}