Skip to content

Commit

Permalink
make heading and paragraph as optional fields for MediaShowcase
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Dec 3, 2024
1 parent 16cffcd commit eb99ae5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 12 additions & 7 deletions apps/astro/src/components/global/MediaShowcase.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const MediaShowcase_Query = `
type Props = {
index: number
sectionId?: string
heading: PortableTextValue
paragraph: PortableTextValue
heading?: PortableTextValue
paragraph?: PortableTextValue
layout: '50/50' | '30/70' | '70/30'
media: Array<
| {
Expand Down Expand Up @@ -75,16 +75,21 @@ const { index, sectionId, heading, paragraph, layout, media } = Astro.props as P
</div>
)
}
<header>
<PortableText value={heading} heading={index === 0 ? 'h1' : 'h2'} class="heading" />
<PortableText value={paragraph} class="paragraph" />
</header>
{
heading && (
<header>
<PortableText value={heading} heading={index === 0 ? 'h1' : 'h2'} class="heading" />
{paragraph && <PortableText value={paragraph} class="paragraph" />}
</header>
)
}
</section>

<style lang="scss">
.MediaShowcase {
padding: clamp(2rem, calc(3vw / 0.48), 3rem) 0;
header {
margin-top: clamp(1.5rem, calc(2vw / 0.48), 2rem);
display: grid;
grid-template-columns: 1fr 1fr;
gap: clamp(1.5rem, calc(3vw / 0.48), 3rem) 1.5rem;
Expand All @@ -94,7 +99,7 @@ const { index, sectionId, heading, paragraph, layout, media } = Astro.props as P
}
}
.media-wrapper {
margin: 0 calc(var(--page-margin) * -1) clamp(1.5rem, calc(2vw / 0.48), 2rem);
margin: 0 calc(var(--page-margin) * -1);
display: grid;
.media {
height: 100%;
Expand Down
10 changes: 7 additions & 3 deletions apps/sanity/schema/components/MediaShowcase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ export default defineField({
defineField({
name: 'heading',
type: 'Heading',
title: 'Heading',
validation: Rule => Rule.required(),
title: 'Heading (optional)',
}),
defineField({
name: 'paragraph',
type: 'PortableText',
title: 'Paragraph',
validation: Rule => Rule.required(),
hidden: ({ parent }) => !parent?.heading,
validation: Rule => Rule.custom((value, context) => {
const isHeading = !!(context.parent as { heading: string }).heading
if (isHeading && !value) return 'Paragraph is required'
return true
})
}),
defineField({
name: 'layout',
Expand Down

0 comments on commit eb99ae5

Please sign in to comment.