-
-
Notifications
You must be signed in to change notification settings - Fork 751
Expand file tree
/
Copy pathInstallInstructions.svelte
More file actions
168 lines (141 loc) · 4.8 KB
/
Copy pathInstallInstructions.svelte
File metadata and controls
168 lines (141 loc) · 4.8 KB
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
163
164
165
166
167
168
<script lang="ts">
import { browser } from '$app/environment';
import CopyButton from '$lib/components/CopyButton.svelte';
import Icon from '$lib/components/Icon.svelte';
interface Props {
crate: string;
version: string;
exactVersion?: boolean;
binNames?: string[];
hasLib?: boolean;
}
let { crate, version, exactVersion = false, binNames, hasLib }: Props = $props();
let isClipboardSupported = browser && Boolean(navigator.clipboard?.writeText);
let cargoInstallCommand = $derived(exactVersion ? `cargo install ${crate}@${version}` : `cargo install ${crate}`);
let cargoAddCommand = $derived(exactVersion ? `cargo add ${crate}@=${version}` : `cargo add ${crate}`);
let tomlSnippet = $derived.by(() => {
let v = version.split('+', 1)[0];
let exact = exactVersion ? '=' : '';
return `${crate} = "${exact}${v}"`;
});
let versionOnly = $derived.by(() => {
let v = version.split('+', 1)[0];
return exactVersion ? `=${v}` : v;
});
</script>
<div class="install-instructions">
{#if binNames && binNames.length !== 0}
{#if isClipboardSupported}
<CopyButton copyText={cargoInstallCommand} title="Copy command to clipboard" class="copy-button">
<span class="selectable">{cargoInstallCommand}</span>
<Icon class="i-mdi:content-copy copy-icon" />
</CopyButton>
{:else}
<code class="copy-fallback">{cargoInstallCommand}</code>
{/if}
<p class="copy-help">
{#if binNames.length === 1}
Running the above command will globally install the <span class="bin-name">{binNames[0]}</span> binary.
{:else if binNames.length === 2}
Running the above command will globally install the <span class="bin-name">{binNames[0]}</span> and
<span class="bin-name">{binNames[1]}</span> binaries.
{:else}
Running the above command will globally install these binaries:
{#each binNames as binName, index (binName)}
{#if index === 0}
<span class="bin-name">{binName}</span>
{:else if index === binNames.length - 1}
, and <span class="bin-name">{binName}</span>
{:else}
, <span class="bin-name">{binName}</span>
{/if}
{/each}
{/if}
</p>
{/if}
{#if hasLib && binNames && binNames.length !== 0}
<h3>Install as library</h3>
{/if}
{#if hasLib}
<p class="copy-help">Run the following Cargo command in your project directory:</p>
{#if isClipboardSupported}
<CopyButton copyText={cargoAddCommand} title="Copy command to clipboard" class="copy-button">
<span class="selectable">{cargoAddCommand}</span>
<Icon class="i-mdi:content-copy copy-icon" />
</CopyButton>
{:else}
<code class="copy-fallback">{cargoAddCommand}</code>
{/if}
<p class="copy-help">Or add the following line to your Cargo.toml:</p>
{#if isClipboardSupported}
<CopyButton copyText={tomlSnippet} title="Copy Cargo.toml snippet to clipboard" class="copy-button">
<span class="selectable">{tomlSnippet}</span>
<Icon class="i-mdi:content-copy copy-icon" />
</CopyButton>
{:else}
<code class="copy-fallback">{tomlSnippet}</code>
{/if}
<p class="copy-help">Or copy just the version:</p>
{#if isClipboardSupported}
<CopyButton copyText={versionOnly} title="Copy version to clipboard" class="copy-button">
<span class="selectable">{versionOnly}</span>
<Icon class="i-mdi:content-copy copy-icon" />
</CopyButton>
{:else}
<code class="copy-fallback">{versionOnly}</code>
{/if}
{/if}
</div>
<style>
.copy-help {
font-size: 12px;
overflow-wrap: break-word;
&:last-child {
margin-bottom: 0;
}
}
.install-instructions :global(.copy-button),
.copy-fallback {
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
padding: var(--space-2xs) var(--space-xs);
font-family: var(--font-monospace);
font-size: 14px;
line-height: 1.5em;
color: var(--main-color);
background: transparent;
border-radius: var(--space-3xs);
border: solid var(--space-4xs) var(--gray-border);
span {
flex: auto;
display: block;
word-break: break-word;
}
}
.install-instructions :global(.copy-button) {
text-align: start;
cursor: pointer;
&:hover {
background-color: light-dark(white, #141413);
}
}
.install-instructions :global(.copy-button .copy-icon) {
width: 1.25em;
height: 1.25em;
margin-left: var(--space-2xs);
opacity: 0;
transition: opacity var(--transition-fast);
}
.install-instructions :global(.copy-button:hover .copy-icon) {
opacity: 1;
}
.selectable {
user-select: text;
}
.bin-name {
font-family: var(--font-monospace);
font-weight: bold;
}
</style>