Skip to content

Commit

Permalink
Use modal for all breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonnetangsu committed Dec 9, 2024
1 parent 6dd1f5f commit 7410386
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
40 changes: 5 additions & 35 deletions components/ChangemakerCard/ChangemakerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { useId, useRef, useState } from 'react';
import {
Description, Dialog, DialogPanel, DialogTitle, Transition, TransitionChild,
} from '@headlessui/react';
import { useMediaQuery, useOnClickOutside, useToggle } from 'usehooks-ts';
import { useOnClickOutside, useToggle } from 'usehooks-ts';
import { AnimateInView, type AnimationType } from '@/components/Animate';
import { Heading, type HeadingType, Text } from '@/components/Typography';
import { FlexBox } from '@/components/FlexBox';
import { HeroIcon } from '@/components/HeroIcon';
import useEscape from '@/hooks/useEscape';
import { config } from '@/utilities/config';
import { getProcessedImage } from '@/utilities/getProcessedImage';
import * as styles from './ChangemakerCard.styles';

Expand Down Expand Up @@ -41,8 +40,6 @@ export const ChangemakerCard = ({
className,
...props
}: ChangemakerCardProps) => {
const isNotPhone = useMediaQuery(`(min-width: ${config.breakpoints.sm}px)`);

const cardRef = useRef<HTMLDivElement>(null);
const buttonRef = useRef<HTMLButtonElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
Expand All @@ -53,19 +50,6 @@ export const ChangemakerCard = ({
// For the mobile modal
const [isModalOpen, setIsModalOpen] = useState(false);

const handleClick = () => {
// If it's not XS breakpoint, toggle the card content and if it is shown, focus on contentRef
if (isNotPhone) {
toggle();
if (!isShown) {
contentRef.current?.focus();
}
} else {
// Open the modal if it's XS breakpoint
setIsModalOpen(true);
}
};

// If card content is shown, clicking outside it will dismiss it
useOnClickOutside(cardRef, () => {
if (isShown) {
Expand Down Expand Up @@ -164,27 +148,13 @@ export const ChangemakerCard = ({
)}
</FlexBox>
</div>
{/* Content layer */}
{/* Content is displayed on an overlay over the card for all breakpoint except XS */}
<FlexBox
id={contentId}
aria-labelledby={headingId}
direction="col"
className={styles.cardContent(isHorizontal)}
aria-hidden={!isShown}
>
<div ref={contentRef} tabIndex={isShown ? 0 : -1} className={styles.contentWrapper(isHorizontal)}>
{children}
</div>
</FlexBox>
<button
ref={buttonRef}
type="button"
onClick={handleClick}
aria-label={isShown ? 'Dismiss' : `Read more about ${heading}`}
aria-controls={isNotPhone ? contentId : undefined}
aria-expanded={isShown || isModalOpen}
aria-haspopup={isNotPhone ? undefined : 'dialog'}
onClick={() => setIsModalOpen(true)}
aria-label={`Read more about ${heading}`}
aria-expanded={isModalOpen}
aria-haspopup="dialog"
className={styles.button}
>
<HeroIcon
Expand Down
2 changes: 1 addition & 1 deletion components/Storyblok/SbChangemakerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const SbChangemakerCard = ({
},
blok,
}: SbChangemakerCardProps) => {
const Body = !!getNumBloks(body) ? <CreateBloks blokSection={body} baseFontSize={isHorizontal ? 'changemakerHorizontal' : 'changemaker'} /> : undefined;
const Body = !!getNumBloks(body) ? <CreateBloks blokSection={body} baseFontSize="card" /> : undefined;

return (
<ChangemakerCard
Expand Down

0 comments on commit 7410386

Please sign in to comment.