code for automatically generated HSL color scheme
-
Can we implement in GP a color system with auto-generated HSL color scheme (with variables/formula)?
Here is a detailed description about how to do it in oxygen with some custom code: https://www.youtube.com/watch?v=1Ta8_OhKY7kHow this can be adapted for GP?
It would be great to have a code that would make possible to insert only the main/accent color and all the other colors to be generated automatically, with parameters specified by the user.
It would be great if in the future such feature would be present by default in the color features of the theme, with clicks and fields.
But with code it would be OK anyway…Can anyone (with better knowledge of programming) write some lines of code, to adapt for GP the code described in the video above?
Thanks!
-
Hi there,
At this time it isn’t possible within GP (without writing your own CSS) as the color fields won’t accept
hsl()
values.However, we’re currently revamping our color system to including Global Colors (https://generatepress.com/generatepress-3-1-global-colors-dynamic-typography/), and while
hsl()
isn’t supported right now, I think it’s something we can add quite easily.Then it should be relatively simple to build a system like this (likely using some CSS as they did in the video).
Right now I don’t have a solution for you, but check back in the next few weeks and see if we do.
Thanks! ??
hello Tom!
I was able to replace a default color, using HSL, in GP Developer Child Theme (by Addison Hall)
In the file colors.php (inc/colors.php) i was able to replace and rename a grey color with “Light-Purple” in HSL code…
But i wasn’t able to use the “Light-purple” as variable color, as hue in the code bellow, in a new formula to define the new color “Dark Purple”…
Since i`m totally beginner in coding, probably is a syntax error on my part?
Or the theme doesn’t support calculated formulas for generating colors in code?Here is the code (the two last colors are my attempts, light purple using simple HSL, dark purple trying to use a calculated value):
* ADD YOUR THEME COLORS HERE! * Array of theme colors will be added to WordPress */ $gpc_theme_colors = array( array( 'name' => __( 'White', 'generatepress-child' ), 'slug' => 'white', 'color' => '#ffffff', ), array( 'name' => __( 'Purple', 'generatepress-child' ), 'slug' => 'purple', 'color' => '#8939cc', ), array( 'name' => __( 'Black', 'generatepress-child' ), 'slug' => 'black', 'color' => '#000000', ), array( 'name' => __( 'Light Purple', 'generatepress-child' ), 'slug' => 'light-purple', 'color' => 'hsl(267, 81%, 90%)', ), array( 'name' => __( 'Dark Purple', 'generatepress-child' ), 'slug' => 'dark-purple', 'color' => 'hsl(var(--light-purple), 100%, 35%)', ), );
Hi there,
I’m not really familiar with the child theme – what do these colors do? Where are they added?
Did you get a specific error when doing this, or did it just not work?
It is an awesome developer child theme for GeneratePress, with a multitude of functions, which is a great help for someone without deep coding knowledge (like me): https://github.com/addisonhall/generatepress-child
Here is an overview: https://www.youtube.com/playlist?list=PL7raQfw3hl92x0ErLPA5hb-I-yHQQXFttIf I put my colors in the file colors.php (inc/colors.php), they will appear in color pickers both in GP customizer and gutenberg.
I was able to put HSL colors in colors.php, instead of HEX.
And it worked! ??
My HSL colors replaced all default colors in the picker.
It worked only in GP 3.0.4 Version.
In 3.1 alpha it didnt replace the default colors, but there is no need, because in 3.1 the HSL colors can be inserted natively.
But i wasnt able to use HSL calculated values, probably because i dont have the coding knowledge to write the correct syntax to calculate secondary/complementary colors from the primary color.Another solution i used is https://www.ads-software.com/plugins/kt-tinymce-color-grid/ which seems to work with 3.1 alpha too… but this plugin seems abandoned and it doesn’t offer the possibility to generate calculated color values…
After the GP version 3.1 will be released, Addison Hall will update his developer child theme too.
Until then, i will tinker with 3.1 alpha, to find a way to code the calculations to generate all the color palette only by changing the primary color, like in the video about Oxygen (from my first comment).
Awesome – definitely let us know if it’s possible in 3.1. I have a feeling we may need to update our sanitizing functions to allow
hsla()
values, as right now we only check for hex orrgba()
.I like the concept – it will definitely be nice if it’s possible natively in the theme ??
Hi @edge22 !
I added this code (below) in the style.css of the blank/normal child theme (downloaded from your site), using 3.1 alpha GP theme.
Results:
– the colors can be added and work in the customizers Global Colors; if i insert, for example “var(–secondary)” in a new global color, it can be applied to the elements in the customizer… i tried with the site background and it worked!
– anyway, in the customizers picker, the color is not translated, it appears as a dark-grey circle for any variable color (but not a big problem, as it keeps the title in tooltip and it works anyway to be applied);
– in Stackable and GenerateBlocks, the variable colors inserted in the customizers Global Colors appear in the picker as the same dark-grey circle, but they do not work to be applied to blocks in gutenberg…How the colors declared in the code fragment below could be added as default GP colors?
is there any code which could help?
or they will be better supported in the GP 3.1 final version?Thanks!
:root { /*** COLOR SYSTEM ***/ /* GLOBAL COLOR SETUP (HSL) Set the global colors below using HSL variables. */ --primary-h: 44; --primary-s: 98%; --primary-l: 50%; --secondary-h: calc(var(--primary-h) + 120); --secondary-s: 100%; --secondary-l: 63.3%; --accent-h: 54.5; --accent-s: 15.5%; --accent-l: 86.1%; --base-h: 357.2; --base-s: 70.5%; --base-l: 47.8%; /* SHADING VARIABLES If you want to adjust the generated shade variants, you can adjust the percentages here. Higher percentages are lighter and lower are darker. */ --ultra-light: 95%; --light: 85%; --dark: 25%; --ultra-dark: 10%; /* GLOBAL COLOR VARIABLES These are the variables you can use in styling. They don't need to be edited. Future plans: Auto generate full complimentary, triadic, analogous, etc. color schemes. */ --primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l)); --primary-ultra-light: hsl(var(--primary-h), var(--primary-s), var(--ultra-light)); --primary-light: hsl(var(--primary-h), var(--primary-s), var(--light)); --primary-dark: hsl(var(--primary-h), var(--primary-s), var(--dark)); --primary-ultra-dark: hsl(var(--primary-h), var(--primary-s), var(--ultra-dark)); --primary-trans-80: hsla(var(--primary-h), var(--primary-s), var(--primary-l), .8); --primary-trans-60: hsla(var(--primary-h), var(--primary-s), var(--primary-l), .6); --primary-trans-40: hsla(var(--primary-h), var(--primary-s), var(--primary-l), .4); --primary-trans-20: hsla(var(--primary-h), var(--primary-s), var(--primary-l), .2); --primary-comp: hsl(calc(var(--primary-h) + 180), var(--primary-s), var(--primary-l)); --secondary: hsl(var(--secondary-h), var(--secondary-s), var(--secondary-l)); --secondary-ultra-light: hsl(var(--secondary-h), var(--secondary-s), var(--ultra-light)); --secondary-light: hsl(var(--secondary-h), var(--secondary-s), var(--light)); --secondary-dark: hsl(var(--secondary-h), var(--secondary-s), var(--dark)); --secondary-ultra-dark: hsl(var(--secondary-h), var(--secondary-s), var(--ultra-dark)); --secondary-trans-80: hsla(var(--secondary-h), var(--secondary-s), var(--secondary-l), .8); --secondary-trans-60: hsla(var(--secondary-h), var(--secondary-s), var(--secondary-l), .6); --secondary-trans-40: hsla(var(--secondary-h), var(--secondary-s), var(--secondary-l), .4); --secondary-trans-20: hsla(var(--secondary-h), var(--secondary-s), var(--secondary-l), .2); --secondary-comp: hsl(calc(var(--secondary-h) + 180), var(--secondary-s), var(--secondary-l)); --accent: hsl(var(--accent-h), var(--accent-s), var(--accent-l)); --accent-ultra-light: hsl(var(--accent-h), var(--accent-s), var(--ultra-light)); --accent-light: hsl(var(--accent-h), var(--accent-s), var(--light)); --accent-dark: hsl(var(--accent-h), var(--accent-s), var(--dark)); --accent-ultra-dark: hsl(var(--accent-h), var(--accent-s), var(--ultra-dark)); --accent-trans-80: hsla(var(--accent-h), var(--accent-s), var(--accent-l), .8); --accent-trans-60: hsla(var(--accent-h), var(--accent-s), var(--accent-l), .6); --accent-trans-40: hsla(var(--accent-h), var(--accent-s), var(--accent-l), .4); --accent-trans-20: hsla(var(--accent-h), var(--accent-s), var(--accent-l), .2); --accent-comp: hsl(calc(var(--accent-h) + 180), var(--accent-s), var(--accent-l)); --base: hsl(var(--base-h), var(--base-s), var(--base-l)); --base-ultra-light: hsl(var(--base-h), var(--base-s), var(--ultra-light)); --base-light: hsl(var(--base-h), var(--base-s), var(--light)); --base-dark: hsl(var(--base-h), var(--secondary-s), var(--dark)); --base-ultra-dark: hsl(var(--base-h), var(--base-s), var(--ultra-dark)); --base-trans-80: hsla(var(--base-h), var(--base-s), var(--base-l), .8); --base-trans-60: hsla(var(--base-h), var(--base-s), var(--base-l), .6); --base-trans-40: hsla(var(--base-h), var(--base-s), var(--base-l), .4); --base-trans-20: hsla(var(--base-h), var(--base-s), var(--base-l), .2); --base-comp: hsl(calc(var(--base-h) + 180), var(--base-s), var(--base-l)); /*** END COLOR SYSTEM ***/ }
Have you tried in GenerateBlocks 1.4.0-alpha?: https://generateblocks.com/generateblocks-1-4-0/
It should accept
var()
values in the color picker.Let me know ??
thanks for the help me issue is solved for the site apks.trendytaste.xyz
Color system behaviour in GPress & GBlocks (Alpha Versions):
Variable colors declared in style.css of the child theme:
– can be applied to elements both from customizer and gutenberg page editor;
– in the customizer, my variable colors from style.css can be declared as Global Colors too (for example “global-color-1” can have my primary color from style.css if instead of hex color, i put “var(–primary) in the dedicated field when editing the respective global color;
– they work the same in both the customizer and editor, indifferently of being applied directly, using “var(–primary)” or indirectly, by declaring “var(primary)” as the “global-color-1” in the customizer
– in both the customizer and gutenberg editor, the variable colors are not rendered correctly in the picker circles; all variable colors from style.css are shown in picker as dark-grey;
– the same dark grey in customizer if i try to declare Stackable custom colors as global in customizer;
– the custom colors set in Stackable cannot be declared as Global Colors in customizer, but they are seen in the picker and applied correctly when coloring particular customizer elements (backgrounds, text etc);
– while working in gutenberg editor, the transformation applied with variable colors declared in style.css is not visible in real time in the editor, but the variable color is applied anyway, visible only when reloading the page from an incognito window.Working with Central Color Palette plugin:
– it works: the colors of the circles in the picker are seen correctly and can be applied both in editor and customizer…
– but if the color is changed in CCP, the change does not reflect itself in the elements colored with the respective color…
– to apply a CCP color from the picker works, but to apply directly the “var” with the CCP color name doesnt work… probably the theme does not recognize the CCP colors names as variables… but the CCP colors are integrated with the picker when creating GP Global Colors from the GP customizer, so the colors created in the customizer from CCP colors are applied and updated correctly, updating everywhere any changes done in the CCP…CCP worked best, but sadly, i cannot use it, because i want my color system to be with calculated values (as in my message above) : when i change the primary color, all other colors from the palette to be changed automatically to a new eye-pleasing palette, using programmed HSL values which respect golden ratio and other design rules… ??
For example, the secondary color should be complementary to primary (which can be quantified numerically in HSL) AND its saturation could be 1.618 higher or lower, to introduce a difference using Fibonacci number… the result will be mathematically, easy, automatically pleasing to the eye…I think that implementing some ways to ease the application of such methods in GP would be a formidable selling proposition for all the designers, since no other theme or pagebuilder is able to do something like that now…
- This reply was modified 3 years, 2 months ago by Calin MANESCU.
Here is a useful topic about the integration of CCP colors as variables system-wide https://www.ads-software.com/support/topic/create-css-color-variables-from-within-this-plugin/
Anyway, the best and simplest solution would be to put in GP customizer (as global colors) the variable colors declared in :root, but to enable them to be seen correctly in the picker and in the gutenberg editor, only for a better UX and convenience (as they are basically already working as desired).
- The topic ‘code for automatically generated HSL color scheme’ is closed to new replies.