Skip to content

Commit f9b8ebc

Browse files
authored
Version Packages (#278)
1 parent 4bcbd6f commit f9b8ebc

File tree

5 files changed

+131
-132
lines changed

5 files changed

+131
-132
lines changed

.changeset/clever-vans-prove.md

Lines changed: 0 additions & 126 deletions
This file was deleted.

fixtures/themed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"private": true,
88
"dependencies": {
99
"@vanilla-extract/css": "1.2.2",
10-
"@vanilla-extract/dynamic": "1.0.0"
10+
"@vanilla-extract/dynamic": "2.0.0"
1111
}
1212
}

packages/dynamic/CHANGELOG.md

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,137 @@
11
# @vanilla-extract/dynamic
22

3-
## 1.0.0
3+
## 2.0.0
4+
45
### Major Changes
56

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
68

9+
**assignInlineVars**
710

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');
980

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
10135

11136
### Patch Changes
12137

packages/dynamic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vanilla-extract/dynamic",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Zero-runtime Stylesheets-in-TypeScript",
55
"sideEffects": false,
66
"main": "dist/vanilla-extract-dynamic.cjs.js",

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ __metadata:
17731773
resolution: "@fixtures/themed@workspace:fixtures/themed"
17741774
dependencies:
17751775
"@vanilla-extract/css": 1.2.2
1776-
"@vanilla-extract/dynamic": 1.0.0
1776+
"@vanilla-extract/dynamic": 2.0.0
17771777
languageName: unknown
17781778
linkType: soft
17791779

@@ -3199,7 +3199,7 @@ __metadata:
31993199
languageName: unknown
32003200
linkType: soft
32013201

3202-
"@vanilla-extract/dynamic@1.0.0, @vanilla-extract/dynamic@workspace:packages/dynamic":
3202+
"@vanilla-extract/dynamic@2.0.0, @vanilla-extract/dynamic@workspace:packages/dynamic":
32033203
version: 0.0.0-use.local
32043204
resolution: "@vanilla-extract/dynamic@workspace:packages/dynamic"
32053205
dependencies:

0 commit comments

Comments
 (0)