✨ feature: emit handled
This commit is contained in:
parent
fb93a3e353
commit
2c4a134152
|
@ -3,7 +3,7 @@ import Checkbox from 'primevue/checkbox';
|
||||||
import VLabel from '../label/VLabel.vue';
|
import VLabel from '../label/VLabel.vue';
|
||||||
import VHint from '../hint/VHint.vue';
|
import VHint from '../hint/VHint.vue';
|
||||||
import type IVCheckBox from './IVCheckbox.type';
|
import type IVCheckBox from './IVCheckbox.type';
|
||||||
import { useId, computed } from 'vue';
|
import { useId, computed, watch, ref } from 'vue';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<IVCheckBox>(), {
|
const props = withDefaults(defineProps<IVCheckBox>(), {
|
||||||
id: () => useId(),
|
id: () => useId(),
|
||||||
|
@ -16,7 +16,6 @@ const props = withDefaults(defineProps<IVCheckBox>(), {
|
||||||
readonlyOpacity: 0.75,
|
readonlyOpacity: 0.75,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const size = computed(() => props.small ? 'small' : undefined)
|
const size = computed(() => props.small ? 'small' : undefined)
|
||||||
const message = computed(() => props.errorMessage || props.validMessage)
|
const message = computed(() => props.errorMessage || props.validMessage)
|
||||||
|
|
||||||
|
@ -33,6 +32,26 @@ const labelState = computed(() => {
|
||||||
else if((!!props.validMessage || props.type === 'success') && !props.disabled) return 'success';
|
else if((!!props.validMessage || props.type === 'success') && !props.disabled) return 'success';
|
||||||
else return 'default';
|
else return 'default';
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits([
|
||||||
|
'update:modelValue',
|
||||||
|
'value-change',
|
||||||
|
'change',
|
||||||
|
'focus',
|
||||||
|
'blur'
|
||||||
|
])
|
||||||
|
|
||||||
|
const localModelValue = ref(props.modelValue);
|
||||||
|
watch(() => props.modelValue, (newVal) => {
|
||||||
|
if(localModelValue.value !== newVal){
|
||||||
|
localModelValue.value = newVal;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
watch(localModelValue, (newVal) => {
|
||||||
|
if(props.modelValue !== newVal){
|
||||||
|
emit('update:modelValue', newVal);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -51,14 +70,20 @@ const labelState = computed(() => {
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:label="props.label"
|
:label="props.label"
|
||||||
:model-value="modelValue"
|
|
||||||
:binary="binary"
|
:binary="binary"
|
||||||
|
:aria-label="props.label"
|
||||||
:class="['p-checkbox', {
|
:class="['p-checkbox', {
|
||||||
'checked-disabled': props.modelValue && disabled,
|
'checked-disabled': props.modelValue && disabled,
|
||||||
'unchecked-disabled': !props.modelValue && disabled,
|
'unchecked-disabled': !props.modelValue && disabled,
|
||||||
'error': (!!props.errorMessage || type === 'error') && !disabled,
|
'error': (!!props.errorMessage || type === 'error') && !disabled,
|
||||||
'success': (!!props.validMessage || type === 'success') && !disabled,
|
'success': (!!props.validMessage || type === 'success') && !disabled,
|
||||||
}]"
|
}]"
|
||||||
|
v-model:model-value="localModelValue"
|
||||||
|
@update:model-value="emit('update:modelValue', $event)"
|
||||||
|
@change="emit('change', $event)"
|
||||||
|
@blur="emit('blur', $event)"
|
||||||
|
@focus="emit('focus', $event)"
|
||||||
|
@value-change="emit('value-change', $event)"
|
||||||
/>
|
/>
|
||||||
<VLabel
|
<VLabel
|
||||||
:for="props.id"
|
:for="props.id"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user