Skip to content

Commit

Permalink
feat: Show how to implement visual previews for facets (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Anand Gorantala <anand.gorantala@bloomreach.com>
  • Loading branch information
anandgorantala and anandgorantala authored Aug 22, 2024
1 parent 2510c73 commit 5cdea83
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
Binary file added examples/facets/src/assets/natural.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/facets/src/assets/rust.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AssetTag } from "@bloomreach/react-banana-ui";
import {capitalize} from "lodash";

export const AppliedFacetMultiSelect = ({ value, onClear }) => {
return (
Expand All @@ -10,7 +11,7 @@ export const AppliedFacetMultiSelect = ({ value, onClear }) => {
key={val}
onDismiss={() => onClear(val)}
>
{val}
{capitalize(val)}
</AssetTag>
))}
</div>
Expand Down
36 changes: 30 additions & 6 deletions examples/facets/src/components/facet-color.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
import { CheckboxGroup } from "./checkbox-group";
import RustImg from "../assets/rust.png";
import NaturalImg from "../assets/natural.png";
import {capitalize} from "lodash";

export const FacetColor = ({ facet, value, onChange }) => {
const colorMapping = {
acorn: 'brown',
cream: '#f7f5ca',
};

const componentMapping = {
metallic: <div
className="w-5 h-5 rounded-full border border-gray-100 bg-gradient-to-r from-slate-400 to-gray-50"></div>,
rust: <img src={RustImg} alt="Rust preview" className="w-5 h-5 rounded-full border border-gray-100"/>,
natural: <img src={NaturalImg} alt="Rust preview" className="w-5 h-5 rounded-full border border-gray-100"/>,
}

function getPreview(value) {
if (componentMapping[value]) {
return componentMapping[value];
}

const color = colorMapping[value] || value;
return <div
className="w-5 h-5 rounded-full border border-gray-100"
style={{backgroundColor: color}}
></div>
}

export const FacetColor = ({facet, value, onChange}) => {
const options = facet.value.map((val) => ({
label: (
<div className="flex gap-2 items-center">
<div
className="w-5 h-5 rounded-full border border-gray-100"
style={{ backgroundColor: val.name }}
></div>
{getPreview(val.name)}
{" "}
{val.name}
{capitalize(val.name)}
</div>
),
value: val.name,
Expand Down
3 changes: 2 additions & 1 deletion examples/facets/src/components/facet-multi-select.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CheckboxGroup } from "./checkbox-group";
import {capitalize} from "lodash";

export const FacetMultiSelect = ({ facet, value, onChange }) => {
const options = facet.value.map((val) => ({
label: val.name,
label: capitalize(val.name),
value: val.name,
count: val.count,
}));
Expand Down
2 changes: 1 addition & 1 deletion examples/facets/src/components/facet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Facet = ({ facet, value, onChange }) => {
return (
<Accordion value={facet.name}>
<AccordionHeader>
<span className="grow text-sm uppercase">{facet.name}</span>
<span className="uppercase">{facet.name}</span>
</AccordionHeader>
<AccordionContent>
<FacetInner facet={facet} value={value} onChange={onChange} />
Expand Down

0 comments on commit 5cdea83

Please sign in to comment.