Skip to content

Commit

Permalink
Allow multiline mode for input with type text.
Browse files Browse the repository at this point in the history
This adds a toggle react component which can be used to change text input to textarea and vice versa.
  • Loading branch information
Anupam-dagar committed Dec 10, 2018
1 parent 9cbbac9 commit 016a737
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions console/src/components/Common/Common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ table thead tr th
color: #4D4D4D;
font-weight: 600 !important;
}

.textareaNoResize {
resize: none;
}

.textareaButtonAlign {
margin-top: -8em !important;
}

.pageSidebar {
height: calc(100vh - 50px);
overflow: auto;
Expand Down
68 changes: 68 additions & 0 deletions console/src/components/Common/Toggler/Toggler.js
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;
10 changes: 10 additions & 0 deletions console/src/components/Services/Data/TableInsertItem/InsertItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TableHeader from '../TableCommon/TableHeader';
import { insertItem, I_RESET } from './InsertActions';
import { ordinalColSort } from '../utils';
import { setTable } from '../DataActions';
import Toggler from '../../../Common/Toggler/Toggler';

class InsertItem extends Component {
constructor() {
Expand Down Expand Up @@ -149,6 +150,15 @@ class InsertItem extends Component {
);
}

if (colType === 'text') {
typedInput = (
<Toggler
standardProps={standardInputProps}
placeholderProp={getPlaceholder(colType)}
/>
);
}

if (colType === 'json' || colType === 'jsonb') {
// JSON/JSONB
typedInput = (
Expand Down

0 comments on commit 016a737

Please sign in to comment.