|
1 | 1 | <script lang="ts"> |
2 | 2 | import type { Package } from '$lib/server/content'; |
3 | | - import { prefersReducedMotion } from 'svelte/motion'; |
4 | 3 | import PackageCard from './PackageCard.svelte'; |
5 | 4 |
|
6 | 5 | interface Props { |
|
10 | 9 | } |
11 | 10 |
|
12 | 11 | let { title, description, packages }: Props = $props(); |
13 | | -
|
14 | | - let content: HTMLElement; |
15 | | - let scroller: HTMLElement; |
16 | | -
|
17 | | - let behavior = $derived<ScrollBehavior>(prefersReducedMotion.current ? 'instant' : 'smooth'); |
18 | | -
|
19 | | - let at_start = $state(true); |
20 | | - let at_end = $state(true); |
21 | | -
|
22 | | - function update() { |
23 | | - at_start = scroller.scrollLeft === 0; |
24 | | - at_end = scroller.scrollLeft + scroller.offsetWidth >= scroller.scrollWidth; |
25 | | - } |
26 | | -
|
27 | | - function go(d: number) { |
28 | | - const [a, b] = scroller.querySelectorAll('.item') as NodeListOf<HTMLElement>; |
29 | | - const left = scroller.scrollLeft + d * (b.offsetLeft - a.offsetLeft); |
30 | | -
|
31 | | - scroller.scrollTo({ left, behavior }); |
32 | | - } |
33 | | -
|
34 | | - $effect(update); |
35 | 12 | </script> |
36 | 13 |
|
37 | | -<svelte:window onresize={update} /> |
38 | | - |
39 | 14 | <section class="category"> |
40 | 15 | <header> |
41 | | - <h2> |
42 | | - {title} |
43 | | - </h2> |
44 | | - |
45 | | - {#if !at_start || !at_end} |
46 | | - <div class="controls"> |
47 | | - <button disabled={at_start} aria-label="Previous" class="raised icon" onclick={() => go(-1)} |
48 | | - ></button> |
49 | | - |
50 | | - <button disabled={at_end} aria-label="Next" class="raised icon" onclick={() => go(1)} |
51 | | - ></button> |
52 | | - </div> |
53 | | - {/if} |
| 16 | + <h2>{title}</h2> |
54 | 17 | </header> |
55 | 18 | {#if description} |
56 | 19 | <h3>{@html description}</h3> |
57 | 20 | {/if} |
58 | 21 |
|
59 | | - <div class="wrapper"> |
60 | | - <!-- we duplicate the DOM for the sake of the gradient effect - |
61 | | - without this, the scrollbar extends beyond the content area --> |
62 | | - <div inert class="viewport"> |
63 | | - <div bind:this={content} class="content"> |
64 | | - {#each packages as pkg} |
65 | | - <div class="item"> |
66 | | - <PackageCard {pkg} /> |
67 | | - </div> |
68 | | - {/each} |
69 | | - </div> |
70 | | - </div> |
71 | | - |
72 | | - <div |
73 | | - bind:this={scroller} |
74 | | - class="viewport" |
75 | | - onscroll={(e) => { |
76 | | - const left = e.currentTarget.scrollLeft; |
77 | | - content.style.translate = `-${left}px`; |
78 | | - |
79 | | - update(); |
80 | | - }} |
81 | | - > |
82 | | - <div class="content"> |
83 | | - {#each packages as pkg} |
84 | | - <div class="item"> |
85 | | - <PackageCard {pkg} /> |
86 | | - </div> |
87 | | - {/each} |
88 | | - </div> |
89 | | - </div> |
| 22 | + <div class="content"> |
| 23 | + {#each packages as pkg} |
| 24 | + <PackageCard {pkg} /> |
| 25 | + {/each} |
90 | 26 | </div> |
91 | 27 | </section> |
92 | 28 |
|
|
97 | 33 | } |
98 | 34 |
|
99 | 35 | header { |
100 | | - display: flex; |
101 | 36 | margin-bottom: 1rem; |
102 | | - align-items: center; |
103 | | - gap: 2rem; |
104 | 37 |
|
105 | 38 | h2 { |
106 | | - flex: 1; |
107 | | - } |
108 | | -
|
109 | | - .controls { |
110 | | - display: flex; |
111 | | - gap: 0.5rem; |
112 | | - } |
113 | | -
|
114 | | - button { |
115 | | - background: var(--sk-bg-3); |
116 | | -
|
117 | | - &::after { |
118 | | - content: ''; |
119 | | - position: absolute; |
120 | | - width: 100%; |
121 | | - height: 100%; |
122 | | - top: 0; |
123 | | - left: 0; |
124 | | - background: currentColor; |
125 | | - mask: url(icons/chevron) 50% 50% no-repeat; |
126 | | - mask-size: 2rem 2rem; |
127 | | - } |
128 | | -
|
129 | | - &[aria-label='Next']::after { |
130 | | - rotate: 180deg; |
131 | | - } |
132 | | -
|
133 | | - &:disabled { |
134 | | - background: none; |
135 | | - } |
| 39 | + margin: 0; |
136 | 40 | } |
137 | 41 | } |
138 | 42 |
|
139 | 43 | h3 { |
140 | 44 | font: var(--sk-font-ui-medium); |
141 | 45 | font-size: 1.5rem; |
142 | | - } |
143 | | -
|
144 | | - .wrapper { |
145 | | - position: relative; |
146 | | - } |
147 | | -
|
148 | | - .viewport { |
149 | | - overscroll-behavior-x: contain; |
150 | | - overscroll-behavior-y: auto; |
151 | | - scroll-snap-type: x mandatory; |
152 | | -
|
153 | | - &[inert] { |
154 | | - position: relative; |
155 | | - margin: 0 calc(-1 * var(--bleed)); |
156 | | - padding: 1rem var(--bleed); |
157 | | - scroll-padding: 0 var(--bleed); |
158 | | - overflow: hidden; |
159 | | - filter: blur(0.5px); |
160 | | - mask-image: linear-gradient( |
161 | | - to right, |
162 | | - rgb(0 0 0 / 0) 0%, |
163 | | - rgb(0 0 0 / 0.5) var(--bleed), |
164 | | - rgb(0 0 0 / 0) var(--bleed), |
165 | | - rgb(0 0 0 / 0) calc(100% - var(--bleed)), |
166 | | - rgb(0 0 0 / 0.5) calc(100% - var(--bleed)), |
167 | | - rgb(0 0 0 / 0) 100% |
168 | | - ); |
169 | | - } |
170 | | -
|
171 | | - &:not([inert]) { |
172 | | - position: absolute; |
173 | | - top: 0; |
174 | | - left: 0; |
175 | | - width: 100%; |
176 | | - height: 100%; |
177 | | - overflow-x: auto; |
178 | | - overflow-y: visible; |
179 | | - margin: 1rem 0; |
180 | | - } |
| 46 | + margin-bottom: 0.5rem; |
| 47 | + color: var(--sk-fg-2); |
181 | 48 | } |
182 | 49 |
|
183 | 50 | .content { |
184 | 51 | display: grid; |
185 | | - grid-auto-columns: 34rem; |
186 | | - grid-auto-flow: column; |
187 | | - gap: 2rem; |
188 | | - width: fit-content; |
189 | | - } |
190 | | -
|
191 | | - .item { |
192 | | - height: 16rem; |
193 | | - scroll-snap-align: start; |
| 52 | + grid-template-columns: repeat(auto-fill, minmax(28rem, 1fr)); |
| 53 | + gap: 1.5rem; |
194 | 54 | } |
195 | 55 | </style> |
0 commit comments