forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Also fixes elastic#792: Moved bottom padding from help text to form row
- Loading branch information
cchaos
committed
May 7, 2018
1 parent
87fcdb2
commit 279f1a5
Showing
6 changed files
with
211 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiCheckboxGroup, | ||
EuiFieldText, | ||
EuiForm, | ||
EuiFormRow, | ||
EuiFilePicker, | ||
EuiRange, | ||
EuiSelect, | ||
EuiSwitch, | ||
EuiPanel, | ||
} 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 ( | ||
<EuiPanel style={{ maxWidth: 300 }}> | ||
<EuiForm compressed> | ||
<EuiFormRow | ||
label="Text field" | ||
helpText="I am some friendly help text." | ||
compressed | ||
> | ||
<EuiFieldText name="first" /> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="Select" | ||
compressed | ||
> | ||
<EuiSelect | ||
options={[ | ||
{ value: 'option_one', text: 'Option one' }, | ||
{ value: 'option_two', text: 'Option two' }, | ||
{ value: 'option_three', text: 'Option three' }, | ||
]} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="File picker" | ||
compressed | ||
> | ||
<EuiFilePicker /> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="Range" | ||
compressed | ||
> | ||
<EuiRange | ||
min={0} | ||
max={100} | ||
name="range" | ||
id="range" | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="Use a switch instead of a single checkbox" | ||
compressed | ||
> | ||
<EuiSwitch | ||
label="Should we do this?" | ||
name="switch" | ||
checked={this.state.isSwitchChecked} | ||
onChange={this.onSwitchChange} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow | ||
label="Checkboxes" | ||
compressed | ||
> | ||
<EuiCheckboxGroup | ||
options={this.state.checkboxes} | ||
idToSelectedMap={this.state.checkboxIdToSelectedMap} | ||
onChange={this.onCheckboxChange} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiButton type="submit" size="s" fill> | ||
Save form | ||
</EuiButton> | ||
</EuiForm> | ||
</EuiPanel> | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.euiFormErrorText { | ||
@include euiFontSizeXS; | ||
padding: $euiSizeS 0; | ||
padding-top: $euiSizeS; | ||
color: $euiColorDanger; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.euiFormHelpText { | ||
@include euiFontSizeXS; | ||
padding: $euiSizeS 0; | ||
padding-top: $euiSizeS; | ||
color: $euiColorDarkShade; | ||
} |
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