@ydant/transition 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -63
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,10 +12,11 @@ pnpm add @ydant/transition
|
|
|
12
12
|
|
|
13
13
|
### Transition (Enter-only)
|
|
14
14
|
|
|
15
|
-
For simple show/hide with enter animation
|
|
15
|
+
For simple show/hide with enter animation:
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import {
|
|
18
|
+
import { mount, type Component } from "@ydant/core";
|
|
19
|
+
import { createBasePlugin, div, button, text, on, type Slot } from "@ydant/base";
|
|
19
20
|
import { Transition } from "@ydant/transition";
|
|
20
21
|
|
|
21
22
|
const App: Component = () => {
|
|
@@ -29,7 +30,9 @@ const App: Component = () => {
|
|
|
29
30
|
transitionSlot.refresh(() =>
|
|
30
31
|
Transition({
|
|
31
32
|
show,
|
|
32
|
-
|
|
33
|
+
enter: "transition-opacity duration-300",
|
|
34
|
+
enterFrom: "opacity-0",
|
|
35
|
+
enterTo: "opacity-100",
|
|
33
36
|
children: () => div(() => [text("Fade me!")]),
|
|
34
37
|
}),
|
|
35
38
|
);
|
|
@@ -40,7 +43,9 @@ const App: Component = () => {
|
|
|
40
43
|
transitionSlot = yield* div(() =>
|
|
41
44
|
Transition({
|
|
42
45
|
show,
|
|
43
|
-
|
|
46
|
+
enter: "transition-opacity duration-300",
|
|
47
|
+
enterFrom: "opacity-0",
|
|
48
|
+
enterTo: "opacity-100",
|
|
44
49
|
children: () => div(() => [text("Fade me!")]),
|
|
45
50
|
}),
|
|
46
51
|
);
|
|
@@ -53,7 +58,8 @@ const App: Component = () => {
|
|
|
53
58
|
For full enter/leave animation support with programmatic control:
|
|
54
59
|
|
|
55
60
|
```typescript
|
|
56
|
-
import {
|
|
61
|
+
import { type Component } from "@ydant/core";
|
|
62
|
+
import { div, button, text, on } from "@ydant/base";
|
|
57
63
|
import { createTransition, type TransitionHandle } from "@ydant/transition";
|
|
58
64
|
|
|
59
65
|
const App: Component = () => {
|
|
@@ -83,18 +89,7 @@ const App: Component = () => {
|
|
|
83
89
|
|
|
84
90
|
### CSS Classes
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
| Class | When Applied |
|
|
89
|
-
| --------------------- | -------------- |
|
|
90
|
-
| `{name}-enter` | Start of enter |
|
|
91
|
-
| `{name}-enter-active` | During enter |
|
|
92
|
-
| `{name}-enter-to` | End of enter |
|
|
93
|
-
| `{name}-leave` | Start of leave |
|
|
94
|
-
| `{name}-leave-active` | During leave |
|
|
95
|
-
| `{name}-leave-to` | End of leave |
|
|
96
|
-
|
|
97
|
-
#### For `createTransition` (explicit classes)
|
|
92
|
+
Both `Transition` and `createTransition` use explicit class props:
|
|
98
93
|
|
|
99
94
|
| Prop | When Applied |
|
|
100
95
|
| ----------- | -------------------------- |
|
|
@@ -105,21 +100,11 @@ const App: Component = () => {
|
|
|
105
100
|
| `leaveFrom` | Initial state before leave |
|
|
106
101
|
| `leaveTo` | Final state after leave |
|
|
107
102
|
|
|
103
|
+
All props are optional. Classes are applied as space-separated strings (e.g. Tailwind CSS compatible).
|
|
104
|
+
|
|
108
105
|
### Example CSS
|
|
109
106
|
|
|
110
107
|
```css
|
|
111
|
-
/* For Transition (name="fade") */
|
|
112
|
-
.fade-enter-active,
|
|
113
|
-
.fade-leave-active {
|
|
114
|
-
transition: opacity 0.3s ease;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.fade-enter,
|
|
118
|
-
.fade-leave-to {
|
|
119
|
-
opacity: 0;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/* For createTransition */
|
|
123
108
|
.fade-enter {
|
|
124
109
|
transition: opacity 300ms ease;
|
|
125
110
|
}
|
|
@@ -145,60 +130,83 @@ const App: Component = () => {
|
|
|
145
130
|
For animating lists of items:
|
|
146
131
|
|
|
147
132
|
```typescript
|
|
148
|
-
import {
|
|
133
|
+
import { type Component } from "@ydant/core";
|
|
134
|
+
import { div, text } from "@ydant/base";
|
|
135
|
+
import { TransitionGroup, createTransitionGroupRefresher } from "@ydant/transition";
|
|
149
136
|
|
|
150
137
|
const App: Component = () => {
|
|
151
|
-
const items = [
|
|
138
|
+
const items = [
|
|
139
|
+
{ id: 1, text: "Item 1" },
|
|
140
|
+
{ id: 2, text: "Item 2" },
|
|
141
|
+
];
|
|
152
142
|
|
|
153
143
|
return div(function* () {
|
|
154
|
-
const
|
|
155
|
-
name: "list",
|
|
144
|
+
const slot = yield* TransitionGroup({
|
|
156
145
|
items,
|
|
157
146
|
keyFn: (item) => item.id,
|
|
158
|
-
|
|
147
|
+
enter: "transition-opacity duration-300",
|
|
148
|
+
enterFrom: "opacity-0",
|
|
149
|
+
enterTo: "opacity-100",
|
|
150
|
+
leave: "transition-opacity duration-300",
|
|
151
|
+
leaveFrom: "opacity-100",
|
|
152
|
+
leaveTo: "opacity-0",
|
|
153
|
+
children: (item) => div(() => [text(item.text)]),
|
|
159
154
|
});
|
|
160
155
|
|
|
161
|
-
// To update
|
|
162
|
-
// items.push({ id: 2, text: "Item 2" });
|
|
163
|
-
// refresh(items);
|
|
156
|
+
// To update with transitions, use createTransitionGroupRefresher
|
|
164
157
|
});
|
|
165
158
|
};
|
|
166
159
|
```
|
|
167
160
|
|
|
161
|
+
#### Updating with createTransitionGroupRefresher
|
|
162
|
+
|
|
163
|
+
`createTransitionGroupRefresher` creates a stateful refresh function that applies enter/leave transitions on list updates:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const refresher = createTransitionGroupRefresher({
|
|
167
|
+
keyFn: (item) => item.id,
|
|
168
|
+
enter: "transition-opacity duration-300",
|
|
169
|
+
enterFrom: "opacity-0",
|
|
170
|
+
enterTo: "opacity-100",
|
|
171
|
+
leave: "transition-opacity duration-300",
|
|
172
|
+
leaveFrom: "opacity-100",
|
|
173
|
+
leaveTo: "opacity-0",
|
|
174
|
+
children: (item) => div(() => [text(item.text)]),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Later, update items with transitions:
|
|
178
|
+
refresher(slot, newItems);
|
|
179
|
+
```
|
|
180
|
+
|
|
168
181
|
## API
|
|
169
182
|
|
|
170
183
|
### Transition
|
|
171
184
|
|
|
172
185
|
```typescript
|
|
173
|
-
function Transition(props: TransitionProps):
|
|
186
|
+
function Transition(props: TransitionProps): Render;
|
|
174
187
|
|
|
175
188
|
interface TransitionProps {
|
|
176
189
|
show: boolean;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
190
|
+
enter?: string;
|
|
191
|
+
enterFrom?: string;
|
|
192
|
+
enterTo?: string;
|
|
193
|
+
leave?: string;
|
|
194
|
+
leaveFrom?: string;
|
|
195
|
+
leaveTo?: string;
|
|
196
|
+
children: () => ChildContent;
|
|
183
197
|
}
|
|
184
198
|
```
|
|
185
199
|
|
|
200
|
+
Enter-only transition component. For leave animations, use `createTransition`.
|
|
201
|
+
|
|
186
202
|
### createTransition
|
|
187
203
|
|
|
188
204
|
```typescript
|
|
189
205
|
function* createTransition(
|
|
190
|
-
props:
|
|
191
|
-
):
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
enter: string;
|
|
195
|
-
enterFrom: string;
|
|
196
|
-
enterTo: string;
|
|
197
|
-
leave: string;
|
|
198
|
-
leaveFrom: string;
|
|
199
|
-
leaveTo: string;
|
|
200
|
-
children: () => Render;
|
|
201
|
-
}
|
|
206
|
+
props: Omit<TransitionProps, "show">,
|
|
207
|
+
): TransitionInstruction;
|
|
208
|
+
|
|
209
|
+
type TransitionInstruction = Generator<Element, TransitionHandle, Slot>;
|
|
202
210
|
|
|
203
211
|
interface TransitionHandle {
|
|
204
212
|
slot: Slot;
|
|
@@ -206,27 +214,45 @@ interface TransitionHandle {
|
|
|
206
214
|
}
|
|
207
215
|
```
|
|
208
216
|
|
|
217
|
+
Creates a transition with programmatic show/hide control including leave animations.
|
|
218
|
+
|
|
209
219
|
### TransitionGroup
|
|
210
220
|
|
|
211
221
|
```typescript
|
|
212
|
-
function TransitionGroup<T>(props: TransitionGroupProps<T>):
|
|
222
|
+
function* TransitionGroup<T>(props: TransitionGroupProps<T>): ElementRender;
|
|
213
223
|
|
|
214
224
|
interface TransitionGroupProps<T> {
|
|
215
|
-
name: string;
|
|
216
225
|
items: T[];
|
|
217
226
|
keyFn: (item: T) => string | number;
|
|
218
|
-
|
|
227
|
+
enter?: string;
|
|
228
|
+
enterFrom?: string;
|
|
229
|
+
enterTo?: string;
|
|
230
|
+
leave?: string;
|
|
231
|
+
leaveFrom?: string;
|
|
232
|
+
leaveTo?: string;
|
|
233
|
+
children: (item: T, index: number) => ElementRender;
|
|
219
234
|
}
|
|
220
235
|
```
|
|
221
236
|
|
|
237
|
+
### createTransitionGroupRefresher
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
function createTransitionGroupRefresher<T>(
|
|
241
|
+
props: Omit<TransitionGroupProps<T>, "items">,
|
|
242
|
+
): (slot: Slot, items: T[]) => void;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Creates a stateful refresher that applies enter/leave transitions when updating items.
|
|
246
|
+
|
|
222
247
|
### Low-level APIs
|
|
223
248
|
|
|
224
249
|
```typescript
|
|
225
|
-
function enterTransition(el: HTMLElement, props:
|
|
226
|
-
function leaveTransition(el: HTMLElement, props:
|
|
250
|
+
function enterTransition(el: HTMLElement, props: TransitionProps): Promise<void>;
|
|
251
|
+
function leaveTransition(el: HTMLElement, props: TransitionProps): Promise<void>;
|
|
227
252
|
```
|
|
228
253
|
|
|
229
254
|
## Module Structure
|
|
230
255
|
|
|
231
|
-
- `Transition.ts` -
|
|
232
|
-
- `TransitionGroup.ts` -
|
|
256
|
+
- `Transition.ts` - Transition, createTransition, enterTransition, leaveTransition
|
|
257
|
+
- `TransitionGroup.ts` - TransitionGroup, createTransitionGroupRefresher
|
|
258
|
+
- `utils.ts` - CSS class helpers (addClasses, removeClasses, waitForTransition)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ydant/transition",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Transition components for Ydant",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"animation",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@ydant/base": "0.1.
|
|
43
|
-
"@ydant/core": "0.1.
|
|
42
|
+
"@ydant/base": "0.1.2",
|
|
43
|
+
"@ydant/core": "0.1.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "vite build",
|