@@ -30,6 +30,8 @@ Basically, it’s [“CSS Modules](https://github.com/css-modules/css-modules)-i
3030
3131🏃♂️   ; Optional runtime version for development and testing.
3232
33+ 🙈   ; Optional API for dynamic runtime theming.
34+
3335---
3436
3537** Write your styles in ` .css.ts ` files.**
@@ -84,7 +86,6 @@ document.write(`
8486 - [ mapToStyles] ( #maptostyles )
8587 - [ createTheme] ( #createtheme )
8688 - [ createGlobalTheme] ( #createglobaltheme )
87- - [ createInlineTheme] ( #createinlinetheme )
8889 - [ createThemeVars] ( #createthemevars )
8990 - [ assignVars] ( #assignvars )
9091 - [ createVar] ( #createvar )
@@ -93,6 +94,10 @@ document.write(`
9394 - [ globalFontFace] ( #globalfontface )
9495 - [ keyframes] ( #keyframes )
9596 - [ globalKeyframes] ( #globalkeyframes )
97+ - [ Dynamic API] ( #dynamic-api )
98+ - [ createInlineTheme] ( #createinlinetheme )
99+ - [ setElementTheme] ( #setelementtheme )
100+ - [ setElementVar] ( #setelementvar )
96101- [ Utility functions] ( #utility-functions )
97102 - [ calc] ( #calc )
98103- [ Thanks] ( #thanks )
@@ -376,27 +381,6 @@ export const themeVars = createGlobalTheme(':root', {
376381
377382> 💡 All theme variants must provide a value for every variable or it’s a type error.
378383
379- ### createInlineTheme
380-
381- Generates a custom theme at runtime as an inline style object.
382-
383- ``` ts
384- import { createInlineTheme } from ' @vanilla-extract/css/createInlineTheme' ;
385- import { themeVars , exampleStyle } from ' ./styles.css.ts' ;
386-
387- const customTheme = createInlineTheme (themeVars , {
388- small: ' 4px' ,
389- medium: ' 8px' ,
390- large: ' 16px'
391- });
392-
393- document .write (`
394- <section style="${customTheme }">
395- <h1 class="${exampleStyle }">Hello world!</h1>
396- </section>
397- ` );
398- ```
399-
400384### createThemeVars
401385
402386Creates a collection of CSS Variables without coupling them to a specific theme variant.
@@ -439,7 +423,7 @@ export const themeB = createTheme(themeVars, {
439423
440424### assignVars
441425
442- Allows you to set an entire collection of CSS Variables anywhere within a style block.
426+ Assigns a collection of CSS Variables anywhere within a style block.
443427
444428> 💡 This is useful for creating responsive themes since it can be used within ` @media ` blocks.
445429
@@ -597,6 +581,65 @@ export const animated = style({
597581});
598582```
599583
584+ ## Dynamic API
585+
586+ We also provide a lightweight standalone package to support dynamic runtime theming.
587+
588+ ``` bash
589+ $ yarn add --dev @vanilla-extract/dynamic
590+ ```
591+
592+ ### createInlineTheme
593+
594+ Generates a custom theme at runtime as an inline style object.
595+
596+ ``` ts
597+ import { createInlineTheme } from ' @vanilla-extract/dynamic' ;
598+ import { themeVars , exampleStyle } from ' ./styles.css.ts' ;
599+
600+ const customTheme = createInlineTheme (themeVars , {
601+ small: ' 4px' ,
602+ medium: ' 8px' ,
603+ large: ' 16px'
604+ });
605+
606+ document .write (`
607+ <section style="${customTheme }">
608+ <h1 class="${exampleStyle }">Hello world!</h1>
609+ </section>
610+ ` );
611+ ```
612+
613+ ### setElementTheme
614+
615+ Sets a collection of CSS Variables on an element.
616+
617+ ``` ts
618+ import { setElementTheme } from ' @vanilla-extract/dynamic' ;
619+ import { themeVars } from ' ./styles.css.ts' ;
620+
621+ const element = document .getElementById (' myElement' );
622+ setElementTheme (element , themeVars , {
623+ small: ' 4px' ,
624+ medium: ' 8px' ,
625+ large: ' 16px'
626+ });
627+ ```
628+
629+ > 💡 All variables passed into this function must be assigned or it’s a type error.
630+
631+ ### setElementVar
632+
633+ Sets a single var on an element.
634+
635+ ``` ts
636+ import { setElementVar } from ' @vanilla-extract/dynamic' ;
637+ import { themeVars } from ' ./styles.css.ts' ;
638+
639+ const element = document .getElementById (' myElement' );
640+ setElementVar (element , themeVars .color .brand , ' darksalmon' );
641+ ```
642+
600643## Utility functions
601644
602645We also provide a standalone package of optional utility functions to make it easier to work with CSS in TypeScript.
0 commit comments