``I am experiencing difficulties with utilizing a personalized color scheme in React JS with Material

I'm currently working on customizing the color palette for my project, but I am only able to modify the main attribute and not others. My development environment is JavaScript with MUI, not Typescript.

import './App.css';
import {BrowserRouter as Router, Route, Routes} from 'react-router-dom'
import Navbar from './components/Navbar/Navbar';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import Home from './components/Home/Home';
import Contact from './components/Contact/Contact';
import Pricing from './components/Pricing/Pricing';
import About from './components/About/About';

const theme = createTheme({
  palette: {
    primary: {
      light: '#f5f6fc', //highlight
      main: '#f6f6f6',  //site bg gray...this works (light, dark doesn't)
      dark: '#000629',   //navbar items
      contrastText: '#fff', //main text large font
    },
    
    secondary: {
      light: '#cdd0d9', //paragraph text dark gray
      main: '#dce6ff',  // for content bg light blue......this works (light, dark doesn't)
      dark: '#ba000d',  //hover buttons
      contrastText: '#000',
    },
  },
});


Answer №1

To incorporate multiple primary/secondary colors, utilize personalized variables.

Substituting primary with myPrimaryColor or any preferred label will create a custom variable that can be referenced later on.

const theme = createTheme({
    myPrimaryColor: {
        success: 'green',
        danger: 'red',
    },
}); 

followed by

`theme.myPrimaryColor.success` 

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

How to Show an Image in a Search Bar Using HTML

As I put the finishing touches on this table, I decided to add a search function to it. However, I encountered an issue with the search bar design. I wanted to incorporate a search icon png file as the background image, similar to the example showcased on ...

Determine the number of items (within an array) that were created within the past few days, weeks, and months leading up to the 'current time'

Having an array filled with objects containing timestamps: Here is a glimpse of the data: const dataList = [ { _id: "602102db3acc4515d4b2f687", createdDt: "2021-02-08T09:22:35.000Z", }, { _id: "6021024da706a260d89 ...

Display requested tab feature using jQuery upon page load

I am new to jquery and have been using this code for creating tabs: <script type="text/javascript" charset="utf-8> $(function () { var tabContainers = $('div.tabs > div'); tabContainers.hide().filter(':first&apo ...

Deselect the checkbox that was initially selected when an alternative checkbox option has been chosen

I am trying to implement a feature where there are 2 groups of checkbox options on the same page. Below is the code snippet: <div class="col-xs-12"> <label class="checkbox-inline"> <input type="checkbox" th:field="*{borrowerRace1}" th:val ...

Having trouble centering a Material UI card in React JS?

Struggling to center a card on my homepage using React. I've tried various CSS properties like justify, alignItems, alignContent, but nothing seems to work. Can't figure out how to get this card centered. Here's the code snippet: import Rea ...

Whenever I attempt to start a new React app, an error message pops up saying "Template was not provided. This issue may be due to using an outdated version of create-react-app."

Every time I attempt to set up a react app with the code below npx create-react-app app1 I encounter this issue: A template was not provided. This is likely due to using an outdated version of create-react-app. Please be aware that global installations of ...

Unraveling the onsubmit FormObject in an HTML form within the Google Sheets Sidebar: Tips and tricks

In the sidebar, I am setting up a form with 27 inputs to create new sheets based on various criteria. The form includes a text entry field and multiple groups of radio buttons and checkboxes. However, I am currently facing an issue when trying to create a ...

Actions for HTML form submission to API through proxy link

Currently, the form is functioning properly with this setup <form method="POST" action='http://localhost:3000/newRecord'> However, my goal is to simplify the action attribute to just be action='/newRecord'. In React, I achieve ...

I am perplexed by the CSS property `height: auto;` which seems to be making the element taller than necessary. How exactly is

Currently, I am dealing with some HTML/CSS aspects of an already established WordPress website. It appears that there might be an issue related to the theme's CSS causing this problem, although it is not immediately apparent. Specifically, there is s ...

Strange HTML pop-up keeps appearing every time I use styles in my code or insert anything with CSS

Recently, I created an OctoberCMS backend setup through my cPanel (I also have one on my localhost). Now, I am trying to add a background image but every time I attempt to do so, a strange HTML popup appears that I can't seem to figure out. Here is th ...

I am eager to run the code that I retrieved from the server. I have access to the code in my console and I desire for it to execute on the main browser page

Currently, I have a simple Google Chrome Extension that includes a button. By using AJAX, I am fetching a script from a server in my browser's console. Essentially, clicking on the extension reveals a button which, when clicked, fetches the script fro ...

Using z-index to position a paragraph element behind other elements in a webpage

I am facing a challenge where I want to hide a paragraph within an element, and layer it behind another element. Despite my attempts with z-index, I have been unsuccessful in achieving this effect between the elements. Could someone shed some light on why ...

Exploring the Magic of Organizing Styled Component Constants in Visual Studio Code

After trying out Styled Components in NextJS/React, I have come to appreciate its benefits. Although I usually separate my styles into different js files, my limited experience with React, props, hooks, and context sometimes requires me to keep the styles ...

React: Retrieved information, yet unable to access the properties of the object

After successfully fetching data from an API call and seeing the results in console, I am facing issues with accessing object properties and displaying them. interface Data { data: [] isLoading: boolean } function About() { const [ dataUser, ...

Solution for accessing the callee function in JavaScript slide down operation

While exploring a tutorial from CSS Tricks about animating section height, I came across a solution that I would like to implement in my Angular 2 application. Here is the function responsible for expanding sections in my app: expandSection(element) { / ...

"Unsupported source" issue when using Backblaze and next-video within a NextJS environment

When I try to access my Video component, I encounter an error. The URL functions correctly in a video tag within Next.js, but it doesn't seem to work the same way with the next-video package. Despite configuring my next.config.mjs file based on the pr ...

Having trouble accessing the 'root' property for all components in Material-ui v4

After upgrading from Material-UI v3 to v4, I am encountering an error with every component I import: app.js:3581 Uncaught TypeError: Cannot read property 'root' of undefined at Button (app.js:3581) at renderWithHooks (app.js:126202) ...

React.js TypeScript Error: Property 'toLowerCase' cannot be used on type 'never'

In my ReactJS project with TSX, I encountered an issue while trying to filter data using multiple key values. The main component Cards.tsx is the parent, and the child component is ShipmentCard.tsx. The error message I'm receiving is 'Property &a ...

Instructions for displaying a React component in the <main> element when employing react-burger-menu

Check out my code here. Utilizing react-burger-menu has allowed me to successfully implement the sidebar feature. The sidebar functionality is working as expected. My current challenge involves figuring out how to open the content for Home or GG within ...

What is the best way to make a black background div that perfectly aligns with another div?

When hovering over an image, I want it to fade out to opacity: 0.4, but instead of fading to white, I would like it to fade to black. To achieve this, I decided to change the background color of the body to black so that the fadeout will be towards black. ...