Enhancing your CircularProgressBar with dual variant colors using Material-UI

https://i.sstatic.net/0d35R.png

Best practices for customizing MUI components with React

Answer №1

If you're looking to achieve a dual-tone circular progress effect, one way to do it is by layering multiple CircularProgress components over each other and positioning them accordingly. Here's an example:

import React from "react";
import ReactDOM from "react-dom";
import { Box, Typography, CircularProgress } from "@material-ui/core";

function App() {
  return (
    <Box
      sx={{
        height: "100vh",
        display: "flex",
        justifyContent: "center",
        alignItems: "center"
      }}
    >
      <Box sx={{ position: "relative" }}>
        <Box
          sx={{
            position: "absolute",
            top: 0,
            bottom: 0,
            margin: "auto",
            zIndex: 0,
            color: "#f3f3f3"
          }}
        >
          <CircularProgress
            variant="determinate"
            color="inherit"
            value={100}
            thickness={3}
            size={100}
          />
        </Box>
        <Box
          sx={{
            position: "absolute",
            top: 0,
            bottom: 0,
            margin: "auto",
            zIndex: 1,
            color: "red"
          }}
        >
          <CircularProgress
            variant="determinate"
            color="inherit"
            value={30}
            thickness={3}
            size={100}
          />
        </Box>
        <Box
          sx={{
            position: "absolute",
            top: 0,
            bottom: 0,
            margin: "auto",
            zIndex: 2
          }}
        >
          <CircularProgress
            variant="determinate"
            value={25}
            thickness={3}
            size={100}
          />
        </Box>
        <Box
          sx={{
            position: "absolute",
            top: 32,
            left: 32,
            zIndex: 2
          }}
        >
          <Typography color="primary" variant="h5">
            25%
          </Typography>
        </Box>
      </Box>
    </Box>
  );
}

ReactDOM.render(<App />, document.querySelector("#app"));

The end result is depicted in this image: circular progress dual tone

To view this code in action, check out the CodeSandbox link: https://codesandbox.io/s/determined-wu-dtwy7y

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What's preventing my code from running the CSS class properly?

I'm puzzled as to why the "grow" class for image pop up is not working even though it's included in the echo script. Here is the PHP code snippet: echo "<a href='$file'><img class='grow' src='$file' alt=&a ...

The callback function fails to execute properly when called from a child component

Is there a way to modify the parent state directly from the child component? I believe my code is correct, but for some reason it's not functioning as expected. const [newValidate, setNewValidate] = useState<Array<boolean>>(new Array(check ...

Equal-height rows and columns using Flexbox

I've been working on a row layout with two columns, each set to 50% width. The left column contains an image, while the right column displays text. Here is my HTML: .row{ display:flex; ...

Clicking again on the second onclick attribute

I have an image file named image1.png. When the button is clicked for the first time, I want it to change to image2.png. Then, when the button is clicked for a second time, I want it to change to yet another image, image3.png. So far, I've successful ...

Revise the cascading style sheets for HTML content loaded via AJAX

I have a situation where I am dynamically loading HTML content using AJAX with JQuery. After the content is loaded, I am triggering a click event on specific elements within the newly added HTML. However, I am encountering an issue when trying to set the ...

Troubleshooting issues with browser scrollbars in a Silverlight application (HTML)

I am currently working on a simple silverlight application and I need to incorporate web browser scroll bars into it (scroll bars should not be inside my silverlight app). This is the HTML code I have: <style type="text/css"> html, body { heigh ...

Is it possible that certain optimistic responses are failing to trigger page re-renders in Apollo and GraphQL with React?

When a deletion occurs, the page updates immediately with the expected result. However, when editing an item, the update does not occur until the mutation is successful. I am collaborating with a friend to develop a workout tracking app using the MERN sta ...

"Successfully rendering the map on the initial load, but encountering an error of 'cannot map undefined'

Having trouble displaying data retrieved from an API. Initially, the movie titles are shown without any issues. However, upon refreshing the page, an error message stating "cannot map undefined" appears. Here is the code snippet: const [media, set ...

Is there no sign of rails being utilized in production?

There are some classic image png files located in app/assets/images/... However, in production, after running rake assets:precompile The images do not appear! Upon inspecting the CSS source code, I noticed that .logo { background-image: url("/ass ...

Dispatch is successful half of the time in children when looping within useEffect

Recently, I embarked on the journey of learning React. However, I encountered a problem when using dispatch in UseEffect, which is nested inside a child component loop. While I cannot share the entire project, here is a snippet of the code: The home page ...

Encountering a Typescript Type error when attempting to include a new custom property 'tab' within the 'Typography' component in a Material UI theme

Currently, I am encountering a Typescript Type error when attempting to add a custom new property called 'tab' inside 'Typography' in my Material UI Theme. The error message states: Property 'tab' does not exist on type &apos ...

Troublesome situation arising from CSS floats overlapping div elements

It's strange how this issue always occurs when using floats. This is what my div (samle) looks like: <div class="main> <div class="inn_div">&nbsp</div> </div> Here is my stylesheet: .main{ width:250px; border:1px ...

Encountered an issue with retrieving the property "tagName" of null during Razorpay payment integration in a Next.js application

I encountered a tagName of null error while integrating Razorpay. The issue seems to be related to the head manager. https://i.sstatic.net/b4zTP.png For those interested, here is the link to the Github repository: https://github.com/rajatgalav/razorpay-d ...

"Revealing the specific row and column of the selected element in each table when hovering over it

On my webpage, I have set up two tables positioned side by side like this: <!DOCTYPE html> <table> <tr> <td> <table> <tr><td>1</td><td>2& ...

Issues with the FlexBox styling of Bootstrap 4 Modals in Internet Explorer causing malfunction

I have designed a confirmation dialog using Bootstrap 4 with the following code snippet: <div class="modal fade show" id="completeAlertDialogue" role="dialog" style="display: block;"> <div class="modal-dialog"> <div class="modal-co ...

Executing API calls in Redux Saga prior to the token being established

Implementing a React application with authentication using Keycloak has been smooth sailing so far, but I've encountered an issue. When I refresh the page and there is an API call fetching data, Saga performs the call before the token is properly set. ...

What is the best way to extract value from an input text that is being repeated using ng-repeat within a Tr

Having a table with repeated rows in angular, you can also dynamically add new rows by clicking a button. If there are already 3 repeated rows and 2 extra rows are added with data entered, how can we retrieve all the data from the table in the controller ...

Tips for repairing a horizontal line at the bottom of the <TD> tag and placing text on top

I am working with an HTML table that contains a single TR tag and two TD tags. Each TD has two HR tags creating horizontal lines, along with some text. I am looking for a way to keep the text aligned at the top of the TD and the horizontal line at the bott ...

"Looking for a way to eliminate the background of an image on NextJS? Learn

https://i.stack.imgur.com/zAsrJ.png When this image is incorporated into a Nextjs rendering, it unexpectedly includes additional content. <div className="flex flex-col items-start justify-start rounded-3xl p-4 bg-boxi w-1/3"> <div cla ...

Tips for React component to recognize modifications in state object and trigger a re-render

In my React component, I have a step called StepA. This step gathers a value on submission and then saves it in the redux store as state.chef_positions.[0].chef_title_id. The issue arises when after submitting StepA, the user is immediately directed to St ...