-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(useReducedMotion): use state (#8008)
- Loading branch information
1 parent
b82c391
commit a698551
Showing
3 changed files
with
58 additions
and
61 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
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,42 @@ | ||
'use client'; | ||
|
||
import { useReducedMotion } from '../../lib/animation'; | ||
import { type SpinnerProps } from './Spinner'; | ||
|
||
interface SpinnerAnimationProps { | ||
size: SpinnerProps['size']; | ||
} | ||
|
||
export function SpinnerAnimation({ size = 'm' }: SpinnerAnimationProps) { | ||
const isReducedMotion = useReducedMotion(); | ||
|
||
if (isReducedMotion === undefined) { | ||
return null; | ||
} | ||
|
||
if (isReducedMotion) { | ||
return ( | ||
<animate | ||
attributeName="opacity" | ||
keyTimes="0; 0.5; 1" | ||
values="1; 0.1; 1" | ||
begin="0s" | ||
dur="2s" | ||
repeatCount="indefinite" | ||
/> | ||
); | ||
} | ||
|
||
const center = { s: 8, m: 12, l: 16, xl: 22 }[size]; | ||
return ( | ||
<animateTransform | ||
attributeType="XML" | ||
attributeName="transform" | ||
type="rotate" | ||
from={`0 ${center} ${center}`} | ||
to={`360 ${center} ${center}`} | ||
dur="0.7s" | ||
repeatCount="indefinite" | ||
/> | ||
); | ||
} |
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