1- import { defineComponent , h } from 'vue'
1+ import { defineComponent , h , inject } from 'vue'
22
33import { CProgressBar } from './CProgressBar'
4+ import { Color } from '../../props'
45
56const CProgress = defineComponent ( {
67 name : 'CProgress' ,
78 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 ,
819 /**
920 * Sets the height of the component. If you set that value the inner `<CProgressBar>` will automatically resize accordingly.
1021 */
1122 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 ,
1229 /**
1330 * Makes progress bar thinner.
1431 */
1532 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+ } ,
1651 /**
1752 * Change the default color to white.
1853 */
1954 white : Boolean ,
20- ...CProgressBar . props ,
2155 } ,
2256 setup ( props , { slots } ) {
57+ const stacked = inject ( 'stacked' , false ) as boolean
58+
2359 return ( ) =>
2460 h (
2561 'div' ,
@@ -31,20 +67,42 @@ const CProgress = defineComponent({
3167 'progress-white' : props . white ,
3268 } ,
3369 ] ,
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+ } ) ,
3580 } ,
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 (
3896 CProgressBar ,
3997 {
40- value : props . value ,
98+ ... ( props . progressBarClassName && { class : props . progressBarClassName } ) ,
4199 animated : props . animated ,
42100 color : props . color ,
101+ value : props . value ,
43102 variant : props . variant ,
44103 } ,
45- slots . default && slots . default ( ) ,
46- )
47- : slots . default && slots . default ( ) ,
104+ ( ) => slots . default && slots . default ( ) ,
105+ ) ,
48106 )
49107 } ,
50108} )
0 commit comments