Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding breakpoint to custom theme in Material UI Next (reactjs)

I'm creating a custom theme with mui as follows:

export default createMuiTheme({
  breakpoints: {
    keys: [
      "xxs",
      "xs",
      "sm",
      "md",
      "lg",
      "xl",
    ],
    values: {
      xxs: 0,
      xs: 414, // iPhone X and below in portrait mode
      sm: 600,
      md: 960,
      lg: 1280,
      xl: 1920,
    },
  },
})

But when I try to use it in a class declaration like so:

const styles = theme => ({
  root: {
    [theme.breakpoints.down('xxs')]: {
      textAlign: "center",
      padding: theme.spacing.unit * 2,
    },
  },
})

I get the following CSS:

@media (max-width:NaNpx) {
  .root-3 {
    padding: 16px;
    text-align: center;
  }
}

Is there a special way to add a custom breakpoint vs. just modifying existing ones?

like image 376
jake Avatar asked Apr 09 '18 18:04

jake


1 Answers

Currently it is only possible to customize the values of the predefined breakpoints. Here is an example:

const theme = createMuiTheme({
  breakpoints: {
    values: {
      xs: 0,
      sm: 450,
      md: 600,
      lg: 900,
      xl: 1200
    }
  }
});

Edit Material-UI Custom breakpoints

The breakpoint names cannot be configured. There is a comment in createBreakpoints.js explaining this:

// Sorted ASC by size. That's important.
// It can't be configured as it's used statically for propTypes.
export const keys = ['xs', 'sm', 'md', 'lg', 'xl'];

UPDATE (September 2018):

This feature has been requested and is currently under discussion. See material-ui/issues/11649

like image 104
Luke Peavey Avatar answered Oct 13 '22 15:10

Luke Peavey