Cannot use conditions inside custom utilities #2825
Replies: 3 comments 2 replies
-
I thought the base part was removed when declaring CSS. I haven't created and used the utility, but I've tried to reproduce it and it looks like I can't use the conditional style primaryBorderNoWorks: {
values: { type: 'boolean' },
transform(value) {
if (!value) return {};
return {
border:'1px solid black',
"&:hover":{
border:'1px solid blue'
},
"&:disabled":{
border:'1px solid gray'
}
};
},
}, If you try it with this code, it should work as you want! |
Beta Was this translation helpful? Give feedback.
-
That's nice for a workaround. Definitely better DX if we could use the utilities though... |
Beta Was this translation helpful? Give feedback.
-
This is by design. Utilities are Panda's fundamental building block and should transform directly into CSS objects. This is important for performance and speed. I'd recommend that you import the default conditions and use them in the selectors if you need to reference them. If you're trying to shorten the className, you probably want to use a config recipe instead. |
Beta Was this translation helpful? Give feedback.
-
Description
I'm creating a design system with Panda. We have many components that change color or background color for hover/active/disabled states. Result is there are a lot of classes added to simple elements (like buttons) 4 classes for color and 4 classes for background color, maybe 4 classes for border.
I had an idea that if we could create utilities that group the base + states for a color option (like primary text color) we could get one class instead of four, taking components that need to set color/background color/border down from 12 classes to 3. Utilities are also highly reusable across different components.
But I was sad to find out, that conditions are not supported inside utilities...
I'm not sure if this is a bug, or just an unsupported feature?
Link to Reproduction
https://stackblitz.com/edit/vitejs-vite-qwrsbf?file=src%2FApp.tsx
Steps to reproduce
primaryBorderWorks
only setsborder
and works fineJS Framework
React
Panda CSS Version
latest
Browser
No response
Operating System
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions