diff --git a/sanityv3/schemas/objects/grid/cellTypes/gridTeaser.tsx b/sanityv3/schemas/objects/grid/cellTypes/gridTeaser.tsx index 8332540a2..5f5976f7e 100644 --- a/sanityv3/schemas/objects/grid/cellTypes/gridTeaser.tsx +++ b/sanityv3/schemas/objects/grid/cellTypes/gridTeaser.tsx @@ -71,7 +71,7 @@ export default { { title: 'Use extended themes', name: 'useExtendedThemes', - description: 'Enabling this removes normal text style, but gives more theme options', + description: 'Enabling this removes normal text style and quote, but gives more theme options', type: 'boolean', }, { @@ -96,41 +96,26 @@ export default { return validateCharCounterEditor(value, 600) }).warning(), }, - { - name: 'contentThemeFromNormal', - title: 'Content theme', - type: 'themeList', - options: { - colors: fromNormalTextThemeColors, - }, - hidden: ({ parent }: GridTeaserDocument) => parent.useExtendedThemes, - }, - { - name: 'contentThemeFromLarger', - title: 'Content theme', - type: 'themeList', - options: { - colors: fromLargerTextThemeColors, - }, - hidden: ({ parent }: GridTeaserDocument) => !parent.useExtendedThemes, - }, { name: 'quote', type: 'text', title: 'Quote', description: 'Highlighted quote from the article, gets theme from below', rows: 5, + hidden: ({ parent }: GridTeaserDocument) => parent.useExtendedThemes, }, { name: 'author', type: 'string', title: 'Name', + hidden: ({ parent }: GridTeaserDocument) => parent.useExtendedThemes, }, { name: 'authorTitle', type: 'string', title: 'Title', description: 'Optional title for the author.', + hidden: ({ parent }: GridTeaserDocument) => parent.useExtendedThemes, }, { name: 'action', @@ -173,11 +158,20 @@ export default { { name: 'theme', title: 'Theme', + type: 'themeList', options: { colors: fromNormalTextThemeColors, }, - description: 'If no theme set, normal text color is set', + hidden: ({ parent }: GridTeaserDocument) => parent.useExtendedThemes, + }, + { + name: 'themeFromLarger', + title: 'Theme', type: 'themeList', + options: { + colors: fromLargerTextThemeColors, + }, + hidden: ({ parent }: GridTeaserDocument) => !parent.useExtendedThemes, }, ], preview: { diff --git a/sanityv3/schemas/objects/grid/cellTypes/gridTextBlock.tsx b/sanityv3/schemas/objects/grid/cellTypes/gridTextBlock.tsx index 6481c4ff9..ee9b469d2 100644 --- a/sanityv3/schemas/objects/grid/cellTypes/gridTextBlock.tsx +++ b/sanityv3/schemas/objects/grid/cellTypes/gridTextBlock.tsx @@ -95,17 +95,6 @@ export default { validation: (Rule: Rule) => Rule.custom((value: PortableTextBlock[]) => (!value ? 'A title is recommended' : true)).warning(), }, - { - name: 'titleThemeFromNormal', - title: 'Title theme', - type: 'themeList', - options: { - colors: fromNormalTextThemeColors, - }, - fieldset: 'title', - hidden: ({ parent }: GridTextBlockDocument) => parent.useThemedTitle, - description: 'use white text or black text when background image', - }, { name: 'titleThemeFromLarger', title: 'Title theme', @@ -115,7 +104,7 @@ export default { }, fieldset: 'title', hidden: ({ parent }: GridTextBlockDocument) => !parent.useThemedTitle, - description: 'use white text or black text when background image', + description: 'Use white text or black text when background image', }, { name: 'content', @@ -142,9 +131,20 @@ export default { options: { colors: fromNormalTextThemeColors, }, + hidden: ({ parent }: GridTextBlockDocument) => !parent.useThemedTitle, description: 'Title theme background will be used if different.Text will then be white/black. Use white or black text when background image', }, + { + name: 'theme', + title: 'Theme', + type: 'themeList', + options: { + colors: fromNormalTextThemeColors, + }, + hidden: ({ parent }: GridTextBlockDocument) => parent.useThemedTitle, + description: 'Use white or black text when background image', + }, { name: 'contentAlignment', title: 'Content Alignment', diff --git a/sanityv3/schemas/objects/imageWithAlt.tsx b/sanityv3/schemas/objects/imageWithAlt.tsx index b14d5679e..e26802853 100644 --- a/sanityv3/schemas/objects/imageWithAlt.tsx +++ b/sanityv3/schemas/objects/imageWithAlt.tsx @@ -22,7 +22,6 @@ export default { title: 'Image is decorative', description: 'If this image is purely decorative you can disable the alt tag input here. Please note that this makes the image invisible for screen reader users.', - initialValue: false, }, { name: 'alt', diff --git a/web/lib/queries/gridContentFields.ts b/web/lib/queries/gridContentFields.ts index f3fbe9417..7c9c9f465 100644 --- a/web/lib/queries/gridContentFields.ts +++ b/web/lib/queries/gridContentFields.ts @@ -41,10 +41,10 @@ overline, useThemedTitle, title[]{..., ${markDefs}}, themedTitle[]{..., ${markDefs}}, -"titleThemeFromNormal": coalesce(titleThemeFromNormal.value, null), "titleThemeFromLarger":coalesce(titleThemeFromLarger.value, null), content[]{..., ${markDefs}}, "contentTheme":coalesce(contentTheme.value, null), +"theme":coalesce(theme.value, null), "action": action[0]{ ${linkSelectorFields}, ${downloadableFileFields}, @@ -72,17 +72,13 @@ _type == "gridTeaser" => { useExtendedThemes, content[]{..., ${markDefs}}, themedContent[]{..., ${markDefs}}, - "contentThemeFromNormal": coalesce(contentThemeFromNormal.value, null), - "contentThemeFromLarger":coalesce(contentThemeFromLarger.value, null), + "themeFromLarger": coalesce(themeFromLarger.value, null), + "theme":coalesce(theme.value, null), author, authorTitle, quote, "imagePosition": coalesce(imagePosition, 'left'), - "theme": coalesce(theme.value, null), - "image": image { - ..., - "extension": asset-> extension - }, + image, "action": action[0]{ ${linkSelectorFields}, ${downloadableFileFields}, diff --git a/web/sections/Grid/GridLinkArrow.tsx b/web/sections/Grid/GridLinkArrow.tsx index fd8da69a9..b6172b864 100644 --- a/web/sections/Grid/GridLinkArrow.tsx +++ b/web/sections/Grid/GridLinkArrow.tsx @@ -5,44 +5,29 @@ import { BaseLink } from '@core/Link' import { getLocaleFromName } from '../../lib/localization' import { ArrowRight } from '../../icons' import { LinkData } from '../../types/types' -import { getColorForTheme } from '../../pageComponents/shared/textTeaser/theme' type GridLinkArrowProps = { - theme?: number action?: LinkData className?: string - /* If background image */ - hasBackgroundImage?: boolean - useLight?: boolean + bgColor?: string } -const GridLinkArrow = ({ - theme, - action, - className = '', - hasBackgroundImage = false, - useLight = false, -}: GridLinkArrowProps) => { +const GridLinkArrow = ({ action, className = '', bgColor }: GridLinkArrowProps) => { const url = action && getUrlFromAction(action) - const { textUtility } = getColorForTheme(theme) const variantClassName = () => { - if (hasBackgroundImage) { - if (useLight) { - return 'text-slate-80 hover:bg-white-100 hover:text-slate-80 focus-visible:bg-white-100 focus-visible:text-slate-80' - } - return 'text-white-100 hover:bg-white-100 hover:text-slate-80 focus-visible:bg-white-100 focus-visible:text-slate-80' - } - switch (theme) { - case 0: - return 'text-energy-red-100 hover:bg-energy-red-100 hover:text-white-100 focus-visible:bg-energy-red-100 focus-visible:text-white-100' - case 8: - return `text-white-100 hover:bg-white-100 hover:text-blue-50 focus-visible:bg-white-100 focus-visible:text-blue-50` - case 10: + switch (bgColor) { + case 'bg-yellow-50': + case 'bg-green-50': + case 'bg-orange-50': + case 'bg-mist-blue-100': + return `text-slate-80 hover:bg-slate-80 hover:text-white-100 focus-visible:bg-slate-80 focus-visible:text-white-100` + case 'bg-white-100': + return `text-slate-80 hover:bg-grey-50 hover:text-white-100 focus-visible:bg-grey-50 focus-visible:text-white-100` + case 'bg-blue-50': + case 'bg-slate-80': default: - return `${theme !== null ? textUtility : ''} hover:bg-white-100 hover:${ - theme !== null ? textUtility : '' - } focus-visible:bg-white-100 focus-visible:${theme !== null ? textUtility : ''}` + return `text-white-100 hover:bg-white-100 hover:text-slate-80 focus-visible:bg-white-100 focus-visible:text-slate-80` } } diff --git a/web/sections/Grid/GridTeaser.tsx b/web/sections/Grid/GridTeaser.tsx index 871cda24b..b875fb47b 100644 --- a/web/sections/Grid/GridTeaser.tsx +++ b/web/sections/Grid/GridTeaser.tsx @@ -28,20 +28,33 @@ export const GridTeaser = forwardRef(function G author, authorTitle, useExtendedThemes, - contentThemeFromLarger, - contentThemeFromNormal, + themeFromLarger, theme, } = data + const imageSrc = urlFor(image).size(1200, 800).auto('format').toString() const altTag = image?.isDecorative ? '' : image?.alt || '' - const { - backgroundUtility, - textUtility: contentTextUtility, - dark, - } = getColorForTheme(useExtendedThemes ? contentThemeFromLarger : contentThemeFromNormal) - - const contentTextColor = (contentThemeFromNormal || contentThemeFromLarger) !== null ? contentTextUtility : '' + let contentTextColor = 'text-slate-80' + let bgColor = 'bg-white-100' + if (useExtendedThemes && themeFromLarger) { + const { backgroundUtility: extendedBg, textUtility: extendedTxt } = getColorForTheme(themeFromLarger) + if (extendedTxt) { + contentTextColor = extendedTxt + } + if (extendedBg) { + bgColor = extendedBg + } + } + if (theme) { + const { backgroundUtility: themeBg, textUtility: themeTxt } = getColorForTheme(theme) + if (themeTxt) { + contentTextColor = themeTxt + } + if (themeBg) { + bgColor = themeBg + } + } return (
(function G grid-rows-2 lg:grid-rows-[250px_1fr] ${String(rowType) === 'span3' ? 'lg:grid-cols-[40%_60%] lg:grid-rows-1' : ''} - ${backgroundUtility ?? ''} - ${dark ? 'dark' : ''} + ${bgColor} `)} > {image && ( @@ -119,7 +131,7 @@ export const GridTeaser = forwardRef(function G )}
- {action && } + {action && } ) diff --git a/web/sections/Grid/GridTextBlock.tsx b/web/sections/Grid/GridTextBlock.tsx index 76e6b839f..809732b41 100644 --- a/web/sections/Grid/GridTextBlock.tsx +++ b/web/sections/Grid/GridTextBlock.tsx @@ -24,8 +24,8 @@ const GridTextBlock = ({ data, className, rowType }: GridTextBlockProps) => { useThemedTitle, themedTitle, titleThemeFromLarger, - titleThemeFromNormal, contentTheme, + theme, contentAlignment, imageBackground, } = data @@ -33,8 +33,8 @@ const GridTextBlock = ({ data, className, rowType }: GridTextBlockProps) => { const contentAlignmentUtilities = { center: 'justify-center items-center', - right: 'justify-center items-end', - left: 'justify-center items-start', + right: 'justify-end items-center', + left: 'justify-start items-center', 'bottom-left': 'justify-start items-end', 'bottom-center': 'justify-center items-end', } @@ -48,42 +48,66 @@ const GridTextBlock = ({ data, className, rowType }: GridTextBlockProps) => { const textClassNames = twMerge(`${(title || themedTitle) && content ? 'text-sm' : 'text-md'}`, className) - const { - backgroundUtility: titleBgUtility, - textUtility: titleTextUtility, - dark, - } = getColorForTheme(useThemedTitle ? titleThemeFromLarger : titleThemeFromNormal) + let titleTextColor = 'text-slate-80' + let contentTextColor = 'text-slate-80' + let bgColor = 'bg-white-100' - const { textUtility: contentTextUtility, backgroundUtility: contentBgUtility } = getColorForTheme(contentTheme ?? 0) + if (useThemedTitle) { + const { + backgroundUtility: titleBgUtility, + textUtility: titleTextUtility, + dark, + } = getColorForTheme(titleThemeFromLarger) + if (titleTextUtility) { + titleTextColor = titleTextUtility + } + const { textUtility: contentTextUtility, backgroundUtility: contentBgUtility } = getColorForTheme(contentTheme) + if (contentBgUtility === titleBgUtility && contentTextUtility) { + contentTextColor = contentTextUtility + } + if (contentBgUtility !== titleBgUtility) { + contentTextColor = dark ? 'text-white-100' : 'text-slate-80' + } + bgColor = titleBgUtility ?? contentBgUtility ?? 'bg-white-100' + } + if (theme) { + const { backgroundUtility: commonBgUtility, textUtility: commonTextUtility } = getColorForTheme(theme) + if (commonTextUtility) { + titleTextColor = commonTextUtility + contentTextColor = commonTextUtility + } + if (commonBgUtility) { + bgColor = commonBgUtility + } + } const imageBgOptions = { background: { type: 'backgroundImage' as BackgroundTypes, backgroundImage: imageBackground, dark: - (titleThemeFromNormal ?? titleThemeFromLarger ?? contentTheme) === 12 && !imageBackground?.useLight + (((useThemedTitle && titleThemeFromLarger) || contentTheme) ?? theme) === 12 && !imageBackground?.useLight ? true : false, }, } - let titleTextColor = (titleThemeFromNormal || titleThemeFromLarger) !== null ? titleTextUtility : '' if (imageBackground?.image) { titleTextColor = 'text-white-100' if (imageBackground?.useLight) { titleTextColor = 'text-slate-80' } } - let mainContentTextColor = contentTheme !== null ? contentTextUtility : titleTextColor + if (imageBackground?.image) { - mainContentTextColor = 'text-white-100' + bgColor = 'bg-slate-80' + contentTextColor = 'text-white-100' if (imageBackground?.useLight) { - mainContentTextColor = 'text-slate-80' + contentTextColor = 'text-slate-80' + bgColor = 'bg-white-100' } } - const backgroundUtility = titleBgUtility ?? contentBgUtility ?? '' - const lightGradientForContentAlignment = { center: '', right: '', @@ -111,29 +135,29 @@ const GridTextBlock = ({ data, className, rowType }: GridTextBlockProps) => { return '4xl:grid 4xl:grid-cols-[35%_60%] gap-10' case 'threeColumns': default: - return 'lg:items-end' + return '' } } const serializerClassnames = { - largeText: `leading-tight text-balance`, - normal: `text-lg leading-snug text-balance`, + largeText: `leading-tight text-balance ${titleTextColor}`, + normal: `text-lg leading-snug text-balance ${titleTextColor}`, } const mainContent = ( <>
{overline ? (
{overline} @@ -165,24 +189,18 @@ const GridTextBlock = ({ data, className, rowType }: GridTextBlockProps) => { )} {content && ( -
+
)}
- {action && url && ( - - )} + {action && url && } ) @@ -213,9 +231,9 @@ const GridTextBlock = ({ data, className, rowType }: GridTextBlockProps) => { ) : (
{mainContent}
diff --git a/web/types/types.ts b/web/types/types.ts index 9dded6037..df3b1021f 100644 --- a/web/types/types.ts +++ b/web/types/types.ts @@ -875,11 +875,11 @@ export type GridTextBlockData = { useThemedTitle?: boolean title?: PortableTextBlock[] themedTitle?: PortableTextBlock[] - titleThemeFromNormal?: any - titleThemeFromLarger?: any content?: PortableTextBlock[] contentAlignment?: GridTextBlockContentAlignment contentTheme?: any + titleThemeFromLarger?: any + theme?: any imageBackground?: ImageBackground } @@ -897,8 +897,7 @@ export type GridTeaserData = { useExtendedThemes?: boolean content?: PortableTextBlock[] themedContent?: PortableTextBlock[] - contentThemeFromNormal?: any - contentThemeFromLarger?: any + themeFromLarger?: any quote?: string author?: string authorTitle?: string