@wix/interact 1.92.0 → 2.0.0-rc.2
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/dist/cjs/index.js +2 -23
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react.js +15 -0
- package/dist/cjs/react.js.map +1 -0
- package/dist/cjs/web.js +2 -0
- package/dist/cjs/web.js.map +1 -0
- package/dist/es/index.js +8 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/react.js +650 -0
- package/dist/es/react.js.map +1 -0
- package/dist/es/web.js +56 -0
- package/dist/es/web.js.map +1 -0
- package/dist/index-C8QxOkui.mjs +7940 -0
- package/dist/index-C8QxOkui.mjs.map +1 -0
- package/dist/index-DEPRHaUt.js +18 -0
- package/dist/index-DEPRHaUt.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/core/Interact.d.ts +17 -7
- package/dist/types/core/Interact.d.ts.map +1 -0
- package/dist/types/core/InteractionController.d.ts +19 -0
- package/dist/types/core/InteractionController.d.ts.map +1 -0
- package/dist/types/core/add.d.ts +4 -3
- package/dist/types/core/add.d.ts.map +1 -0
- package/dist/types/core/css.d.ts +3 -0
- package/dist/types/core/css.d.ts.map +1 -0
- package/dist/types/core/remove.d.ts +3 -1
- package/dist/types/core/remove.d.ts.map +1 -0
- package/dist/types/core/utilities.d.ts +1 -0
- package/dist/types/core/utilities.d.ts.map +1 -0
- package/dist/types/dom/api.d.ts +3 -0
- package/dist/types/dom/api.d.ts.map +1 -0
- package/dist/types/handlers/animationEnd.d.ts +3 -2
- package/dist/types/handlers/animationEnd.d.ts.map +1 -0
- package/dist/types/handlers/click.d.ts +3 -2
- package/dist/types/handlers/click.d.ts.map +1 -0
- package/dist/types/handlers/hover.d.ts +3 -2
- package/dist/types/handlers/hover.d.ts.map +1 -0
- package/dist/types/handlers/index.d.ts +1 -0
- package/dist/types/handlers/index.d.ts.map +1 -0
- package/dist/types/handlers/pointerMove.d.ts +3 -2
- package/dist/types/handlers/pointerMove.d.ts.map +1 -0
- package/dist/types/handlers/utilities.d.ts +1 -0
- package/dist/types/handlers/utilities.d.ts.map +1 -0
- package/dist/types/handlers/viewEnter.d.ts +3 -2
- package/dist/types/handlers/viewEnter.d.ts.map +1 -0
- package/dist/types/handlers/viewProgress.d.ts +4 -3
- package/dist/types/handlers/viewProgress.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/react/Interaction.d.ts +10 -0
- package/dist/types/react/Interaction.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +8 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/interactRef.d.ts +3 -0
- package/dist/types/react/interactRef.d.ts.map +1 -0
- package/dist/types/types.d.ts +25 -10
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +4 -2
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/{InteractElement.d.ts → web/InteractElement.d.ts} +115 -77
- package/dist/types/web/InteractElement.d.ts.map +1 -0
- package/dist/types/web/defineInteractElement.d.ts +2 -0
- package/dist/types/web/defineInteractElement.d.ts.map +1 -0
- package/dist/types/web/index.d.ts +6 -0
- package/dist/types/web/index.d.ts.map +1 -0
- package/docs/README.md +211 -0
- package/docs/advanced/README.md +164 -0
- package/docs/api/README.md +157 -0
- package/docs/api/element-selection.md +607 -0
- package/docs/api/functions.md +638 -0
- package/docs/api/interact-class.md +663 -0
- package/docs/api/interact-element.md +565 -0
- package/docs/api/interaction-controller.md +450 -0
- package/docs/api/types.md +957 -0
- package/docs/examples/README.md +212 -0
- package/docs/examples/click-interactions.md +977 -0
- package/docs/examples/entrance-animations.md +935 -0
- package/docs/examples/hover-effects.md +930 -0
- package/docs/examples/list-patterns.md +737 -0
- package/docs/guides/README.md +49 -0
- package/docs/guides/conditions-and-media-queries.md +1068 -0
- package/docs/guides/configuration-structure.md +726 -0
- package/docs/guides/custom-elements.md +327 -0
- package/docs/guides/effects-and-animations.md +634 -0
- package/docs/guides/getting-started.md +379 -0
- package/docs/guides/lists-and-dynamic-content.md +713 -0
- package/docs/guides/state-management.md +747 -0
- package/docs/guides/understanding-triggers.md +690 -0
- package/docs/integration/README.md +264 -0
- package/docs/integration/react.md +605 -0
- package/package.json +73 -56
- package/rules/Integration.md +255 -0
- package/rules/click-rules.md +533 -0
- package/rules/full-lean.md +346 -0
- package/rules/hover-rules.md +593 -0
- package/rules/pointermove-rules.md +1341 -0
- package/rules/scroll-list-rules.md +900 -0
- package/rules/viewenter-rules.md +1015 -0
- package/rules/viewprogress-rules.md +1044 -0
- package/dist/cjs/InteractElement.js +0 -162
- package/dist/cjs/InteractElement.js.map +0 -1
- package/dist/cjs/__tests__/interact.spec.js +0 -1930
- package/dist/cjs/__tests__/interact.spec.js.map +0 -1
- package/dist/cjs/__tests__/viewEnter.spec.js +0 -207
- package/dist/cjs/__tests__/viewEnter.spec.js.map +0 -1
- package/dist/cjs/core/Interact.js +0 -257
- package/dist/cjs/core/Interact.js.map +0 -1
- package/dist/cjs/core/add.js +0 -246
- package/dist/cjs/core/add.js.map +0 -1
- package/dist/cjs/core/remove.js +0 -35
- package/dist/cjs/core/remove.js.map +0 -1
- package/dist/cjs/core/utilities.js +0 -16
- package/dist/cjs/core/utilities.js.map +0 -1
- package/dist/cjs/external-types.d.js +0 -2
- package/dist/cjs/external-types.d.js.map +0 -1
- package/dist/cjs/handlers/animationEnd.js +0 -33
- package/dist/cjs/handlers/animationEnd.js.map +0 -1
- package/dist/cjs/handlers/click.js +0 -116
- package/dist/cjs/handlers/click.js.map +0 -1
- package/dist/cjs/handlers/hover.js +0 -141
- package/dist/cjs/handlers/hover.js.map +0 -1
- package/dist/cjs/handlers/index.js +0 -32
- package/dist/cjs/handlers/index.js.map +0 -1
- package/dist/cjs/handlers/pointerMove.js +0 -49
- package/dist/cjs/handlers/pointerMove.js.map +0 -1
- package/dist/cjs/handlers/utilities.js +0 -49
- package/dist/cjs/handlers/utilities.js.map +0 -1
- package/dist/cjs/handlers/viewEnter.js +0 -127
- package/dist/cjs/handlers/viewEnter.js.map +0 -1
- package/dist/cjs/handlers/viewProgress.js +0 -65
- package/dist/cjs/handlers/viewProgress.js.map +0 -1
- package/dist/cjs/test-types.d.js +0 -2
- package/dist/cjs/test-types.d.js.map +0 -1
- package/dist/cjs/types.js +0 -2
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utils.js +0 -68
- package/dist/cjs/utils.js.map +0 -1
- package/dist/esm/InteractElement.js +0 -156
- package/dist/esm/InteractElement.js.map +0 -1
- package/dist/esm/__tests__/interact.spec.js +0 -1937
- package/dist/esm/__tests__/interact.spec.js.map +0 -1
- package/dist/esm/__tests__/viewEnter.spec.js +0 -210
- package/dist/esm/__tests__/viewEnter.spec.js.map +0 -1
- package/dist/esm/core/Interact.js +0 -251
- package/dist/esm/core/Interact.js.map +0 -1
- package/dist/esm/core/add.js +0 -241
- package/dist/esm/core/add.js.map +0 -1
- package/dist/esm/core/remove.js +0 -30
- package/dist/esm/core/remove.js.map +0 -1
- package/dist/esm/core/utilities.js +0 -14
- package/dist/esm/core/utilities.js.map +0 -1
- package/dist/esm/external-types.d.js +0 -2
- package/dist/esm/external-types.d.js.map +0 -1
- package/dist/esm/handlers/animationEnd.js +0 -29
- package/dist/esm/handlers/animationEnd.js.map +0 -1
- package/dist/esm/handlers/click.js +0 -116
- package/dist/esm/handlers/click.js.map +0 -1
- package/dist/esm/handlers/hover.js +0 -141
- package/dist/esm/handlers/hover.js.map +0 -1
- package/dist/esm/handlers/index.js +0 -27
- package/dist/esm/handlers/index.js.map +0 -1
- package/dist/esm/handlers/pointerMove.js +0 -48
- package/dist/esm/handlers/pointerMove.js.map +0 -1
- package/dist/esm/handlers/utilities.js +0 -43
- package/dist/esm/handlers/utilities.js.map +0 -1
- package/dist/esm/handlers/viewEnter.js +0 -129
- package/dist/esm/handlers/viewEnter.js.map +0 -1
- package/dist/esm/handlers/viewProgress.js +0 -61
- package/dist/esm/handlers/viewProgress.js.map +0 -1
- package/dist/esm/index.js +0 -5
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/test-types.d.js +0 -2
- package/dist/esm/test-types.d.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils.js +0 -63
- package/dist/esm/utils.js.map +0 -1
- package/dist/types/__tests__/interact.spec.d.ts +0 -1
- package/dist/types/__tests__/viewEnter.spec.d.ts +0 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
Welcome to `@wix/interact`! This guide will help you create your first interaction in under 4 minutes.
|
|
4
|
+
|
|
5
|
+
## What is @wix/interact?
|
|
6
|
+
|
|
7
|
+
`@wix/interact` is a powerful library that lets you create interactive animations and effects triggered by user actions like clicking, hovering, or scrolling. It integrates seamlessly with `@wix/motion` to provide smooth, performant animations.
|
|
8
|
+
|
|
9
|
+
## Core Concepts
|
|
10
|
+
|
|
11
|
+
Before we dive in, let's understand the three main concepts:
|
|
12
|
+
|
|
13
|
+
1. **Triggers** - User actions that start an interaction (click, hover, scroll, etc.)
|
|
14
|
+
2. **Effects** - The visual changes that happen (animations, transitions, style changes)
|
|
15
|
+
3. **Elements** - The HTML elements that participate in the interaction
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @wix/interact
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Package Entry Points
|
|
24
|
+
|
|
25
|
+
`@wix/interact` provides three entry points for different use cases:
|
|
26
|
+
|
|
27
|
+
| Entry Point | Use Case | Key Exports |
|
|
28
|
+
|-------------|----------|-------------|
|
|
29
|
+
| `@wix/interact/react` | React applications | `Interaction`, `createInteractRef`, `Interact` |
|
|
30
|
+
| `@wix/interact/web` | Web Components | `Interact`, `defineInteractElement`, `add`, `remove` |
|
|
31
|
+
| `@wix/interact` | Vanilla JS | `Interact`, `add`, `remove` |
|
|
32
|
+
|
|
33
|
+
Choose the entry point that matches your framework:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// For React applications
|
|
37
|
+
import { Interact, Interaction } from '@wix/interact/react';
|
|
38
|
+
|
|
39
|
+
// For native Web Components
|
|
40
|
+
import { Interact } from '@wix/interact/web';
|
|
41
|
+
|
|
42
|
+
// For vaniall JavaScript
|
|
43
|
+
import { Interact, add, remove } from '@wix/interact';
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Your First Interaction (React)
|
|
49
|
+
|
|
50
|
+
If you're using React, here's the quickest way to get started using the `Interaction` component:
|
|
51
|
+
|
|
52
|
+
### Step 1: Create the Configuration
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import React, { useEffect } from 'react';
|
|
56
|
+
import { Interact, Interaction, InteractConfig } from '@wix/interact/react';
|
|
57
|
+
|
|
58
|
+
const config: InteractConfig = {
|
|
59
|
+
interactions: [
|
|
60
|
+
{
|
|
61
|
+
key: 'my-image', // What element triggers the interaction
|
|
62
|
+
trigger: 'hover', // What user action starts it
|
|
63
|
+
effects: [
|
|
64
|
+
{
|
|
65
|
+
keyframeEffect: {
|
|
66
|
+
name: 'scale',
|
|
67
|
+
keyframes: [
|
|
68
|
+
{ scale: 2 }
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
duration: 300, // Animation duration in milliseconds
|
|
72
|
+
easing: 'ease-out' // Animation timing
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
effects: {}
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Step 2: Create the Component
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
function App() {
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const instance = Interact.create(config);
|
|
87
|
+
return () => instance.destroy();
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Interaction tagName="div" interactKey="my-image" className="image-container">
|
|
92
|
+
<img src="logo.png" alt="Logo" />
|
|
93
|
+
</Interaction>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default App;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
That's it! The image will now scale up when you hover over it.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Your First Interaction (Vanilla JavaScript)
|
|
105
|
+
|
|
106
|
+
For vanilla JavaScript or non-React frameworks, use the `interact-element` custom element:
|
|
107
|
+
|
|
108
|
+
### Step 1: Basic HTML Structure
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<!DOCTYPE html>
|
|
112
|
+
<html>
|
|
113
|
+
<head>
|
|
114
|
+
<title>My First Interaction</title>
|
|
115
|
+
</head>
|
|
116
|
+
<body>
|
|
117
|
+
<interact-element data-interact-key="my-image">
|
|
118
|
+
<img id="my-image" src="logo.png" alt="Logo" />
|
|
119
|
+
</interact-element>
|
|
120
|
+
|
|
121
|
+
<script type="module" src="./main.js"></script>
|
|
122
|
+
</body>
|
|
123
|
+
</html>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Key points:**
|
|
127
|
+
- Wrap your element in `<interact-element>`
|
|
128
|
+
- Use `data-interact-key` to identify the element (must be unique)
|
|
129
|
+
- The key in your interaction config should be a unique string that matches the value of `data-interact-key` for that element
|
|
130
|
+
|
|
131
|
+
### Step 2: Configure the Interaction
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// main.js
|
|
135
|
+
import { Interact } from '@wix/interact/web';
|
|
136
|
+
|
|
137
|
+
// Create the interaction configuration
|
|
138
|
+
const config = {
|
|
139
|
+
interactions: [
|
|
140
|
+
{
|
|
141
|
+
key: 'my-image', // What element triggers the interaction
|
|
142
|
+
trigger: 'hover', // What user action starts it
|
|
143
|
+
effects: [
|
|
144
|
+
{
|
|
145
|
+
keyframeEffect: {
|
|
146
|
+
name: 'scale',
|
|
147
|
+
keyframes: [
|
|
148
|
+
{ scale: 2 }
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
duration: 300, // Animation duration in milliseconds
|
|
152
|
+
easing: 'ease-out' // Animation timing
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
effects: {}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Initialize the interaction
|
|
161
|
+
Interact.create(config);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Understanding the Configuration
|
|
167
|
+
|
|
168
|
+
Let's break down what each part does:
|
|
169
|
+
|
|
170
|
+
### The `interactions` Array
|
|
171
|
+
This contains all your interactions. Each interaction defines:
|
|
172
|
+
- **key**: Which element triggers the interaction
|
|
173
|
+
- **trigger**: What user action starts it
|
|
174
|
+
- **effects**: What animations happen
|
|
175
|
+
|
|
176
|
+
### The `effects` Object
|
|
177
|
+
Define reusable effects that can be referenced by `effectId`:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const config = {
|
|
181
|
+
effects: {
|
|
182
|
+
'fade-in': {
|
|
183
|
+
duration: 1000,
|
|
184
|
+
keyframeEffect: {
|
|
185
|
+
name: 'fade-in',
|
|
186
|
+
keyframes: [
|
|
187
|
+
{ opacity: 0 },
|
|
188
|
+
{ opacity: 1 }
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
interactions: [
|
|
194
|
+
{
|
|
195
|
+
key: 'hero',
|
|
196
|
+
trigger: 'viewEnter',
|
|
197
|
+
effects: [{ effectId: 'fade-in' }] // Reference the effect
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Effect Properties
|
|
204
|
+
Each effect defines:
|
|
205
|
+
- **key**: Which element gets animated (if missing it defaults to source)
|
|
206
|
+
- **keyframeEffect**: An object containing a `keyframes` property that maps to an array of keyframe objects, and a `name` containing a unique name for that effect
|
|
207
|
+
- **duration**: How long the animation takes
|
|
208
|
+
- **easing**: The animation timing curve
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Common Patterns
|
|
213
|
+
|
|
214
|
+
### Hover with Scale and Rotation
|
|
215
|
+
```javascript
|
|
216
|
+
{
|
|
217
|
+
key: 'my-element',
|
|
218
|
+
trigger: 'hover',
|
|
219
|
+
effects: [
|
|
220
|
+
{
|
|
221
|
+
key: 'my-element',
|
|
222
|
+
keyframeEffect: {
|
|
223
|
+
name: 'twist',
|
|
224
|
+
keyframes: [
|
|
225
|
+
{ transform: 'scale(1) rotate(0deg)' },
|
|
226
|
+
{ transform: 'scale(1.1) rotate(5deg)' }
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
duration: 200,
|
|
230
|
+
easing: 'ease-out'
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Click to Toggle State
|
|
237
|
+
```javascript
|
|
238
|
+
{
|
|
239
|
+
key: 'my-button',
|
|
240
|
+
trigger: 'click',
|
|
241
|
+
params: { method: 'toggle' },
|
|
242
|
+
effects: [
|
|
243
|
+
{
|
|
244
|
+
key: 'my-content',
|
|
245
|
+
effectId: 'expand',
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Entrance Animation on Viewport Entry
|
|
252
|
+
```javascript
|
|
253
|
+
{
|
|
254
|
+
key: 'my-element',
|
|
255
|
+
trigger: 'viewEnter',
|
|
256
|
+
effects: [
|
|
257
|
+
{
|
|
258
|
+
key: 'my-element',
|
|
259
|
+
namedEffect: 'FadeIn',
|
|
260
|
+
duration: 800,
|
|
261
|
+
easing: 'ease-out'
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
> **Tip**: To prevent a flash of content before entrance animations start, use the `generate()` function to create CSS that hides elements until their animation triggers. See [Entrance Animations](../examples/entrance-animations.md#preventing-flash-of-unstyled-content-fouc) for details.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## React vs Web Components
|
|
272
|
+
|
|
273
|
+
| Approach | When to Use |
|
|
274
|
+
|----------|-------------|
|
|
275
|
+
| **React (`Interaction` component)** | React applications, automatic cleanup |
|
|
276
|
+
| **Web Components (`interact-element`)** | Framework-agnostic projects, declerative creation and automatic DOM-changes handling |
|
|
277
|
+
| **Mini** | Framework-agnostic projects, if no need for dynamic DOM changes or integrating with other frameworks |
|
|
278
|
+
|
|
279
|
+
### React Example (Recommended for React)
|
|
280
|
+
|
|
281
|
+
```tsx
|
|
282
|
+
import { Interact, Interaction } from '@wix/interact/react';
|
|
283
|
+
|
|
284
|
+
function Card() {
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
Interact.create(config);
|
|
287
|
+
return () => Interact.destroy();
|
|
288
|
+
}, []);
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<Interaction tagName="article" interactKey="card" className="card">
|
|
292
|
+
<h2>Card Title</h2>
|
|
293
|
+
<p>Card content here</p>
|
|
294
|
+
</Interaction>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Web Component Example (Framework-agnostic)
|
|
300
|
+
|
|
301
|
+
```html
|
|
302
|
+
<interact-element data-interact-key="card">
|
|
303
|
+
<article class="card">
|
|
304
|
+
<h2>Card Title</h2>
|
|
305
|
+
<p>Card content here</p>
|
|
306
|
+
</article>
|
|
307
|
+
</interact-element>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
import { Interact } from '@wix/interact/web';
|
|
312
|
+
Interact.create(config);
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## TypeScript Support
|
|
318
|
+
|
|
319
|
+
Both entry points provide full TypeScript support:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { Interact, InteractConfig, Interaction } from '@wix/interact/react';
|
|
323
|
+
|
|
324
|
+
const config: InteractConfig = {
|
|
325
|
+
interactions: [
|
|
326
|
+
{
|
|
327
|
+
key: 'hero',
|
|
328
|
+
trigger: 'viewEnter', // TypeScript validates trigger types
|
|
329
|
+
effects: [
|
|
330
|
+
{
|
|
331
|
+
duration: 1000,
|
|
332
|
+
keyframeEffect: {
|
|
333
|
+
name: 'fade',
|
|
334
|
+
keyframes: [{ opacity: 0 }, { opacity: 1 }]
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
],
|
|
340
|
+
effects: {}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// Full type inference
|
|
344
|
+
const instance = Interact.create(config);
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Cleanup
|
|
350
|
+
|
|
351
|
+
Always clean up interactions when components unmount or pages change:
|
|
352
|
+
|
|
353
|
+
### React
|
|
354
|
+
```tsx
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
const instance = Interact.create(config);
|
|
357
|
+
return () => instance.destroy();
|
|
358
|
+
}, []);
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Vanilla JavaScript
|
|
362
|
+
```javascript
|
|
363
|
+
// On page unload or SPA navigation
|
|
364
|
+
window.addEventListener('beforeunload', () => {
|
|
365
|
+
Interact.destroy();
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## Next Steps
|
|
372
|
+
|
|
373
|
+
Congratulations! You've created your first interaction. Here's what to explore next:
|
|
374
|
+
|
|
375
|
+
1. **[Understanding Triggers](./understanding-triggers.md)** - Learn about all 7 trigger types
|
|
376
|
+
2. **[Effects and Animations](./effects-and-animations.md)** - Discover more animation options
|
|
377
|
+
3. **[Custom Elements](./custom-elements.md)** - Understand how `<interact-element>` works
|
|
378
|
+
4. **[React Integration](../integration/react.md)** - Deep dive into React components and hooks
|
|
379
|
+
5. **[Configuration Structure](./configuration-structure.md)** - Organize complex interactions
|