Skip to content

Commit da6bc3b

Browse files
committed
main 🧊 add support text
1 parent 29ccf3d commit da6bc3b

23 files changed

Lines changed: 395 additions & 60 deletions

File tree

‎packages/core/src/bundle/hooks/useGamepad/useGamepad.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ export const useGamepad = () => {
3030
if (gamepad && gamepads[gamepad.index]) gamepads[gamepad.index] = createGamepad(gamepad);
3131
}
3232
};
33-
const { active } = useRaf(updateGamepadState, { enabled: !!Object.keys(gamepads).length });
33+
const { active } = useRaf(updateGamepadState, {
34+
enabled: !!Object.keys(gamepads).length
35+
});
3436
useEffect(() => {
3537
if (!supported) return;
3638
const gamepads = navigator.getGamepads();
3739
setGamepads(
3840
gamepads.reduce(
39-
(acc, gamepad) => ({ ...acc, ...(gamepad && { [gamepad.index]: createGamepad(gamepad) }) }),
41+
(acc, gamepad) => ({
42+
...acc,
43+
...(gamepad && { [gamepad.index]: createGamepad(gamepad) })
44+
}),
4045
{}
4146
)
4247
);

‎packages/core/src/bundle/hooks/useIntersectionObserver/useIntersectionObserver.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useRefState } from '../useRefState/useRefState';
1313
* @param {boolean} [options.enabled=true] The IntersectionObserver options
1414
* @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
1515
* @param {HookTarget} [options.root] The root element to observe
16-
* @returns {UseIntersectionObserverReturn} An object containing the state and the supported status
16+
* @returns {UseIntersectionObserverReturn} An object containing the state
1717
*
1818
* @example
1919
* const { ref, entry, inView } = useIntersectionObserver();

‎packages/core/src/bundle/hooks/useMemory/useMemory.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import { useInterval } from '../useInterval/useInterval';
1313
* const { supported, value } = useMemory();
1414
*/
1515
export const useMemory = () => {
16-
const supported = performance && 'memory' in performance;
17-
const [value, setValue] = useState({
18-
jsHeapSizeLimit: 0,
19-
totalJSHeapSize: 0,
20-
usedJSHeapSize: 0
16+
const supported = performance && 'memory' in performance && !!performance.memory;
17+
const [value, setValue] = useState(
18+
performance?.memory ?? {
19+
jsHeapSizeLimit: 0,
20+
totalJSHeapSize: 0,
21+
usedJSHeapSize: 0
22+
}
23+
);
24+
useInterval(() => setValue(performance.memory), 1000, {
25+
immediately: supported
2126
});
22-
useInterval(() => setValue(performance.memory), 1000, { immediately: supported });
2327
return { supported, value };
2428
};

‎packages/core/src/hooks/useDeviceOrientation/useDeviceOrientation.demo.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { useDeviceOrientation } from '@siberiacancode/reactuse';
33
const Demo = () => {
44
const deviceOrientation = useDeviceOrientation();
55

6+
if (!deviceOrientation.supported)
7+
return (
8+
<p>
9+
Api not supported, make sure to check for compatibility with different browsers when using
10+
this{' '}
11+
<a
12+
href='https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceOrientationEvent'
13+
rel='noreferrer'
14+
target='_blank'
15+
>
16+
api
17+
</a>
18+
</p>
19+
);
20+
621
return (
722
<pre lang='json'>
823
<b>Device orientation data:</b>

‎packages/core/src/hooks/useDevicePixelRatio/useDevicePixelRatio.demo.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ import { useDevicePixelRatio } from '@siberiacancode/reactuse';
33
const Demo = () => {
44
const { supported, ratio } = useDevicePixelRatio();
55

6-
if (!supported) {
7-
return <p>Device pixel ratio is not supported.</p>;
8-
}
6+
if (!supported)
7+
return (
8+
<p>
9+
Api not supported, make sure to check for compatibility with different browsers when using
10+
this{' '}
11+
<a
12+
href='https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio'
13+
rel='noreferrer'
14+
target='_blank'
15+
>
16+
api
17+
</a>
18+
</p>
19+
);
920

1021
return (
1122
<p>

‎packages/core/src/hooks/useDisplayMedia/useDisplayMedia.demo.tsx‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
import { useDisplayMedia } from '@siberiacancode/reactuse';
22

33
const Demo = () => {
4-
const { sharing, supported, start, stop, ref } = useDisplayMedia();
4+
const displayMedia = useDisplayMedia();
5+
6+
if (!displayMedia.supported)
7+
return (
8+
<p>
9+
Api not supported, make sure to check for compatibility with different browsers when using
10+
this{' '}
11+
<a
12+
href='https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia'
13+
rel='noreferrer'
14+
target='_blank'
15+
>
16+
api
17+
</a>
18+
</p>
19+
);
520

621
return (
722
<div className='flex flex-col gap-4'>
823
<div className='flex items-center justify-center gap-4'>
9-
<button disabled={!supported} type='button' onClick={sharing ? stop : start}>
10-
{sharing ? 'Stop Sharing' : 'Start Sharing'}
24+
<button
25+
type='button'
26+
onClick={displayMedia.sharing ? displayMedia.stop : displayMedia.start}
27+
>
28+
{displayMedia.sharing ? 'Stop Sharing' : 'Start Sharing'}
1129
</button>
1230
</div>
1331

14-
<video muted playsInline ref={ref} className='w-full max-w-2xl rounded border' autoPlay />
32+
<video
33+
muted
34+
playsInline
35+
ref={displayMedia.ref}
36+
className='w-full max-w-2xl rounded border'
37+
autoPlay
38+
/>
1539
</div>
1640
);
1741
};

‎packages/core/src/hooks/useEyeDropper/useEyeDropper.demo.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ import { useEyeDropper } from '@siberiacancode/reactuse';
33
const Demo = () => {
44
const eyeDropper = useEyeDropper();
55

6-
return (
7-
<>
6+
if (!eyeDropper.supported)
7+
return (
88
<p>
9-
supported: <code>{String(eyeDropper.supported)}</code>
9+
Api not supported, make sure to check for compatibility with different browsers when using
10+
this{' '}
11+
<a
12+
href='https://developer.mozilla.org/en-US/docs/Web/API/EyeDropper'
13+
rel='noreferrer'
14+
target='_blank'
15+
>
16+
api
17+
</a>
1018
</p>
19+
);
20+
21+
return (
22+
<>
1123
<p>
1224
value:{' '}
1325
<span style={{ color: eyeDropper.value }}>

‎packages/core/src/hooks/useGamepad/useGamepad.demo.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ import { useGamepad } from '@siberiacancode/reactuse';
33
const Demo = () => {
44
const { supported, gamepads } = useGamepad();
55

6-
return (
7-
<>
6+
if (!supported)
7+
return (
88
<p>
9-
supported: <code>{String(supported)}</code>
9+
Api not supported, make sure to check for compatibility with different browsers when using
10+
this{' '}
11+
<a
12+
href='https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getGamepads'
13+
rel='noreferrer'
14+
target='_blank'
15+
>
16+
api
17+
</a>
1018
</p>
19+
);
1120

21+
return (
22+
<>
1223
<p>Gamepads</p>
1324
{!gamepads.length && <code>no gamepads connected</code>}
1425
{!!gamepads.length && (

‎packages/core/src/hooks/useGamepad/useGamepad.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ export const useGamepad = () => {
5353
}
5454
};
5555

56-
const { active } = useRaf(updateGamepadState, { enabled: !!Object.keys(gamepads).length });
56+
const { active } = useRaf(updateGamepadState, {
57+
enabled: !!Object.keys(gamepads).length
58+
});
5759

5860
useEffect(() => {
5961
if (!supported) return;
6062
const gamepads = navigator.getGamepads();
6163
setGamepads(
6264
gamepads.reduce(
63-
(acc, gamepad) => ({ ...acc, ...(gamepad && { [gamepad.index]: createGamepad(gamepad) }) }),
65+
(acc, gamepad) => ({
66+
...acc,
67+
...(gamepad && { [gamepad.index]: createGamepad(gamepad) })
68+
}),
6469
{}
6570
)
6671
);

‎packages/core/src/hooks/useIntersectionObserver/useIntersectionObserver.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface UseIntersectionObserver {
4242
* @param {boolean} [options.enabled=true] The IntersectionObserver options
4343
* @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
4444
* @param {HookTarget} [options.root] The root element to observe
45-
* @returns {UseIntersectionObserverReturn} An object containing the state and the supported status
45+
* @returns {UseIntersectionObserverReturn} An object containing the state
4646
*
4747
* @example
4848
* const { ref, entry, inView } = useIntersectionObserver();

0 commit comments

Comments
 (0)