Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(icons): Do not remove colors from icons with -colored suffix #DS-990 #1134

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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