Tips for customizing stepper color using hooks in Material UI

Looking for help to change the color of a stepper from 'primary' to 'success' using React hooks. The stepper component does not have a built-in color method like an icon, so I'm struggling to find a solution. Any advice would be greatly appreciated. Thank you.

Here is my code:

const steps = ['Select master blaster campaign settings','Create an ad group','Create an ad'];
const [color, setColor] = useState('primary')

const successBoxClicked = (e) => {
setColor('success')}

<Stepper activeStep={1} alternativeLabel>
    {steps.map((label) => (
      <Step key={label}>
        <StepLabel>{label}</StepLabel>
      </Step>
    ))}
  </Stepper>

Answer №1

The Stepper component can be quite intricate to customize. I recently had to modify one and followed a helpful guide provided by the creators. You can check out their customization guide for this component here.

When it comes to changing colors, it really depends on the specific color you're targeting. One efficient method could involve customizing the theme.

For example, if you need to change the colors of all step icons, you might utilize the StepIconProps prop. More information on this can be found here.

If you want to extract a color from the theme itself, direct access to the theme will be necessary. Here's a snippet illustrating how this can be done:

const steps = ['Select master blaster campaign settings','Create an ad group','Create an ad',];

const theme = useTheme() // Import from Material UI
const [color, setColor] = useState(theme.palette.primary.main)

const successBoxClicked = (e) => {
  setColor(theme.palette.success.main)
}

<Stepper activeStep={1} alternativeLabel>
    {steps.map((label) => (
      <Step key={label}>
        <StepLabel StepIconProps={{style: {color}}}>{label}</StepLabel>
      </Step>
    ))}
  </Stepper>

There are various approaches to achieve this customization. It may not always require using style, but that was the quickest solution for me in this case. Best of luck with your customization!

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

Exploring the use of the "++" operator in Regular

Is there a way to detect the presence of ++, --, // or ** signs in a string? Any help would be greatly appreciated. var str = document.getElementById('screen').innerHTML; var res = str.substring(0, str.length); var patt1 = ++,--,//,**; var resul ...

Load the content of the dialog and transfer variables

After struggling for days, I am still unable to find a solution to my current dilemma. In my database, there are approximately 1300 items each with its own unique "id", a corresponding "name", and a property called "enabled". My goal is to display links t ...

Guide on implementing OrbitControls to a camera imported from a glTF file

I am facing an issue with OrbitControls.js when trying to apply it to a loaded camera in a three.js scene. While the camera and model load successfully, the OrbitControls.js seem to work only with cameras created directly in the three.js using new THREE.Pe ...

Getting js.map Files to Function Properly with UMD Modules

I am experiencing an issue with debugging TypeScript files in Chrome and Firefox. Specifically, when trying to debug the MapModuleTest.ts file, the debugger seems to be out of sync with the actual JavaScript code by two lines. This discrepancy makes settin ...

Clicking on the image in an owl carousel slider does not trigger the onsen template page to load

I am experiencing an issue with my owl carousel slider while calling an API for page content on image click. I have implemented an onsen template page using ng-click on image, but it only works for the first image click. Subsequent images do not call the o ...

Navigating Cross-Origin Resource Sharing (CORS) Challenges within

Currently in the process of developing an API utilizing our API server script and attempting to establish communication with the API on the IONIC framework application. Progress is being made, however, encountering a recurring issue with the cross-origin b ...

Using the map function with a React onClick handler

After tirelessly scouring the internet for answers to my query, I've hit a dead end. My goal is to implement a basic react click handler on my button, but for some reason, it just won't cooperate. It's likely something incredibly straightfor ...

typescript: the modules with relational paths could not be located

As part of a migration process, I am currently converting code from JavaScript to TypeScript. In one of my files 'abc.ts', I need to import the 'xyz.css' file, which is located in the same directory. However, when I try to import it usi ...

Using Javascript's regular expressions to add double quotes around JSON values that are not already enclosed in quotes

Dealing with improperly formatted JSON values can be a challenge. The response I am working with is from a Java Servlet, specifically a hashmap, over which I have no control. Initially, it looked like this: { response={ type=000, products=[{id=1,name=prod ...

Please ask Java to receive a JSON parameter for converting a JSON array into a Java array

Essentially, my goal is to pass a Java String array to a JavaScript array, then pass this array via JSON to a JSP page, where I can parse it as a Java array. I attempted the following: JSONArray arr = new JSONArray(); JSONObject tmp; for(int i = 0; ...

Calculate the combined sum of values within dynamic inputs that share a common class, and automatically update the sum whenever input values are altered or new rows are added or removed dynamically

$("#add-btn").click(function() { $("#dynamic").append('<tr>' + '<td class="td">' + '<input type="number" name="Debit" class="form-control Debit"/>' + '</td>' + '<td c ...

Transitioning images in JQuery by using a rollover effect

Is there a way to use Jquery for a hover effect that transitions images with a slide up animation? I've looked everywhere online, but I can't seem to find a code that works. All the examples I've found use fadeIn or fadeOut. Thank you for yo ...

Exploring the topics of Subjects in RxJs and EventEmitters in Angular2

Can you explain the distinction between these concepts, along with guidance on when and how to utilize them? I've come across the idea that Subject is akin to an EventEmitter. If I aim to rephrase this information, what approach should I take? impor ...

What is the process for building a reusable component from a static component in Vue 3?

I am delving into Vue 3 and Headless UI, and I have successfully created a ListBox component in App.vue to display a list of People which is functioning as expected. Now, I am aiming to transform it into a reusable component capable of displaying lists of ...

The useState hook introduces a lag of one character before updating the input state

I've been working on implementing an instant search feature for user profiles in my social network. Everything seems to be functioning properly, but I've noticed a delay of one character when setting the state using hooks on input change. After ...

Retrieving hashtags from a text

If I had a string like this var feedback = "Yum! #yummy #delicious at #CZ" Is there an efficient way to extract all the hashtags from the string variable? I attempted using JavaScript's split() method, but it seems cumbersome as I have to repeate ...

Iconic Navigation: Bootstrap 3 Navbar featuring Carousel

I'm currently in the process of developing a website using bootstrap3. Despite watching numerous tutorial videos, I am still facing challenges. One of my goals is to have the logo on the navbar aligning with the left side (which I've achieved ...

How to dynamically navigate using id in Next.js

For the CRUD functionality I'm working on, I want to navigate to a separate page containing the details of a specific row in the table when the user clicks the edit button. Here's an overview of my folder structure: https://i.sstatic.net/1G58w.p ...

We encountered an error when trying to locate the module: "Unable to locate '@material-ui/icons/Favorite'"

Error: Unable to find module '@material-ui/icons/Favorite' Error: Could not locate module '@material-ui/icons/Share' Module not found: Error: Can't resolve '@material-ui/icons/ExpandMore' Ever since upgrading to React ...

JavaScript layout: Thymealf

I have a unique thymeleaf template like so: <body> <div id="layout"> <!-- Menu toggle --> <a href="#menu" id="menuLink" class="menu-link"> <!-- Hamburger icon --> <span>& ...