feat: dropdown support set right icon

This commit is contained in:
DiamondYuan 2019-04-10 17:09:41 +08:00
parent 98fc8a14e0
commit de7c8d09bd
7 changed files with 78 additions and 33 deletions

View File

@ -51,7 +51,7 @@ exports[`renders ./components/dropdown/demo/dropdown-button.md correctly 1`] = `
</span>
</button>
<button
class="ant-btn ant-dropdown-trigger ant-btn-default ant-btn-icon-only"
class="ant-btn ant-dropdown-trigger ant-btn-default"
type="button"
>
<i
@ -75,6 +75,42 @@ exports[`renders ./components/dropdown/demo/dropdown-button.md correctly 1`] = `
</i>
</button>
</div>
<div
class="ant-btn-group ant-dropdown-button"
style="margin-left:8px"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Dropdown
</span>
</button>
<button
class="ant-btn ant-dropdown-trigger ant-btn-default"
type="button"
>
<i
aria-label="icon: user"
class="anticon anticon-user"
>
<svg
aria-hidden="true"
class=""
data-icon="user"
fill="currentColor"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M858.5 763.6a374 374 0 0 0-80.6-119.5 375.63 375.63 0 0 0-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 0 0-80.6 119.5A371.7 371.7 0 0 0 136 901.8a8 8 0 0 0 8 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 0 0 8-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"
/>
</svg>
</i>
</button>
</div>
<div
class="ant-btn-group ant-dropdown-button"
style="margin-left:8px"
@ -89,7 +125,7 @@ exports[`renders ./components/dropdown/demo/dropdown-button.md correctly 1`] = `
</span>
</button>
<button
class="ant-btn ant-dropdown-trigger ant-btn-default ant-btn-icon-only"
class="ant-btn ant-dropdown-trigger ant-btn-default"
disabled=""
type="button"
>

View File

@ -9,7 +9,7 @@ exports[`DropdownButton should support href like Button 1`] = `
href="https://ant.design"
/>
<button
class="ant-btn ant-dropdown-trigger ant-btn-default ant-btn-icon-only"
class="ant-btn ant-dropdown-trigger ant-btn-default"
type="button"
>
<i

View File

