Replies: 1 comment
-
I'm currently tackling this using a JavaScript plugin and accessing the (likely unsafe) /** @param {number} [value] */
function isInlineThemeReference(value) {
if (!value) return false;
if (value & (1 << 0)) return true;
if (value & (1 << 1)) return true;
return false;
}
/**
* @param {string} namespace
* @param {string} token
* @param {string} [defaultValue]
*/
function t(namespace, token, defaultValue) {
const options = theme(namespace)?.__CSS_VALUES__?.[token];
const key = `--${namespace}-${token}`;
if (isInlineThemeReference(options)) {
return theme(key, defaultValue);
}
return `var(${key})`;
};
t("color", "accent"); // Returns var(--color-accent) or the inline value |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This question relates to this discussion, where I asked about
--value()
and--modifier()
.If I understand correctly, outside of a functional utility, there are two ways to retrieve a theme value:
var(--prop)
and--theme(--prop)
. However, they seem to ignore the@theme
options (such asinline
), meaning that--theme(--prop)
still returns the inline value even if the theme isn’t set that way. Similarly,var(--prop)
disregards@theme inline
, which is reasonable but leaves us without a method to obtain the value based on the@theme
options.I'd expect
--theme(--prop)
(or another function) to output eithervar(--prop)
or the inline value depending on whether theinline
option was set on@theme
.It's probably too late to change
--theme()
though, but I'm wondering if there's another way to do it.Beta Was this translation helpful? Give feedback.
All reactions