-
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.
- Loading branch information
1 parent
bbd54c1
commit ef31df3
Showing
7 changed files
with
305 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
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 |
---|---|---|
@@ -0,0 +1,210 @@ | ||
import { type CSSProperties, useRef } from 'react' | ||
|
||
import { InfoOutlineIcon, Tooltip } from '@pluralsh/design-system' | ||
|
||
import styled, { useTheme } from 'styled-components' | ||
|
||
import { useMousePosition } from '@src/hooks/useMousePosition' | ||
|
||
import { ResponsiveText } from '../Typography' | ||
|
||
export function ImpactCardSection() { | ||
return ( | ||
<div className="flex flex-col items-center gap-xxlarge"> | ||
<ResponsiveText textStyles={{ '': 'mHero1' }}>Our impact</ResponsiveText> | ||
<ImpactCardsWrapperSC> | ||
<ImpactCard | ||
metric="88%" | ||
subtitle="Reduction in Operational Costs" | ||
embellishment="top-left" | ||
// tooltipText="Tooltip" | ||
borderGradientDir="to right" | ||
/> | ||
<ImpactCard | ||
metric="95%" | ||
subtitle="Reduction in Day 2 Operation Time" | ||
// tooltipText="Tooltip" | ||
borderGradientDir="to left" | ||
/> | ||
<ImpactCard | ||
metric="50%" | ||
subtitle="Allocation of Engineers to Strategic Projects" | ||
// tooltipText="Tooltip" | ||
borderGradientDir="to right" | ||
/> | ||
<ImpactCard | ||
metric="~30x" | ||
subtitle="ROI Over 3 Years" | ||
// tooltipText="Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. Lorem ipsum dolor sit amet consecutor. " | ||
embellishment="bottom-right" | ||
borderGradientDir="to left" | ||
/> | ||
</ImpactCardsWrapperSC> | ||
</div> | ||
) | ||
} | ||
|
||
function ImpactCard({ | ||
metric, | ||
subtitle, | ||
tooltipText, | ||
embellishment, | ||
borderGradientDir = 'to right', | ||
}: { | ||
metric: string | ||
subtitle: string | ||
tooltipText?: string | ||
embellishment?: 'top-left' | 'bottom-right' | ||
borderGradientDir?: 'to right' | 'to left' | ||
}) { | ||
const theme = useTheme() | ||
const cardRef = useRef<HTMLDivElement>(null) | ||
const { relativePosition } = useMousePosition(cardRef) | ||
|
||
const backgroundStyle = { | ||
'--x': `${relativePosition.x}px`, | ||
'--y': `${relativePosition.y}px`, | ||
} as CSSProperties | ||
|
||
return ( | ||
<ImpactCardSC | ||
ref={cardRef} | ||
style={backgroundStyle} | ||
css={` | ||
@property --gradient-opacity { | ||
syntax: '<number>'; | ||
inherits: false; | ||
initial-value: 0.3; | ||
} | ||
`} | ||
$borderGradientDir={borderGradientDir} | ||
> | ||
{embellishment && <EmblishmentSC $position={embellishment} />} | ||
<ImpactCardContentSC> | ||
{tooltipText && ( | ||
<Tooltip | ||
placement="top" | ||
label={tooltipText} | ||
{...theme.partials.marketingText.body1} | ||
backgroundColor={theme.colors['marketing-white']} | ||
color={theme.colors.grey[600]} | ||
maxWidth={500} | ||
> | ||
<ImpactCardInfoIconSC size={32} /> | ||
</Tooltip> | ||
)} | ||
<ImpactCardMetricSC>{metric}</ImpactCardMetricSC> | ||
<ImpactCardSubtitleSC>{subtitle}</ImpactCardSubtitleSC> | ||
</ImpactCardContentSC> | ||
</ImpactCardSC> | ||
) | ||
} | ||
|
||
const ImpactCardsWrapperSC = styled.div(({ theme }) => ({ | ||
display: 'grid', | ||
gridTemplateColumns: 'repeat(1, minmax(0, 1fr))', | ||
gap: theme.spacing.xxlarge, | ||
paddingBottom: theme.spacing.xxxxlarge, | ||
[`@media (min-width: ${theme.breakpoints.desktopSmall}px)`]: { | ||
gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', | ||
}, | ||
})) | ||
|
||
const ImpactCardSC = styled.div<{ | ||
$borderGradientDir?: 'to right' | 'to left' | ||
}>(({ theme, $borderGradientDir }) => ({ | ||
position: 'relative', | ||
borderRadius: theme.borderRadiuses.large, | ||
overflow: 'hidden', | ||
transition: 'filter 0.3s ease', | ||
// first value is circular glow that follows cursor, second is actual background | ||
background: `radial-gradient(400px circle at var(--x) var(--y),rgba(255, 255, 255, 0.06), transparent), | ||
linear-gradient(96deg, rgba(42, 46, 55, 0.48) -95.57%, rgba(42, 46, 55, 0.16) 113.54%)`, | ||
// trick to make a border with a gradient effect | ||
'::before': { | ||
transition: '--gradient-opacity 0.3s ease', | ||
content: '""', | ||
position: 'absolute', | ||
inset: 0, | ||
borderRadius: theme.borderRadiuses.large, | ||
border: '1px solid transparent', | ||
background: `linear-gradient(${$borderGradientDir}, #E9EBEC, rgba(233, 235, 236, var(--gradient-opacity))) border-box`, | ||
mask: 'linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0)', | ||
maskComposite: 'exclude', | ||
}, | ||
':hover': { | ||
'::before': { | ||
'--gradient-opacity': 1, | ||
}, | ||
filter: 'brightness(1.1)', | ||
}, | ||
})) | ||
|
||
const ImpactCardContentSC = styled.div(({ theme }) => ({ | ||
position: 'relative', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
gap: theme.spacing.medium, | ||
borderRadius: theme.borderRadiuses.large, | ||
padding: theme.spacing.xxlarge, | ||
})) | ||
|
||
const ImpactCardInfoIconSC = styled(InfoOutlineIcon)(({ theme }) => ({ | ||
position: 'absolute', | ||
cursor: 'pointer', | ||
top: theme.spacing.medium, | ||
right: theme.spacing.medium, | ||
})) | ||
|
||
const ImpactCardMetricSC = styled.h3(({ theme }) => ({ | ||
...theme.partials.marketingText.hero1, | ||
lineHeight: '100%', | ||
})) | ||
|
||
const ImpactCardSubtitleSC = styled.p(({ theme }) => ({ | ||
color: theme.colors['text-light'], | ||
fontFamily: 'Inter', | ||
fontSize: '28px', | ||
fontStyle: 'normal', | ||
fontWeight: 400, | ||
lineHeight: '150%', | ||
})) | ||
|
||
const EmblishmentSC = styled.div<{ $position: 'top-left' | 'bottom-right' }>( | ||
({ $position }) => { | ||
const size = 300 | ||
const strokeWidth = 1 | ||
const gradientBorderSVG = encodeURIComponent(` | ||
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${size} ${size}'> | ||
<defs> | ||
<linearGradient id='grad1' x1='0%' y1='0%' x2='100%' y2='0%'> | ||
<stop offset='0%' stop-color='#5C77FF00'/> | ||
<stop offset='30%' stop-color='#494FF299'/> | ||
<stop offset='36%' stop-color='#8FD6FF5C'/> | ||
<stop offset='50%' stop-color='#52F4D94D'/> | ||
</linearGradient> | ||
</defs> | ||
<circle | ||
cx='${size / 2}' | ||
cy='${size / 2}' | ||
r='${(size - strokeWidth) / 2}' | ||
fill='none' | ||
stroke='url(#grad1)' | ||
stroke-width='${strokeWidth}' | ||
/> | ||
</svg> | ||
`) | ||
|
||
return { | ||
position: 'absolute', | ||
top: $position === 'top-left' ? -size / 2 : 'auto', | ||
left: $position === 'top-left' ? -size / 2 : 'auto', | ||
right: $position === 'bottom-right' ? -size / 2 : 'auto', | ||
bottom: $position === 'bottom-right' ? -size / 2 : 'auto', | ||
width: `${size}px`, | ||
height: `${size}px`, | ||
backgroundImage: `url("data:image/svg+xml,${gradientBorderSVG}")`, | ||
} | ||
} | ||
) |
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,12 +1,19 @@ | ||
// import original module declarations | ||
import 'styled-components' | ||
|
||
import { type styledTheme } from '@pluralsh/design-system' | ||
|
||
import { type CSSProp } from 'styled-components' | ||
|
||
// Allow css prop on html elements | ||
declare module 'react' { | ||
interface Attributes { | ||
css?: CSSProp | undefined | ||
} | ||
} | ||
|
||
type StyledTheme = typeof styledTheme | ||
|
||
// and extend them! | ||
// extend original module declarations | ||
declare module 'styled-components' { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface DefaultTheme extends StyledTheme {} | ||
export declare function useTheme(): DefaultTheme | ||
} |
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,48 @@ | ||
import { type RefObject, useEffect, useState } from 'react' | ||
|
||
type MouseCoordinates = { | ||
x: number | null | ||
y: number | null | ||
} | ||
|
||
export function useMousePosition(): { mousePosition: MouseCoordinates } | ||
export function useMousePosition(elementRef: RefObject<HTMLElement>): { | ||
mousePosition: MouseCoordinates | ||
relativePosition: MouseCoordinates | ||
} | ||
|
||
export function useMousePosition(elementRef?: RefObject<HTMLElement>) { | ||
const [mousePosition, setMousePosition] = useState<MouseCoordinates>({ | ||
x: null, | ||
y: null, | ||
}) | ||
|
||
useEffect(() => { | ||
const updateMousePosition = (ev: MouseEvent) => { | ||
setMousePosition({ x: ev.clientX, y: ev.clientY }) | ||
} | ||
|
||
window.addEventListener('mousemove', updateMousePosition) | ||
|
||
return () => { | ||
window.removeEventListener('mousemove', updateMousePosition) | ||
} | ||
}, []) | ||
|
||
let relativePosition: MouseCoordinates = { x: null, y: null } | ||
|
||
if ( | ||
elementRef?.current && | ||
mousePosition.x !== null && | ||
mousePosition.y !== null | ||
) { | ||
const rect = elementRef.current.getBoundingClientRect() | ||
|
||
relativePosition = { | ||
x: mousePosition.x - rect.left, | ||
y: mousePosition.y - rect.top, | ||
} | ||
} | ||
|
||
return elementRef ? { mousePosition, relativePosition } : { mousePosition } | ||
} |