-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added EuiFormFieldset
and EuiFormLegend
components
#2706
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ece87b0
Moved form label font styles to a mixin
4180a1c
Added `EuiFormFieldset` and `EuiFormLegend` components
a672d3c
Add snippet
230676e
Revert accidental commit of radio group doc example
8e728bb
cl
9ceeb1d
Merge branch 'master' into form-fieldset-and-legend
cchaos c838123
Remove unecessary omit and update tests to include children
e0938ef
Merge branch 'master' into form-fieldset-and-legend
cchaos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ | ||
import React from 'react'; | ||
|
||
import { EuiFormFieldset } from '../../../../src/components/form/form_fieldset'; | ||
import { EuiSwitch } from '../../../../src/components/form/switch'; | ||
import { EuiSpacer } from '../../../../src/components/spacer'; | ||
|
||
export default () => ( | ||
<EuiFormFieldset legend={{ children: 'Enable these objects' }}> | ||
<EuiSwitch label="Object 1" onChange={() => {}} checked={false} /> | ||
<EuiSpacer size="s" /> | ||
<EuiSwitch label="Object 2" onChange={() => {}} checked={true} /> | ||
</EuiFormFieldset> | ||
); |
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
22 changes: 22 additions & 0 deletions
22
src/components/form/form_fieldset/__snapshots__/form_fieldset.test.tsx.snap
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiFormFieldset is rendered 1`] = ` | ||
<fieldset | ||
aria-label="aria-label" | ||
class="testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
> | ||
<input /> | ||
</fieldset> | ||
`; | ||
|
||
exports[`EuiFormFieldset props legend is rendered 1`] = ` | ||
<fieldset> | ||
<legend | ||
class="euiFormLegend" | ||
> | ||
Legend | ||
</legend> | ||
<input /> | ||
</fieldset> | ||
`; |
31 changes: 31 additions & 0 deletions
31
src/components/form/form_fieldset/__snapshots__/form_legend.test.tsx.snap
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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiFormLegend is rendered 1`] = ` | ||
<legend | ||
aria-label="aria-label" | ||
class="euiFormLegend testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
> | ||
Legend | ||
</legend> | ||
`; | ||
|
||
exports[`EuiFormLegend props compressed is rendered 1`] = ` | ||
<legend | ||
class="euiFormLegend euiFormLegend--compressed" | ||
> | ||
Legend | ||
</legend> | ||
`; | ||
|
||
exports[`EuiFormLegend props hidden is rendered 1`] = ` | ||
<legend | ||
class="euiFormLegend euiFormLegend-isHidden" | ||
> | ||
<span | ||
class="euiScreenReaderOnly" | ||
> | ||
Legend | ||
</span> | ||
</legend> | ||
`; |
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,11 @@ | ||
.euiFormLegend { | ||
@include euiFormLabel; | ||
|
||
&:not(.euiFormLegend-isHidden) { | ||
margin-bottom: $euiSizeS; | ||
|
||
&.euiFormLegend--compressed { | ||
margin-bottom: $euiSizeXS; | ||
} | ||
} | ||
} |
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 @@ | ||
@import 'form_legend'; |
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,29 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../../test/required_props'; | ||
|
||
import { EuiFormFieldset } from './form_fieldset'; | ||
|
||
describe('EuiFormFieldset', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiFormFieldset {...requiredProps}> | ||
<input /> | ||
</EuiFormFieldset> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
describe('props', () => { | ||
test('legend is rendered', () => { | ||
const component = render( | ||
<EuiFormFieldset legend={{ children: 'Legend' }}> | ||
<input /> | ||
</EuiFormFieldset> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,28 @@ | ||
import React, { HTMLAttributes, FunctionComponent } from 'react'; | ||
import { CommonProps } from '../../common'; | ||
import { EuiFormLegendProps, EuiFormLegend } from './form_legend'; | ||
|
||
export interface EuiFormFieldsetProps | ||
extends CommonProps, | ||
HTMLAttributes<HTMLFieldSetElement> { | ||
/** | ||
* Adds an EuiFormLegend element as the first child | ||
*/ | ||
legend?: EuiFormLegendProps; | ||
} | ||
|
||
export const EuiFormFieldset: FunctionComponent<EuiFormFieldsetProps> = ({ | ||
children, | ||
className, | ||
legend, | ||
...rest | ||
}) => { | ||
const legendDisplay = !!legend && <EuiFormLegend {...legend} />; | ||
|
||
return ( | ||
<fieldset className={className} {...rest}> | ||
{legendDisplay} | ||
{children} | ||
</fieldset> | ||
); | ||
}; |
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,33 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../../test/required_props'; | ||
|
||
import { EuiFormLegend } from './form_legend'; | ||
|
||
describe('EuiFormLegend', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiFormLegend {...requiredProps}>Legend</EuiFormLegend> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
describe('props', () => { | ||
test('hidden is rendered', () => { | ||
const component = render( | ||
<EuiFormLegend display="hidden">Legend</EuiFormLegend> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('compressed is rendered', () => { | ||
const component = render( | ||
<EuiFormLegend compressed>Legend</EuiFormLegend> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,44 @@ | ||
import React, { HTMLAttributes, FunctionComponent, ReactNode } from 'react'; | ||
import { CommonProps } from '../../common'; | ||
import classNames from 'classnames'; | ||
import { EuiScreenReaderOnly } from '../../accessibility'; | ||
|
||
export type EuiFormLegendProps = HTMLAttributes<HTMLLegendElement> & | ||
CommonProps & { | ||
children: ReactNode; | ||
/** | ||
* For a hidden legend that is still visible to the screen reader, set to 'hidden' | ||
*/ | ||
display?: 'hidden' | 'visible'; | ||
compressed?: boolean; | ||
}; | ||
|
||
export const EuiFormLegend: FunctionComponent<EuiFormLegendProps> = ({ | ||
children, | ||
className, | ||
display = 'visible', | ||
compressed, | ||
...rest | ||
}) => { | ||
const isLegendHidden = display === 'hidden'; | ||
const classes = classNames( | ||
'euiFormLegend', | ||
{ | ||
'euiFormLegend-isHidden': isLegendHidden, | ||
'euiFormLegend--compressed': compressed, | ||
}, | ||
className | ||
); | ||
|
||
return ( | ||
<legend className={classes} {...rest}> | ||
{isLegendHidden ? ( | ||
<EuiScreenReaderOnly> | ||
<span>{children}</span> | ||
</EuiScreenReaderOnly> | ||
) : ( | ||
children | ||
)} | ||
</legend> | ||
); | ||
}; |
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,2 @@ | ||
export { EuiFormFieldset, EuiFormFieldsetProps } from './form_fieldset'; | ||
export { EuiFormLegend, EuiFormLegendProps } from './form_legend'; |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these tests should provide
children
as well so the snapshot can help catch any regression there.