Skip to content
All components FileList

FileList

On this page

A list of files, each with an extension badge, its name, its size and its date (KlyFileList), and the overlay that previews them (KlyFilePreviewProvider, driven through FilePreviewService). A click on a file opens the whole list as a gallery at that file, once a KlyFilePreviewProvider is mounted and the page is interactive. Otherwise the name is a plain link to Src.

Examples

Rows with a description, meta and icon

A FileListItem is a FilePreviewFile plus a Description under the name, a Meta text at the end of the row (the date of the file when it is not set), an Icon shown in the badge instead of the extension and a Tone color for the badge. A FilePreviewFile converts to an item on its own, as the last entry does. CSV, Markdown and text files are previewed from Content, and an image or a PDF from Src. The layout of this site mounts the KlyFilePreviewProvider, so the example does not mount a second one: two providers would draw the overlay twice.

Attachments

Razor
<KlyFileList Title="Attachments" Files="_files" />

@code {
    private const string Notes = "# Release notes\n\nVersion **0.2** highlights code in thirteen languages.\n\n- Line numbers\n- Emphasized lines\n";
    private const string Metrics = "Region,Revenue,Orders\nEurope,148900,1204\nUS,192400,1788\nAsia,98750,901\n";

    private readonly IReadOnlyList<FileListItem> _files =
    [
        new FileListItem(new FilePreviewFile { Src = "/files/notes.md", Name = "notes.md", Size = 2_480, Content = Notes },
            Description: "Release notes", Icon: "note", Tone: KlyColor.Info),
        new FileListItem(new FilePreviewFile { Src = "/files/metrics.csv", Name = "metrics.csv", Size = 18_400, Content = Metrics },
            Meta: "Updated today"),
        new FileListItem(new FilePreviewFile { Src = DisplayDemo.ImageSrc, Name = "logo.svg", Mime = "image/svg+xml", Size = 3_200 },
            Description: "Zoom and rotate", Tone: KlyColor.Secondary),
        // A FilePreviewFile converts to an item on its own: the badge is the extension, the name the last segment of Src.
        new FilePreviewFile { Src = "/files/report.pdf", Size = 183_204 },
    ];
}

Max and Step

Max sets how many files show first and Step how many each click on Show more adds. Without Step one click shows everything. The gallery that a click opens always holds the whole list, hidden files included, and the reveal state lives in the component.

Documents, 3 shown, 2 more per click

Razor
<KlyFileList Title="Documents, 3 shown, 2 more per click" Files="_files" Max="3" Step="2" />

@code {
    private readonly IReadOnlyList<FileListItem> _files =
    [
        .. Enumerable.Range(1, 8).Select(n => (FileListItem)new FilePreviewFile
        {
            Src = $"/files/document-{n}.pdf",
            Name = $"document-{n}.pdf",
            Size = n * 41_000,
        }),
    ];
}

Open the preview from code

FilePreviewService.Open and OpenGallery only change state, and nothing appears until a KlyFilePreviewProvider is mounted: place one in your layout, once (the layout of this site has it). Options takes the Index of the file shown first, a Loop that makes Previous and Next wrap around, and a container Mode, which defaults to one chosen from the kinds of the files. The overlay responds to Escape, the arrow keys, Home and End. Statically rendered the buttons do nothing.

Razor
@inject FilePreviewService Preview

<div class="flex flex-wrap gap-2">
    <KlyButton Label="Open a gallery" OnClick="OpenGallery" />
    <KlyButton Label="Open one file" Variant="ButtonVariant.Outline" OnClick="OpenOne" />
</div>

@code {
    private static readonly FilePreviewFile _notes = new()
    {
        Src = "/files/notes.md",
        Name = "notes.md",
        Content = "# Q3 notes\n\nRevenue grew in **both** regions.",
        Details = [new FilePreviewDetail("Owner", "Finance team")],
    };

    private static readonly FilePreviewFile _metrics = new()
    {
        Src = "/files/metrics.csv",
        Name = "metrics.csv",
        Content = "Region,Revenue\nEurope,148900\nUS,192400",
    };

    private static readonly FilePreviewFile _logo = new() { Src = DisplayDemo.ImageSrc, Name = "logo.svg", Mime = "image/svg+xml" };

    private void OpenGallery() =>
        Preview.OpenGallery([_notes, _metrics, _logo], new FilePreviewOptions { Index = 1, Loop = true });

    private void OpenOne() => Preview.Open(_logo);
}

API

KlyFileList

A list of files, each with an extension badge, its name, its size and its date. Clicking a file opens the whole list as a gallery in the file preview, at that file, when a KlyFilePreviewProvider is mounted and the page is interactive. Otherwise the name is a plain link to the file.

Parameters

Name Type Description
Class string Classes added to the root element, merged last so they win over the theme.
Files IReadOnlyList<FileListItem> The files to list, in order. A FilePreviewFile converts to an item by itself. A row shows the badge (the extension, or the item Icon ), the name (or the last segment of Src ), the description and the size, and the item Meta or the date of the file.
Max int? The number of files shown before a Show more button (all files when null ).
Step int? The number of files each click on Show more reveals (all remaining files when null ).
Title string A title above the list.
Ui FileListUi Per-instance class overrides of the slots of the list, see FileListUi . They are merged after the theme, and Class wins on the root slot.

Ui slots

Ui takes a FileListUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyFileList , after the theme and the app configuration.
Title Classes merged into the title slot of KlyFileList , after the theme and the app configuration.
List Classes merged into the list slot of KlyFileList , after the theme and the app configuration.
Item Classes merged into the item slot of KlyFileList , after the theme and the app configuration.
Main Classes merged into the main slot of KlyFileList , after the theme and the app configuration.
Badge Classes merged into the badge slot of KlyFileList , after the theme and the app configuration.
BadgeIdle Classes merged into the badgeIdle slot of KlyFileList , after the theme and the app configuration.
BadgeTone Classes merged into the badgeTone slot of KlyFileList , after the theme and the app configuration.
BadgeIcon Classes merged into the badgeIcon slot of KlyFileList , after the theme and the app configuration.
Body Classes merged into the body slot of KlyFileList , after the theme and the app configuration.
Name Classes merged into the name slot of KlyFileList , after the theme and the app configuration.
Description Classes merged into the description slot of KlyFileList , after the theme and the app configuration.
Meta Classes merged into the meta slot of KlyFileList , after the theme and the app configuration.
More Classes merged into the more slot of KlyFileList , after the theme and the app configuration.
MoreIcon Classes merged into the moreIcon slot of KlyFileList , after the theme and the app configuration.

KlyFilePreviewProvider

Renders the file preview overlay that FilePreviewService opens: a dialog, drawer or fullscreen panel with a header (name, kind, size, zoom and rotate for images, custom actions, details, download, close), a stage that renders the file, a rendition notice, and a strip of thumbnails for galleries. Place one provider in your layout, once.

Parameters

Name Type Description
Class string Classes added to the root element, merged last so they win over the theme.
MarkdownRenderer Func<string, string> Converts the Markdown of a file to HTML. The result is rendered as markup without sanitizing, so use a renderer that escapes untrusted input. When null , Markdown files are shown as source.

Slots

Name Type Description
ChildContent RenderFragment Content rendered before the overlay. Use it to wrap your layout, or leave it empty and place the provider next to it.