简体   繁体   中英

Change style(color) Linear Progress Bar/ Material UI / Reactjs

 <LinearProgress style={{barColorPrimary: "red"}}" value={Number(campanha.Percentual)} />

How can I change the barColorPrimary of the bar? I need to use style like in code.

I like to use the withStyles() higher-order component to inject custom styles.

Take a look at the example for the LinearProgress here: https://codesandbox.io/s/material-demo-forked-kwvb1?file=/demo.tsx (we override barColorPrimary for the bar color and colorPrimary for the background).

More info about customizing components in Material UI can be found here: https://material-ui.com/customization/components/

I solved like this..

 const CustomLinearProgress = styled(LinearProgress)(({ datatype }) => ({ height: 6, borderRadius: 5, [`&.${linearProgressClasses.colorPrimary}`]: { backgroundColor: 'light gray', }, [`&.${linearProgressClasses.bar}`]: { borderRadius: 5, backgroundColor: datatype === 'finished'? 'green': 'blue', }, })); return ( <CustomLinearProgress datatype="finished" variant="determinate" value={50} /> );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM