Skip to content

Commit

Permalink
add svg theme wrapper, update project filters stories
Browse files Browse the repository at this point in the history
  • Loading branch information
wgardiner committed Oct 6, 2024
1 parent 5383368 commit b699b7b
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 189 deletions.
39 changes: 39 additions & 0 deletions web-components/src/components/icons/SvgThemeWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Box, SxProps, SvgIcon } from '@mui/material';

export default function SvgThemeWrapper({
src,
sx,
color,
}: {
src: string;
sx: SxProps;
color: string;
}) {
// TODO: support svg react components
return (
// <Box
// sx={{
// maskImage: `url(${src})`,
// maskSize: 'contain',
// maskRepeat: 'no-repeat',
// maskPosition: 'center',
// boxSizing: 'border-box',
// width: '30px',
// height: '30px',
// background: color,
// ...sx,
// }}
// />
<SvgIcon sx={sx}>
<mask id="mask_123">
<image
href={src}
style={{ filter: 'brightness(10)' }}
height="100%"
width="100%"
/>
</mask>
<rect mask="url(#mask_123)" width="100%" height="100%" fill={color} />
</SvgIcon>
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';
import path from 'path';

import { sxToArray } from '../../../utils/mui/sxToArray';

// TODO: utilize theme colors?
const selectedFill = '#BD9A11';
const selectedStroke = '#8A6E0B';

Expand All @@ -26,7 +26,6 @@ const ANDEAN_PATH =
export type Region = 'PACIFIC' | 'ORINOCO' | 'CARIBBEAN' | 'AMAZON' | 'ANDEAN';

interface RegionPaths {
// [key in Region]: string;
PACIFIC: string;
ORINOCO: string;
CARIBBEAN: string;
Expand Down Expand Up @@ -73,20 +72,24 @@ export default function RegionIndicatorIcon({
}: RegionIndicatorIconProps): JSX.Element {
const activeRegionPath = Object.entries(regionPaths).filter(
([key, value]) => key === region,
// TODO: review this
)[0][1];
const otherRegionPaths = Object.entries(regionPaths)
.filter(([key, value]) => key !== region)
.map(([_, value]) => value);
return (
<SvgIcon
sx={[{ color: '#4FB573' }, ...sxToArray(sx)]}
sx={[
{ color: '#4FB573', mr: 1, width: '30px', height: '30px' },
...sxToArray(sx),
]}
width="30"
height="30"
viewBox="0 0 30 30"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<g clip-path="url(#clip0_1479_22775)">
<g clipPath="url(#clip0_1479_22775)">
{otherRegionPaths.map((path: string, index: number) => (
<RegionPath key={index} path={path} />
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Grid } from '@mui/material';
import { Meta } from '@storybook/react';

import { LabeledIcon } from '../icons.stories';
import RegionIndicatorIcon from './RegionIndicatorIcon';
import RegionIndicatorIcon from './ColombiaRegionIndicatorIcon';

export default {
title: 'Terassos/Icons',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,208 @@
import { Box } from '@mui/material';
import { Meta, StoryFn } from '@storybook/react';

import ProjectFilters from './ProjectFilters';
import SvgThemeWrapper from '../../icons/SvgThemeWrapper';
import RegionIndicatorIcon, {
Region,
} from '../../icons/terassos/ColombiaRegionIndicatorIcon';
import ProjectFilters, { Filter, FilterOptions } from './ProjectFilters';

export default {
title: 'Organisms/ProjectFilters',
component: ProjectFilters,
} as Meta;

const Template: StoryFn = args => <ProjectFilters {...args} />;
const activeFilters = ['AMAZON', 'TROPICAL_VERY_HUMID_FOREST'];

export const Default = Template.bind({});
Default.args = {};
export function ComplianceBadge() {
return (
<Box
display="flex"
alignItems="center"
justifyContent="center"
width="24px"
height="24px"
padding="3px"
borderRadius="50%"
fontSize="12px"
fontWeight={700}
sx={{
borderRadius: '40px',
border: '1px dashed var(--surface-stroke, #D2D5D9)',
background: 'var(--surface-selected-item-background, #EFEFEF)',
ml: 2,
}}
>
ha.
</Box>
);
}

const Template: StoryFn = args => (
<ProjectFilters
{...args}
filters={args.filters}
activeFilterIds={activeFilters}
/>
);
// add another component

const ecosystemIconSx = {
width: '30px',
height: '30px',
mr: 2,
};

const ecosystemTags: FilterOptions[] = [
{
name: 'Tropical very humid forest',
id: 'TROPICAL_VERY_HUMID_FOREST',
icon: (
<SvgThemeWrapper
src="/tag/forest.svg"
sx={ecosystemIconSx}
color="#A5A4A4"
/>
),
},
{
name: 'Tropical humid forest',
id: 'TROPICAL_HUMID_FOREST',
icon: (
<SvgThemeWrapper
src="/tag/forest.svg"
sx={ecosystemIconSx}
color="#A5A4A4"
/>
),
},
{
name: 'Tropical dry forest',
id: 'TROPICAL_DRY_FOREST',
icon: (
<SvgThemeWrapper
src="/tag/forest.svg"
sx={ecosystemIconSx}
color="#A5A4A4"
/>
),
},
{
name: 'Premontane humid forest',
id: 'PREMONTANE_HUMID_FOREST',
icon: (
<SvgThemeWrapper
src="/tag/forest.svg"
sx={ecosystemIconSx}
color="#A5A4A4"
/>
),
},
{
name: 'Low montane very humid forest',
id: 'LOW_MONTANE_VERY_HUMID_FOREST',
icon: (
<SvgThemeWrapper
src="/tag/forest.svg"
sx={ecosystemIconSx}
color="#A5A4A4"
/>
),
},
];

export const WithCustomProps = Template.bind({});
WithCustomProps.args = {};
const regionTags: FilterOptions[] = [
{
name: 'Amazon',
id: 'AMAZON',
icon: (
<RegionIndicatorIcon
isSelected={activeFilters.includes('AMAZON')}
region={'AMAZON'}
/>
),
},
{
name: 'Pacific',
id: 'PACIFIC',
icon: (
<RegionIndicatorIcon
isSelected={activeFilters.includes('PACIFIC')}
region="PACIFIC"
/>
),
},
{
name: 'Orinoco',
id: 'ORINOCO',
icon: (
<RegionIndicatorIcon
isSelected={activeFilters.includes('ORINOCO')}
region="ORINOCO"
/>
),
},
{
name: 'Caribbean',
id: 'CARIBBEAN',
icon: (
<RegionIndicatorIcon
isSelected={activeFilters.includes('CARIBBEAN')}
region="CARIBBEAN"
/>
),
},
{
name: 'Andean',
id: 'ANDEAN',
icon: (
<RegionIndicatorIcon
isSelected={activeFilters.includes('ANDEAN')}
region="ANDEAN"
/>
),
},
];

const marketCheckboxes = [
{
name: 'Voluntary',
id: 'VOLUNTARY',
icon: (
<Box
component="img"
sx={{ width: '24px', ml: 2 }}
src="/logos/tebu-badge.png"
alt="Tebu"
/>
),
},
{
name: 'Compliance',
id: 'COMPLIANCE',
icon: <ComplianceBadge />,
},
];

const filters: Filter[] = [
{
displayType: 'tag',
title: 'Region',
options: regionTags,
},
{
displayType: 'tag',
title: 'Ecosystem',
options: ecosystemTags,
},
{
displayType: 'checkbox',
title: 'Market',
options: marketCheckboxes,
},
];

export const Default = Template.bind({});
Default.args = {
filters: filters,
};
Loading

0 comments on commit b699b7b

Please sign in to comment.