-
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.
Allow
EuiAccordion
state to be controlled from outside (#3240)
* Allow state to be controlled from outside * CL * snippet * prop definition * added test, snap * allowed state change from outside * changed prop name, used toggle buttons * left out changes * fixed all errors * updated Snap, Example description * example added * updated snippet * changed accordion title to more relevant * Update src-docs/src/views/accordion/accordion_example.js Co-Authored-By: Chandler Prall <chandler.prall@gmail.com> * Update src-docs/src/views/accordion/accordion_example.js Co-Authored-By: Chandler Prall <chandler.prall@gmail.com> * Update CHANGELOG.md Co-Authored-By: Chandler Prall <chandler.prall@gmail.com> * fixed prettier issue * fixed accessibility issues * fixed id problem Co-authored-by: Chandler Prall <chandler.prall@gmail.com>
- Loading branch information
1 parent
6f44f92
commit 60f885f
Showing
6 changed files
with
166 additions
and
11 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
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,54 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { | ||
EuiAccordion, | ||
EuiText, | ||
EuiButtonGroup, | ||
EuiSpacer, | ||
} from '../../../../src/components'; | ||
import { htmlIdGenerator } from '../../../../src/services'; | ||
|
||
const idPrefix = htmlIdGenerator()(); | ||
|
||
export default () => { | ||
const [trigger, setTrigger] = useState('closed'); | ||
const [toggleIdSelected, setID] = useState(`${idPrefix}--closed`); | ||
const toggleButtons = [ | ||
{ | ||
id: `${idPrefix}--open`, | ||
label: 'Open', | ||
}, | ||
{ | ||
id: `${idPrefix}--closed`, | ||
label: 'Close', | ||
}, | ||
]; | ||
|
||
const onChange = id => { | ||
setTrigger(id === toggleButtons[0].id ? 'open' : 'closed'); | ||
setID(id); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<EuiButtonGroup | ||
legend="This is a basic group" | ||
options={toggleButtons} | ||
idSelected={toggleIdSelected} | ||
onChange={onChange} | ||
/> | ||
<EuiSpacer /> | ||
<EuiAccordion | ||
id="accordion--forceState" | ||
forceState={trigger} | ||
buttonContent="I am controlled via prop"> | ||
<EuiText> | ||
<p> | ||
Any content inside of <strong>EuiAccordion</strong> will appear | ||
here. | ||
</p> | ||
</EuiText> | ||
</EuiAccordion> | ||
</div> | ||
); | ||
}; |
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