From 115a48f3b27d9f17ce60d0d94c138067926d20ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kry=C5=A1p=C3=ADn?= Date: Thu, 9 Nov 2023 17:33:33 +0100 Subject: [PATCH] fixup! Feat(icons): Do not remove colors from icons with `-colored` suffix #DS-990 --- packages/icons/README.md | 6 ++++++ packages/icons/scripts/buildSvg.js | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/icons/README.md b/packages/icons/README.md index 343a1dacc4..49d1a42082 100644 --- a/packages/icons/README.md +++ b/packages/icons/README.md @@ -20,6 +20,12 @@ or npm install --save @lmc-eu/spirit-icons ``` +## Colors + +Icons with the suffix `-colored` come with predefined colors, so no additional coloring is needed. +In contrast, icons without this suffix inherit the color from the `currentColor` CSS property of their parent element +or themself. + ## Usage ### SVG files diff --git a/packages/icons/scripts/buildSvg.js b/packages/icons/scripts/buildSvg.js index 40c5148c19..27e604f817 100644 --- a/packages/icons/scripts/buildSvg.js +++ b/packages/icons/scripts/buildSvg.js @@ -5,6 +5,8 @@ const { filterSvgFiles } = require('./shared'); const svgSrcDir = path.resolve(__dirname, `../src/svg`); const svgDistDir = path.resolve(__dirname, `../dist/svg`); +const normalizeSvgColors = (svg, svgContent) => svg.endsWith('-colored.svg') ? svgContent : svgContent.replace(/fill="#\w+"/g, 'fill="currentColor"'); + const normalizeAndCopySvg = (srcDir, distDir) => { fs.readdir(srcDir, (err, files) => { const svgs = filterSvgFiles(files); @@ -17,7 +19,7 @@ const normalizeAndCopySvg = (srcDir, distDir) => { const svgPath = path.join(srcDir, svg); const svgDistPath = path.join(distDir, svg); const svgContent = fs.readFileSync(svgPath, 'utf8'); - const svgContentFixed = svg.endsWith('-colored.svg') ? svgContent : svgContent.replace(/fill="#\w+"/g, 'fill="currentColor"'); + const svgContentFixed = normalizeSvgColors(svg, svgContent); const svgSpriteContent = svgContentFixed .replace(//, ``) .replace(/<\/svg>/g, '');