react-spring-carousel 3.0.0-beta090.51 → 3.0.0-beta090.53

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 (58) hide show
  1. package/.storybook/main.ts +17 -0
  2. package/.storybook/preview.ts +15 -0
  3. package/README.md +50 -0
  4. package/eslint.config.js +28 -0
  5. package/index.html +13 -0
  6. package/lib/events.ts +39 -0
  7. package/lib/index.tsx +980 -0
  8. package/lib/types.ts +44 -0
  9. package/lib/useEventsModule.ts +51 -0
  10. package/lib/utils.ts +42 -0
  11. package/lib/vite-env.d.ts +1 -0
  12. package/package.json +36 -84
  13. package/src/stories/Button.stories.ts +52 -0
  14. package/src/stories/Button.tsx +48 -0
  15. package/src/stories/Configure.mdx +364 -0
  16. package/src/stories/Main.stories.ts +14 -0
  17. package/src/stories/Main.tsx +87 -0
  18. package/src/stories/assets/accessibility.png +0 -0
  19. package/src/stories/assets/accessibility.svg +1 -0
  20. package/src/stories/assets/addon-library.png +0 -0
  21. package/src/stories/assets/assets.png +0 -0
  22. package/src/stories/assets/avif-test-image.avif +0 -0
  23. package/src/stories/assets/context.png +0 -0
  24. package/src/stories/assets/discord.svg +1 -0
  25. package/src/stories/assets/docs.png +0 -0
  26. package/src/stories/assets/figma-plugin.png +0 -0
  27. package/src/stories/assets/github.svg +1 -0
  28. package/src/stories/assets/share.png +0 -0
  29. package/src/stories/assets/styling.png +0 -0
  30. package/src/stories/assets/testing.png +0 -0
  31. package/src/stories/assets/theming.png +0 -0
  32. package/src/stories/assets/tutorials.svg +1 -0
  33. package/src/stories/assets/youtube.svg +1 -0
  34. package/src/stories/button.css +30 -0
  35. package/src/stories/main.css +37 -0
  36. package/src/storybook.global.styles.css +5 -0
  37. package/tsconfig.app.json +24 -0
  38. package/tsconfig.json +7 -0
  39. package/tsconfig.node.json +22 -0
  40. package/vite.config.ts +30 -0
  41. package/dist/index.cjs.js +0 -28
  42. package/dist/index.cjs.js.map +0 -1
  43. package/dist/index.es.js +0 -1728
  44. package/dist/index.es.js.map +0 -1
  45. package/dist/types/index.d.ts +0 -3
  46. package/dist/types/modules/index.d.ts +0 -1
  47. package/dist/types/modules/useEventsModule.d.ts +0 -5
  48. package/dist/types/modules/useFullscreenModule.d.ts +0 -6
  49. package/dist/types/modules/useThumbsModule.d.ts +0 -6
  50. package/dist/types/types/common.d.ts +0 -36
  51. package/dist/types/types/index.d.ts +0 -4
  52. package/dist/types/types/useEventsModule.types.d.ts +0 -46
  53. package/dist/types/types/useFullscreenModule.types.d.ts +0 -6
  54. package/dist/types/types/useSpringCarousel.types.d.ts +0 -130
  55. package/dist/types/types/useThumbsModule.types.d.ts +0 -9
  56. package/dist/types/types/useTransitionCarousel.types.d.ts +0 -37
  57. package/dist/types/useSpringCarousel.d.ts +0 -12
  58. package/dist/types/useTransitionCarousel.d.ts +0 -5
