All files / utils/input-container index.js

0% Statements 0/26
0% Branches 0/12
0% Functions 0/5
0% Lines 0/8
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                                                                                                                                                                                                                                               
import React from 'react'
import css from 'classnames'
import styled from 'styled-components'
 
const InputContainerStyled = styled.div`
  position:relative;
  display:flex;
  width:${p => p.width};
 
  &.error, &.alert, &.success {
    input {
      box-sizing: border-box;
      padding-right: 44px;
    }
  }
 
  &.horizontal{
    margin-top: 5px;
 
    >.label{
      line-height: 30px;
      margin-right: 10px;
      white-space: nowrap;
    }
  }
 
  .component
  {
    position:relative;
    width:100%;
    padding: 2px 1px 1px 1px;
    border-radius: 2px;
    box-shadow: inset -1px 0 0 0 #c5d0e1, inset 0 -1px 0 0 #c5d0e1, inset 1px 0 0 0 #c5d0e1, inset 0 2px 0 0 #afcef3;
    transition: box-shadow 300ms linear;
    max-height:${p => p.height};
 
    &:focus-within {
      box-shadow: inset -1px 0 0 0 #c5d0e1, inset 0 -1px 0 0 #c5d0e1, inset 1px 0 0 0 #c5d0e1, inset 0 2px 0 0 #2870b2;
    }
  }
 
  &.error {
    .component {
      box-shadow: inset -1px 0 0 0 #c5d0e1, inset 0 -1px 0 0 #c5d0e1, inset 1px 0 0 0 #c5d0e1, inset 0 2px 0 0 #F9575B;
    }
  }
 
  &.alert {
    .component {
      box-shadow: inset -1px 0 0 0 #c5d0e1, inset 0 -1px 0 0 #c5d0e1, inset 1px 0 0 0 #c5d0e1, inset 0 2px 0 0 #ffc107;
    }
  }
 
  &.success {
    .component {
      box-shadow: inset -1px 0 0 0 #c5d0e1, inset 0 -1px 0 0 #c5d0e1, inset 1px 0 0 0 #c5d0e1, inset 0 2px 0 0 #6f9e32;
    }
  }
 
  &.vertical{
    flex-flow:column;
  }
 
  >.label {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 7px;
    text-transform: uppercase;
    color: #3b495e;
    margin-top: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
 
  >.input-component {
    position: relative;
    width: 100%;
  }
 
  .message {
    display: block;
    margin-top: 2px;
    opacity:0;
    height:14px;
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    transition: opacity 300ms linear;
 
    &.error {
      color: #ec393d;
    }
 
    &.alert {
      color: #e8b007;
    }
 
    &.success {
      color: #6f9e32;
    }
 
    &.show{
      opacity:1;
    }
  }
`
 
const InputContainer = ({ children, width = '100%', height = '40px', type, label, message, orientation = 'vertical' }) => (
  <InputContainerStyled width={width} height={height} className={css(type, orientation, 'input-container')}>
    {label && <div className='label' title={label} >{label}</div>}
    <div className='input-component'>
      <div className='component'>{children}</div>
      <div className={css({ 'show': message !== null }, type, 'message')}>{message}</div>
    </div>
  </InputContainerStyled>
)
 
export default InputContainer