@@ -102,6 +102,8 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
102102 - [ globalFontFace] ( #globalfontface )
103103 - [ keyframes] ( #keyframes )
104104 - [ globalKeyframes] ( #globalkeyframes )
105+ - [ Recipes API] ( #recipes-api )
106+ - [ recipe] ( #recipe )
105107- [ Dynamic API] ( #dynamic-api )
106108 - [ assignInlineVars] ( #assigninlinevars )
107109 - [ setElementVars] ( #setelementvars )
@@ -936,9 +938,117 @@ export const animated = style({
936938});
937939```
938940
941+ ## Recipes API
942+
943+ Create multi-variant styles with a type-safe runtime API, heavily inspired by [ Stitches.] ( https://stitches.dev )
944+
945+ As with the rest of vanilla-extract, all styles are generated at build time.
946+
947+ ``` bash
948+ $ npm install @vanilla-extract/recipes
949+ ```
950+
951+ ### recipe
952+
953+ Creates a multi-variant style function that can be used at runtime or statically in ` .css.ts ` files.
954+
955+ Accepts an optional set of ` base ` styles, ` variants ` , ` compoundVariants ` and ` defaultVariants ` .
956+
957+ ``` ts
958+ import { recipe } from ' @vanilla-extract/recipes' ;
959+
960+ export const button = recipe ({
961+ base: {
962+ borderRadius: 6
963+ },
964+
965+ variants: {
966+ color: {
967+ neutral: { background: ' whitesmoke' },
968+ brand: { background: ' blueviolet' },
969+ accent: { background: ' slateblue' }
970+ },
971+ size: {
972+ small: { padding: 12 },
973+ medium: { padding: 16 },
974+ large: { padding: 24 }
975+ },
976+ rounded: {
977+ true: { borderRadius: 999 }
978+ }
979+ },
980+
981+ // Applied when multiple variants are set at once
982+ compoundVariants: [
983+ {
984+ variants: {
985+ color: ' neutral' ,
986+ size: ' large'
987+ },
988+ style: {
989+ background: ' ghostwhite'
990+ }
991+ }
992+ ],
993+
994+ defaultVariants: {
995+ color: ' accent' ,
996+ size: ' medium'
997+ }
998+ });
999+ ```
1000+
1001+ With this recipe configured, you can now use it in your templates.
1002+
1003+ ``` ts
1004+ import { button } from ' ./button.css.ts' ;
1005+
1006+ document .write (`
1007+ <button class="${button ({
1008+ color: ' accent' ,
1009+ size: ' large' ,
1010+ rounded: true
1011+ })}">
1012+ Hello world
1013+ </button>
1014+ ` );
1015+ ```
1016+
1017+ Your recipe configuration can also make use of existing variables, classes and styles.
1018+
1019+ For example, you can use your ` atoms ` function from [ Sprinkles.] ( https://github.com/seek-oss/vanilla-extract/tree/master/packages/sprinkles )
1020+
1021+ ``` ts
1022+ import { recipe } from ' @vanilla-extract/recipes' ;
1023+ import { reset } from ' ./reset.css.ts' ;
1024+ import { atoms } from ' ./sprinkles.css.ts' ;
1025+
1026+ export const button = recipe ({
1027+ base: [reset , atoms ({ borderRadius: ' round' })],
1028+
1029+ variants: {
1030+ color: {
1031+ neutral: atoms ({ background: ' neutral' }),
1032+ brand: atoms ({ background: ' brand' }),
1033+ accent: atoms ({ background: ' accent' })
1034+ },
1035+ size: {
1036+ small: atoms ({ padding: ' small' }),
1037+ medium: atoms ({ padding: ' medium' }),
1038+ large: atoms ({ padding: ' large' })
1039+ }
1040+ },
1041+
1042+ defaultVariants: {
1043+ color: ' accent' ,
1044+ size: ' medium'
1045+ }
1046+ });
1047+ ```
1048+
9391049## Dynamic API
9401050
941- We also provide a lightweight standalone package to support dynamic runtime theming .
1051+ Dynamically update theme variables at runtime.
9421052
9431053``` bash
9441054npm install @vanilla-extract/dynamic
0 commit comments