Skip to content

Commit

Permalink
Add an expanded classname to the facet container (#114)
Browse files Browse the repository at this point in the history
* Add expanded class so we can apply styles

* Lint fix

* Prop to preserve facet items when not expanded

* Formatting
  • Loading branch information
jonkafton authored Jun 25, 2024
1 parent 3b4d0ec commit ed4f12d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/facet_display/Facet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@ interface Props {
selected: string[]
onUpdate: React.ChangeEventHandler<HTMLInputElement>
expandedOnLoad: boolean
preserveItems?: boolean
}

function SearchFacet(props: Props) {
const { name, title, results, selected, onUpdate, expandedOnLoad } = props
const {
name,
title,
results,
selected,
onUpdate,
expandedOnLoad,
preserveItems
} = props

const [showFacetList, setShowFacetList] = useState(expandedOnLoad)
const [showAllFacets, setShowAllFacets] = useState(false)

const titleLineIcon = showFacetList ? "expand_less" : "expand_more"

return results && results.length === 0 ? null : (
<div className="facets base-facet">
<div
className={`facets base-facet${showFacetList ? " facets-expanded" : ""}`}
>
<button
className="filter-section-button"
type="button"
Expand All @@ -37,7 +48,7 @@ function SearchFacet(props: Props) {
{titleLineIcon}
</i>
</button>
{showFacetList ? (
{showFacetList || preserveItems ? (
<>
{results ?
results.map((bucket, i) =>
Expand Down
2 changes: 2 additions & 0 deletions src/facet_display/FacetDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const AvailableFacets: React.FC<Omit<FacetDisplayProps, "clearAllFilters">> = ({
}
selected={activeFacets[facetSettings.name] || []}
expandedOnLoad={facetSettings.expandedOnLoad}
preserveItems={facetSettings.preserveItems}
/>
)
} else if (facetSettings.type === "filterable") {
Expand All @@ -146,6 +147,7 @@ const AvailableFacets: React.FC<Omit<FacetDisplayProps, "clearAllFilters">> = ({
}
selected={activeFacets[facetSettings.name] || []}
expandedOnLoad={facetSettings.expandedOnLoad}
preserveItems={facetSettings.preserveItems}
/>
)
} else if (facetSettings.type === "group") {
Expand Down
19 changes: 16 additions & 3 deletions src/facet_display/FilterableFacet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ interface Props {
selected: string[]
onUpdate: React.ChangeEventHandler<HTMLInputElement>
expandedOnLoad: boolean
preserveItems?: boolean
}

function FilterableFacet(props: Props) {
const { name, title, results, selected, onUpdate, expandedOnLoad } = props
const {
name,
title,
results,
selected,
onUpdate,
expandedOnLoad,
preserveItems
} = props
const [showFacetList, setShowFacetList] = useState(expandedOnLoad)

const [filterText, setFilterText] = useState("")
Expand All @@ -45,7 +54,11 @@ function FilterableFacet(props: Props) {

const buckets = (filteredResults || results) ?? []
return results && results.length === 0 ? null : (
<div className="facets filterable-facet">
<div
className={`facets filterable-facet${
showFacetList ? " facets-expanded" : ""
}`}
>
<button
className="filter-section-button"
type="button"
Expand All @@ -57,7 +70,7 @@ function FilterableFacet(props: Props) {
{titleLineIcon}
</i>
</button>
{showFacetList ? (
{showFacetList || preserveItems ? (
<>
<div className="input-wrapper">
<input
Expand Down
1 change: 1 addition & 0 deletions src/facet_display/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type SingleFacetOptions = {
name: FacetKey
title: string
expandedOnLoad: boolean
preserveItems?: boolean
labelFunction?: ((value: string) => string) | null
}

Expand Down

0 comments on commit ed4f12d

Please sign in to comment.