Is it possible to expose Vanilla Extract vars as part of component library? #1009
-
Hello, I have a question -- I'm building a component library using I basically want to expose an "escape-hatch" hook along the lines of // tokens would contain all the vanilla-extract defined vars that I used internally
const { tokens } = useTheme(). Is this possible to do? I know |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This is definitely possible. Any vars (tokens) you create, whether that be with As a small suggestion, I'd advise against exposing your tokens via a hook, if possible. Unless there's a specific reason you need to use a hook, a simpler approach could just be to document an exported |
Beta Was this translation helpful? Give feedback.
This is definitely possible. Any vars (tokens) you create, whether that be with
createVar
,createThemeContract
, or other APIs, are just strings. They can safely be exported from a.css.ts
file and used within other styles (.css.ts
files) or even at runtime in your components, just like how styles created with thestyle
function are compiled away, but can still be referenced via their classname string (this is what ends up being exported in your.css.ts
file).As a small suggestion, I'd advise against exposing your tokens via a hook, if possible. Unless there's a specific reason you need to use a hook, a simpler approach could just be to document an exported
vars
ortokens
object in your p…