Skip to content

Commit f2af8d2

Browse files
zkwolftangjinzhou
andauthored
feat: update grid (#2377)
* feat: update grid * fix: row can't provide rowContext to col Co-authored-by: tangjinzhou <[email protected]>
1 parent 585bb74 commit f2af8d2

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

components/col/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { Col } from '../grid';
2-
import Base from '../base';
32
/* istanbul ignore next */
4-
Col.install = function(Vue) {
5-
Vue.use(Base);
6-
Vue.component(Col.name, Col);
3+
Col.install = function(app) {
4+
app.component(Col.name, Col);
75
};
86

97
export default Col;

components/grid/Col.jsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { inject } from 'vue';
12
import PropTypes from '../_util/vue-types';
23
import { ConfigConsumerProps } from '../config-provider';
3-
import { getListeners } from '../_util/props-util';
44

55
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
66

@@ -32,11 +32,11 @@ export const ColProps = {
3232
export default {
3333
name: 'ACol',
3434
props: ColProps,
35-
inject: {
36-
configProvider: { default: () => ConfigConsumerProps },
37-
rowContext: {
38-
default: () => null,
39-
},
35+
setup() {
36+
return {
37+
configProvider: inject('configProvider', ConfigConsumerProps),
38+
rowContext: inject('rowContext', null),
39+
};
4040
},
4141
render() {
4242
const {
@@ -82,7 +82,6 @@ export default {
8282
...sizeClassObj,
8383
};
8484
const divProps = {
85-
on: getListeners(this),
8685
class: classes,
8786
style: {},
8887
};
@@ -105,6 +104,6 @@ export default {
105104
};
106105
}
107106
}
108-
return <div {...divProps}>{$slots.default}</div>;
107+
return <div {...divProps}>{$slots.default && $slots.default()}</div>;
109108
},
110109
};

components/grid/Row.jsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inject, provide, reactive } from 'vue';
12
import PropTypes from '../_util/vue-types';
23
import BaseMixin from '../_util/BaseMixin';
34
import { ConfigConsumerProps } from '../config-provider';
@@ -20,20 +21,24 @@ export default {
2021
...RowProps,
2122
gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]).def(0),
2223
},
23-
provide() {
24+
setup() {
25+
const rowContext = reactive({
26+
getGutter: undefined,
27+
});
28+
provide('rowContext', rowContext);
2429
return {
25-
rowContext: this,
30+
configProvider: inject('configProvider', ConfigConsumerProps),
31+
rowContext,
2632
};
2733
},
28-
inject: {
29-
configProvider: { default: () => ConfigConsumerProps },
30-
},
3134
data() {
3235
return {
3336
screens: {},
3437
};
3538
},
36-
39+
created() {
40+
this.rowContext.getGutter = this.getGutter;
41+
},
3742
mounted() {
3843
this.$nextTick(() => {
3944
this.token = ResponsiveObserve.subscribe(screens => {
@@ -101,7 +106,7 @@ export default {
101106
};
102107
return (
103108
<div class={classes} style={rowStyle}>
104-
{$slots.default}
109+
{$slots.default && $slots.default()}
105110
</div>
106111
);
107112
},

components/row/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Row } from '../grid';
2-
import Base from '../base';
32

43
/* istanbul ignore next */
5-
Row.install = function(Vue) {
6-
Vue.use(Base);
7-
Vue.component(Row.name, Row);
4+
Row.install = function(app) {
5+
app.component(Row.name, Row);
86
};
97

108
export default Row;

examples/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import PageHeader from 'ant-design-vue/page-header';
1717
import Skeleton from 'ant-design-vue/skeleton';
1818
import Empty from 'ant-design-vue/empty';
1919
import Timeline from 'ant-design-vue/timeline';
20+
import Col from 'ant-design-vue/col';
21+
import Row from 'ant-design-vue/row';
2022
import Tooltip from 'ant-design-vue/tooltip';
2123
import 'ant-design-vue/style.js';
2224

@@ -37,5 +39,7 @@ createApp(App)
3739
.use(Spin)
3840
.use(Empty)
3941
.use(Timeline)
42+
.use(Col)
43+
.use(Row)
4044
.use(Tooltip)
4145
.mount('#app');

0 commit comments

Comments
 (0)