Skip to content

Commit

Permalink
fixup! Feat(icons): Do not remove colors from icons with -colored s…
Browse files Browse the repository at this point in the history
…uffix #DS-990
  • Loading branch information
crishpeen committed Nov 9, 2023
1 parent 680350f commit 115a48f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/icons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/icons/scripts/buildSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(/<svg.*(viewBox="(\d+\s){3}\d+").*>/, `<symbol id="${svg.slice(0, -4)}" $1>`)
.replace(/<\/svg>/g, '</symbol>');
Expand Down

0 comments on commit 115a48f

Please sign in to comment.