-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds split image component and add it to Employee site (#926)
* feat: adds image split module * fix: adds style to split image * feat: support left and right image placement * lint * feat: adds option to have several links * fix: changes title and description to translateable string
- Loading branch information
Showing
9 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { SanityImage } from "src/components/image/SanityImage"; | ||
import LinkButton from "src/components/linkButton/LinkButton"; | ||
import Text from "src/components/text/Text"; | ||
import { ImageSplitSection } from "studio/lib/interfaces/pages"; | ||
import { ImageAlignment } from "studio/schemas/fields/media"; | ||
|
||
import styles from "./image-split.module.css"; | ||
|
||
interface ImageSplitProps { | ||
section: ImageSplitSection; | ||
} | ||
|
||
const ImageSplitComponent = ({ section }: ImageSplitProps) => { | ||
const hasImage = section.imageExtended; | ||
const alignment = section.imageExtended?.imageAlignment; | ||
const showImageToLeft = hasImage && alignment == ImageAlignment.Left; | ||
const showImageToRight = hasImage && alignment == ImageAlignment.Right; | ||
|
||
return ( | ||
<article className={styles.imageSplit}> | ||
{showImageToLeft && ( | ||
<div className={styles.image}> | ||
<SanityImage image={section.imageExtended} /> | ||
</div> | ||
)} | ||
|
||
<div className={styles.textContainer}> | ||
<Text type="h4" as="h2"> | ||
{section.basicTitle} | ||
</Text> | ||
|
||
{section.description && ( | ||
<Text type="bodyNormal">{section.description}</Text> | ||
)} | ||
|
||
{section.actions.length > 0 && ( | ||
<div className={styles.textContainer__link}> | ||
{section.actions.map((action, index) => ( | ||
<LinkButton | ||
key={action._key} | ||
type={index === 0 ? "primary" : "secondary"} | ||
isSmall | ||
link={action} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
|
||
{showImageToRight && ( | ||
<div className={styles.image}> | ||
<SanityImage image={section.imageExtended} /> | ||
</div> | ||
)} | ||
</article> | ||
); | ||
}; | ||
|
||
export default ImageSplitComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
import { useQuery } from "@sanity/react-loader"; | ||
import { Suspense } from "react"; | ||
|
||
import { PreviewProps } from "src/types/preview"; | ||
import { ImageSplitSection, PageBuilder } from "studio/lib/interfaces/pages"; | ||
import { PAGE_QUERY } from "studio/lib/queries/pages"; | ||
|
||
import ImageSplit from "./ImageSplit"; | ||
|
||
export default function ImageSplitComponentPreview({ | ||
sectionIndex, | ||
initialData, | ||
}: PreviewProps) { | ||
const { data: newData } = useQuery<PageBuilder | null>( | ||
PAGE_QUERY, | ||
{ id: initialData.data._id, language: initialData.data.language }, | ||
{ initial: initialData }, | ||
); | ||
|
||
const imageSplitSection = newData | ||
? (newData.sections.find( | ||
(section, index) => | ||
section._type === "imageSplitSection" && index === sectionIndex, | ||
) as ImageSplitSection) | ||
: (initialData.data.sections.find( | ||
(section, index) => | ||
section._type === "imageSplitSection" && index === sectionIndex, | ||
) as ImageSplitSection); | ||
|
||
return ( | ||
<Suspense> | ||
<ImageSplit section={imageSplitSection} /> | ||
</Suspense> | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/components/sections/image-split/image-split.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.imageSplit { | ||
max-width: var(--max-content-width-small); | ||
|
||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | ||
|
||
gap: 3rem; | ||
row-gap: 5.25rem; | ||
padding: 1rem; | ||
margin: 3.75rem auto; | ||
|
||
box-sizing: content-box; | ||
align-items: center; | ||
} | ||
|
||
.textContainer { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
} | ||
|
||
.textContainer__link { | ||
margin-top: 1.5rem; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 0.5rem; | ||
} | ||
|
||
.image { | ||
display: flex; | ||
justify-content: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { defineField } from "sanity"; | ||
|
||
import { imageExtended } from "studio/schemas/fields/media"; | ||
import { titleID } from "studio/schemas/fields/text"; | ||
import { link } from "studio/schemas/objects/link"; | ||
import { firstTranslation } from "studio/utils/i18n"; | ||
|
||
export const imageID = "imageSplitSection"; | ||
|
||
export const imageSplitSection = defineField({ | ||
name: imageID, | ||
title: "Image Split", | ||
type: "object", | ||
fields: [ | ||
{ | ||
name: titleID.basic, | ||
type: "internationalizedArrayString", | ||
title: "Title", | ||
description: | ||
"Enter the primary title that will be displayed at the top of the employees section.", | ||
}, | ||
|
||
{ | ||
name: "description", | ||
type: "internationalizedArrayString", | ||
title: "Main content", | ||
description: | ||
"Enter the main content that will be displayed below the title.", | ||
}, | ||
|
||
imageExtended, | ||
{ | ||
name: "actions", | ||
title: "Actions (links)", | ||
type: "array", | ||
of: [link], | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
title: "basicTitle", | ||
}, | ||
prepare(selection) { | ||
const { title } = selection; | ||
return { | ||
title: firstTranslation(title) ?? undefined, | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
export default imageSplitSection; |