Skip to content

Commit

Permalink
include example directory with tooltip slots
Browse files Browse the repository at this point in the history
  • Loading branch information
ani hammond authored and ani hammond committed Nov 6, 2023
1 parent cda8e18 commit be92e3f
Show file tree
Hide file tree
Showing 34 changed files with 340 additions and 579 deletions.
424 changes: 8 additions & 416 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@adobe/storefront-product-listing-page",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"typings": "./dist/@types/index.d.ts",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Alert/Alert.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Canvas, Meta, Story, ArgsTable } from "@storybook/addon-docs";
import { Alert } from "./Alert";

<Meta
title="UIKit/Alert"
title="PLP/Alert"
component={Alert}
parameters={{
layout: "padded"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Breadcrumbs/Breadcrumbs.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Breadcrumbs } from "../Breadcrumbs";
import { pages } from "./MockPages.ts";

<Meta
title="UIKit/Breadcrumbs"
title="PLP/Breadcrumbs"
component={Breadcrumbs}
parameters={{
layout: "centered"
Expand Down
15 changes: 8 additions & 7 deletions src/components/CategoryFilters/CategoryFilters.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
import { CategoryFilters } from './CategoryFilters';
import { mockFilters } from '../mocks.tsx';
import { action } from "@storybook/addon-actions";
import { action } from '@storybook/addon-actions';

<Meta
title="PLP widget/CategoryFilters"
title="PLP/CategoryFilters"
component={CategoryFilters}
parameters={{
layout: 'centered'
layout: 'centered',
}}
decorators={[]}
/>
Expand All @@ -28,10 +28,11 @@ import { CategoryFilters } from './CategoryFilters'
args={{
loading: false,
facets: mockFilters,
totalCount: 15,
categoryName: 'Pants',
phrase: "pants",
setShowFilters: action("setShowFilters")
totalCount: 15,
categoryName: 'Pants',
phrase: 'pants',
showFilters: true,
setShowFilters: action('setShowFilters'),
}}
>
{Template.bind({})}
Expand Down
2 changes: 2 additions & 0 deletions src/components/CategoryFilters/CategoryFilters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ describe('PLP widget/CategoryFilters', () => {
facets={[]}
categoryName=""
phrase=""
showFilters={true}
setShowFilters={() => true}
filterCount={0}
/>
);

Expand Down
9 changes: 7 additions & 2 deletions src/components/CategoryFilters/CategoryFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ interface CategoryFiltersProps {
facets: Facet[];
categoryName: string;
phrase: string;
showFilters: boolean;
setShowFilters: (showFilters: boolean) => void;
filterCount: number;
}

export const CategoryFilters: FunctionComponent<CategoryFiltersProps> = ({
Expand All @@ -33,6 +35,7 @@ export const CategoryFilters: FunctionComponent<CategoryFiltersProps> = ({
categoryName,
phrase,
setShowFilters,
filterCount,
}) => {
const translation = useContext(TranslationContext);
let title = categoryName || '';
Expand All @@ -52,13 +55,15 @@ export const CategoryFilters: FunctionComponent<CategoryFiltersProps> = ({
)}
</div>

{!pageLoading && (
{!pageLoading && facets.length > 0 && totalCount > 0 && (
<>
<div className="flex pb-4 w-full h-full">
<FilterButton
displayFilter={() => setShowFilters(false)}
type="desktop"
title={translation.Filter.hideTitle}
title={`${translation.Filter.hideTitle}${
filterCount > 0 ? ` (${filterCount})` : ''
}`}
/>
</div>
<Facets searchFacets={facets} />
Expand Down
101 changes: 1 addition & 100 deletions src/components/Facets/Facets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ it.

import { FunctionComponent } from 'preact';

import { useProducts, useSearch } from '../../context';
import {
Facet as FacetType,
FacetFilter,
PriceFacet,
} from '../../types/interface';
import { Pill } from '../Pill';
import { Facet as FacetType, PriceFacet } from '../../types/interface';
import { RangeFacet } from './Range/RangeFacet';
import { ScalarFacet } from './Scalar/ScalarFacet';

Expand All @@ -26,101 +20,8 @@ interface FacetsProps {
export const Facets: FunctionComponent<FacetsProps> = ({
searchFacets,
}: FacetsProps) => {
const searchCtx = useSearch();
const productsCtx = useProducts();

// format range with null "to"
const formatRangeLabel = (filter: FacetFilter) => {
const range = filter.range;

const currencyRate = productsCtx.currencyRate
? productsCtx.currencyRate
: '1';
const currencySymbol = productsCtx.currencySymbol
? productsCtx.currencySymbol
: '$';
const label = `${currencySymbol}${
range?.from &&
parseFloat(currencyRate) * parseInt(range.to.toFixed(0), 10)
? (
parseFloat(currencyRate) * parseInt(range.from?.toFixed(0), 10)
)?.toFixed(2)
: 0
}${
range?.to && parseFloat(currencyRate) * parseInt(range.to.toFixed(0), 10)
? ` - ${currencySymbol}${(
parseFloat(currencyRate) * parseInt(range.to.toFixed(0), 10)
).toFixed(2)}`
: ' and above'
}`;
return label;
};

const formatBinaryLabel = (filter: FacetFilter, option: string) => {
if (productsCtx.categoryPath) {
const category = searchCtx.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;
};

return (
<div className="ds-plp-facets flex flex-col">
{searchCtx.filters?.length > 0 && (
<>
<div className="border-t border-gray-200" />
<div className="ds-plp-facets__header flex justify-between align-middle py-md">
<span className="ds-plp-facets__header__title ml-0 text-normal">
Filters
</span>
<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"
onClick={() => searchCtx.clearFilters()}
>
Clear all
</button>
</div>

<div className="ds-plp-facets__pills pb-4 sm:pb-6 flex flex-wrap gap-3">
{searchCtx.filters.map((filter) => (
<div className="flex flex-wrap gap-3" key={filter.attribute}>
{filter.in?.map((option) => (
<Pill
key={filter.attribute}
label={formatBinaryLabel(filter, option)}
onClick={() =>
searchCtx.updateFilterOptions(filter, option)
}
/>
))}
{filter.range && (
<Pill
label={formatRangeLabel(filter)}
onClick={() => {
searchCtx.removeFilter(filter.attribute);
}}
/>
)}
</div>
))}
</div>
</>
)}

<form className="ds-plp-facets__list border-t border-gray-200">
{searchFacets?.map((facet) => {
const bucketType = facet?.buckets[0]?.__typename;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Facets/Range/RangeFacet.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mockPriceFilter } from "../mocks.tsx";
import { SearchDecorator } from "../../../../.storybook/decorators/SearchDecorator";

<Meta
title="PLP widget/RangeFacet"
title="PLP/RangeFacet"
component={RangeFacet}
parameters={{
layout: "centered"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Facets/Scalar/ScalarFacet.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScalarFacet } from "../../../components";
import { mockColorFilter } from "../mocks.tsx";

<Meta
title="PLP widget/ScalarFacet"
title="PLP/ScalarFacet"
component={ScalarFacet}
parameters={{
layout: "centered"
Expand Down
72 changes: 72 additions & 0 deletions src/components/Facets/SelectedFilters.tsx
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>
);
};
61 changes: 61 additions & 0 deletions src/components/Facets/format.ts
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 };
1 change: 1 addition & 0 deletions src/components/Facets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ it.
*/

export * from './Facets';
export * from './SelectedFilters';
export * from './Range/RangeFacet';
export * from './Scalar/ScalarFacet';
export { Facets as default } from './Facets';
2 changes: 1 addition & 1 deletion src/components/FilterButton/FilterButton.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { action } from "@storybook/addon-actions"
import { FilterButton } from '../FilterButton';

<Meta
title="UIKit/FilterButton"
title="PLP/FilterButton"
component={FilterButton}
parameters={{
layout: 'centered',
Expand Down
Loading

0 comments on commit be92e3f

Please sign in to comment.