-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Selemondev
authored and
Selemondev
committed
Aug 1, 2023
1 parent
6fb9cf0
commit 89c8180
Showing
7 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
<script setup lang='ts'> | ||
function handleClose() { | ||
alert('Closing') | ||
import { ref } from 'vue' | ||
const isActive = ref(false) | ||
function handleOpen() { | ||
return isActive.value = true | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="grid place-items-center w-full min-h-screen"> | ||
<WTag value="Success" variant="success-light" closable @close="handleClose" /> | ||
<button @click="handleOpen"> | ||
Open Modal | ||
</button> | ||
<WModal v-model="isActive"> | ||
hello there | ||
</WModal> | ||
</div> | ||
</template> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ export enum Components { | |
WDivider = 'WDivider', | ||
WSwitch = 'WSwitch', | ||
WTag = 'WTag', | ||
WModal = 'WModal', | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<script setup lang='ts'> | ||
import { computed, defineComponent } from 'vue' | ||
import classNames from 'classnames' | ||
import { Dialog, DialogPanel, TransitionChild, TransitionRoot } from '@headlessui/vue' | ||
import type { VariantJSWithClassesListProps } from '../../utils/getVariantProps' | ||
import { getVariantPropsWithClassesList } from '../../utils/getVariantProps' | ||
import { useVariants } from '../../composables/useVariants' | ||
import type { WModal } from '../../Types/componentsTypes/components' | ||
import { Components } from '../../Types/enums/Components' | ||
const props = defineProps({ | ||
...getVariantPropsWithClassesList<WModal>(), | ||
modelValue: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
disableClose: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
appear: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
overlay: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
transition: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
}) | ||
const emit = defineEmits<{ | ||
(event: 'update:modelValue', value: boolean): void | ||
(event: 'close') | ||
}>() | ||
const variant = computed(() => { | ||
const customProps = { | ||
...props, | ||
} | ||
return useVariants<WModal>( | ||
Components.WModal, | ||
customProps as VariantJSWithClassesListProps<WModal>, | ||
) | ||
}) | ||
const isOpen = computed({ | ||
get() { | ||
return props.modelValue | ||
}, | ||
set(value) { | ||
return emit('update:modelValue', value) | ||
}, | ||
}) | ||
const transitionClassWrapper = computed(() => { | ||
if (!props.transition) | ||
return {} | ||
return { | ||
...variant.value.transitions, | ||
} | ||
}) | ||
function close(value: boolean) { | ||
isOpen.value = value | ||
emit('close') | ||
} | ||
const transitionOverlay = computed(() => { | ||
return classNames( | ||
variant.value.modalOverlayTransition, | ||
) | ||
}) | ||
</script> | ||
|
||
<script lang="ts"> | ||
export default defineComponent({ | ||
name: Components.WModal, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<TransitionRoot :appear="appear" :show="isOpen" as="template"> | ||
<Dialog :class="variant.root" @close="(e: boolean) => !props.disableClose && close(e)"> | ||
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="transitionOverlay"> | ||
<div :class="[variant.modalOverlayBase, variant.modalOverlayBackground]" /> | ||
</TransitionChild> | ||
|
||
<div :class="variant.modalWrapper"> | ||
<div :class="variant.container"> | ||
<TransitionChild as="template" :appear="appear" v-bind="transitionClassWrapper"> | ||
<DialogPanel :class="[variant.modalBase, variant.modalHeight, variant.modalWidth, variant.modalShadow, variant.modalBackground, variant.modalRing, variant.modalRounded]"> | ||
<slot /> | ||
</DialogPanel> | ||
</TransitionChild> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</TransitionRoot> | ||
</template> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Modal from './WModal.vue' | ||
|
||
export default { | ||
Modal, | ||
} |
This file contains 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
This file contains 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