@n1kname/components 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/CaseTile.astro +374 -0
package/package.json
CHANGED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A case on an index as a tile in the client's colour: the project's name large, one line on what
|
|
4
|
+
* it achieved, a few figures, and two or three screens that run off the tile's edge. The whole tile
|
|
5
|
+
* is one link.
|
|
6
|
+
*
|
|
7
|
+
* `layout="wide"` puts the words on the left and the screens on the right, with the figures under
|
|
8
|
+
* the words; it spans the full row, for the case that leads. `layout="half"` puts the words on top
|
|
9
|
+
* and the screens underneath, two tiles to a row. Either becomes the half layout once the tile is
|
|
10
|
+
* narrower than 760px, and the figures drop out there.
|
|
11
|
+
*
|
|
12
|
+
* Screens are laptop (wide) or phone (tall) screenshots, or one picture (`image`), such as a photo,
|
|
13
|
+
* for a case without screens. The first screen sits in front.
|
|
14
|
+
*
|
|
15
|
+
* Motion, all of it off under reduced motion: the screens rise in once as the tile scrolls into view,
|
|
16
|
+
* front first. Under a real pointer the tile lifts and the screens fan out a little; focus does the
|
|
17
|
+
* same.
|
|
18
|
+
*/
|
|
19
|
+
import type { ImageMetadata } from 'astro';
|
|
20
|
+
import { Image } from 'astro:assets';
|
|
21
|
+
|
|
22
|
+
interface Metric {
|
|
23
|
+
value: string;
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Screen {
|
|
28
|
+
image: ImageMetadata | string;
|
|
29
|
+
/** Empty by default: the tile is one link, named by its words. */
|
|
30
|
+
alt?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Props {
|
|
34
|
+
href: string;
|
|
35
|
+
/** The project's name, set large. */
|
|
36
|
+
title: string;
|
|
37
|
+
/** One line on what it achieved. */
|
|
38
|
+
text?: string;
|
|
39
|
+
/** Above the title: organisation, years, state. */
|
|
40
|
+
overline?: string;
|
|
41
|
+
/** Shown on a wide tile only; up to four. */
|
|
42
|
+
metrics?: Metric[];
|
|
43
|
+
screens?: Screen[];
|
|
44
|
+
/** One picture instead of screens, such as a photo. */
|
|
45
|
+
image?: ImageMetadata | string;
|
|
46
|
+
device?: 'laptop' | 'phone';
|
|
47
|
+
layout?: 'wide' | 'half';
|
|
48
|
+
/** The tile colour, deep enough for white text. */
|
|
49
|
+
tone?: string;
|
|
50
|
+
/** A label on the picture, such as "Concepts". */
|
|
51
|
+
note?: string;
|
|
52
|
+
/** A view-transition-name for the screens, shared with the cover on the page it opens. */
|
|
53
|
+
transition?: string;
|
|
54
|
+
/** The title's heading level. */
|
|
55
|
+
as?: 'h2' | 'h3';
|
|
56
|
+
class?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
href,
|
|
61
|
+
title,
|
|
62
|
+
text,
|
|
63
|
+
overline,
|
|
64
|
+
metrics = [],
|
|
65
|
+
screens = [],
|
|
66
|
+
image,
|
|
67
|
+
device = 'laptop',
|
|
68
|
+
layout = 'half',
|
|
69
|
+
tone = 'var(--c-accent)',
|
|
70
|
+
note,
|
|
71
|
+
transition,
|
|
72
|
+
as: Heading = 'h2',
|
|
73
|
+
class: className,
|
|
74
|
+
} = Astro.props;
|
|
75
|
+
|
|
76
|
+
const shots = screens.slice(0, 3);
|
|
77
|
+
const order = [...shots.keys()].reverse();
|
|
78
|
+
const phone = device === 'phone';
|
|
79
|
+
const widths = phone ? [240, 480] : [600, 1200];
|
|
80
|
+
const sizes = phone ? '(max-width: 760px) 30vw, 200px' : '(max-width: 760px) 80vw, 600px';
|
|
81
|
+
const fit = (img: ImageMetadata) => {
|
|
82
|
+
const w = widths.filter((x) => x <= img.width);
|
|
83
|
+
return w.length ? w : [img.width];
|
|
84
|
+
};
|
|
85
|
+
const figures = layout === 'wide' ? metrics.slice(0, 4) : [];
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
<a
|
|
89
|
+
class:list={['case-tile', layout, device, { 'has-image': !shots.length && image }, className]}
|
|
90
|
+
href={href}
|
|
91
|
+
style={`--tile-tone: ${tone}`}
|
|
92
|
+
data-case-tile
|
|
93
|
+
>
|
|
94
|
+
<div class="frame">
|
|
95
|
+
<div class="copy">
|
|
96
|
+
{overline && <p class="overline">{overline}</p>}
|
|
97
|
+
<Heading class="title">{title}</Heading>
|
|
98
|
+
{text && <p class="text">{text}</p>}
|
|
99
|
+
{note && <p class="note">{note}</p>}
|
|
100
|
+
{
|
|
101
|
+
figures.length > 0 && (
|
|
102
|
+
<dl class="metrics">
|
|
103
|
+
{figures.map((m) => (
|
|
104
|
+
<div>
|
|
105
|
+
<dt>{m.value}</dt>
|
|
106
|
+
<dd>{m.label}</dd>
|
|
107
|
+
</div>
|
|
108
|
+
))}
|
|
109
|
+
</dl>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div class="art" style={transition ? `view-transition-name: ${transition}; view-transition-class: media` : undefined}>
|
|
115
|
+
{
|
|
116
|
+
shots.length > 0
|
|
117
|
+
? order.map((i) => {
|
|
118
|
+
const s = shots[i];
|
|
119
|
+
return (
|
|
120
|
+
<div class={`screen s${i}`}>
|
|
121
|
+
{typeof s.image === 'string' ? (
|
|
122
|
+
<img src={s.image} alt={s.alt ?? ''} loading="lazy" />
|
|
123
|
+
) : (
|
|
124
|
+
<Image src={s.image} alt={s.alt ?? ''} widths={fit(s.image)} sizes={sizes} format="webp" quality={80} loading="lazy" />
|
|
125
|
+
)}
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
})
|
|
129
|
+
: image && (
|
|
130
|
+
<div class="screen picture s0">
|
|
131
|
+
{typeof image === 'string' ? (
|
|
132
|
+
<img src={image} alt="" loading="lazy" />
|
|
133
|
+
) : (
|
|
134
|
+
<Image src={image} alt="" widths={fit(image)} sizes="(max-width: 760px) 90vw, 700px" format="webp" quality={78} loading="lazy" />
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</a>
|
|
142
|
+
|
|
143
|
+
<script>
|
|
144
|
+
// Arm the entrance only with script and motion welcome, so without either the screens are simply
|
|
145
|
+
// there. Each tile plays once, when it first comes into view.
|
|
146
|
+
const tiles = document.querySelectorAll<HTMLElement>('[data-case-tile]');
|
|
147
|
+
if (tiles.length && matchMedia('(prefers-reduced-motion: no-preference)').matches && 'IntersectionObserver' in window) {
|
|
148
|
+
const io = new IntersectionObserver(
|
|
149
|
+
(entries) => {
|
|
150
|
+
for (const e of entries) {
|
|
151
|
+
if (!e.isIntersecting) continue;
|
|
152
|
+
e.target.classList.add('in');
|
|
153
|
+
io.unobserve(e.target);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
{ threshold: 0.25 },
|
|
157
|
+
);
|
|
158
|
+
for (const t of tiles) {
|
|
159
|
+
if (t.getBoundingClientRect().top < innerHeight * 0.9) continue;
|
|
160
|
+
t.classList.add('armed');
|
|
161
|
+
io.observe(t);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
</script>
|
|
165
|
+
|
|
166
|
+
<style>
|
|
167
|
+
.case-tile {
|
|
168
|
+
container-type: inline-size;
|
|
169
|
+
position: relative;
|
|
170
|
+
display: block;
|
|
171
|
+
height: 100%;
|
|
172
|
+
overflow: hidden;
|
|
173
|
+
isolation: isolate;
|
|
174
|
+
border-radius: 24px;
|
|
175
|
+
color: #fff;
|
|
176
|
+
text-decoration: none;
|
|
177
|
+
background:
|
|
178
|
+
radial-gradient(circle at 1px 1px, rgb(255 255 255 / 0.13) 1px, transparent 0) 0 0 / 22px 22px,
|
|
179
|
+
linear-gradient(
|
|
180
|
+
150deg,
|
|
181
|
+
color-mix(in oklab, var(--tile-tone), white 10%),
|
|
182
|
+
var(--tile-tone) 50%,
|
|
183
|
+
color-mix(in oklab, var(--tile-tone), black 32%)
|
|
184
|
+
);
|
|
185
|
+
transition:
|
|
186
|
+
translate var(--motion-spring, 500ms) var(--ease-spring, ease-out),
|
|
187
|
+
box-shadow var(--motion-hover, 160ms) var(--ease-hover, ease-out);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.case-tile:focus-visible {
|
|
191
|
+
outline: 3px solid var(--c-focus, #fff);
|
|
192
|
+
outline-offset: 3px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* The tile is the container, and a container can't restyle itself, so the layout lives on this
|
|
196
|
+
* frame inside it. */
|
|
197
|
+
.frame {
|
|
198
|
+
display: flex;
|
|
199
|
+
flex-direction: column;
|
|
200
|
+
height: 100%;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* Words first; the pictures take the rest, so they never run under the text. */
|
|
204
|
+
.copy {
|
|
205
|
+
position: relative;
|
|
206
|
+
z-index: 2;
|
|
207
|
+
padding: clamp(24px, 7cqw, 48px);
|
|
208
|
+
padding-bottom: 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.overline {
|
|
212
|
+
margin: 0 0 var(--sp-3);
|
|
213
|
+
font-size: var(--text-caption);
|
|
214
|
+
letter-spacing: 0.02em;
|
|
215
|
+
color: rgb(255 255 255 / 0.74);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.title {
|
|
219
|
+
margin: 0;
|
|
220
|
+
font-family: var(--font-display);
|
|
221
|
+
font-weight: 600;
|
|
222
|
+
font-size: clamp(1.75rem, 7.5cqw, 3.25rem);
|
|
223
|
+
line-height: 1.05;
|
|
224
|
+
letter-spacing: -0.01em;
|
|
225
|
+
color: #fff;
|
|
226
|
+
text-wrap: balance;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.text {
|
|
230
|
+
margin: var(--sp-3) 0 0;
|
|
231
|
+
max-width: 36ch;
|
|
232
|
+
font-size: clamp(1rem, 2.6cqw, 1.2rem);
|
|
233
|
+
line-height: 1.45;
|
|
234
|
+
color: rgb(255 255 255 / 0.88);
|
|
235
|
+
text-wrap: pretty;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.note {
|
|
239
|
+
display: inline-block;
|
|
240
|
+
margin: var(--sp-4) 0 0;
|
|
241
|
+
padding: 2px var(--sp-3);
|
|
242
|
+
border-radius: var(--radius-full);
|
|
243
|
+
background: rgb(255 255 255 / 0.16);
|
|
244
|
+
font-size: var(--text-caption);
|
|
245
|
+
color: #fff;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Figures only when the tile is wide enough to give them room. */
|
|
249
|
+
.metrics {
|
|
250
|
+
display: none;
|
|
251
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
252
|
+
gap: var(--sp-5) var(--sp-6);
|
|
253
|
+
margin: var(--sp-6) 0 0;
|
|
254
|
+
padding-top: var(--sp-5);
|
|
255
|
+
border-top: 1px solid rgb(255 255 255 / 0.24);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.metrics dt {
|
|
259
|
+
font-family: var(--font-display);
|
|
260
|
+
font-weight: 600;
|
|
261
|
+
font-size: clamp(1.5rem, 2.6cqw, 2.5rem);
|
|
262
|
+
line-height: 1.1;
|
|
263
|
+
font-variant-numeric: tabular-nums;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.metrics dd {
|
|
267
|
+
margin: var(--sp-1) 0 0;
|
|
268
|
+
font-size: var(--text-body-sm);
|
|
269
|
+
color: rgb(255 255 255 / 0.8);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* Pictures, running off the bottom and right edge. Their height follows the tile's width. */
|
|
273
|
+
.art {
|
|
274
|
+
position: relative;
|
|
275
|
+
z-index: 1;
|
|
276
|
+
flex: 1 0 auto;
|
|
277
|
+
min-height: 56cqw;
|
|
278
|
+
margin-top: var(--sp-6);
|
|
279
|
+
pointer-events: none;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.screen {
|
|
283
|
+
position: absolute;
|
|
284
|
+
overflow: hidden;
|
|
285
|
+
border-radius: 10px;
|
|
286
|
+
box-shadow:
|
|
287
|
+
0 1px 2px rgb(0 0 0 / 0.2),
|
|
288
|
+
0 30px 60px -16px rgb(0 0 0 / 0.5);
|
|
289
|
+
transition:
|
|
290
|
+
transform 600ms var(--ease-soft, cubic-bezier(0.16, 1, 0.3, 1)),
|
|
291
|
+
translate 900ms var(--ease-soft, cubic-bezier(0.16, 1, 0.3, 1)),
|
|
292
|
+
opacity 700ms ease-out;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.screen :global(img) {
|
|
296
|
+
display: block;
|
|
297
|
+
width: 100%;
|
|
298
|
+
height: auto;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.s0 { z-index: 3; }
|
|
302
|
+
.s1 { z-index: 2; transition-delay: 0ms, 90ms, 90ms; }
|
|
303
|
+
.s2 { z-index: 1; transition-delay: 0ms, 180ms, 180ms; }
|
|
304
|
+
|
|
305
|
+
.phone .screen {
|
|
306
|
+
border-radius: 11% / 5%;
|
|
307
|
+
box-shadow:
|
|
308
|
+
0 0 0 3px rgb(18 18 20),
|
|
309
|
+
0 30px 50px -14px rgb(0 0 0 / 0.55);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/* Half, and any tile under 760px. */
|
|
313
|
+
.laptop .screen { width: 84%; }
|
|
314
|
+
.laptop .s0 { left: 6%; top: 22%; }
|
|
315
|
+
.laptop .s1 { left: 13%; top: 11%; }
|
|
316
|
+
.laptop .s2 { left: 20%; top: 0; }
|
|
317
|
+
.phone .screen { width: 28%; }
|
|
318
|
+
.phone .s0 { left: 12%; top: 18%; }
|
|
319
|
+
.phone .s1 { left: 36%; top: 10%; }
|
|
320
|
+
.phone .s2 { left: 60%; top: 2%; }
|
|
321
|
+
.has-image .picture { left: 7%; top: 0; width: 100%; border-radius: 10px 0 0 0; }
|
|
322
|
+
|
|
323
|
+
/* Wide, from 760px of tile: words and figures left, pictures right. */
|
|
324
|
+
@container (min-width: 760px) {
|
|
325
|
+
.wide .frame {
|
|
326
|
+
flex-direction: row;
|
|
327
|
+
}
|
|
328
|
+
.wide .copy {
|
|
329
|
+
flex: 0 0 46%;
|
|
330
|
+
padding: clamp(32px, 4.5cqw, 56px);
|
|
331
|
+
padding-right: 0;
|
|
332
|
+
}
|
|
333
|
+
.wide .metrics { display: grid; }
|
|
334
|
+
.wide .title { font-size: clamp(2.25rem, 4.6cqw, 3.75rem); }
|
|
335
|
+
.wide .text { font-size: clamp(1rem, 1.5cqw, 1.25rem); }
|
|
336
|
+
.wide .art {
|
|
337
|
+
flex: 1 1 auto;
|
|
338
|
+
min-height: 38cqw;
|
|
339
|
+
margin-top: 0;
|
|
340
|
+
}
|
|
341
|
+
.wide.laptop .screen { width: 88%; }
|
|
342
|
+
.wide.laptop .s0 { left: 6%; top: 30%; }
|
|
343
|
+
.wide.laptop .s1 { left: 14%; top: 17%; }
|
|
344
|
+
.wide.laptop .s2 { left: 22%; top: 4%; }
|
|
345
|
+
.wide.phone .screen { width: 28%; }
|
|
346
|
+
.wide.phone .s0 { left: 10%; top: 16%; }
|
|
347
|
+
.wide.phone .s1 { left: 35%; top: 9%; }
|
|
348
|
+
.wide.phone .s2 { left: 60%; top: 2%; }
|
|
349
|
+
.wide.has-image .picture { left: 8%; top: 10%; }
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
353
|
+
.armed .screen {
|
|
354
|
+
opacity: 0;
|
|
355
|
+
translate: 0 48px;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@media (hover: hover) {
|
|
359
|
+
.case-tile:hover {
|
|
360
|
+
translate: 0 -3px;
|
|
361
|
+
box-shadow: 0 24px 48px -24px rgb(0 0 0 / 0.6);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
.case-tile:is(:hover, :focus-visible) .s0 { transform: translate(-1.5%, -2%); }
|
|
365
|
+
.case-tile:is(:hover, :focus-visible) .s1 { transform: translate(1%, -4%); }
|
|
366
|
+
.case-tile:is(:hover, :focus-visible) .s2 { transform: translate(3.5%, -6%); }
|
|
367
|
+
.case-tile.phone:is(:hover, :focus-visible) .s0 { transform: translate(-6%, -2%) rotate(-2deg); }
|
|
368
|
+
.case-tile.phone:is(:hover, :focus-visible) .s2 { transform: translate(6%, -5%) rotate(2deg); }
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
@media (max-width: 640px) {
|
|
372
|
+
.case-tile { border-radius: 18px; }
|
|
373
|
+
}
|
|
374
|
+
</style>
|