-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiline mode for input with type text.
This adds a toggle react component which can be used to change text input to textarea and vice versa.
- Loading branch information
1 parent
9cbbac9
commit 016a737
Showing
3 changed files
with
87 additions
and
0 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,68 @@ | ||
import React, { Component } from 'react'; | ||
|
||
const styles = require('../Common.scss'); | ||
|
||
class Toggler extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
input_textarea: 0, | ||
input_value: '', | ||
}; | ||
|
||
this.handleClick = this.handleClick.bind(this); | ||
this.handleChange = this.handleChange.bind(this); | ||
} | ||
|
||
handleClick(e) { | ||
e.preventDefault(); | ||
const stateValue = this.state.input_textarea; | ||
if (stateValue === 0) { | ||
this.setState({ input_textarea: 1 }); | ||
} else { | ||
this.setState({ input_textarea: 0 }); | ||
} | ||
} | ||
|
||
handleChange(e) { | ||
const inputVal = e.target.value; | ||
this.setState({ input_value: inputVal }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<span> | ||
<label> | ||
{this.state.input_textarea === 1 ? ( | ||
<textarea | ||
{...this.props.standardProps} | ||
placeholder={this.props.placeholderProp} | ||
rows="5" | ||
cols="5" | ||
/> | ||
) : ( | ||
<input | ||
{...this.props.standardProps} | ||
placeholder={this.props.placeholderProp} | ||
/> | ||
)} | ||
</label> | ||
<button | ||
className={ | ||
'btn ' + | ||
styles.yellow_button + | ||
(this.state.input_textarea === 1 | ||
? ' ' + styles.textareaButtonAlign | ||
: '') | ||
} | ||
onClick={this.handleClick} | ||
> | ||
Toggle | ||
</button> | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
export default Toggler; |
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