Skip to content

Commit fce0e5b

Browse files
authored
Merge pull request #23 from user-interviews/feature/UIDS-22-form-group-description
UIDS-22 add description prop to FormGroup
2 parents 83478e5 + d5bf136 commit fce0e5b

File tree

4 files changed

+118
-6
lines changed

4 files changed

+118
-6
lines changed

spec/__snapshots__/Storyshots.test.js.snap

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ exports[`Storyshots Design System/Form Default 1`] = `
180180
type="text"
181181
/>
182182
<div
183-
className="invalid-feedback"
183+
className="FormGroup__invalid-feedback"
184184
>
185185
Invalid phone number
186186
</div>
@@ -286,6 +286,80 @@ exports[`Storyshots Design System/Form Group Required 1`] = `
286286
</div>
287287
`;
288288

289+
exports[`Storyshots Design System/Form Group With Description 1`] = `
290+
<div
291+
style={
292+
Object {
293+
"padding": "1rem",
294+
}
295+
}
296+
>
297+
<div
298+
className="FormGroup"
299+
id="with-description"
300+
>
301+
<label
302+
className="InputLabel"
303+
htmlFor="input"
304+
>
305+
Form Group with description
306+
</label>
307+
<input
308+
className="form-control"
309+
id="input"
310+
type="text"
311+
/>
312+
<div
313+
className="FormGroup__description"
314+
>
315+
test description
316+
</div>
317+
</div>
318+
</div>
319+
`;
320+
321+
exports[`Storyshots Design System/Form Group With Description And Errors 1`] = `
322+
<div
323+
style={
324+
Object {
325+
"padding": "1rem",
326+
}
327+
}
328+
>
329+
<div
330+
className="FormGroup FormGroup--is-invalid"
331+
id="with-description-and-errors"
332+
>
333+
<label
334+
className="InputLabel"
335+
htmlFor=""
336+
>
337+
Form Group with description and errors
338+
</label>
339+
<input
340+
className="form-control"
341+
type="text"
342+
/>
343+
<div
344+
className="FormGroup__invalid-feedback"
345+
>
346+
<ol
347+
className="FormGroup__invalid-feedback__list"
348+
>
349+
<li>
350+
invalid input!
351+
</li>
352+
</ol>
353+
</div>
354+
<div
355+
className="FormGroup__description"
356+
>
357+
test description
358+
</div>
359+
</div>
360+
</div>
361+
`;
362+
289363
exports[`Storyshots Design System/Form Group With Errors 1`] = `
290364
<div
291365
style={
@@ -309,10 +383,10 @@ exports[`Storyshots Design System/Form Group With Errors 1`] = `
309383
type="text"
310384
/>
311385
<div
312-
className="invalid-feedback"
386+
className="FormGroup__invalid-feedback"
313387
>
314388
<ol
315-
className="invalid-feedback__list"
389+
className="FormGroup__invalid-feedback__list"
316390
>
317391
<li>
318392
invalid input!

src/FormGroup/FormGroup.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function renderErrors(errors) {
1212
}
1313

1414
return (
15-
<ol className="invalid-feedback__list">
15+
<ol className="FormGroup__invalid-feedback__list">
1616
{
1717
// eslint-disable-next-line react/no-array-index-key
1818
errors.map((e, idx) => <li key={idx}>{e}</li>)
@@ -42,17 +42,26 @@ export default function FormGroup(props) {
4242
{props.children}
4343

4444
{props.displayErrorText && hasErrors && (
45-
<div className="invalid-feedback">
45+
<div className="FormGroup__invalid-feedback">
4646
{renderErrors(errors[inputKey])}
4747
</div>
4848
)}
49+
50+
{
51+
props.description && (
52+
<div className="FormGroup__description">
53+
{props.description}
54+
</div>
55+
)
56+
}
4957
</div>
5058
);
5159
}
5260

5361
FormGroup.propTypes = {
5462
children: PropTypes.node,
5563
className: PropTypes.string,
64+
description: PropTypes.string,
5665
displayErrorText: PropTypes.bool,
5766
errors: PropTypes.object,
5867
id: PropTypes.string.isRequired,
@@ -66,6 +75,7 @@ FormGroup.propTypes = {
6675
FormGroup.defaultProps = {
6776
children: undefined,
6877
className: '',
78+
description: undefined,
6979
displayErrorText: true,
7080
errors: {},
7181
inputKey: null,

src/FormGroup/FormGroup.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
}
1010
}
1111

12-
.invalid-feedback {
12+
&__description {
13+
padding: .25rem 0;
14+
}
15+
16+
&__invalid-feedback {
1317
color: $ux-red;
1418
display: block;
1519
font-size: 100%;

stories/FormGroup.stories.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export const WithLabel = () => (
3838
</FormGroup>
3939
);
4040

41+
export const WithDescription = () => (
42+
<FormGroup
43+
description="test description"
44+
id="with-description"
45+
label="Form Group with description"
46+
labelHtmlFor="input"
47+
>
48+
<input className="form-control" id="input" type="text" />
49+
</FormGroup>
50+
);
51+
4152
export const WithErrors = () => (
4253
<FormGroup
4354
displayErrorText
@@ -49,3 +60,16 @@ export const WithErrors = () => (
4960
<input className="form-control" type="text" />
5061
</FormGroup>
5162
);
63+
64+
export const WithDescriptionAndErrors = () => (
65+
<FormGroup
66+
description="test description"
67+
displayErrorText
68+
errors={{ test: ['invalid input!'] }}
69+
id="with-description-and-errors"
70+
inputKey="test"
71+
label="Form Group with description and errors"
72+
>
73+
<input className="form-control" type="text" />
74+
</FormGroup>
75+
);

0 commit comments

Comments
 (0)