2022-07-13 00:56:22 +08:00
|
|
|
<script>
|
|
|
|
import { createEventDispatcher, onMount } from "svelte";
|
|
|
|
import tooltip from "@/actions/tooltip";
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
let tooltipData = { text: "Refresh", position: "right" };
|
|
|
|
export { tooltipData as tooltip };
|
|
|
|
|
|
|
|
let refreshTimeoutId = null;
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
dispatch("refresh");
|
|
|
|
|
|
|
|
// clear tooltip
|
|
|
|
const oldTooltipData = tooltipData;
|
|
|
|
tooltipData = null;
|
|
|
|
|
|
|
|
clearTimeout(refreshTimeoutId);
|
|
|
|
refreshTimeoutId = setTimeout(() => {
|
|
|
|
refreshTimeoutId = null;
|
|
|
|
tooltipData = oldTooltipData;
|
2022-10-30 16:28:14 +08:00
|
|
|
}, 150);
|
2022-07-13 00:56:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
return () => clearTimeout(refreshTimeoutId);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-01-29 02:13:15 +08:00
|
|
|
aria-label="Refresh"
|
2023-01-24 03:57:35 +08:00
|
|
|
class="btn btn-transparent btn-circle"
|
2022-07-13 00:56:22 +08:00
|
|
|
class:refreshing={refreshTimeoutId}
|
|
|
|
use:tooltip={tooltipData}
|
|
|
|
on:click={refresh}
|
|
|
|
>
|
|
|
|
<i class="ri-refresh-line" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
@keyframes refresh {
|
|
|
|
100% {
|
|
|
|
transform: rotate(180deg);
|
|
|
|
}
|
|
|
|
}
|
2022-07-18 05:16:09 +08:00
|
|
|
.btn.refreshing i {
|
2022-10-30 16:28:14 +08:00
|
|
|
animation: refresh 150ms ease-out;
|
2022-07-13 00:56:22 +08:00
|
|
|
}
|
|
|
|
</style>
|