-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2315081
commit 38ad4ce
Showing
6 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 19 additions & 16 deletions
35
frontend/packages/data-portal/app/components/KeyPhoto.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,36 @@ | ||
import Skeleton from '@mui/material/Skeleton' | ||
import { match, P } from 'ts-pattern' | ||
|
||
import { useIsLoading } from 'app/hooks/useIsLoading' | ||
import { i18n } from 'app/i18n' | ||
import { cns } from 'app/utils/cns' | ||
|
||
export function KeyPhoto({ src, title }: { src?: string; title: string }) { | ||
const { isLoadingDebounced } = useIsLoading() | ||
const containerClassName = | ||
'!min-w-[134px] !max-w-[134px] !min-h-[100px] !max-h-[100px]' | ||
|
||
if (isLoadingDebounced) { | ||
return <Skeleton className={containerClassName} variant="rounded" /> | ||
} | ||
|
||
export function KeyPhoto({ | ||
loading, | ||
src, | ||
title, | ||
}: { | ||
loading?: boolean | ||
src?: string | ||
title: string | ||
}) { | ||
return ( | ||
<div | ||
className={cns( | ||
containerClassName, | ||
'!min-w-[134px] !max-w-[134px] !min-h-[100px] !max-h-[100px]', | ||
'flex items-center justify-center bg-[#d9d9d9]', | ||
|
||
// crop image to container dimensions | ||
'overflow-hidden object-cover', | ||
)} | ||
> | ||
{src ? ( | ||
<img alt={`key visualization for ${title}`} src={src} /> | ||
) : ( | ||
<p className="text-sds-gray-400 text-sm">{i18n.keyPhoto}</p> | ||
)} | ||
{match([src, loading]) | ||
.with([P._, true], () => <Skeleton variant="rounded" />) | ||
.with([P.string, false], () => ( | ||
<img alt={`key visualization for ${title}`} src={src} /> | ||
)) | ||
.otherwise(() => ( | ||
<p className="text-sds-gray-400 text-sm">{i18n.keyPhoto}</p> | ||
))} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters