-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
20 changed files
with
196 additions
and
76 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { BackgroundContainerProps } from '@components' | ||
import { createContext, useState } from 'react' | ||
|
||
type Props = { | ||
backgroundContainerProps: BackgroundContainerProps | undefined | ||
setBackgroundContainerProps: React.Dispatch<React.SetStateAction<BackgroundContainerProps | undefined>> | ||
} | ||
|
||
type ProviderProps = { | ||
children: React.ReactNode | ||
} | ||
|
||
export const BackgroundContext = createContext<Props>({ | ||
backgroundContainerProps: undefined, | ||
setBackgroundContainerProps: () => { | ||
return | ||
}, | ||
}) | ||
|
||
export const BackgroundContextProvider = ({ children }: ProviderProps) => { | ||
const [backgroundContainerProps, setBackgroundContainerProps] = useState({ | ||
background: { backgroundColor: 'White' }, | ||
} as BackgroundContainerProps | undefined) | ||
|
||
return ( | ||
<BackgroundContext.Provider value={{ backgroundContainerProps, setBackgroundContainerProps }}> | ||
{children} | ||
</BackgroundContext.Provider> | ||
) | ||
} |
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
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
52 changes: 52 additions & 0 deletions
52
web/pageComponents/pageTemplates/shared/FixedBackground.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,52 @@ | ||
import { BackgroundContext } from '@components/Backgrounds/BackgroundContext' | ||
import { useSanityLoader } from 'lib/hooks/useSanityLoader' | ||
import { useContext, forwardRef, HTMLAttributes, useEffect, useState, memo } from 'react' | ||
import styled from 'styled-components' | ||
import { getContainerColor } from '@utils/backgroundColours' | ||
|
||
type ContainerProps = { | ||
imageUrl?: string | ||
backgroundColor: String | ||
} | ||
const ImageContainer = styled.div<ContainerProps>` | ||
position: relative; | ||
background-attachment: fixed; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
background-color: ${({ color, imageUrl }) => `var(${color})`}; | ||
background-image: ${({ color, imageUrl }) => | ||
imageUrl ? `linear-gradient(to right, rgba(0, 0, 0, 0), var(${color}) 70%), url(${imageUrl})` : 'none'}; | ||
transition: all 0.5s ease-out; | ||
//animation: reveal 5s; | ||
/*@keyframes reveal { | ||
from { | ||
opacity: 0.2; | ||
} | ||
to { | ||
opacity: 1; | ||
} | ||
}*/ | ||
` | ||
|
||
export const FixedBackground = memo( | ||
forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(function FixedBackground( | ||
{ children, className, style, ...rest }, | ||
ref, | ||
) { | ||
const { backgroundContainerProps } = useContext(BackgroundContext) | ||
const background = backgroundContainerProps?.background | ||
|
||
const styleVariant = getContainerColor(background?.backgroundColor || 'White') | ||
|
||
let props = undefined | ||
if (background?.imageBackground?.image) { | ||
props = useSanityLoader(background?.imageBackground?.image, 1920, undefined) | ||
} | ||
return ( | ||
<ImageContainer imageUrl={props?.src} color={styleVariant}> | ||
{children} | ||
</ImageContainer> | ||
) | ||
}), | ||
) |
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
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
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
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
Oops, something went wrong.