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,
xxl: objectOrNumber,
prefixCls: PropTypes.string,
flex: stringOrNumber,
};
export default {
@ -38,6 +39,17 @@ export default {
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() {
const {
span,
@ -45,6 +57,7 @@ export default {
offset,
push,
pull,
flex,
prefixCls: customizePrefixCls,
$slots,
rowContext,
@ -105,6 +118,11 @@ export default {
};
}
}
if (flex) {
divProps.style.flex = this.parseFlex(flex);
}
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;
/**
* the layout fill of flex
* @default none
* @type ColSpanType
*/
flex: ColSpanType;
/**
* the number of cells to offset Col from the left
* @default 0