-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved form label font styles to a mixin * Added `EuiFormFieldset` and `EuiFormLegend` components * Remove unecessary omit and update tests to include children
- Loading branch information
Showing
17 changed files
with
289 additions
and
3 deletions.
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