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
|