Skip to content

Commit 7b256d2

Browse files
wuzaskoufis
andauthored
Add createViewTransition function (#1450)
Co-authored-by: Adam Skoufis <[email protected]>
1 parent d271b9f commit 7b256d2

File tree

8 files changed

+86
-0
lines changed

8 files changed

+86
-0
lines changed

.changeset/good-wombats-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vanilla-extract/babel-plugin-debug-ids": minor
3+
---
4+
5+
Add support for the new `createViewTransition` API

.changeset/purple-cheetahs-hear.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"@vanilla-extract/css": minor
3+
---
4+
5+
Add `createViewTransition` API
6+
7+
`createViewTransition` creates a single scoped view transition name for use with CSS View Transitions. This avoids potential naming collisions with other view transitions.
8+
9+
```ts
10+
import {
11+
style,
12+
createViewTransition
13+
} from '@vanilla-extract/css';
14+
15+
export const titleViewTransition = createViewTransition();
16+
17+
export const pageTitle = style({
18+
viewTransitionName: titleViewTransition
19+
});
20+
``

packages/babel-plugin-debug-ids/src/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ describe('babel plugin', () => {
230230
`);
231231
});
232232

233+
it('should handle createViewTransition assigned to const', () => {
234+
const source = `
235+
import { createViewTransition } from '@vanilla-extract/css';
236+
237+
const myViewTransition = createViewTransition();
238+
`;
239+
240+
expect(transform(source)).toMatchInlineSnapshot(`
241+
import { createViewTransition } from '@vanilla-extract/css';
242+
const myViewTransition = createViewTransition("myViewTransition");
243+
`);
244+
});
245+
233246
it('should handle fontFace assigned to const', () => {
234247
const source = `
235248
import { fontFace } from '@vanilla-extract/css';

packages/babel-plugin-debug-ids/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const debuggableFunctionConfig = {
3939
createContainer: {
4040
maxParams: 1,
4141
},
42+
createViewTransition: {
43+
maxParams: 1,
44+
},
4245
layer: {
4346
maxParams: 2,
4447
hasDebugId: ({ arguments: args }) => {

packages/css/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export * from './theme';
1313
export * from './style';
1414
export * from './vars';
1515
export { createContainer } from './container';
16+
export { createViewTransition } from './viewTransition';
1617
export * from './layer';

packages/css/src/viewTransition.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { generateIdentifier } from './identifier';
2+
3+
// createViewTransition is used for locally scoping CSS view transitions
4+
// For now it is mostly just an alias of generateIdentifier
5+
export const createViewTransition = (debugId?: string) =>
6+
generateIdentifier(debugId);

site/contents.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const contents = [
2525
'keyframes',
2626
'create-container',
2727
'layer',
28+
'create-view-transition',
2829
'add-function-serializer',
2930
],
3031
},
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: createViewTransition
3+
parent: api
4+
---
5+
6+
# createViewTransition
7+
8+
Creates a single scoped view transition name for use with [CSS View Transitions].
9+
This avoids potential naming collisions with other view transitions.
10+
11+
> 🚧&nbsp;&nbsp;Ensure your target browsers [support view transitions].
12+
> Vanilla-extract supports the [view transition syntax][css view transitions] but does not polyfill the feature in unsupported browsers.
13+
14+
```ts compiled
15+
// itemPage.css.ts
16+
import {
17+
style,
18+
createViewTransition
19+
} from '@vanilla-extract/css';
20+
21+
export const titleViewTransition = createViewTransition();
22+
23+
export const pageTitle = style({
24+
viewTransitionName: titleViewTransition
25+
});
26+
27+
// navigation.css.ts
28+
import { style } from '@vanilla-extract/css';
29+
import { titleViewTransition } from './itemPage.css.ts';
30+
31+
export const navigationLinkTitle = style({
32+
viewTransitionName: titleViewTransition
33+
});
34+
```
35+
36+
[css view transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API#css_additions
37+
[support view transitions]: https://caniuse.com/view-transitions

0 commit comments

Comments
 (0)