Skip to content

Commit ad81186

Browse files
sendyatangjinzhou
authored andcommitted
feat: button support link type (#1077)
1 parent 6d1a385 commit ad81186

File tree

12 files changed

+73
-28
lines changed

12 files changed

+73
-28
lines changed

components/button/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`renders ./components/button/demo/basic.md correctly 1`] = `<div><button type="button" class="ant-btn ant-btn-primary"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default"><span>Default</span></button> <button type="button" class="ant-btn ant-btn-dashed"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger"><span>Danger</span></button></div>`;
3+
exports[`renders ./components/button/demo/basic.md correctly 1`] = `<div><button type="button" class="ant-btn ant-btn-primary"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default"><span>Default</span></button> <button type="button" class="ant-btn ant-btn-dashed"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger"><span>Danger</span></button> <button type="button" class="ant-btn ant-btn-link"><span>Link</span></button></div>`;
44

5-
exports[`renders ./components/button/demo/block.md correctly 1`] = `<div><button type="button" class="ant-btn ant-btn-primary ant-btn-block"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default ant-btn-block"><span>Default</span></button> <button type="button" class="ant-btn ant-btn-dashed ant-btn-block"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger ant-btn-block"><span>danger</span></button></div>`;
5+
exports[`renders ./components/button/demo/block.md correctly 1`] = `<div><button type="button" class="ant-btn ant-btn-primary ant-btn-block"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default ant-btn-block"><span>Default</span></button> <button type="button" class="ant-btn ant-btn-dashed ant-btn-block"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger ant-btn-block"><span>Danger</span></button> <button type="button" class="ant-btn ant-btn-link ant-btn-block"><span>Link</span></button></div>`;
66

