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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions sections/Theme/Theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

"--fallback-pc": t["primary-content"],
"--fallback-s": t["secondary"],
"--fallback-sc": t["secondary-content"],
"--fallback-a": t["tertiary"],
"--fallback-ac": t["tertiary-content"],
"--fallback-n": t["neutral"],
"--fallback-nc": t["neutral-content"],
"--fallback-b1": t["base-100"],
"--fallback-b2": t["base-200"],
"--fallback-b3": t["base-300"],
"--fallback-bc": t["base-content"],
"--fallback-in": t["info"],
"--fallback-inc": t["info-content"],
"--fallback-su": t["success"],
"--fallback-suc": t["success-content"],
"--fallback-wa": t["warning"],
"--fallback-wac": t["warning-content"],
"--fallback-er": t["error"],
"--fallback-erc": t["error-content"],
}).filter((entries): entries is [string, string] => !!entries[1]);

const miscellaneousVariables = Object.entries({
"--rounded-box": t["--rounded-box"],
"--rounded-btn": t["--rounded-btn"],
Expand All @@ -209,8 +232,8 @@ const toVariables = (
"--tab-border": t["--tab-border"],
"--tab-radius": t["--tab-radius"],
});

return [...colorVariables, ...miscellaneousVariables];
return [...colorVariables, ...fallbackVariables, ...miscellaneousVariables];
};

const defaultTheme = {
Expand Down