Skip to content

Commit

Permalink
add link button
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Apr 25, 2019
1 parent 5d7b83f commit 4f4ae81
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 28 deletions.
32 changes: 18 additions & 14 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function insertSpace(child: React.ReactChild, needInserted: boolean) {
return child;
}

const ButtonTypes = tuple('default', 'primary', 'ghost', 'dashed', 'danger');
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];
Expand Down Expand Up @@ -266,20 +266,24 @@ class Button extends React.Component<ButtonProps, ButtonState> {
// React does not recognize the `htmlType` prop on a DOM element. Here we pick it out of `rest`.
const { htmlType, ...otherProps } = rest as NativeButtonProps;

return (
<Wave>
<button
{...otherProps as NativeButtonProps}
type={htmlType}
className={classes}
onClick={this.handleClick}
ref={this.saveButtonRef}
>
{iconNode}
{kids}
</button>
</Wave>
const buttonNode = (
<button
{...otherProps as NativeButtonProps}
type={htmlType}
className={classes}
onClick={this.handleClick}
ref={this.saveButtonRef}
>
{iconNode}
{kids}
</button>
);

if (type === 'link') {
return buttonNode;
}

return <Wave>{buttonNode}</Wave>;
};

render() {
Expand Down
1 change: 1 addition & 0 deletions components/button/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ReactDOM.render(
<Button>Default</Button>
<Button type="dashed">Dashed</Button>
<Button type="danger">Danger</Button>
<Button type="link">Link</Button>
</div>,
mountNode
);
Expand Down
3 changes: 2 additions & 1 deletion components/button/demo/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ReactDOM.render(
<Button type="primary" block>Primary</Button>
<Button block>Default</Button>
<Button type="dashed" block>Dashed</Button>
<Button type="danger" block>danger</Button>
<Button type="danger" block>Danger</Button>
<Button type="link" block>Link</Button>
</div>,
mountNode
);
Expand Down
3 changes: 3 additions & 0 deletions components/button/demo/disabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ ReactDOM.render(
<br />
<Button type="dashed">Dashed</Button>
<Button type="dashed" disabled>Dashed(disabled)</Button>
<br />
<Button type="link">Link</Button>
<Button type="link" disabled>Link(disabled)</Button>
<div style={{ padding: '8px 8px 0 8px', background: 'rgb(190, 200, 200)' }}>
<Button ghost>Ghost</Button>
<Button ghost disabled>Ghost(disabled)</Button>
Expand Down
1 change: 1 addition & 0 deletions components/button/demo/ghost.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ReactDOM.render(
<Button ghost>Default</Button>
<Button type="dashed" ghost>Dashed</Button>
<Button type="danger" ghost>danger</Button>
<Button type="link" ghost>link</Button>
</div>,
mountNode
);
Expand Down
1 change: 1 addition & 0 deletions components/button/demo/size.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ButtonSize extends React.Component {
<Button size={size}>Normal</Button>
<Button type="dashed" size={size}>Dashed</Button>
<Button type="danger" size={size}>Danger</Button>
<Button type="link" size={size}>Link</Button>
<br />
<Button type="primary" shape="circle" icon="download" size={size} />
<Button type="primary" shape="round" icon="download" size={size}>Download</Button>
Expand Down
2 changes: 1 addition & 1 deletion components/button/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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`(added in 2.7) or omitted (meaning `default`) | string | `default` |
| type | can be set to `primary` `ghost` `dashed` `danger` `link`(added in 3.17) 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` |

Expand Down
4 changes: 2 additions & 2 deletions components/button/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ subtitle: 按钮
按钮的属性说明如下:

| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| --- | --- | --- | --- | --- |
| disabled | 按钮失效状态 | boolean | `false` |
| ghost | 幽灵属性,使按钮背景透明,版本 2.7 中增加 | boolean | false |
| href | 点击跳转的地址,指定此属性 button 的行为和 a 链接一致 | string | - |
Expand All @@ -28,7 +28,7 @@ subtitle: 按钮
| shape | 设置按钮形状,可选值为 `circle``round` 或者不设 | string | - |
| size | 设置按钮大小,可选值为 `small` `large` 或者不设 | string | `default` |
| target | 相当于 a 链接的 target 属性,href 存在时生效 | string | - |
| type | 设置按钮类型,可选值为 `primary` `dashed` `danger`(版本 2.7 中增加) 或者不设 | string | - |
| type | 设置按钮类型,可选值为 `primary` `dashed` `danger` `link`(3.17 中增加) 或者不设 | string | - |
| onClick | 点击按钮时的回调 | (event) => void | - |
| block | 将按钮宽度调整为其父宽度的选项 | boolean | `false` |

Expand Down
10 changes: 10 additions & 0 deletions components/button/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
.btn-danger;
}

&-link {
.btn-link;
}

&-round {
.btn-round(@btn-prefix-cls);
}
Expand Down Expand Up @@ -165,6 +169,12 @@
.button-variant-ghost(@btn-danger-color);
}

&-background-ghost&-link {
.button-variant-ghost(@link-color; transparent);

color: @component-background;
}

&-two-chinese-chars::first-letter {
letter-spacing: 0.34em;
}
Expand Down
37 changes: 27 additions & 10 deletions components/button/style/mixin.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
border-radius: @border-radius;
}

.button-disabled() {
.button-disabled(@color: @btn-disable-color; @background: @btn-disable-bg; @border: @btn-disable-border) {
&-disabled,
&.disabled,
&[disabled] {
Expand All @@ -16,7 +16,7 @@
&:focus,
&:active,
&.active {
.button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
.button-color(@color; @background; @border);

text-shadow: none;
box-shadow: none;
Expand Down Expand Up @@ -86,17 +86,26 @@
}
.button-disabled();
}
.button-variant-ghost(@color) {
.button-color(@color; transparent; @color);

.button-variant-ghost(@color; @border: @color) {
.button-color(@color; transparent; @border);
text-shadow: none;
&:hover,
&:focus {
.button-color(~`colorPalette('@{color}', 5) `; transparent; ~`colorPalette('@{color}', 5) `);
& when (@border = transparent) {
.button-color(~`colorPalette('@{color}', 5) `; transparent; transparent);
}
& when not(@border = transparent) {
.button-color(~`colorPalette('@{color}', 5) `; transparent; ~`colorPalette('@{color}', 5) `);
}
}
&:active,
&.active {
.button-color(~`colorPalette('@{color}', 7) `; transparent; ~`colorPalette('@{color}', 7) `);
& when (@border = transparent) {
.button-color(~`colorPalette('@{color}', 7) `; transparent; transparent);
}
& when not(@border = transparent) {
.button-color(~`colorPalette('@{color}', 7) `; transparent; ~`colorPalette('@{color}', 7) `);
}
}
.button-disabled();
}
Expand Down Expand Up @@ -139,13 +148,11 @@
&-lg > .@{btnClassName},
&-lg > span > .@{btnClassName} {
.button-size(@btn-height-lg; @btn-padding-lg; @btn-font-size-lg; 0);

line-height: @btn-height-lg - 2px;
}
&-sm > .@{btnClassName},
&-sm > span > .@{btnClassName} {
.button-size(@btn-height-sm; @btn-padding-sm; @font-size-base; 0);

line-height: @btn-height-sm - 2px;
> .@{iconfont-css-prefix} {
font-size: @font-size-base;
Expand Down Expand Up @@ -219,13 +226,23 @@
// dashed button style
.btn-dashed() {
.button-variant-other(@btn-default-color, @btn-default-bg, @btn-default-border);

border-style: dashed;
}
// danger button style
.btn-danger() {
.button-variant-danger(@btn-danger-color, @btn-danger-bg, @btn-danger-border);
}
// link button style
.btn-link() {
.button-variant-other(@link-color, transparent, transparent);
box-shadow: none;
&:hover,
&:focus,
&:active {
border-color: transparent;
}
.button-disabled(@disabled-color; transparent; transparent);
}
// round button
.btn-round(@btnClassName: btn) {
.button-size(@btn-circle-size; 0 @btn-circle-size / 2; @font-size-base + 2px; @btn-circle-size);
Expand Down

0 comments on commit 4f4ae81

Please sign in to comment.