Home > OS >  Is there a way to extend makeStyle classes in Material UI?
Is there a way to extend makeStyle classes in Material UI?

Time:09-16

I want to be able to achieve something like this:

const useStyles = makeStyles((theme) => ({
  button: {
    backgroundColor: 'red',
    border: 'black solid 5px',
  },
  selectedButton: {
    extend: 'button',
    backgroundColor: 'yellow'
  }
}))

So class 'selectedButton' would still have a black border but the background color will change.

CodePudding user response:

Using makeStyles

const button = {
  backgroundColor: "red",
  border: "black solid 5px",
};

const useStyles = makeStyles({
  button,
  selectedButton: {
    ...button,
    backgroundColor: "yellow"
  }
});

Edit zen-platform-gylg4

Using withStyles

const StyledButton = withStyles({
  root: {
    backgroundColor: "red",
    border: "black solid 5px"
  }
})(Button);

const SelectedButton = withStyles({
  root: {
    backgroundColor: "yellow"
  }
})(StyledButton);

Edit hardcore-lumiere-26zpr

  • Related