Skip to content

Commit

Permalink
Merge branch 'bose/2581' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle committed Oct 25, 2024
2 parents 8bd0fa2 + b658e1a commit 7ca9dbf
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions sanityv3/schemas/documents/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default {
Flags.HAS_TWITTER_FEED && { type: 'twitterEmbed' },
{ type: 'cookieDeclaration' },
{ type: 'anchorLinkList' },
{ type: 'stickyTextBlocks' },
].filter((e) => e),
},
].filter((e) => e),
Expand Down
2 changes: 2 additions & 0 deletions sanityv3/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import transcript from './objects/transcript'
import imageForText from './objects/imageForText'
import anchorLinkList from './objects/anchorLinkList/anchorLinkList'
import anchorLinkReference from './objects/anchorLinkList/anchorLinkReference'
import stickyTextBlocks from './objects/stickyTextBlocks'

const {
pageNotFound,
Expand Down Expand Up @@ -210,6 +211,7 @@ const RemainingSchemas = [
imageForText,
anchorLinkList,
anchorLinkReference,
stickyTextBlocks,
]

// Then we give our schema to the builder and provide the result to Sanity
Expand Down
71 changes: 71 additions & 0 deletions sanityv3/schemas/objects/stickyTextBlocks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { view_module } from '@equinor/eds-icons'
import { EdsIcon } from '../../icons'
import { SchemaType } from '../../types'
import { configureBlockContent } from '../editors'

const blockContentType = configureBlockContent({
h2: false,
h3: true,
h4: true,
attachment: false,
})

export default {
type: 'object',
name: 'stickyTextBlocks',
title: 'Sticky text blocks',
fieldsets: [
{
name: 'design',
title: 'Design options',
},
],
fields: [
{
type: 'array',
name: 'blockGroup',
title: 'List of text block',
of: [
{
name: 'textBlock',
title: 'Text block',
type: 'object',
fields: [
{
name: 'title',
title: 'Title heading',
type: 'string',
description: 'Heading that will stay sticky until side content is scrolled by',
},
{
name: 'content',
title: 'Text content',
type: 'array',
of: [blockContentType],
},
],
},
],
validation: (Rule: SchemaType.ValidationRule) => Rule.required(),
},
{
title: 'Background',
description: 'Pick a colour for the background. Default is white.',
name: 'background',
type: 'colorlist',
fieldset: 'design',
},
],
preview: {
select: {
group: 'blockGroup',
},
prepare({ group }: any) {
return {
title: 'Sticky textblocks',
subtitle: `${group ? group.length : 0} textblocks`,
media: <div>{EdsIcon(view_module)}</div>,
}
},
},
}
16 changes: 16 additions & 0 deletions web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,22 @@ _type == "keyNumbers" =>{
anchorReference,
}
},
_type == "stickyTextBlocks"=>{
"type": _type,
"id": _key,
"group": blockGroup[]{
"id": _key,
title,
content[]{
...,
${markDefs},
}
},
"designOptions": {
${background},
},
},
`

export default pageContentFields
11 changes: 11 additions & 0 deletions web/pageComponents/pageTemplates/shared/SharedPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
DesignOptions,
ImageForTextData,
AnchorLinkListData,
StickyTextBlocksData,
} from '../../../types/index'
import { getColorForTheme } from '../../shared/textTeaser/theme'
import Grid from '@sections/Grid/Grid'
Expand All @@ -63,6 +64,7 @@ import VideoPlayerCarousel from '@sections/VideoPlayerCarousel/VideoPlayerCarous
import ImageCarousel from '@sections/ImageCarousel/ImageCarousel'
import ImageForText from '@sections/ImageForText/ImageForText'
import { AnchorLinkList } from '@sections/AnchorLinkList'
import { StickyTextBlocks } from '@sections/StickyTextBlocks'

type DefaultComponent = {
id?: string
Expand Down Expand Up @@ -354,6 +356,15 @@ export const PageContent = ({ data, titleBackground }: PageContentProps) => {
className={topSpacingClassName}
/>
)
case 'stickyTextBlocks':
return (
<StickyTextBlocks
key={c.id}
data={c as StickyTextBlocksData}
anchor={anchorReference}
className={topSpacingClassName}
/>
)
default:
return null
}
Expand Down
39 changes: 39 additions & 0 deletions web/sections/StickyTextBlocks/StickyTextBlocks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { BackgroundContainer } from '@components/Backgrounds'
import { Typography } from '@core/Typography'
import Blocks from '../../pageComponents/shared/portableText/Blocks'
import { twMerge } from 'tailwind-merge'
import { PortableTextBlock } from '@portabletext/types'
import { StickyTextBlocksData } from '../../types/types'

export type StickyTextBlocksProps = {
data: StickyTextBlocksData
anchor?: string
className?: string
}
const StickyTextBlocks = ({ data, anchor, className }: StickyTextBlocksProps) => {
const { group, designOptions } = data
return (
<BackgroundContainer {...designOptions} className={twMerge(`pb-page-content px-layout-sm`, className)} id={anchor}>
{group?.length > 0 &&
group?.map((textBlock: { id: string; title?: string; content: PortableTextBlock[] }) => {
return (
<section
key={textBlock?.id}
className="lg:grid lg:grid-cols-[30%_70%] gap-24 py-12 border-y-2 border-energy-red-100"
>
{textBlock?.title && (
<Typography variant="h2" className="h-max lg:sticky top-32 text-pretty">
{textBlock.title}
</Typography>
)}
<div className="max-w-text">
{textBlock?.content && <Blocks value={textBlock.content} className="flex flex-col" />}
</div>
</section>
)
})}
</BackgroundContainer>
)
}

export default StickyTextBlocks
2 changes: 2 additions & 0 deletions web/sections/StickyTextBlocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//"use client";
export { default as StickyTextBlocks, type StickyTextBlocksProps } from './StickyTextBlocks'
10 changes: 10 additions & 0 deletions web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,13 @@ export type AnchorLinkListData = {
anchorReference?: string
}[]
}
export type StickyTextBlocksData = {
type: string
id: string
group: {
id: string
title?: string
content: PortableTextBlock[]
}[]
designOptions: DesignOptions
}

0 comments on commit 7ca9dbf

Please sign in to comment.