Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SLB-405-Fade-effect' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Luqmaan Essop committed Jun 18, 2024
2 parents 2b815f7 + 6fcb3a4 commit 2099de5
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 109 deletions.
42 changes: 42 additions & 0 deletions packages/ui/src/components/Molecules/FadeUp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use client';
import { motion } from 'framer-motion';
import React, { PropsWithChildren, useEffect, useState } from 'react';

export function FadeUp({
yGap,
children,
className,
}: PropsWithChildren<{ yGap: number; className?: string }>) {
const [reducedMotion, setReducedMotion] = useState(false);

useEffect(() => {
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');

const handleChange = () => {
setReducedMotion(mediaQuery.matches);
};

// Set the initial value
handleChange();

// Add the event listener
mediaQuery.addEventListener('change', handleChange);

return () => {
// Clean up the event listener on unmount
mediaQuery.removeEventListener('change', handleChange);
};
}, [reducedMotion]);

return (
<motion.div
className={className}
transition={{ duration: 0.8 }}
style={{ opacity: reducedMotion ? 1 : 0, y: reducedMotion ? 0 : yGap }}
viewport={{ once: true }}
whileInView={{ opacity: 1, y: 0 }}
>
{children}
</motion.div>
);
}
46 changes: 25 additions & 21 deletions packages/ui/src/components/Organisms/PageContent/BlockCta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ import {
import clsx from 'clsx';
import React from 'react';

import { FadeUp } from '../../Molecules/FadeUp';

export function BlockCta(props: BlockCtaFragment) {
return (
<div className="container-page">
<div className="container-content">
<div className="container-text my-2 lg:my-3">
<Link
className={clsx(
{
'flex-row-reverse':
props.iconPosition === CtaIconPosition.Before,
},
'text-blue-600 hover:text-white border border-blue-600 hover:bg-blue-600 focus:ring-4 focus:outline-none focus:ring-blue-300 rounded-lg py-2 px-3 gap-2 flex flex-row items-center text-xs leading-[1.125rem] font-medium text-center w-fit transition-all duration-200 ease-in-out group',
)}
href={props.url ?? ('/' as Url)}
target={props.openInNewTab ? '_blank' : '_self'}
rel="noreferrer"
>
{props.text}
{!!props.icon && props.icon === CtaIconType.Arrow && (
<ArrowRightIcon />
)}
</Link>
<FadeUp yGap={50}>
<div className="container-page">
<div className="container-content">
<div className="container-text my-2 lg:my-3">
<Link
className={clsx(
{
'flex-row-reverse':
props.iconPosition === CtaIconPosition.Before,
},
'text-blue-600 hover:text-white border border-blue-600 hover:bg-blue-600 focus:ring-4 focus:outline-none focus:ring-blue-300 rounded-lg py-2 px-3 gap-2 flex flex-row items-center text-xs leading-[1.125rem] font-medium text-center w-fit transition-all duration-200 ease-in-out group',
)}
href={props.url ?? ('/' as Url)}
target={props.openInNewTab ? '_blank' : '_self'}
rel="noreferrer"
>
{props.text}
{!!props.icon && props.icon === CtaIconType.Arrow && (
<ArrowRightIcon />
)}
</Link>
</div>
</div>
</div>
</div>
</FadeUp>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function BlockForm(
}

return (
<div className="container-page">
<div className="container-page my-10">
<div className="container-content">
<div className={clsx('container-text', props.className)}>
<SilverbackIframe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react';

import { FadeUp } from '../../Molecules/FadeUp';

export function BlockHorizontalSeparator() {
return (
<div className="container-page">
<FadeUp yGap={50} className="container-page my-8">
<div className="container-content">
<hr className="container-text my-8 text-gray-200" />
<hr className="container-text text-gray-200" />
</div>
</div>
</FadeUp>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import clsx from 'clsx';
import React from 'react';

import { isTruthy } from '../../../utils/isTruthy';
import { FadeUp } from '../../Molecules/FadeUp';

export function BlockImageTeasers(props: BlockImageTeasersFragment) {
return (
// eslint-disable-next-line tailwindcss/no-custom-classname
<section className="my-10 block-background-image-cards">
<div className="text-center">
<div
className={clsx('grid gap-2', {
'grid-cols-2': props.teasers.filter(isTruthy).length > 1,
})}
>
{props.teasers.filter(isTruthy).map((teaser, index) => (
<BlockImageTeaser key={index} {...teaser} />
))}
<FadeUp yGap={50} className="my-10 block-background-image-cards">
<section>
<div className="text-center">
<div
className={clsx('grid gap-2', {
'grid-cols-2': props.teasers.filter(isTruthy).length > 1,
})}
>
{props.teasers.filter(isTruthy).map((teaser, index) => (
<BlockImageTeaser key={index} {...teaser} />
))}
</div>
</div>
</div>
</section>
</section>
</FadeUp>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,41 @@ import {
import clsx from 'clsx';
import React from 'react';

import { FadeUp } from '../../Molecules/FadeUp';
import { BlockMarkup } from './BlockMarkup';

export function BlockImageWithText(props: BlockImageWithTextFragment) {
return (
<div className="container-page">
<div className="container-content my-12 lg:my-16">
<div
className={clsx(
'flex flex-col lg:flex-row gap-8 lg:gap-16 items-start lg:items-center',
{
'lg:flex-row-reverse':
props.imagePosition === ImagePosition.Right,
},
)}
>
{!!props.image?.source && (
<div className={'lg:w-1/2 self-start'}>
<Image
className="object-cover w-full"
source={props.image.source}
alt={props.image.alt || ''}
/>
</div>
)}

<div className={'lg:w-1/2 nested-container'}>
{props.textContent?.markup && (
<BlockMarkup {...props.textContent} />
<FadeUp yGap={50}>
<div className="container-page">
<div className="container-content my-12 lg:my-16">
<div
className={clsx(
'flex flex-col lg:flex-row gap-8 lg:gap-16 items-start lg:items-center',
{
'lg:flex-row-reverse':
props.imagePosition === ImagePosition.Right,
},
)}
>
{!!props.image?.source && (
<div className={'lg:w-1/2 self-start'}>
<Image
className="object-cover w-full"
source={props.image.source}
alt={props.image.alt || ''}
/>
</div>
)}

<div className={'lg:w-1/2 nested-container'}>
{props.textContent?.markup && (
<BlockMarkup {...props.textContent} />
)}
</div>
</div>
</div>
</div>
</div>
</FadeUp>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { selectAll } from 'hast-util-select';
import React, { PropsWithChildren } from 'react';
import { Plugin } from 'unified';

import { FadeUp } from '../../Molecules/FadeUp';

const unorderedItems: Plugin<[], Element> = () => (tree) => {
selectAll('ul > li', tree).forEach((node) => {
node.properties!.unordered = true;
Expand All @@ -13,7 +15,7 @@ const unorderedItems: Plugin<[], Element> = () => (tree) => {

export function BlockMarkup(props: BlockMarkupFragment) {
return (
<div className="container-page mt-10">
<FadeUp yGap={50} className="container-page my-10">
<div className="container-content">
<div className="container-text">
<div
Expand Down Expand Up @@ -51,6 +53,6 @@ export function BlockMarkup(props: BlockMarkupFragment) {
</div>
</div>
</div>
</div>
</FadeUp>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { BlockMediaFragment, Html, Image } from '@custom/schema';
import React from 'react';

import { UnreachableCaseError } from '../../../utils/unreachable-case-error';
import { FadeUp } from '../../Molecules/FadeUp';

export function BlockMedia(props: BlockMediaFragment) {
if (!props.media) {
return null;
}
return (
<div className="container-page">
<FadeUp yGap={50} className="container-page my-10">
<div className="container-content">
<figure className="mt-16 container-text">
<figure className="container-text">
<Media {...props.media} />
{props.caption ? (
<figcaption className="mt-3 flex justify-center gap-x-2 text-sm leading-6 text-gray-500">
Expand All @@ -19,7 +20,7 @@ export function BlockMedia(props: BlockMediaFragment) {
) : null}
</figure>
</div>
</div>
</FadeUp>
);
}

Expand Down
88 changes: 47 additions & 41 deletions packages/ui/src/components/Organisms/PageContent/BlockQuote.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
import { BlockQuoteFragment, Html, Image } from '@custom/schema';
import React from 'react';

import { FadeUp } from '../../Molecules/FadeUp';

export function BlockQuote(props: BlockQuoteFragment) {
return (
<div className="container-page">
<div className="container-content">
<div className="container-text">
<div className="prose lg:prose-xl prose-p:text-xl prose-p:font-bold prose-p:leading-8 prose-p:text-[#111928]">
<blockquote className="border-l-0 relative pl-0 pb-8 pt-16">
<svg
width="32"
height="24"
viewBox="0 0 32 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
role="img"
aria-labelledby="quote-svg-title"
>
<title id="quote-svg-title">Quote Symbol</title>
<path
d="M18.6893 24V14.1453C18.6893 6.54 23.664 1.38533 30.6667 0L31.9933 2.868C28.7507 4.09066 26.6667 7.71867 26.6667 10.6667H32V24H18.6893ZM0 24V14.1453C0 6.54 4.99733 1.384 12 0L13.328 2.868C10.084 4.09066 8 7.71867 8 10.6667L13.3107 10.6667V24H0Z"
fill="#9CA3AF"
/>
</svg>
<p>{props.quote && <Html markup={props.quote} />}</p>
<div className="flex not-prose items-center flex-wrap">
{props.image && (
<Image
className="w-6 h-6 rounded-full object-contain mr-3.5 "
source={props.image.source}
alt={props.image.alt || 'Author image'}
<FadeUp yGap={50} className="container-page mt-16 mb-8">
<div className="container-page">
<div className="container-content">
<div className="container-text">
<div className="prose lg:prose-xl prose-p:text-xl prose-p:font-bold prose-p:leading-8 prose-p:text-[#111928]">
<blockquote className="border-l-0 relative pl-0 pb-8 pt-16">
<svg
width="32"
height="24"
viewBox="0 0 32 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
role="img"
aria-labelledby="quote-svg-title"
>
<title id="quote-svg-title">Quote Symbol</title>
<path
d="M18.6893 24V14.1453C18.6893 6.54 23.664 1.38533 30.6667 0L31.9933 2.868C28.7507 4.09066 26.6667 7.71867 26.6667 10.6667H32V24H18.6893ZM0 24V14.1453C0 6.54 4.99733 1.384 12 0L13.328 2.868C10.084 4.09066 8 7.71867 8 10.6667L13.3107 10.6667V24H0Z"
fill="#9CA3AF"
/>
)}
<div className="not-italic text-base font-semibold">
{props.author && <p className="not-prose">{props.author}</p>}
</svg>
<p>{props.quote && <Html markup={props.quote} />}</p>
<div className="flex not-prose items-center flex-wrap">
{props.image && (
<Image
className="w-6 h-6 rounded-full object-contain mr-3.5 "
source={props.image.source}
alt={props.image.alt || 'Author image'}
/>
)}
<div className="not-italic text-base font-semibold">
{props.author && (
<p className="not-prose">{props.author}</p>
)}
</div>
{props.role && (
<p className="not-prose flex">
<span className="ml-3 text-base">/</span>
<span className="mt-0.5 not-italic text-gray-500 text-sm ml-3">
{props.role}
</span>
</p>
)}
</div>
{props.role && (
<p className="not-prose flex">
<span className="ml-3 text-base">/</span>
<span className="mt-0.5 not-italic text-gray-500 text-sm ml-3">
{props.role}
</span>
</p>
)}
</div>
</blockquote>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</FadeUp>
);
}

0 comments on commit 2099de5

Please sign in to comment.