Skip to content

Commit f783a19

Browse files
committed
use <details>
1 parent c78510e commit f783a19

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

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

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import type { Package } from '$lib/server/content';
3-
import { fix_position } from '../../../../../packages/site-kit/src/lib/actions/utils';
43
import PackageCard from './PackageCard.svelte';
54
65
interface Props {
@@ -11,58 +10,47 @@
1110
1211
let { title, description, packages }: Props = $props();
1312
14-
let header: HTMLElement;
15-
1613
const INITIAL_ITEMS = 3;
1714
let showAll = $state(false);
18-
let visiblePackages = $derived(showAll ? packages : packages.slice(0, INITIAL_ITEMS));
1915
</script>
2016

2117
<section class="category">
2218
<header>
23-
<h2 bind:this={header}>
24-
{title}
25-
</h2>
19+
<h2>{title}</h2>
2620

2721
{#if description}
2822
<p>{@html description}</p>
2923
{/if}
3024
</header>
3125

32-
<div class="content">
33-
{#each visiblePackages as pkg}
26+
<div class="grid">
27+
{#each packages.slice(0, INITIAL_ITEMS) as pkg}
3428
<div class="item">
3529
<PackageCard {pkg} />
3630
</div>
3731
{/each}
3832
</div>
3933

4034
{#if packages.length > INITIAL_ITEMS}
41-
<div class="show-more-container">
42-
<label>
43-
<button
44-
class="raised"
45-
aria-label="Show more"
46-
aria-pressed={showAll}
47-
onclick={(e) => {
48-
const { bottom } = header.getBoundingClientRect();
49-
50-
// if the current section is wholly visible, don't muck about with the scroll position
51-
if (!showAll || bottom > 0) {
52-
showAll = !showAll;
53-
return;
54-
}
55-
56-
// otherwise, keep the button in the same position
57-
fix_position(e.currentTarget, () => {
58-
showAll = !showAll;
59-
});
60-
}}><span class="icon"></span></button
61-
>
62-
63-
{showAll ? 'show less' : `show all (${packages.length})`}
64-
</label>
65-
</div>
35+
<details>
36+
<summary>
37+
<span class="raised button" aria-label="Toggle">
38+
<span class="icon"></span>
39+
</span>
40+
41+
<span>
42+
{showAll ? 'show less' : `show all (${packages.length})`}
43+
</span>
44+
</summary>
45+
46+
<div class="grid">
47+
{#each packages.slice(INITIAL_ITEMS) as pkg}
48+
<div class="item">
49+
<PackageCard {pkg} />
50+
</div>
51+
{/each}
52+
</div>
53+
</details>
6654
{/if}
6755
</section>
6856

@@ -83,17 +71,43 @@
8371
}
8472
}
8573
86-
.content {
74+
.grid {
8775
display: grid;
8876
grid-template-columns: 1fr;
8977
gap: 2rem;
90-
margin-top: 1rem;
9178
9279
@media (min-width: 1024px) {
9380
grid-template-columns: repeat(3, 1fr);
9481
}
9582
}
9683
84+
details {
85+
position: relative;
86+
margin-bottom: 9rem;
87+
88+
.grid {
89+
margin-top: 2rem;
90+
}
91+
}
92+
93+
summary {
94+
position: absolute;
95+
bottom: -6rem;
96+
font: var(--sk-font-ui-small);
97+
display: flex;
98+
align-items: center;
99+
gap: 1rem;
100+
101+
.icon {
102+
mask-size: 2rem;
103+
mask-image: url(icons/plus);
104+
105+
[open] & {
106+
mask-image: url(icons/minus);
107+
}
108+
}
109+
}
110+
97111
.item {
98112
height: 16rem;
99113
min-width: 0; /* Prevents grid items from overflowing */

packages/site-kit/src/lib/styles/utils/buttons.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868

6969
button.icon,
7070
summary.icon,
71-
button:has(> span.icon) {
71+
button:has(> span.icon),
72+
.button:has(> span.icon) {
7273
position: relative;
7374
width: 3.2rem;
7475
height: 3.2rem;
@@ -77,6 +78,7 @@ button:has(> span.icon) {
7778
background-size: 2.3rem 2.3rem;
7879
}
7980

81+
.button > span.icon,
8082
button > span.icon {
8183
position: absolute;
8284
left: 0;

0 commit comments

Comments
 (0)