This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sphere image in hero for safari browser
- Loading branch information
Showing
9 changed files
with
113 additions
and
61 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
landing/fragments/landing-hero/src/helpers/define-safari-browser.helper.ts
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,17 @@ | ||
import { Browser } from '../landing-hero.constants' | ||
|
||
export const defineSafariBrowser = (): boolean => { | ||
if (typeof navigator !== 'undefined') { | ||
const userAgent = navigator.userAgent.toLowerCase() | ||
|
||
return ( | ||
userAgent.includes(Browser.SAFARI) && | ||
!userAgent.includes(Browser.CHROME) && | ||
!userAgent.includes(Browser.OPERA) && | ||
!userAgent.includes(Browser.YANDEX) && | ||
!userAgent.includes(Browser.FIREFOX) | ||
) | ||
} | ||
|
||
return false | ||
} |
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 @@ | ||
export * from './define-safari-browser.helper' |
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
41 changes: 41 additions & 0 deletions
41
landing/fragments/landing-hero/src/sphere/sphere.component.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,41 @@ | ||
import React from 'react' | ||
import { FastAverageColorResult } from 'fast-average-color' | ||
import { FastAverageColor } from 'fast-average-color' | ||
import { useEffect } from 'react' | ||
import { useState } from 'react' | ||
|
||
import { CDN_VIDEO_PATH } from '../landing-hero.constants' | ||
import { CDN_VIDEO_MINE } from '../landing-hero.constants' | ||
import { Video } from '../video' | ||
|
||
const fac = new FastAverageColor() | ||
|
||
export const Sphere = ({ setBackgroundColor }) => { | ||
const [videoIsPlaying, setVideoIsPlaying] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
if (!videoIsPlaying) return | ||
|
||
const videoElement = document.querySelector('video') | ||
|
||
const getColor = () => { | ||
try { | ||
let color: FastAverageColorResult | undefined | ||
|
||
// eslint-disable-next-line prefer-const | ||
color = fac.getColor(videoElement, { algorithm: 'dominant' }) | ||
if (color.value.every((value) => value === 0)) return | ||
|
||
setBackgroundColor(color?.rgb) | ||
} catch (error) { | ||
if (process.env.NODE_ENV !== 'production') throw error | ||
} | ||
} | ||
|
||
getColor() | ||
}, [videoIsPlaying, setBackgroundColor]) | ||
|
||
return ( | ||
<Video mimeType={CDN_VIDEO_MINE} src={CDN_VIDEO_PATH} onPlay={() => setVideoIsPlaying(true)} /> | ||
) | ||
} |
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