-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (49 loc) · 1.47 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { PropTypes } from 'react'
import styled, { css } from 'styled-components'
import { font, palette } from 'styled-theme'
import { ifProp } from 'styled-tools'
export const fontSize = ({ height }) => `${height / 35.5555555556}rem`
const styles = css`
font-family: ${font('primary')};
display: block;
width: 100%;
margin: 0;
box-sizing: border-box;
font-size: ${fontSize};
padding: ${ifProp({ type: 'textarea' }, '0.4444444444em', '0 0.4444444444em')};
height: ${ifProp({ type: 'textarea' }, 'auto', '2.2222222222em')};
color: ${palette('grayscale', 0)};
background-color: ${palette('grayscale', 0, true)};
border: 1px solid ${ifProp('invalid', palette('danger', 2), palette('grayscale', 3))};
border-radius: 2px;
&[type=checkbox], &[type=radio] {
display: inline-block;
border: 0;
border-radius: 0;
width: auto;
height: auto;
margin: 0 0.2rem 0 0;
}
`
const StyledTextarea = styled.textarea`${styles}`
const StyledSelect = styled.select`${styles}`
const StyledInput = styled.input`${styles}`
const Input = ({ ...props }) => {
if (props.type === 'textarea') {
return <StyledTextarea {...props} />
} else if (props.type === 'select') {
return <StyledSelect {...props} />
}
return <StyledInput {...props} />
}
Input.propTypes = {
type: PropTypes.string,
reverse: PropTypes.bool,
height: PropTypes.number,
invalid: PropTypes.bool,
}
Input.defaultProps = {
type: 'text',
height: 40,
}
export default Input