-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from anthonyshibitov/modal-refactor
Refactor ModalBase from existing modals
- Loading branch information
Showing
3 changed files
with
135 additions
and
112 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<!-- Normal display on page --> | ||
<div @click="openModal"> | ||
<slot name="normalDisplay"></slot> | ||
</div> | ||
<!-- Modal pop up --> | ||
<Dialog @close="closeModal" class="relative z-50" :open="isOpen"> | ||
<div | ||
@click="closeModal" | ||
class="fixed inset-0 bg-light-popup dark:bg-dark-popup" | ||
aria-hidden="true" | ||
/> | ||
<div | ||
:class="[ | ||
imageModal | ||
? 'fixed top-0 z-10 flex flex-col items-center w-full h-screen overflow-hidden cursor-pointer bg-light-popup dark:bg-dark-popup' | ||
: 'fixed inset-0 flex w-screen items-center justify-center', | ||
]" | ||
> | ||
<DialogPanel | ||
:class="[ | ||
imageModal | ||
? 'flex flex-col items-center' | ||
: 'pl-6 h-full md:h-auto overflow-y-auto w-full max-w-4xl card-style text-light-text dark:text-dark-text container p-5', | ||
]" | ||
> | ||
<button | ||
v-if="imageModal" | ||
@click="closeModal" | ||
class="absolute right-0 p-1 mt-8 mr-24 rounded-full text-light-special-text dark:text-dark-special-text hover:text-light-text hover:dark:text-dark-text focus-brand" | ||
:aria-label="$t('components.modal-image.close-modal-aria-label')" | ||
> | ||
<Icon class="w-10 h-10" name="bi:x-circle-fill" /> | ||
</button> | ||
<div v-else class="relative"> | ||
<button | ||
@click="closeModal" | ||
class="absolute right-0 p-1 rounded-full text-light-special-text dark:text-dark-special-text hover:text-light-text hover:dark:text-dark-text focus-brand" | ||
> | ||
<Icon class="w-10 h-10" name="bi:x-circle-fill" /> | ||
</button> | ||
</div> | ||
<div | ||
v-if="imageModal" | ||
@click="closeModal" | ||
class="flex flex-col items-center justify-center w-4/5 focus-brand" | ||
:aria-label="$t('components.modal-image.close-modal-aria-label')" | ||
> | ||
<slot name="modalDisplay"></slot> | ||
</div> | ||
<div v-else> | ||
<slot name="modalDisplay"></slot> | ||
</div> | ||
</DialogPanel> | ||
</div> | ||
</Dialog> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Dialog, DialogPanel } from "@headlessui/vue"; | ||
import { ref } from "vue"; | ||
defineProps<{ | ||
imageModal?: boolean; | ||
}>(); | ||
const isOpen = ref(false); | ||
function openModal() { | ||
isOpen.value = true; | ||
} | ||
function closeModal() { | ||
isOpen.value = false; | ||
} | ||
</script> |
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,75 +1,42 @@ | ||
<template> | ||
<button | ||
@click="openModal" | ||
class="hidden p-4 cursor-pointer md:block md:float-right md:w-1/3 2xl:w-full 2xl:col-span-1 h-min focus-brand" | ||
:aria-label="$t('components.modal-image.open-modal-aria-label')" | ||
> | ||
<img | ||
v-if="$colorMode.value == 'light'" | ||
:src="imageURL + '_light.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
<img | ||
v-else-if="$colorMode.value == 'dark'" | ||
:src="imageURL + '_dark.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
</button> | ||
<Dialog @close="closeModal" class="relative z-50" :open="isOpen"> | ||
<div | ||
class="fixed inset-0 bg-light-popup dark:bg-dark-popup" | ||
aria-hidden="true" | ||
/> | ||
<div | ||
class="fixed top-0 z-10 flex flex-col items-center w-full h-screen overflow-hidden cursor-pointer bg-light-popup dark:bg-dark-popup" | ||
> | ||
<DialogPanel class="flex flex-col items-center"> | ||
<button | ||
@click="closeModal" | ||
class="absolute right-0 p-1 mt-8 mr-24 rounded-full text-light-special-text dark:text-dark-special-text hover:text-light-text hover:dark:text-dark-text focus-brand" | ||
:aria-label="$t('components.modal-image.close-modal-aria-label')" | ||
> | ||
<Icon class="w-10 h-10" name="bi:x-circle-fill" /> | ||
</button> | ||
<button | ||
@click="closeModal" | ||
class="flex flex-col items-center justify-center w-4/5 focus-brand" | ||
:aria-label="$t('components.modal-image.close-modal-aria-label')" | ||
> | ||
<img | ||
v-if="$colorMode.value == 'light'" | ||
class="object-contain p-12" | ||
:src="imageURL + '_light.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
<img | ||
v-else-if="$colorMode.value == 'dark'" | ||
class="object-contain p-12" | ||
:src="imageURL + '_dark.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
</button> | ||
</DialogPanel> | ||
</div> | ||
</Dialog> | ||
<ModalBase imageModal> | ||
<template #normalDisplay> | ||
<button | ||
class="hidden p-4 cursor-pointer md:block md:float-right md:w-1/3 2xl:w-full 2xl:col-span-1 h-min focus-brand" | ||
:aria-label="$t('components.modal-image.open-modal-aria-label')" | ||
> | ||
<img | ||
v-if="$colorMode.value == 'light'" | ||
:src="imageURL + '_light.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
<img | ||
v-else-if="$colorMode.value == 'dark'" | ||
:src="imageURL + '_dark.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
</button> | ||
</template> | ||
<template #modalDisplay> | ||
<img | ||
v-if="$colorMode.value == 'light'" | ||
class="object-contain p-12" | ||
:src="imageURL + '_light.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
<img | ||
v-else-if="$colorMode.value == 'dark'" | ||
class="object-contain p-12" | ||
:src="imageURL + '_dark.png'" | ||
:alt="$t(imageAltText)" | ||
/> | ||
</template> | ||
</ModalBase> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Dialog, DialogPanel } from "@headlessui/vue"; | ||
import { ref } from "vue"; | ||
defineProps<{ | ||
imageURL: string; | ||
imageAltText: string; | ||
}>(); | ||
const isOpen = ref(false); | ||
function openModal() { | ||
isOpen.value = true; | ||
} | ||
function closeModal() { | ||
isOpen.value = false; | ||
} | ||
</script> |
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