-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathExamplesPagePreview.svelte
More file actions
148 lines (132 loc) · 3.97 KB
/
Copy pathExamplesPagePreview.svelte
File metadata and controls
148 lines (132 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<script lang="ts">
import { resolve } from '$app/paths';
import { useDark } from '$shared/ui';
import { flip } from 'svelte/animate';
const exampleImages = import.meta.glob('../../snapshots/*/*.png', {
eager: true,
query: {
enhanced: true,
w: 440
}
});
let {
paths,
pages
}: {
paths: Record<string, string[]>;
pages: Record<
string,
{
title: string;
description?: string;
sortKey?: number;
transforms?: string[];
}
>;
} = $props();
const ds = useDark();
function sortPages(a: string, b: string) {
const sortA = pages[a].sortKey ?? 10;
const sortB = pages[b].sortKey ?? 10;
return sortA - sortB;
}
</script>
<div class="column-container">
{#each Object.entries(paths).sort( (a, b) => a[0].localeCompare(b[0]) ) as [group, groupPages] (group)}
<div>
<h2 id={group}>
<a href={resolve(`/examples/${group}`)}
>{pages[groupPages.find((p) => p.endsWith('/_index.svelte')) ?? '']?.title ??
group}</a>
</h2>
<div class="example-grid">
{#each groupPages
.sort(sortPages)
.filter((p) => !p.endsWith('/_index.svelte')) as page (page)}
{@const imageKey = `../../snapshots/${page
.replace('./', '')
.replace('.svelte', ds.isDark ? '.dark.png' : '.png')}`}
<a
animate:flip
href={resolve(
page.replace('./', './examples/').replace('.svelte', '') as any
)}
><div>
{#if exampleImages[imageKey]}
<enhanced:img
title={pages[page].title}
src={(exampleImages[imageKey] as any).default}
alt={pages[page].title} />
{/if}
<div class="title">{pages[page].title}</div>
</div></a>
{/each}
</div>
</div>
{/each}
</div>
<style>
:global(.content) h2 {
margin-top: 1rem !important;
margin-bottom: 1rem;
text-transform: capitalize;
border: 0;
a {
text-decoration: none;
color: inherit;
}
}
.column-container {
container-type: inline-size;
}
.example-grid {
--example-grid-columns: 5;
/* width: 100%; */
display: grid;
/* overflow-x: clip; */
grid-template-columns: repeat(var(--example-grid-columns), 1fr);
grid-auto-rows: 1fr;
gap: 1.25rem;
a {
text-decoration: none;
color: inherit;
}
.title {
font-size: 0.75rem;
opacity: 0.8;
line-height: 1.2;
text-decoration: none;
}
}
@container (max-width: 800px) {
.example-grid {
--example-grid-columns: 4;
}
}
@container (max-width: 600px) {
.example-grid {
--example-grid-columns: 3;
}
}
@container (max-width: 500px) {
.example-grid {
--example-grid-columns: 2;
}
}
.example-grid :global(img) {
height: auto !important;
aspect-ratio: 4 / 3;
object-fit: cover;
width: 100%;
height: auto;
position: relative;
transition: transform 0.05s ease-out;
&:hover {
transform: scale(1.5);
object-fit: contain;
z-index: 1;
background: fixed var(--svelteplot-bg);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
}
</style>