forked from adobe/storefront-product-listing-page
-
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.
include example directory with tooltip slots
- Loading branch information
ani hammond
authored and
ani hammond
committed
Nov 6, 2023
1 parent
cda8e18
commit be92e3f
Showing
34 changed files
with
340 additions
and
579 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,72 @@ | ||
/* | ||
Copyright 2024 Adobe | ||
All Rights Reserved. | ||
NOTICE: Adobe permits you to use, modify, and distribute this file in | ||
accordance with the terms of the Adobe license agreement accompanying | ||
it. | ||
*/ | ||
|
||
import { FunctionComponent } from 'preact'; | ||
|
||
import { useProducts, useSearch } from '../../context'; | ||
import Pill from '../Pill'; | ||
import { formatBinaryLabel, formatRangeLabel } from './format'; | ||
|
||
export const SelectedFilters: FunctionComponent = ({}) => { | ||
const searchCtx = useSearch(); | ||
const productsCtx = useProducts(); | ||
|
||
return ( | ||
<div className="w-full h-full"> | ||
{searchCtx.filters?.length > 0 && ( | ||
<div className="ds-plp-facets__pills pb-6 sm:pb-6 flex flex-wrap mt-8 justify-start"> | ||
{searchCtx.filters.map((filter) => ( | ||
<div key={filter.attribute}> | ||
{filter.in?.map((option) => ( | ||
<Pill | ||
key={formatBinaryLabel( | ||
filter, | ||
option, | ||
searchCtx.categoryNames, | ||
productsCtx.categoryPath | ||
)} | ||
label={formatBinaryLabel( | ||
filter, | ||
option, | ||
searchCtx.categoryNames, | ||
productsCtx.categoryPath | ||
)} | ||
type="transparent" | ||
onClick={() => searchCtx.updateFilterOptions(filter, option)} | ||
/> | ||
))} | ||
{filter.range && ( | ||
<Pill | ||
label={formatRangeLabel( | ||
filter, | ||
productsCtx.currencyRate, | ||
productsCtx.currencySymbol | ||
)} | ||
type="transparent" | ||
onClick={() => { | ||
searchCtx.removeFilter(filter.attribute); | ||
}} | ||
/> | ||
)} | ||
</div> | ||
))} | ||
<div className="py-1"> | ||
<button | ||
className="ds-plp-facets__header__clear-all border-none bg-transparent hover:border-none hover:bg-transparent | ||
focus:border-none focus:bg-transparent active:border-none active:bg-transparent active:shadow-none text-sm px-4" | ||
onClick={() => searchCtx.clearFilters()} | ||
> | ||
Clear all | ||
</button> | ||
</div> | ||
</div> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2024 Adobe | ||
All Rights Reserved. | ||
NOTICE: Adobe permits you to use, modify, and distribute this file in | ||
accordance with the terms of the Adobe license agreement accompanying | ||
it. | ||
*/ | ||
|
||
import { FacetFilter } from '../../types/interface'; | ||
|
||
// format range with null "to" | ||
const formatRangeLabel = ( | ||
filter: FacetFilter, | ||
currencyRate: string, | ||
currencySymbol: string | ||
) => { | ||
const range = filter.range; | ||
|
||
const rate = currencyRate ? currencyRate : '1'; | ||
const symbol = currencySymbol ? currencySymbol : '$'; | ||
const label = `${symbol}${ | ||
range?.from && parseFloat(rate) * parseInt(range.from.toFixed(0), 10) | ||
? (parseFloat(rate) * parseInt(range.from?.toFixed(0), 10))?.toFixed(2) | ||
: 0 | ||
}${ | ||
range?.to && parseFloat(rate) * parseInt(range.to.toFixed(0), 10) | ||
? ` - ${symbol}${( | ||
parseFloat(rate) * parseInt(range.to.toFixed(0), 10) | ||
).toFixed(2)}` | ||
: ' and above' | ||
}`; | ||
return label; | ||
}; | ||
|
||
const formatBinaryLabel = ( | ||
filter: FacetFilter, | ||
option: string, | ||
categoryNames?: { value: string; name: string; attribute: string }[], | ||
categoryPath?: string | ||
) => { | ||
if (categoryPath && categoryNames) { | ||
const category = categoryNames.find( | ||
(facet) => facet.attribute === filter.attribute && facet.value === option | ||
); | ||
|
||
if (category?.name) { | ||
return category.name; | ||
} | ||
} | ||
|
||
const title = filter.attribute?.split('_'); | ||
if (option === 'yes') { | ||
return title.join(' '); | ||
} else if (option === 'no') { | ||
return `not ${title.join(' ')}`; | ||
} | ||
return option; | ||
}; | ||
|
||
export { formatBinaryLabel, formatRangeLabel }; |
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
Oops, something went wrong.