77
exports[`renders ./components/button/demo/button-group.md correctly 1`] = `
88
<div id="components-button-demo-button-group">
@@ -26,12 +26,12 @@ exports[`renders ./components/button/demo/button-group.md correctly 1`] = `
2626
`;
2727

2828
exports[`renders ./components/button/demo/disabled.md correctly 1`] = `
29-
<div><button type="button" class="ant-btn ant-btn-primary"><span>Primary</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-primary"><span>Primary(disabled)</span></button> <br> <button type="button" class="ant-btn ant-btn-default"><span>Default</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-default"><span>Default(disabled)</span></button> <br> <button type="button" class="ant-btn ant-btn-dashed"><span>Dashed</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-dashed"><span>Dashed(disabled)</span></button>
29+
<div><button type="button" class="ant-btn ant-btn-primary"><span>Primary</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-primary"><span>Primary(disabled)</span></button> <br> <button type="button" class="ant-btn ant-btn-default"><span>Default</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-default"><span>Default(disabled)</span></button> <br> <button type="button" class="ant-btn ant-btn-dashed"><span>Dashed</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-dashed"><span>Dashed(disabled)</span></button> <br> <button type="button" class="ant-btn ant-btn-link"><span>Link</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-link"><span>Link(disabled)</span></button>
3030
<div style="padding: 8px 8px 0px 8px; background: rgb(190, 200, 200);"><button type="button" class="ant-btn ant-btn-default ant-btn-background-ghost"><span>Ghost</span></button> <button disabled="disabled" type="button" class="ant-btn ant-btn-default ant-btn-background-ghost"><span>Ghost(disabled)</span></button></div>
3131
</div>
3232
`;
3333
34-
exports[`renders ./components/button/demo/ghost.md correctly 1`] = `<div style="background: rgb(190, 200, 200); padding: 26px 16px 16px;"><button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default ant-btn-background-ghost"><span>Default</span></button> <button type="button" class="ant-btn ant-btn-dashed ant-btn-background-ghost"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger ant-btn-background-ghost"><span>danger</span></button></div>`;
34+
exports[`renders ./components/button/demo/ghost.md correctly 1`] = `<div style="background: rgb(190, 200, 200); padding: 26px 16px 16px;"><button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default ant-btn-background-ghost"><span>Default</span></button> <button type="button" class="ant-btn ant-btn-dashed ant-btn-background-ghost"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger ant-btn-background-ghost"><span>Danger</span></button> <button type="button" class="ant-btn ant-btn-link ant-btn-background-ghost"><span>Link</span></button></div>`;
3535
3636
exports[`renders ./components/button/demo/icon.md correctly 1`] = `
3737
<div><button type="button" class="ant-btn ant-btn-primary ant-btn-circle"><i class="anticon anticon-search"><svg viewBox="64 64 896 896" data-icon="search" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
@@ -75,7 +75,7 @@ exports[`renders ./components/button/demo/multiple.md correctly 1`] = `
7575
7676
exports[`renders ./components/button/demo/size.md correctly 1`] = `
7777
<div>
78-
<div class="ant-radio-group ant-radio-group-outline ant-radio-group-default"><label class="ant-radio-button-wrapper ant-radio-button-wrapper-checked"><span class="ant-radio-button ant-radio-button-checked"><input type="radio" class="ant-radio-button-input" value="large"><span class="ant-radio-button-inner"></span></span><span>Large</span></label><label class="ant-radio-button-wrapper"><span class="ant-radio-button"><input type="radio" class="ant-radio-button-input" value="default"><span class="ant-radio-button-inner"></span></span><span>Default</span></label><label class="ant-radio-button-wrapper"><span class="ant-radio-button"><input type="radio" class="ant-radio-button-input" value="small"><span class="ant-radio-button-inner"></span></span><span>Small</span></label></div> <br><br> <button type="button" class="ant-btn ant-btn-primary ant-btn-lg"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default ant-btn-lg"><span>Normal</span></button> <button type="button" class="ant-btn ant-btn-dashed ant-btn-lg"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger ant-btn-lg"><span>Danger</span></button> <br> <button type="button" class="ant-btn ant-btn-primary ant-btn-circle ant-btn-lg"><i class="anticon anticon-download"><svg viewBox="64 64 896 896" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
78+
<div class="ant-radio-group ant-radio-group-outline ant-radio-group-default"><label class="ant-radio-button-wrapper ant-radio-button-wrapper-checked"><span class="ant-radio-button ant-radio-button-checked"><input type="radio" class="ant-radio-button-input" value="large"><span class="ant-radio-button-inner"></span></span><span>Large</span></label><label class="ant-radio-button-wrapper"><span class="ant-radio-button"><input type="radio" class="ant-radio-button-input" value="default"><span class="ant-radio-button-inner"></span></span><span>Default</span></label><label class="ant-radio-button-wrapper"><span class="ant-radio-button"><input type="radio" class="ant-radio-button-input" value="small"><span class="ant-radio-button-inner"></span></span><span>Small</span></label></div> <br><br> <button type="button" class="ant-btn ant-btn-primary ant-btn-lg"><span>Primary</span></button> <button type="button" class="ant-btn ant-btn-default ant-btn-lg"><span>Normal</span></button> <button type="button" class="ant-btn ant-btn-dashed ant-btn-lg"><span>Dashed</span></button> <button type="button" class="ant-btn ant-btn-danger ant-btn-lg"><span>Danger</span></button> <button type="button" class="ant-btn ant-btn-link ant-btn-lg"><span>Link</span></button> <br> <button type="button" class="ant-btn ant-btn-primary ant-btn-circle ant-btn-lg"><i class="anticon anticon-download"><svg viewBox="64 64 896 896" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
7979
<path d="M505.7 661a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path>
8080
</svg></i></button> <button type="button" class="ant-btn ant-btn-primary ant-btn-lg"><i class="anticon anticon-download"><svg viewBox="64 64 896 896" data-icon="download" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
8181
<path d="M505.7 661a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"></path>

components/button/button.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export default {
118118
},
119119
render() {
120120
const {
121+
type,
121122
htmlType,
122123
classes,
123124
icon,
@@ -151,15 +152,19 @@ export default {
151152
{kids}
152153
</a>
153154
);
154-
} else {
155-
return (
156-
<Wave>
157-
<button {...buttonProps} ref="buttonNode" type={htmlType || 'button'}>
158-
{iconNode}
159-
{kids}
160-
</button>
161-
</Wave>
162-
);
163155
}
156+
157+
const buttonNode = (
158+
<button {...buttonProps} ref="buttonNode" type={htmlType || 'button'}>
159+
{iconNode}
160+
{kids}
161+
</button>
162+
);
163+
164+
if (type === 'link') {
165+
return buttonNode;
166+
}
167+
168+
return <Wave>{buttonNode}</Wave>;
164169
},
165170
};

