endigma / unocss-preset-radix

A preset for UnoCSS to let you use Radix color palette
https://endigma.github.io/unocss-preset-radix/
MIT License
32 stars 6 forks source link

Add foreground color #13

Closed silveltman closed 1 year ago

silveltman commented 1 year ago

Some radix scales use black on hue9, some use white. A selector for this would be great.

Just sharing my personal fix for this:

    theme: {
      colors: {
        foreground: 'var(--un-preset-theme-fg)',
        'foreground-base': getForeground(options.colors.base),
        'foreground-primary': getForeground(options.colors.primary),
        'foreground-secondary': getForeground(options.colors.secondary),
      },
    },
    rules: [
      [
        'hue-base',
        {
          '--un-preset-theme-fg': getForeground(options.colors.base),
        },
      ],
      [
        'hue-primary',
        {
          '--un-preset-theme-fg': getForeground(options.colors.primary),
        },
      ],
      [
        'hue-secondary',
        {
          '--un-preset-theme-fg': getForeground(options.colors.secondary),
        },
      ],
    ],
endigma commented 1 year ago

Yeah thats a pretty good idea, you mean to select between the dark fg and light fg colors?

Something like darkfg:text-black lightfg:text-white?

endigma commented 1 year ago

I think there could potentially be some magic stuff here to allow an extra color to come with the hue 0-12 for fg, maybe even like fg[1..12] etc

silveltman commented 1 year ago

I don't think it would have to be difficult, it's only about this part of the docs: image

The following classes would suffice:

-bluefg -redfg Etc.

-huefg

For sky-amber it would be black, for the other colors it would be white

endigma commented 1 year ago

I suppose 11 and 12 are universal foregrounds for lower numbered backgrounds, could just add another color to every palette for the appropriate high contrast foreground color. I'll look into it.

silveltman commented 1 year ago

Yes you're right, for the lower numbered backgrounds 11 and 12 are fine indeed.

You solution sounds fine 👌🏼

endigma commented 1 year ago

Added in 2.5.2. You can use like text-amber-fg or text-hue-fg. Detection doesn't seem quite as flexible as the colors so huefg and amberfg don't work I think.