Skip to content
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

[Docs] filter_group_multi: update multi select example to be functional #4178

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src-docs/src/views/filter_group/filter_group_multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default () => {
setIsPopoverOpen(false);
};

const items = [
const [items, setItems] = useState([
{ name: 'Johann Sebastian Bach', checked: 'on' },
{ name: 'Wolfgang Amadeus Mozart', checked: 'on' },
{ name: 'Antonín Dvořák', checked: 'off' },
Expand All @@ -43,16 +43,39 @@ export default () => {
{ name: 'Robert Schumann' },
{ name: 'Sergej S. Prokofiew' },
{ name: 'Wolfgang Amadeus Mozart' },
];
]);

function updateItem(index) {
if (!items[index]) {
return;
}

const newItems = [...items];

switch (newItems[index].checked) {
case 'on':
newItems[index].checked = 'off';
break;

case 'off':
newItems[index].checked = undefined;
break;

default:
newItems[index].checked = 'on';
}

setItems(newItems);
}

const button = (
<EuiFilterButton
iconType="arrowDown"
onClick={onButtonClick}
isSelected={isPopoverOpen}
numFilters={items.length}
hasActiveFilters={true}
numActiveFilters={2}>
hasActiveFilters={!!items.find((item) => item.checked === 'on')}
numActiveFilters={items.filter((item) => item.checked === 'on').length}>
Composers
</EuiFilterButton>
);
Expand All @@ -71,7 +94,10 @@ export default () => {
</EuiPopoverTitle>
<div className="euiFilterSelect__items">
{items.map((item, index) => (
<EuiFilterSelectItem checked={item.checked} key={index}>
<EuiFilterSelectItem
checked={item.checked}
key={index}
onClick={() => updateItem(index)}>
{item.name}
</EuiFilterSelectItem>
))}
Expand Down