Skip to content

Commit

Permalink
feat(homepage): add preview for announcements component (#1496)
Browse files Browse the repository at this point in the history
* feat(announcements): add SCSS styles from template

* feat(announcements): add frontmatter types

* feat(announcements): introduce preview component

* chore: sync padding and margin helpers

* chore: sync template changes to CMS preview
  • Loading branch information
dcshzj authored Sep 20, 2023
1 parent 0d951b0 commit dcf9e97
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 47 deletions.
14 changes: 14 additions & 0 deletions src/layouts/EditHomepage/HomepagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useParams } from "react-router-dom"

import editorStyles from "styles/isomer-cms/pages/Editor.module.scss"

import { TemplateAnnouncementsSection } from "templates/homepage/AnnouncementsSection"
import TemplateHeroSection from "templates/homepage/HeroSection"
import TemplateInfobarSection from "templates/homepage/InfobarSection"
import TemplateInfopicLeftSection from "templates/homepage/InfopicLeftSection"
Expand Down Expand Up @@ -166,6 +167,19 @@ export const HomepagePreview = ({
)}
</>
)}
{/* Announcements section */}
{EditorHomepageFrontmatterSection.isAnnouncements(section) && (
<>
<TemplateAnnouncementsSection
key={`section-${sectionIndex}`}
title={section.announcements.title}
subtitle={section.announcements.subtitle}
announcementItems={section.announcements.announcement_items}
sectionIndex={sectionIndex}
ref={scrollRefs[sectionIndex] as Ref<HTMLDivElement>}
/>
</>
)}
</>
))}
</div>
Expand Down
95 changes: 60 additions & 35 deletions src/styles/isomer-template/helpers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

$spaceamounts: (
"auto",
0,
1,
2,
Expand Down Expand Up @@ -39,46 +40,70 @@ $spaceamounts: (
80,
96
);
$sides: (top, bottom, left, right);

@each $space in $spaceamounts {
$remSpace: calc(#{$space}rem / 4);

@each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$space} {
margin-#{$side}: $remSpace;
}

.p#{str-slice($side, 0, 1)}-#{$space} {
padding-#{$side}: $remSpace;
}
}
$sides: (
"t": "top",
"b": "bottom",
"l": "left",
"r": "right",
"x": (
"left",
"right",
),
"y": (
"top",
"bottom",
),
"": (
"top",
"bottom",
"left",
"right",
),
);

.mx-#{$space} {
margin-left: $remSpace;
margin-right: $remSpace;
}
@each $breakpoint, $minwidth in $breakpoints {
@if $minwidth != 0px {
@media (min-width: $minwidth) {
@each $space in $spaceamounts {
$remSpace: if($space == "auto", auto, calc(#{$space}rem / 4));

.px-#{$space} {
padding-left: $remSpace;
padding-right: $remSpace;
}
@each $prefix, $positions in $sides {
$suffix: #{$prefix};
@if $minwidth != 0px {
$suffix: #{$prefix}-#{$breakpoint};
}

.my-#{$space} {
margin-top: $remSpace;
margin-bottom: $remSpace;
}
.m#{$suffix}-#{$space} {
@each $position in $positions {
margin-#{$position}: $remSpace !important;
}
}

.py-#{$space} {
padding-top: $remSpace;
padding-bottom: $remSpace;
}
.p#{$suffix}-#{$space} {
@each $position in $positions {
padding-#{$position}: $remSpace !important;
}
}
}
}
}
} @else {
@each $space in $spaceamounts {
$remSpace: if($space == "auto", auto, calc(#{$space}rem / 4));

.m-#{$space} {
margin: $remSpace;
}
@each $prefix, $positions in $sides {
.m#{$prefix}-#{$space} {
@each $position in $positions {
margin-#{$position}: $remSpace !important;
}
}

.p-#{$space} {
padding: $remSpace;
.p#{$prefix}-#{$space} {
@each $position in $positions {
padding-#{$position}: $remSpace !important;
}
}
}
}
}
}
35 changes: 35 additions & 0 deletions src/styles/isomer-template/homepage/announcements.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.announcements-divider {
height: 1px;
color: #f9f9f9;
}

.announcements-announcement-title {
font-size: 1.625rem;
font-weight: 700;
line-height: 2rem;
}

.announcements-announcement-subtitle {
font-size: 1rem;
font-weight: 400;
line-height: 1.375rem;
}

.announcements-announcement-link {
color: var(--site-secondary-color);
font-size: 1.125rem;
font-weight: 600;
line-height: 1.5rem;
letter-spacing: 0.27px;
text-decoration-line: underline;
text-transform: capitalize;
text-underline-offset: 0.25rem;
}

.announcements-announcement-link:hover {
color: var(--site-secondary-color-hover);
}

a[target="_blank"].announcements-announcement-link::after {
content: unset;
}
14 changes: 12 additions & 2 deletions src/styles/isomer-template/styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
@charset 'UTF-8';
// Minimum width before a media query is triggered
$breakpoints: (
"": 0px,
sm: 431px,
md: 770px,
lg: 1024px,
xl: 1280px,
xxl: 1408px,
);

@use "helpers";
@import "helpers";

@import "homepage/announcements";
168 changes: 168 additions & 0 deletions src/templates/homepage/AnnouncementsSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { forwardRef } from "react"

import editorStyles from "styles/isomer-cms/pages/Editor.module.scss"

import { getClassNames } from "templates/utils/stylingUtils"

import { AnnouncementsSection } from "types/homepage"

type TemplateAnnouncementsSectionProps = Omit<
AnnouncementsSection,
"announcement_items"
> & {
announcementItems: AnnouncementsSection["announcement_items"]
sectionIndex: number
}

export const TemplateAnnouncementsSection = forwardRef<
HTMLDivElement,
TemplateAnnouncementsSectionProps
>(
(
{
title,
subtitle,
announcementItems,
sectionIndex,
}: TemplateAnnouncementsSectionProps,
ref
) => {
return (
<div ref={ref}>
<section
className={getClassNames(editorStyles, [
`bp-section`,
sectionIndex % 2 === 1 ? "bg-newssection" : "",
"px-14",
"px-md-24",
"py-24",
])}
>
<div
className={getClassNames(editorStyles, [
"bp-container",
"is-fluid",
"m-0",
])}
>
<div className={editorStyles.row}>
<div className={getClassNames(editorStyles, ["col", "is-full"])}>
<>
{subtitle && (
<p
className={getClassNames(editorStyles, [
"eyebrow",
"is-uppercase",
"pb-4",
"has-text-centered",
])}
>
{subtitle}
</p>
)}
{title && (
<h1
className={getClassNames(editorStyles, [
"has-text-secondary",
"pb-4",
"has-text-centered",
])}
>
<b>{title}</b>
</h1>
)}

<hr
className={getClassNames(editorStyles, [
"my-8",
"announcements-divider",
])}
/>

{announcementItems &&
announcementItems.map((announcement, index) => {
return (
<>
<div
className={getClassNames(editorStyles, [
"row",
"is-desktop",
])}
>
<div
className={getClassNames(editorStyles, [
"col",
"is-4-desktop",
"px-lg-6",
"mr-lg-6",
])}
>
<h3
className={getClassNames(editorStyles, [
"announcements-announcement-title",
"mb-4",
])}
>
<b>{announcement.title}</b>
</h3>
<p
className={
editorStyles[
"announcements-announcement-subtitle"
]
}
>
{announcement.date}
</p>
</div>
<div
className={getClassNames(editorStyles, [
"col",
"px-lg-6",
])}
>
<p>{announcement.announcement}</p>
{announcement.link_text && announcement.link_url && (
<div className={editorStyles["mt-4"]}>
<div
className={
editorStyles[
"announcements-announcement-link"
]
}
>
<span>{announcement.link_text}</span>
</div>
</div>
)}
</div>
</div>
{announcementItems &&
announcementItems.length === index + 1 ? (
<hr
className={getClassNames(editorStyles, [
"mt-8",
"mb-0",
"announcements-divider",
])}
/>
) : (
<hr
className={getClassNames(editorStyles, [
"my-8",
"announcements-divider",
])}
/>
)}
</>
)
})}
</>
</div>
</div>
</div>
</section>
</div>
)
}
)
Loading

0 comments on commit dcf9e97

Please sign in to comment.