-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic Input component wrapper. (#204)
* Add basic Input component wrapper. Fixes #202 * Fix version bump
- Loading branch information
1 parent
9c190fe
commit 4bd0a01
Showing
12 changed files
with
186 additions
and
3 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,9 @@ | ||
# \<Input\> | ||
|
||
### Input component is a thin wrapper around an HTML input element | ||
|
||
The basic `<Input />` doesn't add any behavior to the HTML element, it just adds styles. | ||
|
||
It also provides 1 custom prop | ||
|
||
- _fauxDisabled_: Applies the same style as disabled, but, unlike the real thing, doesn't stop click events. Useful for adding tooltips or other helpful behavior when a user tries to interact with a disabled field. |
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,26 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import styles from './style.css'; | ||
|
||
const Input = ({ className, fauxDisabled, ...passedProps }) => ( | ||
<input | ||
className={classNames(styles.Input, className, { | ||
[styles.disabled]: fauxDisabled, | ||
})} | ||
{...passedProps} | ||
/> | ||
); | ||
|
||
Input.propTypes = { | ||
className: PropTypes.string, | ||
/** Applies disabled appearance without disabling. Helpful for adding tooltips on disabled field clicks. */ | ||
fauxDisabled: PropTypes.bool, | ||
}; | ||
|
||
Input.defaultProps = { | ||
className: '', | ||
fauxDisabled: false, | ||
}; | ||
|
||
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,62 @@ | ||
import React, { useState } from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { boolean, text } from '@storybook/addon-knobs'; | ||
|
||
import Input from './'; | ||
import Readme from './README.md'; | ||
|
||
const InteractiveInput = props => { | ||
const [value, setValue] = useState(''); | ||
|
||
return ( | ||
<Input {...props} onChange={e => setValue(e.target.value)} value={value} /> | ||
); | ||
}; | ||
|
||
storiesOf('Planets/Input', module) | ||
.addParameters({ | ||
readme: { | ||
sidebar: Readme, | ||
}, | ||
}) | ||
.add( | ||
'Overview', | ||
() => ( | ||
<Input | ||
disabled={boolean('disabled (HTML)', false)} | ||
fauxDisabled={boolean('fauxDisabled', false)} | ||
onChange={action('onChange (HTML)')} | ||
placeholder={text('placeholder(HTML)', 'Placeholder')} | ||
value={text('value (HTML)', '')} | ||
pattern={text('pattern (HTML)', '.*')} | ||
type={text('type (HTML)', '')} | ||
/> | ||
), | ||
{ | ||
info: { | ||
inline: true, | ||
source: true, | ||
}, | ||
} | ||
) | ||
.add( | ||
'Examples', | ||
() => ( | ||
<div> | ||
<InteractiveInput placeholder="Type here" /> | ||
<br /> | ||
<br /> | ||
<Input disabled value="Disabled" /> | ||
<br /> | ||
<br /> | ||
<Input pattern="" value="Invalid" /> | ||
</div> | ||
), | ||
{ | ||
info: { | ||
inline: false, | ||
source: true, | ||
}, | ||
} | ||
); |
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,61 @@ | ||
.Input { | ||
background-color: var(--rvr-white); | ||
border-radius: var(--rvr-border-radius); | ||
border: var(--rvr-border-width-md) solid var(--rvr-gray-60); | ||
color: var(--rvr-gray-90); | ||
font-family: var(--rvr-base-font-family); | ||
line-height: var(--rvr-line-height-lg); | ||
padding: var(--rvr-space-bordered-sm); | ||
transition: | ||
100ms linear background-color, | ||
100ms linear border-color, | ||
100ms linear box-shadow, | ||
100ms linear color; | ||
} | ||
|
||
.Input::placeholder { | ||
color: var(--rvr-gray-60); | ||
} | ||
|
||
.Input:hover { | ||
background-color: var(--rvr-gray-10); | ||
border-color: var(--rvr-gray-80); | ||
} | ||
|
||
.Input:hover::placeholder { | ||
color: var(--rvr-gray-80); | ||
} | ||
|
||
.Input:focus { | ||
border-color: var(--rvr-color-primary); | ||
box-shadow: 0 0 4px var(--rvr-color-primary); | ||
outline: 0 none; | ||
} | ||
|
||
.Input:active { | ||
background-color: var(--rvr-gray-10); | ||
border-color: var(--rvr-gray-80); | ||
} | ||
|
||
.Input:active::placeholder { | ||
color: var(--rvr-gray-80); | ||
} | ||
|
||
.Input:disabled, | ||
.Input.disabled { | ||
border-color: var(--rvr-gray-40); | ||
color: var(--rvr-gray-40); | ||
cursor: default; | ||
} | ||
|
||
.Input:disabled::placeholder, | ||
.Input.disabled::placeholder { | ||
color: var(--rvr-gray-60); | ||
} | ||
|
||
.Input:invalid, | ||
.Input.invalid { | ||
background-color: var(--rvr-color-danger-lite); | ||
border-color: var(--rvr-color-danger); | ||
color: var(--rvr-color-danger); | ||
} |
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 React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Input from './'; | ||
|
||
describe('Input', () => { | ||
it('renders', () => { | ||
shallow(<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
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