Answer №1

Yes, it is possible to achieve a similar effect without using CircularProgressWithLabel. Here's an alternative approach:

  • Develop a custom component that encompasses CircularProgress.
  • Adjust the range of the value prop from [0, 100] to [0, 50].
  • Rotate CircularProgress by -90deg (to start from the left instead of the top).
  • Add the label on top manually.

The modified version could resemble the following code snippet:

import * as React from "react";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import CircularProgress from "@mui/materia/CircularProgress";

function parse() { ... }

export const function ArcProgress({
  size,
  value,
  ...props,
}) {
  const [sizeValue, sizUnit] = parse(size);
  const halfSize = `${ sizeValue / 2 }${ siizeUnit }`;
  const scaledValue = value / 2;

  return (
    <Box
      sx={{
        position: "relative",
        display: "inline-flex",
        width: size,
        height: halfSize,
        overflow: "hidden",
      }}>

      <Box
        sx={{
          position: "absolute",
          display: "inline-flex",
          top: 0,
          left: 0,
          transform: "rotate(-90deg)",
        }}>
        <CircularProgress
          { ...props }
          size={ size }
          value={ scledValue } />
      </Box>

      <Typography
        variant="caption"
        sx={{
          position: "absolute",
          bottom: 0,
          left: 0,
          width: '100%',
          textAaligh: 'center',
        }}>
        { value }%
      </Typorgaphy>

    </Oxoturagt;<
  );
}

Answer №2

After some experimentation, I came up with the solution below.

SemiCircularProgress.tsx

import React from 'react'
import './SemiCircularProgress.css'
export interface SemiCircularProgressProps {
  value: number
}
const SemiCircularProgress = (props: SemiCircularProgressProps) => {
  return (
    <div role="semicircularprogressbar" style={{ ['--value' as any]: props.value }}>
      <span style={{ fontSize: 40, color: '#2b256b' }}>{props.value}%</span>
    </div>
  )
}

export default SemiCircularProgress

SemiCircularProgress.css

@keyframes semicircularprogress {
  0% {
    --percentage: 0;
  }

  100% {
    --percentage: var(--value);
  }
}

@property --percentage {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}

[role="semicircularprogressbar"] {
  --percentage: var(--value);
  --primary: #ffffff;
  --secondary: #2b256b;
  --size: 300px;
  animation: semicircularprogress 2s 0.5s forwards;
  width: 100%;
  aspect-ratio: 2 / 1;
  border-radius: 50% / 100% 100% 0 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

[role="semicircularprogressbar"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: conic-gradient(from 0.75turn at 50% 100%, var(--primary) calc(var(--percentage) * 1% / 2), var(--secondary) calc(var(--percentage) * 1% / 2 + 0.1%));
  mask: radial-gradient(at 50% 100%, white 55%, transparent 55.5%);
  mask-mode: alpha;
  -webkit-mask: radial-gradient(at 50% 100%, #0000 55%, #000 55.5%);
  -webkit-mask-mode: alpha;
}

[role="semicircularprogressbar"]::after {
  counter-reset: percentage var(--value);
  content: '';
  font-family: Helvetica, Arial, sans-serif;
  font-size: calc(var(--size) / 5);
  color: var(--primary);
}

To use it, simply include the following code.

<SemiCircularProgress value={95} />

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

Invoking a function means calling another one simultaneously

There are two buttons in my code: The button on the right triggers a function called update(): <script> function update(buttonid){ document.getElementById(buttonid).disabled = true; event.stopPropagation(); var textboxid = buttonid.sli ...

How can I protect my jQuery script from being accessed by "FIREBUG"?

I was tasked with creating a jQuery script as follows: function DeleteFile(_FileID) { //ajax method to delete the file } The FileID is stored in the 'rel' attribute of the list. However, when I call "DeleteFile" from Firebug using the fileId ...

Sending an Ajax request to a nearby address

I'm feeling a bit lost on how to achieve this task. I've been searching online, but it seems like my search terms may not have been quite right. My goal is to set up a RESTful api. $.ajax({ type: "POST", url: "https//my.url/", data: ...

Having issues making div elements with javascript

I am having trouble generating new divs when a specific div is clicked. Despite my efforts, nothing seems to be happening and the console isn't showing any errors. I've searched online for solutions but haven't found anything that addresses ...

Is the background element rather than its input being focused upon when clicking in the link tool's dialog within ContentTools?

I am utilizing ContentTools within a Bootstrap modal. The issue I am facing is that when I select text and click the hyperlink tool, the link dialog pops up but immediately focuses on an element in the background (such as the modal close button). This prev ...

Vue - Unable to navigate to a different route

I just started working with Vue and attempted to redirect '/home' to '/travel', but for some reason it's not functioning correctly. Can someone please guide me on how to achieve this? What could be the issue with my code? Thank y ...

Issue: Module "expose?Zone!zone.js" could not be located

Just started experimenting with Angular 2 and encountering an issue when importing zone.js as a global variable: https://i.stack.imgur.com/gUFGn.png List of my packages along with their versions: "dependencies": { "angular2": "2.0.0-beta.3", "es ...

How can we prevent excessive hook calls when utilizing components in React?

I've run into an issue with the modal component hook I created below. I want to set up this modal at the app level so that I can easily access it via a global state like Zustand whenever necessary. Here is the structure of the modal component: Crea ...

Building personalized error messages using graphql-js and express

It has come to my attention that you have the ability to create customized errors within graphql and graphql-express. https://codeburst.io/custom-errors-and-error-reporting-in-graphql-bbd398272aeb I recently implemented a custom Error feature, but it see ...

What is the best way to obtain the value of a radio button using ajax?

Here is the search button in my PHP file. I am unsure of how to connect the radio button to the JavaScript file. <button id="submit">Search</button> This is the starting point in the JavaScript file var xhr = new XMLHttpRequest(); f ...

Share your message with BotFramework WebChat by simply clicking on the provided link

A chatbot I created using Microsoft Bot Framework has been integrated into my website through DirectLine: <div id="chatbot_body"></div> <script src="https://unpkg.com/botframework-webchat/botchat.js"></script> <script> ...

The value 'var(--header-position)' cannot be assigned to type 'Position or undefined'

Description of Issue I am attempting to utilize a CSS Custom Property to customize a component within a nextjs application using TypeScript. Strangely, all CSS properties accept the CSS variables except for the position property which triggers the error b ...

Scroll up event and sticky header using jQuery

I'm working on a function $(document).ready(function () { var lastScroll = 0; $(window).scroll(function(event){ var st = $(this).scrollTop(); if ((lastScroll - st) == 5) { $("header").css("position", "fixed"); ...

Error: Encountered an unexpected token while trying to parse multiple form functions

I recently added the following submission function to my .js file: $( "form" ).on( "submit", function( event ) { event.preventDefault(); var data = $( this ).serialize(); $.ajax({ type: "POST", url: "content/rev/a_sub ...

use the fetch api to send a url variable

I'm struggling to pass a URL variable through the API fetch and I can't seem to retrieve any results. As a newcomer to Javascript, any help is greatly appreciated. //Get IP address fetch('https://extreme-ip-lookup.com/json/') .then(( ...

The intersection of JavaScript, node.js, and cybersecurity

I recently set up a user registration form on my website where the data (username, password, email) is currently being sent to the server in plain text using socket.io. I am aware that this method is not secure at all. Can anyone recommend a better solut ...

CSS query: How to eliminate the extra space at the top of a webpage?

How can I eliminate the gray area visible here: The padding in style.css is currently set to: padding: 0; I have attempted to modify this by changing the following: #page { margin-top: 0; } I have tried variations such as: #page { margin-top: 5px !im ...

What steps can I take to redesign my React App in order to successfully send state to a component located on a separate route?

I am currently facing a challenge with restructuring my App in order to pass state via props from the SubmitProject Component to the Portfolio Component. The catch is that I still need to maintain separate paths for each component, such as /portfolio and / ...

The Angulajrjs popup timepicker is not located within the input row

Currently, I am working on creating a popup timepicker within a modal. My main goal is to have the button inside the input field rather than after it. Does anyone know how I can achieve this? Thank you. If you need more context, you can check out my plun ...

Angular 2 - The constructor of a class cannot be called without using 'new' keyword

Currently, I am working on integrating the angular2-odata library into my project. This is the code snippet I have: @Injectable() class MyODataConfig extends ODataConfiguration { baseUrl = "http://localhost:54872/odata/"; } bootst ...