Skip to content

Commit 3ad83e2

Browse files
committed
New textarea component added.
Example of textarea added in app.js
1 parent da2e7df commit 3ad83e2

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

src/App.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
.control-error {
1616
border: 1px solid red;
1717
}
18-
.error-text {
19-
color: red;
20-
}
2118

2219
.form-group label,
2320
.form-group .info-text {
@@ -31,6 +28,10 @@
3128
margin-top: 4px;
3229
}
3330

31+
.form-group .error-text {
32+
color: red;
33+
}
34+
3435
.btn-submit {
3536
margin: 20px 0;
3637
padding: 8px 14px;

src/App.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22
import './App.css';
3-
import { TextInput } from './utils/form_helpers';
3+
import { TextInput, TextArea } from './utils/form_helpers';
44
import Validation, { Validate } from './utils/form_helpers/Validation';
55
import { inputType } from './utils/Constants';
66
import { onChangeHandler } from './utils/form_helpers/FormMethods';
@@ -74,6 +74,20 @@ class App extends Component {
7474
message: "Password is required"
7575
}
7676
]
77+
},
78+
summary: {
79+
value: '',
80+
placeholder: 'Enter summary',
81+
rows: 5,
82+
valid: false,
83+
touched: false,
84+
errorMessage: "",
85+
validationRules: [
86+
{
87+
validate: Validation.isRequired,
88+
message: "Summary is required"
89+
}
90+
]
7791
}
7892
}
7993
}
@@ -135,6 +149,19 @@ class App extends Component {
135149
touched={this.state.formControls.password.touched}
136150
valid={this.state.formControls.password.valid}
137151
/>
152+
153+
<TextArea
154+
label="Summary"
155+
name="summary"
156+
placeholder={this.state.formControls.summary.placeholder}
157+
// helpText="summary"
158+
errorMessage={this.state.formControls.summary.errorMessage}
159+
value={this.state.formControls.summary.value}
160+
rows={this.state.formControls.summary.rows}
161+
onChange={onChangeHandler(this)}
162+
touched={this.state.formControls.summary.touched}
163+
valid={this.state.formControls.summary.valid}
164+
/>
138165
<button type="submit" className="btn-submit" disabled={!this.state.formIsValid}> Submit </button>
139166
</form>
140167
</div>

src/utils/form_helpers/TextArea.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
3+
const TextArea = ({
4+
touched,
5+
valid,
6+
label,
7+
value,
8+
errorMessage,
9+
helpText,
10+
...props
11+
}) => {
12+
let formControl = "form-control";
13+
14+
if (touched && !valid) {
15+
formControl = "form-control control-error";
16+
}
17+
return (
18+
<div className="form-group">
19+
<label htmlFor={props.name}>{label}</label>
20+
<textarea className={formControl} id={props.name} {...props} >
21+
{value}
22+
</textarea>
23+
{/* Help text or Error */}
24+
<div className={errorMessage ? "info-text error-text" : "info-text"}>{errorMessage ? errorMessage : helpText}</div>
25+
</div>
26+
);
27+
}
28+
29+
export default TextArea;

src/utils/form_helpers/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { default as TextInput } from "./TextInput";
1+
export { default as TextInput } from "./TextInput";
2+
export { default as TextArea } from "./TextArea";

0 commit comments

Comments
 (0)