Skip to content

Commit

Permalink
Updates modal styling.
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyleelarson committed Jul 12, 2023
1 parent a79bd9f commit 701021c
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 20 deletions.
19 changes: 10 additions & 9 deletions src/components/atoms/Modal/Modal.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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%',
Expand Down Expand Up @@ -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]: {
Expand Down Expand Up @@ -105,21 +109,18 @@ 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({
display: 'flex',
flexDirection: 'column',
overflow: 'auto',
padding: `${theme.spacing.large} ${theme.spacing.large}`,
textAlign: 'center',
});

globalStyle(`${variant.condensed} ${content}`, {
Expand Down
26 changes: 24 additions & 2 deletions src/components/atoms/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,16 +13,37 @@ export interface ModalProps {
}

export const Modal = ({ description, image, onClose, title }: ModalProps) => {
const modalRef = useRef<HTMLDivElement>(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 (
<dialog className={styles.wrapper} open>
<div className={styles.dialog}>
<div className={styles.dialog} ref={modalRef}>
<header className={styles.header}>
<button className={styles.close} onClick={onClose} type="button">
<FaTimes />
</button>
</header>
<img alt="" className={styles.image} src={image.fields.file.url} />
<div className={styles.content}>
<img alt="" src={image.fields.file.url} />
<h2>{title}</h2>
<RichText field={description} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Header = (props: HeaderProps) => {

return (
<header className={styles.header}>
<a className={styles.logo} onClick={handleLinkClick} href="#">
<a className={styles.logo} onClick={handleLinkClick} href="/">
<span>Life Itself</span>
</a>
<button
Expand Down
10 changes: 10 additions & 0 deletions src/components/organisms/HeroSection/HeroSection.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const grid = style({
});

export const content = style({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.small,
order: 3,
marginBottom: theme.spacing.medium,

Expand All @@ -59,6 +62,13 @@ export const content = style({
},
});

export const announcement = style({
color: theme.colors.red,
cursor: 'pointer',
fontSize: theme.fontSizes.small,
fontWeight: 'bold',
});

export const image = style({
marginInline: 'auto',
maxWidth: 536,
Expand Down
7 changes: 5 additions & 2 deletions src/components/organisms/HeroSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export const HeroSection = (props: HeroSectionProps) => {
<div className={styles.content}>
{props.event.fields.announcementModal && (
<>
<p onClick={() => setIsAnnouncementModalOpen(true)}>
<strong
className={styles.announcement}
onClick={() => setIsAnnouncementModalOpen(true)}
>
{props.event.fields.announcementModal.fields.title}
</p>
</strong>
{isAnnouncementModalOpen && (
<Modal
onClose={() => setIsAnnouncementModalOpen(false)}
Expand Down
7 changes: 4 additions & 3 deletions src/components/organisms/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const Layout = (props: LayoutProps) => {
<Header event={event} />
<main>
<HeroSection event={event} />
<SpeakersSection event={props.event} />
<LocationSection event={event} />
<PartnersSection event={event} />
<SpeakersSection event={props.event} isPastEvent={props.isPastEvent} />
<LocationSection event={event} isPastEvent={props.isPastEvent} />
<PartnersSection event={event} isPastEvent={props.isPastEvent} />
<AboutUsSection event={event} />
</main>
<Footer event={event} />
Expand All @@ -50,4 +50,5 @@ export const Layout = (props: LayoutProps) => {

export interface LayoutProps {
event: Entry<Event>;
isPastEvent?: boolean;
}
5 changes: 4 additions & 1 deletion src/components/organisms/LocationSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const LocationSection = (props: LocationSectionProps) => {
className={styles.container}
contentClassName={styles.content}
id="location"
title="Location"
title={
props.isPastEvent ? `${props.event.fields.year} Location` : 'Location'
}
>
<header className={styles.header}>
{props.event.fields.hotel.fields.video && (
Expand Down Expand Up @@ -106,4 +108,5 @@ export const LocationSection = (props: LocationSectionProps) => {

export interface LocationSectionProps {
event: Entry<Event>;
isPastEvent?: boolean;
}
5 changes: 4 additions & 1 deletion src/components/organisms/PartnersSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const PartnersSection = (props: PartnersSectionProps) => (
<ContentSection
contentClassName={styles.container}
id="partners"
title="Partners"
title={
props.isPastEvent ? `${props.event.fields.year} Partners` : 'Partners'
}
size="medium"
>
<ul className={styles.list}>
Expand Down Expand Up @@ -45,4 +47,5 @@ export const PartnersSection = (props: PartnersSectionProps) => (

export interface PartnersSectionProps {
event: Entry<Event>;
isPastEvent?: boolean;
}
2 changes: 1 addition & 1 deletion src/pages/[year].astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const event = await getEvent({ isPreview: false, year: year as string });
---

<Document>
<Layout client:load event={event} />
<Layout client:load event={event} isPastEvent />
</Document>

0 comments on commit 701021c

Please sign in to comment.