secundant / neodx

A collection of frontend-focused tools aimed at enhancing your development experience
MIT License
80 stars 6 forks source link

`@neodx/svg` - Color Reset API improvement #91

Closed secundant closed 1 year ago

secundant commented 1 year ago

API Design

svg({
  resetColors: [
    {
      include: /^flags/,
      replace: {
        from: 'white',
        to: 'currentColor'
      }
    },
    {
      keep: myTheme.brandColors,
      exclude: [/^flags/, /^logos/, /-colored\.svg$/, 'my-icon.svg'],
      replace: [
        {
          from: myTheme.accentIconColors,
          to: 'var(--icon-color)'
        },
        {
          from: myTheme.secondaryIconColors,
          to: 'var(--icon-bg)'
        }
      ],
      replaceUnknwon: 'currentColor'
    }
  ]
});

Motivation

I've got some missed features from the real users:

First versions of API

Disable
svg({
  resetColors: false
})
Filter icons
svg({
  resetColors: {
    exclude: ['logos/colored', /^flags/]
  }
})
Filter colors
svg({
  resetColors: {
    keep: ['#fff', 'red']
  }
})
Complex solution
svg({
  resetColors: {
    replace: {
      from: ['#222', '#eee'],
      to: 'var(--icon-color)'
    },
    keep: ['#a1a1a1', '#f9c52'],
    exclude: [/flags/],
    replaceUnknown: 'currentColor'
  }
});