V
V
Vladimir Golub2019-04-26 10:57:17
User interface
Vladimir Golub, 2019-04-26 10:57:17

How to properly organize styles for a design system?

For example, there is a button component (Button). He has three sizes.
To change the size of a button, you need to read the width of the user's screen and change the corresponding props (size) or write media requests for different screen widths. What styles are better to use inline, jss and modular css?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-26
@RazerVG

We must first of all start from the tasks.
If your project has several button sizes for the same resolution, several styles, then you need to pass the appropriate properties: If the button, for any size value, must adapt to different resolutions, then it makes sense to use media queries. Using styled-components as an example:

const StyledButton = styled.button`
  height: ${props => props.height.sm}px;

  ${media.md`
    height: ${props => props.height.md}px;
  `}

  ${media.lg`
    height: ${props => props.height.lg}px;
  `}
`;

const getHeightProp = size => {
  switch(size) {
    case 'sm':
      return { ... };
    case 'md':
      return {
        sm: 32,
        md: 48,
        lg: 64,
      };
    case 'lg':
      return { ... };
  }
};

const Button = ({ size }) => {
  return <StyledButton height={getHeightProp(size)} />;
}

When using other tools, selectors, modifiers, style objects, etc. are used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question