-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bose/2254' into staging
- Loading branch information
Showing
36 changed files
with
1,521 additions
and
23 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
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,130 @@ | ||
/* eslint-disable react/display-name */ | ||
import blocksToText from '../../../helpers/blocksToText' | ||
import { configureBlockContent } from '../../editors' | ||
import { validateCharCounterEditor } from '../../validations/validateCharCounterEditor' | ||
|
||
import type { Image, PortableTextBlock, Reference, Rule, ValidationContext } from 'sanity' | ||
import type { ColorSelectorValue } from '../../components/ColorSelector' | ||
|
||
const blockConfigTitle = { | ||
h2: false, | ||
h3: false, | ||
h4: false, | ||
internalLink: false, | ||
externalLink: false, | ||
attachment: false, | ||
lists: false, | ||
smallText: true, | ||
largeText: true, | ||
extraLargeText: true, | ||
} | ||
const blockConfigContent = { | ||
h2: false, | ||
h3: false, | ||
h4: false, | ||
internalLink: false, | ||
externalLink: false, | ||
attachment: false, | ||
lists: false, | ||
smallText: true, | ||
} | ||
|
||
const blockTitleType = configureBlockContent({ ...blockConfigTitle }) | ||
const blockContentType = configureBlockContent({ ...blockConfigContent }) | ||
|
||
export type CampaignBanner = { | ||
_type: 'campaignBanner' | ||
overline?: string | ||
title?: PortableTextBlock[] | ||
text?: PortableTextBlock[] | ||
image: Image | ||
imagePosition?: string | ||
imageSize?: string | ||
background?: ColorSelectorValue | ||
} | ||
|
||
export default { | ||
name: 'campaignBanner', | ||
title: 'Campaign Banner', | ||
type: 'object', | ||
localize: true, | ||
fieldsets: [ | ||
{ | ||
title: 'Background image', | ||
name: 'backgroundImage', | ||
description: 'Settings for the background image', | ||
options: { | ||
collapsible: true, | ||
collapsed: true, | ||
}, | ||
}, | ||
], | ||
fields: [ | ||
{ | ||
name: 'title', | ||
title: 'Title content', | ||
type: 'array', | ||
of: [blockTitleType], | ||
validation: (Rule: Rule) => | ||
Rule.custom((value: PortableTextBlock[], ctx: ValidationContext) => { | ||
return validateCharCounterEditor(value, 600) | ||
}).warning(), | ||
}, | ||
{ | ||
name: 'text', | ||
title: 'Text content', | ||
type: 'array', | ||
of: [blockContentType], | ||
validation: (Rule: Rule) => | ||
Rule.custom((value: PortableTextBlock[], ctx: ValidationContext) => { | ||
return validateCharCounterEditor(value, 600) | ||
}).warning(), | ||
}, | ||
{ | ||
title: 'Image', | ||
name: 'backgroundImage', | ||
type: 'image', | ||
options: { | ||
hotspot: true, | ||
collapsed: false, | ||
}, | ||
fieldset: 'backgroundImage', | ||
}, | ||
{ | ||
name: 'attribution', | ||
title: 'Credit', | ||
description: '', | ||
type: 'string', | ||
}, | ||
{ | ||
title: 'Apply light gradient', | ||
name: 'useLightOverlay', | ||
type: 'boolean', | ||
description: 'Applies a white gradient over semi transparent background image.', | ||
fieldset: 'backgroundImage', | ||
}, | ||
{ | ||
title: 'Background Color', | ||
description: 'Fallback if no background image. Default is white.', | ||
name: 'backgroundColor', | ||
type: 'colorlist', | ||
fieldset: 'backgroundImage', | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
title: 'title', | ||
text: 'text', | ||
image: 'backgroundImage.asset', | ||
}, | ||
prepare({ title, text, image }: { title: PortableTextBlock[]; text: PortableTextBlock[]; image: Reference }) { | ||
const plainTitle = blocksToText(title || text) | ||
|
||
return { | ||
title: plainTitle || 'Missing title/content', | ||
subtitle: 'Campaign banner component', | ||
media: image, | ||
} | ||
}, | ||
}, | ||
} |
Oops, something went wrong.