Skip to main content
Brand and assets
Build
Monitor and contribute
/
Front-end platform
  • Overview
  • Technical architecture
  • Core framework
  • Application
  • global-shell
  • modular-arch
  • Product shells
  • Modules & apps
  • Module directory
  • Apps
  • Bundles
  • Bundle explorer
  • Guides
  • Install Murray
  • Universal components
  • Build a universal component
  • Responsive styles
  • RTL support
  • Translations & i18n
  • When to use Form
  • Positioning elements
  • Add a new icon
  • Utilities
  • Overview
  • Layouts
  • Responsive styles

Responsive styles

Murray has several ways to handle responsive styles.

Breakpoints​

We work with the same breakpoints across all our apps:

xsvssmmdlgxlxxl
0px420px640px800px960px1120px1440px

Each breakpoint has 2 design tokens related to it: one for the min-width and one for the max-width. For example, the sm breakpoint has the following tokens:

  • ltSm, which coressponds to max-width: 639px (the lt stands for "less than")
  • sm, which coressponds to min-width: 640px

sx prop​

For any component that supports the sx styling prop, it's easy to add responsive styles though media properties.

It can be used to change any style of a component:

Demo

It can also be used to hide or show a component. Please keep in mind that doing so will always keep both elements in the tree (they are present but hidden).

I'm displayed on smaller screens 📱

I'm displayed on larger screens 🖥️

Responsive styling through sx is the recommended approach in most cases as:

  • it works universally (on both mobile and web)
  • it is compatible with Server-Side-Rendering
  • it is the most performant (it relies on CSS on web, and on inline styles and global listeners on mobile)

However, it's not compatible with legacy Murray components that don't support the sx prop.

useMedia hook​

Sometimes sx is not enough for responsiveness. It can be either that:

  • you need to change the styles of a component that doesn't support sx
  • you need to completely unmount components dependening on the screen size
  • you want to actually change logic (and not only styles)

For such situations, the useMedia hook can be used. It returns an object with media query tokens as keys and booleans as values:

I'm mounted on smaller screens 📱

This hook is optmized to avoid re-renders when the screen size changes without triggering a breakpoint change we're not listening to.

useResponsiveBreakpoints hook​

Murray also provides a useResponsiveBreakpoints hook. This hook only works on web and can be replaced by the newer useMedia is most cases.

The only advantage of using this hook is that it can listen to the size of the parent <ResponsiveRoot /> container (instead of the page size)

I'm mounted on smaller screens 📱

cssUtils helpers​

You might encouter usages of cssUtils's helpers: responsiveUp, responsiveDown, responsiveHideUp and responsiveHideDown.

These helpers can be used on legacy components that don't support the sx prop and rely on JSS or Emotion for styling.

Edit this page
Previous
Build a universal component
Next
RTL support
  • Breakpoints
  • sx prop
  • useMedia hook
  • useResponsiveBreakpoints hook
  • cssUtils helpers