-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2290460
commit 090b555
Showing
9 changed files
with
160 additions
and
53 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 |
---|---|---|
|
@@ -36,3 +36,5 @@ yarn-error.log* | |
.vercel | ||
|
||
.eslintcache | ||
|
||
.npmrc |
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,60 @@ | ||
import { useRect } from '@studio-freight/hamo' | ||
import { gsap } from 'gsap' | ||
import { SplitText as GSAPSplitText } from 'gsap/dist/SplitText' | ||
import { | ||
forwardRef, | ||
useEffect, | ||
useImperativeHandle, | ||
useMemo, | ||
useRef, | ||
useState, | ||
} from 'react' | ||
import s from './split-text.module.scss' | ||
|
||
gsap.registerPlugin(GSAPSplitText) | ||
|
||
export const SplitText = forwardRef(function SplitText( | ||
{ children, className, type }, | ||
ref, | ||
) { | ||
const elementRef = useRef() | ||
const [setRectRef, rect] = useRect() | ||
|
||
const [splitted, setSplitted] = useState() | ||
|
||
useImperativeHandle(ref, () => splitted, [splitted]) | ||
|
||
useEffect(() => { | ||
const splitted = new GSAPSplitText(elementRef.current, { | ||
tag: 'span', | ||
type, | ||
}) | ||
setSplitted(splitted) | ||
|
||
return () => { | ||
splitted.revert() | ||
setSplitted() | ||
} | ||
}, [rect, type]) | ||
|
||
const render = useMemo( | ||
() => ( | ||
<span className={className}> | ||
<span className={s.wrapper}> | ||
<span | ||
style={{ visibility: 'hidden', display: 'inline-block' }} | ||
ref={setRectRef} | ||
> | ||
{children} | ||
</span> | ||
<span ref={elementRef} className={s.splitText}> | ||
{children} | ||
</span> | ||
</span> | ||
</span> | ||
), | ||
[children, className], | ||
) | ||
|
||
return render | ||
}) |
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,9 @@ | ||
.wrapper { | ||
display: inline-block; | ||
position: relative; | ||
|
||
.splitText { | ||
position: absolute; | ||
inset: 0; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
090b555
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"⚡️ Lighthouse report for the changes in this commit:
🟠 Performance: 56
🟢 Accessibility: 97
🟢 Best practices: 100
🟠 SEO: 75
🔴 PWA: 30
Lighthouse ran on https://astro-satus-d7tuymmgx-studio-freight.vercel.app/"