feat: add col `flex` (#2562)

* feat: add col `flex`

* feat: add types
pull/2580/head
xrk 2020-07-17 13:31:53 +08:00 committed by GitHub
parent 39541875ff
commit 745b2983ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -27,6 +27,7 @@ export const ColProps = {
xl: objectOrNumber, xl: objectOrNumber,
xxl: objectOrNumber, xxl: objectOrNumber,
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
flex: stringOrNumber,
}; };
export default { export default {
@ -38,6 +39,17 @@ export default {
default: () => null, default: () => null,
}, },
}, },
methods: {
parseFlex(flex) {
if (typeof flex === 'number') {
return `${flex} ${flex} auto`;
}
if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
return `0 0 ${flex}`;
}
return flex;
},
},
render() { render() {
const { const {
span, span,
@ -45,6 +57,7 @@ export default {
offset, offset,
push, push,
pull, pull,
flex,
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
$slots, $slots,
rowContext, rowContext,
@ -105,6 +118,11 @@ export default {
}; };
} }
} }
if (flex) {
divProps.style.flex = this.parseFlex(flex);
}
return <div {...divProps}>{$slots.default}</div>; return <div {...divProps}>{$slots.default}</div>;
}, },
}; };

7
types/grid/col.d.ts vendored
View File

@ -19,6 +19,13 @@ export declare class Col extends AntdComponent {
*/ */
order: ColSpanType; order: ColSpanType;
/**
* the layout fill of flex
* @default none
* @type ColSpanType
*/
flex: ColSpanType;
/** /**
* the number of cells to offset Col from the left * the number of cells to offset Col from the left
* @default 0 * @default 0