|
1 | 1 | 'use client';
|
2 | 2 |
|
3 | 3 | import { Category } from '@prezly/sdk';
|
4 |
| -import { useMemo } from 'react'; |
| 4 | +import classNames from 'classnames'; |
5 | 5 |
|
6 | 6 | import { useLocale } from '@/adapters/client';
|
7 | 7 | import type { ListStory } from 'types';
|
8 | 8 |
|
| 9 | +import { Badge } from '../Badge'; |
| 10 | +import { Link } from '../Link'; |
| 11 | +import { StoryImage } from '../StoryImage'; |
| 12 | + |
9 | 13 | import { StoryCard } from './StoryCard';
|
10 | 14 |
|
| 15 | +import styles from './HighlightedStoryCard.module.scss'; |
| 16 | + |
11 | 17 | type Props = {
|
| 18 | + fullWidth: boolean; |
| 19 | + rounded: boolean; |
12 | 20 | showDate: boolean;
|
13 | 21 | showSubtitle: boolean;
|
14 | 22 | story: ListStory;
|
15 | 23 | };
|
16 | 24 |
|
17 |
| -export function HighlightedStoryCard({ showDate, showSubtitle, story }: Props) { |
18 |
| - const localeCode = useLocale(); |
19 |
| - const { categories } = story; |
| 25 | +export function HighlightedStoryCard({ fullWidth, rounded, showDate, showSubtitle, story }: Props) { |
| 26 | + const locale = useLocale(); |
| 27 | + const { categories, slug, subtitle } = story; |
20 | 28 |
|
21 |
| - const translatedCategories = useMemo( |
22 |
| - () => Category.translations(categories, localeCode), |
23 |
| - [categories, localeCode], |
24 |
| - ); |
| 29 | + const translatedCategories = Category.translations(categories, locale); |
| 30 | + |
| 31 | + if (fullWidth) { |
| 32 | + return ( |
| 33 | + <div |
| 34 | + className={classNames(styles.container, { |
| 35 | + [styles.rounded]: rounded, |
| 36 | + })} |
| 37 | + > |
| 38 | + <StoryImage |
| 39 | + size="full-width" |
| 40 | + className={styles.image} |
| 41 | + thumbnailImage={story.thumbnail_image} |
| 42 | + title={story.title} |
| 43 | + /> |
| 44 | + <div className={styles.overlay} /> |
| 45 | + <div className={styles.content}> |
| 46 | + {translatedCategories.length > 0 && ( |
| 47 | + <div className={styles.categories}> |
| 48 | + {translatedCategories.map((category) => ( |
| 49 | + <Link |
| 50 | + className={styles.link} |
| 51 | + href={{ |
| 52 | + routeName: 'category', |
| 53 | + params: { localeCode: locale, slug: category.slug }, |
| 54 | + }} |
| 55 | + key={category.id} |
| 56 | + > |
| 57 | + <Badge className={styles.badge} size="small"> |
| 58 | + {category.name} |
| 59 | + </Badge> |
| 60 | + </Link> |
| 61 | + ))} |
| 62 | + </div> |
| 63 | + )} |
| 64 | + <Link className={styles.link} href={{ routeName: 'story', params: { slug } }}> |
| 65 | + <h2 |
| 66 | + className={classNames(styles.title, { |
| 67 | + [styles.expanded]: !showSubtitle || !subtitle, |
| 68 | + })} |
| 69 | + > |
| 70 | + {story.title} |
| 71 | + <span className={styles.mask} /> |
| 72 | + </h2> |
| 73 | + </Link> |
| 74 | + {showSubtitle && subtitle && <p className={styles.subtitle}>{subtitle}</p>} |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + ); |
| 78 | + } |
25 | 79 |
|
26 | 80 | return (
|
27 | 81 | <StoryCard
|
|
0 commit comments