-
Notifications
You must be signed in to change notification settings - Fork 12
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
Color parameterization #16
Conversation
Co-authored-by: Dillon Kearns <[email protected]>
Co-authored-by: Dillon Kearns <[email protected]>
Co-authored-by: Dillon Kearns <[email protected]>
Co-authored-by: Dillon Kearns <[email protected]>
This looks really promising! Exposing the relevant raw parts (such as colors) of the tailwind config in a One thing bothers me: As type NiceColor
= HslaSpace Float Float Float Float
| RgbaSpace Float Float Float Float
color : Color -> NiceColor
... which can then be transformed further, e.g. with Maybe something like this wouldn't be needed if Alternatively, the internal representation could be made more type safe (i.e. use Alternatively, make What do you think? Do you have other ideas? |
Hello, good discussion @nidico! @matheus23 and I discussed exactly that in our pairing session when we first built the Theme module. The main challenges are:
So with those challenges, there's not always a neat mapping. And it presents some challenges for parsing those different formats. For example, here are some example theme values that reference CSS variables from the Tailwind docs: module.exports = {
theme: {
colors: {
// Using modern `rgb`
primary: 'rgb(var(--color-primary) / <alpha-value>)',
secondary: 'rgb(var(--color-secondary) / <alpha-value>)',
// Using modern `hsl`
primary: 'hsl(var(--color-primary) / <alpha-value>)',
secondary: 'hsl(var(--color-secondary) / <alpha-value>)',
// Using legacy `rgba`
primary: 'rgba(var(--color-primary), <alpha-value>)',
secondary: 'rgba(var(--color-secondary), <alpha-value>)',
}
}
} Given that the CSS spec can change over time, I'm not sure we can necessarily have a And the user experience is a bit confusing with these different possibilities. If something uses a CSS value like I'm not sure what the best approach is given that. I suppose we could generate different types based on the actual occurrences in the project. For example: type NiceColor
= HslaSpace Float Float Float Float
| RgbaSpace Float Float Float Float
| Other String -- CSS keywords, or values that referenc CSS variables or can't be parsed into known color spaces or formats What if the user's project only had |
I think what you suggest is a pragmatic approach, which should work fine in most cases. Let's look at a potential
Option 2 is messy, but I guess acceptable. So even if more than 1 % of the projects generated the This is all a bit awkward indeed! If the somebody comes up with a better idea, that'd be cool, but if not, I'd propose to go with this for now. |
One nice thing is that we can always improve the set of things which are parsed into nicely structured data over time, so we don't necessarily have to ship something to parse all variations right away. It's nice to avoid breaking changes, but I imagine there will be a lot of edge cases to consider that will come up over time. For example, we could even potentially parse things like the CSS value |
Yes, I fear so ;) (not knowing the full extent of the CSS spec) - but anyway - breaking changes aren't such a big deal thanks to our friendly elm compiler.
Right! I first thought this would make up for a good separate package
Alternatively, that parser could be put into one of the generated What do you think? |
With the current setup of the code generator, this would live in TypeScript rather than Elm. That might be good in some ways because there might be some existing utilities out there to help translate color values to different formats, maybe even some that are used by Tailwind. |
Co-authored-by: Dillon Kearns <[email protected]>
Previously: #13