All files / src/Stack styles.ts

100% Statements 8/8
83.33% Branches 5/6
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56      30x                 30x                           2x 6x 6x 6x                                                    
import { css, cssClass } from '../styled';
import { space, theme } from '../utils';
 
export const Stack = styleProps => cssClass`
  ${styleProps.orientation === 'vertical' && getVerticalAttributes(styleProps)}
  ${styleProps.orientation === 'horizontal' && getHorizontalAttributes(styleProps)}
 
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
const getVerticalAttributes = styleProps => css`
  & > *:not(:last-child) {
    margin-bottom: ${space(styleProps.spacing)(styleProps)}rem;
 
    & {
      ${theme(styleProps.themeKey, `css.child.vertical`)(styleProps)};
    }
  }
 
  & {
    ${theme(styleProps.themeKey, `css.vertical`)(styleProps)};
  }
`;
 
const getHorizontalAttributes = styleProps => {
  let breakpoint = theme('breakpoints', styleProps.verticalAt)(styleProps);
  breakpoint = breakpoint ? `${breakpoint}px` : styleProps.verticalAt;
  return css`
    @media screen and (min-width: ${breakpoint}) {
      display: flex;
 
      & > * {
        flex: 1;
      }
 
      & > *:not(:last-child) {
        margin-right: ${space(styleProps.spacing)(styleProps)}rem;
 
        & {
          ${theme(styleProps.themeKey, `css.child.horizontal`)(styleProps)};
        }
      }
 
      & {
        ${theme(styleProps.themeKey, `css.horizontal`)(styleProps)};
      }
    }
 
    @media screen and (max-width: ${breakpoint}) {
      ${getVerticalAttributes(styleProps)}
    }
  `;
};