``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

Is it possible to implement a Cross-Domain iframe Resizer in NextJS?

I am facing a challenge with my NextJS project that will be loaded within an Iframe. The page's content is dynamic, and its height changes frequently. Rather than relying on scrolling, I would like the Iframe to automatically adjust its height based o ...

Enhance your export capabilities with Material-UI theme integration for helper functions

Looking to create a new file that will house helper functions for multiple components sharing the same logic. The challenge arises when trying to access my locale.ts file within this new file in order to utilize the current language based on the theme (loc ...

Achieving Perfect Alignment for Absolutely Positioned Divs in

I'm currently facing an issue where the image I'm trying to center horizontally also moves the parent div downward when I try to vertically center it using top-margin. This is not the desired outcome. If you'd like to see what I mean, I&apo ...

Utilizing express and socket.io for seamless cross-domain communication

Is there a way to activate cross-domain functionality for express.io? I require it for a Cordova application, but when using Chrome, I get an error message saying "No 'Access-Control-Allow-Origin' header is present on the requested resource. Orig ...

Reposition icons to the center within the icon-div container

I am trying to center align the elements in my icon-div as shown in the wireframe image. What steps should I take to achieve this layout? HTML: <div class="icons_div"> <div class="row bg-secondary"> <div class="col-sm-2"> ...

How can I effectively organize REST backend API requests when using React?

As my colleagues and I collaborate on developing a full stack web application, we have chosen React as our frontend framework. Our project involves performing CRUD operations on multiple resources, which means creating various pages. In the past, I came a ...

Error 500: An invalid data type was encountered in an express.js node.js environment

Currently, I am in the process of developing an Authentication page using a combination of node.js, express.js, and mysql2. The user ID and password entered on the webpage are then passed through app.post('/login',...). However, upon submitting t ...

Spinning loader on MaterialUI CardMedia image

I have a component that is functioning perfectly fine. However, I want to display a spinner until the image has finished loading. Can anyone advise me on how to achieve this? import React from 'react'; import { makeStyles } from '@material- ...

Unusual CSS anomalies encountered on iPhone devices

Having an issue with the animation on my homepage where the logo spins into place. It works fine on desktop and in Chrome and Firefox mobile simulators, but on actual phones it rotates an additional 90 degrees. Included are screenshots from the Firefox mob ...

Error in RatingBar component: Vue.js 3 and Tailwind CSS not displaying dynamic width correctly

I have a component called RatingBar in Vue.js 3 with Tailwind CSS. My goal is to dynamically adjust the width of the parent element's class based on a value, but even though I see the desired width in DevTools, it always renders as 100%. Below is the ...

Looking to capture a specific div in a React JS component? I initially tried using the "use-screenshot-hook" package, but unfortunately, it captured the entire page instead

const reference = useRef(null); const { capturedImage, takeScreenshot } = useScreenshot(); const imageStyle = { height: imgHeight, width: imgWidth }; const fetchImage = () => takeScreenshot({reference}); const saveImage = () => ...

Why is the label on my styled checkbox shifting position?

While custom styling a checkbox, I'm facing an issue where the label next to it keeps shifting. When unchecked, it aligns itself at the bottom of the box, but upon checking, it moves to center align with the box. .check { width: 100%; font-we ...

Implementing a custom error page in Nextjs for failed api requests

I have implemented a custom error page in Next.js to be displayed when an API call fails. However, the issue I am encountering is that even when the API call fails, it still shows the same page as if the route was successful. For instance, I have a route " ...

Is there a way to show a 'Refresh' icon in HTML without the need to download an image through HTTP?

In my HTML/JavaScript app project, I am looking to incorporate a 'refresh' symbol without having to load an image through HTTP requests. Are there reliable methods that can achieve this across all major browsers? I came across the Unicode value: ...

Turning a stateful React component into a stateless functional component: Ways to achieve functionality similar to "componentDidMount"

I recently developed a small, stateful React component that utilizes Kendo UI to display its content in a popup window when it loads. Here is a snippet of the code: export class ErrorDialog extends React.Component { constructor(props, context) { sup ...

Adjust the vertical size of the background hue on the span element within the text

Can the height of the background color in my span be adjusted? HTML <span class="highlight">Some highlighted text</span> CSS .highlight{ font-family: 'Roboto', sans-serif; font-weight: 300; font-size: 1.5em; backgr ...

The Vite project fails to open when I attempt to run the command "npm run dev" in react

When attempting to start a new React project using Vite React, I encountered an error after running npm install and npm run dev. The specific error message is as follows: node:internal/modules/cjs/loader:1327 return process.dlopen(module, path.toNamespace ...

Every time I try to use useState in my React application with Material UI, I encounter the error message "Failed to compile" and "not defined"

Currently, I am working on a project where I need to create a component for generating a blog post. Struggling with a confusing error message popping up, and despite my attempts to move the useState code outside the function, it only leads to more issues. ...

Unit testing an API built with Express and Mongoose using Jest

I have decided to implement a TDD approach for a user API that I am working on. Specifically, I am looking to add unit tests for two functions: userRegister and userLogin. Here is the code snippet from my app.js: 'use strict' const express = r ...

Selenium and PhantomJS are having trouble interpreting JavaScript code

Currently experimenting with Selenium and PhantomJS for Java search tasks, I'm facing an issue where PhantomJS fails to activate javascript. My goal is to access a webpage that utilizes javascript. Previously, this method worked well for me, but now I ...