@rcaferati/react-awesome-slider 5.0.0

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -0
  3. package/dist/autoplay.d.mts +20 -0
  4. package/dist/autoplay.d.ts +20 -0
  5. package/dist/autoplay.js +1880 -0
  6. package/dist/autoplay.js.map +1 -0
  7. package/dist/autoplay.mjs +1869 -0
  8. package/dist/autoplay.mjs.map +1 -0
  9. package/dist/captioned.css +50 -0
  10. package/dist/captioned.d.mts +17 -0
  11. package/dist/captioned.d.ts +17 -0
  12. package/dist/captioned.js +1640 -0
  13. package/dist/captioned.js.map +1 -0
  14. package/dist/captioned.mjs +1623 -0
  15. package/dist/captioned.mjs.map +1 -0
  16. package/dist/custom-animations/cube-animation.css +1 -0
  17. package/dist/custom-animations/fall-animation.css +1 -0
  18. package/dist/custom-animations/fold-out-animation.css +1 -0
  19. package/dist/custom-animations/open-animation.css +1 -0
  20. package/dist/custom-animations/scale-out-animation.css +1 -0
  21. package/dist/index.d.mts +62 -0
  22. package/dist/index.d.ts +62 -0
  23. package/dist/index.js +1613 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/index.mjs +1590 -0
  26. package/dist/index.mjs.map +1 -0
  27. package/dist/lettering.css +163 -0
  28. package/dist/lettering.d.mts +17 -0
  29. package/dist/lettering.d.ts +17 -0
  30. package/dist/lettering.js +1637 -0
  31. package/dist/lettering.js.map +1 -0
  32. package/dist/lettering.mjs +1620 -0
  33. package/dist/lettering.mjs.map +1 -0
  34. package/dist/navigation.d.mts +37 -0
  35. package/dist/navigation.d.ts +37 -0
  36. package/dist/navigation.js +416 -0
  37. package/dist/navigation.js.map +1 -0
  38. package/dist/navigation.mjs +382 -0
  39. package/dist/navigation.mjs.map +1 -0
  40. package/dist/styles.css +383 -0
  41. package/package.json +172 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017–2026 Rafael Caferati
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,403 @@
1
+ # React `<AwesomeSlider />`
2
+
3
+ `@rcaferati/react-awesome-slider` provides a fast, production-ready slider/carousel with optional HOCs:
4
+
5
+ - **`AwesomeSlider`** — animated media/children slider
6
+ - **`withAutoplay`** — autoplay wrapper
7
+ - **`withCaptionedImages`** — caption overlay wrapper
8
+ - **`withAnimatedLettering`** — “screens → <p> lines” wrapper
9
+ - **Navigation utilities** — `Provider`, `Link`, `withNavigationContext`, `withNavigationHandlers`
10
+
11
+ This README is updated for the current v5+ patterns (functional core + CSS variables + optional CSS Modules).
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @rcaferati/react-awesome-slider
19
+ ```
20
+
21
+ Peer deps:
22
+
23
+ - `react >= 18`
24
+ - `react-dom >= 18`
25
+
26
+ ---
27
+
28
+ ## Quick Start
29
+
30
+ ### Plain CSS (no CSS Modules)
31
+
32
+ ```jsx
33
+ import React from 'react';
34
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
35
+ import '@rcaferati/react-awesome-slider/styles.css';
36
+
37
+ export default function Example() {
38
+ return (
39
+ <AwesomeSlider>
40
+ <div data-src="https://picsum.photos/id/1018/1200/600" />
41
+ <div data-src="https://picsum.photos/id/1015/1200/600" />
42
+ <div data-src="https://picsum.photos/id/1019/1200/600" />
43
+ </AwesomeSlider>
44
+ );
45
+ }
46
+ ```
47
+
48
+ ### Media prop (recommended for deterministic slides)
49
+
50
+ ```jsx
51
+ import React from 'react';
52
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
53
+ import '@rcaferati/react-awesome-slider/styles.css';
54
+
55
+ export default function Example() {
56
+ return (
57
+ <AwesomeSlider
58
+ media={[
59
+ { source: 'https://picsum.photos/id/1018/1200/600', slug: 'slide-1' },
60
+ { source: 'https://picsum.photos/id/1015/1200/600', slug: 'slide-2' },
61
+ { source: 'https://picsum.photos/id/1019/1200/600', slug: 'slide-3' },
62
+ ]}
63
+ />
64
+ );
65
+ }
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Animations
71
+
72
+ ### Default animation: `sideAnimation`
73
+
74
+ The default “side” animation ships in the base stylesheet:
75
+
76
+ ```js
77
+ import '@rcaferati/react-awesome-slider/styles.css';
78
+ ```
79
+
80
+ ### Extra animation recipes
81
+
82
+ Load one of the extra animation stylesheets and set `animation`:
83
+
84
+ - `cubeAnimation`
85
+ - `fallAnimation`
86
+ - `foldOutAnimation`
87
+ - `openAnimation`
88
+ - `scaleOutAnimation`
89
+
90
+ ```jsx
91
+ import React from 'react';
92
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
93
+
94
+ import '@rcaferati/react-awesome-slider/styles.css';
95
+ import '@rcaferati/react-awesome-slider/custom-animations/cube-animation.css';
96
+
97
+ export default function Example() {
98
+ return (
99
+ <AwesomeSlider animation="cubeAnimation">
100
+ <div data-src="https://picsum.photos/id/1018/1200/600" />
101
+ <div data-src="https://picsum.photos/id/1015/1200/600" />
102
+ <div data-src="https://picsum.photos/id/1019/1200/600" />
103
+ </AwesomeSlider>
104
+ );
105
+ }
106
+ ```
107
+
108
+ > Tip: When `animation="sideAnimation"` you typically omit `animation` entirely (core defaults).
109
+
110
+ ---
111
+
112
+ ## Styling
113
+
114
+ ### CSS variables (recommended)
115
+
116
+ The core stylesheet exposes CSS variables on the slider root element (default `awssld`).
117
+ You can override them per instance using `style`:
118
+
119
+ ```jsx
120
+ <AwesomeSlider
121
+ style={{
122
+ // arrows
123
+ '--organic-arrow-color': 'rgba(255,255,255,0.9)',
124
+ '--organic-arrow-height': '44px',
125
+ '--organic-arrow-thickness': '4px',
126
+
127
+ // bullets
128
+ '--control-bullet-color': 'rgba(255,255,255,0.35)',
129
+ '--control-bullet-active-color': 'rgba(255,255,255,0.9)',
130
+
131
+ // content
132
+ '--content-background-color': '#10131a',
133
+ }}
134
+ />
135
+ ```
136
+
137
+ ### CSS Modules (`cssModule`)
138
+
139
+ If your bundler emits CSS module maps, you can pass module objects via `cssModule`.
140
+ Many setups export the module object as `default` — this pattern is safe:
141
+
142
+ ```jsx
143
+ import AwsSliderStyles from '@rcaferati/react-awesome-slider/dist/styles.css?inline'; // (example — depends on bundler)
144
+ ```
145
+
146
+ In this repository’s Storybook setup, `*.scss` imports resolve to CSS module maps. In consumer apps, you’ll typically import prebuilt CSS files (`styles.css`, `captioned.css`, `lettering.css`, and `custom-animations/*.css`) unless you have a CSS-module pipeline configured.
147
+
148
+ ---
149
+
150
+ ## `AwesomeSlider`
151
+
152
+ ### Common usage patterns
153
+
154
+ #### Children mode (HTML slides)
155
+
156
+ ```jsx
157
+ <AwesomeSlider>
158
+ <div style={{ background: '#0b0f18', height: '100%' }}>
159
+ <h2 style={{ color: 'white' }}>Slide A</h2>
160
+ </div>
161
+ <div style={{ background: '#f4f6fb', height: '100%' }}>
162
+ <h2 style={{ color: '#111' }}>Slide B</h2>
163
+ </div>
164
+ </AwesomeSlider>
165
+ ```
166
+
167
+ #### Media mode (images/videos)
168
+
169
+ ```jsx
170
+ <AwesomeSlider
171
+ media={[
172
+ { source: '/img/0.jpg', slug: 'a' },
173
+ { source: '/img/1.jpg', slug: 'b' },
174
+ ]}
175
+ />
176
+ ```
177
+
178
+ ---
179
+
180
+ ## `AwesomeSlider` Props (current)
181
+
182
+ | Prop | Type | Default | Description |
183
+ | --------------------- | ---------------------------- | ------------------ | --------------------------------------------------------------------------------------- |
184
+ | `media` | `MediaItem[]` | `[]` | Slides as objects (`{ source, slug, preload? }`). |
185
+ | `children` | `ReactNode` | `null` | Slides as React children (supports `data-src` / `data-slug`). |
186
+ | `selected` | `number \| string` | `0` | Active slide index (number) or slug (string). |
187
+ | `name` | `string` | `'awesome-slider'` | Instance name (useful when multiple sliders are present). |
188
+ | `animation` | `string \| null` | `null` | Animation key (`cubeAnimation`, `fallAnimation`, etc). Omit for default side animation. |
189
+ | `buttons` | `boolean` | `true` | Show next/prev buttons. |
190
+ | `bullets` | `boolean` | `true` | Show bullets. |
191
+ | `organicArrows` | `boolean` | `true` | Use the organic arrow shape styling. |
192
+ | `infinite` | `boolean` | `true` | Wrap-around navigation. |
193
+ | `fillParent` | `boolean` | `false` | Fill parent bounds (fullscreen layouts). |
194
+ | `startupScreen` | `ReactNode` | `null` | Optional startup screen shown before first slide. |
195
+ | `startup` | `boolean` | `true` | If `startupScreen` is set, whether to auto-start into first slide. |
196
+ | `startupDelay` | `number` | `0` | Delay before auto-start. |
197
+ | `transitionDelay` | `number` | `0` | Delay before starting transition animation (ms). |
198
+ | `controlsReturnDelay` | `number` | `0` | Delay to remove “controls active” class after transitions (ms). |
199
+ | `mobileTouch` | `boolean` | `true` | Enables touch/swipe navigation. |
200
+ | `cssModule` | `object \| object[] \| null` | `null` | CSS module map(s) used to map class names. |
201
+ | `className` | `string \| null` | `null` | Extra className(s) added to root element. |
202
+ | `style` | `React.CSSProperties` | `{}` | Inline styles (also used for CSS variables). |
203
+ | `onFirstMount` | `(info) => void` | `null` | Called once after mount with `getInfo()` payload. |
204
+ | `onTransitionStart` | `(info) => void` | `null` | Called on transition start. |
205
+ | `onTransitionEnd` | `(info) => void` | `null` | Called on transition end. |
206
+ | `onTransitionRequest` | `(info) => void` | `null` | Called when user requests a transition (next/prev/bullet). |
207
+ | `onTransitionReject` | `(info) => void` | `null` | Called when a transition is rejected (e.g., busy/loading). |
208
+ | `onLoadStart` | `(payload) => void` | `null` | Optional custom preload hook. Call `payload.next()` when ready. |
209
+
210
+ ### `getInfo()` payload (high level)
211
+
212
+ `getInfo()` is used by the event callbacks and includes (best-effort):
213
+
214
+ - `slides` — slide count
215
+ - `currentIndex` — current index
216
+ - `currentMedia` — current media item
217
+ - `currentSlide` — active slide element (when available)
218
+ - `element` — slider root element
219
+
220
+ ---
221
+
222
+ ## HOCs
223
+
224
+ ### Autoplay
225
+
226
+ ```jsx
227
+ import React from 'react';
228
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
229
+ import withAutoplay from '@rcaferati/react-awesome-slider/autoplay';
230
+ import '@rcaferati/react-awesome-slider/styles.css';
231
+
232
+ const AutoplaySlider = withAutoplay(AwesomeSlider);
233
+
234
+ export default function Example() {
235
+ return (
236
+ <AutoplaySlider
237
+ play={true}
238
+ cancelOnInteraction={false}
239
+ interval={6000}
240
+ media={[
241
+ { source: 'https://picsum.photos/id/1018/1200/600' },
242
+ { source: 'https://picsum.photos/id/1015/1200/600' },
243
+ ]}
244
+ />
245
+ );
246
+ }
247
+ ```
248
+
249
+ ### Captioned Images
250
+
251
+ ```jsx
252
+ import React from 'react';
253
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
254
+ import withCaptionedImages from '@rcaferati/react-awesome-slider/captioned';
255
+
256
+ import '@rcaferati/react-awesome-slider/styles.css';
257
+ import '@rcaferati/react-awesome-slider/captioned.css';
258
+
259
+ const Captioned = withCaptionedImages(AwesomeSlider);
260
+
261
+ export default function Example() {
262
+ return (
263
+ <Captioned
264
+ screens={[
265
+ {
266
+ media: 'https://picsum.photos/id/1018/1200/600',
267
+ caption: 'The first captioned slide',
268
+ backgroundColor: '#ffffff',
269
+ },
270
+ {
271
+ media: 'https://picsum.photos/id/1015/1200/600',
272
+ caption: 'Second slide — caption overlay',
273
+ backgroundColor: '#ffffff',
274
+ },
275
+ ]}
276
+ />
277
+ );
278
+ }
279
+ ```
280
+
281
+ ### Animated Lettering
282
+
283
+ ```jsx
284
+ import React from 'react';
285
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
286
+ import withAnimatedLettering from '@rcaferati/react-awesome-slider/lettering';
287
+
288
+ import '@rcaferati/react-awesome-slider/styles.css';
289
+ import '@rcaferati/react-awesome-slider/lettering.css';
290
+
291
+ const Lettering = withAnimatedLettering(AwesomeSlider);
292
+
293
+ export default function Example() {
294
+ return (
295
+ <Lettering
296
+ screens={[
297
+ {
298
+ backgroundColor: '#ffffff',
299
+ children: [
300
+ 'React Awesome Slider',
301
+ 'Animated Lettering',
302
+ 'Each line is a <p>',
303
+ ],
304
+ },
305
+ {
306
+ backgroundColor: '#f5f5f5',
307
+ children: ['Transitions are slide-based', 'Text moves on change'],
308
+ },
309
+ ]}
310
+ />
311
+ );
312
+ }
313
+ ```
314
+
315
+ ### Adaptive Controls (optional HOC)
316
+
317
+ If your build includes `hoc/adaptive-controls`, it can compute a theme (light/dark) and apply CSS variables for arrows/bullets based on the active slide background.
318
+
319
+ > This HOC is intentionally CSS-modules-safe and applies variables to the real slider root.
320
+
321
+ ---
322
+
323
+ ## Fullpage Navigation Utilities
324
+
325
+ These are designed for SPA / “slides-as-routes” setups.
326
+
327
+ ### `Provider`
328
+
329
+ ```jsx
330
+ import React from 'react';
331
+ import { Provider } from '@rcaferati/react-awesome-slider/navigation';
332
+
333
+ export default function App({ children }) {
334
+ return (
335
+ <Provider slug={window.location.pathname} defaultSlug="home">
336
+ {children}
337
+ </Provider>
338
+ );
339
+ }
340
+ ```
341
+
342
+ ### `Link`
343
+
344
+ ```jsx
345
+ import React from 'react';
346
+ import { Link } from '@rcaferati/react-awesome-slider/navigation';
347
+
348
+ export default function Nav() {
349
+ return (
350
+ <nav>
351
+ <Link href="/home">Home</Link>
352
+ <Link href="/about">About</Link>
353
+ <Link href="/contact">Contact</Link>
354
+ </nav>
355
+ );
356
+ }
357
+ ```
358
+
359
+ ### `withNavigationHandlers`
360
+
361
+ Wrap a slider so URL ↔ slider selection stays aligned (supports popstate, retries on rejects, and mismatch correction).
362
+
363
+ ```jsx
364
+ import AwesomeSlider from '@rcaferati/react-awesome-slider';
365
+ import { withNavigationHandlers } from '@rcaferati/react-awesome-slider/navigation';
366
+
367
+ const SliderWithNav = withNavigationHandlers(AwesomeSlider);
368
+
369
+ export default function Page() {
370
+ return <SliderWithNav />;
371
+ }
372
+ ```
373
+
374
+ ---
375
+
376
+ ## Recommended patterns (current)
377
+
378
+ ### ✅ Prefer `media` for stable routing
379
+
380
+ If you use slugs + navigation handlers, keep `media` entries stable and include `slug`.
381
+
382
+ ### ✅ Keep animations modular
383
+
384
+ - Always load `styles.css`
385
+ - Load one extra animation CSS only when that animation is selected
386
+
387
+ ### ✅ Customize via CSS variables first
388
+
389
+ Theme/contrast/polish is usually easiest via the exposed custom properties.
390
+
391
+ ---
392
+
393
+ ## Author
394
+
395
+ **Rafael Caferati**
396
+ Website: https://caferati.dev
397
+ GitHub: https://github.com/rcaferati
398
+
399
+ ---
400
+
401
+ ## License
402
+
403
+ MIT
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ declare const AutoplayComponent: React.FC<P & {
4
+ interval?: number;
5
+ cssModule?: any;
6
+ play?: boolean;
7
+ cancelOnInteraction?: boolean;
8
+ timerHeight?: string;
9
+ timerBackgroundColor?: string;
10
+ showTimer?: boolean;
11
+ onTransitionStart?: ((info: any) => void) | null;
12
+ onTransitionEnd?: ((info: any) => void) | null;
13
+ onTransitionRequest?: ((info: any) => void) | null;
14
+ onFirstMount?: ((info: any) => void) | null;
15
+ rootElement?: string;
16
+ }>;
17
+ type AutoplayProps = React.ComponentProps<typeof AutoplayComponent>;
18
+ declare function Autoplay(props: AutoplayProps): any;
19
+
20
+ export { type AutoplayProps, Autoplay as default };
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ declare const AutoplayComponent: React.FC<P & {
4
+ interval?: number;
5
+ cssModule?: any;
6
+ play?: boolean;
7
+ cancelOnInteraction?: boolean;
8
+ timerHeight?: string;
9
+ timerBackgroundColor?: string;
10
+ showTimer?: boolean;
11
+ onTransitionStart?: ((info: any) => void) | null;
12
+ onTransitionEnd?: ((info: any) => void) | null;
13
+ onTransitionRequest?: ((info: any) => void) | null;
14
+ onFirstMount?: ((info: any) => void) | null;
15
+ rootElement?: string;
16
+ }>;
17
+ type AutoplayProps = React.ComponentProps<typeof AutoplayComponent>;
18
+ declare function Autoplay(props: AutoplayProps): any;
19
+
20
+ export { type AutoplayProps, Autoplay as default };