1- import React , { cloneElement } from 'react' ;
1+ import React , { cloneElement , useContext } from 'react' ;
22import PropTypes from 'prop-types' ;
33import classNames from 'classnames' ;
44import { map } from 'react-bootstrap/ElementChildren' ;
55import { omit } from 'ramda' ;
66
77import { bootstrapColors } from '../../private/BootstrapColors' ;
88
9+ export const ProgressContext = React . createContext ( { } ) ;
10+
911/*
1012 * Bulk of this file is vendored from react-bootstrap/src/ProgressBar, but we
1113 * add the ability to style the bar which is needed for setting colors more
@@ -59,15 +61,17 @@ function renderProgressBar(
5961 ) ;
6062}
6163
62- const ProgressBar = React . forwardRef ( ( { isChild, ...props } , ref ) => {
64+ const ProgressBar = React . forwardRef ( ( { isChild, min , max , ...props } , ref ) => {
6365 if ( isChild ) {
64- return renderProgressBar ( props , ref ) ;
66+ const context = useContext ( ProgressContext ) ;
67+ return renderProgressBar (
68+ { ...props , max : max || context . max , min : min || context . min } ,
69+ ref
70+ ) ;
6571 }
6672
6773 const {
68- min,
6974 now,
70- max,
7175 label,
7276 visuallyHidden,
7377 striped,
@@ -79,35 +83,38 @@ const ProgressBar = React.forwardRef(({isChild, ...props}, ref) => {
7983 ...wrapperProps
8084 } = props ;
8185
86+ min = min === undefined ? 0 : min ;
87+ max = max === undefined ? 100 : max ;
88+
8289 return (
8390 < div
8491 ref = { ref }
8592 { ...wrapperProps }
8693 className = { classNames ( className , 'progress' ) }
8794 >
88- { children
89- ? map ( children , child => cloneElement ( child , { isChild : true } ) )
90- : renderProgressBar (
91- {
92- min,
93- now,
94- max,
95- label,
96- visuallyHidden,
97- striped,
98- animated,
99- variant,
100- barStyle
101- } ,
102- ref
103- ) }
95+ < ProgressContext . Provider value = { { min, max} } >
96+ { children
97+ ? map ( children , child => cloneElement ( child , { isChild : true } ) )
98+ : renderProgressBar (
99+ {
100+ min,
101+ now,
102+ max,
103+ label,
104+ visuallyHidden,
105+ striped,
106+ animated,
107+ variant,
108+ barStyle
109+ } ,
110+ ref
111+ ) }
112+ </ ProgressContext . Provider >
104113 </ div >
105114 ) ;
106115} ) ;
107116
108117ProgressBar . defaultProps = {
109- min : 0 ,
110- max : 100 ,
111118 animated : false ,
112119 isChild : false ,
113120 visuallyHidden : false ,
0 commit comments