|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref } from "vue"; |
| 3 | +import OnOffSwitch from "./OnOffSwitch.vue"; |
| 4 | +
|
| 5 | +const props = defineProps<{ |
| 6 | + id: string; |
| 7 | + initialTimeout?: number; |
| 8 | + onChange: (newValue: number | null) => void; |
| 9 | + onManualRefresh: () => void; |
| 10 | +}>(); |
| 11 | +
|
| 12 | +const autoRefresh = ref(props.initialTimeout != null); |
| 13 | +const refreshTimeout = ref(props.initialTimeout ?? 5); |
| 14 | +
|
| 15 | +function toggleRefresh() { |
| 16 | + autoRefresh.value = !autoRefresh.value; |
| 17 | + updateTimeout(); |
| 18 | +} |
| 19 | +
|
| 20 | +function updateTimeout() { |
| 21 | + validateTimeout(); |
| 22 | + props.onChange(autoRefresh.value ? refreshTimeout.value * 1000 : null); |
| 23 | +} |
| 24 | +
|
| 25 | +function validateTimeout() { |
| 26 | + refreshTimeout.value = Math.max(1, Math.min(600, refreshTimeout.value)); |
| 27 | +} |
| 28 | +</script> |
| 29 | + |
| 30 | +<template> |
| 31 | + <div class="refresh-config"> |
| 32 | + <button class="fa" title="refresh" @click="() => onManualRefresh()"> |
| 33 | + <i class="fa fa-lg fa-refresh" /> |
| 34 | + </button> |
| 35 | + <span>|</span> |
| 36 | + <label>Auto-Refresh:</label> |
| 37 | + <div> |
| 38 | + <OnOffSwitch :id="id" @toggle="toggleRefresh" :value="autoRefresh" /> |
| 39 | + </div> |
| 40 | + <input type="number" v-model="refreshTimeout" min="1" max="600" v-on:change="updateTimeout" /> |
| 41 | + <span class="unit">s</span> |
| 42 | + </div> |
| 43 | +</template> |
| 44 | + |
| 45 | +<style scoped> |
| 46 | +.refresh-config { |
| 47 | + display: flex; |
| 48 | + align-items: center; |
| 49 | + gap: 0.5em; |
| 50 | +} |
| 51 | +
|
| 52 | +.refresh-config .unit { |
| 53 | + margin-left: -0.45em; |
| 54 | +} |
| 55 | +
|
| 56 | +.refresh-config label { |
| 57 | + margin: 0; |
| 58 | +} |
| 59 | +
|
| 60 | +.refresh-config input { |
| 61 | + width: 3.5em; |
| 62 | +} |
| 63 | +
|
| 64 | +.refresh-config button { |
| 65 | + background: none; |
| 66 | + border: none; |
| 67 | + width: 2em; |
| 68 | +} |
| 69 | +
|
| 70 | +.refresh-config button .fa { |
| 71 | + transition: all 0.15s ease-in-out; |
| 72 | + transition: rotate 0.05s ease-in-out; |
| 73 | + transform-origin: center; |
| 74 | +} |
| 75 | +
|
| 76 | +.refresh-config button:hover .fa { |
| 77 | + color: #00a3c4; |
| 78 | + transform: scale(1.1); |
| 79 | +} |
| 80 | +
|
| 81 | +.refresh-config button:active .fa { |
| 82 | + transform: rotate(25deg); |
| 83 | + text-shadow: #929e9e 0.25px 0.25px; |
| 84 | +} |
| 85 | +</style> |
0 commit comments