1
- import { defineComponent , h } from 'vue'
1
+ import { defineComponent , h , inject } from 'vue'
2
2
3
3
import { CProgressBar } from './CProgressBar'
4
+ import { Color } from '../../props'
4
5
5
6
const CProgress = defineComponent ( {
6
7
name : 'CProgress' ,
7
8
props : {
9
+ /**
10
+ * Use to animate the stripes right to left via CSS3 animations.
11
+ */
12
+ animated : Boolean ,
13
+ /**
14
+ * Sets the color context of the component to one of CoreUI’s themed colors.
15
+ *
16
+ * @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light'
17
+ */
18
+ color : Color ,
8
19
/**
9
20
* Sets the height of the component. If you set that value the inner `<CProgressBar>` will automatically resize accordingly.
10
21
*/
11
22
height : Number ,
23
+ /**
24
+ * A string of all className you want applied to the <CProgressBar/> component.
25
+ *
26
+ * @since 5.0.0-alpha.1
27
+ */
28
+ progressBarClassName : String ,
12
29
/**
13
30
* Makes progress bar thinner.
14
31
*/
15
32
thin : Boolean ,
33
+ /**
34
+ * The percent to progress the ProgressBar.
35
+ */
36
+ value : {
37
+ type : Number ,
38
+ default : 0 ,
39
+ } ,
40
+ /**
41
+ * Set the progress bar variant to optional striped.
42
+ *
43
+ * @values 'striped'
44
+ */
45
+ variant : {
46
+ type : String ,
47
+ validator : ( value : string ) => {
48
+ return value === 'striped'
49
+ } ,
50
+ } ,
16
51
/**
17
52
* Change the default color to white.
18
53
*/
19
54
white : Boolean ,
20
- ...CProgressBar . props ,
21
55
} ,
22
56
setup ( props , { slots } ) {
57
+ const stacked = inject ( 'stacked' , false ) as boolean
58
+
23
59
return ( ) =>
24
60
h (
25
61
'div' ,
@@ -31,20 +67,42 @@ const CProgress = defineComponent({
31
67
'progress-white' : props . white ,
32
68
} ,
33
69
] ,
34
- ...( props . height , { style : `height: ${ props . height } px` } ) ,
70
+ style : {
71
+ ...( props . height ? { height : `${ props . height } px` } : { } ) ,
72
+ ...( stacked ? { width : `${ props . value } %` } : { } ) ,
73
+ } ,
74
+ ...( props . value !== undefined && {
75
+ role : 'progressbar' ,
76
+ 'aria-valuenow' : props . value ,
77
+ 'aria-valuemin' : 0 ,
78
+ 'aria-valuemax' : 100 ,
79
+ } ) ,
35
80
} ,
36
- props . value
37
- ? h (
81
+ // @ts -expect-error name is defined in component
82
+ slots . default && slots . default ( ) . some ( ( vnode ) => vnode . type . name === 'CProgressBar' )
83
+ ? slots . default ( ) . map ( ( vnode ) => {
84
+ // @ts -expect-error name is defined in component
85
+ if ( vnode . type . name === 'CProgressBar' ) {
86
+ return h ( vnode , {
87
+ ...( props . animated && { animated : props . animated } ) ,
88
+ ...( props . color && { color : props . color } ) ,
89
+ ...( props . value && { value : props . value } ) ,
90
+ ...( props . variant && { variant : props . variant } ) ,
91
+ } )
92
+ }
93
+ return vnode
94
+ } )
95
+ : h (
38
96
CProgressBar ,
39
97
{
40
- value : props . value ,
98
+ ... ( props . progressBarClassName && { class : props . progressBarClassName } ) ,
41
99
animated : props . animated ,
42
100
color : props . color ,
101
+ value : props . value ,
43
102
variant : props . variant ,
44
103
} ,
45
- slots . default && slots . default ( ) ,
46
- )
47
- : slots . default && slots . default ( ) ,
104
+ ( ) => slots . default && slots . default ( ) ,
105
+ ) ,
48
106
)
49
107
} ,
50
108
} )
0 commit comments