Skip to content

Commit 991ae72

Browse files
authored
noMargin prop for FormGroup (#1261)
1 parent 6a81f7d commit 991ae72

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

scss/forms/form_group.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
}
5555
}
5656

57+
&--no-margin {
58+
margin: 0;
59+
}
60+
5761
&__helper-text {
5862
@include synth-font-type-20;
5963
color: var(--ux-gray-900);

src/FormGroup/FormGroup.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ be beneficial to the user
4242

4343
<Canvas of={ComponentStories.Required} />
4444

45+
### No margin
46+
47+
- Remove the default margin on the FormGroup.
48+
49+
<Canvas of={ComponentStories.NoMargin} />
50+
4551
### With Label Tooltip
4652

4753
- Information users will typically only reference once (and then it's learned) or here and there.

src/FormGroup/FormGroup.stories.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { faSearch } from '@fortawesome/pro-solid-svg-icons';
33

4+
import { FlexContainer } from 'src/FlexContainer';
45
import FormGroup from '.';
56
import Input from '../Input';
67
import FormControlLabel from '../FormControlLabel';
@@ -56,6 +57,27 @@ export const Required = () => (
5657
</FormGroup>
5758
);
5859

60+
export const NoMargin = () => (
61+
<FlexContainer flexDirection="column" gap={4}>
62+
<FormGroup
63+
label="Label"
64+
labelHtmlFor="no-margin-1-input"
65+
noMargin
66+
required
67+
>
68+
<InputComponent id="no-margin-1-input" placeholder="This FormGroup has no default margin" />
69+
</FormGroup>
70+
<FormGroup
71+
label="Label"
72+
labelHtmlFor="no-margin-2-input"
73+
noMargin
74+
required
75+
>
76+
<InputComponent id="no-margin-2-input" placeholder="This FormGroup has no default margin" />
77+
</FormGroup>
78+
</FlexContainer>
79+
);
80+
5981
export const WithLabelTooltip = () => (
6082
<FormGroup
6183
id="with-label"

src/FormGroup/FormGroup.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export type FormGroupProps = {
5757
labelHelperText?: string;
5858
labelHtmlFor?: string;
5959
labelTooltip?: React.ReactNode;
60+
noMargin?: boolean;
6061
required?: boolean;
6162
};
6263

@@ -76,6 +77,7 @@ export default function FormGroup({
7677
labelHelperText,
7778
labelHtmlFor = '',
7879
labelTooltip,
80+
noMargin,
7981
required,
8082
}: FormGroupProps) {
8183
const errorMessage = buildErrorMessage(errors[inputKey || ''], label);
@@ -137,6 +139,7 @@ export default function FormGroup({
137139
'FormGroup--is-invalid': hasErrors,
138140
'FormGroup--bordered': bordered,
139141
'FormGroup--inline': inline,
142+
'FormGroup--no-margin': noMargin,
140143
},
141144
),
142145
id,

0 commit comments

Comments
 (0)