feat: add Button danger

This commit is contained in:
ycjcl868 2019-11-22 15:32:11 +08:00 committed by GitHub Action
parent 3a6c76ecc3
commit 37a85366f3
12 changed files with 201 additions and 256 deletions

View File

@ -27,13 +27,29 @@ exports[`renders ./components/button/demo/basic.md correctly 1`] = `
</span>
</button>
<button
class="ant-btn ant-btn-danger"
class="ant-btn ant-btn-primary ant-btn-dangerous"
type="button"
>
<span>
Danger
</span>
</button>
<button
class="ant-btn ant-btn-dangerous"
type="button"
>
<span>
Danger default
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-dangerous"
type="button"
>
<span>
Danger Link
</span>
</button>
<button
class="ant-btn ant-btn-link"
type="button"
@ -72,13 +88,29 @@ exports[`renders ./components/button/demo/block.md correctly 1`] = `
</span>
</button>
<button
class="ant-btn ant-btn-danger ant-btn-block"
class="ant-btn ant-btn-primary ant-btn-block ant-btn-dangerous"
type="button"
>
<span>
Danger
</span>
</button>
<button
class="ant-btn ant-btn-block ant-btn-dangerous"
type="button"
>
<span>
Danger Default
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-block ant-btn-dangerous"
type="button"
>
<span>
Danger Link
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-block"
type="button"
@ -163,6 +195,42 @@ exports[`renders ./components/button/demo/disabled.md correctly 1`] = `
Link(disabled)
</span>
</button>
<br />
<button
class="ant-btn ant-btn-link ant-btn-dangerous"
type="button"
>
<span>
Danger Link
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-dangerous"
disabled=""
type="button"
>
<span>
Danger Link(disabled)
</span>
</button>
<br />
<button
class="ant-btn ant-btn-dangerous"
type="button"
>
<span>
Danger Default
</span>
</button>
<button
class="ant-btn ant-btn-dangerous"
disabled=""
type="button"
>
<span>
Danger Default(disabled)
</span>
</button>
<div
style="padding:8px 8px 0 8px;background:rgb(190, 200, 200)"
>
@ -208,13 +276,29 @@ exports[`renders ./components/button/demo/ghost.md correctly 1`] = `
</span>
</button>
<button
class="ant-btn ant-btn-danger ant-btn-background-ghost"
class="ant-btn ant-btn-primary ant-btn-background-ghost ant-btn-dangerous"
type="button"
>
<span>
danger
</span>
</button>
<button
class="ant-btn ant-btn-background-ghost ant-btn-dangerous"
type="button"
>
<span>
Danger Default
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-background-ghost ant-btn-dangerous"
type="button"
>
<span>
Danger Link
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-background-ghost"
type="button"
@ -670,14 +754,31 @@ exports[`renders ./components/button/demo/size.md correctly 1`] = `
Dashed
</span>
</button>
<br />
<button
class="ant-btn ant-btn-danger ant-btn-lg"
class="ant-btn ant-btn-primary ant-btn-lg ant-btn-dangerous"
type="button"
>
<span>
Danger
</span>
</button>
<button
class="ant-btn ant-btn-lg ant-btn-dangerous"
type="button"
>
<span>
Danger Default
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-lg ant-btn-dangerous"
type="button"
>
<span>
Danger Link
</span>
</button>
<button
class="ant-btn ant-btn-link ant-btn-lg"
type="button"
@ -818,66 +919,5 @@ exports[`renders ./components/button/demo/size.md correctly 1`] = `
Download
</span>
</button>
<br />
<div
class="ant-btn-group ant-btn-group-lg"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span
aria-label="left"
class="anticon anticon-left"
role="img"
>
<svg
aria-hidden="true"
class=""
data-icon="left"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 000 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"
/>
</svg>
</span>
<span>
Backward
</span>
</button>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Forward
</span>
<span
aria-label="right"
class="anticon anticon-right"
role="img"
>
<svg
aria-hidden="true"
class=""
data-icon="right"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z"
/>
</svg>
</span>
</button>
</div>
</div>
`;

View File

@ -9,6 +9,7 @@ import omit from 'omit.js';
import Group from './button-group';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import Wave from '../_util/wave';
import warning from '../_util/warning';
import { Omit, tuple } from '../_util/type';
const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
@ -65,16 +66,7 @@ function spaceChildren(children: React.ReactNode, needInserted: boolean) {
);
}
const ButtonTypes = tuple(
'default',
'primary',
'ghost',
'dashed',
'danger',
'danger-link',
'danger-default',
'link',
);
const ButtonTypes = tuple('default', 'primary', 'ghost', 'dashed', 'danger', 'link');
export type ButtonType = typeof ButtonTypes[number];
const ButtonShapes = tuple('circle', 'circle-outline', 'round');
export type ButtonShape = typeof ButtonShapes[number];
@ -92,6 +84,7 @@ export interface BaseButtonProps {
prefixCls?: string;
className?: string;
ghost?: boolean;
danger?: boolean;
block?: boolean;
children?: React.ReactNode;
}
@ -158,6 +151,11 @@ class Button extends React.Component<ButtonProps, ButtonState> {
componentDidMount() {
this.fixTwoCNChar();
warning(
!('type' in this.props && this.props.type === 'danger'),
'Button',
'`type="danger"` is deprecated, please use `danger` instead.',
);
}
componentDidUpdate(prevProps: ButtonProps) {
@ -227,6 +225,7 @@ class Button extends React.Component<ButtonProps, ButtonState> {
const {
prefixCls: customizePrefixCls,
type,
danger,
shape,
size,
className,
@ -266,6 +265,7 @@ class Button extends React.Component<ButtonProps, ButtonState> {
[`${prefixCls}-background-ghost`]: ghost,
[`${prefixCls}-two-chinese-chars`]: hasTwoCNChar && autoInsertSpace,
[`${prefixCls}-block`]: block,
[`${prefixCls}-dangerous`]: !!danger,
});
const iconNode = loading ? <Loading /> : icon || null;
@ -305,7 +305,7 @@ class Button extends React.Component<ButtonProps, ButtonState> {
</button>
);
if (type === 'link' || type === 'danger-link') {
if (type === 'link') {
return buttonNode;
}

View File

@ -21,9 +21,13 @@ ReactDOM.render(
<Button type="primary">Primary</Button>
<Button>Default</Button>
<Button type="dashed">Dashed</Button>
<Button type="danger">Danger</Button>
<Button type="danger-default">Danger default</Button>
<Button type="danger-link">Danger Link</Button>
<Button type="primary" danger>
Danger
</Button>
<Button danger>Danger default</Button>
<Button type="link" danger>
Danger Link
</Button>
<Button type="link">Link</Button>
</div>,
mountNode,

View File

@ -25,13 +25,13 @@ ReactDOM.render(
<Button type="dashed" block>
Dashed
</Button>
<Button type="danger" block>
<Button type="primary" danger block>
Danger
</Button>
<Button type="danger-default" block>
<Button danger block>
Danger Default
</Button>
<Button type="danger-link" block>
<Button type="link" danger block>
Danger Link
</Button>
<Button type="link" block>

View File

@ -36,13 +36,15 @@ ReactDOM.render(
Link(disabled)
</Button>
<br />
<Button type="danger-link">Danger Link</Button>
<Button type="danger-link" disabled>
<Button type="link" danger>
Danger Link
</Button>
<Button type="link" danger disabled>
Danger Link(disabled)
</Button>
<br />
<Button type="danger-default">Danger Default</Button>
<Button type="danger-default" disabled>
<Button danger>Danger Default</Button>
<Button danger disabled>
Danger Default(disabled)
</Button>
<div style={{ padding: '8px 8px 0 8px', background: 'rgb(190, 200, 200)' }}>

View File

@ -22,13 +22,13 @@ ReactDOM.render(
Primary
</Button>
<Button ghost>Default</Button>
<Button type="danger" ghost>
<Button type="primary" danger ghost>
danger
</Button>
<Button type="danger-default" ghost>
<Button danger ghost>
Danger Default
</Button>
<Button type="danger-link" ghost>
<Button type="link" danger ghost>
Danger Link
</Button>
<Button type="link" ghost>

View File

@ -49,13 +49,13 @@ class ButtonSize extends React.Component {
Dashed
</Button>
<br />
<Button type="danger" size={size}>
<Button type="primary" danger size={size}>
Danger
</Button>
<Button type="danger-default" size={size}>
<Button danger size={size}>
Danger Default
</Button>
<Button type="danger-link" size={size}>
<Button danger type="link" size={size}>
Danger Link
</Button>
<Button type="link" size={size}>

View File

@ -25,9 +25,10 @@ To get a customized button, just set `type`/`shape`/`size`/`loading`/`disabled`.
| shape | can be set to `circle`, `round` or omitted | string | - | |
| size | can be set to `small` `large` or omitted | string | `default` | |
| target | same as target attribute of a, works when href is specified | string | - | |
| type | can be set to `primary` `ghost` `dashed` `danger` `link` or omitted (meaning `default`) | string | `default` | |
| type | can be set to `primary` `ghost` `dashed` `link` or omitted (meaning `default`) | string | `default` | |
| onClick | set the handler to handle `click` event | (event) => void | - | |
| block | option to fit button width to its parent width | boolean | `false` | |
| danger | set the danger status of button | boolean | `false` | |
It accepts all props which native buttons support.

View File

@ -28,9 +28,10 @@ subtitle: 按钮
| shape | 设置按钮形状,可选值为 `circle``round` 或者不设 | string | - | |
| size | 设置按钮大小,可选值为 `small` `large` 或者不设 | string | `default` | |
| target | 相当于 a 链接的 target 属性href 存在时生效 | string | - | |
| type | 设置按钮类型,可选值为 `primary` `dashed` `danger` `link` 或者不设 | string | - | |
| type | 设置按钮类型,可选值为 `primary` `dashed` `link` 或者不设 | string | - | |
| onClick | 点击按钮时的回调 | (event) => void | - | |
| block | 将按钮宽度调整为其父宽度的选项 | boolean | `false` | |
| danger | 设置危险按钮 | boolean | `false` | |
支持原生 button 的其他所有属性。

View File

@ -63,20 +63,26 @@
.btn-dashed;
}
// type="danger" will deprecated
// use danger instead
&-danger {
.btn-danger;
}
&-danger-default {
&-link {
.btn-link;
}
&-dangerous {
.btn-danger-default;
}
&-danger-link {
.btn-danger-link;
&-dangerous&-primary {
.btn-danger;
}
&-link {
.btn-link;
&-dangerous&-link {
.btn-danger-link;
}
&-icon-only {
@ -183,12 +189,6 @@
color: @component-background;
}
&-background-ghost&-danger-link {
.button-variant-ghost(@error-color; transparent);
color: @component-background;
}
&-two-chinese-chars::first-letter {
letter-spacing: 0.34em;
}

View File

@ -384,13 +384,11 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
<a
style="margin-right:16px"
>
Invite John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
Delete
</a>
@ -432,13 +430,11 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
<a
style="margin-right:16px"
>
Invite Jim Green
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
Delete
</a>
@ -485,13 +481,11 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
<a
style="margin-right:16px"
>
Invite Joe Black
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
Delete
</a>
@ -2460,20 +2454,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -2554,20 +2539,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -2648,20 +2624,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -2742,20 +2709,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -2836,20 +2794,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -2930,20 +2879,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -3024,20 +2964,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -3118,20 +3049,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -3212,20 +3134,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -3306,20 +3219,11 @@ exports[`renders ./components/table/demo/dynamic-settings.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
Action 一 John Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
<a
style="margin-right:16px"
>
Delete
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a
class="ant-dropdown-link"
>
@ -8775,13 +8679,11 @@ exports[`renders ./components/table/demo/jsx.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
<a
style="margin-right:16px"
>
Invite Brown
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
Delete
</a>
@ -8826,13 +8728,11 @@ exports[`renders ./components/table/demo/jsx.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
<a
style="margin-right:16px"
>
Invite Green
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
Delete
</a>
@ -8882,13 +8782,11 @@ exports[`renders ./components/table/demo/jsx.md correctly 1`] = `
class="ant-table-cell"
>
<span>
<a>
<a
style="margin-right:16px"
>
Invite Black
</a>
<div
class="ant-divider ant-divider-vertical"
role="separator"
/>
<a>
Delete
</a>

View File

@ -39,7 +39,6 @@ const columns = [
key: 'action',
render: (text, record) => (
<span>
<a style={{ marginRight: 16 }}>Action 一 {record.name}</a>
<a style={{ marginRight: 16 }}>Delete</a>
<a className="ant-dropdown-link">
More actions <Down />