-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf52f5d
commit 49fc78d
Showing
8 changed files
with
176 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as React from 'react' | ||
import { mount } from 'enzyme' | ||
|
||
import TextArea from './index' | ||
|
||
describe('<TextArea />', () => { | ||
it('renders', () => { | ||
mount(<TextArea />) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import * as React from 'react' | ||
import { FunctionComponent, InputHTMLAttributes } from 'react' | ||
import styles from './styles' | ||
import concat from '../_utility/concat' | ||
import Error from '../Error' | ||
import Gutter from '../Gutter' | ||
|
||
interface Props { | ||
name?: string | ||
onChange?: InputHTMLAttributes<HTMLTextAreaElement>['onChange'] | ||
onFocus?: () => void | ||
onBlur?: () => void | ||
value?: string | number | ||
defaultValue?: string | number | ||
error?: string | boolean | ||
placeholder?: string | ||
className?: string | ||
onClick?: (MouseEvent) => void | ||
background?: string | ||
color?: string | ||
containerStyle?: object | ||
inputStyle?: object | ||
inputErrorStyle?: object | ||
errorStyle?: object | ||
style?: object | ||
label?: string | ||
min?: number | ||
max?: number | ||
step?: number | ||
textAlign?: 'center' | 'left' | '-moz-initial' | 'inherit' | 'initial' | 'revert' | 'unset' | 'right' | 'end' | 'justify' | 'match-parent' | 'start' | undefined | ||
cols?: number | ||
rows?: number | ||
prefix?: string | ||
suffix?: string | ||
disabled?: boolean | ||
} | ||
|
||
/** | ||
* A standardized input component plus textarea | ||
*/ | ||
const Input: FunctionComponent<Props> = ({ | ||
name, onChange, onFocus, onBlur, value, defaultValue, error, placeholder, | ||
className, onClick, background, color, | ||
containerStyle, inputStyle, inputErrorStyle, errorStyle, style, | ||
textAlign, | ||
rows = 3, cols, | ||
label, min, max, step, | ||
disabled | ||
}) => { | ||
return ( | ||
<div | ||
className={concat('text-area', className)} | ||
style={{ | ||
...styles.container, | ||
position: 'relative', | ||
...style, | ||
...containerStyle | ||
}}> | ||
|
||
{ label | ||
? <> | ||
<label className='text-area__label'> {label} </label> | ||
<Gutter half /> | ||
</> | ||
: null } | ||
|
||
<textarea | ||
className='textarea__input' | ||
name={name} | ||
rows={rows} // textarea | ||
cols={cols} // textarea | ||
onChange={onChange} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
placeholder={placeholder} | ||
value={value} | ||
defaultValue={defaultValue} | ||
onClick={onClick} | ||
style={{ | ||
...styles.input, | ||
textAlign: textAlign || 'left' as 'left', | ||
resize: 'none', | ||
padding: '1rem', | ||
...(background ? { background: background } : null), | ||
...(color ? { color: color } : null), | ||
...inputStyle, | ||
...(error ? (inputErrorStyle || styles.errorBorder) : null), | ||
height: 'auto' | ||
}} | ||
disabled={disabled}/> | ||
|
||
{ typeof error === 'string' | ||
? <Error | ||
className='input__error' | ||
style={{ | ||
...styles.error, | ||
...errorStyle | ||
}}> | ||
|
||
{error} | ||
|
||
</Error> | ||
: null } | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default Input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
Input example: | ||
|
||
```js | ||
<TextArea /> | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import config from '../config' | ||
|
||
export default { | ||
container: { | ||
width: '100%', | ||
display: 'block' | ||
}, | ||
input: { | ||
height: '42px', // uniform height | ||
border: '1px solid rgba(0,0,0, 0.20)', | ||
borderRadius: config.size.corners, | ||
WebkitBorderRadius: config.size.corners, | ||
MozBorderRadius: config.size.corners, | ||
WebkitAppearance: 'none' as 'none', // Disable chrome styles | ||
MozAppearance: 'none' as 'none', // Disable firefox styles | ||
// border: 'none', | ||
// height: '100%', | ||
width: '100%', | ||
margin: 0, | ||
padding: 0, | ||
paddingLeft: '1rem', | ||
paddingRight: '1px', // border fix | ||
WebkitBoxSizing: 'border-box' as 'border-box', /* Safari/Chrome, other WebKit */ | ||
MozBoxSizing: 'border-box' as 'border-box', /* Firefox, other Gecko */ | ||
boxSizing: 'border-box' as 'border-box', /* Opera/IE 8+ */ | ||
// width: '100%', | ||
fontFamily: 'sans-serif', | ||
fontSize: '1rem', | ||
textAlign: 'center' as 'center', | ||
textDecoration: 'none' | ||
}, | ||
textarea: { | ||
|
||
}, | ||
|
||
errorBorder: { | ||
border: '2px solid red' | ||
}, | ||
error: { | ||
padding: '1rem 0 0 0' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters