|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <template>
- <div class="box is-flex is-flex-direction-row is-justify-content-space-between">
- <div class="my-auto">
- <input type="checkbox" v-model="allow" :aria-label="props.inputs.checkbox.label">
- {{ props.inputs.checkbox.label }}
- </div>
- <div>
- <button :class="`button ${props.inputs.button.style}`"
- :disabled="disable"
- @click="modification">
- {{ props.inputs.button.label }}
- </button>
- </div>
- </div>
- </template>
-
- <script setup lang="ts">
- import {
- computed,
- PropType,
- ref,
- watch,
- } from 'vue';
-
- type Modification = () => Promise<void>;
-
- export interface ModificationInputs {
- checkbox: {
- label: string,
- },
- button: {
- label: string,
- style: string,
- },
- }
-
- // eslint-disable-next-line no-undef
- const emits = defineEmits(['confirmed']);
-
- // eslint-disable-next-line no-undef
- const props = defineProps({
- inputs: Object as PropType<ModificationInputs>,
- condition: Object as PropType<boolean | undefined>,
- modification: Object as PropType<Modification>,
- });
-
- const allow = ref(false);
-
- const disable = computed(() => !allow.value || props.condition);
-
- const modTimeout = ref(undefined as number | undefined);
- watch(allow, () => {
- emits('confirmed', allow.value);
- if (modTimeout.value) window.clearTimeout(modTimeout.value);
- modTimeout.value = window.setTimeout(() => {
- allow.value = false;
- modTimeout.value = undefined;
- }, 10000);
- });
- </script>
-
- <style scoped lang="stylus">
- </style>
|