Skip to content

Commit

Permalink
feat(v-alert): default isOpen state for model-less component
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed Mar 13, 2022
1 parent d44cd3e commit 56ce7df
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/alert/src/VAlert.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import {computed, toRefs} from 'vue';
import {computed, toRefs, ref, watch} from 'vue';
import {XIcon, ExclamationIcon, CheckCircleIcon} from '@heroicons/vue/solid';
const props = defineProps({
Expand All @@ -21,10 +21,20 @@ const props = defineProps({
},
});
const {color} = toRefs(props);
const {color, modelValue} = toRefs(props);
const emit = defineEmits(['dismissed', 'update:modelValue']);
const isOpen = ref(modelValue.value);
watch(modelValue, (val) => {
isOpen.value = val;
});
watch(isOpen, (val) => {
emit('update:modelValue', val);
});
const classes = computed(() => {
switch (color.value) {
case 'primary':
Expand Down Expand Up @@ -64,8 +74,8 @@ const iconClasses = computed(() => {
});
const dismiss = () => {
isOpen.value = false;
emit('dismissed');
emit('update:modelValue', false);
};
</script>

Expand All @@ -79,7 +89,7 @@ const dismiss = () => {
leave-to-class="opacity-0 scale-95"
>
<div
v-if="props.modelValue"
v-if="isOpen"
class="px-4 py-3 border rounded flex w-full items-center"
:class="classes"
>
Expand Down

0 comments on commit 56ce7df

Please sign in to comment.