Skip to content
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

1889 As editors we see a need to have text promotion cards to link to other pages #1943

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bf67944
✨ WIP: text promo component #1889
millianapia Oct 20, 2023
b3d0ca5
✨ WIP: cleanup text promo component #1889
millianapia Nov 2, 2023
7d82fd7
✨ WIP: cleanup text promo component #1889
millianapia Nov 7, 2023
d5700ed
Revert "✨ WIP: cleanup text promo component #1889"
millianapia Nov 7, 2023
67ea374
✨ WIP: cleanup text promo component #1889
millianapia Nov 7, 2023
2f09be2
♻️ Extract action from contentfields #1889
millianapia Nov 7, 2023
32b83ca
♻️ Remove title, add link toggle #1889
millianapia Nov 8, 2023
1cd82c8
♻️ Removed one too many lines #1889
millianapia Nov 8, 2023
22acdf7
♻️ Add padding and bigger fontsize #1889
millianapia Nov 8, 2023
826c1dd
♻️ Change from text to ingress #1889
millianapia Nov 8, 2023
620e799
♻️ Add a better toggling of spacing and aligning #1889
millianapia Nov 13, 2023
b2f928f
🐛 Working links #1889
millianapia Nov 14, 2023
36a4c4e
🚚 Rename for tile #1889
millianapia Nov 14, 2023
173f3b3
♻️ Refactor promotilebuttonlogic #1889
millianapia Nov 14, 2023
5f46bac
♻️ Small refactor for double linkreferences #1889
millianapia Nov 15, 2023
1dadce0
♻️ Restructure code #1889
fernandolucchesi Nov 15, 2023
0486a21
♻️ Restructure code #1889
millianapia Nov 15, 2023
142d4c3
♻️ Refactor type and preview #1889
millianapia Nov 20, 2023
af315fc
🔥 Remove redundant css #1889
millianapia Nov 20, 2023
70ec668
🔥 Remove redundant css #1889
millianapia Nov 21, 2023
b69f9f7
🐛 Limit gridtemplate columns #1889
millianapia Dec 1, 2023
f663032
🔥 size adjustment, breakline added and remove char limit #1889
millianapia Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sanityv3/schemas/documents/magazine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default {
{ type: 'pullQuote', initialValue: { background: defaultColors[0] } },
{ type: 'accordion' },
{ type: 'promoTileArray' },
{ type: 'promoTextTileArray' },
{ type: 'promotion' },
{ type: 'iframe' },
{ type: 'imageCarousel' },
Expand Down
1 change: 1 addition & 0 deletions sanityv3/schemas/documents/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default {
{ type: 'pullQuote', initialValue: { background: defaultColors[0] } },
{ type: 'accordion' },
{ type: 'promoTileArray' },
{ type: 'promoTextTileArray' },
{ type: 'promotion' },
{ type: 'table' },
{ type: 'stockValuesApi' },
Expand Down
4 changes: 4 additions & 0 deletions sanityv3/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ import menuLink from './objects/menuLink'
import newsList from './objects/newsList'
import positionedInlineImage from './objects/positionedInlineImage'
import promoTile from './objects/promoTile'
import promoTextTile from './objects/promoTextTile'
import promoTileArray from './objects/promoTileArray'
import promoTextTileArray from './objects/promoTextTileArray'
import promoteEvents from './objects/promotion/promoteEvents'
import promoteMagazine from './objects/promotion/promoteMagazine'
import promoteNews from './objects/promotion/promoteNews'
Expand Down Expand Up @@ -131,7 +133,9 @@ const RemainingSchemas = [
textWithIconArray,
linkSelector,
promoTile,
promoTextTile,
promoTileArray,
promoTextTileArray,
stockValuesApi,
iframe,
basicIframe,
Expand Down
97 changes: 97 additions & 0 deletions sanityv3/schemas/objects/promoTextTile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { label } from '@equinor/eds-icons'
import type { PortableTextBlock, Rule, ValidationContext } from 'sanity'
import type { ColorSelectorValue } from '../components/ColorSelector'
import { EdsIcon } from '../../icons'
import { validateCharCounterEditor } from '../validations/validateCharCounterEditor'
import type { LinkSelector } from './linkSelector'
import { configureBlockContent } from '../editors'
import { getLinkSelectorFields } from './linkSelector'

const ingressBlockContentType = configureBlockContent({
h1: false,
h2: false,
h3: false,
h4: false,
internalLink: false,
externalLink: false,
attachment: false,
lists: false,
})

export type PromoTextTile = {
_type: 'promoTextTile'
linkLabelAsTitle?: boolean
millianapia marked this conversation as resolved.
Show resolved Hide resolved
link?: LinkSelector
isLink?: boolean
background?: ColorSelectorValue
}

export default {
title: 'Promo text tile',
name: 'promoTextTile',
type: 'object',
fieldsets: [
{
title: 'Design options',
name: 'design',
description: 'Some options for design',
options: {
collapsible: true,
collapsed: false,
},
},
{
name: 'link',
title: 'Link',
description: 'Select either an internal link or external URL.',
},
],
fields: [
{
name: 'ingress',
title: 'Promo Text',
description: 'Max 200 characters',
type: 'array',
of: [ingressBlockContentType],
validation: (Rule: Rule) => Rule.custom((value: any) => validateCharCounterEditor(value, 200)),
},
{
name: 'isLink',
type: 'boolean',
title: 'Use a link',
description: 'Link to another piece of content',
initialValue: false,
},
{
name: 'linkLabelAsTitle',
title: 'Toggle button text',
description: 'This will add the text to link',
type: 'boolean',
initialValue: false,
hidden: ({ parent }: { parent: PromoTextTile }) => !parent.isLink,
},
...getLinkSelectorFields(undefined, 'isLink'),

{
title: 'Background',
description: 'Pick a colour for the background. Default is white.',
name: 'background',
type: 'colorlist',
fieldset: 'design',
},
],
preview: {
select: {
title: 'title',
linkLabelAsTitle: 'linkLabelAsTitle',
millianapia marked this conversation as resolved.
Show resolved Hide resolved
link: 'link.label',
},
prepare({ linkLabelAsTitle, link }: { title: PortableTextBlock[]; linkLabelAsTitle: boolean; link: string }) {
return {
title: linkLabelAsTitle || link || 'Promo Text Tile',
millianapia marked this conversation as resolved.
Show resolved Hide resolved
subtitle: `Promo text tile component`,
media: EdsIcon(label),
}
},
},
}
43 changes: 43 additions & 0 deletions sanityv3/schemas/objects/promoTextTileArray.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { collection_2 } from '@equinor/eds-icons'
import { EdsIcon } from '../../icons'
import type { Rule } from 'sanity'
import type { PromoTextTile } from './promoTextTile'

export type PromoTextTileArray = {
_type: 'promoTextTileArray'
group: PromoTextTile[]
}

export default {
type: 'object',
name: 'promoTextTileArray',
title: 'Promo text tiles',
fields: [
{
name: 'spacing',
type: 'boolean',
title: 'Space between other components',
initialValue: false,
},
{
type: 'array',
name: 'group',
description: 'Add promo tiles as one or a pair',
title: 'Promo text tiles',
of: [{ type: 'promoTextTile' }],
validation: (Rule: Rule) => Rule.required().min(1).max(2),
},
].filter((e) => e),
millianapia marked this conversation as resolved.
Show resolved Hide resolved
preview: {
select: {
group: 'group',
},
prepare() {
return {
title: 'Promo tiles array',
subtitle: `Promo text tile array component`,
media: <div>{EdsIcon(collection_2)}</div>,
millianapia marked this conversation as resolved.
Show resolved Hide resolved
}
},
},
}
11 changes: 6 additions & 5 deletions sanityv3/schemas/objects/promoTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { EdsIcon } from '../../icons'
import CompactBlockEditor from '../components/CompactBlockEditor'
import type { ImageWithAlt } from './imageWithAlt'
import type { LinkSelector } from './linkSelector'
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { configureTitleBlockContent } from '../editors'

const titleContentType = configureTitleBlockContent()

export type PromoTile = {
_type: 'promoTile'
title: any[]
title: PortableTextBlock[]
linkLabelAsTitle?: boolean
image?: ImageWithAlt
link?: LinkSelector
Expand Down Expand Up @@ -50,7 +49,9 @@ export default {
{
name: 'title',
type: 'array',
inputComponent: CompactBlockEditor,
components: {
input: CompactBlockEditor,
},
of: [titleContentType],
title: 'Title',
hidden: ({ parent }: { parent: PromoTile }) => parent?.linkLabelAsTitle,
Expand Down Expand Up @@ -92,13 +93,13 @@ export default {
linkLabelAsTitle,
link,
}: {
title: any[]
title: PortableTextBlock[]
imageUrl: string
linkLabelAsTitle: boolean
link: string
}) {
return {
title: linkLabelAsTitle ? link : blocksToText(title as any[]),
title: linkLabelAsTitle ? link : blocksToText(title),
subtitle: `Promo tile component`,
media: imageUrl ? <img src={imageUrl} alt="" style={{ height: '100%' }} /> : EdsIcon(label),
}
Expand Down
19 changes: 19 additions & 0 deletions web/lib/queries/common/actions/promoLinkReferenceFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { linkReferenceFields } from '../actions/linkSelectorFields'

export const promoLinkReferenceFields = /* groq */ `
{
"label": link.label,
"ariaLabel": link.ariaLabel,
"anchorReference": link.anchorReference,
"link": select(
link.linkToOtherLanguage == true =>
link.referenceToOtherLanguage->${linkReferenceFields},
link.reference->${linkReferenceFields},
),
"href": link.url,
"type": select(
defined(link.url) => "externalUrl",
"internalUrl"
)
}
`
15 changes: 15 additions & 0 deletions web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { videoPlayerFields } from '../videoPlayerFields'
import downloadableFileFields from './actions/downloadableFileFields'
import downloadableImageFields from './actions/downloadableImageFields'
import linkSelectorFields, { linkReferenceFields } from './actions/linkSelectorFields'
import { promoLinkReferenceFields } from './actions/promoLinkReferenceFields'
import markDefs from './blockEditorMarks'
import { eventPromotionFields, futureEventsQuery, pastEventsQuery } from './eventPromotion'
import { imageCarouselFields } from './imageCarouselFields'
Expand Down Expand Up @@ -180,6 +181,20 @@ const pageContentFields = /* groq */ `
},
},
},
_type == "promoTextTileArray"=>{
millianapia marked this conversation as resolved.
Show resolved Hide resolved
"type": _type,
"id": _key,
spacing,
"group": group[]{
"id": _key,
ingress[]{..., ${markDefs}},
linkLabelAsTitle,
"action": ${promoLinkReferenceFields},
"designOptions": {
"background": coalesce(background.title, 'none'),
},
},
},
_type == "iframe" => {
"type": _type,
"id": _key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TextWithIconArray from '../../topicPages/TextWithIconArray'
import PageQuote from '../../topicPages/PageQuote'
import AccordionBlock from '../../topicPages/Accordion/AccordionBlock'
import PromoTileArray from '../../topicPages/PromoTileArray'
import PromoTextTileArray from '../../topicPages/PromoTextTileArray'
import IFrame from '../../topicPages/IFrame'
import Promotion from '../../topicPages/Promotion'
import Form from '../../topicPages/Form/Form'
Expand All @@ -33,6 +34,7 @@ import {
QuoteData,
AccordionData,
PromoTileArrayData,
PromoTextTileArrayData,
IFrameData,
PromotionData,
FormData,
Expand All @@ -58,6 +60,7 @@ type ComponentProps =
| QuoteData
| AccordionData
| PromoTileArrayData
| PromoTextTileArrayData
| IFrameData
| PromotionData
| FormData
Expand Down Expand Up @@ -97,6 +100,8 @@ export const PageContent = ({ data }: PageContentProps) => {
return <AccordionBlock key={c.id} data={c as AccordionData} anchor={anchorReference} />
case 'promoTileArray':
return <PromoTileArray key={c.id} data={c as PromoTileArrayData} anchor={anchorReference} />
case 'promoTextTileArray':
return <PromoTextTileArray key={c.id} data={c as PromoTextTileArrayData} anchor={anchorReference} />
case 'iframe':
return <IFrame key={c.id} data={c as IFrameData} anchor={anchorReference} />
case 'promotion':
Expand Down
Loading