motionrail 0.1.0 → 0.1.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/README.md +322 -3
- package/dist/client-pmAKFFi-.js +1755 -0
- package/dist/react.d.ts +10 -0
- package/dist/react.js +25 -0
- package/dist/solid.d.ts +11 -0
- package/dist/solid.js +23 -0
- package/dist/svelte.js +59 -0
- package/dist/svelte5.js +53 -0
- package/dist/vue.js +27 -0
- package/package.json +32 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> ⚠️ **Not Ready for Production** - This library is currently in development and not yet ready for production use.
|
|
4
4
|
|
|
5
|
-
A lightweight, smooth carousel library with momentum-based scrolling, snap alignment, and responsive breakpoints.
|
|
5
|
+
A lightweight, smooth carousel library with momentum-based scrolling, snap alignment, and responsive breakpoints. Works with vanilla JavaScript or your favorite framework.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
@@ -14,7 +14,8 @@ A lightweight, smooth carousel library with momentum-based scrolling, snap align
|
|
|
14
14
|
- 🎨 **CSS Grid based** - Modern layout with customizable styling
|
|
15
15
|
- 🪶 **Lightweight** - Zero dependencies, minimal bundle size
|
|
16
16
|
- 🎮 **Full control API** - Programmatic navigation and playback control
|
|
17
|
-
- 🧩 **Extension system** - Modular architecture with built-in extensions
|
|
17
|
+
- 🧩 **Extension system** - Modular architecture with built-in extensions
|
|
18
|
+
- ⚛️ **Framework integrations** - React, Solid, Vue, Svelte components
|
|
18
19
|
|
|
19
20
|
## Installation
|
|
20
21
|
|
|
@@ -24,6 +25,8 @@ npm install motionrail
|
|
|
24
25
|
|
|
25
26
|
## Quick Start
|
|
26
27
|
|
|
28
|
+
### Vanilla JavaScript
|
|
29
|
+
|
|
27
30
|
```js
|
|
28
31
|
import { MotionRail } from 'motionrail';
|
|
29
32
|
import 'motionrail/style.css';
|
|
@@ -37,6 +40,93 @@ const carousel = new MotionRail(document.getElementById('carousel'), {
|
|
|
37
40
|
});
|
|
38
41
|
```
|
|
39
42
|
|
|
43
|
+
### React
|
|
44
|
+
|
|
45
|
+
```jsx
|
|
46
|
+
import { MotionRail } from 'motionrail/react';
|
|
47
|
+
import 'motionrail/style.css';
|
|
48
|
+
|
|
49
|
+
function App() {
|
|
50
|
+
return (
|
|
51
|
+
<MotionRail options={{ breakpoints: [{ columns: 3, gap: '20px' }] }}>
|
|
52
|
+
<div>Item 1</div>
|
|
53
|
+
<div>Item 2</div>
|
|
54
|
+
<div>Item 3</div>
|
|
55
|
+
</MotionRail>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Solid.js
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
import { MotionRail } from 'motionrail/solid';
|
|
64
|
+
import 'motionrail/style.css';
|
|
65
|
+
|
|
66
|
+
function App() {
|
|
67
|
+
return (
|
|
68
|
+
<MotionRail options={{ breakpoints: [{ columns: 3, gap: '20px' }] }}>
|
|
69
|
+
<div>Item 1</div>
|
|
70
|
+
<div>Item 2</div>
|
|
71
|
+
<div>Item 3</div>
|
|
72
|
+
</MotionRail>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Vue
|
|
78
|
+
|
|
79
|
+
```vue
|
|
80
|
+
<script setup>
|
|
81
|
+
import { MotionRail } from 'motionrail/vue';
|
|
82
|
+
import 'motionrail/style.css';
|
|
83
|
+
|
|
84
|
+
const options = { breakpoints: [{ columns: 3, gap: '20px' }] };
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<MotionRail :options="options">
|
|
89
|
+
<div>Item 1</div>
|
|
90
|
+
<div>Item 2</div>
|
|
91
|
+
<div>Item 3</div>
|
|
92
|
+
</MotionRail>
|
|
93
|
+
</template>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Svelte
|
|
97
|
+
|
|
98
|
+
```svelte
|
|
99
|
+
<script>
|
|
100
|
+
import { MotionRail } from 'motionrail/svelte';
|
|
101
|
+
import 'motionrail/style.css';
|
|
102
|
+
|
|
103
|
+
const options = { breakpoints: [{ columns: 3, gap: '20px' }] };
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<MotionRail {options}>
|
|
107
|
+
<div>Item 1</div>
|
|
108
|
+
<div>Item 2</div>
|
|
109
|
+
<div>Item 3</div>
|
|
110
|
+
</MotionRail>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Svelte 5 (with Runes)
|
|
114
|
+
|
|
115
|
+
```svelte
|
|
116
|
+
<script>
|
|
117
|
+
import { MotionRail } from 'motionrail/svelte5';
|
|
118
|
+
import 'motionrail/style.css';
|
|
119
|
+
|
|
120
|
+
const options = { breakpoints: [{ columns: 3, gap: '20px' }] };
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<MotionRail {options}>
|
|
124
|
+
<div>Item 1</div>
|
|
125
|
+
<div>Item 2</div>
|
|
126
|
+
<div>Item 3</div>
|
|
127
|
+
</MotionRail>
|
|
128
|
+
```
|
|
129
|
+
|
|
40
130
|
## Usage
|
|
41
131
|
|
|
42
132
|
### HTML Structure
|
|
@@ -66,7 +156,7 @@ const carousel = new MotionRail(document.getElementById('carousel'), {
|
|
|
66
156
|
import 'motionrail/style.css';
|
|
67
157
|
```
|
|
68
158
|
|
|
69
|
-
### JavaScript
|
|
159
|
+
### Vanilla JavaScript
|
|
70
160
|
|
|
71
161
|
```js
|
|
72
162
|
import { MotionRail } from 'motionrail';
|
|
@@ -88,6 +178,235 @@ const carousel = new MotionRail(element, {
|
|
|
88
178
|
});
|
|
89
179
|
```
|
|
90
180
|
|
|
181
|
+
## Framework Integrations
|
|
182
|
+
|
|
183
|
+
MotionRail provides first-class framework integrations for React, Solid.js, Vue, and Svelte. All integrations are lightweight and use the same API.
|
|
184
|
+
|
|
185
|
+
### Bundle Sizes
|
|
186
|
+
|
|
187
|
+
- **React**: 0.87 kB (gzipped: 0.42 kB)
|
|
188
|
+
- **Solid.js**: 0.89 kB (gzipped: 0.48 kB)
|
|
189
|
+
- **Vue**: 1.22 kB (gzipped: 0.62 kB)
|
|
190
|
+
- **Svelte**: 2.21 kB (gzipped: 0.94 kB)
|
|
191
|
+
- **Svelte 5**: 1.80 kB (gzipped: 0.82 kB)
|
|
192
|
+
|
|
193
|
+
### React Integration
|
|
194
|
+
|
|
195
|
+
```jsx
|
|
196
|
+
import { MotionRail } from 'motionrail/react';
|
|
197
|
+
import 'motionrail/style.css';
|
|
198
|
+
|
|
199
|
+
function MyCarousel() {
|
|
200
|
+
const carouselRef = useRef(null);
|
|
201
|
+
const containerRef = useRef(null);
|
|
202
|
+
|
|
203
|
+
const handleNext = () => {
|
|
204
|
+
carouselRef.current?.next();
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<>
|
|
209
|
+
<MotionRail
|
|
210
|
+
ref={carouselRef}
|
|
211
|
+
divRef={containerRef}
|
|
212
|
+
options={{
|
|
213
|
+
autoplay: true,
|
|
214
|
+
delay: 3000,
|
|
215
|
+
breakpoints: [
|
|
216
|
+
{ columns: 1, gap: '16px' },
|
|
217
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
218
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
219
|
+
],
|
|
220
|
+
onChange: (state) => console.log(state)
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<div>Item 1</div>
|
|
224
|
+
<div>Item 2</div>
|
|
225
|
+
<div>Item 3</div>
|
|
226
|
+
</MotionRail>
|
|
227
|
+
<button onClick={handleNext}>Next</button>
|
|
228
|
+
</>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Props:**
|
|
234
|
+
- `options`: MotionRailOptions object
|
|
235
|
+
- `ref`: Receives the MotionRail instance
|
|
236
|
+
- `divRef`: Receives the container HTMLDivElement
|
|
237
|
+
- `children`: Carousel items
|
|
238
|
+
|
|
239
|
+
### Solid.js Integration
|
|
240
|
+
|
|
241
|
+
```jsx
|
|
242
|
+
import { MotionRail } from 'motionrail/solid';
|
|
243
|
+
import 'motionrail/style.css';
|
|
244
|
+
|
|
245
|
+
function MyCarousel() {
|
|
246
|
+
let carousel;
|
|
247
|
+
let container;
|
|
248
|
+
|
|
249
|
+
const handleNext = () => {
|
|
250
|
+
carousel?.next();
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<>
|
|
255
|
+
<MotionRail
|
|
256
|
+
ref={(instance) => carousel = instance}
|
|
257
|
+
divRef={(el) => container = el}
|
|
258
|
+
options={{
|
|
259
|
+
autoplay: true,
|
|
260
|
+
delay: 3000,
|
|
261
|
+
breakpoints: [
|
|
262
|
+
{ columns: 1, gap: '16px' },
|
|
263
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
264
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
265
|
+
],
|
|
266
|
+
onChange: (state) => console.log(state)
|
|
267
|
+
}}
|
|
268
|
+
>
|
|
269
|
+
<div>Item 1</div>
|
|
270
|
+
<div>Item 2</div>
|
|
271
|
+
<div>Item 3</div>
|
|
272
|
+
</MotionRail>
|
|
273
|
+
<button onClick={handleNext}>Next</button>
|
|
274
|
+
</>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Props:**
|
|
280
|
+
- `options`: MotionRailOptions object
|
|
281
|
+
- `ref`: Callback that receives the MotionRail instance
|
|
282
|
+
- `divRef`: Callback that receives the container HTMLDivElement
|
|
283
|
+
- `children`: Carousel items
|
|
284
|
+
|
|
285
|
+
### Vue Integration
|
|
286
|
+
|
|
287
|
+
```vue
|
|
288
|
+
<script setup>
|
|
289
|
+
import { ref } from 'vue';
|
|
290
|
+
import { MotionRail } from 'motionrail/vue';
|
|
291
|
+
import 'motionrail/style.css';
|
|
292
|
+
|
|
293
|
+
const carouselRef = ref(null);
|
|
294
|
+
|
|
295
|
+
const options = {
|
|
296
|
+
autoplay: true,
|
|
297
|
+
delay: 3000,
|
|
298
|
+
breakpoints: [
|
|
299
|
+
{ columns: 1, gap: '16px' },
|
|
300
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
301
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
302
|
+
],
|
|
303
|
+
onChange: (state) => console.log(state)
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const handleNext = () => {
|
|
307
|
+
carouselRef.value?.instance?.next();
|
|
308
|
+
};
|
|
309
|
+
</script>
|
|
310
|
+
|
|
311
|
+
<template>
|
|
312
|
+
<div>
|
|
313
|
+
<MotionRail ref="carouselRef" :options="options">
|
|
314
|
+
<div>Item 1</div>
|
|
315
|
+
<div>Item 2</div>
|
|
316
|
+
<div>Item 3</div>
|
|
317
|
+
</MotionRail>
|
|
318
|
+
<button @click="handleNext">Next</button>
|
|
319
|
+
</div>
|
|
320
|
+
</template>
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Props:**
|
|
324
|
+
- `options`: MotionRailOptions object
|
|
325
|
+
|
|
326
|
+
**Template Ref Access:**
|
|
327
|
+
- `instance`: MotionRail instance
|
|
328
|
+
- `container`: Container HTMLDivElement
|
|
329
|
+
|
|
330
|
+
### Svelte Integration
|
|
331
|
+
|
|
332
|
+
```svelte
|
|
333
|
+
<script>
|
|
334
|
+
import { MotionRail } from 'motionrail/svelte';
|
|
335
|
+
import 'motionrail/style.css';
|
|
336
|
+
|
|
337
|
+
let instance;
|
|
338
|
+
let container;
|
|
339
|
+
|
|
340
|
+
const options = {
|
|
341
|
+
autoplay: true,
|
|
342
|
+
delay: 3000,
|
|
343
|
+
breakpoints: [
|
|
344
|
+
{ columns: 1, gap: '16px' },
|
|
345
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
346
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
347
|
+
],
|
|
348
|
+
onChange: (state) => console.log(state)
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
function handleNext() {
|
|
352
|
+
instance?.next();
|
|
353
|
+
}
|
|
354
|
+
</script>
|
|
355
|
+
|
|
356
|
+
<MotionRail {options} bind:instance bind:container>
|
|
357
|
+
<div>Item 1</div>
|
|
358
|
+
<div>Item 2</div>
|
|
359
|
+
<div>Item 3</div>
|
|
360
|
+
</MotionRail>
|
|
361
|
+
<button on:click={handleNext}>Next</button>
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**Props:**
|
|
365
|
+
- `options`: MotionRailOptions object
|
|
366
|
+
- `bind:instance`: Binds the MotionRail instance
|
|
367
|
+
- `bind:container`: Binds the container HTMLDivElement
|
|
368
|
+
|
|
369
|
+
### Svelte 5 Integration (Runes)
|
|
370
|
+
|
|
371
|
+
```svelte
|
|
372
|
+
<script>
|
|
373
|
+
import { MotionRail } from 'motionrail/svelte5';
|
|
374
|
+
import 'motionrail/style.css';
|
|
375
|
+
|
|
376
|
+
let instance = $state();
|
|
377
|
+
let container = $state();
|
|
378
|
+
|
|
379
|
+
const options = {
|
|
380
|
+
autoplay: true,
|
|
381
|
+
delay: 3000,
|
|
382
|
+
breakpoints: [
|
|
383
|
+
{ columns: 1, gap: '16px' },
|
|
384
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
385
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
386
|
+
],
|
|
387
|
+
onChange: (state) => console.log(state)
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
function handleNext() {
|
|
391
|
+
instance?.next();
|
|
392
|
+
}
|
|
393
|
+
</script>
|
|
394
|
+
|
|
395
|
+
<MotionRail {options} bind:instance bind:container>
|
|
396
|
+
<div>Item 1</div>
|
|
397
|
+
<div>Item 2</div>
|
|
398
|
+
<div>Item 3</div>
|
|
399
|
+
</MotionRail>
|
|
400
|
+
<button onclick={handleNext}>Next</button>
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
**Props:**
|
|
404
|
+
- `options`: MotionRailOptions object
|
|
405
|
+
- `bind:instance`: Binds the MotionRail instance (using $bindable)
|
|
406
|
+
- `bind:container`: Binds the container HTMLDivElement (using $bindable)
|
|
407
|
+
|
|
408
|
+
**Note:** All framework integrations automatically handle dynamic children updates using the `update()` method. No manual reinitialization needed when items change.
|
|
409
|
+
|
|
91
410
|
## Configuration Options
|
|
92
411
|
|
|
93
412
|
| Option | Type | Default | Description |
|