Skip to content

Commit

Permalink
Feat(icons): Do not remove colors from icons with -colored suffix #…
Browse files Browse the repository at this point in the history
…DS-990
  • Loading branch information
crishpeen committed Nov 14, 2023
1 parent 96cad29 commit 5da46d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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
9 changes: 6 additions & 3 deletions packages/icons/scripts/buildSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const { filterSvgFiles } = require('./shared');
const svgSrcDir = path.resolve(__dirname, `../src/svg`);
const svgDistDir = path.resolve(__dirname, `../dist/svg`);

const normalizeSvgColors = (fileName, svgContent) =>
fileName.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,12 +20,12 @@ const normalizeAndCopySvg = (srcDir, distDir) => {
const svgPath = path.join(srcDir, svg);
const svgDistPath = path.join(distDir, svg);
const svgContent = fs.readFileSync(svgPath, 'utf8');
const svgContentFixed = svgContent.replace(/fill="#\w+"/g, 'fill="currentColor"');
const svgSpriteContent = svgContentFixed
const svgContentNormalized = normalizeSvgColors(svg, svgContent);
const svgSpriteContent = svgContentNormalized
.replace(/<svg.*(viewBox="(\d+\s){3}\d+").*>/, `<symbol id="${svg.slice(0, -4)}" $1>`)
.replace(/<\/svg>/g, '</symbol>');
sprite += svgSpriteContent;
fs.writeFileSync(path.join(svgDistPath), svgContentFixed);
fs.writeFileSync(path.join(svgDistPath), svgContentNormalized);
});

sprite += '</svg>';
Expand Down

0 comments on commit 5da46d2

Please sign in to comment.