Skip to content

Commit

Permalink
revert(icons): handle country flag colors
Browse files Browse the repository at this point in the history
  • Loading branch information
solygambas committed Jul 13, 2023
1 parent 22b1f0c commit 93e45ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
7 changes: 1 addition & 6 deletions packages/components/icons/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ const main = async (pattern = 'assets/**/*.svg') => {

const relativeDir = path.relative('assets', dir)

// Handle flags differently
const isCountryFlag = /^Flag[A-Z]{2}$/.test(name)
const svgFill = isCountryFlag ? 'none' : 'currentColor'

const tsxIconCode = componentize({
componentName: pascalCase(name),
node: optimize(svgData, {
attributes: [{ fill: svgFill }, { stroke: 'none' }],
attributes: [{ fill: 'currentColor' }, { stroke: 'none' }],
title: name,
isCountryFlag,
}).trim(),
name,
tags: relativeDir.split('/'),
Expand Down
19 changes: 7 additions & 12 deletions packages/components/icons/scripts/utils/optimize.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { optimize as optimizeSVGO } from 'svgo'

const optimize = (svgString, { attributes = [], title, isCountryFlag = false } = {}) => {
const optimize = (svgString, { attributes = [], title } = {}) => {
return optimizeSVGO(svgString, {
multipass: true, // boolean. false by default
js2svg: {
indent: 2, // string with spaces or number of spaces. 4 by default
pretty: true, // boolean, false by default
},
plugins: [
// Exclude removeAttrs plugin for country flags
...(isCountryFlag
? []
: [
{
name: 'removeAttrs',
params: {
attrs: '(fill|stroke|stroke-width)',
},
},
]),
{
name: 'removeAttrs',
params: {
attrs: '(fill|stroke)',
},
},
{
name: 'addAttributesToSVGElement',
params: {
Expand Down

0 comments on commit 93e45ff

Please sign in to comment.