-
I am currently facing a problem that I didn't expect. Previously, I was using a simple stylex.js file with some tokens, with something like: // vars.stylex.ts
const supports_okhsl = "@supports (color: oklch(0% 0 0))";
// .... and some other @ rules
export const colors = css.defineVars({
main: {
default: "rgb(0 161 255)",
[supports_okhsl]: "oklch(0.7 0.2 250)",
},
// ... more token
}) That said, in some cases, I would like to rely on some values outside of RSD/stylex environment like the following:
So first thing I tried, I changed the way things are exported to be able to reuse some stuff without // vars.stylex.ts
export const supports_okhsl = "@supports (color: oklch(0% 0 0))";
// .... and some other @ rules
export const colorVars = {
main: {
default: "rgb(0 161 255)",
[supports_okhsl]: "oklch(0.7 0.2 250)",
},
// ... more token
})
export const colors = css.defineVars(colorVars) Problem is that in those envs outside of stylex setup (nextjs) I cannot use stylex babel plugin, so I am getting the style "cannot be used in runtime" issue (which make sense because stylex need that). So I tried another approach, to be able to share "raw values" that I could import in dumb case, and also in stylex files ( // rawVars.ts
export const supports_okhsl = "@supports (color: oklch(0% 0 0))";
// .... and some other @ rules
export const colorVars = {
main: {
default: "rgb(0 161 255)",
[supports_okhsl]: "oklch(0.7 0.2 250)",
},
// ... more token
}) // vars.stylex.ts
import { supports_okhsl, /*...*/, colorsVars } from "@src/rawVars"
export const colors = css.defineVars(colorVars) But when I do that, I am getting So my question will be kinda stupid but what is a good setup so I can reuse some shared values inside and outside of stylex scope ? Also, for thing like a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The problem with importing those objects into the file that calls Let me know if that does the trick.
Sorry that was probably a confusing error since you were actually calling
Yeah good idea. We'll try to update the docs for both projects to help clarify the constraints of a built-time compiler. |
Beta Was this translation helpful? Give feedback.
I guess having the plugin that would check content from other files will be a significant change that could become a pain to maintain, but is that an option ?
Currently I did this script that is taking my files from the folder the script is in (in my case
src/tokens
) and take all files that doesn't end with.stylex.ts
and generate the same files by reexportingexport const *Tokens
asexport const ${baseName} = css.defineVars(${fullName})
which is enough to make me happy for now.