Open hughbris opened 10 months ago
Having spent some time actively investigating this, I am not so sure it's possible without some compromises that go against the goal of the theme being trivial to install and use.
There are three important theme goals that are difficult to align in a solution:
I know the last two there seem inconsistent. I don't know a way to explain that they are not.
Here is an imperfectly recalled account of what I have investigated and tried.
I tried this by copying Admin's blueprints to Particles.
I was able to embed the UI into the theme's admin but looking further into what happens after saving, PHP is required to recompile the SCSS. I could use that code, but it would require Admin to be installed with the theme (refer Goal 2). If I copy and adapt the PHP to avoid that dependency, then the theme would require PHP/Composer libraries as dependencies to compile the SCSS (refer Goal 3).
So I looked for ways to implement the theme in a robust (repeatable) way without SCSS. CSS variables are well supported now and provide a single place where a colour could be overridden for the theme.
I could do a one-off search-and-replace on the compiled CSS bundled with the theme, but that would need to be performed every time the source SCSS changes (refer Goal 1). This approach is complicated further by requiring SCSS functions like darken()
without stable CSS analogues to derive some colours.
I looked at whether SCSS has a compilation option that outputs CSS variables in place of its own variables where possible. So instead of producing CSS with (for example) colour values like '#3085EE', SCSS could be configured to declare --primary-color: #3085EE
and then use var(--primary-color)
to reference it. Then we could simply override that CSS variable declaration to change the primary theme colour. Sadly, I did not find such an option in the CLI documentation.
Conclusions: The rubber duck method is real. It may be that a hybrid approach is the best option. Changes made in Admin piggyback off its SCSS recompilation and changes made manually require that developers update run scripts to apply their changes. This is fine if we accept that site administrators working directly with configuration files have the technical expertise to do this.
Investigations into implementing this also bore no satisfying solutions. Happily the investigations revealed that with less time spent :laughing:
The first approach was based on the naive assumptions that:
I guess the second one is not new and why CSS supports fallbacks when specifying fonts and ultimately recommends specifying a generic font family.
We can compile and provide a dropdown list of font sets including fallbacks and font families. This would need to be updated occasionally. It would be nicer to retrieve common font option sets from a web service.
There are also the same issues discussed for theme colours above of integrating CSS overrides into CSS generated from SCSS. There are not as many rules to override and they seem more straightforward, but it's all a bit fragile for my taste.
Web loaded fonts are another option but there are GDPR compliance implications with requiring them.