-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
useSynchronizedAnimation
to storybook, and export
- Loading branch information
Showing
7 changed files
with
128 additions
and
3 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { useMediaQuery } from './useMediaQuery'; | ||
export { usePrevious } from './usePrevious'; | ||
export { useSynchronizedAnimation } from './useSynchronizedAnimation'; | ||
export { useSynchronizedAnimation } from './useSynchronizedAnimation/useSynchronizedAnimation'; | ||
export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; |
26 changes: 26 additions & 0 deletions
26
packages/react/src/hooks/useSynchronizedAnimation/useSynchronizedAnimation.mdx
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,26 @@ | ||
import { Meta, Primary, ArgTypes } from '@storybook/blocks'; | ||
|
||
import * as SyncStories from './useSynchronizedAnimation.stories'; | ||
import { useSynchronizedAnimation } from '../'; | ||
|
||
<Meta of={SyncStories} /> | ||
|
||
# useSynchronizedAnimation | ||
|
||
En react hook for å synkronisere CSS animasjoner på tvers av flere elementer. | ||
|
||
<Primary /> | ||
|
||
Du sender inn navnet på animasjonen du vil synkronisere. | ||
Hooken returnerer en `ref`, som du sender til elementet ditt. | ||
Animasjonen på elementet ditt blir synkronsisert til den første animasjonen med samme navn på siden. | ||
|
||
## Bruk | ||
|
||
```tsx | ||
const SyncedBox = () => { | ||
const ref = useSynchronizedAnimation<HTMLDivElement>('spin'); | ||
|
||
return <div ref={ref} />; | ||
}; | ||
``` |
85 changes: 85 additions & 0 deletions
85
packages/react/src/hooks/useSynchronizedAnimation/useSynchronizedAnimation.stories.tsx
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,85 @@ | ||
import type { Meta, StoryFn } from '@storybook/react'; | ||
import { useState } from 'react'; | ||
|
||
import { Button } from '../../components'; | ||
|
||
import { useSynchronizedAnimation } from './useSynchronizedAnimation'; | ||
|
||
const decorators = [ | ||
(Story: StoryFn) => ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '20px', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
padding: '20px', | ||
}} | ||
> | ||
<Story /> | ||
</div> | ||
), | ||
]; | ||
|
||
const meta: Meta = { | ||
title: 'Hooks/useSynchronizedAnimation', | ||
decorators, | ||
}; | ||
|
||
export default meta; | ||
|
||
const boxStyle = { | ||
width: '30px', | ||
height: '30px', | ||
backgroundColor: 'red', | ||
}; | ||
|
||
const SyncedBox = () => { | ||
const ref = useSynchronizedAnimation<HTMLDivElement>('spin'); | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
style={{ | ||
animation: 'spin 2s linear infinite', | ||
...boxStyle, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export const TestSync = () => { | ||
const [count, setCount] = useState(1); | ||
|
||
return ( | ||
<> | ||
<Button onClick={() => setCount(count + 1)}>Ny boks</Button> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
gap: '10px', | ||
maxWidth: '300px', | ||
flexWrap: 'wrap', | ||
}} | ||
> | ||
{Array.from({ length: count }).map((_, i) => ( | ||
<SyncedBox key={i} /> | ||
))} | ||
</div> | ||
|
||
<style> | ||
{` | ||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
`} | ||
</style> | ||
</> | ||
); | ||
}; |
File renamed without changes.
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 +1,2 @@ | ||
export * from './components'; | ||
export { useSynchronizedAnimation } from './hooks'; |