MUI provides the flexibility to adjust the opacity separately for Chip labels/icons and backgrounds

My objective is to customize the opacity of label/icon and background in MUI Chip. I want the label & icon to have an opacity of 1, while the background should have an opacity of 0.0571.
Technologies used in this project include React, TypeScript, Material-UI v5, and Go.

Below is a snippet of my code:

export default function InvoiceItem({ data, func }: Props) {
    return (
        {data.map((invoice, index: number) => (
            <Chip
                label={capitalizeFirstLetter(invoice.status)}
                color={func(invoice.status)}
                sx={{
                    mr: 5,
                    width: 100,
                    typography: "h4",
                }}
                icon={<FiberManualRecordIcon />}
            ></Chip>
        ))}
    );
}

I have already attempted the following:


<Chip
    label={capitalizeFirstLetter(invoice.status)}
    color={func(invoice.status)}
    opacity= 0.057
    sx={{
        "& .MuiChip-label": {
            opacity: 1
        },
    }}
    icon={<FiberManualRecordIcon />}
></Chip>

sx={{
    "& .MuiChip-root”: {
        opacity: 0.0571
    },
    "& .MuiChip-label": {
        opacity: 1
    },
}}

Answer №1

Attempting this method may not yield the desired results due to the parent element's opacity affecting the child. To accomplish this in an alternative manner, consider implementing the following approach:

"& .MuiChip-root”: {
    background-color: rgb(100 100 100 / 0.057)
},

It is essential for the RGB values to align with your initial color scheme.

Answer №2

To add some flair to your design, consider utilizing the rgba value for background colors.

<Chip
  label={capitalizeFirstLetter(invoice.status)}
  // color={func(invoice.status)}
  icon={<MdFiberManualRecord />}
  sx={{
    backgroundColor: "rgba(0, 0, 0, 0.0571)",
    color: "black",
  }}
/>

By setting the background color using rgba values, you can avoid redundant color definitions for both the label and icon. For added flexibility, you can even incorporate the "backgroundColor" property with a custom function that returns an rgba value based on the invoice status.

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 steps can be taken to ensure that a box is the exact same size

Is it possible to make two of my main buttons the same size? I'm just starting out in web development and could use some guidance. Below is the HTML and CSS code I currently have for my index.html: <body> <div> <img src="img/projec ...

Having difficulty implementing a versatile helper using Typescript in a React application

Setting up a generic for a Text Input helper has been quite challenging for me. I encountered an error when the Helper is used (specifically on the e passed to props.handleChange) <TextInput hiddenLabel={true} name={`${id}-number`} labelText=" ...

The challenge of handling overflow in CSS slide-in and slide-out animations

Trying to achieve a smooth animation where one list of tiles moves off screen as another list comes into view. Utilizing Angular's ng-for to iterate through a visible items array, causing only one list technically despite Angular's ngAnimate mod ...

Tips for making a fluid DIV expand to fit the entire width of the page

My layout features fixed-width sidebars on the left and right, with a fluid main content area that fills the space in between using float:left. Here's an example: #left-sidebar {width: 200px;} #right-sidebar {width: 300px;} #main-content {margin-left ...

Implementing event emitters in a React and Node.js application to connect to a socket.io server through an

I am currently using socket.io to send messages to the client. While I know that I could achieve this by using the HTTP response from the express route, my intention is to emit messages as I receive data from an API in a real-world scenario. However, the ...

The Angular route successfully navigated to the page, but the HTML content was not

Whenever I select the Home option in the navigation bar, it takes me to the home URL but doesn't display the HTML content. Below is my app.routing.module.ts code: import { Component, NgModule } from '@angular/core'; import { RouterModule, Ro ...

Is it possible to position my label above my text box input?

Having trouble aligning the checkbox label with the edge of the text area in my login form code. It always ends up on the right side, outside of the div container when inspected. I've attempted setting a left value for the label, but it causes issues ...

Disregarding boundaries set by divisions

Trying to keep things concise here. I have a division called "the box" with a fixed width of 1200px that contains various other divisions. One of these divisions is a links bar, known as the "pink bar", which has a width of 100% and a height of 25px. My is ...

Incorporate the block-input feature from sanity.io into your next.js blog for enhanced functionality

Currently, I'm in the process of creating a blog using next.js with sanity.io platform. However, I am facing some difficulties when it comes to utilizing the code-input plugin. What's working: I have successfully implemented the code component b ...

Tips for maintaining consistent content length of nested divs as one div's content grows

I am looking for a solution to ensure that when the map is running on my MUI card, some cards with more text content will increase in length while maintaining equal text alignment. I have attached a screenshot of my actual app and a CodeSandbox example for ...

Accepting undefined in rest parameter of typescript

I'm struggling with an exercise involving Function parameters: The maximum function below has the wrong type. To allow undefined in the rest arguments, you need to update the type of the rest parameter. Fortunately, you don't have to change the ...

Changing font color of a selected item in Material-UI's textview

I have a select textview in my react app and I am wondering how to change the font color after selecting an item from this textview. <div> <TextField id="standard-select-currency" select fullWidth l ...

Is there a way to verify the presence of an extra category while mapping through this array in React JS?

When dealing with the SubCategoryDetail, it's important to note that there may or may not be an Additional Category included. To address this, I need a method to determine if an Additional Category exists so that I can either proceed to explore the Ad ...

Tips for creating unique, custom styled components in Material-UI

Here's a seemingly simple problem: An Example Background: We have many lists of items and render them in the UI with <List>. An Example Problem: We sometimes want to remove the extra padding injected on <List> (for example, using <Unpa ...

Switch between input and the input is not displayed inline

I've been struggling to align the Toggle button with the input box for quite some time now. I really need them to be inline so that they form a grid properly as everything is dynamic. I have experimented with using a Div on its own instead of a label ...

Guidelines for automatically installing npm modules during the building of an ASP.NET Core project

In my current project, I am using ASP.NET Core Web API as the backend and React SPA as the frontend. The folder structure is organized like this: WebApiProject │ ├── ClientApp/ │ ├── public/ │ ├── src/ │ └── package.j ...

Checkbox in Angular FormGroup not triggering touched state

There seems to be an issue with the Angular form when checking if the form is touched, especially in relation to a checkbox element. Despite the value of the checkbox changing on click, I am seeing !newDeviceGroup.touched = true. I'm not quite sure wh ...

I am encountering an issue where Typescript paths specified in the tsConfig.app.json file are not resolving properly

I have defined path settings in my tsconfig.app.json file like this: "paths": { "@app/core": ["./src/app/core"] } Every time I run a test that includes import statements with relative paths, it throws the following error: ...

Setting the minimum and maximum width of a div using Bootstrap, not based on the number of columns

I want to adjust the number of columns based on the width of the screen rather than choosing a specific value like 3, 4, 5, or 6. ...

Expressjs makes it easy to upload audio files to your website

Currently, I'm developing a music app and I'm looking for the best way to upload an audio file in my ExpressJS application. Is it possible to use Cloudinary or is there another method that is more efficient? I attempted to follow the same proces ...