diff options
author | 2023-04-05 22:55:40 +0200 | |
---|---|---|
committer | 2023-04-05 22:57:58 +0200 | |
commit | 6e84ea40616ab95d90f7ff6f8ab1f7723dea7112 (patch) | |
tree | 848ae64ed8e01bf020ec14d86e473778f421277b /src/tools/benchmark-builder/dynamic-values.vue | |
parent | 004cb83719492f06370179388a6d8e2e6cacadce (diff) | |
download | it-tools-6e84ea40616ab95d90f7ff6f8ab1f7723dea7112.tar.gz it-tools-6e84ea40616ab95d90f7ff6f8ab1f7723dea7112.tar.zst it-tools-6e84ea40616ab95d90f7ff6f8ab1f7723dea7112.zip |
feat(new-tool): simple benchmark calculator
Diffstat (limited to 'src/tools/benchmark-builder/dynamic-values.vue')
-rw-r--r-- | src/tools/benchmark-builder/dynamic-values.vue | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tools/benchmark-builder/dynamic-values.vue b/src/tools/benchmark-builder/dynamic-values.vue new file mode 100644 index 0000000..70268ae --- /dev/null +++ b/src/tools/benchmark-builder/dynamic-values.vue @@ -0,0 +1,61 @@ +<template> + <div> + <n-space v-for="(value, index) of values" :key="index" :wrap="false" style="margin-bottom: 5px" :size="5"> + <n-input-number + :ref="refs.set" + v-model:value="values[index]" + :show-button="false" + placeholder="Set your measure..." + autofocus + @keydown.enter="onInputEnter(index)" + /> + <n-tooltip> + <template #trigger> + <n-button circle quaternary @click="values.splice(index, 1)"> + <template #icon> + <n-icon :component="Trash" depth="3" /> + </template> + </n-button> + </template> + Delete value + </n-tooltip> + </n-space> + + <n-button tertiary @click="addValue"> + <template #icon> + <n-icon :component="Plus" /> + </template> + Add a measure + </n-button> + </div> +</template> + +<script setup lang="ts"> +import { Trash, Plus } from '@vicons/tabler'; +import { useTemplateRefsList, useVModel } from '@vueuse/core'; +import { NInputNumber } from 'naive-ui'; +import { nextTick } from 'vue'; + +const refs = useTemplateRefsList<typeof NInputNumber>(); + +const props = defineProps<{ values: (number | null)[] }>(); +const emit = defineEmits(['update:values']); +const values = useVModel(props, 'values', emit); + +async function addValue() { + values.value.push(null); + await nextTick(); + refs.value.at(-1)?.focus(); +} + +function onInputEnter(index: number) { + if (index === values.value.length - 1) { + addValue(); + return; + } + + refs.value.at(index + 1)?.focus(); +} +</script> + +<style scoped></style> |