|
1 | 1 | # @vanilla-extract/dynamic |
2 | 2 |
|
3 | | -## 1.0.0 |
| 3 | +## 2.0.0 |
| 4 | + |
4 | 5 | ### Major Changes |
5 | 6 |
|
| 7 | +- [#276](https://github.com/seek-oss/vanilla-extract/pull/276) [`4bcbd6f`](https://github.com/seek-oss/vanilla-extract/commit/4bcbd6f4ac0170a09553ce8d44ca84361782cce5) Thanks [@markdalgleish](https://github.com/markdalgleish)! - Add `assignInlineVars` and `setElementVars` functions |
6 | 8 |
|
| 9 | + **assignInlineVars** |
7 | 10 |
|
8 | | -- [#171](https://github.com/seek-oss/vanilla-extract/pull/171) [`84a8611`](https://github.com/seek-oss/vanilla-extract/commit/84a8611972f32a00a6cbd85267a01dd2d31be869) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Release v1 |
| 11 | + Assigns CSS Variables as inline styles. |
| 12 | + |
| 13 | + ```tsx |
| 14 | + // app.tsx |
| 15 | + |
| 16 | + import { assignInlineVars } from '@vanilla-extract/dynamic'; |
| 17 | + import { vars } from './vars.css.ts'; |
| 18 | + |
| 19 | + const MyComponent = () => ( |
| 20 | + <section |
| 21 | + style={assignInlineVars({ |
| 22 | + [vars.colors.brand]: 'pink', |
| 23 | + [vars.colors.accent]: 'green', |
| 24 | + })} |
| 25 | + > |
| 26 | + ... |
| 27 | + </section> |
| 28 | + ); |
| 29 | + ``` |
| 30 | + |
| 31 | + 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. |
| 32 | + |
| 33 | + ```tsx |
| 34 | + // app.tsx |
| 35 | + |
| 36 | + import { assignInlineVars } from '@vanilla-extract/dynamic'; |
| 37 | + import { vars } from './vars.css.ts'; |
| 38 | + |
| 39 | + const MyComponent = () => ( |
| 40 | + <section |
| 41 | + style={assignInlineVars(vars.colors, { |
| 42 | + brand: 'pink', |
| 43 | + accent: 'green', |
| 44 | + })} |
| 45 | + > |
| 46 | + ... |
| 47 | + </section> |
| 48 | + ); |
| 49 | + ``` |
| 50 | + |
| 51 | + 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. |
| 52 | + |
| 53 | + ```tsx |
| 54 | + // app.ts |
| 55 | + |
| 56 | + import { assignInlineVars } from '@vanilla-extract/dynamic'; |
| 57 | + import { vars } from './vars.css.ts'; |
| 58 | + |
| 59 | + document.write(` |
| 60 | + <section style="${assignInlineVars({ |
| 61 | + [vars.colors.brand]: 'pink', |
| 62 | + [vars.colors.accent]: 'green', |
| 63 | + })}"> |
| 64 | + ... |
| 65 | + </section> |
| 66 | + `); |
| 67 | + ``` |
| 68 | + |
| 69 | + **setElementVars** |
| 70 | + |
| 71 | + Sets CSS Variables on a DOM element. |
| 72 | + |
| 73 | + ```tsx |
| 74 | + // app.ts |
| 75 | + |
| 76 | + import { setElementVars } from '@vanilla-extract/dynamic'; |
| 77 | + import { vars } from './styles.css.ts'; |
| 78 | + |
| 79 | + const el = document.getElementById('myElement'); |
9 | 80 |
|
| 81 | + setElementVars(el, { |
| 82 | + [vars.colors.brand]: 'pink', |
| 83 | + [vars.colors.accent]: 'green', |
| 84 | + }); |
| 85 | + ``` |
| 86 | + |
| 87 | + 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. |
| 88 | + |
| 89 | + ```tsx |
| 90 | + // app.ts |
| 91 | + |
| 92 | + import { setElementVars } from '@vanilla-extract/dynamic'; |
| 93 | + import { vars } from './styles.css.ts'; |
| 94 | + |
| 95 | + const el = document.getElementById('myElement'); |
| 96 | + |
| 97 | + setElementVars(el, vars.colors, { |
| 98 | + brand: 'pink', |
| 99 | + accent: 'green', |
| 100 | + }); |
| 101 | + ``` |
| 102 | + |
| 103 | + **BREAKING CHANGE** |
| 104 | + |
| 105 | + These functions replace `createInlineTheme`, `setElementTheme` and `setElementVar`. |
| 106 | + |
| 107 | + `assignInlineVars` works as a drop-in replacement for `createInlineTheme`. |
| 108 | + |
| 109 | + ```diff |
| 110 | + -createInlineTheme(vars, { brandColor: 'red' }); |
| 111 | + +assignInlineVars(vars, { brandColor: 'red' }); |
| 112 | + ``` |
| 113 | + |
| 114 | + `setElementVars` works as a drop-in replacement for `setElementTheme`. |
| 115 | + |
| 116 | + ```diff |
| 117 | + -setElementTheme(el, vars, { brandColor: 'red' }); |
| 118 | + +setElementVars(el, vars, { brandColor: 'red' }); |
| 119 | + ``` |
| 120 | + |
| 121 | + You can replicate the functionality of `setElementVar` by passing an object with dynamic keys to `setElementVars`. This now makes it easy to support setting multiple vars at once. |
| 122 | + |
| 123 | + ```diff |
| 124 | + -setElementVar(el, vars.brandColor, 'red'); |
| 125 | + +setElementVars(el, { |
| 126 | + + [vars.brandColor]: 'red' |
| 127 | + +}); |
| 128 | + ``` |
| 129 | + |
| 130 | +## 1.0.0 |
| 131 | + |
| 132 | +### Major Changes |
| 133 | + |
| 134 | +- [#171](https://github.com/seek-oss/vanilla-extract/pull/171) [`84a8611`](https://github.com/seek-oss/vanilla-extract/commit/84a8611972f32a00a6cbd85267a01dd2d31be869) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Release v1 |
10 | 135 |
|
11 | 136 | ### Patch Changes |
12 | 137 |
|
|
0 commit comments