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

Aliases as rules / Hues as aliases #2

Open
endigma opened this issue Mar 4, 2023 · 6 comments
Open

Aliases as rules / Hues as aliases #2

endigma opened this issue Mar 4, 2023 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@endigma
Copy link
Owner

endigma commented Mar 4, 2023

It could be useful to be able to define aliases inline, which would also perhaps be used to power hue functionality.

something like alias-danger-red as a rulename. This would more or less replace hue in-place if a shortcut for hue- -> alias-hue- was set up, and would allow stuff like hue5-blue or etc if multiple hues are required to power a hue combination.

@endigma endigma self-assigned this Mar 4, 2023
@endigma endigma added the enhancement New feature or request label Mar 4, 2023
@awwwdev
Copy link

awwwdev commented Mar 23, 2023

I thought about this a little bit. here is what I found.
To avoid mixing hue colors you need to create a new set of CSS vars for each hue.
Let's say we have we have:

<div class="alias-info-blue alias-primary-green" >
   <button class="c-info11 bg-primary3" >Hi</button>
</div>

for it to work we need to generate this CSS:

.alias-info-blue   {
  --uno-radix-info12 : var(--uno-radix-blue12);
  --uno-radix-info11 : var(--uno-radix-blue11);
  ...
}

.alias-primary-green {
  --uno-radix-primary12 : var(--uno-radix-green12);
  --uno-radix-promary11 : var(--uno-radix-green11);
  ...
}

and then have some rules to handle c-(w+)(d+) , bg-(w+)(d+) , ... For example c-info12 and bg-primary3 should create:

.c-info12 {
  color: var(--uno-radix-info12);
}

.bg-primary3 {
  background-color: var(--uno-radix-primary3);
}

So they can pick up the hue and use it.

@endigma
Copy link
Owner Author

endigma commented Mar 23, 2023

CSS vars wise it'd actually be essentially the same code as hues right now, just subbing in another part of the rule in the generated CSS. I would need to find a way to dynamically add or detect the colors though, hue is still hardcoded into the theme.

https://github.com/endigma/unocss-preset-radix/blob/8c3f43d9317bf8c8336d385b7719e12800f90e59/src/radix.ts#LL56-L59C2

Is responsible for generating a "scale" that represents the current hue value. I think uno may give some sort of hook that returns which rules get used, or which colors, which might give an avenue to adding the colors that get made by alias-x-y dynamically. This is my first unocss preset though, so I'm not entirely sure how that system works.

@awwwdev
Copy link

awwwdev commented Mar 25, 2023

yeah, with adding colors dynamically, you don't need to select colors in config. I guess you currently add all 12 levels of a color if it's in the selected colors.
I used unocss-preset-theme to manage dark them. This add colors dynamically. I gave all radix colors to this preset (and also the default unocss them) and then if I use "c-orange11" it only add the light and dark variables of orange11.
But I had a hard time to config it correctly and the its new versions don't work with hsl colors. I really look forward to this preset.

BTW it would be nice to add "lightSelector". It's useful when you want to force lightmode in page/section or when you want to auto/OS option beside light and dark.

@endigma
Copy link
Owner Author

endigma commented Mar 25, 2023

What's blocking you from using it right now? lightSelector support is in as of 2.1.0

@endigma endigma added the help wanted Extra attention is needed label Mar 25, 2023
@endigma endigma removed their assignment Mar 25, 2023
@endigma
Copy link
Owner Author

endigma commented Mar 25, 2023

I don't have time to scope and impl this atm, contribution would be welcome.

@awwwdev
Copy link

awwwdev commented Mar 28, 2023

What's blocking you from using it right now? lightSelector support is in as of 2.1.0

Didn't know that. Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants