Skip to content

Commit b4ab9a8

Browse files
committed
Upgrade examples to Vite and fix intersection observer mock
1 parent c52965c commit b4ab9a8

File tree

15 files changed

+3494
-16842
lines changed

15 files changed

+3494
-16842
lines changed

examples/global.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
export {};
1+
/// <reference types="vite/client" />
22

33
declare global {
44
var runner: {
55
name: 'vi' | 'jest';
66
useFakeTimers: () => void;
77
useRealTimers: () => void;
88
advanceTimersByTime: (time: number) => Promise<void>;
9-
fn: () => jest.Mock<any, any>;
9+
fn: () => jest.Mock | ReturnType<typeof vi.fn>;
1010
};
1111
}
12+
13+
export {};
File renamed without changes.

examples/package-lock.json

Lines changed: 3411 additions & 16766 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,32 @@
66
"@testing-library/jest-dom": "^6.6.4",
77
"@testing-library/react": "^16.3.0",
88
"@testing-library/user-event": "^14.6.1",
9-
"@types/jest": "^27.5.2",
9+
"@types/jest": "^30.0.0",
1010
"@types/react": "^19.1.8",
1111
"@types/react-dom": "^19.1.6",
12-
"motion": "^10.15.5",
13-
"react": "^18.2.0",
14-
"react-dom": "^18.2.0",
15-
"react-router-dom": "^6.3.0",
16-
"react-scripts": "^5.0.1",
17-
"typescript": "^4.7.4"
12+
"motion": "^12.23.11",
13+
"react": "^19.1.1",
14+
"react-dom": "^19.1.1",
15+
"react-router-dom": "^7.7.1",
16+
"typescript": "^5.8.3"
1817
},
1918
"scripts": {
20-
"start": "react-scripts start",
21-
"build": "react-scripts build",
22-
"test:jest": "react-scripts test --watchAll=false",
19+
"start": "vite",
20+
"build": "vite build",
21+
"preview": "vite preview",
22+
"test:jest": "jest --config ./swcjest.config.js",
2323
"test:swc": "jest --config ./swcjest.config.js",
2424
"test:vi": "vitest --config ./vitest.config.ts run",
2525
"test:all": "npm run test:jest && npm run test:vi && npm run test:swc",
26-
"eject": "react-scripts eject"
27-
},
28-
"eslintConfig": {
29-
"extends": [
30-
"react-app",
31-
"react-app/jest"
32-
]
33-
},
34-
"browserslist": {
35-
"production": [
36-
">0.2%",
37-
"not dead",
38-
"not op_mini all"
39-
],
40-
"development": [
41-
"last 1 chrome version",
42-
"last 1 firefox version",
43-
"last 1 safari version"
44-
]
26+
"lint": "eslint src --ext .ts,.tsx,.js,.jsx",
27+
"typecheck": "tsc --noEmit"
4528
},
4629
"devDependencies": {
4730
"@types/node": "^24.1.0",
4831
"@vitejs/plugin-react": "^4.7.0",
32+
"eslint": "^9.0.0",
4933
"identity-obj-proxy": "^3.0.0",
34+
"vite": "^7.0.6",
5035
"vitest": "^3.2.4"
51-
},
52-
"jest": {
53-
"moduleNameMapper": {
54-
"\\.(css|less)$": "identity-obj-proxy"
55-
}
5636
}
5737
}

examples/src/components/animations/examples/inview/InView.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ const AnimationsInView = () => {
1010
return;
1111
}
1212

13-
const stop = inView('.inview-section', ({ target }) => {
14-
const span = target.querySelector('span');
13+
const stop = inView('.inview-section', (element) => {
14+
const span = element.querySelector('span');
1515

1616
if (span) {
17-
animate(
18-
span,
19-
{ opacity: 1, transform: 'none' },
20-
{ delay: 0.2, duration: 0.9, easing: [0.17, 0.55, 0.55, 1] }
21-
);
17+
animate(span, { opacity: 1, transform: 'none' }, { delay: 0.2, duration: 0.9 });
2218
}
2319
});
2420

examples/src/components/intersection-observer/global-observer/useIntersection.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useState, useEffect, MutableRefObject } from 'react';
22

3-
const entryCallbacks: {
4-
[key: string]: (entry: IntersectionObserverEntry) => void;
5-
} = {};
3+
const entryCallbacks = new Map<string, (entry: IntersectionObserverEntry) => void>();
64
let id = 0;
75
let observer: IntersectionObserver;
86

@@ -15,9 +13,8 @@ function createObserver() {
1513
observer = new IntersectionObserver(
1614
(entries) =>
1715
entries.forEach((entry) => {
18-
entryCallbacks[(entry.target as HTMLElement).dataset._ioid as string](
19-
entry
20-
);
16+
const callback = entryCallbacks.get((entry.target as HTMLElement).dataset._ioid as string);
17+
callback?.(entry);
2118
}),
2219
{
2320
rootMargin: '-30% 0% -30% 0%',
@@ -38,14 +35,14 @@ const useIntersection = (
3835
return;
3936
}
4037

41-
const domId = generateId();
38+
const domId = generateId().toString();
4239

43-
entryCallbacks[domId.toString()] = (entry) => {
40+
entryCallbacks.set(domId, (entry) => {
4441
setIsIntersecting(entry.isIntersecting);
4542
callback?.([entry], observer);
46-
};
43+
});
4744

48-
node.dataset._ioid = domId.toString();
45+
node.dataset._ioid = domId;
4946

5047
if (!observer) {
5148
createObserver();
@@ -54,7 +51,7 @@ const useIntersection = (
5451
observer.observe(node);
5552

5653
return () => {
57-
delete entryCallbacks[domId];
54+
entryCallbacks.delete(domId);
5855
observer.unobserve(node);
5956
};
6057
}, [callback, ref]);

examples/src/components/resize-observer/measure-parent/MeasureParent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { useRef } from 'react';
33
import useDoIFit from './useDoIFit';
44

55
const MeasureParent = () => {
6-
const ref1 = useRef(null);
7-
const ref2 = useRef(null);
6+
const ref1 = useRef<HTMLDivElement>(null);
7+
const ref2 = useRef<HTMLDivElement>(null);
88
const iFit1 = useDoIFit(ref1);
99
const iFit2 = useDoIFit(ref2);
1010

examples/src/components/resize-observer/measure-parent/useDoIFit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
const useDoIFit = (ref: React.RefObject<HTMLElement>) => {
3+
const useDoIFit = (ref: React.RefObject<HTMLElement | null>) => {
44
const [iFit, setIFit] = useState(false);
55

66
useEffect(() => {

examples/src/components/viewport/custom-use-media/useMedia.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { useState, useEffect, useCallback } from 'react';
22

33
function useMedia(
44
query: string,
5-
defaultValue: any | null = null,
5+
defaultValue: boolean | null = null,
66
options?:
77
| {
8-
callback?: (this: MediaQueryList, ev: MediaQueryListEvent) => any;
8+
callback?: (this: MediaQueryList, ev: MediaQueryListEvent) => void;
99
asObject: false;
1010
}
1111
| {
12-
callback?: (ev: MediaQueryListEvent) => any;
12+
callback?: (ev: MediaQueryListEvent) => void;
1313
asObject: true;
1414
}
1515
) {

examples/src/components/viewport/deprecated-use-media/DeprecatedUseMedia.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useState, useEffect, useCallback } from 'react';
22

33
function useMedia(
44
query: string,
5-
defaultValue: any | null = null,
6-
callback?: (this: MediaQueryList, ev: MediaQueryListEvent) => any
5+
defaultValue: boolean | null = null,
6+
callback?: (this: MediaQueryList, ev: MediaQueryListEvent) => void
77
) {
88
const isInBrowser = typeof window !== 'undefined' && window.matchMedia;
99

0 commit comments

Comments
 (0)