All files / src/Input styles.ts

91.67% Statements 11/12
92.31% Branches 12/13
83.33% Functions 5/6
100% Lines 7/7

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150      76x                       76x                                                                                                                                           3x                     76x                               22x             6x                                                       6x    
import { css, cssClass } from '../styled';
import { borderRadius, fontSize, palette, theme } from '../utils';
 
export const InputWrapper = styleProps => cssClass`
  align-items: center;
  position: relative;
  width: 100%;
 
  ${styleProps.size && wrapperSizeProperties(styleProps)};
 
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
export const Input = styleProps => cssClass`
  -webkit-appearance: none;
  border: 1px solid ${palette('white900')(styleProps)};
  border-radius: ${borderRadius('default')(styleProps)};
  height: 2.75em;
  width: 100%;
  padding: 0.4em 0.8em;
  transition: box-shadow 0.1s ease-in-out 0s, border-color 0.1s, background-color 0.1s;
 
  &[disabled] {
    background-color: ${palette('white700')(styleProps)};
    box-shadow: unset;
    cursor: not-allowed;
 
    & {
      ${theme(styleProps.themeKey, `css.disabled`)(styleProps)};
    }
  }
 
  &:hover {
    box-shadow: ${palette(`${styleProps.state || 'primary'}Tint`)(styleProps)} 0px 0px 0px 2px !important;
    border-color: ${palette(`${styleProps.state || 'primary'}100`)(styleProps)};
  }
 
  &:focus {
    outline: unset;
    z-index: 2;
    border-color: ${palette('primary')(styleProps)};
    box-shadow: ${palette('primaryTint')(styleProps)} 0px 0px 0px 3px !important;
 
    & {
      ${theme(styleProps.themeKey, `css.focus`)(styleProps)};
    }
  }
 
  &::placeholder {
    opacity: 0.6;
 
    & {
      ${theme(styleProps.themeKey, `css.placeholder`)(styleProps)};
    }
  }
 
  ${styleProps.state &&
    css`
      & {
        border-color: ${palette(`${styleProps.state}`)(styleProps)};
        box-shadow: ${palette(`${styleProps.state}Tint`)(styleProps)} 0px 0px 0px 3px !important;
      }
    `}
 
  ${(styleProps.after || styleProps.isLoading) &&
    css`
      & {
        padding-right: 2.3em;
      }
    `};
 
  ${styleProps.before &&
    css`
      & {
        padding-left: 2.3em;
      }
    `};
 
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
export const InputIcon = styleProps => cssClass`
  && {
    fill: ${palette('text100')(styleProps)};
    height: 2.75em;
    margin: 0 0.75em;
    top: 0;
 
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
export const InputSpinner = styleProps => cssClass`
  && {
    font-size: inherit;
    align-items: center;
    display: flex;
    position: absolute;
    height: 2.75em;
    margin: 0 0.75em;
    top: 0;
    right: 0;
    z-index: 2;
 
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
export const InputField = styleProps => cssClass`
  & {
    ${theme(styleProps.themeKey, `css.root`)(styleProps)};
  }
`;
 
export function wrapperSizeProperties(styleProps) {
  const properties = {
    small: css`
      font-size: ${fontSize('150')(styleProps)}rem;
 
      & {
        ${theme(styleProps.themeKey, `css.sizes.small`)(styleProps)};
      }
    `,
    default: css`
      & {
        ${theme(styleProps.themeKey, `css.sizes.default`)(styleProps)};
      }
    `,
    medium: css`
      font-size: ${fontSize('300')(styleProps)}rem;
 
      & {
        ${theme(styleProps.themeKey, `css.sizes.medium`)(styleProps)};
      }
    `,
    large: css`
      font-size: ${fontSize('400')(styleProps)}rem;
 
      & {
        ${theme(styleProps.themeKey, `css.sizes.large`)(styleProps)};
      }
    `
  };
  return properties[styleProps.size];
}