Skip to content

Commit

Permalink
add impact section
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman committed Sep 30, 2024
1 parent bbd54c1 commit c38d0ed
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ module.exports = {
},
},
],
// Allow css prop for styled-components
'react/no-unknown-property': ['error', { ignore: ['css'] }],
}
19 changes: 15 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FooterVariant } from '@src/components/FooterFull'
import { GradientBG } from '@src/components/layout/GradientBG'
import { HeaderPad } from '@src/components/layout/HeaderPad'
import ArticleSection from '@src/components/page-sections/articleSection'
import { ImpactCardSection } from '@src/components/page-sections/ImpactCardSection'
import { QuoteSection } from '@src/components/page-sections/QuoteSection'
import { HomePageHero } from '@src/components/PageHeros'
import { CenteredSectionHead } from '@src/components/SectionHeads'
Expand Down Expand Up @@ -306,10 +307,20 @@ export default function Index({
</StandardPageWidth>
</div>
</HeaderPad>
<QuoteSection
title="Delivering value to DevOps and Platform Engineering teams"
quotes={quotes ?? []}
/>
<div
css={{
background:
'linear-gradient(to bottom, #0E1015, #747AF6 60%, #102356)',
}}
>
<StandardPageWidth className="pb-xxxxxlarge">
<QuoteSection
title="Delivering value to DevOps and Platform Engineering teams"
quotes={quotes ?? []}
/>
<ImpactCardSection />
</StandardPageWidth>
</div>
<HomepageFeaturesSection />
<ArticleSection articleCards={articleCards} />
</>
Expand Down
210 changes: 210 additions & 0 deletions src/components/page-sections/ImpactCardSection.tsx
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}")`,
}
}
)
46 changes: 19 additions & 27 deletions src/components/page-sections/QuoteSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import styled, { useTheme } from 'styled-components'

import { type QuoteFragment } from '@src/generated/graphqlDirectus'

import { StandardPageWidth } from '../layout/LayoutHelpers'
import { QuotesCarousel } from '../QuoteCards'
import { ResponsiveText } from '../Typography'

Expand All @@ -16,33 +15,26 @@ export function QuoteSection({
const theme = useTheme()

return (
<StandardPageWidth
style={{
background:
'linear-gradient(to bottom, #0E1015, rgba(14, 16, 21, 0)), linear-gradient(to bottom, #0A0F8F, #747AF6)',
}}
>
<div className="flex flex-col items-start justify-between gap-large px-xxxlarge py-xxxxxxlarge lg:flex-row">
<ResponsiveText
as="h3"
textStyles={{ lg: 'mHero1', '': 'mHero2' }}
className="w-full max-w-[500px] lg:w-1/2"
style={{ color: theme.colors.grey[25] }}
>
{title}
</ResponsiveText>
<div className="relative w-full max-w-[500px] lg:w-1/2">
<DoubleQuote style={{ top: -30, left: -50 }} />
<QuotesCarousel
quotes={quotes}
quoteElement={<QuoteText />}
/>
<DoubleQuote
style={{ transform: 'rotate(180deg)', bottom: 40, right: 0 }}
/>
</div>
<div className="flex flex-col items-center justify-between gap-large py-xxxxxxlarge lg:flex-row lg:items-start">
<ResponsiveText
as="h3"
textStyles={{ lg: 'mHero1', '': 'mHero2' }}
className="w-full max-w-[500px] lg:w-1/2"
style={{ color: theme.colors.grey[25] }}
>
{title}
</ResponsiveText>
<div className="relative w-full max-w-[500px] lg:w-1/2">
<DoubleQuote style={{ top: -30, left: -50 }} />
<QuotesCarousel
quotes={quotes}
quoteElement={<QuoteText />}
/>
<DoubleQuote
style={{ transform: 'rotate(180deg)', bottom: 40, right: 0 }}
/>
</div>
</StandardPageWidth>
</div>
)
}

Expand Down
13 changes: 10 additions & 3 deletions src/components/types/styled.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// import original module declarations
import 'styled-components'
import { CSSProp } from 'styled-components'

import { type styledTheme } from '@pluralsh/design-system'

// 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
}
48 changes: 48 additions & 0 deletions src/hooks/useMousePosition.tsx
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 }
}

0 comments on commit c38d0ed

Please sign in to comment.