You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+74-2Lines changed: 74 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# @cardstack/view-transitions
2
2
3
-
[Short description of the addon.]
3
+
Ember utilities for triggering native View Transition API animations.
4
4
5
5
## Compatibility
6
6
@@ -15,7 +15,79 @@ ember install @cardstack/view-transitions
15
15
16
16
## Usage
17
17
18
-
[Longer description of how to use the addon in apps.]
18
+
You will need to learn about the [View Transition API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) to make use of this library. This library provides some small utilities that make it convenient to use View Transitions in Ember apps.
19
+
20
+
### Animatable values
21
+
22
+
```ts
23
+
exportfunction animatable<T>(
24
+
initialValue:T,
25
+
opts?: { equals?: (a:T, b:T) =>boolean },
26
+
):Animatable<T>
27
+
28
+
exportinterfaceAnimatable<T> {
29
+
readonly current:T;
30
+
set(newValue:T):void;
31
+
}
32
+
```
33
+
34
+
Creates a value that triggers a ViewTransition whenever it changes. `current` does not update instantly when you call `set`, instead `current` is allowed to update after the ViewTransition has already snapshotted the "before" state for the View Transition.
35
+
36
+
```gts
37
+
import { animatable } from '@cardstack/view-transitions';
Animatable values are also necessarily `tracked`, for full interoperability with the rest of Ember. You can consume them like any other tracked state, and re-renders will happen automatically, with the added bonus that the DOM state before and after the re-render will be captured by the browser and can be smoothly animated.
56
+
57
+
### viewTransitionName
58
+
59
+
A modifier that sets the `view-transition-name` CSS property. Useful for programmatically assigning unique names based on model IDs, etc. Accepts any number of strings or numbers and concatenates them to form the view-transition-name.
60
+
61
+
```ts
62
+
viewTransitionName: FunctionBasedModifier<{
63
+
Args: {
64
+
Positional: (string|number)[];
65
+
};
66
+
Element:HTMLElement;
67
+
}>;
68
+
```
69
+
70
+
```gts
71
+
import { viewTransitionName } from '@cardstack/view-transitions';
72
+
<template>
73
+
{{#each @products as |product|}}
74
+
<div {{viewTransitionName "product" product.id}}>
75
+
{{product.title}}
76
+
</div>
77
+
{{/each}}
78
+
</template>
79
+
```
80
+
81
+
The critical thing to understand about the `view-transition-name` CSS property is that it must be unique on the whole page. It can appear in both the "old" and "new" states of the DOM, but can't appear simultaneously more than once. It controls which elements get captured (think: "screenshotted") during the ViewTransition, and how the old and new element correlate.
0 commit comments