- 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
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
---
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import DocsLayout from "../../layouts/DocsLayout.astro";
import Document from "../../components/Document.astro";
import Preview from "../../components/Preview.astro";
const gridItems = Array.from({ length: 20 }, (_, i) => {
const name = `--space-px-${20 - i}`;
const hasLabel = i <= 5;
const properties = [
`width: var(${name})`,
`height: var(${name})`,
hasLabel ? "padding: var(--space-px-1) var(--space-px-2)" : null,
];
return {
style: properties.filter((s) => typeof s === "string").join(";"),
label: hasLabel ? name : null,
};
});
---
<script>
const interactiveContainer = document.getElementById("interactive_container");
const interactiveSlider = document.getElementById("interactive_slider");
const interactiveLabel = document.getElementById("interactive_label");
function syncInteractiveGap() {
const size = interactiveSlider.value;
interactiveContainer.style.gap = `var(--space-px-${size})`;
interactiveLabel.textContent = `--space-x-${size}`;
}
document
.getElementById("interactive_slider")
.addEventListener("input", (event) => {
syncInteractiveGap();
});
syncInteractiveGap();
</script>
<style>
.list.list {
display: grid;
grid-template-columns: var(--space-px-20);
grid-template-rows: var(--space-px-20);
width: 100%;
padding: 0;
}
.box.box {
display: inline-flex;
align-items: end;
border: 1px solid oklch(var(--color-border) / var(--alpha-border-strong));
grid-column: 1 / 2;
grid-row: 1 / 2;
font-size: var(--font-xs);
font-family: var(--font-mono);
border-radius: var(--space-px-1);
color: oklch(var(--color-fg) / var(--alpha-fg-subtle));
list-style: none;
}
.box:not(:first-child) {
border-inline-start-color: transparent;
border-block-start-color: transparent;
}
.interactive-scroller {
display: block;
margin-block-end: var(--space-px-6);
overflow-x: auto;
}
.interactive-container {
display: flex;
align-items: center;
width: calc(var(--space-px-6) * 2 + var(--space-px-20));
}
.fill {
display: block;
width: var(--space-px-6);
height: var(--space-px-12);
background-color: oklch(var(--color-fg) / var(--alpha-fg-strong));
border-radius: 2px;
}
.interactive-controls {
display: flex;
flex-direction: column;
align-items: start;
gap: var(--space-px-3);
}
.interactive-label {
font-size: var(--font-sm);
font-family: var(--font-mono);
}
.slider {
border: 1px solid oklch(var(--color-border) / var(--alpha-border-subtle));
background-color: oklch(var(--color-fg) / 2%);
border-radius: 0.6em;
}
.slider:focus-visible {
border-color: oklch(var(--color-focus));
box-shadow: 0 0 0 var(--size-focus-ring)
oklch(var(--color-focus) / var(--alpha-focus-ring));
}
</style>
<DocsLayout title="Spacings">
<Document>
<p>
要素間・周囲の隙間の大きさは <code>--space-px-*</code>
というカスタムプロパティによって一覧定義されています。
</p>
<Preview title="List">
<ul class="list">
{
gridItems.map(({ style, label }) => (
<li class="box" style={style}>{label}</li>
))
}
</ul>
</Preview>
<Preview title="Interactive Gap">
<div class="interactive-scroller">
<div
id="interactive_container"
class="interactive-container"
style="gap: var(--space-px-1)"
>
<div class="fill" />
<div class="fill" />
</div>
</div>
<div class="interactive-controls">
<input
id="interactive_slider"
class="slider"
type="range"
value="1"
min="1"
max="20"
step="1"
aria-label="Gap size"
/>
<span id="interactive_label" class="interactive-label"
>--space-px-1</span>
</div>
</Preview>
</Document>
</DocsLayout>