-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
cb03639
commit 03e52ca
Showing
7 changed files
with
152 additions
and
61 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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Tooltip } from 'lib/lemon-ui/Tooltip' | ||
|
||
import { ElementType } from '~/types' | ||
|
||
export function autocaptureToImage( | ||
elements: ElementType[] | ||
): null | { src: string | undefined; width: string | undefined; height: string | undefined } { | ||
const find = elements.find((el) => el.tag_name === 'img') | ||
const image = { | ||
src: find?.attributes?.attr__src, | ||
width: find?.attributes?.attr__width, | ||
height: find?.attributes?.attr__height, | ||
} | ||
return image.src ? image : null | ||
} | ||
|
||
export function AutocaptureImageTab({ elements }: { elements: ElementType[] }): JSX.Element | null { | ||
const img = autocaptureToImage(elements) | ||
if (img) { | ||
return ( | ||
<div className="flex bg-bg-3000 items-center justify-center relative border-2"> | ||
{/* Transparent grid background */} | ||
<div className="ImagePreview__background absolute h-full w-full" /> | ||
|
||
<img | ||
className="relative z-10 max-h-100 object-contain" | ||
src={img.src} | ||
alt="Autocapture image src" | ||
height={img.height || 'auto'} | ||
width={img.width || 'auto'} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
return null | ||
} | ||
|
||
export function AutocapturePreviewImage({ | ||
elements, | ||
imgPreviewHeight = '40', | ||
}: { | ||
elements: ElementType[] | ||
imgPreviewHeight?: string | ||
}): JSX.Element | null { | ||
const img = autocaptureToImage(elements) | ||
if (img) { | ||
return ( | ||
<Tooltip title={<AutocaptureImageTab elements={elements} />}> | ||
<img | ||
className="max-h-10" | ||
src={img.src} | ||
alt="Autocapture image src" | ||
height={imgPreviewHeight} | ||
width="auto" | ||
/> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
return null | ||
} |
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