Files
lucent-laravel/front/js/svelte/files/Preview.svelte
T

77 lines
2.1 KiB
Svelte
Raw Normal View History

2023-10-02 23:10:49 +03:00
<script>
import Icon from "../common/Icon.svelte";
2026-05-05 19:21:59 +03:00
import { imgurl } from "./imageserver.js";
import { getContext } from "svelte";
2023-10-04 13:32:30 +03:00
2026-05-05 19:21:59 +03:00
export let file;
2023-10-02 23:10:49 +03:00
const channel = getContext("channel");
export let size = "small";
export let showFilename = false;
let imageSide;
let fileSide;
let fontSize;
if (size == "large") {
imageSide = 256;
fileSide = 32;
fontSize = "20";
} else if (size == "medium") {
imageSide = 128;
fileSide = 12;
fontSize = "17";
} else if (size == "small") {
imageSide = 64;
fileSide = 12;
fontSize = "15";
} else if (size == "tiny") {
imageSide = 42;
fileSide = 12;
fontSize = "13";
}
</script>
2026-05-05 19:21:59 +03:00
<div style="display: flex;align-items: center;gap: 5px;">
{#if file}
{#if file.mime.startsWith("image")}
2024-08-15 14:44:53 +03:00
<!-- href={imgurl(record)} -->
<a
2026-05-05 19:21:59 +03:00
href="{channel.lucentUrl}/files/{file.id}"
title={file.filename}
style="width:{imageSide}px;height:{imageSide}px"
2024-08-15 14:44:53 +03:00
>
<img
2026-05-05 19:21:59 +03:00
class="rounded w-100"
src={imgurl(channel, file)}
alt={file.path}
2024-08-15 14:44:53 +03:00
/>
</a>
{:else}
<a
2026-05-05 19:21:59 +03:00
href="{channel.lucentUrl}/files/{file.id}"
title={file.path}
class="file-preview-small"
style="width:{imageSide}px;height:{imageSide}px"
2024-08-15 14:44:53 +03:00
>
2026-05-05 19:21:59 +03:00
<Icon icon="file" width={fileSide} height={fileSide} />
2024-08-15 14:44:53 +03:00
<span class="ms-2"
2026-05-05 19:21:59 +03:00
>.{file.path.split(".").pop().toLowerCase()}</span
2024-08-15 14:44:53 +03:00
>
</a>
{/if}
{/if}
{#if showFilename}
2023-10-02 23:10:49 +03:00
<a
2026-05-05 19:21:59 +03:00
href="{channel.lucentUrl}/files/{file.id}"
title={file.path}
class="preview-file-filename lx-small-text text-decoration-none"
>{file.path}
</a>
2023-10-02 23:10:49 +03:00
{/if}
2024-08-15 14:44:53 +03:00
</div>
<style>
2026-05-05 19:21:59 +03:00
img {
2024-08-15 14:44:53 +03:00
border-radius: 12px;
padding: 4px;
}
2026-05-05 19:21:59 +03:00
</style>