-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1093 from cozy/feat/dualfield
feat: Add InputGroup component
- Loading branch information
Showing
9 changed files
with
246 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
### InputGroup with an appended text | ||
|
||
``` | ||
const { Bold } = require('../Text'); | ||
const Input = require('../Input').default; | ||
<form> | ||
<div> | ||
<InputGroup append={<Bold className="u-pr-1">text</Bold>}> | ||
<Input placeholder="Placeholder" /> | ||
</InputGroup> | ||
</div> | ||
</form> | ||
``` | ||
|
||
### InputGroup with a prepended text | ||
|
||
``` | ||
const { Bold } = require('../Text'); | ||
const Input = require('../Input').default; | ||
<form> | ||
<div> | ||
<InputGroup prepend={<Bold className="u-pl-1">text</Bold>}> | ||
<Input placeholder="Placeholder" /> | ||
</InputGroup> | ||
</div> | ||
</form> | ||
``` | ||
|
||
### InputGroup with an appended input | ||
|
||
You will need to set a width to the side component, with a utility class for example. | ||
|
||
``` | ||
const Input = require('../Input').default; | ||
<form> | ||
<div> | ||
<InputGroup append={<Input placeholder="@domain.tld" className="u-w-4"/>}> | ||
<Input placeholder="Email" /> | ||
</InputGroup> | ||
</div> | ||
</form> | ||
``` | ||
|
||
### InputGroup with an appended select | ||
|
||
You will need to set a width to the side component, with a utility class for example. | ||
|
||
``` | ||
const SelectBox = require('../SelectBox').default; | ||
const options = [ | ||
{ value: 'cozy.io', label: '.cozy.io' }, | ||
{ value: 'cozycloud.cc', label: '.cozycloud.cc' } | ||
]; | ||
<form> | ||
<div> | ||
<InputGroup append={<SelectBox inset options={options} className="u-w-4" />}> | ||
<Input placeholder="URL" /> | ||
</InputGroup> | ||
</div> | ||
</form> | ||
``` | ||
|
||
### Full width InputGroup with an appended text | ||
|
||
``` | ||
const { Bold } = require('../Text'); | ||
const Input = require('../Input').default; | ||
<form> | ||
<div> | ||
<InputGroup fullwidth append={<Bold className="u-pr-1">text</Bold>}> | ||
<Input placeholder="Placeholder" /> | ||
</InputGroup> | ||
</div> | ||
</form> | ||
``` | ||
|
||
### Errored InputGroup with an appended text | ||
|
||
``` | ||
const { Bold } = require('../Text'); | ||
const Input = require('../Input').default; | ||
<form> | ||
<div> | ||
<InputGroup error append={<Bold className="u-pr-1">text</Bold>}> | ||
<Input placeholder="Placeholder" /> | ||
</InputGroup> | ||
</div> | ||
</form> | ||
``` |
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,57 @@ | ||
import React, { Component } from 'react' | ||
import cx from 'classnames' | ||
import PropTypes from 'prop-types' | ||
import styles from './styles.styl' | ||
|
||
class InputGroup extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.handleFocus = this.handleFocus.bind(this) | ||
this.handleBlur = this.handleBlur.bind(this) | ||
this.state = { | ||
focused: false | ||
} | ||
} | ||
|
||
handleFocus() { | ||
this.setState({ focused: true }) | ||
} | ||
|
||
handleBlur() { | ||
this.setState({ focused: false }) | ||
} | ||
|
||
render() { | ||
const { children, prepend, append, error, fullwidth } = this.props | ||
const { focused } = this.state | ||
return ( | ||
<div | ||
className={cx(styles['c-inputgroup'], { | ||
[styles['c-inputgroup--error']]: error, | ||
[styles['c-inputgroup--fullwidth']]: fullwidth, | ||
[styles['c-inputgroup--focus']]: focused | ||
})} | ||
> | ||
{prepend && ( | ||
<div className={styles['c-inputgroup-side']}>{prepend}</div> | ||
)} | ||
<div className={styles['c-inputgroup-main']}>{children}</div> | ||
{append && <div className={styles['c-inputgroup-side']}>{append}</div>} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
InputGroup.propTypes = { | ||
prepend: PropTypes.object, | ||
append: PropTypes.object, | ||
error: PropTypes.bool, | ||
fullwidth: PropTypes.bool | ||
} | ||
|
||
InputGroup.defaultProps = { | ||
error: false, | ||
fullwidth: false | ||
} | ||
|
||
export default InputGroup |
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,22 @@ | ||
@require '../../stylus/components/forms' | ||
|
||
.c-inputgroup | ||
@extend $inputgroup | ||
|
||
input | ||
@extend $inputgroup-input | ||
|
||
.c-inputgroup--focus | ||
@extend $inputgroup--focus | ||
|
||
.c-inputgroup--error | ||
@extend $inputgroup--error | ||
|
||
.c-inputgroup--fullwidth | ||
@extend $inputgroup--fullwidth | ||
|
||
.c-inputgroup-main | ||
@extend $inputgroup-main | ||
|
||
.c-inputgroup-side | ||
@extend $inputgroup-side |
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
Oops, something went wrong.