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

Theme | Add Fallback in Theme #209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Theme | Add Fallback in Theme #209

wants to merge 1 commit into from

Conversation

stherzada
Copy link

@stherzada stherzada commented Nov 7, 2024

Hi people,

I noticed an issue where older versions of Safari weren't displaying theme colors correctly due to the lack of support for OKLCH. To resolve this, I created a fallback to ensure compatibility.

This fallback will be included at the start of every new project to prevent similar issues.

Here's a demonstration:

Without fallback:
https://www.loom.com/share/7c6acd9c3c4549f09316bcea84fa9c92

With fallback:
https://www.loom.com/share/9cad4d0804b443a28f464bb00cf0dfe3

@JonasJesus42 JonasJesus42 marked this pull request as draft November 7, 2024 20:03
@stherzada stherzada changed the title [Draft] Theme | Add Fallback in Theme Theme | Add Fallback in Theme Nov 7, 2024
@stherzada stherzada marked this pull request as ready for review November 7, 2024 20:12
@@ -198,6 +198,29 @@ const toVariables = (
"--inc": t["info-content"] ?? contrasted(t["info"]),
}).map(([key, color]) => [key, toValue(color)] as [string, string]);

const fallbackVariables = Object.entries({
"--fallback-p": t["primary"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daisy UI theme uses the fallback variables as follow:

"primary": "var(--fallback-p,oklch(var(--p)/<alpha-value>))",

So, if fallback-* is used, the other variables are ignored.

Those variables should be set ONLY if oklch is not supported by browser.

See https://github.com/saadeghi/daisyui/blob/master/src/base/colors.css to a better approach:

@supports not (color: oklch(0% 0 0)) {
  :root {
    color-scheme: light;
    --fallback-p: #491eff;
    --fallback-pc: #d4dbff;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants