Skip to content

Commit 8eb152e

Browse files
committed
make the entire card a link
1 parent e2e491c commit 8eb152e

File tree

1 file changed

+63
-58
lines changed

1 file changed

+63
-58
lines changed

apps/svelte.dev/src/routes/packages/PackageCard.svelte

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,65 @@
2020
</script>
2121

2222
<article data-pubdate={pkg.updated}>
23-
<header>
24-
{#snippet title()}
23+
{#snippet contents()}
24+
<header>
2525
<h3>
2626
{#if pkg.official}
2727
<span data-icon="svelte"></span>
2828
{/if}
2929

3030
<span>{pkg.name}</span>
3131
</h3>
32-
{/snippet}
33-
34-
{#if pkg.homepage}
35-
<a
36-
href={pkg.homepage}
37-
target="_blank"
38-
rel="noreferrer"
39-
aria-label="View project homepage"
40-
onclick={(e) => e.stopPropagation()}
41-
>
42-
{@render title()}
43-
</a>
44-
{:else}
45-
{@render title()}
46-
{/if}
47-
<span class="updated">
48-
{pkg.version}
49-
50-
<strong title={formatter.format(new Date(pkg.updated))}>
51-
{ago(new Date(pkg.updated), true)}
52-
</strong>
53-
</span>
54-
</header>
5532

56-
<p class="description">{pkg.description}</p>
33+
<span class="updated">
34+
{pkg.version}
5735

58-
<p class="stats">
59-
{#if pkg.downloads}
60-
<span title="{pkg.downloads} downloads">
61-
<span data-icon="download"></span>
62-
{format_number(+pkg.downloads)}
36+
<strong title={formatter.format(new Date(pkg.updated))}>
37+
{ago(new Date(pkg.updated), true)}
38+
</strong>
6339
</span>
64-
{/if}
40+
</header>
6541

66-
{#if pkg.github_stars}
67-
<span title="{pkg.github_stars} Github Stars">
68-
<span data-icon="star"></span>
69-
{format_number(pkg.github_stars)}
70-
</span>
71-
{/if}
42+
<p class="description">{pkg.description}</p>
7243

73-
<span style="flex: 1 1 auto"></span>
44+
<p class="stats">
45+
{#if pkg.downloads}
46+
<span title="{pkg.downloads} downloads">
47+
<span data-icon="download"></span>
48+
{format_number(+pkg.downloads)}
49+
</span>
50+
{/if}
51+
52+
{#if pkg.github_stars}
53+
<span title="{pkg.github_stars} Github Stars">
54+
<span data-icon="star"></span>
55+
{format_number(pkg.github_stars)}
56+
</span>
57+
{/if}
7458

59+
<span style="flex: 1 1 auto"></span>
60+
</p>
61+
{/snippet}
62+
63+
{#if pkg.homepage}
64+
<a
65+
class="contents"
66+
href={pkg.homepage}
67+
target={pkg.homepage.startsWith('/') ? null : '_blank'}
68+
rel="noreferrer"
69+
aria-label="View project homepage"
70+
onclick={(e) => e.stopPropagation()}
71+
>
72+
{@render contents()}
73+
</a>
74+
{:else}
75+
<div class="contents">
76+
{@render contents()}
77+
</div>
78+
{/if}
79+
80+
<!-- this is a sibling element so that we don't have links inside links -->
81+
<div class="links">
7582
<span style="display: flex; gap: 0.75rem">
7683
{#if !pkg.svAlias}
7784
<a
@@ -94,19 +101,8 @@
94101
onclick={(e) => e.stopPropagation()}
95102
></a>
96103
{/if}
97-
98-
{#if pkg.homepage}
99-
<a
100-
href={pkg.homepage}
101-
target="_blank"
102-
rel="noreferrer"
103-
data-icon="external-link"
104-
aria-label="View project homepage"
105-
onclick={(e) => e.stopPropagation()}
106-
></a>
107-
{/if}
108104
</span>
109-
</p>
105+
</div>
110106
</article>
111107

112108
<style>
@@ -136,17 +132,10 @@
136132
137133
article {
138134
display: grid;
139-
grid-template-rows: auto 1fr auto;
140-
box-sizing: border-box;
141-
142-
height: 100%;
143-
min-height: 0;
144-
145135
background-color: var(--sk-bg-1);
146136
147137
border-radius: var(--sk-border-radius);
148138
filter: drop-shadow(0.2rem 0.4rem 0.6rem rgb(0 0 0 / 0.07));
149-
padding: 1rem;
150139
151140
min-height: 16em;
152141
@@ -158,6 +147,22 @@
158147
filter: drop-shadow(0.3rem 0.5rem 0.7rem rgb(0 0 0 / 0.1));
159148
}
160149
150+
.contents {
151+
display: grid;
152+
grid-template-rows: auto 1fr auto;
153+
box-sizing: border-box;
154+
padding: 1rem;
155+
156+
height: 100%;
157+
min-height: 0;
158+
}
159+
160+
.links {
161+
position: absolute;
162+
right: 1rem;
163+
bottom: 1rem;
164+
}
165+
161166
a {
162167
display: block;
163168
text-decoration: none;

0 commit comments

Comments
 (0)