components/button/buttonTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from '../_util/vue-types';
22
export default () => ({
33
prefixCls: PropTypes.string.def('ant-btn'),
4-
type: PropTypes.oneOf(['primary', 'danger', 'dashed', 'ghost', 'default']).def('default'),
4+
type: PropTypes.oneOf(['primary', 'danger', 'dashed', 'ghost', 'link', 'default']).def('default'),
55
htmlType: PropTypes.oneOf(['button', 'submit', 'reset']).def('button'),
66
icon: PropTypes.string,
77
shape: PropTypes.oneOf(['circle', 'circle-outline']),

components/button/demo/basic.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
<cn>
33
#### 按钮类型
4-
按钮有四种类型:主按钮、次按钮、虚线按钮、危险按钮。主按钮在同一个操作区域最多出现一次。
4+
按钮有四种类型:主按钮、次按钮、虚线按钮、危险按钮和链接按钮。主按钮在同一个操作区域最多出现一次。
55
</cn>
66

77
<us>
88
#### Type
9-
There are `primary` button, `default` button, `dashed` button and `danger` button in antd.
9+
There are `primary` button, `default` button, `dashed` button and `danger` button and `link` button in antd.
1010
</us>
1111

1212
```html
@@ -16,6 +16,7 @@ There are `primary` button, `default` button, `dashed` button and `danger` butto
1616
<a-button>Default</a-button>
1717
<a-button type="dashed">Dashed</a-button>
1818
<a-button type="danger">Danger</a-button>
19+
<a-button type="link">Link</a-button>
1920
</div>
2021
</template>
2122
```

components/button/demo/block.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<a-button type="primary" block>Primary</a-button>
1616
<a-button block>Default</a-button>
1717
<a-button type="dashed" block>Dashed</a-button>
18-
<a-button type="danger" block>danger</a-button>
18+
<a-button type="danger" block>Danger</a-button>
19+
<a-button type="link" block>Link</a-button>
1920
</div>
2021
</template>
2122
```

components/button/demo/disabled.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ To mark a button as disabled, add the `disabled` property to the `Button`.
2020
<br />
2121
<a-button type="dashed">Dashed</a-button>
2222
<a-button type="dashed" disabled>Dashed(disabled)</a-button>
23+
<br />
24+
<a-button type="link">Link</a-button>
25+
<a-button type="link" disabled>Link(disabled)</a-button>
2326
<div :style="{ padding: '8px 8px 0 8px', background: 'rgb(190, 200, 200)' }">
2427
<a-button ghost>Ghost</a-button>
2528
<a-button ghost disabled>Ghost(disabled)</a-button>

components/button/demo/ghost.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<a-button type="primary" ghost>Primary</a-button>
1515
<a-button ghost>Default</a-button>
1616
<a-button type="dashed" ghost>Dashed</a-button>
17-
<a-button type="danger" ghost>danger</a-button>
17+
<a-button type="danger" ghost>Danger</a-button>
18+
<a-button type="link" ghost>Link</a-button>
1819
</div>
1920
</template>
2021
```

components/button/demo/size.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ If a large or small button is desired, set the `size` property to either `large`
2323
<a-button :size="size">Normal</a-button>
2424
<a-button type="dashed" :size="size">Dashed</a-button>
2525
<a-button type="danger" :size="size">Danger</a-button>
26+
<a-button type="link" :size="size">Link</a-button>
2627
<br />
2728
<a-button type="primary" shape="circle" icon="download" :size="size" />
2829
<a-button type="primary" icon="download" :size="size">Download</a-button>
@@ -51,4 +52,4 @@ export default {
5152
},
5253
}
5354
</script>
54-
```
55+
```

components/button/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To get a customized button, just set `type`/`shape`/`size`/`loading`/`disabled`.
1111
| loading | set the loading status of button | boolean \| { delay: number } | false |
1212
| shape | can be set to `circle` or omitted | string | - |
1313
| size | can be set to `small` `large` or omitted | string | `default` |
14-
| type | can be set to `primary` `ghost` `dashed` `danger`(added in 2.7) or omitted (meaning `default`) | string | `default` |
14+
| type | can be set to `primary` `ghost` `dashed` `danger` `link` or omitted (meaning `default`) | string | `default` |
1515
| block | option to fit button width to its parent width | boolean | `false` |
1616

1717
### events

components/button/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| loading | 设置按钮载入状态 | boolean \| { delay: number } | `false` |
1414
| shape | 设置按钮形状,可选值为 `circle` 或者不设 | string | - |
1515
| size | 设置按钮大小,可选值为 `small` `large` 或者不设 | string | `default` |
16-
| type | 设置按钮类型,可选值为 `primary` `dashed` `danger` | string | - |
16+
| type | 设置按钮类型,可选值为 `primary` `dashed` `danger` `link` 或者不设| string | `default` |
1717
| block | 将按钮宽度调整为其父宽度的选项 | boolean | `false` |
1818

1919
### 事件

0 commit comments

Comments
 (0)