Skip to content

Commit 1e20e87

Browse files
committed
Add button hovering
1 parent 0408f73 commit 1e20e87

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

src/components/tools/ItemCommandConverter.svelte

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{ label: "Item Argument", value: "item-argument" },
1111
{ label: "Component Argument", value: "component-argument" },
1212
{ label: "Entity Argument", value: "entity-argument" },
13-
];
13+
].sort((e1, e2) => e1.label.localeCompare(e2.label));
1414
1515
const ENTITY_TYPES: Option[] = [
1616
"item",
@@ -98,7 +98,7 @@
9898
"ender_crystal",
9999
]
100100
.map((e) => ({ label: e, value: e }))
101-
.sort((e1, e2) => e1.label.charCodeAt(0) - +e2.label.charCodeAt(0));
101+
.sort((e1, e2) => e1.label.localeCompare(e2.label));
102102
</script>
103103

104104
<script lang="ts">
@@ -108,6 +108,13 @@
108108
let input = $state("");
109109
let output = $state("");
110110
111+
let copied = $state(false);
112+
$effect(() => {
113+
if (copied) {
114+
setTimeout(() => (copied = false), 1500);
115+
}
116+
});
117+
111118
let mode = $state<Option>(MODES[0]);
112119
113120
let entityType = $state<Option>();
@@ -122,33 +129,39 @@
122129
output = "";
123130
loading = true;
124131
try {
125-
const query = mode === MODES[3] ? "?entityType=" + entityType?.value : "";
126-
const response = await fetch(
127-
"https://item-converter.papermc.io/convert-" + mode.value + query,
128-
{
129-
method: "POST",
130-
body: input,
131-
}
132-
);
133-
if (response.status === 200) {
134-
output = await response.text();
135-
toggleState(convertSuccess);
136-
} else {
137-
console.warn(
138-
"Failed to convert command: " +
139-
response.status +
140-
": " +
141-
(await response.text())
142-
);
143-
toggleState(convertError);
144-
}
132+
// const query = mode === MODES[3] ? "?entityType=" + entityType?.value : "";
133+
// const response = await fetch(
134+
// "https://item-converter.papermc.io/convert-" + mode.value + query,
135+
// {
136+
// method: "POST",
137+
// body: input,
138+
// }
139+
// );
140+
// if (response.status === 200) {
141+
// output = await response.text();
142+
output = input;
143+
toggleState(convertSuccess);
144+
// } else {
145+
// console.warn(
146+
// "Failed to convert command: " +
147+
// response.status +
148+
// ": " +
149+
// (await response.text())
150+
// );
151+
// toggleState(convertError);
152+
// }
145153
} catch (error) {
146154
console.error("Failed to convert command: " + error);
147155
toggleState(convertError);
148156
}
149157
150158
loading = false;
151159
};
160+
161+
const copyToClipboard = () => {
162+
navigator.clipboard.writeText(output);
163+
copied = true;
164+
};
152165
</script>
153166

154167
<div class="item-command-converter">
@@ -162,7 +175,9 @@
162175
</p>
163176

164177
<div class="convert-controls">
165-
<button class="convert-content clickable" onclick={convert}>Convert</button>
178+
<button class="convert-content clickable convert-button" onclick={convert}
179+
>Convert</button
180+
>
166181
{#if mode.value === "entity-argument"}
167182
<p class="convert-content entity-type">
168183
Entity Type:
@@ -192,14 +207,21 @@
192207
placeholder="Press 'Convert' to convert the command."
193208
class="textarea-panel"
194209
readonly
210+
bind:value={output}
195211
></textarea>
196212
</p>
197213

198-
<button class="clickable">Copy output!</button>
214+
<button
215+
class:copied
216+
onclick={copyToClipboard}
217+
class="clickable"
218+
disabled={loading}>{copied ? "Copied!" : "Copy output!"}</button
219+
>
199220
</div>
200221

201222
<style>
202223
.item-command-converter {
224+
margin-top: 1rem;
203225
padding: 1rem;
204226
border: 2px;
205227
border-style: solid;
@@ -256,5 +278,11 @@
256278
padding: 0.25rem;
257279
padding-left: 0.75rem;
258280
padding-right: 0.75rem;
281+
transition: 0.15s;
282+
}
283+
284+
.clickable:hover {
285+
background-color: var(--sl-color-gray-5);
286+
transition: 0.15s;
259287
}
260288
</style>

0 commit comments

Comments
 (0)