From 701021c36aa124b93ab4a14547618998cc58d0ca Mon Sep 17 00:00:00 2001 From: Corey Larson Date: Wed, 12 Jul 2023 10:48:42 -0500 Subject: [PATCH] Updates modal styling. --- src/components/atoms/Modal/Modal.css.ts | 19 +++++++------- src/components/atoms/Modal/index.tsx | 26 +++++++++++++++++-- src/components/organisms/Header/index.tsx | 2 +- .../organisms/HeroSection/HeroSection.css.ts | 10 +++++++ .../organisms/HeroSection/index.tsx | 7 +++-- src/components/organisms/Layout/index.tsx | 7 ++--- .../organisms/LocationSection/index.tsx | 5 +++- .../organisms/PartnersSection/index.tsx | 5 +++- src/pages/[year].astro | 2 +- 9 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/components/atoms/Modal/Modal.css.ts b/src/components/atoms/Modal/Modal.css.ts index 3215f5b..0e09e14 100644 --- a/src/components/atoms/Modal/Modal.css.ts +++ b/src/components/atoms/Modal/Modal.css.ts @@ -12,11 +12,12 @@ export const wrapper = style({ }); export const dialog = style({ + alignItems: 'center', backgroundColor: theme.colors.black, border: 0, color: theme.colors.white, display: 'grid', - gridTemplateRows: 'auto 1fr', + gridTemplateColumns: '1fr 1fr', height: '100%', margin: 0, maxHeight: '100%', @@ -73,9 +74,12 @@ globalStyle(`${dialog}::backdrop`, { export const header = style({ alignItems: 'center', display: 'flex', - justifyContent: 'space-between', + justifyContent: 'flex-end', paddingBlock: theme.spacing.small, paddingInline: theme.spacing.medium, + position: 'absolute', + top: 0, + width: '100%', '@media': { [queries.large]: { @@ -105,14 +109,10 @@ export const close = style({ justifyContent: 'center', width: theme.spacing.large, zIndex: 1, +}); - '@media': { - [queries.large]: { - position: 'absolute', - right: theme.spacing.small, - top: theme.spacing.small, - }, - }, +export const image = style({ + width: '100%', }); export const content = style({ @@ -120,6 +120,7 @@ export const content = style({ flexDirection: 'column', overflow: 'auto', padding: `${theme.spacing.large} ${theme.spacing.large}`, + textAlign: 'center', }); globalStyle(`${variant.condensed} ${content}`, { diff --git a/src/components/atoms/Modal/index.tsx b/src/components/atoms/Modal/index.tsx index 36e5e7b..5af009f 100644 --- a/src/components/atoms/Modal/index.tsx +++ b/src/components/atoms/Modal/index.tsx @@ -1,5 +1,6 @@ import type { Document } from '@contentful/rich-text-types'; import type { Asset } from 'contentful'; +import { useEffect, useRef } from 'react'; import { FaTimes } from 'react-icons/fa/index.js'; import { RichText } from '../RichText'; import * as styles from './Modal.css'; @@ -12,16 +13,37 @@ export interface ModalProps { } export const Modal = ({ description, image, onClose, title }: ModalProps) => { + const modalRef = useRef(null); + + useEffect(() => { + const handleClick = (e: any) => { + if ( + e.target === modalRef || + modalRef.current?.contains(e.target as Node) + ) { + return; + } + + onClose?.(); + }; + + document.addEventListener('pointerdown', handleClick); + + return () => { + document.removeEventListener('pointerdown', handleClick); + }; + }, [onClose]); + return ( -
+
+
-

{title}

diff --git a/src/components/organisms/Header/index.tsx b/src/components/organisms/Header/index.tsx index f4f7751..30a15d8 100644 --- a/src/components/organisms/Header/index.tsx +++ b/src/components/organisms/Header/index.tsx @@ -23,7 +23,7 @@ export const Header = (props: HeaderProps) => { return (
- + Life Itself