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

Improve color generation #14

Open
ooflorent opened this issue Jan 9, 2017 · 1 comment
Open

Improve color generation #14

ooflorent opened this issue Jan 9, 2017 · 1 comment

Comments

@ooflorent
Copy link

Currently axs uses palx to generate the palette. When working on an existing design using incremental refactor, I must use our brand colors. However palx only accept the main color. It would be a greet improvement to expose functions to generate the palette (especially the shades).

import {config, palette} from "axs"

// Possible API satisfying the need:
config.set({
  colors: palette({
    orange: "#ff8000",
    red: "#d62828",
    green: "#128811",
    blue: "#2f638b",
  })
})
@gorango
Copy link

gorango commented Apr 21, 2017

This feature depends largely on the understyle package (which generates all the color props - for text, bg and borders).

Would it be more viable to raise the issue there?

EDIT#2: Made a PR: jxnblk/palx#5

EDIT#1: palx needs to be extended... or add a short script to the axs source.

I can see two ways to solve this issue:

  1. palx includes an options param which is currently unused but could be leveraged to pass in new theme colors. On line 93, add the following snippet to enable passing your own colors.
Object.keys(options).forEach(key => {
  colors.push({
    key,
    value: createShades('' + options[key])
  })
})

With this implementation you could just call palx('#07c', {orange: '#ff8000'}).
But because orange is already defined in the defaults, the new orange would be renamed to orange2 instead of replacing the default. You can see why on line 63.

  1. An alternative would be to extend axs by adopting the relevant features from palx into a new script.
    Implementing this would mean that updating your configuration would look like this:
import {config, palette} from "axs"

config.set({
  colors: {
    ...config.colors,
    ...palette({
      orange: '#ff8000',
      red: '#d62828'
    })
  }
})

This would overwrite any of the existing orange and red values while retaining the rest of the palette.


I believe the first approach (updating palx) would be more tidy and appropriate. It's also just as easy to add a { replace: true } flag in options to allow overwriting defaults.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants