introducing fitContainer prop for button

This commit is contained in:
Ilan 2018-07-29 00:54:54 +02:00 committed by 偏右
parent 0156fef165
commit 623cf1eaff
4 changed files with 73 additions and 2 deletions

View File

@ -252,6 +252,43 @@ exports[`renders ./components/button/demo/disabled.md correctly 1`] = `
</div>
`;
exports[`renders ./components/button/demo/fitContainer.md correctly 1`] = `
<div>
<button
class="ant-btn ant-btn-primary ant-btn-fit"
type="button"
>
<span>
Primary
</span>
</button>
<button
class="ant-btn ant-btn-fit"
type="button"
>
<span>
Default
</span>
</button>
<button
class="ant-btn ant-btn-dashed ant-btn-fit"
type="button"
>
<span>
Dashed
</span>
</button>
<button
class="ant-btn ant-btn-danger ant-btn-fit"
type="button"
>
<span>
danger
</span>
</button>
</div>
`;
exports[`renders ./components/button/demo/ghost.md correctly 1`] = `
<div
style="background:rgb(190, 200, 200);padding:26px 16px 16px"
@ -460,7 +497,7 @@ exports[`renders ./components/button/demo/multiple.md correctly 1`] = `
type="button"
>
<span>
Actions
Actions
</span>
<i
class="anticon anticon-down"

View File

@ -47,6 +47,7 @@ export interface BaseButtonProps {
prefixCls?: string;
className?: string;
ghost?: boolean;
fitContainer?: boolean;
}
export type AnchorButtonProps = {
@ -70,6 +71,7 @@ export default class Button extends React.Component<ButtonProps, any> {
prefixCls: 'ant-btn',
loading: false,
ghost: false,
fitContainer: false,
};
static propTypes = {
@ -163,7 +165,7 @@ export default class Button extends React.Component<ButtonProps, any> {
render() {
const {
type, shape, size, className, children, icon, prefixCls, ghost, loading: _loadingProp, ...rest
type, shape, size, className, children, icon, prefixCls, ghost, loading: _loadingProp, fitContainer, ...rest
} = this.props;
const { loading, clicked, hasTwoCNChar } = this.state;
@ -190,6 +192,7 @@ export default class Button extends React.Component<ButtonProps, any> {
[`${prefixCls}-clicked`]: clicked,
[`${prefixCls}-background-ghost`]: ghost,
[`${prefixCls}-two-chinese-chars`]: hasTwoCNChar,
[`${prefixCls}-fit`]: fitContainer,
});
const iconType = loading ? 'loading' : icon;

View File

@ -0,0 +1,27 @@
---
order: 8
title:
zh-CN: fitContainer 按钮
en-US: fitContainer Button
---
## zh-CN
`fitContainer`属性将使按钮适合其父宽度。
## en-US
`fitContainer` property will make the button fit to its parent width.
````jsx
import { Button } from 'antd';
ReactDOM.render(
<div>
<Button type="primary" fitContainer>Primary</Button>
<Button fitContainer>Default</Button>
<Button type="dashed" fitContainer>Dashed</Button>
<Button type="danger" fitContainer>danger</Button>
</div>,
mountNode);
````

View File

@ -171,6 +171,10 @@
letter-spacing: .34em;
margin-right: -.34em;
}
&-fit {
width: 100%;
}
}
@keyframes buttonEffect {