-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add big text teaser component #1890 #1913
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b2a9a0
✨ Add big text teaser component #1890
fernandolucchesi 0656f5a
🎨 Improve logic structure #1890
fernandolucchesi b4a64a5
✨ Add big title for rich text and improve code #1890
fernandolucchesi 07b2a1e
✨ Adjust line height #1890
fernandolucchesi a7c4bdb
♻️ Index big title text #1890
fernandolucchesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
import { text_field } from '@equinor/eds-icons' | ||
import type { Reference, Rule } from 'sanity' | ||
import type { PortableTextBlock, Reference, Rule, SanityDocument, ValidationContext } from 'sanity' | ||
import type { ColorSelectorValue } from '../components/ColorSelector' | ||
import blocksToText from '../../helpers/blocksToText' | ||
import { EdsIcon } from '../../icons' | ||
import { SchemaType } from '../../types' | ||
import CompactBlockEditor from '../components/CompactBlockEditor' | ||
import { configureBlockContent, configureTitleBlockContent } from '../editors' | ||
import { validateComponentAnchor } from '../validations/validateAnchorReference' | ||
|
@@ -16,13 +15,29 @@ const blockContentType = configureBlockContent({ | |
h4: false, | ||
attachment: false, | ||
}) | ||
|
||
const ingressContentType = configureBlockContent({ | ||
h1: false, | ||
h2: false, | ||
h3: false, | ||
h4: false, | ||
attachment: false, | ||
}) | ||
|
||
const blockContentTypeForBigText = configureBlockContent({ | ||
h1: false, | ||
h2: false, | ||
h3: false, | ||
h4: false, | ||
attachment: false, | ||
smallText: false, | ||
normalTextOverride: { | ||
title: 'Normal', | ||
value: 'normal', | ||
component: ({ children }: { children: React.ReactNode }) => <span style={{ fontSize: '42px' }}>{children}</span>, | ||
}, | ||
}) | ||
|
||
const titleContentType = configureTitleBlockContent() | ||
|
||
type TextBlock = { | ||
|
@@ -31,12 +46,18 @@ type TextBlock = { | |
anchor?: string | ||
ingress?: string | ||
text?: string | ||
isBigText?: boolean | ||
bigText?: PortableTextBlock[] | ||
action?: Reference[] | ||
splitList?: boolean | ||
overrideButtonStyle?: boolean | ||
background?: ColorSelectorValue | ||
} | ||
|
||
type TextBlockDocument = { | ||
parent: TextBlock | ||
} | ||
|
||
export default { | ||
name: 'textBlock', | ||
title: 'Text block', | ||
|
@@ -50,6 +71,7 @@ export default { | |
collapsible: true, | ||
collapsed: true, | ||
}, | ||
hidden: ({ parent }: TextBlockDocument) => parent.isBigText, | ||
}, | ||
{ | ||
title: 'Eyebrow headline', | ||
|
@@ -59,6 +81,7 @@ export default { | |
collapsible: true, | ||
collapsed: true, | ||
}, | ||
hidden: ({ parent }: TextBlockDocument) => parent.isBigText, | ||
}, | ||
{ | ||
title: 'Call to action(s)', | ||
|
@@ -84,6 +107,11 @@ export default { | |
}, | ||
], | ||
fields: [ | ||
{ | ||
title: 'Big text', | ||
name: 'isBigText', | ||
type: 'boolean', | ||
}, | ||
{ | ||
name: 'image', | ||
type: 'imageWithAlt', | ||
|
@@ -105,7 +133,11 @@ export default { | |
input: CompactBlockEditor, | ||
}, | ||
of: [titleContentType], | ||
validation: (Rule: SchemaType.ValidationRule) => Rule.required().warning('A title is recommended'), | ||
validation: (Rule: Rule) => | ||
Rule.custom((value: PortableTextBlock[], ctx: ValidationContext) => | ||
!value && !(ctx.parent as TextBlock)?.isBigText ? 'A title is recommended' : true, | ||
).warning(), | ||
hidden: ({ parent }: TextBlockDocument) => parent.isBigText, | ||
}, | ||
{ | ||
name: 'anchor', | ||
|
@@ -124,6 +156,18 @@ export default { | |
title: 'Ingress', | ||
type: 'array', | ||
of: [ingressContentType], | ||
hidden: ({ parent }: TextBlockDocument) => parent.isBigText, | ||
}, | ||
{ | ||
name: 'bigTitle', | ||
title: 'Title', | ||
type: 'array', | ||
of: [blockContentTypeForBigText], | ||
hidden: ({ parent }: TextBlockDocument) => !parent.isBigText, | ||
validation: (Rule: Rule) => | ||
Rule.custom((value: PortableTextBlock[], ctx: ValidationContext) => | ||
!value && (ctx.parent as TextBlock)?.isBigText ? 'Title is required' : true, | ||
), | ||
}, | ||
{ | ||
name: 'text', | ||
|
@@ -176,27 +220,27 @@ export default { | |
title: 'title', | ||
ingress: 'ingress', | ||
text: 'text', | ||
}, | ||
prepare({ title = [], ingress, text }: { title: any[]; ingress: any; text: any }) { | ||
const textBlock = (text || []).find((introBlock: any) => introBlock._type === 'block') | ||
const ingressBlock = (ingress || []).find((introBlock: any) => introBlock._type === 'block') | ||
const plainTitle = title ? blocksToText(title) : undefined | ||
isBigText: 'isBigText', | ||
bigTitle: 'bigTitle', | ||
}, | ||
prepare({ | ||
title, | ||
isBigText, | ||
bigTitle, | ||
ingress, | ||
text, | ||
}: { | ||
title: PortableTextBlock[] | ||
ingress: PortableTextBlock[] | ||
isBigText: boolean | ||
bigTitle: PortableTextBlock[] | ||
text: PortableTextBlock[] | ||
}) { | ||
const plainTitle = isBigText ? blocksToText(bigTitle) : blocksToText(title || ingress || text) | ||
|
||
return { | ||
title: | ||
plainTitle || | ||
(textBlock && | ||
textBlock.children | ||
.filter((child: any) => child._type === 'span') | ||
.map((span: any) => span.text) | ||
.join('')) || | ||
(ingressBlock && | ||
ingressBlock.children | ||
.filter((child: any) => child._type === 'span') | ||
.map((span: any) => span.text) | ||
.join('')) || | ||
'Missing content!', | ||
subtitle: `Text block component.`, | ||
title: plainTitle || 'Missing title/content', | ||
subtitle: isBigText ? 'Text block component (BIG TEXT)' : 'Text block component', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨🧹✨ |
||
media: EdsIcon(text_field), | ||
} | ||
}, | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use the
Rule.custom((value: PortableTextBlock[]) => validateCharCounterEditor(value, 600)).warning()
andRule.custom((value: PortableTextBlock[]) => validateCharCounterEditor(value, 600))
for text and bigText.. seems like no difference to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one is a warning, the other is required