aotds-docks/src/lib/components/ShipItem/index.svelte

98 lines
1.4 KiB
Svelte
Raw Normal View History

2022-03-01 17:42:33 +00:00
<div class="ship-item">
<div><slot /></div>
2020-07-19 20:21:28 +00:00
2022-03-01 17:42:33 +00:00
<div class="reqs">
<div class="mass" bind:this={mass_el}>{mass}</div>
<div class="cost" bind:this={cost_el}>{cost}</div>
</div>
</div>
2020-07-19 20:21:28 +00:00
<script>
2021-05-17 14:07:01 +00:00
import { tick } from "svelte";
2020-07-25 15:56:23 +00:00
2020-07-19 20:21:28 +00:00
export let mass;
export let cost;
2020-07-25 15:56:23 +00:00
let mass_el;
let cost_el;
const update_el = async (el) => {
2021-05-17 14:07:01 +00:00
if (!el) return;
el.classList.remove("updated");
2020-07-25 15:56:23 +00:00
void el.offsetWidth;
2021-05-17 14:07:01 +00:00
el.classList.add("updated");
};
2020-07-25 15:56:23 +00:00
2021-05-17 14:07:01 +00:00
$: update_el(mass_el, mass);
$: update_el(cost_el, cost);
2020-07-19 20:21:28 +00:00
</script>
<style>
2020-07-28 18:38:40 +00:00
div {
margin-bottom: 1em;
}
2022-03-01 17:42:33 +00:00
2021-05-17 14:07:01 +00:00
.cost,
.mass {
2022-03-01 17:42:33 +00:00
width: 4em;
padding: 0px 0.5em;
2021-05-17 14:07:01 +00:00
text-align: right;
}
2020-07-28 18:38:40 +00:00
2020-07-19 20:21:28 +00:00
.ship-item {
display: flex;
}
2021-05-17 14:07:01 +00:00
.ship-item :global(> *) {
flex: 1;
}
2020-07-19 20:21:28 +00:00
img {
width: 0.75em;
}
2021-05-17 14:07:01 +00:00
.cost:after {
content: "\00A4";
margin-left: 0.5em;
}
.mass:after {
2021-06-13 16:48:22 +00:00
content: url("/mass.svg");
2021-05-17 14:07:01 +00:00
width: 0.75em;
display: inline-block;
margin-left: 0.5em;
}
2020-07-25 15:56:23 +00:00
:global(.updated) {
animation-name: update;
animation-duration: 1.5s;
animation-fill-mode: forwards;
}
2021-05-17 14:07:01 +00:00
@keyframes update {
0% {
color: inherit;
font-weight: inherit;
}
20% {
color: red;
font-weight: bold;
}
80% {
color: red;
font-weight: bold;
}
100% {
color: inherit;
font-weight: inherit;
}
}
2020-07-25 15:56:23 +00:00
2022-03-01 17:42:33 +00:00
.ship-item {
display: flex;
}
.reqs {
flex: 0;
width: 10em;
display: flex;
}
2020-07-19 20:21:28 +00:00
</style>