From bf6794450d104da4f3163027bac124f1b4f5da36 Mon Sep 17 00:00:00 2001 From: Malin J Date: Fri, 20 Oct 2023 11:48:52 +0200 Subject: [PATCH 01/22] =?UTF-8?q?=E2=9C=A8=20WIP:=20text=20promo=20compone?= =?UTF-8?q?nt=20#1889?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanityv3/schemas/documents/magazine.ts | 1 + sanityv3/schemas/documents/page.ts | 1 + sanityv3/schemas/index.js | 4 + sanityv3/schemas/objects/promoTextTile.tsx | 107 ++++++++++++++++ .../schemas/objects/promoTextTileArray.tsx | 52 ++++++++ web/lib/queries/common/pageContentFields.ts | 30 +++++ .../shared/SharedPageContent.tsx | 5 + .../topicPages/PromoTextTileArray.tsx | 115 ++++++++++++++++++ .../topicPages/PromoTileArray.tsx | 2 +- .../topicPages/PromoTileButton.tsx | 17 ++- web/types/types.ts | 17 +++ 11 files changed, 348 insertions(+), 3 deletions(-) create mode 100644 sanityv3/schemas/objects/promoTextTile.tsx create mode 100644 sanityv3/schemas/objects/promoTextTileArray.tsx create mode 100644 web/pageComponents/topicPages/PromoTextTileArray.tsx diff --git a/sanityv3/schemas/documents/magazine.ts b/sanityv3/schemas/documents/magazine.ts index 9f8b825fc..4f8a5251a 100644 --- a/sanityv3/schemas/documents/magazine.ts +++ b/sanityv3/schemas/documents/magazine.ts @@ -157,6 +157,7 @@ export default { { type: 'pullQuote', initialValue: { background: defaultColors[0] } }, { type: 'accordion' }, { type: 'promoTileArray' }, + { type: 'promoTextTileArray' }, { type: 'promotion' }, { type: 'iframe' }, { type: 'imageCarousel' }, diff --git a/sanityv3/schemas/documents/page.ts b/sanityv3/schemas/documents/page.ts index 799f4df1c..2788c6100 100644 --- a/sanityv3/schemas/documents/page.ts +++ b/sanityv3/schemas/documents/page.ts @@ -59,6 +59,7 @@ export default { { type: 'pullQuote', initialValue: { background: defaultColors[0] } }, { type: 'accordion' }, { type: 'promoTileArray' }, + { type: 'promoTextTileArray' }, { type: 'promotion' }, { type: 'table' }, { type: 'stockValuesApi' }, diff --git a/sanityv3/schemas/index.js b/sanityv3/schemas/index.js index dfb745a4c..150791e4a 100644 --- a/sanityv3/schemas/index.js +++ b/sanityv3/schemas/index.js @@ -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' @@ -131,7 +133,9 @@ const RemainingSchemas = [ textWithIconArray, linkSelector, promoTile, + promoTextTile, promoTileArray, + promoTextTileArray, stockValuesApi, iframe, basicIframe, diff --git a/sanityv3/schemas/objects/promoTextTile.tsx b/sanityv3/schemas/objects/promoTextTile.tsx new file mode 100644 index 000000000..c35a7c3c9 --- /dev/null +++ b/sanityv3/schemas/objects/promoTextTile.tsx @@ -0,0 +1,107 @@ +import { label } from '@equinor/eds-icons' +import type { PortableTextBlock, Rule, ValidationContext } from 'sanity' +import type { ColorSelectorValue } from '../components/ColorSelector' +import blocksToText from '../../helpers/blocksToText' +import { EdsIcon } from '../../icons' +import CompactBlockEditor from '../components/CompactBlockEditor' +import { validateCharCounterEditor } from '../validations/validateCharCounterEditor' +import type { LinkSelector } from './linkSelector' +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { configureTitleBlockContent, configureBlockContent } from '../editors' + +const titleContentType = configureTitleBlockContent() + +const blockContentType = configureBlockContent({ + h1: false, + h2: false, + h3: false, + h4: false, + internalLink: false, + externalLink: false, + attachment: false, + lists: false, +}) + +export type PromoTextTile = { + _type: 'promoTextTile' + title: any[] + linkLabelAsTitle?: boolean + link?: LinkSelector + 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: 'linkLabelAsTitle', + title: 'Use link label as link title', + type: 'boolean', + initialValue: false, + }, + { + name: 'title', + type: 'array', + inputComponent: CompactBlockEditor, + of: [titleContentType], + title: 'Title', + validation: (Rule: Rule) => + Rule.custom((value: PortableTextBlock[], context: ValidationContext) => { + const { parent } = context as { parent: PromoTextTile } + if (parent?.linkLabelAsTitle || value) return true + return 'Required' + }), + }, + { + name: 'text', + title: 'Text content', + type: 'array', + of: [blockContentType], + validation: (Rule: Rule) => + Rule.custom((value: PortableTextBlock[]) => validateCharCounterEditor(value, 600)).warning(), + }, + { + name: 'link', + type: 'linkSelector', + }, + { + title: 'Background', + description: 'Pick a colour for the background. Default is white.', + name: 'background', + type: 'colorlist', + fieldset: 'design', + }, + ], + preview: { + select: { + title: 'title', + linkLabelAsTitle: 'linkLabelAsTitle', + link: 'link.label', + }, + prepare({ title, linkLabelAsTitle, link }: { title: any[]; linkLabelAsTitle: boolean; link: string }) { + return { + title: linkLabelAsTitle ? link : blocksToText(title as any[]), + subtitle: `Promo text tile component`, + media: EdsIcon(label), + } + }, + }, +} diff --git a/sanityv3/schemas/objects/promoTextTileArray.tsx b/sanityv3/schemas/objects/promoTextTileArray.tsx new file mode 100644 index 000000000..3f32b37be --- /dev/null +++ b/sanityv3/schemas/objects/promoTextTileArray.tsx @@ -0,0 +1,52 @@ +import { collection_2 } from '@equinor/eds-icons' +import { EdsIcon } from '../../icons' +import type { PortableTextBlock, Rule } from 'sanity' +import type { PromoTextTile } from './promoTextTile' +import blocksToText from '../../helpers/blocksToText' + +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), + preview: { + select: { + group: 'group', + }, + prepare({ group }: { group: PromoTextTile[] }) { + const getTitle = (promoTextTile: PromoTextTile) => { + return promoTextTile.linkLabelAsTitle + ? promoTextTile.link?.label + : blocksToText(promoTextTile.title as PortableTextBlock[]) + } + const firstTitle = group[0] ? getTitle(group[0]) : '' + const secondTitle = group[1] ? getTitle(group[1]) : '' + + return { + title: firstTitle + (group[1] ? ' | ' + secondTitle : ''), + subtitle: 'Promo tiles component', + media:
{EdsIcon(collection_2)}
, + } + }, + }, +} diff --git a/web/lib/queries/common/pageContentFields.ts b/web/lib/queries/common/pageContentFields.ts index 43cf55fdd..9fb8bf2d0 100644 --- a/web/lib/queries/common/pageContentFields.ts +++ b/web/lib/queries/common/pageContentFields.ts @@ -180,6 +180,36 @@ const pageContentFields = /* groq */ ` }, }, }, + _type == "promoTextTileArray"=>{ + "type": _type, + "id": _key, + "useHorizontalScroll": useHorizontalScroll, + spacing, + "group": group[]{ + "id": _key, + title, + linkLabelAsTitle, + text[]{..., ${markDefs}}, + "action": { + "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" + ), + }, + "designOptions": { + "background": coalesce(background.title, 'none'), + }, + }, + }, _type == "iframe" => { "type": _type, "id": _key, diff --git a/web/pageComponents/pageTemplates/shared/SharedPageContent.tsx b/web/pageComponents/pageTemplates/shared/SharedPageContent.tsx index 30d90d0f7..f42f073ec 100644 --- a/web/pageComponents/pageTemplates/shared/SharedPageContent.tsx +++ b/web/pageComponents/pageTemplates/shared/SharedPageContent.tsx @@ -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' @@ -33,6 +34,7 @@ import { QuoteData, AccordionData, PromoTileArrayData, + PromoTextTileArrayData, IFrameData, PromotionData, FormData, @@ -58,6 +60,7 @@ type ComponentProps = | QuoteData | AccordionData | PromoTileArrayData + | PromoTextTileArrayData | IFrameData | PromotionData | FormData @@ -97,6 +100,8 @@ export const PageContent = ({ data }: PageContentProps) => { return case 'promoTileArray': return + case 'promoTextTileArray': + return case 'iframe': return