Skip to content

Commit 745b298

Browse files
authored
feat: add col flex (#2562)
* feat: add col `flex` * feat: add types
1 parent 3954187 commit 745b298

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

components/grid/Col.jsx

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const ColProps = {
2727
xl: objectOrNumber,
2828
xxl: objectOrNumber,
2929
prefixCls: PropTypes.string,
30+
flex: stringOrNumber,
3031
};
3132

3233
export default {
@@ -38,13 +39,25 @@ export default {
3839
default: () => null,
3940
},
4041
},
42+
methods: {
43+
parseFlex(flex) {
44+
if (typeof flex === 'number') {
45+
return `${flex} ${flex} auto`;
46+
}
47+
if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
48+
return `0 0 ${flex}`;
49+
}
50+
return flex;
51+
},
52+
},
4153
render() {
4254
const {
4355
span,
4456
order,
4557
offset,
4658
push,
4759
pull,
60+
flex,
4861
prefixCls: customizePrefixCls,
4962
$slots,
5063
rowContext,
@@ -105,6 +118,11 @@ export default {
105118
};
106119
}
107120
}
121+
122+
if (flex) {
123+
divProps.style.flex = this.parseFlex(flex);
124+
}
125+
108126
return <div {...divProps}>{$slots.default}</div>;
109127
},
110128
};

types/grid/col.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export declare class Col extends AntdComponent {
1919
*/
2020
order: ColSpanType;
2121

22+
/**
23+
* the layout fill of flex
24+
* @default none
25+
* @type ColSpanType
26+
*/
27+
flex: ColSpanType;
28+
2229
/**
2330
* the number of cells to offset Col from the left
2431
* @default 0

0 commit comments

Comments
 (0)