-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format: auto-fix new website formatting errors
- with `yarn lint --fix` - formatting errors are from b09e195
- Loading branch information
Showing
5 changed files
with
41 additions
and
35 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 |
---|---|---|
@@ -1,52 +1,52 @@ | ||
import { useRef, useCallback, useEffect } from 'react' | ||
import { useInView } from 'react-intersection-observer' | ||
import 'intersection-observer' | ||
import { useRef, useCallback, useEffect } from 'react'; | ||
import { useInView } from 'react-intersection-observer'; | ||
import 'intersection-observer'; | ||
|
||
export default ({ src, caption, ratio }) => { | ||
const [inViewRef, inView] = useInView({ | ||
threshold: 1, | ||
}) | ||
const videoRef = useRef() | ||
}); | ||
const videoRef = useRef(); | ||
|
||
const setRefs = useCallback( | ||
(node) => { | ||
node => { | ||
// Ref's from useRef needs to have the node assigned to `current` | ||
videoRef.current = node | ||
videoRef.current = node; | ||
// Callback refs, like the one from `useInView`, is a function that takes the node as an argument | ||
inViewRef(node) | ||
inViewRef(node); | ||
|
||
if (node) { | ||
node.addEventListener('click', function () { | ||
node.addEventListener('click', function() { | ||
if (this.paused) { | ||
this.play() | ||
this.play(); | ||
} else { | ||
this.pause() | ||
this.pause(); | ||
} | ||
}) | ||
}); | ||
} | ||
}, | ||
[inViewRef] | ||
) | ||
); | ||
|
||
useEffect(() => { | ||
if (!videoRef || !videoRef.current) { | ||
return | ||
return; | ||
} | ||
|
||
if (inView) { | ||
videoRef.current.play() | ||
videoRef.current.play(); | ||
} else { | ||
videoRef.current.pause() | ||
videoRef.current.pause(); | ||
} | ||
}, [inView]) | ||
}, [inView]); | ||
|
||
return ( | ||
<figure> | ||
<div style={{ paddingBottom: ratio * 100 + '%' }}/> | ||
<div style={{ paddingBottom: ratio * 100 + '%' }} /> | ||
<video loop muted autoPlay playsInline ref={setRefs}> | ||
<source src={src} type="video/mp4" /> | ||
</video> | ||
{caption && <figcaption>{caption}</figcaption>} | ||
</figure> | ||
) | ||
} | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
plugins: ['tailwindcss', 'postcss-preset-env'] | ||
} | ||
plugins: ['tailwindcss', 'postcss-preset-env'], | ||
}; |
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