|
1 | | -import { forwardRef, HTMLAttributes } from 'react' |
2 | | -import { BaseLink } from '@/core/Link' |
| 1 | +import type { SanityImageObject } from '@sanity/image-url' |
| 2 | +import NextImage from 'next/image' |
| 3 | +import { forwardRef, type HTMLAttributes } from 'react' |
| 4 | +import { twMerge } from 'tailwind-merge' |
| 5 | +import FormattedDateTime from '@/core/FormattedDateTime/FormattedDateTime' |
| 6 | +import { BaseLink } from '@/core/Link/BaseLink' |
3 | 7 | import { Typography } from '@/core/Typography' |
4 | 8 | import { getSmallerThanPxLgSizes, Image } from '../../../core/Image/Image' |
5 | | -import NextImage from 'next/image' |
6 | | -import { NewsRoomNewsItem } from '../../../types/algoliaIndexPage' |
7 | | -import { SanityImageObject } from '@sanity/image-url/lib/types/types' |
8 | 9 | import Blocks from '../../../portableText/Blocks' |
9 | | -import FormattedDateTime from '@/core/FormattedDateTime/FormattedDateTime' |
10 | | -import { twMerge } from 'tailwind-merge' |
| 10 | +import type { NewsRoomNewsItem } from '../../../types/algoliaIndexPage' |
11 | 11 |
|
12 | 12 | export type NewsHeadlinerProps = { |
13 | 13 | data: NewsRoomNewsItem |
14 | 14 | fallbackImage?: SanityImageObject |
15 | 15 | } & HTMLAttributes<HTMLLIElement> |
16 | 16 |
|
17 | | -const NewsHeadliner = forwardRef<HTMLLIElement, NewsHeadlinerProps>(function NewsHeadliner( |
18 | | - { data, fallbackImage, className = '', ...rest }, |
19 | | - ref, |
20 | | -) { |
21 | | - const { slug, title, ingress, publishDateTime, heroImage, thumbnailUrl } = data |
| 17 | +const NewsHeadliner = forwardRef<HTMLLIElement, NewsHeadlinerProps>( |
| 18 | + function NewsHeadliner( |
| 19 | + { data, fallbackImage, className = '', ...rest }, |
| 20 | + ref, |
| 21 | + ) { |
| 22 | + const { slug, title, ingress, publishDateTime, heroImage, thumbnailUrl } = |
| 23 | + data |
22 | 24 |
|
23 | | - return ( |
24 | | - <section ref={ref} {...rest} className={twMerge('', className)}> |
25 | | - <BaseLink href={slug} className="group flex flex-col gap-2 pb-6"> |
26 | | - {(heroImage?.image?.asset || fallbackImage || thumbnailUrl) && ( |
27 | | - <div className="relative mb-2 aspect-video max-h-[324px]"> |
28 | | - {thumbnailUrl ? ( |
29 | | - <NextImage |
30 | | - className="relative h-full w-full rounded-2xs object-cover" |
31 | | - src={thumbnailUrl} |
32 | | - alt="" |
33 | | - sizes={getSmallerThanPxLgSizes()} |
34 | | - role={'presentation'} |
35 | | - /> |
36 | | - ) : ( |
37 | | - (heroImage?.image?.asset || fallbackImage) && ( |
38 | | - <Image |
39 | | - //@ts-ignore: TODO Fix SanityImage to take SanityImageObject |
40 | | - image={heroImage?.image?.asset ? heroImage?.image : fallbackImage} |
41 | | - aria-hidden |
42 | | - grid="sm" |
43 | | - fill |
44 | | - className="rounded-2xs" |
| 25 | + return ( |
| 26 | + <section ref={ref} {...rest} className={twMerge('', className)}> |
| 27 | + <BaseLink href={slug} className='group flex flex-col gap-2 pb-6'> |
| 28 | + {(heroImage?.image?.asset || fallbackImage || thumbnailUrl) && ( |
| 29 | + <div className='relative mb-2 aspect-video max-h-[324px]'> |
| 30 | + {thumbnailUrl ? ( |
| 31 | + <NextImage |
| 32 | + className='relative h-full w-full rounded-2xs object-cover' |
| 33 | + src={thumbnailUrl} |
| 34 | + alt='' |
| 35 | + sizes={getSmallerThanPxLgSizes()} |
| 36 | + role={'presentation'} |
45 | 37 | /> |
46 | | - ) |
47 | | - )} |
48 | | - </div> |
49 | | - )} |
50 | | - {publishDateTime && ( |
51 | | - <div> |
52 | | - <FormattedDateTime |
53 | | - variant="date" |
54 | | - datetime={publishDateTime} |
55 | | - uppercase |
56 | | - className="text-2xs leading-normal font-normal" |
57 | | - /> |
58 | | - <span className="mx-2 pb-1 text-2xs leading-normal font-normal">|</span> |
59 | | - <FormattedDateTime |
60 | | - variant="time" |
61 | | - datetime={publishDateTime} |
62 | | - className="pb-1 text-2xs leading-normal font-normal" |
63 | | - /> |
64 | | - </div> |
65 | | - )} |
66 | | - {title && ( |
67 | | - <Typography as="h2" variant="md" className="group-hover:underline"> |
68 | | - {title} |
69 | | - </Typography> |
70 | | - )} |
71 | | - {Array.isArray(ingress) ? ( |
72 | | - <Blocks value={ingress} className="max-w-prose text-sm" /> |
73 | | - ) : ( |
74 | | - <Typography variant="body" className="max-w-prose` text-sm"> |
75 | | - {ingress} |
76 | | - </Typography> |
77 | | - )} |
78 | | - </BaseLink> |
79 | | - </section> |
80 | | - ) |
81 | | -}) |
| 38 | + ) : ( |
| 39 | + (heroImage?.image?.asset || fallbackImage) && ( |
| 40 | + <Image |
| 41 | + //@ts-ignore: TODO Fix SanityImage to take SanityImageObject |
| 42 | + image={ |
| 43 | + heroImage?.image?.asset ? heroImage?.image : fallbackImage |
| 44 | + } |
| 45 | + aria-hidden |
| 46 | + grid='sm' |
| 47 | + fill |
| 48 | + className='rounded-2xs' |
| 49 | + /> |
| 50 | + ) |
| 51 | + )} |
| 52 | + </div> |
| 53 | + )} |
| 54 | + {publishDateTime && ( |
| 55 | + <div> |
| 56 | + <FormattedDateTime |
| 57 | + variant='date' |
| 58 | + datetime={publishDateTime} |
| 59 | + uppercase |
| 60 | + className='font-normal text-2xs leading-normal' |
| 61 | + /> |
| 62 | + <span className='mx-2 pb-1 font-normal text-2xs leading-normal'> |
| 63 | + | |
| 64 | + </span> |
| 65 | + <FormattedDateTime |
| 66 | + variant='time' |
| 67 | + datetime={publishDateTime} |
| 68 | + className='pb-1 font-normal text-2xs leading-normal' |
| 69 | + /> |
| 70 | + </div> |
| 71 | + )} |
| 72 | + {title && ( |
| 73 | + <Typography as='h2' variant='md' className='group-hover:underline'> |
| 74 | + {title} |
| 75 | + </Typography> |
| 76 | + )} |
| 77 | + {Array.isArray(ingress) ? ( |
| 78 | + <Blocks value={ingress} className='max-w-prose text-sm' /> |
| 79 | + ) : ( |
| 80 | + <Typography variant='body' className='max-w-prose` text-sm'> |
| 81 | + {ingress} |
| 82 | + </Typography> |
| 83 | + )} |
| 84 | + </BaseLink> |
| 85 | + </section> |
| 86 | + ) |
| 87 | + }, |
| 88 | +) |
82 | 89 | export default NewsHeadliner |
0 commit comments