@ -8,10 +8,12 @@ title:
## zh-CN
左边是按钮,右边是额外的相关功能菜单。
可以设置 icon 属性 来修改右边的 icon
## en-US
A button is on the left, and a related functional menu is on the right.
You can set the icon property to modify the icon of right.
````jsx
import {
@ -41,12 +43,10 @@ ReactDOM.render(
<Dropdown.Button onClick={handleButtonClick} overlay={menu}>
Dropdown
</Dropdown.Button>
<Dropdown.Button
onClick={handleButtonClick}
overlay={menu}
disabled
style={{ marginLeft: 8 }}
>
<Dropdown.Button overlay={menu} icon={<Icon type="user" />} style={{ marginLeft: 8 }}>
Dropdown
</Dropdown.Button>
<Dropdown.Button onClick={handleButtonClick} overlay={menu} disabled style={{ marginLeft: 8 }}>
Dropdown
</Dropdown.Button>
<Dropdown overlay={menu}>
@ -55,6 +55,6 @@ ReactDOM.render(
</Button>
</Dropdown>
</div>,
mountNode
mountNode,
);
````

View File

@ -16,7 +16,7 @@ The menu has multiple levels.
````jsx
import { Menu, Dropdown, Icon } from 'antd';
const SubMenu = Menu.SubMenu;
const {SubMenu} = Menu;
const menu = (
<Menu>

View File

@ -5,6 +5,7 @@ import { ButtonGroupProps } from '../button/button-group';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import Dropdown, { DropDownProps } from './dropdown';
import classNames from 'classnames';
import Icon from '../icon';
const ButtonGroup = Button.Group;
type DropdownButtonType = 'primary' | 'ghost' | 'dashed';
@ -14,12 +15,17 @@ export interface DropdownButtonProps extends ButtonGroupProps, DropDownProps {
htmlType?: ButtonHTMLType;
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
/**
* @since 3.17.0
*/
icon?: React.ReactNode;
href?: string;
children?: any;
}
export default class DropdownButton extends React.Component<DropdownButtonProps, any> {
static defaultProps = {
icon: <Icon type="ellipsis" />,
placement: 'bottomRight' as DropDownProps['placement'],
type: 'default' as DropdownButtonType,
};
@ -44,6 +50,7 @@ export default class DropdownButton extends React.Component<DropdownButtonProps,
placement,
getPopupContainer,
href,
icon,
...restProps
} = this.props;
@ -67,7 +74,7 @@ export default class DropdownButton extends React.Component<DropdownButtonProps,
{children}
</Button>
<Dropdown {...dropdownProps}>
<Button type={type} icon="ellipsis" />
<Button type={type}>{icon}</Button>
</Dropdown>
</ButtonGroup>
);

View File

@ -34,14 +34,15 @@ You should use [Menu](/components/menu/) as `overlay`. The menu items and divide
### Dropdown.Button
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| disabled | whether the dropdown menu is disabled | boolean | - |
| overlay | the dropdown menu | [Menu](/components/menu) | - |
| placement | placement of pop menu: `bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` |
| size | size of the button, the same as [Button](/components/button) | string | `default` |
| trigger | the trigger mode which executes the drop-down action | Array&lt;`click`\|`hover`\|`contextMenu`> | `['hover']` |
| type | type of the button, the same as [Button](/components/button) | string | `default` |
| visible | whether the dropdown menu is visible | boolean | - |
| onClick | a callback function, the same as [Button](/components/button), which will be executed when you click the button on the left | Function | - |
| onVisibleChange | a callback function takes an argument: `visible`, is executed when the visible state is changed | Function | - |
| Property | Description | Type | Default | Version|
| -------- | ----------- | ---- | ------- |------- |
| disabled | whether the dropdown menu is disabled | boolean | - ||
| overlay | the dropdown menu | [Menu](/components/menu) | - ||
| placement | placement of pop menu: `bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` ||
| size | size of the button, the same as [Button](/components/button) | string | `default` ||
| trigger | the trigger mode which executes the drop-down action | Array&lt;`click`\|`hover`\|`contextMenu`> | `['hover']` ||
| type | type of the button, the same as [Button](/components/button) | string | `default` ||
| visible | whether the dropdown menu is visible | boolean | - ||
| onClick | a callback function, the same as [Button](/components/button), which will be executed when you click the button on the left | Function | - ||
| onVisibleChange | a callback function takes an argument: `visible`, is executed when the visible state is changed | Function | - ||
| icon | icon of right | ReactNode | - | 3.17.0 |

View File

@ -35,14 +35,15 @@ title: Dropdown
### Dropdown.Button
| 参数 | 说明 | 类型 | 默认值 |
| 参数 | 说明 | 类型 | 默认值 |版本|
| --- | --- | --- | --- |
| disabled | 菜单是否禁用 | boolean | - |
| overlay | 菜单 | [Menu](/components/menu/) | - |
| placement | 菜单弹出位置:`bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` |
| size | 按钮大小,和 [Button](/components/button/) 一致 | string | 'default' |
| trigger | 触发下拉的行为 | Array&lt;`click`\|`hover`\|`contextMenu`> | `['hover']` |
| type | 按钮类型,和 [Button](/components/button/) 一致 | string | 'default' |
| visible | 菜单是否显示 | boolean | - |
| onClick | 点击左侧按钮的回调,和 [Button](/components/button/) 一致 | Function | - |
| onVisibleChange | 菜单显示状态改变时调用,参数为 visible | Function | - |
| disabled | 菜单是否禁用 | boolean | - |||
| overlay | 菜单 | [Menu](/components/menu/) | - ||
| placement | 菜单弹出位置:`bottomLeft` `bottomCenter` `bottomRight` `topLeft` `topCenter` `topRight` | String | `bottomLeft` ||
| size | 按钮大小,和 [Button](/components/button/) 一致 | string | 'default' ||
| trigger | 触发下拉的行为 | Array&lt;`click`\|`hover`\|`contextMenu`> | `['hover']` ||
| type | 按钮类型,和 [Button](/components/button/) 一致 | string | 'default' ||
| visible | 菜单是否显示 | boolean | - ||
| onClick | 点击左侧按钮的回调,和 [Button](/components/button/) 一致 | Function | - ||
| onVisibleChange | 菜单显示状态改变时调用,参数为 visible | Function | - ||
| icon | 右侧的 icon | ReactNode | - |3.17.0|