-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show all filters in a popover when clicking a button with total…
… filter count
- Loading branch information
1 parent
b2d7937
commit a01587e
Showing
6 changed files
with
185 additions
and
90 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
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,80 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { Layer, Popper } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React, { useMemo, useState, useRef } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { sGetNamedItemFilters } from '../../reducers/itemFilters.js' | ||
import styles from './styles/SlideshowFiltersInfo.module.css' | ||
|
||
const popperModifiers = [ | ||
{ | ||
name: 'offset', | ||
options: { | ||
offset: [0, 8], | ||
}, | ||
}, | ||
] | ||
const FilterSection = ({ name, values }) => ( | ||
<div className={styles.filterSection}> | ||
<h4 className={styles.filterSectionHeader}>{name}</h4> | ||
<ul className={styles.filterSectionList}> | ||
{values.map((value) => ( | ||
<li className={styles.filterSectionListItem} key={value.name}> | ||
{value.name} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
|
||
FilterSection.propTypes = { | ||
name: PropTypes.string, | ||
values: PropTypes.arrayOf(PropTypes.shape({ name: PropTypes.string })), | ||
} | ||
|
||
export const SlideshowFiltersInfo = () => { | ||
const [isOpen, setIsOpen] = useState(false) | ||
const ref = useRef(null) | ||
const filters = useSelector(sGetNamedItemFilters) | ||
const totalFilterCount = useMemo( | ||
() => | ||
filters.reduce((total, filter) => total + filter.values.length, 0), | ||
[filters] | ||
) | ||
|
||
if (filters.length === 0) { | ||
return null | ||
} | ||
|
||
return ( | ||
<> | ||
<button | ||
ref={ref} | ||
className={styles.filterButton} | ||
onClick={() => setIsOpen(true)} | ||
> | ||
{i18n.t('{{totalFilterCount}} filters active', { | ||
totalFilterCount, | ||
})} | ||
</button> | ||
{isOpen && ( | ||
<Layer disablePortal onClick={() => setIsOpen(false)}> | ||
<Popper | ||
className={styles.popover} | ||
reference={ref} | ||
placement="top-end" | ||
modifiers={popperModifiers} | ||
> | ||
{filters.map((filter) => ( | ||
<FilterSection | ||
key={filter.name} | ||
name={filter.name} | ||
values={filter.values} | ||
/> | ||
))} | ||
</Popper> | ||
</Layer> | ||
)} | ||
</> | ||
) | ||
} |
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,30 @@ | ||
.filterButton { | ||
padding: 4px; | ||
inline-size: auto; | ||
border-radius: 3px; | ||
color: black; | ||
background-color: #f4f6f8; | ||
} | ||
|
||
.popover { | ||
border: 1px solid var(--colors-grey400); | ||
border-radius: 4px; | ||
box-shadow: var(--elevations-e400); | ||
padding: var(--spacers-dp8); | ||
background-color: var(--colors-white); | ||
} | ||
|
||
.filterSection { | ||
margin-block-end: var(--spacers-dp4); | ||
} | ||
|
||
.filterSectionHeader { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.filterSectionList { | ||
margin: 0; | ||
padding: 0; | ||
padding-inline-start: 18px; | ||
} |