Files
fnx_web/svelte/src/filesystem/filemanager/GalleryView.svelte

126 lines
2.7 KiB
Svelte

<script lang="ts">
import { fs_node_icon, fs_node_type, fs_encode_path } from "lib/FilesystemAPI.svelte";
import { move_target, type FSNavigator } from "filesystem/FSNavigator";
import { FileAction, type FileActionHandler } from "./FileManagerLib";
let {
nav,
file_event,
show_hidden = false,
large_icons = false
}: {
nav: FSNavigator
file_event: FileActionHandler
show_hidden?: boolean
large_icons?: boolean
} = $props();
</script>
<div class="gallery">
{#each $nav.children as child, index (child.path)}
<a class="file"
href={"/d"+fs_encode_path(child.path)}
onclick={e => file_event(FileAction.Click, index, e)}
oncontextmenu={e => file_event(FileAction.Context, index, e)}
ondragstart={e => file_event(FileAction.Drag, index, e)}
use:move_target={{nav, node: () => child}}
class:selected={$nav.selection.has(child.path)}
class:hidden={child.name.startsWith(".") && !show_hidden}
class:large_icons
title={child.name}
>
<img
class="node_icon"
class:cover={fs_node_type(child) === "image" || fs_node_type(child) === "video"}
src={fs_node_icon(child, 256, 256)}
loading="lazy"
alt=""
draggable="false"
/>
<div class="node_name">
{child.name}
</div>
</a>
{/each}
</div>
<style>
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 10px;
justify-content: center;
}
.file {
aspect-ratio: 1;
width: 150px;
height: 150px;
/* Skips style, layout and paint for nodes which are off-screen. The
intrinsic size keeps the scrollbar accurate while they're skipped */
content-visibility: auto;
contain-intrinsic-size: auto 150px;
overflow: hidden;
background: var(--body_background);
border-radius: 4px;
color: var(--input_text);
display: flex;
flex-direction: column;
transition: background 0.2s;
text-decoration: none;
padding: 3px;
}
.file.large_icons {
width: 200px;
height: 200px;
contain-intrinsic-size: auto 200px;
}
/* On very small screens we switch to grid layout */
@media (max-width: 500px) {
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.file {
width: unset;
height: unset;
max-width: 200px;
max-height: 200px;
}
.file.large_icons {
width: unset;
height: unset;
}
}
.file:hover {
background: var(--input_hover_background);
}
.file.selected {
background: var(--accent_background);
color: var(--accent_text_color);
}
.node_icon {
flex: 1 1 0;
min-height: 0;
width: 100%;
border-radius: 4px;
object-fit: contain;
}
.node_icon.cover {
object-fit: cover;
}
.node_name {
flex: 0 0 auto;
word-break: break-all;
line-clamp: 2;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.hidden {
display: none;
}
</style>