Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

is it possible to save a colorpicker value as oklch? how do I go about adding that?

form theme

Started by Anna 3 days ago · 7 replies · 89 views
3 days ago

I have a theme that lets users pick a colour, bur I would like to have them as oklch values instead of hexadecimal. The Grav documentation says nothing about such an option, but I would like to make sure before I go hacking that…

If there is indeed no built in option for that, this would be my plan:

  • add a php library with colour conversion functions to my theme
  • hook into onAdminSave
  • convert hex to oklch
  • save with the new value

Any ideas would be much appreciated!

3 days ago

I have a theme that lets users pick a colour, bur I would like to have them as oklch values instead of hexadecimal.

Just curious, a user picks a color and the colorpicker returns a hex (or sRGB). What would be the benefit to convert it to oklch to store it?

2 days ago

It’s easier to use in Tailwind as that stores all its colours as oklch…

2 days ago

Tailwind provides a default color set defined using oklch. For example --color-gray-50: oklch(0.984 0.003 247.858), whould be used in css like: color: var(--color-gray-50);

I don't see why you cannot override the color variable using --color-gray-50: #FF00FF, where #FF00FF is derived from a page header variable or other variable.

I might be missing some requirement in your project though...

7 hours ago

Oh, I totally can. Sorry, I did not explain this very well: I actually manipulate the picked theme colour into different shades, and that is very easy to do if it’s oklch, but not if I’m working with hex codes…

6 hours ago

I actually manipulate the picked theme colour into different shades

That's the info that was missing...

I've not found a single reference to OKLCH in the entire getgrav github repo (core, admin, plugins, themes). Guess you'll need to search for an OKLCH lib and import it in your js/typescript code. E.g. https://oklume.com/ or https://oklch.com/

5 hours ago

Hm, I would like to do it with PHP whenever the theme settings are saved. Just convert the freshly picked colour and save it in the theme config as an extra field. Do you see any reason to use js for that?

Currently my problem is that since I would like to do that onAdminSave, I need to figure out how to hook into the new Admin bits. But I’m making a new post about that, others may well have similar problems.

5 hours ago

whenever the theme settings are saved

Ah, you want to set the color in Admin and handle it in a plugin/theme.

I need to figure out how to hook into the new Admin bits.

Read all about that in https://github.com/getgrav/grav-plugin-api

You can still use the old onAdminSave Admin-Compatible Events, but you might consider getting used to the new way of catching API calls.

Suggested topics

Topic Participants Replies Views Activity
Support · by TomW, 2 hours ago
1 11 2 hours ago
Support · by Anna, 3 days ago
5 98 5 hours ago
Support · by Anna, 5 hours ago
0 8 5 hours ago
Support · by stuart young, 2 days ago
2 65 2 days ago
Support · by BenLaKnet, 2 weeks ago
3 215 3 days ago