Closed Kesmek closed 1 year ago
This is strange indeed. I'm not sure what's different between my repo (private project) and yours, but I'm using this technique and not receiving any errors.
So this works as intended....
PandaCSS is compile time (not runtime) which means that css()
calls get computed at build time. There is no access to the prop at build time; hence, this can't work.
To solve your issue, create a CSS variable and pass it to PandaCSS through styles. Here is an example:
import { component$, useSignal } from "@builder.io/qwik";
import { css } from "~/styled-system/css";
export default component$(() => {
const opacity = useSignal(0.5);
return (
<div>
Opacity:{" "}
<input
type="range"
min="0"
max="1"
step="0.05"
value={opacity.value}
onInput$={(e) =>
(opacity.value = (e.target as HTMLInputElement).valueAsNumber)
}
/>{" "}
{opacity.value}
<Child opacity={opacity.value} />
</div>
);
});
export const Child = component$<{ opacity: number }>(({ opacity }) => {
return (
<div
class={css({
opacity: "var(--myOpacity)",
})}
style={{ "--myOpacity": opacity }}
>
Hello Qwik!
</div>
);
});
I am going to close this as working as intended... But feel free to continue the discussion or create new issues.
Oh I see, thanks for the clarification!
Which component is affected?
Qwik Rollup / Vite plugin
Describe the bug
I would like to pass some CSS to a component that's using PandaCSS
css()
function. Everything works correctly unless I try to pass CSS to the component as props, as shown on the PandaCSS docs here. The CSS does get passed to the component, as I'm able to log it for example. However attempting to use in the thecss()
function in that component is what brings up this error. The issue seems to be related to the vite-plugin-macro package somehow, although I'm not sure exactly what is causing the issue. The error:And this is how I'm attempting to use the css in props:
Reproduction
https://github.com/Kesmek/qwik-pandacss-css-props
Steps to reproduce
pnpm create qwik@latest
pnpm qwik add pandacss
pnpm upgrade @pandacss/dev -L
(The version that gets added by Qwik is quite outdated)css(style)
function.System Info
Additional Information
I'm not certain that this is actually an error based in Qwik/vite-plugin-macro so if I'm mistaken, please let me know and I'll gladly bring up this issue to the appropriate project.