Skip to content

Commit ac7a269

Browse files
#3748 Functions cannot be passed directly to Client Components - Fixes in campaignBanner (#3754)
1 parent 1ea5b5a commit ac7a269

2 files changed

Lines changed: 60 additions & 36 deletions

File tree

web/sections/CampaignBanner/CampaignBanner.tsx

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,10 @@ import type { PortableTextBlock } from '@portabletext/types'
22
import { forwardRef, type HTMLAttributes } from 'react'
33
import { twMerge } from 'tailwind-merge'
44
import { urlForImage } from '@/sanity/lib/utils'
5-
import Blocks, { type MarkType } from '../../portableText/Blocks'
6-
import isEmpty from '../../portableText/helpers/isEmpty'
5+
import { CampaignBannerTitle } from './CampaignBannerTitle'
76
import { colorKeyToUtilityMap } from '../../styles/colorKeyToUtilityMap'
87
import type { CampaignBannerData } from '../../types/index'
98

10-
/* eslint-disable @typescript-eslint/ban-ts-comment */
11-
const campaignTitleBlocks: MarkType = {
12-
//@ts-ignore
13-
smallText: ({ children }: PortableTextBlock) => (
14-
<p className='text-sm'>{<>{children}</>}</p>
15-
),
16-
//@ts-ignore
17-
largeText: ({ children }: PortableTextBlock) => (
18-
<p className='block w-fit text-balance rounded-xs bg-white-100 text-2xl leading-none'>
19-
{<>{children}</>}
20-
</p>
21-
),
22-
//@ts-ignore
23-
extraLargeText: ({ children }: PortableTextBlock) => {
24-
return (
25-
<p className='mt-4 block w-fit text-balance rounded-xs bg-white-100 font-semibold text-4xl leading-none lg:text-8xl'>
26-
{<>{children}</>}
27-
</p>
28-
)
29-
},
30-
//@ts-ignore
31-
normal: ({ children }: PortableTextBlock) => {
32-
if (isEmpty(children)) return null
33-
return (
34-
<p>
35-
<>{children}</>
36-
</p>
37-
)
38-
},
39-
}
40-
/* eslint-enable @typescript-eslint/ban-ts-comment */
41-
429
export type CampaignBannerProps = {
4310
data: CampaignBannerData
4411
className?: string
@@ -89,10 +56,9 @@ const CampaignBanner = forwardRef<HTMLElement, CampaignBannerProps>(
8956
<div className={`mx-auto px-layout-md`}>
9057
<div className='flex justify-start'>
9158
<h2 className=''>
92-
<Blocks
59+
<CampaignBannerTitle
9360
value={title}
9461
blockClassName='my-0 text-energy-red-100'
95-
blocksComponents={campaignTitleBlocks}
9662
className='w-fit max-w-prose text-energy-red-100'
9763
/>
9864
</h2>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use client'
2+
3+
import type { PortableTextBlock } from '@portabletext/types'
4+
import Blocks, { type MarkType } from '../../portableText/Blocks'
5+
import isEmpty from '../../portableText/helpers/isEmpty'
6+
7+
/* eslint-disable @typescript-eslint/ban-ts-comment */
8+
const campaignTitleBlocks: MarkType = {
9+
//@ts-ignore
10+
smallText: ({ children }: PortableTextBlock) => (
11+
<p className='text-sm'>{<>{children}</>}</p>
12+
),
13+
//@ts-ignore
14+
largeText: ({ children }: PortableTextBlock) => (
15+
<p className='block w-fit text-balance rounded-xs bg-white-100 text-2xl leading-none'>
16+
{<>{children}</>}
17+
</p>
18+
),
19+
//@ts-ignore
20+
extraLargeText: ({ children }: PortableTextBlock) => {
21+
return (
22+
<p className='mt-4 block w-fit text-balance rounded-xs bg-white-100 font-semibold text-4xl leading-none lg:text-8xl'>
23+
{<>{children}</>}
24+
</p>
25+
)
26+
},
27+
//@ts-ignore
28+
normal: ({ children }: PortableTextBlock) => {
29+
if (isEmpty(children)) return null
30+
return (
31+
<p>
32+
<>{children}</>
33+
</p>
34+
)
35+
},
36+
}
37+
/* eslint-enable @typescript-eslint/ban-ts-comment */
38+
39+
type CampaignBannerTitleProps = {
40+
value: PortableTextBlock[]
41+
blockClassName?: string
42+
className?: string
43+
}
44+
45+
export const CampaignBannerTitle = ({
46+
value,
47+
blockClassName,
48+
className,
49+
}: CampaignBannerTitleProps) => {
50+
return (
51+
<Blocks
52+
value={value}
53+
blockClassName={blockClassName}
54+
blocksComponents={campaignTitleBlocks}
55+
className={className}
56+
/>
57+
)
58+
}

0 commit comments

Comments
 (0)