eratic / packages / core / src / components / Aside.astro
205 words
 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
---
/**
 * A note beside the text.
 *
 * On a wide screen it sits in the margin; below that it folds into the flow as
 * an indented note. Use it for the aside that would otherwise become a
 * parenthesis three lines long.
 *
 *   <Aside>The lake is not actually a lake.</Aside>
 *   <Aside side="left" label="Note">…</Aside>
 */
interface Props {
	side?: 'right' | 'left';
	/** Small label above the note. */
	label?: string;
}

const { side = 'right', label } = Astro.props;
---

<aside class:list={['aside', `aside--${side}`]}>
	{label && <p class="eyebrow">{label}</p>}
	<slot />
</aside>

<style>
	.aside {
		font-family: var(--font-ui);
		font-size: var(--step--1);
		line-height: var(--leading-prose);
		color: var(--ink-muted);
		text-wrap: pretty;
	}

	/* Below the breakpoint the margin does not exist, so the note becomes an
	   indented block instead of being crushed into a sliver. */
	@media (width < 64rem) {
		.aside {
			border-inline-start: 1px solid var(--rule);
			padding-inline-start: var(--space-s);
			margin-block: var(--space-m);
		}
	}

	@media (width >= 64rem) {
		.aside {
			/* Pulled into the gutter and pinned to the top of the paragraph it
			   follows, without leaving the document flow. */
			inline-size: 13rem;
			margin-block: 0;
		}

		.aside--right {
			float: inline-end;
			margin-inline-end: -15rem;
			margin-inline-start: var(--space-m);
		}

		.aside--left {
			float: inline-start;
			margin-inline-start: -15rem;
			margin-inline-end: var(--space-m);
		}
	}
</style>

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/eratic.git