Skip to content

Commit

Permalink
Rename fillSvgWithColor helper by optimizeAndDefineColor
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Jul 27, 2023
1 parent 847b315 commit 7dfc560
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import SVG from 'react-inlinesvg';

import { fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';
import { Link } from 'components/Link';

interface Props {
Expand All @@ -16,7 +16,7 @@ export const ActivityButton: React.FC<Props> = ({ iconUrl, href, label }) => {
href={href}
className="flex flex-col items-center text-center mt-6 text-greyDarkColored bg-white transition hover:text-primary3 focus:text-primary3"
>
<SVG src={iconUrl} className="h-9 desktop:w-12" preProcessor={fillSvgWithColor()} />
<SVG src={iconUrl} className="h-9 desktop:w-12" preProcessor={optimizeAndDefineColor()} />
<span className="w-20 text-sm mt-2 text-ellipsis overflow-hidden">{label}</span>
</Link>
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/CardIcon/CardIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';
import SVG from 'react-inlinesvg';
import styled from 'styled-components';
import Image from 'next/image';
Expand Down Expand Up @@ -36,7 +36,7 @@ const Icon: React.FC<IconProps> = ({ iconUri = '', className = '', color }) => {
<SVG
src={iconUri}
className={`p-1 text-white ${className}`}
preProcessor={fillSvgWithColor()}
preProcessor={optimizeAndDefineColor()}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Image from 'next/image';
import SVG from 'react-inlinesvg';

import { fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';
import { Information } from '../BaseInformation';

export interface Props {
Expand All @@ -16,7 +16,7 @@ export interface Props {
export const RemoteIconInformation: React.FC<Props> = ({ iconUri, ...props }) => {
let icon = null;
if (RegExp(/(.*).svg/).test(iconUri)) {
icon = <SVG src={iconUri} className="w-6 h-full" preProcessor={fillSvgWithColor()} />;
icon = <SVG src={iconUri} className="w-6 h-full" preProcessor={optimizeAndDefineColor()} />;
} else if (typeof iconUri === 'string' && iconUri.length) {
icon = (
<Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Image from 'next/image';
import SVG from 'react-inlinesvg';
import { colorPalette, fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';

interface DetailsSourceProps {
name: string;
Expand Down Expand Up @@ -46,7 +46,7 @@ const SourceIcon: React.FC<{ pictogramUri: string }> = ({ pictogramUri }) => {
<SVG
src={pictogramUri}
className="h-full w-full p-1 text-white"
preProcessor={fillSvgWithColor()}
preProcessor={optimizeAndDefineColor()}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getActivityColor from 'components/pages/search/components/ResultCard/getA
import { Activity } from 'modules/activities/interface';
import Image from 'next/image';
import SVG from 'react-inlinesvg';
import { fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';
import { Details } from '../../../../../modules/details/interface';
import { OutdoorCourseDetails } from '../../../../../modules/outdoorCourse/interface';
import { OutdoorSiteDetails } from '../../../../../modules/outdoorSite/interface';
Expand Down Expand Up @@ -33,7 +33,9 @@ const Icon: React.FC<IconProps> = ({ src = '', ...props }) => {
return null;
}
if (RegExp(/(.*).svg/).test(src)) {
return <SVG src={src} {...props} className="text-white" preProcessor={fillSvgWithColor()} />;
return (
<SVG src={src} {...props} className="text-white" preProcessor={optimizeAndDefineColor()} />
);
}
return <Image loading="lazy" src={src} {...props} alt="" />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getHoverId } from 'components/pages/search/utils';
import { ActivitySuggestion } from 'modules/activitySuggestions/interface';
import SVG from 'react-inlinesvg';
import styled from 'styled-components';
import { fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';

export interface HomeSectionProps {
title: string;
Expand All @@ -19,7 +19,11 @@ export const HomeSection: React.FC<HomeSectionProps> = ({ title, iconUrl, result
id="home_sectionTitle"
className="flex border-t border-greySoft border-solid pt-4 desktop:pt-10 mb-2 desktop:mb-6 mx-4 desktop:mx-10percent"
>
<SVG src={iconUrl} preProcessor={fillSvgWithColor()} className="h-10 mr-2 desktop:mr-3" />
<SVG
src={iconUrl}
preProcessor={optimizeAndDefineColor()}
className="h-10 mr-2 desktop:mr-3"
/>
<span className="mt-1 desktop:mt-0 text-H2 desktop:text-H2 font-bold">{title}</span>
</h2>
<ScrollContainer className="flex p-5 overflow-scroll desktop:overflow-auto desktop:mx-10percent desktop:px-0 desktop:grid desktop:grid-cols-3 desktop:gap-3">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import SVG from 'react-inlinesvg';
import { useIntl } from 'react-intl';
import { fillSvgWithColor } from 'stylesheet';
import { optimizeAndDefineColor } from 'stylesheet';
import { cn } from 'services/utils/cn';
import { FilterState, Option } from '../../../../../modules/filters/interface';

Expand All @@ -24,7 +24,7 @@ const Icon: React.FC<IconProps> = ({ option, isSelected }) => {
<SVG
className={cn('w-6 h-6 mr-2', isSelected ? 'text-primary1' : 'text-greyDarkColored')}
src={option.pictogramUrl}
preProcessor={fillSvgWithColor()}
preProcessor={optimizeAndDefineColor()}
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const optimizeSVG = (svg: string): string => {
return data;
};

export const fillSvgWithColor =
export const optimizeAndDefineColor =
(color = 'currentColor') =>
(svg: string): string => {
const optimizedSVG = optimizeSVG(svg);
Expand Down

0 comments on commit 7dfc560

Please sign in to comment.