7
7
* @see Source https://github.com/chakra-ui/chakra-ui-vue/blob/master/packages/chakra-ui-core/src/CTabs/CTabs.js
8
8
*/
9
9
10
- import { baseProps } from '../config'
11
- import { useVariantColorWarning , isDef , useId , forwardProps , cleanChildren , cloneVNodeElement } from '../utils'
12
- import styleProps from '../config/props'
13
-
14
- import CFlex from '../CFlex'
15
- import CBox from '../CBox'
16
- import CPseudoBox from '../CPseudoBox'
10
+ import { useVariantColorWarning , isDef , useId , cleanChildren , cloneVNodeElement , createStyledAttrsMixin } from '../utils'
17
11
import { useTabListStyle , useTabStyle } from './utils/tabs.styles'
18
12
19
13
/**
@@ -25,10 +19,8 @@ import { useTabListStyle, useTabStyle } from './utils/tabs.styles'
25
19
* @see Docs https://vue.chakra-ui.com/tabs
26
20
*/
27
21
const CTabs = {
28
- name : 'CTabs' ,
29
- inject : [ '$chakraTheme' , '$chakraColorMode' ] ,
22
+ mixins : [ createStyledAttrsMixin ( 'CTabs' ) ] ,
30
23
props : {
31
- ...baseProps ,
32
24
index : Number ,
33
25
defaultIndex : Number ,
34
26
isManual : Boolean ,
@@ -87,12 +79,6 @@ const CTabs = {
87
79
set : this . set
88
80
}
89
81
} ,
90
- theme ( ) {
91
- return this . $chakraTheme ( )
92
- } ,
93
- colorMode ( ) {
94
- return this . $chakraColorMode ( )
95
- } ,
96
82
isControlled ( ) {
97
83
return isDef ( this . index )
98
84
} ,
@@ -180,11 +166,10 @@ const CTabs = {
180
166
}
181
167
} ,
182
168
render ( h ) {
183
- return h ( CBox , {
184
- props : forwardProps ( this . $props ) ,
185
- attrs : {
186
- 'data-chakra-component' : 'CTabs'
187
- }
169
+ return h ( this . as , {
170
+ class : [ this . className ] ,
171
+ attrs : this . computedAttrs ,
172
+ on : this . computedListeners
188
173
} , this . $slots . default )
189
174
}
190
175
}
@@ -198,9 +183,8 @@ const CTabs = {
198
183
* @see Docs https://vue.chakra-ui.com/tabs
199
184
*/
200
185
const CTabList = {
201
- name : 'CTabList' ,
202
- props : baseProps ,
203
- inject : [ '$TabContext' , '$chakraTheme' , '$chakraColorMode' ] ,
186
+ mixins : [ createStyledAttrsMixin ( 'CTabList' ) ] ,
187
+ inject : [ '$TabContext' ] ,
204
188
data ( ) {
205
189
return {
206
190
allNodes : { } ,
@@ -212,20 +196,17 @@ const CTabList = {
212
196
context ( ) {
213
197
return this . $TabContext ( )
214
198
} ,
215
- theme ( ) {
216
- return this . $chakraTheme ( )
217
- } ,
218
- colorMode ( ) {
219
- return this . $chakraColorMode ( )
220
- } ,
221
- tabListStyleProps ( ) {
199
+ componentStyles ( ) {
222
200
const { align, variant, orientation } = this . context
223
- return useTabListStyle ( {
224
- theme : this . theme ,
225
- align,
226
- orientation,
227
- variant
228
- } )
201
+ return {
202
+ display : 'flex' ,
203
+ ...useTabListStyle ( {
204
+ theme : this . theme ,
205
+ align,
206
+ orientation,
207
+ variant
208
+ } )
209
+ }
229
210
} ,
230
211
enabledSelectedIndex ( ) {
231
212
const { selectedIndex } = this . context
@@ -329,17 +310,15 @@ const CTabList = {
329
310
. map ( ( child , index ) => ( child . componentOptions . propsData . isDisabled === true ? null : index ) )
330
311
. filter ( index => index != null )
331
312
332
- return h ( CFlex , {
313
+ return h ( this . as , {
314
+ class : [ this . className ] ,
333
315
attrs : {
334
316
role : 'tablist' ,
335
317
'aria-orientation' : orientation ,
336
- 'data-chakra-component' : 'CTabList'
337
- } ,
338
- props : {
339
- ...this . tabListStyleProps ,
340
- ...forwardProps ( )
318
+ ...this . computedAttrs
341
319
} ,
342
- nativeOn : {
320
+ on : {
321
+ ...this . computedListeners ,
343
322
keydown : this . handleKeyDown
344
323
}
345
324
} , clones )
@@ -355,46 +334,40 @@ const CTabList = {
355
334
* @see Docs https://vue.chakra-ui.com/tabs
356
335
*/
357
336
const CTab = {
358
- name : 'CTab' ,
359
- inject : [ '$chakraTheme' , '$chakraColorMode' , '$ TabContext'] ,
337
+ mixins : [ createStyledAttrsMixin ( 'CTab' , true ) ] ,
338
+ inject : [ '$TabContext' ] ,
360
339
props : {
361
- ...styleProps ,
362
340
isSelected : Boolean ,
363
341
isDisabled : Boolean ,
364
- id : String
342
+ id : String ,
343
+ as : {
344
+ type : [ String , Object ] ,
345
+ default : 'button'
346
+ }
365
347
} ,
366
348
computed : {
367
349
context ( ) {
368
350
return this . $TabContext ( )
369
351
} ,
370
- tabStyleProps ( ) {
352
+ componentStyles ( ) {
371
353
const { color, isFitted, orientation, size, variant } = this . context
372
- const styles = useTabStyle ( {
373
- colorMode : this . colorMode ,
374
- theme : this . theme ,
375
- color,
376
- isFitted,
377
- orientation,
378
- size,
379
- variant
380
- } )
381
- return styles
382
- } ,
383
- theme ( ) {
384
- return this . $chakraTheme ( )
385
- } ,
386
- colorMode ( ) {
387
- return this . $chakraColorMode ( )
354
+ return {
355
+ outline : 'none' ,
356
+ ...useTabStyle ( {
357
+ colorMode : this . colorMode ,
358
+ theme : this . theme ,
359
+ color,
360
+ isFitted,
361
+ orientation,
362
+ size,
363
+ variant
364
+ } )
365
+ }
388
366
}
389
367
} ,
390
368
render ( h ) {
391
- return h ( CPseudoBox , {
392
- props : {
393
- outline : 'none' ,
394
- as : 'button' ,
395
- ...this . tabStyleProps ,
396
- ...forwardProps ( this . $props )
397
- } ,
369
+ return h ( this . as , {
370
+ class : [ this . className ] ,
398
371
attrs : {
399
372
role : 'tab' ,
400
373
tabIndex : this . isSelected ? 0 : - 1 ,
@@ -404,8 +377,9 @@ const CTab = {
404
377
'aria-disabled' : this . isDisabled ,
405
378
'aria-selected' : this . isSelected ,
406
379
'aria-controls' : `panel:${ this . id } ` ,
407
- 'data-chakra-component' : 'CTab'
408
- }
380
+ ...this . computedAttrs
381
+ } ,
382
+ on : this . computedListeners
409
383
} , this . $slots . default )
410
384
}
411
385
}
@@ -419,25 +393,25 @@ const CTab = {
419
393
* @see Docs https://vue.chakra-ui.com/tabs
420
394
*/
421
395
const CTabPanel = {
422
- name : 'CTabPanel' ,
396
+ mixins : [ createStyledAttrsMixin ( 'CTabPanel' ) ] ,
423
397
props : {
424
- ...baseProps ,
425
398
isSelected : Boolean ,
426
399
selectedPanelNode : Object ,
427
400
id : String
428
401
} ,
429
402
render ( h ) {
430
- return h ( CBox , {
431
- props : forwardProps ( this . $props ) ,
403
+ return h ( this . as , {
404
+ class : [ this . className ] ,
432
405
attrs : {
433
406
role : 'tabpanel' ,
434
407
tabIndex : - 1 ,
435
408
'aria-labelledby' : `tab:${ this . id } ` ,
436
409
hidden : ! this . isSelected ,
437
410
id : `panel:${ this . id } ` ,
438
411
outline : 0 ,
439
- 'data-chakra-component' : 'CTabPanel'
440
- }
412
+ ...this . computedAttrs
413
+ } ,
414
+ on : this . computedListeners
441
415
} , this . $slots . default )
442
416
}
443
417
}
@@ -451,9 +425,8 @@ const CTabPanel = {
451
425
* @see Docs https://vue.chakra-ui.com/tabs
452
426
*/
453
427
const CTabPanels = {
454
- name : 'CTabPanels' ,
428
+ mixins : [ createStyledAttrsMixin ( 'CTabPanels' ) ] ,
455
429
inject : [ '$TabContext' ] ,
456
- props : baseProps ,
457
430
computed : {
458
431
context ( ) {
459
432
return this . $TabContext ( )
@@ -470,20 +443,22 @@ const CTabPanels = {
470
443
const validChildren = cleanChildren ( this . $slots . default )
471
444
472
445
const clones = validChildren . map ( ( child , index ) => {
446
+ const isSelected = isManual ? index === manualIndex : index === selectedIndex
473
447
return cloneVNodeElement ( child , {
474
448
props : {
475
- isSelected : isManual ? index === manualIndex : index === selectedIndex ,
449
+ isSelected,
476
450
id : `${ id } -${ index } `
477
451
}
478
452
} , h )
479
453
} )
480
454
481
- return h ( CBox , {
482
- props : forwardProps ( this . $props ) ,
455
+ return h ( this . as , {
456
+ class : [ this . className ] ,
483
457
attrs : {
484
458
tabIndex : - 1 ,
485
- 'data-chakra-component' : 'CTabPanels'
486
- }
459
+ ...this . computedAttrs
460
+ } ,
461
+ on : this . computedListeners
487
462
} , clones )
488
463
}
489
464
}
0 commit comments