-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Table): restrict media column to image column
- Loading branch information
1 parent
d9d5a15
commit f73d635
Showing
9 changed files
with
125 additions
and
77 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
79 changes: 79 additions & 0 deletions
79
packages/visualizations/src/components/Table/Cell/Format/ImageFormat.svelte
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,79 @@ | ||
<script lang="ts"> | ||
import type { Instance } from 'tippy.js'; | ||
import tippy from '../../../utils/tippy'; | ||
import { warn } from './utils'; | ||
export let rawValue: string; | ||
export let display = (v: string) => v; | ||
export let alt: (v: string) => string = () => ''; | ||
export let loadingContent: (v: string) => string = () => 'Loading...'; | ||
export let errorContent: (v: string) => string = () => 'Error while fetching image'; | ||
let tooltipContent: Element; | ||
let image: HTMLImageElement | null = null; | ||
let imageLoaded = false; | ||
let hasError = false; | ||
async function loadImage(tippyInstance: Instance) { | ||
if (image !== null || hasError) return; | ||
image = new Image(); | ||
image.src = rawValue; | ||
try { | ||
await image.decode(); | ||
image.alt = alt(rawValue); | ||
image.classList.add('ods-visualization-table__image'); | ||
imageLoaded = true; | ||
} catch (error) { | ||
warn(rawValue, 'Image'); | ||
hasError = true; | ||
} | ||
tippyInstance.setContent(tooltipContent); | ||
} | ||
</script> | ||
|
||
<div | ||
role="button" | ||
tabindex="0" | ||
use:tippy={{ | ||
content: tooltipContent, | ||
theme: 'ods-visualization-table', | ||
delay: [500, 0], | ||
duration: [275, 0], | ||
maxWidth: 'none', | ||
onTrigger(instance) { | ||
loadImage(instance); | ||
}, | ||
}} | ||
> | ||
<div class="ods-visualization-table__image-label">{display(rawValue)}</div> | ||
<div bind:this={tooltipContent}> | ||
{#if imageLoaded} | ||
{@html image?.outerHTML} | ||
{:else if hasError} | ||
<div class="ods-visualization-table__image-error-container"> | ||
{@html errorContent(rawValue)} | ||
</div> | ||
{:else} | ||
<div class="ods-visualization-table__image-loading-container"> | ||
{@html loadingContent(rawValue)} | ||
</div> | ||
{/if} | ||
</div> | ||
</div> | ||
|
||
<style lang="scss"> | ||
div[role='button'] { | ||
display: inline-block; | ||
} | ||
.ods-visualization-table__image-label { | ||
cursor: pointer; | ||
text-decoration: underline; | ||
} | ||
:global(.ods-visualization-table__image) { | ||
object-fit: contain; | ||
border-radius: 3px; | ||
width: 360px; | ||
height: 240px; | ||
} | ||
</style> |
59 changes: 0 additions & 59 deletions
59
packages/visualizations/src/components/Table/Cell/Format/MediaFormat.svelte
This file was deleted.
Oops, something went wrong.
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