Chase AdamsChase Adams
AboutContentPromptsPrototypesNewsletter

Styling the MUI Linear Progress Bar

Essays and updates on product, engineering, and AI by Chase Adams.

1 minute read

Post Details

Published
Jan 12, 2023
Category
Engineering
Share
ChatGPT

Latest Posts

A 2x2 Framework for Navigating AI Disruption

A 2x2 Framework for Navigating AI Disruption

Not all change requires the same response. A new framework for diagnosing which kind of disruption you're facing—and choosing the right strategy.

Styling the MUI Linear Progress Bar React component is incredibly confusing when you want to change both the colors of the whole bar and the foreground of the bar, even with the LinearProgressAPI handy.

In order to get this working, I ended up styling the root element with the &.${linearProgressClasses.determinate} and to style the progress indicator color, I styled the bar1Determinate (&.${linearProgressClasses.determinate} > .${linearProgressClasses.bar1Determinate}).

In this example I used styled-components but this would work with any style library that exports a styled function that takes an element or react component.

import LinearProgress, {
  linearProgressClasses
} from "@mui/material/LinearProgress";

import styled from "styled-components";

  

const StyledLinearProgressBar = styled(LinearProgress)({
	[`&.${linearProgressClasses.determinate}`]: { backgroundColor: "#f0f" },
	[`&.${linearProgressClasses.determinate} > .${linearProgressClasses.bar1Determinate}`]: { backgroundColor: "#0ff" }
});

You can see this in action in this CodeSandbox

AboutAI Workflow SpecContentStacksNewsletterPromptsRSS