Skip to content

Commit

Permalink
Rework media preview style
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Nov 10, 2023
1 parent 5fb8328 commit 62d09d8
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<div class="row">
<div class="preview">
{#if $selectedAsset.kind === 'image'}
<Image asset={$selectedAsset} alt={$selectedAsset.name} checkerboard={true} />
<Image asset={$selectedAsset} blurBackground={true} alt={$selectedAsset.name} />
{:else if $selectedAsset.kind === 'video'}
<Video asset={$selectedAsset} controls />
<Video asset={$selectedAsset} blurBackground={true} controls />
{:else}
<EmptyState>
<span>{$_('no_preview_available')}</span>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/assets/list/asset-list-item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
* @type {Asset}
*/
export let asset;
/**
* @type {ViewType}
*/
export let viewType;
$: ({ name, kind } = asset);
</script>
Expand All @@ -34,10 +38,10 @@
</TableCell>
<TableCell class="image">
{#if kind === 'image'}
<Image {asset} checkerboard={true} />
<Image {asset} variant={viewType === 'list' ? 'icon' : 'tile'} />
{/if}
{#if kind === 'video'}
<Video {asset} />
<Video {asset} variant={viewType === 'list' ? 'icon' : 'tile'} />
{/if}
</TableCell>
<TableCell class="title">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/assets/list/asset-list.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{/if}
<svelte:component this={$currentView.type === 'list' ? BasicListView : BasicGridView}>
{#each assets as asset (asset.path)}
<AssetListItem {asset} />
<AssetListItem {asset} viewType={$currentView.type} />
{/each}
</svelte:component>
</Group>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/assets/shared/assets-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
{#each filteredAssets as asset (asset.path)}
<Option value={asset.sha}>
{#if asset.kind === 'image'}
<Image {asset} checkerboard={true} />
<Image {asset} variant="tile" />
{/if}
{#if asset.kind === 'video'}
<Video {asset} />
<Video {asset} variant="tile" />
{/if}
<span class="name">{asset.name}</span>
</Option>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/assets/shared/external-assets-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@
{#each searchResults as { id, previewURL, description, kind: _kind } (id)}
<Option value={id}>
{#if _kind === 'image'}
<Image src={previewURL} crossorigin="anonymous" />
<Image src={previewURL} variant="tile" crossorigin="anonymous" />
{/if}
{#if _kind === 'video'}
<Video src={previewURL} crossorigin="anonymous" />
<Video src={previewURL} variant="tile" crossorigin="anonymous" />
{/if}
<span class="name">{description}</span>
</Option>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/assets/shared/info-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
{#if showPreview && canPreview}
<div class="preview">
{#if kind === 'image'}
<Image {asset} checkerboard={true} />
<Image {asset} variant="tile" />
{/if}
{#if kind === 'video'}
<Video {asset} controls />
<Video {asset} variant="tile" controls />
{/if}
</div>
{/if}
Expand Down Expand Up @@ -168,6 +168,10 @@
margin: 0 0 16px;
}
h4 {
color: var(--sui-secondary-foreground-color);
}
h4,
p {
margin: 0 0 4px;
Expand Down
11 changes: 4 additions & 7 deletions src/lib/components/assets/shared/simple-image-grid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
height: auto;
transition: none;
:global(img),
:global(video) {
:global(.preview) {
flex: none;
border-radius: var(--sui-control-medium-border-radius);
aspect-ratio: 1 / 1;
Expand Down Expand Up @@ -58,8 +57,7 @@
:global(.option) {
:global(button) {
:global(img),
:global(video) {
:global(.preview) {
width: 100%;
}
Expand All @@ -76,9 +74,8 @@
:global(button) {
gap: 16px;
:global(img),
:global(video) {
width: 48px;
:global(.preview) {
width: 64px;
}
:global(.name) {
Expand Down
12 changes: 4 additions & 8 deletions src/lib/components/assets/shared/upload-assets-preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{@const [, extension = ''] = name.match(/\.([^.]+)$/) ?? []}
<div class="file">
{#if type.startsWith('image/')}
<Image src={URL.createObjectURL(file)} />
<Image src={URL.createObjectURL(file)} variant="icon" />
{:else}
<span class="image">
<Icon name="draft" />
Expand Down Expand Up @@ -58,19 +58,15 @@
align-items: center;
gap: 16px;
:global(img),
.image {
display: flex;
justify-content: center;
align-items: center;
width: 48px;
height: 48px;
aspect-ratio: 1 / 1;
object-fit: cover;
border-radius: var(--sui-control-medium-border-radius);
}
.image {
display: flex;
justify-content: center;
align-items: center;
background-color: var(--sui-tertiary-background-color);
}
Expand Down
35 changes: 14 additions & 21 deletions src/lib/components/common/basic-grid-view.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,43 @@
display: block;
position: relative;
overflow: hidden;
border-width: 1px;
border-style: solid;
border-color: var(--sui-secondary-border-color);
border-radius: var(--sui-control-medium-border-radius);
padding: 0;
height: auto;
aspect-ratio: 1 / 1;
text-align: left;
cursor: pointer;
&:focus-visible {
outline-color: transparent;
:global(.preview) {
outline-offset: -2px;
outline-width: 2px;
outline-style: solid;
outline-color: var(--sui-primary-accent-color-light);
}
}
:global(.table-cell) {
display: block;
position: absolute;
}
:global(.checkbox) {
inset: 16px auto auto 16px;
position: absolute;
inset: 8px auto auto 8px;
z-index: 2;
}
:global(.title) {
inset: auto 0 0 0;
z-index: 1;
padding: 16px 16px 16px 16px;
background-color: hsl(var(--sui-background-color-4-hsl) / 80%);
:global(span) {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
margin: 12px 8px 0;
height: 40px;
line-height: 1.5;
}
}
:global(.image) {
inset: 0;
z-index: 1;
}
}
:global([role='row'][aria-selected='true']) {
border-color: var(--sui-primary-accent-color);
}
}
</style>
13 changes: 1 addition & 12 deletions src/lib/components/common/basic-list-view.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,7 @@
}
:global([role='gridcell'].image) {
width: 32px;
:global(img) {
background-color: var(--sui-primary-accent-color-inverted);
}
:global(img),
:global(video) {
width: 32px;
height: 32px;
border-radius: var(--sui-control-medium-border-radius);
}
padding: 8px;
}
}
}
Expand Down
85 changes: 36 additions & 49 deletions src/lib/components/common/image.svelte
Original file line number Diff line number Diff line change
@@ -1,70 +1,57 @@
<script>
import { getAssetPreviewURL } from '$lib/services/assets/view';
import MediaPreview from '$lib/components/common/media-preview.svelte';
/**
* Loading method.
* @type {'lazy' | 'eager'}
*/
export let loading = 'lazy';
/**
* Asset.
* @type {Asset | undefined}
*/
export let asset = undefined;
/**
* Source URL.
* @type {string | undefined}
*/
export let src = undefined;
export let alt = '';
export let checkerboard = false;
/**
* Style variant.
* @type {'tile' | 'icon' | undefined}
*/
export let variant = undefined;
/**
* Whether to show a blurred background (like Slack’s media overlay).
* @type {boolean}
*/
export let blurBackground = false;
/**
* Whether to use `object-fit: cover`.
* @type {boolean}
*/
export let cover = false;
/**
* @type {HTMLImageElement}
* Whether to show a checkerboard background below a transparent image.
* @type {boolean}
*/
let element;
let updatingSrc = false;
export let checkerboard = true;
/**
* Update the {@link src} property.
* Alt text for the image.
* @type {string}
*/
const updateSrc = async () => {
if (asset && element && !updatingSrc) {
updatingSrc = true;
src = await getAssetPreviewURL(asset, loading, element);
updatingSrc = false;
}
};
$: {
void element;
void asset;
updateSrc();
}
export let alt = '';
</script>

<img class:checkerboard class:cover {loading} {src} {alt} {...$$restProps} bind:this={element} />

<style lang="scss">
img {
width: 100%;
height: 100%;
object-fit: contain;
background-color: var(--sui-tertiary-background-color);
&:not([src]) {
visibility: hidden;
}
&.cover {
object-fit: cover;
}
/* prettier-ignore */
&.checkerboard {
background-image:
linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
linear-gradient(45deg, #eee 25%, #fff 25%, #fff 75%, #eee 75%);
background-size: 16px 16px;
background-position: 0 0, 8px 8px;
}
}
</style>
<MediaPreview
type="image"
{loading}
{asset}
{src}
{variant}
{blurBackground}
{cover}
{checkerboard}
{alt}
{...$$restProps}
/>
Loading

0 comments on commit 62d09d8

Please sign in to comment.