@@ -101,9 +101,8 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
101101 - [ keyframes] ( #keyframes )
102102 - [ globalKeyframes] ( #globalkeyframes )
103103- [ Dynamic API] ( #dynamic-api )
104- - [ createInlineTheme] ( #createinlinetheme )
105- - [ setElementTheme] ( #setelementtheme )
106- - [ setElementVar] ( #setelementvar )
104+ - [ assignInlineVars] ( #assigninlinevars )
105+ - [ setElementVars] ( #setelementvars )
107106- [ Utility functions] ( #utility-functions )
108107 - [ calc] ( #calc )
109108- [ Thanks] ( #thanks )
@@ -761,55 +760,98 @@ We also provide a lightweight standalone package to support dynamic runtime them
761760npm install @vanilla-extract/dynamic
762761```
763762
764- ### createInlineTheme
763+ ### assignInlineVars
765764
766- Implements a theme contract at runtime as an inline style object .
765+ Assigns CSS Variables as inline styles .
767766
768- ``` ts
769- import { createInlineTheme } from ' @vanilla-extract/dynamic' ;
770- import { vars , exampleStyle } from ' ./styles.css.ts' ;
767+ ``` tsx
768+ // app.tsx
771769
772- const customTheme = createInlineTheme (vars , {
773- small: ' 4px' ,
774- medium: ' 8px' ,
775- large: ' 16px'
776- });
770+ import { assignInlineVars } from ' @vanilla-extract/dynamic' ;
771+ import { vars } from ' ./vars.css.ts' ;
772+
773+ const MyComponent = () => (
774+ <section
775+ style = { assignInlineVars ({
776+ [vars .colors .brand ]: ' pink' ,
777+ [vars .colors .accent ]: ' green'
778+ })}
779+ >
780+ ...
781+ </section >
782+ );
783+ ```
784+
785+ You can also assign collections of variables by passing a theme contract as the first argument. All variables must be assigned or it’s a type error.
786+
787+ ``` tsx
788+ // app.tsx
789+
790+ import { assignInlineVars } from ' @vanilla-extract/dynamic' ;
791+ import { vars } from ' ./vars.css.ts' ;
792+
793+ const MyComponent = () => (
794+ <section
795+ style = { assignInlineVars (vars .colors , {
796+ brand: ' pink' ,
797+ accent: ' green'
798+ })}
799+ >
800+ ...
801+ </section >
802+ );
803+ ```
804+
805+ Even though this function returns an object of inline styles, its ` toString ` method returns a valid ` style ` attribute value so that it can be used in string templates.
806+
807+ ``` tsx
808+ // app.ts
809+
810+ import { assignInlineVars } from ' @vanilla-extract/dynamic' ;
811+ import { vars } from ' ./vars.css.ts' ;
777812
778813document .write (`
779- <section style="${customTheme }">
780- <h1 class="${exampleStyle }">Hello world!</h1>
814+ <section style="${assignInlineVars ({
815+ [vars .colors .brand ]: ' pink' ,
816+ [vars .colors .accent ]: ' green'
817+ })}">
818+ ...
781819 </section>
782820` );
783821```
784822
785- ### setElementTheme
823+ ### setElementVars
786824
787- Implements a theme contract on an element.
825+ Sets CSS Variables on a DOM element.
788826
789- ``` ts
790- import { setElementTheme } from ' @vanilla-extract/dynamic' ;
827+ ``` tsx
828+ // app.ts
829+
830+ import { setElementVars } from ' @vanilla-extract/dynamic' ;
791831import { vars } from ' ./styles.css.ts' ;
792832
793- const element = document .getElementById (' myElement' );
794- setElementTheme ( element , vars , {
795- small: ' 4px ' ,
796- medium : ' 8px ' ,
797- large : ' 16px '
833+ const el = document .getElementById (' myElement' );
834+
835+ setElementVars ( el , {
836+ [ vars . colors . brand ] : ' pink ' ,
837+ [ vars . colors . accent ] : ' green '
798838});
799839```
800840
801- > 💡 All variables passed into this function must be assigned or it’s a type error.
802-
803- ### setElementVar
841+ You can also set collections of variables by passing a theme contract as the second argument. All variables must be set or it’s a type error.
804842
805- Sets a single var on an element.
843+ ``` tsx
844+ // app.ts
806845
807- ``` ts
808- import { setElementVar } from ' @vanilla-extract/dynamic' ;
846+ import { setElementVars } from ' @vanilla-extract/dynamic' ;
809847import { vars } from ' ./styles.css.ts' ;
810848
811- const element = document .getElementById (' myElement' );
812- setElementVar (element , vars .color .brand , ' darksalmon' );
849+ const el = document .getElementById (' myElement' );
850+
851+ setElementVars (el , vars .colors , {
852+ brand: ' pink' ,
853+ accent: ' green'
854+ });
813855```
814856
815857## Utility functions
0 commit comments