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

Fixing a menu hover appearance

I recently encountered a small issue with the menu on my website. When hovering over a menu item, a sub-menu should appear. However, there seems to be a slight misalignment where the submenu appears a few pixels below the actual menu item. Check out the w ...

Prevent tooltip text from appearing when a button is disabled in an angular application

As a beginner in UI development, I have a requirement for my Angular application. I need to enable and disable a button based on certain conditions. The tricky part is that I want to display a tooltip only when the button is enabled. I have managed to chan ...

"Unlock the power of NGXS by leveraging the raw state values

I'm having trouble locating an example in the NGXS documentation that demonstrates how to properly type the state object. Specifically, I am looking for guidance on typing the return value of the snapshot method of Store. For instance: this.store.sn ...

What is the best way to ensure that my text is perfectly centered both horizontally and vertically within this DIV?

What's the best way to vertically and horizontally center text? Here is an example code that needs to be centered: <div style="display: block; height: 25px;"> <span id="ctl_txt" style="background-color: rgb(255, 0, 0);"> Basic ...

Modify flex direction to column in response to changes in height of another div or when its content wraps

I am currently utilizing React MUI V5 and I am looking to modify the flex direction of a div from row to column when a preceding div changes in height or wraps. Below is a basic example of what I have implemented using plain HTML/CSS, but I am uncertain i ...

Acquire by Identifier - Tonic()

Currently, I am in the process of setting up a code example on tonicdev.com for my open-source React component available on Npm. Below is the code snippet that I am attempting to execute (editable live on tonicdev.com here): var React = require('rea ...

Material UI: Easily adjusting font size within Lists

When developing forms with react js and material UI, I encountered an issue with changing the font size within lists to achieve a more compact layout. The code fontSize={10} didn't seem to have any effect regardless of where I added it. Is there a wa ...

Choosing options using an enum in Angular 2

In my TypeScript code, I have defined an enum called CountryCodeEnum which contains the values for France and Belgium. export enum CountryCodeEnum { France = 1, Belgium = 2 } Now, I need to create a dropdown menu in my form using this enum. Each ...

When viewed on mobile browsers, the side-by-side divs in a tabbed layout appear to be

Looking for some help with responsive design for the "PORTFOLIO ATTRIBUTES" tab on my website. On desktop, the content displays fine, but on mobile it overlaps and cuts off. Here's the link to the page in question: . Any suggestions on how to maintai ...

Achieving responsive design using text font percentage instead of text images can be done by implementing the following code snippet provided below

When working with text in HTML, I encountered an issue where using percentages for width and height was not giving me the desired results. To work around this, I used images of text instead, but each image ended up either stretched or looking too small. H ...

Having trouble with CSS3 radio buttons not functioning properly on Firefox?

Does anyone know why my CSS3 pseudo elements are working fine in Chrome, but reverting back to default styling in Firefox for my radio button? Any suggestions? Check out this JSFIDDLE link for reference: JSFIDDLE Here is the HTML code snippet: <input ...

Tips for creating CSS styles for a selected input field

I seem to be stuck in a situation where my screen looks similar to the screenshot provided. There are four input elements that I would like to have bordered just like in the image, complete with a circled tick mark. I've managed to create these four i ...

The alignment of the DropDown menu in the AppBar is not displaying correctly

I've encountered an issue with aligning the dropdown menu while using MUI with react. I have been referencing the documentation at https://mui.com/material-ui/react-menu/#account-menu. Here is my code snippet: //** A styled component **// const Styled ...

Failed to transmit information from React application to Node server

I'm having trouble creating a search function where I can retrieve a variable from the search field and display the matching results. However, I keep encountering an error stating that the variable is undefined when I try to console.log it in the node ...

Achieve a fade-in effect on an element with TailwindCSS when clicked

Currently working on an app and facing a challenge with fading the menu in and out when clicking a button. The menu is rendering on click using state, but struggling to achieve the fade in / fade out effect. Interestingly, when tweaking the opacity value d ...

"Customizing the topbar of Twitter Bootstrap for right-to

Attempting to implement twitter bootstrap for a top navigation bar on my master page. http://jsfiddle.net/ZqCah/1/ Encountering some issues and seeking assistance: 1- Desiring to switch the direction of all content to right-to-left (rtl). This would me ...

Transferring data to a drawer component from a list using React Ant Design

I am currently working on a functionality that involves displaying a list of customers along with their details. The challenge I am facing is related to implementing a feature where clicking on a customer's name opens up a drawer containing specific d ...

Having difficulty updating the state within a function

While working on developing a server-side pagination that mimics a static version, I have almost completed it. However, I have run into some issues that I am struggling to resolve. Here's how my code currently looks: const LiveIndex = (props) => { ...

Locked first row and first column in HTML table

I'm struggling with freezing the first row and column in an HTML file exported from Microsoft Excel. When attempting to add position:fixed; to achieve this, I noticed that it changes the size and alignment of the headers. Can someone please advise me ...

When the window is resized, the div containing a table is getting pushed beyond its original

I have been developing a 'calculadora de creditos' or credits calculator. For this project, I used a responsive layout. Despite searching extensively online for solutions to my issue, I came up empty-handed. CSS CODE: (CSS code here) HTML CO ...