Use styled components for Input.tsx

This commit is contained in:
Jerko Steiner 2019-11-02 15:30:02 -04:00
parent 77b09fa653
commit 882248a367

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {Control, Field, Input as I, Heading} from 'bloomer'
import {IconType} from 'react-icons' import {IconType} from 'react-icons'
import styled from 'styled-components'
export interface InputProps { export interface InputProps {
name: string name: string
@ -14,6 +14,39 @@ export interface InputProps {
required?: boolean required?: boolean
} }
const Field = styled.div`
margin-bottom: 1em;
`
const Label = styled('label')`
text-transform: uppercase;
font-size: 11px;
`
const Control = styled.div`
position: relative;
`
const I = styled.span`
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
left: 0;
top: 0;
bottom: 0;
width: 2.5rem;
`
const TextInput = styled.input<{hasIconLeft?: boolean}>`
padding: 0.5rem 0.75rem;
padding-left: ${props => props.hasIconLeft ? '2.5rem' : '0.75rem'}
width: 100%;
`
export class Input extends React.PureComponent<InputProps> { export class Input extends React.PureComponent<InputProps> {
handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (this.props.onChange) { if (this.props.onChange) {
@ -24,10 +57,10 @@ export class Input extends React.PureComponent<InputProps> {
const {Icon} = this.props const {Icon} = this.props
return ( return (
<Field> <Field>
<Heading>{this.props.label}</Heading> <Label>{this.props.label}</Label>
<Control hasIcons> <Control>
<I <TextInput
className='input' hasIconLeft={!!Icon}
name={this.props.name} name={this.props.name}
type={this.props.type} type={this.props.type}
value={this.props.value} value={this.props.value}
@ -36,9 +69,7 @@ export class Input extends React.PureComponent<InputProps> {
readOnly={!!this.props.readOnly} readOnly={!!this.props.readOnly}
required={this.props.required} required={this.props.required}
/> />
{Icon && <span className='icon is-left is-small'> {Icon && <I><Icon /></I>}
<Icon />
</span>}
</Control> </Control>
</Field> </Field>
) )