So as you can see, this part has added but it's not working because we're not using the values of the theme. So I go back to my button.css.ts and for the background color, I'm going to import the vars that I exported there in my theme and here I'm going to say pick the colors primary and main. And I'm going to use another one here. So I want the color black. Look at that. Autocomplete. Oh my god. It's so exciting. So and then I'm going to use the dark theme for my hover and for my outline, I'm going to use another color. So I'm just going to go with grey and main. Now let's go back to our computer. Go to our browser and as you can see the theme has been applied and now let's switch theme. We have our two colors in two themes within a few minutes.
So in the component packages, it normally happens that we want to pass in a prop to our component like a variant, a type, a size, and then based on the prop that we pass to the component we want to be able to change our design and our styling of the component. So for that we need to use recipe. So to start implementing that I'm going to replace the style with the recipe function and I need to move all of these stylings under base. So it's going to be the basis styling of my component. So I'm going to comment out these because we are going to move them in another section and recipe provides a variant, oh sorry, I guess variance, yes. So variance can be anything from type to size, even it can be a boolean like disabled. So here I'm just going to create a type variant and I want my type variant to have a fill and then I want it to have outline. So these are going to be different types of my bun and I want a simple text type without any background or anything. So now we need to add all the styling for each and every of these types that is supposed to overwrite the base styling that we have up here. So I have it ready so I'm going to copy and paste it from my notes. So if I can, apparently, I use my ability to copy and paste. And the text. So here we go. It's just simply adding background and hover for each type. But there is one more thing that we need to do. We need to tell Banyuda Extract which one is our default variant. So we say, for default variants, for type, I want it to be fill. And since it's TypeScript, it's fully typed, so it has great suggestions. If we want to implement that into a button, normally what you should do is to add the type here, and then you need to add it to your props type, but then you have to follow the exact naming from your styling, and keeping these in sync over time is a hustle. So you got to go, type, I want it to be fill, and then blah, blah, and keeping that consistent over time is really hard, but you don't really have to do that with Vanilla Xtract, there is a tool, so I'm going to say, I'm going to export button variant, and I'm going to use recipe, recipe, help me, oh my god, oh, sorry, my bad, I need to, okay, there you go, and I'm going to say get all the types from button style, and button style is not a class anymore, so it's whatever is returned from recipe. So now go back to our component and I will import the type that I have just created, what's called bun variants, there you go, and then I'm going to add my new prop, and here we're going to say for my class name, now the bun side as I mentioned is not a simple string anymore, it's a function and you pass in your type prop here, and based on the prop that you're passing it will return the correct class that you need for your component. So there's one last thing that I need to do, is to add these props here, so I want to have outline, and then I want to have text, and the first one it has a default value which is fill. Now let's go back to our browser, and ta-da, we have three variants of the same button, Let's see if the theme works, and yes it does, and as easy as that, within a few minutes I have been able to create a button with three variations and two themes, and that's the power of vanilla extract.
Comments