Skip to content

Commit a21797a

Browse files
committed
Add icon option to collection file
1 parent 4c8268e commit a21797a

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/lib/components/assets/list/primary-sidebar.svelte

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
} from '$lib/services/assets';
1414
import { getFolderLabelByCollection } from '$lib/services/assets/view';
1515
import { getCollection, getCollectionIndex } from '$lib/services/contents/collection';
16-
import { getCollectionFileIndex } from '$lib/services/contents/collection/files';
16+
import {
17+
getCollectionFile,
18+
getCollectionFileIndex,
19+
} from '$lib/services/contents/collection/files';
1720
import { isSmallScreen } from '$lib/services/user/env';
1821
1922
const numberFormatter = $derived(Intl.NumberFormat($appLocale ?? undefined));
@@ -45,8 +48,11 @@
4548
<OptionGroup label={$_('asset_location.repository')}>
4649
{#each folders as folder ([folder.collectionName, folder.fileName, folder.internalPath].join(':'))}
4750
{#await sleep() then}
48-
{@const { collectionName, internalPath, entryRelative, hasTemplateTags } = folder}
51+
{@const { collectionName, fileName, internalPath, entryRelative, hasTemplateTags } =
52+
folder}
4953
{@const collection = collectionName ? getCollection(collectionName) : undefined}
54+
{@const collectionFile =
55+
collection && fileName ? getCollectionFile(collection, fileName) : undefined}
5056
<!-- Can’t upload assets if collection assets are saved at entry-relative paths -->
5157
{@const uploadDisabled = entryRelative || hasTemplateTags}
5258
{@const selected = equal($selectedAssetFolder, folder)}
@@ -107,7 +113,7 @@
107113
}}
108114
>
109115
{#snippet startIcon()}
110-
<Icon name={collection?.icon || 'folder'} />
116+
<Icon name={collectionFile?.icon || collection?.icon || 'folder'} />
111117
{/snippet}
112118
{#snippet endIcon()}
113119
{#key $allAssets}

src/lib/components/common/list-container.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
<style lang="scss">
2828
.list-container {
29+
--icon-size: 36px;
30+
2931
flex: auto;
3032
position: relative;
3133
height: 100%;

src/lib/components/common/listing-grid.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@
119119
}
120120
121121
.list-view {
122-
--icon-size: 36px;
123-
124122
@media (width < 768px) {
125123
padding: 0;
126124
}

src/lib/components/contents/list/file-list.svelte

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { EmptyState, GridCell, GridRow, InfiniteScroll, TruncatedText } from '@sveltia/ui';
2+
import { EmptyState, GridCell, GridRow, Icon, InfiniteScroll, TruncatedText } from '@sveltia/ui';
33
import { sleep } from '@sveltia/utils/misc';
44
import { _ } from 'svelte-i18n';
55
import ListContainer from '$lib/components/common/list-container.svelte';
@@ -20,7 +20,7 @@
2020
aria-rowcount={$selectedCollection.files.length}
2121
>
2222
<InfiniteScroll items={$selectedCollection.files} itemKey="name">
23-
{#snippet renderItem(/** @type {CollectionFile} */ { name, label })}
23+
{#snippet renderItem(/** @type {CollectionFile} */ { name, label, icon })}
2424
{#await sleep() then}
2525
<GridRow
2626
onclick={() => {
@@ -31,6 +31,9 @@
3131
>
3232
<GridCell class="title">
3333
<div role="none" class="label">
34+
{#if icon}
35+
<Icon name={icon} />
36+
{/if}
3437
<TruncatedText lines={2}>
3538
{label || name}
3639
</TruncatedText>
@@ -47,3 +50,21 @@
4750
</EmptyState>
4851
{/if}
4952
</ListContainer>
53+
54+
<style lang="scss">
55+
.label {
56+
display: flex;
57+
align-items: center;
58+
gap: 16px;
59+
60+
:global(.icon) {
61+
display: flex;
62+
align-items: center;
63+
justify-content: center;
64+
border-radius: var(--sui-control-medium-border-radius);
65+
width: var(--icon-size);
66+
height: var(--icon-size);
67+
background-color: var(--sui-secondary-background-color);
68+
}
69+
}
70+
</style>

src/lib/types/public.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@
721721
* @typedef {object} CollectionFile
722722
* @property {string} name Unique identifier for the file.
723723
* @property {string} [label] Label to be displayed in the editor UI. Default: `name` option value.
724+
* @property {string} [icon] Name of a Material Symbols icon to be displayed in the collection file
725+
* list and other places.
724726
* @property {string} file File path relative to the project root.
725727
* @property {Field[]} fields Set of fields to be included in the file.
726728
* @property {string} [media_folder] Internal media folder path for the collection. This overrides

0 commit comments

Comments
 (0)