Skip to content

Commit

Permalink
✨ Add big title option to 50-50 banner #1887
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Oct 25, 2023
1 parent f1088cf commit 081d921
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
45 changes: 40 additions & 5 deletions sanityv3/schemas/documents/header/sharedHeaderFields.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Rule, ValidationContext } from 'sanity'
import { PortableTextBlock, Rule, ValidationContext } from 'sanity'
import CompactBlockEditor from '../../components/CompactBlockEditor'
import { configureBlockContent, configureTitleBlockContent } from '../../editors'
import { HeroTypes } from '../../HeroTypes'

type DocumentType = { parent: { heroType?: string } }
type DocumentType = { parent: Hero }
type Hero = {
heroType?: string
isBigTitle?: boolean
}

const titleContentType = configureTitleBlockContent()
const ingressContentType = configureBlockContent({
Expand All @@ -14,6 +18,29 @@ const ingressContentType = configureBlockContent({
attachment: false,
})

const isBigTitle = {
title: 'Big title',
name: 'isBigTitle',
type: 'boolean',
fieldset: 'header',
hidden: ({ parent }: DocumentType) => {
return parent?.heroType !== HeroTypes.FIFTY_FIFTY
},
}

const heroBigTitle = {
name: 'heroBigTitle',
title: 'Big Title',
type: 'array',
fieldset: 'header',
of: [titleContentType],

This comment has been minimized.

Copy link
@fernandolucchesi

fernandolucchesi Oct 26, 2023

Contributor

nice to make this visually big for editors, title could also be 'Title' instead of 'Big TItle':

image

vs

image

This comment has been minimized.

Copy link
@padms

padms Oct 26, 2023

Author Contributor

The banners also have title, which is shown below the 50-50 banner. So we need to differentiate the title.

hidden: ({ parent }: DocumentType) => !parent.isBigTitle,
validation: (Rule: Rule) =>
Rule.custom((value: PortableTextBlock[], ctx: ValidationContext) =>
!value && (ctx.parent as Hero)?.isBigTitle ? 'Title is required' : true,
),
}

const title = {
name: 'title',
type: 'array',
Expand Down Expand Up @@ -76,7 +103,9 @@ const heroTitle = {
of: [titleContentType],
fieldset: 'header',
hidden: ({ parent }: DocumentType) => {
return parent?.heroType !== HeroTypes.FIFTY_FIFTY
return (
parent?.heroType !== HeroTypes.FIFTY_FIFTY || (parent?.heroType === HeroTypes.FIFTY_FIFTY && parent.isBigTitle)
)
},
validation: (Rule: Rule) =>
Rule.custom((value: string, context: ValidationContext) => {
Expand All @@ -92,7 +121,9 @@ const heroIngress = {
type: 'array',
of: [ingressContentType],
hidden: ({ parent }: DocumentType) => {
return parent?.heroType !== HeroTypes.FIFTY_FIFTY
return (
parent?.heroType !== HeroTypes.FIFTY_FIFTY || (parent?.heroType === HeroTypes.FIFTY_FIFTY && parent.isBigTitle)
)
},
fieldset: 'header',
}
Expand All @@ -104,7 +135,9 @@ const heroLink = {
type: 'array',
of: [{ type: 'linkSelector', title: 'Link' }],
hidden: ({ parent }: DocumentType) => {
return parent?.heroType !== HeroTypes.FIFTY_FIFTY
return (
parent?.heroType !== HeroTypes.FIFTY_FIFTY || (parent?.heroType === HeroTypes.FIFTY_FIFTY && parent.isBigTitle)
)
},
fieldset: 'header',
validation: (Rule: Rule) => Rule.max(1).error('Only one action is permitted'),
Expand Down Expand Up @@ -179,10 +212,12 @@ const heroLoopingVideoRatio = {
}

export default [
isBigTitle,
title,
heroType,
heroRatio,
heroTitle,
heroBigTitle,
heroIngress,
heroLink,
background,
Expand Down
2 changes: 1 addition & 1 deletion web/components/src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const fontWeights = {
md: 'var(--fontWeight-regular)',
lg: 'var(--fontWeight-regular)',
xl: 'var(--fontWeight-regular)',
'2xl': 'var(--fontWeidht-regular)',
'2xl': 'var(--fontWeight-regular)',
'3xl': 'var(--fontWeight-regular)',
}

Expand Down
3 changes: 2 additions & 1 deletion web/lib/queries/common/heroFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import linkSelectorFields from './actions/linkSelectorFields'
export const heroFields = /* groq */ `{
"type": coalesce(heroType, 'default'),
"ratio": heroRatio,
"title": heroTitle,
"isBigTitle":isBigTitle,
"title": select(isBigTitle => heroBigTitle , heroTitle),
"ingress": heroIngress,
"background": coalesce(heroBackground.title, 'White'),
"figure": select(
Expand Down
1 change: 1 addition & 0 deletions web/pageComponents/pageTemplates/shared/SharedBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const SharedBanner = ({ title, hero, hideImageCaption, captionBg }: Banne
link={hero.link}
ingress={hero.ingress}
background={hero.background}
isBigTitle={hero.isBigTitle}
/>
)
case HeroTypes.LOOPING_VIDEO:
Expand Down
9 changes: 5 additions & 4 deletions web/pageComponents/shared/Hero/FiftyFiftyHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const HeroActionLink = ({ action, ...rest }: { action: LinkData }) => {
)
}

export const FiftyFiftyHero = ({ title, ingress, link, background, figure }: HeroType) => {
export const FiftyFiftyHero = ({ title, ingress, link, background, figure, isBigTitle }: HeroType) => {
return (
<>
<StyledHero background={background}>
Expand All @@ -97,8 +97,9 @@ export const FiftyFiftyHero = ({ title, ingress, link, background, figure }: Her
)}
</StyledMedia>
<StyledContent>
{title && <StyledHeroTitle value={title} level="h1" size="xl" />}
{ingress && (
{isBigTitle}

This comment has been minimized.

Copy link
@fernandolucchesi

fernandolucchesi Oct 26, 2023

Contributor

this line?

{title && <StyledHeroTitle value={title} level="h1" size={isBigTitle ? '2xl' : 'xl'} />}

This comment has been minimized.

Copy link
@fernandolucchesi

fernandolucchesi Oct 26, 2023

Contributor

looks like the big title is always bold by default.

This comment has been minimized.

Copy link
@padms

padms Oct 26, 2023

Author Contributor

This has regular font weight, when bold is selected font weight bold is applied. The difference could be seen.

This comment has been minimized.

Copy link
@fernandolucchesi

fernandolucchesi Oct 26, 2023

Contributor

StyledHeroTitle is applying medium

{ingress && !isBigTitle && (
<StyledIngress>
<IngressText
value={ingress}
Expand All @@ -114,7 +115,7 @@ export const FiftyFiftyHero = ({ title, ingress, link, background, figure }: Her
/>
</StyledIngress>
)}
{link && <HeroActionLink action={link} />}
{link && !isBigTitle && <HeroActionLink action={link} />}
</StyledContent>
</StyledHero>
</>
Expand Down
1 change: 1 addition & 0 deletions web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export enum HeroTypes {

export type HeroType = {
figure?: ImageWithCaptionData
isBigTitle?: boolean
title?: PortableTextBlock[]
ingress?: PortableTextBlock[]
link?: LinkData
Expand Down

0 comments on commit 081d921

Please sign in to comment.