forked from smooth-code/smooth-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.js
122 lines (103 loc) · 2.69 KB
/
Input.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
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
121
122
import React from 'react'
import classNames from 'classnames'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import handleRef from './internal/handleRef'
import setWithComponent from './internal/setWithComponent'
import * as defaultTheme from './theme/defaultTheme'
import { th, mixin } from './utils'
const InputComponent = ({
component: Component = 'input',
className,
control,
size,
theme,
valid,
...props
}) => (
<Component
{...props}
className={classNames(
'sui-input',
{
'sui-control': control,
'sui-is-valid': valid === true,
'sui-is-invalid': valid === false,
[`sui-input-${size}`]: size,
},
className,
)}
/>
)
const InputRefComponent = handleRef(InputComponent)
const Input = styled(InputRefComponent)`
${mixin('base')};
display: inline-block;
border-width: ${th('inputBorderWidth')};
border-color: ${th('inputBorderColor')};
border-style: solid;
border-radius: ${th('borderRadius')};
padding: ${th('inputPaddingY')} ${th('inputPaddingX')};
font-size: ${th('fontSizeBase')};
line-height: ${th('inputLineHeight')};
color: ${th('inputTextColor')};
transition: ${th('transitionBase')};
background-color: ${th('inputBgColor')};
&[type='number'] {
padding-right: 6px;
}
&::placeholder {
color: ${th('inputPlaceholderText')};
}
&:focus {
${mixin('controlFocus')};
}
&[disabled] {
background-color: ${th('inputDisabledBgColor')};
color: ${th('inputDisabledText')};
}
&.sui-input-sm {
padding: ${th('inputPaddingYSm')} ${th('inputPaddingXSm')};
font-size: ${th('fontSizeSm')};
border-radius: ${th('borderRadiusSm')};
}
&.sui-input-lg {
padding: ${th('inputPaddingYLg')} ${th('inputPaddingXLg')};
font-size: ${th('fontSizeLg')};
border-radius: ${th('borderRadiusLg')};
}
&.sui-control {
display: block;
width: 100%;
&:focus {
border-color: ${th('controlFocusBorderColor')};
box-shadow: ${mixin('controlFocusBoxShadow', 'primary')};
}
&.sui-is-valid {
border-color: ${th('success')};
&:focus {
border-color: ${th('success')};
box-shadow: ${mixin('controlFocusBoxShadow', 'success')};
}
}
&.sui-is-invalid {
border-color: ${th('danger')};
&:focus {
border-color: ${th('danger')};
box-shadow: ${mixin('controlFocusBoxShadow', 'danger')};
}
}
}
`
Input.propTypes = {
control: PropTypes.bool,
size: PropTypes.oneOf(['sm', 'lg']),
theme: PropTypes.object,
valid: PropTypes.bool,
}
Input.defaultProps = {
theme: defaultTheme,
}
setWithComponent(Input, InputRefComponent)
/** @component */
export default Input