-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use useSyncExternalStore for React hooks
- Loading branch information
Showing
3 changed files
with
57 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@number-flow/react': patch | ||
--- | ||
|
||
Use useSyncExternalStore for hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
import { useCanAnimate } from '@number-flow/react' | ||
import { useIsSupported, usePrefersReducedMotion } from '@number-flow/react' | ||
import clsx from 'clsx/lite' | ||
import Link from './Link' | ||
|
||
export default function Supported() { | ||
const canAnimate = useCanAnimate({ respectMotionPreference: false }) | ||
const reducedMotion = useCanAnimate({ respectMotionPreference: true }) | ||
const isSupported = useIsSupported() | ||
const reducedMotion = usePrefersReducedMotion() | ||
if (isSupported && !reducedMotion) return null | ||
|
||
return ( | ||
!reducedMotion && ( | ||
<> | ||
{/* The only way I could get the blend mode working was to separate the divs which requires fixed sizes */} | ||
<div | ||
role="presentation" | ||
className={clsx( | ||
canAnimate ? 'h-11.5' : 'h-16.5', | ||
'~top-4/8 fixed left-1/2 z-40 -ml-36 w-72 rounded-lg mix-blend-multiply shadow-lg shadow-amber-500/10 dark:shadow-amber-950/20' | ||
)} | ||
/> | ||
<div | ||
role="alert" | ||
className={clsx( | ||
canAnimate ? 'h-11.5' : 'h-16.5', | ||
'~top-4/8 prose prose-current fixed left-1/2 z-50 -ml-36 w-72 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-center text-sm text-amber-800 dark:border-amber-800/30 dark:bg-[#271202] dark:text-amber-50' | ||
)} | ||
> | ||
{!canAnimate ? ( | ||
<p> | ||
Your browser doesn't{' '} | ||
<Link href="https://caniuse.com/mdn-css_types_mod"> | ||
support NumberFlow’s animations | ||
</Link> | ||
</p> | ||
) : ( | ||
<p>Reduce motion is on</p> | ||
)} | ||
</div> | ||
</> | ||
) | ||
<> | ||
{/* The only way I could get the blend mode working was to separate the divs which requires fixed sizes */} | ||
<div | ||
role="presentation" | ||
className={clsx( | ||
reducedMotion ? 'h-11.5' : 'h-16.5', | ||
'~top-4/8 fixed left-1/2 z-40 -ml-36 w-72 rounded-lg mix-blend-multiply shadow-lg shadow-amber-500/10 dark:shadow-amber-950/20' | ||
)} | ||
/> | ||
<div | ||
role="alert" | ||
className={clsx( | ||
reducedMotion ? 'h-11.5' : 'h-16.5', | ||
'~top-4/8 prose prose-current fixed left-1/2 z-50 -ml-36 w-72 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-center text-sm text-amber-800 dark:border-amber-800/30 dark:bg-[#271202] dark:text-amber-50' | ||
)} | ||
> | ||
{reducedMotion ? ( | ||
<p>Reduce motion is on</p> | ||
) : ( | ||
<p> | ||
Your browser doesn't{' '} | ||
<Link href="https://caniuse.com/mdn-css_types_mod"> | ||
support NumberFlow’s animations | ||
</Link> | ||
</p> | ||
)} | ||
</div> | ||
</> | ||
) | ||
} |