-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EuiDescribedFormGroup component (#707)
* Add new EuiDescriptiveFormRow component * Change component to display arbitrary number of form row * Rename text prop to description, add paddingSize, wrap title and description in EuiText * Rename to EuiDescribedFormGroup, change to EuiTitle with titleSize prop, adjust aria, update tests
- Loading branch information
Showing
17 changed files
with
925 additions
and
4 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
175 changes: 175 additions & 0 deletions
175
src-docs/src/views/form_layouts/described_form_group.js
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,175 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiCode, | ||
EuiFieldText, | ||
EuiForm, | ||
EuiFormRow, | ||
EuiDescribedFormGroup, | ||
EuiFilePicker, | ||
EuiRange, | ||
EuiSelect, | ||
EuiSwitch, | ||
} from '../../../../src/components'; | ||
|
||
import makeId from '../../../../src/components/form/form_row/make_id'; | ||
|
||
export default class extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const idPrefix = makeId(); | ||
|
||
this.state = { | ||
isSwitchChecked: false, | ||
checkboxes: [{ | ||
id: `${idPrefix}0`, | ||
label: 'Option one', | ||
}, { | ||
id: `${idPrefix}1`, | ||
label: 'Option two is checked by default', | ||
}, { | ||
id: `${idPrefix}2`, | ||
label: 'Option three', | ||
}], | ||
checkboxIdToSelectedMap: { | ||
[`${idPrefix}1`]: true, | ||
}, | ||
radios: [{ | ||
id: `${idPrefix}4`, | ||
label: 'Option one', | ||
}, { | ||
id: `${idPrefix}5`, | ||
label: 'Option two is selected by default', | ||
}, { | ||
id: `${idPrefix}6`, | ||
label: 'Option three', | ||
}], | ||
radioIdSelected: `${idPrefix}5`, | ||
}; | ||
} | ||
|
||
onSwitchChange = () => { | ||
this.setState({ | ||
isSwitchChecked: !this.state.isSwitchChecked, | ||
}); | ||
} | ||
|
||
onCheckboxChange = optionId => { | ||
const newCheckboxIdToSelectedMap = ({ ...this.state.checkboxIdToSelectedMap, ...{ | ||
[optionId]: !this.state.checkboxIdToSelectedMap[optionId], | ||
} }); | ||
|
||
this.setState({ | ||
checkboxIdToSelectedMap: newCheckboxIdToSelectedMap, | ||
}); | ||
} | ||
|
||
onRadioChange = optionId => { | ||
this.setState({ | ||
radioIdSelected: optionId, | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<EuiForm> | ||
<EuiDescribedFormGroup | ||
idAria="single-example-aria" | ||
title={<h3>Single text field</h3>} | ||
description={ | ||
<span> | ||
When using this with a single form row where this text serves as the help text for the input, | ||
it is a good idea to pass <EuiCode>idAria="someID"</EuiCode> to the form group and pass | ||
<EuiCode>describedByIds={[someID]}</EuiCode> to its form row. | ||
</span> | ||
} | ||
> | ||
<EuiFormRow | ||
label="Text field" | ||
describedByIds={['single-example-aria']} | ||
> | ||
<EuiFieldText name="first" /> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
|
||
<EuiDescribedFormGroup | ||
title={<strong>Multiple fields</strong>} | ||
titleSize="m" | ||
description="Here are three form rows. The first form row does not have a title." | ||
> | ||
<EuiFormRow | ||
hasEmptyLabelSpace | ||
helpText={ | ||
<span> | ||
We do not pass <EuiCode>describedByIds</EuiCode> when there are multiple form rows. | ||
</span> | ||
} | ||
> | ||
<EuiSelect | ||
hasNoInitialSelection | ||
options={[ | ||
{ value: 'option_one', text: 'Option one' }, | ||
{ value: 'option_two', text: 'Option two' }, | ||
{ value: 'option_three', text: 'Option three' }, | ||
]} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="File picker" | ||
> | ||
<EuiFilePicker /> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="Range" | ||
> | ||
<EuiRange | ||
min={0} | ||
max={100} | ||
name="range" | ||
id="range" | ||
/> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
|
||
<EuiDescribedFormGroup | ||
title={<h2>Full width</h2>} | ||
titleSize="xxxs" | ||
description={ | ||
<span> | ||
By default, <EuiCode>EuiDescribedFormGroup</EuiCode> will be double the default width of form elements. | ||
However, you can pass <EuiCode>fullWidth</EuiCode> prop to this, the individual field and row components | ||
to expand to their container. | ||
</span> | ||
} | ||
fullWidth | ||
> | ||
<EuiFormRow | ||
label="Use a switch instead of a single checkbox" | ||
fullWidth | ||
> | ||
<EuiSwitch | ||
name="switch" | ||
label="Should we do this?" | ||
checked={this.state.isSwitchChecked} | ||
onChange={this.onSwitchChange} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow fullWidth> | ||
<EuiFieldText name="second" fullWidth /> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
|
||
<EuiButton type="submit" fill> | ||
Save form | ||
</EuiButton> | ||
</EuiForm> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.