@rxova/astro-ui 0.5.0 → 0.6.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/components/CopyButton.astro +107 -0
- package/src/components/QuickStart.astro +8 -57
- package/src/components/SiteFooter.astro +1 -1
- package/src/components/icons/Check.astro +11 -0
- package/src/components/icons/Copy.astro +12 -0
- package/src/styles/starlight.css +41 -0
package/package.json
CHANGED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* An icon button that puts `text` on the clipboard and shows a tick for a moment. Drawn in
|
|
4
|
+
* `currentColor`, so it sits on any surface, a dark terminal included; the caller places it.
|
|
5
|
+
*/
|
|
6
|
+
import Check from './icons/Check.astro'
|
|
7
|
+
import Copy from './icons/Copy.astro'
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
/** What goes on the clipboard. */
|
|
11
|
+
text: string
|
|
12
|
+
/** The accessible name and tooltip; there is no visible text, so this is what a screen reader says. */
|
|
13
|
+
label?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { text, label = 'Copy' } = Astro.props
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<button class="rx-copy" type="button" data-rx-copy={text} aria-label={label} title={label}>
|
|
20
|
+
<Copy class="rx-copy__idle" />
|
|
21
|
+
<Check class="rx-copy__done" />
|
|
22
|
+
<span class="rx-copy__status" role="status"></span>
|
|
23
|
+
</button>
|
|
24
|
+
|
|
25
|
+
<script>
|
|
26
|
+
for (const button of document.querySelectorAll<HTMLButtonElement>('[data-rx-copy]')) {
|
|
27
|
+
if (button.dataset.rxCopyBound) continue
|
|
28
|
+
button.dataset.rxCopyBound = ''
|
|
29
|
+
const status = button.querySelector<HTMLElement>('.rx-copy__status')
|
|
30
|
+
button.addEventListener('click', async () => {
|
|
31
|
+
try {
|
|
32
|
+
await navigator.clipboard.writeText(button.dataset.rxCopy ?? '')
|
|
33
|
+
} catch {
|
|
34
|
+
// Clipboard access can be denied; saying nothing beats claiming a copy that did not happen.
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
button.dataset.state = 'done'
|
|
38
|
+
if (status) status.textContent = 'Copied'
|
|
39
|
+
window.setTimeout(() => {
|
|
40
|
+
delete button.dataset.state
|
|
41
|
+
if (status) status.textContent = ''
|
|
42
|
+
}, 1600)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<style>
|
|
48
|
+
/* One glyph over the other, so the button keeps its size when the state flips. */
|
|
49
|
+
.rx-copy {
|
|
50
|
+
position: relative;
|
|
51
|
+
display: grid;
|
|
52
|
+
place-items: center;
|
|
53
|
+
flex: none;
|
|
54
|
+
width: 2rem;
|
|
55
|
+
height: 2rem;
|
|
56
|
+
padding: 0;
|
|
57
|
+
color: inherit;
|
|
58
|
+
background: transparent;
|
|
59
|
+
border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
|
|
60
|
+
border-radius: var(--rx-radius-sm);
|
|
61
|
+
opacity: 0.85;
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
transition:
|
|
64
|
+
border-color 0.15s ease,
|
|
65
|
+
opacity 0.15s ease;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.rx-copy:hover {
|
|
69
|
+
opacity: 1;
|
|
70
|
+
border-color: color-mix(in srgb, currentColor 65%, transparent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.rx-copy:focus-visible {
|
|
74
|
+
outline: 2px solid currentColor;
|
|
75
|
+
outline-offset: 2px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rx-copy :global(.rx-copy__idle),
|
|
79
|
+
.rx-copy :global(.rx-copy__done) {
|
|
80
|
+
grid-area: 1 / 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.rx-copy :global(.rx-copy__done),
|
|
84
|
+
.rx-copy[data-state='done'] :global(.rx-copy__idle) {
|
|
85
|
+
visibility: hidden;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.rx-copy[data-state='done'] :global(.rx-copy__done) {
|
|
89
|
+
visibility: visible;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* Announced to screen readers, never shown: the tick is the visible cue. */
|
|
93
|
+
.rx-copy__status {
|
|
94
|
+
position: absolute;
|
|
95
|
+
width: 1px;
|
|
96
|
+
height: 1px;
|
|
97
|
+
overflow: hidden;
|
|
98
|
+
clip-path: inset(50%);
|
|
99
|
+
white-space: nowrap;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@media (prefers-reduced-motion: reduce) {
|
|
103
|
+
.rx-copy {
|
|
104
|
+
transition: none;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
</style>
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
|
-
* An install command with a
|
|
3
|
+
* An install command with a `CopyButton` beside a "Use" pane. The snippet arrives through the slot,
|
|
4
4
|
* so a page can write a fenced block and get the same Shiki highlighting as the docs.
|
|
5
5
|
*/
|
|
6
|
+
import CopyButton from './CopyButton.astro'
|
|
7
|
+
|
|
6
8
|
interface Props {
|
|
7
9
|
command: string
|
|
8
10
|
}
|
|
@@ -21,12 +23,7 @@ const { command } = Astro.props
|
|
|
21
23
|
</span>
|
|
22
24
|
{command}
|
|
23
25
|
</code>
|
|
24
|
-
<
|
|
25
|
-
<span class="rx-qs__copy-idle">Copy</span>
|
|
26
|
-
<span class="rx-qs__copy-done" aria-hidden="true">
|
|
27
|
-
Copied
|
|
28
|
-
</span>
|
|
29
|
-
</button>
|
|
26
|
+
<CopyButton text={command} label="Copy the install command" />
|
|
30
27
|
</div>
|
|
31
28
|
</div>
|
|
32
29
|
|
|
@@ -38,21 +35,6 @@ const { command } = Astro.props
|
|
|
38
35
|
</div>
|
|
39
36
|
</div>
|
|
40
37
|
|
|
41
|
-
<script>
|
|
42
|
-
for (const button of document.querySelectorAll<HTMLButtonElement>('.rx-qs__copy')) {
|
|
43
|
-
button.addEventListener('click', async () => {
|
|
44
|
-
try {
|
|
45
|
-
await navigator.clipboard.writeText(button.dataset.copy ?? '')
|
|
46
|
-
} catch {
|
|
47
|
-
// Clipboard access can be denied; saying nothing beats claiming a copy that did not happen.
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
button.dataset.state = 'done'
|
|
51
|
-
window.setTimeout(() => delete button.dataset.state, 1600)
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
</script>
|
|
55
|
-
|
|
56
38
|
<style>
|
|
57
39
|
.rx-qs {
|
|
58
40
|
display: grid;
|
|
@@ -77,6 +59,10 @@ const { command } = Astro.props
|
|
|
77
59
|
}
|
|
78
60
|
|
|
79
61
|
/* Not `flex: 1`: a one-line command stretched to the snippet's height floats in an empty box. */
|
|
62
|
+
.rx-qs__term :global(.rx-copy) {
|
|
63
|
+
color: var(--rx-muted);
|
|
64
|
+
}
|
|
65
|
+
|
|
80
66
|
.rx-qs__term {
|
|
81
67
|
display: flex;
|
|
82
68
|
align-items: center;
|
|
@@ -103,41 +89,6 @@ const { command } = Astro.props
|
|
|
103
89
|
user-select: none;
|
|
104
90
|
}
|
|
105
91
|
|
|
106
|
-
/* One label over the other, so the button keeps its size when the state flips. */
|
|
107
|
-
.rx-qs__copy {
|
|
108
|
-
display: grid;
|
|
109
|
-
flex: none;
|
|
110
|
-
padding: 0.4rem 0.85rem;
|
|
111
|
-
color: var(--rx-muted);
|
|
112
|
-
background: var(--rx-bg);
|
|
113
|
-
border: 1px solid var(--rx-rule-strong);
|
|
114
|
-
border-radius: var(--rx-radius-pill);
|
|
115
|
-
font: inherit;
|
|
116
|
-
font-size: 0.78rem;
|
|
117
|
-
font-weight: 500;
|
|
118
|
-
cursor: pointer;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.rx-qs__copy:hover {
|
|
122
|
-
color: var(--rx-fg);
|
|
123
|
-
border-color: var(--rx-primary);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.rx-qs__copy-idle,
|
|
127
|
-
.rx-qs__copy-done {
|
|
128
|
-
grid-area: 1 / 1;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.rx-qs__copy-done,
|
|
132
|
-
.rx-qs__copy[data-state='done'] .rx-qs__copy-idle {
|
|
133
|
-
visibility: hidden;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.rx-qs__copy[data-state='done'] .rx-qs__copy-done {
|
|
137
|
-
visibility: visible;
|
|
138
|
-
color: var(--rx-primary);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
92
|
.rx-qs__code {
|
|
142
93
|
flex: 1;
|
|
143
94
|
}
|
|
@@ -131,7 +131,7 @@ const surfaces: readonly SiteLink[] =
|
|
|
131
131
|
<a href="https://www.npmjs.com/org/rxova">npm</a>
|
|
132
132
|
</li>
|
|
133
133
|
<li>
|
|
134
|
-
<a href="mailto:rxova
|
|
134
|
+
<a href="mailto:jonatan@rxova.org">jonatan@rxova.org</a>
|
|
135
135
|
</li>
|
|
136
136
|
</ul>
|
|
137
137
|
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ComponentProps } from 'astro/types'
|
|
3
|
+
import Icon from '../Icon.astro'
|
|
4
|
+
|
|
5
|
+
/** A tick: done. */
|
|
6
|
+
type Props = Omit<ComponentProps<typeof Icon>, 'solid'>
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<Icon {...Astro.props}>
|
|
10
|
+
<path d="m3.2 8.4 3 3 6.6-6.8"></path>
|
|
11
|
+
</Icon>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ComponentProps } from 'astro/types'
|
|
3
|
+
import Icon from '../Icon.astro'
|
|
4
|
+
|
|
5
|
+
/** Two overlapping sheets: the front one is what goes on the clipboard. */
|
|
6
|
+
type Props = Omit<ComponentProps<typeof Icon>, 'solid'>
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<Icon {...Astro.props}>
|
|
10
|
+
<rect x="5.5" y="5.5" width="8" height="8" rx="1.6"></rect>
|
|
11
|
+
<path d="M10.5 3A1.5 1.5 0 0 0 9 1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5"></path>
|
|
12
|
+
</Icon>
|
package/src/styles/starlight.css
CHANGED
|
@@ -153,6 +153,47 @@ header.header {
|
|
|
153
153
|
margin: 0 0 0.4rem;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
/* A page with no sidebar (a splash landing) has no phone menu, so on phones the header takes a
|
|
157
|
+
second row for the switcher and the sections. Starlight offsets the page by --sl-nav-height. */
|
|
158
|
+
@media (max-width: 49.99rem) {
|
|
159
|
+
:root:not([data-has-sidebar]) {
|
|
160
|
+
--sl-nav-height: 6rem;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
:root:not([data-has-sidebar]) header.header > .header {
|
|
164
|
+
flex-wrap: wrap;
|
|
165
|
+
align-content: space-between;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
:root:not([data-has-sidebar]) header.header .title-wrapper {
|
|
169
|
+
flex: 1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
:root:not([data-has-sidebar]) header.header .right-group {
|
|
173
|
+
display: flex;
|
|
174
|
+
flex-basis: 100%;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Only the switcher and the sections: the social icons and theme picker do not fit. */
|
|
178
|
+
:root:not([data-has-sidebar]) header.header .right-group > :not(.social-icons),
|
|
179
|
+
:root:not([data-has-sidebar]) header.header .social-icons > :not(.rx-sections) {
|
|
180
|
+
display: none;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
:root:not([data-has-sidebar]) header.header .social-icons::after {
|
|
184
|
+
content: none;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Flush with the logo above, and opening rightward from the left edge. */
|
|
188
|
+
:root:not([data-has-sidebar]) header.header .rx-switcher__trigger {
|
|
189
|
+
margin-inline-start: -0.5rem;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
:root:not([data-has-sidebar]) header.header .rx-switcher .rx-switcher__menu {
|
|
193
|
+
inset-inline: 0 auto;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
156
197
|
/* --- Footer -------------------------------------------------------------- */
|
|
157
198
|
|
|
158
199
|
/* Footer styles live in footer.css (imported above) because /blog and /updates need them too. */
|