Skip to content

Commit

Permalink
feat: Show how to implement visual previews for facets
Browse files Browse the repository at this point in the history
  • Loading branch information
anandgorantala committed Aug 22, 2024
1 parent 2510c73 commit 5ca401c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 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.
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 5ca401c

Please sign in to comment.