1
1
import PropTypes from '../_util/vue-types' ;
2
- import { getOptionProps , getSlots , getComponentFromProp } from '../_util/props-util' ;
2
+ import { getOptionProps } from '../_util/props-util' ;
3
3
4
4
const ColProps = {
5
5
child : PropTypes . any ,
@@ -9,70 +9,74 @@ const ColProps = {
9
9
layout : PropTypes . oneOf ( [ 'horizontal' , 'vertical' ] ) ,
10
10
} ;
11
11
12
- const Col = {
13
- functional : true ,
14
- props : ColProps ,
15
- render ( h , ctx ) {
16
- const { child, bordered, colon, type, layout } = ctx . props ;
17
- const { prefixCls, span = 1 } = getOptionProps ( child ) ;
18
- const { key } = ctx . data ;
19
- const label = getComponentFromProp ( child , 'label' ) ;
20
- const slots = getSlots ( child ) ;
21
- const labelProps = {
22
- attrs : { } ,
23
- class : [
24
- `${ prefixCls } -item-label` ,
25
- {
26
- [ `${ prefixCls } -item-colon` ] : colon ,
27
- [ `${ prefixCls } -item-no-label` ] : ! label ,
28
- } ,
29
- ] ,
30
- key : `${ key } -label` ,
31
- } ;
32
- if ( layout === 'vertical' ) {
33
- labelProps . attrs . colSpan = span * 2 - 1 ;
34
- }
12
+ const Col = ( _ , { attrs } ) => {
13
+ // props: {
14
+ // child: PropTypes.any,
15
+ // bordered: PropTypes.bool,
16
+ // colon: PropTypes.bool,
17
+ // type: PropTypes.oneOf(['label', 'content']),
18
+ // layout: PropTypes.oneOf(['horizontal', 'vertical']),
19
+ // }
20
+ const { child, bordered, colon, type, layout } = attrs ;
21
+ const { prefixCls, span = 1 } = getOptionProps ( child ) ;
22
+ const { key, children = { } } = child || { } ;
23
+ const label = children . label && children . label ( ) ;
24
+ const defaultSlot = children . default && children . default ( ) ;
35
25
36
- if ( bordered ) {
37
- if ( type === 'label' ) {
38
- return < th { ...labelProps } > { label } </ th > ;
39
- }
40
- return (
41
- < td class = { `${ prefixCls } -item-content` } key = { `${ key } -content` } colSpan = { span * 2 - 1 } >
42
- { slots . default }
43
- </ td >
44
- ) ;
26
+ const someLabelProps = {
27
+ class : [
28
+ `${ prefixCls } -item-label` ,
29
+ {
30
+ [ `${ prefixCls } -item-colon` ] : colon ,
31
+ [ `${ prefixCls } -item-no-label` ] : ! label ,
32
+ } ,
33
+ ] ,
34
+ key : `${ key } -label` ,
35
+ } ;
36
+
37
+ if ( layout === 'vertical' ) {
38
+ someLabelProps . colSpan = span * 2 - 1 ;
39
+ }
40
+
41
+ if ( bordered ) {
42
+ if ( type === 'label' ) {
43
+ return < th { ...someLabelProps } > { label } </ th > ;
45
44
}
46
- if ( layout === 'vertical' ) {
47
- if ( type === 'content' ) {
48
- return (
49
- < td colSpan = { span } class = { `${ prefixCls } -item` } >
50
- < span class = { `${ prefixCls } -item-content` } key = { `${ key } -content` } >
51
- { slots . default }
52
- </ span >
53
- </ td >
54
- ) ;
55
- }
45
+ return (
46
+ < td class = { `${ prefixCls } -item-content` } key = { `${ key } -content` } colSpan = { span * 2 - 1 } >
47
+ { defaultSlot }
48
+ </ td >
49
+ ) ;
50
+ }
51
+ if ( layout === 'vertical' ) {
52
+ if ( type === 'content' ) {
56
53
return (
57
54
< td colSpan = { span } class = { `${ prefixCls } -item` } >
58
- < span
59
- class = { [ `${ prefixCls } -item-label` , { [ `${ prefixCls } -item-colon` ] : colon } ] }
60
- key = { `${ key } -label` }
61
- >
62
- { label }
55
+ < span class = { `${ prefixCls } -item-content` } key = { `${ key } -content` } >
56
+ { defaultSlot }
63
57
</ span >
64
58
</ td >
65
59
) ;
66
60
}
67
61
return (
68
62
< td colSpan = { span } class = { `${ prefixCls } -item` } >
69
- < span { ...labelProps } > { label } </ span >
70
- < span class = { `${ prefixCls } -item-content` } key = { `${ key } -content` } >
71
- { slots . default }
63
+ < span
64
+ class = { [ `${ prefixCls } -item-label` , { [ `${ prefixCls } -item-colon` ] : colon } ] }
65
+ key = { `${ key } -label` }
66
+ >
67
+ { label }
72
68
</ span >
73
69
</ td >
74
70
) ;
75
- } ,
71
+ }
72
+ return (
73
+ < td colSpan = { span } class = { `${ prefixCls } -item` } >
74
+ < span { ...someLabelProps } > { label } </ span >
75
+ < span class = { `${ prefixCls } -item-content` } key = { `${ key } -content` } >
76
+ { defaultSlot }
77
+ </ span >
78
+ </ td >
79
+ ) ;
76
80
} ;
77
81
78
82
export default Col ;
0 commit comments