Skip to content

Commit

Permalink
docs(nxdev): add animation background fallback (#9654)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcabanes committed Apr 1, 2022
1 parent 43eee23 commit 9b13b53
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions nx-dev/nx-dev/pages/index.tsx
Expand Up @@ -23,9 +23,35 @@ import {
} from '@nrwl/nx-dev/ui-home';
import { NextSeo } from 'next-seo';
import Link from 'next/link';
import { ReactComponentElement } from 'react';
import { ReactComponentElement, useEffect, useState } from 'react';

export function Index(): ReactComponentElement<any> {
/**
* Detects whether we should use a background fallback or not.
* `false` by default
*/
function useHeroBackgroundFallback(): boolean {
const [useFallback, setUseFallback] = useState<boolean>(false);

useEffect(() => {
function handleResize(): void {
// Firefox has a hard time rendering SVG for high resolutions
if (navigator.userAgent.search(/firefox/gi) !== -1) {
if (window.innerWidth > 1460) {
return setUseFallback(true);
}
}
return setUseFallback(false);
}
handleResize();
window.addEventListener('resize', handleResize);
return (): void => window.removeEventListener('resize', handleResize);
}, []);

return useFallback;
}
const showBackgroundFallback = useHeroBackgroundFallback();

return (
<>
<NextSeo
Expand Down Expand Up @@ -58,7 +84,9 @@ export function Index(): ReactComponentElement<any> {
id="animated-background"
className="bg-blue-nx-base transform-gpu bg-clip-border bg-right bg-no-repeat bg-origin-border text-white lg:bg-cover"
style={{
backgroundImage: 'url(/images/background/hero-bg-large.svg)',
backgroundImage: showBackgroundFallback
? 'url(/images/background/hero-bg.jpg)'
: 'url(/images/background/hero-bg-large.svg)',
}}
>
<div className="md:py-18 mx-auto max-w-screen-lg px-4 py-4 xl:max-w-screen-xl">
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 9b13b53

@vercel
Copy link

@vercel vercel bot commented on 9b13b53 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.