package/lib/types.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { ReactNode } from "react";
2
+
3
+ type Item = {
4
+ id: string;
5
+ renderItem: ReactNode;
6
+ renderThumb?: ReactNode;
7
+ };
8
+
9
+ type SlideType = "fixed" | "fluid" | "freeScroll";
10
+
11
+ type FixedSlideTypeProps = {
12
+ slideType?: "fixed";
13
+ scrollAmount?: never;
14
+ itemsPerSlide?: number;
15
+ scrollAmountType?: "group" | "slide";
16
+ };
17
+ type FluidSlideTypeProps = {
18
+ slideType?: "fluid";
19
+ scrollAmount?: number;
20
+ itemsPerSlide?: never;
21
+ scrollAmountType?: never;
22
+ };
23
+ type FreeScrollSlideTypeProps = {
24
+ slideType?: "freeScroll";
25
+ scrollAmount?: number;
26
+ itemsPerSlide?: never;
27
+ scrollAmountType?: never;
28
+ withLoop?: never;
29
+ };
30
+
31
+ export type Props = {
32
+ init?: boolean;
33
+ slideType?: SlideType;
34
+ items: Item[];
35
+ withLoop?: boolean;
36
+ enableGestures?: boolean;
37
+ carouselAxis?: "x" | "y";
38
+ slideWhenDragThresholdIsReached?: boolean;
39
+ gutter?: number;
40
+ startEndGutter?: number;
41
+ fadeIn?: boolean;
42
+ } & (FixedSlideTypeProps | FluidSlideTypeProps | FreeScrollSlideTypeProps);
43
+
44
+ export * from "./events";
@@ -0,0 +1,51 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ import {
4
+ SpringCarouselEventsEventHandler,
5
+ SpringCarouselEvents,
6
+ } from "./events";
7
+
8
+ const eventLabel = "RSC::Event";
9
+
10
+ export function useEventsModule() {
11
+ const targetEvent = useRef<HTMLDivElement | null>(null);
12
+
13
+ function useListenToCustomEvent(
14
+ eventHandler: SpringCarouselEventsEventHandler
15
+ ) {
16
+ useEffect(() => {
17
+ if (!targetEvent.current) {
18
+ targetEvent.current = document.createElement("div");
19
+ }
20
+
21
+ function handleEvent(_event: Event) {
22
+ const event = _event as CustomEvent<SpringCarouselEvents>;
23
+ eventHandler(event.detail);
24
+ }
25
+
26
+ if (targetEvent.current) {
27
+ targetEvent.current.addEventListener(eventLabel, handleEvent, false);
28
+ return () => {
29
+ targetEvent.current?.removeEventListener(
30
+ eventLabel,
31
+ handleEvent,
32
+ false
33
+ );
34
+ };
35
+ }
36
+ }, [eventHandler]);
37
+ }
38
+ function emitEvent(event: SpringCarouselEvents) {
39
+ if (targetEvent.current) {
40
+ const newEvent = new CustomEvent(eventLabel, {
41
+ detail: event,
42
+ });
43
+ targetEvent.current.dispatchEvent(newEvent);
44
+ }
45
+ }
46
+
47
+ return {
48
+ useListenToCustomEvent,
49
+ emitEvent,
50
+ };
51
+ }
package/lib/utils.ts ADDED
@@ -0,0 +1,42 @@
1
+ function isOutOfViewport(element: Element): {
2
+ isOut: boolean;
3
+ direction: "start" | "end" | null;
4
+ } {
5
+ const { left, right, top, bottom } = element.getBoundingClientRect();
6
+ const { innerWidth, innerHeight } = window;
7
+
8
+ if (left < 0 || top < 0) {
9
+ return {
10
+ isOut: true,
11
+ direction: "start",
12
+ };
13
+ }
14
+
15
+ if (
16
+ Math.floor(right) > Math.floor(innerWidth) ||
17
+ Math.floor(bottom) > Math.floor(innerHeight)
18
+ ) {
19
+ return {
20
+ isOut: true,
21
+ direction: "end",
22
+ };
23
+ }
24
+
25
+ return {
26
+ isOut: false,
27
+ direction: null,
28
+ };
29
+ }
30
+ function pFloat(v: number) {
31
+ return parseFloat(v.toFixed(2));
32
+ }
33
+ function logWarn(message: string) {
34
+ if (process.env.NODE_ENV !== "production") {
35
+ console.warn(message);
36
+ }
37
+ }
38
+ function logError(message: string) {
39
+ console.error(message);
40
+ }
41
+
42
+ export { isOutOfViewport, pFloat, logWarn, logError };
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/package.json CHANGED
@@ -1,101 +1,53 @@
1
1
  {
2
2
  "name": "react-spring-carousel",
3
- "version": "3.0.0-beta090.51",
4
- "description": "A new <Carousel /> experience for the web",
5
- "homepage": "https://react-spring-carousel.emilianobucci.com",
6
- "repository": "https://github.com/Emiliano-Bucci/react-spring-carousel",
7
- "author": "Emiliano Bucci",
8
- "license": "MIT",
9
- "main": "./dist/index.cjs.js",
10
- "module": "./dist/index.es.js",
11
- "types": "./dist/types/index.d.ts",
12
- "files": [
13
- "dist/*"
14
- ],
15
- "exports": {
16
- ".": {
17
- "import": "./dist/index.es.js",
18
- "module": "./dist/index.es.js",
19
- "require": "./dist/index.cjs.js",
20
- "types": "./dist/types/index.d.ts"
21
- }
22
- },
3
+ "version": "3.0.0-beta090.53",
4
+ "type": "module",
23
5
  "scripts": {
24
6
  "dev": "vite",
25
- "build": "tsc && vite build",
7
+ "build": "tsc -b && vite build",
8
+ "lint": "eslint .",
26
9
  "preview": "vite preview",
27
10
  "storybook": "storybook dev -p 6006",
28
11
  "build-storybook": "storybook build",
29
- "release:beta": "git push && npm run build && npm publish --tag beta",
30
- "lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
31
- "lint:fix": "eslint --fix 'src/**/*.{jsx,ts,tsx}'",
32
- "format": "prettier --write src//**/*.{ts,tsx} --config ./.prettierrc",
33
- "prepare": "husky install"
12
+ "release:beta": "git push && npm run build && npm publish --tag beta"
34
13
  },
35
- "keywords": [
36
- "react",
37
- "react-spring",
38
- "carousel",
39
- "react-carousel",
40
- "react-spring-carousel",
41
- "slider",
42
- "react-slider",
43
- "react-spring-slider",
44
- "animated"
45
- ],
46
- "devDependencies": {
47
- "@storybook/addon-essentials": "^7.5.0",
48
- "@storybook/addon-interactions": "^7.5.0",
49
- "@storybook/addon-links": "^7.5.0",
50
- "@storybook/blocks": "^7.5.0",
51
- "@storybook/manager-api": "^7.5.0",
52
- "@storybook/react": "^7.5.0",
53
- "@storybook/react-vite": "^7.5.0",
54
- "@storybook/testing-library": "^0.2.2",
55
- "@storybook/theming": "^7.5.0",
56
- "@types/react": "^18.0.28",
57
- "@types/react-dom": "^18.0.11",
58
- "@typescript-eslint/eslint-plugin": "^5.59.0",
59
- "@typescript-eslint/parser": "^5.59.0",
60
- "@vitejs/plugin-react": "^4.0.0-beta.0",
61
- "eslint": "^8.39.0",
62
- "eslint-config-prettier": "^8.8.0",
63
- "eslint-plugin-prettier": "^4.2.1",
64
- "eslint-plugin-react": "^7.32.2",
65
- "eslint-plugin-react-hooks": "^4.6.0",
66
- "eslint-plugin-react-refresh": "^0.3.4",
67
- "eslint-plugin-simple-import-sort": "^10.0.0",
68
- "eslint-plugin-storybook": "^0.6.15",
69
- "husky": "^8.0.3",
70
- "lint-staged": "^13.2.1",
71
- "prettier": "^2.8.8",
72
- "prop-types": "^15.8.1",
73
- "react": "^18.2.0",
74
- "react-dom": "^18.2.0",
75
- "react-hooks": "^1.0.1",
76
- "storybook": "^7.5.0",
77
- "typescript": "^5.0.2",
78
- "vite": "^4.3.0",
79
- "vite-plugin-dts": "^2.3.0",
80
- "vite-tsconfig-paths": "^4.2.0"
14
+ "dependencies": {
15
+ "@use-gesture/react": "^10.2.26"
81
16
  },
82
17
  "peerDependencies": {
83
18
  "@react-spring/web": "^9.5.4",
84
- "@use-gesture/react": "^10.2.26",
85
19
  "react": "^18.0.0",
86
- "react-dom": "^18.0.0",
87
- "resize-observer-polyfill": "^1.5.1",
88
- "screenfull": "^5.2.0"
20
+ "react-dom": "^18.0.0"
89
21
  },
90
- "husky": {
91
- "hooks": {
92
- "pre-commit": "lint-staged"
93
- }
22
+ "devDependencies": {
23
+ "@chromatic-com/storybook": "^1.7.0",
24
+ "@eslint/js": "^9.9.0",
25
+ "@storybook/addon-essentials": "^8.2.9",
26
+ "@storybook/addon-interactions": "^8.2.9",
27
+ "@storybook/addon-links": "^8.2.9",
28
+ "@storybook/addon-onboarding": "^8.2.9",
29
+ "@storybook/blocks": "^8.2.9",
30
+ "@storybook/react": "^8.2.9",
31
+ "@storybook/react-vite": "^8.2.9",
32
+ "@storybook/test": "^8.2.9",
33
+ "@types/node": "^22.5.0",
34
+ "@types/react": "^18.3.3",
35
+ "@types/react-dom": "^18.3.0",
36
+ "@vitejs/plugin-react-swc": "^3.5.0",
37
+ "eslint": "^9.9.0",
38
+ "eslint-plugin-react-hooks": "^5.1.0-rc.0",
39
+ "eslint-plugin-react-refresh": "^0.4.9",
40
+ "eslint-plugin-storybook": "^0.8.0",
41
+ "globals": "^15.9.0",
42
+ "storybook": "^8.2.9",
43
+ "typescript": "^5.5.3",
44
+ "typescript-eslint": "^8.0.1",
45
+ "vite": "^5.4.1",
46
+ "vite-plugin-dts": "^4.0.3"
94
47
  },
95
- "lint-staged": {
96
- "src/**/*.{js,jsx,ts,tsx}": [
97
- "npx eslint",
98
- "npm run format"
48
+ "eslintConfig": {
49
+ "extends": [
50
+ "plugin:storybook/recommended"
99
51
  ]
100
52
  }
101
53
  }
@@ -0,0 +1,52 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { fn } from '@storybook/test';
3
+ import { Button } from './Button';
4
+
5
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
6
+ const meta = {
7
+ title: 'Example/Button',
8
+ component: Button,
9
+ parameters: {
10
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
11
+ layout: 'centered',
12
+ },
13
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
14
+ tags: ['autodocs'],
15
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
16
+ argTypes: {
17
+ backgroundColor: { control: 'color' },
18
+ },
19
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
20
+ args: { onClick: fn() },
21
+ } satisfies Meta<typeof Button>;
22
+
23
+ export default meta;
24
+ type Story = StoryObj<typeof meta>;
25
+
26
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
27
+ export const Primary: Story = {
28
+ args: {
29
+ primary: true,
30
+ label: 'Button',
31
+ },
32
+ };
33
+
34
+ export const Secondary: Story = {
35
+ args: {
36
+ label: 'Button',
37
+ },
38
+ };
39
+
40
+ export const Large: Story = {
41
+ args: {
42
+ size: 'large',
43
+ label: 'Button',
44
+ },
45
+ };
46
+
47
+ export const Small: Story = {
48
+ args: {
49
+ size: 'small',
50
+ label: 'Button',
51
+ },
52
+ };
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import './button.css';
3
+
4
+ export interface ButtonProps {
5
+ /**
6
+ * Is this the principal call to action on the page?
7
+ */
8
+ primary?: boolean;
9
+ /**
10
+ * What background color to use
11
+ */
12
+ backgroundColor?: string;
13
+ /**
14
+ * How large should the button be?
15
+ */
16
+ size?: 'small' | 'medium' | 'large';
17
+ /**
18
+ * Button contents
19
+ */
20
+ label: string;
21
+ /**
22
+ * Optional click handler
23
+ */
24
+ onClick?: () => void;
25
+ }
26
+
27
+ /**
28
+ * Primary UI component for user interaction
29
+ */
30
+ export const Button = ({
31
+ primary = false,
32
+ size = 'medium',
33
+ backgroundColor,
34
+ label,
35
+ ...props
36
+ }: ButtonProps) => {
37
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
38
+ return (
39
+ <button
40
+ type="button"
41
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
42
+ style={{ backgroundColor }}
43
+ {...props}
44
+ >
45
+ {label}
46
+ </button>
47
+ );
48
+ };