8
8
* @see Source https://github.com/chakra-ui/chakra-ui-vue/blob/master/packages/chakra-ui-core/src/CSelect/CSelect.js
9
9
*/
10
10
11
- import { baseProps } from '../config'
12
- import styleProps from '../config/props'
13
11
import { inputProps } from '../CInput/utils/input.props'
14
12
15
13
import CBox from '../CBox'
16
14
import CIcon from '../CIcon'
17
15
import CInput from '../CInput'
16
+ import { createStyledAttrsMixin , extractListeners , forwardProps } from '../utils'
18
17
import splitProps from './utils/select.utils'
19
18
20
19
/**
@@ -27,11 +26,12 @@ import splitProps from './utils/select.utils'
27
26
*/
28
27
const CSelectIconWrapper = {
29
28
name : 'SelectIconWrapper' ,
30
- props : baseProps ,
31
- render ( h ) {
29
+ functional : true ,
30
+ render ( h , { data , slots , ... rest } ) {
32
31
return h ( CBox , {
33
- props : {
34
- ...this . $props ,
32
+ ...rest ,
33
+ attrs : {
34
+ ...data . attrs ,
35
35
position : 'absolute' ,
36
36
display : 'inline-flex' ,
37
37
width : '1.5rem' ,
@@ -42,12 +42,10 @@ const CSelectIconWrapper = {
42
42
top : '50%' ,
43
43
pointerEvents : 'none' ,
44
44
zIndex : 2 ,
45
- transform : 'translateY(-50%)'
46
- } ,
47
- attrs : {
45
+ transform : 'translateY(-50%)' ,
48
46
'data-chakra-component' : 'CSelectIconWrapper'
49
47
}
50
- } , this . $ slots. default )
48
+ } , slots ( ) . default )
51
49
}
52
50
}
53
51
@@ -61,35 +59,51 @@ const CSelectIconWrapper = {
61
59
*/
62
60
const CSelectInput = {
63
61
name : 'CSelectInput' ,
62
+ functional : true ,
64
63
props : {
65
- ...styleProps ,
66
64
...inputProps ,
67
65
placeholder : String ,
68
66
value : String
69
67
} ,
70
- render ( h ) {
68
+ render ( h , { props, data, slots, listeners, ...rest } ) {
69
+ const nonNativeEvents = {
70
+ change : ( e ) => {
71
+ const emitChange = listeners . change
72
+ if ( emitChange ) {
73
+ emitChange ( e )
74
+ }
75
+ }
76
+ }
77
+
78
+ const { native, nonNative } = extractListeners ( { listeners } , nonNativeEvents )
79
+ console . log ( forwardProps ( props ) )
71
80
return h ( CInput , {
81
+ ...rest ,
72
82
props : {
73
- ...this . $props ,
83
+ ...forwardProps ( props ) ,
84
+ as : 'select'
85
+ } ,
86
+ on : nonNative ,
87
+ nativeOn : native ,
88
+ domProps : {
89
+ value : props . value
90
+ } ,
91
+ attrs : {
74
92
as : 'select' ,
75
93
appearance : 'none' ,
76
94
pr : '2rem' ,
77
95
pb : 'px' ,
78
- lineHeight : 'normal'
79
- } ,
80
- on : {
81
- change : e => this . $emit ( 'change' , e )
82
- } ,
83
- domProps : {
84
- value : this . value
96
+ lineHeight : 'normal' ,
97
+ ...data . attrs ,
98
+ 'data-chakra-component' : 'CSelectInput'
85
99
}
86
100
} , [
87
- this . placeholder && h ( 'option' , {
101
+ props . placeholder && h ( 'option' , {
88
102
attrs : {
89
103
value : ''
90
104
}
91
- } , this . placeholder ) ,
92
- this . $ slots. default
105
+ } , props . placeholder ) ,
106
+ slots ( ) . default
93
107
] )
94
108
}
95
109
}
@@ -103,14 +117,12 @@ const CSelectInput = {
103
117
* @see Docs https://vue.chakra-ui.com/select
104
118
*/
105
119
const CSelect = {
106
- name : 'CSelect' ,
107
- inject : [ '$chakraColorMode' ] ,
120
+ mixins : [ createStyledAttrsMixin ( 'CSelect' , true ) ] ,
108
121
model : {
109
122
prop : 'value' ,
110
123
event : 'change'
111
124
} ,
112
125
props : {
113
- ...styleProps ,
114
126
...inputProps ,
115
127
rootProps : {
116
128
type : Object ,
@@ -134,9 +146,6 @@ const CSelect = {
134
146
}
135
147
} ,
136
148
computed : {
137
- colorMode ( ) {
138
- return this . $chakraColorMode ( )
139
- } ,
140
149
_color ( ) {
141
150
return this . colorMode === 'dark' ? 'whiteAlpha.800' : 'inherit'
142
151
} ,
@@ -145,45 +154,56 @@ const CSelect = {
145
154
} ,
146
155
_value ( ) {
147
156
return this . value
148
- }
149
- } ,
150
- render ( h ) {
151
- const { rootProps , icon , iconSize , ... props } = this . $props
152
- const [ root , select ] = splitProps ( props )
153
- return h ( CBox , {
154
- props : {
157
+ } ,
158
+ allSplitProps ( ) {
159
+ return splitProps ( this . $data . attrs$ )
160
+ } ,
161
+ componentStyles ( ) {
162
+ const [ root ] = this . allSplitProps
163
+ return {
155
164
...root ,
156
- ...rootProps ,
165
+ ...this . rootProps ,
157
166
position : 'relative' ,
158
167
width : '100%'
159
- } ,
168
+ }
169
+ }
170
+ } ,
171
+ render ( h ) {
172
+ const { icon, iconSize } = this . $props
173
+ const [ , select ] = this . allSplitProps
174
+ return h ( 'div' , {
175
+ class : [ this . className ] ,
160
176
attrs : {
177
+ ...this . computedAttrs ,
161
178
'data-chakra-component' : 'CSelect'
162
179
}
163
180
} , [
164
181
h ( CSelectInput , {
165
182
props : {
166
- color : this . _color ,
167
183
placeholder : this . placeholder ,
168
- ...select
169
- } ,
170
- on : {
171
- change : e => this . $emit ( 'change' , e . target . value )
184
+ ...forwardProps ( this . $props )
172
185
} ,
173
- domProps : {
186
+ attrs : {
187
+ color : this . _color ,
188
+ ...select ,
174
189
value : this . _value
190
+ } ,
191
+ on : {
192
+ change : ( e ) => {
193
+ this . $emit ( 'change' , e . target . value )
194
+ }
175
195
}
176
196
} , this . $slots . default ) ,
177
197
h ( CSelectIconWrapper , {
178
- props : {
198
+ attrs : {
179
199
opacity : this . _opacity ,
180
200
color : select . color || this . _color
181
201
}
182
202
} , [
183
203
h ( CIcon , {
184
204
props : {
185
- name : this . icon || 'chevron-down' ,
186
- size : this . iconSize
205
+ name : icon || 'chevron-down' ,
206
+ size : iconSize
187
207
} ,
188
208
attrs : {
189
209
focusable : false ,
0 commit comments