-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathindex.js
41 lines (34 loc) · 926 Bytes
/
index.js
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
import React, { PropTypes } from 'react'
import styled from 'styled-components'
import { Label, Input, Block } from 'components'
const Error = styled(Block)`
margin: 0.5rem 0 0;
`
const Wrapper = styled.div`
margin-bottom: 1rem;
`
const Field = ({ error, name, invalid, label, type, ...props }) => {
const inputProps = { id: name, name, type, invalid, 'aria-describedby': `${name}Error`, ...props }
return (
<Wrapper>
{label && <Label htmlFor={inputProps.id}>{label}</Label>}
<Input {...inputProps} />
{invalid && error &&
<Error id={`${name}Error`} role="alert" color="danger" transparent>
{error}
</Error>
}
</Wrapper>
)
}
Field.propTypes = {
name: PropTypes.string.isRequired,
invalid: PropTypes.bool,
error: PropTypes.string,
label: PropTypes.string,
type: PropTypes.string
}
Field.defaultProps = {
type: 'text'
}
export default Field