feat: fancycheckbox script setup (#2462)
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2462 Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
parent
9022954257
commit
06c1a54886
1 changed files with 32 additions and 36 deletions
|
@ -4,8 +4,9 @@
|
||||||
:checked="checked"
|
:checked="checked"
|
||||||
:disabled="disabled || undefined"
|
:disabled="disabled || undefined"
|
||||||
:id="checkBoxId"
|
:id="checkBoxId"
|
||||||
@change="(event) => updateData(event.target.checked)"
|
@change="(event: Event) => updateData((event.target as HTMLInputElement).checked)"
|
||||||
type="checkbox"/>
|
type="checkbox"
|
||||||
|
/>
|
||||||
<label :for="checkBoxId" class="check">
|
<label :for="checkBoxId" class="check">
|
||||||
<svg height="18px" viewBox="0 0 18 18" width="18px">
|
<svg height="18px" viewBox="0 0 18 18" width="18px">
|
||||||
<path
|
<path
|
||||||
|
@ -19,21 +20,17 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import {defineComponent} from 'vue'
|
import {ref, toRef, watch} from 'vue'
|
||||||
|
|
||||||
import {createRandomID} from '@/helpers/randomId'
|
import {createRandomID} from '@/helpers/randomId'
|
||||||
|
|
||||||
export default defineComponent({
|
const checked = ref(false)
|
||||||
name: 'fancycheckbox',
|
const checkBoxId = `fancycheckbox_${createRandomID()}`
|
||||||
data() {
|
|
||||||
return {
|
const props = defineProps({
|
||||||
checked: false,
|
|
||||||
checkBoxId: `fancycheckbox_${createRandomID()}`,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
|
@ -41,25 +38,24 @@ export default defineComponent({
|
||||||
required: false,
|
required: false,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
emits: ['update:modelValue', 'change'],
|
|
||||||
watch: {
|
|
||||||
modelValue: {
|
|
||||||
handler(modelValue) {
|
|
||||||
this.checked = modelValue
|
|
||||||
|
|
||||||
},
|
|
||||||
immediate: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
updateData(checked: boolean) {
|
|
||||||
this.checked = checked
|
|
||||||
this.$emit('update:modelValue', checked)
|
|
||||||
this.$emit('change', checked)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
const emit = defineEmits(['update:modelValue', 'change'])
|
||||||
|
|
||||||
|
const modelValue = toRef(props, 'modelValue')
|
||||||
|
|
||||||
|
watch(
|
||||||
|
modelValue,
|
||||||
|
newValue => {
|
||||||
|
checked.value = newValue
|
||||||
|
},
|
||||||
|
{immediate: true},
|
||||||
|
)
|
||||||
|
|
||||||
|
function updateData(newChecked: boolean) {
|
||||||
|
checked.value = newChecked
|
||||||
|
emit('update:modelValue', newChecked)
|
||||||
|
emit('change', newChecked)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue