Created
November 15, 2024 03:36
-
-
Save codemonkey76/a25b191f255f83ea1446a168645e0cb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
import {ref, watch} from "vue"; | |
const props = defineProps<{ | |
modelValue?: boolean | undefined | |
}>(); | |
const emit = defineEmits<{ | |
(event: 'update:modelValue', value: boolean|undefined): void | |
}>(); | |
const currentValue = ref<boolean|undefined>(props.modelValue); | |
watch( | |
() => props.modelValue, | |
(newValue) => currentValue.value = newValue, | |
{ immediate: true } | |
); | |
const toggleState = () => { | |
console.log("ToggleState()", currentValue.value); | |
currentValue.value = currentValue.value === false ? true : false; | |
emit("update:modelValue", currentValue.value); | |
} | |
</script> | |
<template> | |
<input | |
type="checkbox" | |
:checked="currentValue === true" | |
:indeterminate="typeof currentValue === 'undefined'" | |
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" | |
@change.prevent="toggleState" /> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment