Skip to content

Commit

Permalink
feat: added tooltip and internal article badge
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Jan 26, 2024
1 parent d9a0056 commit a33d9cb
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"news": {
"title": "News",
"page": "Page"
"page": "Page",
"internalArticle": "This is an internal article"
}
}
3 changes: 2 additions & 1 deletion messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"news": {
"title": "Nyheter",
"page": "Side"
"page": "Side",
"internalArticle": "Dette er en intern artikkel"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.7",
"@t3-oss/env-nextjs": "^0.7.1",
"autoprefixer": "^10.4.17",
"clsx": "^2.1.0",
Expand Down
28 changes: 28 additions & 0 deletions src/app/[locale]/(dashboard)/news/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,139 +27,162 @@ export default function News({
const mockData = [
{
id: 1,
internal: true,
title: 'Gruppe status: prosjekt spill',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 2,
internal: false,
title: 'DevOps Møtet',
date: '69. oktober 6969',
photoUrl: 'mock.jpg',
},
{
id: 3,
internal: false,
title: 'Jonas er kul',
date: '42. november 2023',
photoUrl: 'mock.jpg',
},
{
id: 4,
internal: true,
title: 'Iskrem er godt',
date: '18. februar 1942',
photoUrl: 'mock.jpg',
},
{
id: 5,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 6,
internal: true,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 7,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 8,
internal: false,
title: 'Dette er en veeeeldig lang overskrift som skal testes',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 9,
internal: true,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 10,
internal: true,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 11,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 12,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 13,
internal: true,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 14,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 15,
internal: true,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 16,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 17,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 18,
internal: false,
title: '18',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},

{
id: 19,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 20,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 21,
internal: false,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 22,
internal: true,
title: 'Hvorfor er jeg her?',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
},
{
id: 23,
internal: false,
title: '23',
date: '22. oktober 2023',
photoUrl: 'mock.jpg',
Expand All @@ -180,9 +203,13 @@ export default function News({
)}
key={data.id}
id={data.id}
internal={data.internal}
title={data.title}
date={data.date}
photoUrl={data.photoUrl}
t={{
internalArticle: t('internalArticle'),
}}
/>
))}
</div>
Expand All @@ -196,6 +223,7 @@ export default function News({
previous: useTranslations('ui')('previous'),
next: useTranslations('ui')('next'),
page: t('page'),
internalArticle: t('internalArticle'),
}}
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ProfileMenu } from '@/components/settings/ProfileMenu';
function Header() {
const t = useTranslations('layout');
return (
<header className='sticky top-0 z-10 flex w-full justify-center border-b border-border/40 bg-background/95 px-4 backdrop-blur supports-[backdrop-filter]:bg-background/60 sm:px-11 md:px-16 lg:px-24'>
<header className='sticky top-0 z-20 flex w-full justify-center border-b border-border/40 bg-background/95 px-4 backdrop-blur supports-[backdrop-filter]:bg-background/60 sm:px-11 md:px-16 lg:px-24'>
<div className='flex h-14 w-full max-w-screen-2xl items-center justify-between'>
<MobileSheet
className='flex md:hidden'
Expand Down
49 changes: 49 additions & 0 deletions src/components/news/InternalBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ShieldAlert } from 'lucide-react';

import { cx } from '@/lib/utils';

import { Button } from '@/components/ui/Button';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/Tooltip';

type InternalBadgeProps = {
className?: string;
internal: boolean;
t: {
internalArticle: string;
};
};

function InternalBadge({ className, internal, t }: InternalBadgeProps) {
if (!internal) return null;
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button
className={cx(
className,
'absolute z-10 m-1 bg-accent/95 p-0.5 backdrop-blur focus-visible:ring-offset-0 supports-[backdrop-filter]:bg-accent/60',
)}
asChild
variant='ghost'
size='xs-icon'
>
<span tabIndex={0}>
<ShieldAlert />
</span>
</Button>
</TooltipTrigger>
<TooltipContent sideOffset={3}>
<p>{t.internalArticle}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}

export { InternalBadge };
16 changes: 15 additions & 1 deletion src/components/news/NewsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Image from 'next/image';
import { Link } from '@/lib/navigation';
import { cx } from '@/lib/utils';

import { InternalBadge } from '@/components/news/InternalBadge';
import { Button } from '@/components/ui/Button';
import {
Card,
Expand All @@ -14,12 +15,24 @@ import {
type NewsCardProps = {
className?: string;
id: number;
internal: boolean;
title: string;
date: string;
photoUrl: string;
t: {
internalArticle: string;
};
};

function NewsCard({ className, id, title, date, photoUrl }: NewsCardProps) {
function NewsCard({
className,
id,
internal,
title,
date,
photoUrl,
t,
}: NewsCardProps) {
return (
<Button
className={cx('group whitespace-normal font-normal', className)}
Expand All @@ -34,6 +47,7 @@ function NewsCard({ className, id, title, date, photoUrl }: NewsCardProps) {
}}
>
<Card className='relative flex h-full min-h-32 w-full overflow-hidden'>
<InternalBadge internal={internal} t={t} />
<Image
className='rounded-lg object-cover object-center transition-transform duration-300 group-hover:scale-105'
src={`/${photoUrl}`}
Expand Down
16 changes: 15 additions & 1 deletion src/components/news/NewsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@ import Image from 'next/image';
import { Link } from '@/lib/navigation';
import { cx } from '@/lib/utils';

import { InternalBadge } from '@/components/news/InternalBadge';
import { Button } from '@/components/ui/Button';

type NewsCardProps = {
className?: string;
id: number;
internal: boolean;
title: string;
date: string;
photoUrl: string;
t: {
internalArticle: string;
};
};

function NewsItem({ className, id, title, date, photoUrl }: NewsCardProps) {
function NewsItem({
className,
id,
internal,
title,
date,
photoUrl,
t,
}: NewsCardProps) {
return (
<Button
className={cx('group block whitespace-normal font-normal', className)}
Expand All @@ -29,6 +42,7 @@ function NewsItem({ className, id, title, date, photoUrl }: NewsCardProps) {
>
<div className='flex gap-4 overflow-hidden rounded-lg transition-colors group-hover:bg-accent group-hover:dark:bg-card'>
<div className='relative h-28 w-28 flex-shrink-0'>
<InternalBadge className='h-5 w-5' internal={internal} t={t} />
<Image
className='rounded-lg object-cover object-center'
src={`/${photoUrl}`}
Expand Down
6 changes: 6 additions & 0 deletions src/components/news/NewsItemGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NewsItem } from '@/components/news/NewsItem';
type NewsItemGridProps = {
newsData: {
id: number;
internal: boolean;
title: string;
date: string;
photoUrl: string;
Expand All @@ -19,6 +20,7 @@ type NewsItemGridProps = {
previous: string;
next: string;
page: string;
internalArticle: string;
};
};

Expand All @@ -42,9 +44,13 @@ function NewsItemGrid({ newsData, t }: NewsItemGridProps) {
<NewsItem
key={data.id}
id={data.id}
internal={data.internal}
title={data.title}
date={data.date}
photoUrl={data.photoUrl}
t={{
internalArticle: t.internalArticle,
}}
/>
))}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/ui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const buttonVariants = cva({
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
'sm-icon': 'h-8 w-8',
'xs-icon': 'h-6 w-6',
none: '',
},
},
Expand Down
Loading

0 comments on commit a33d9cb

Please sign in to comment.