Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI-505 : Modal > Allow the user to define their own modal footer [vue3] #427

Merged
merged 7 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/vue3/src/_dev/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
<script setup lang="ts">
import 'uno.css';
import '../assets/main.css';
import { ref } from 'vue';
import SingleDateInput from '~/components/DateInput/SingleDateInput.vue';
import { reactive } from 'vue';
import Modal from '~/components/Modal/Modal.vue';
import PrimaryButton from '~/components/Button/PrimaryButton.vue';

const date = ref();
const state = reactive({
showModal: false,
isLoading: false,
});

const clicked = async () => {
state.isLoading = true;
state.showModal = true;

(await new Promise(resolve => setTimeout(resolve, 1000)));
state.isLoading = false;
state.showModal = false;
};
</script>

<template>
<div class="container">
<SingleDateInput v-model="date" />
<Modal v-model:visible="state.showModal" title="Edit profile">
<p class="content">
The quick brown fox jumps over the lazy dog.
</p>
<template #footer>
<div class="footer">
<PrimaryButton :disabled="state.isLoading" @click="clicked">
Click me
</PrimaryButton>
</div>
</template>
</Modal>
<PrimaryButton @click="state.showModal = true;">
<span>Open Modal</span>
</PrimaryButton>
</div>
</template>

Expand All @@ -23,4 +50,9 @@ const date = ref();
height: 100vh;
gap: 40px;
}

.footer {
display: flex;
justify-content: end;
}
</style>
27 changes: 17 additions & 10 deletions packages/vue3/src/components/Modal/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const props = withDefaults(defineProps<ModalProps>(), {
});

const emit = defineEmits(['update:visible', 'onConfirm']);

const close = () => {
emit('update:visible', false);
};

const handleKeypress = (event: KeyboardEvent) => {
if (props.visible && event.key === 'Escape') {
close();
Expand Down Expand Up @@ -45,15 +47,20 @@ onUnmounted(() => {
<slot />
</div>
<div class="footer">
<PrimaryButton v-if="!cancelOnly" @click="emit('onConfirm')">
<template v-if="confirmIcon" #icon>
<i :class="confirmIcon" />
</template>
<span>{{ confirmLabel }}</span>
</PrimaryButton>
<SecondaryButton @click="close">
<span>{{ cancelLabel }}</span>
</SecondaryButton>
<div v-if="$slots.footer">
<slot name="footer" />
</div>
<div v-else class="footer-content">
<PrimaryButton v-if="!cancelOnly" @click="emit('onConfirm')">
<template v-if="confirmIcon" #icon>
<i :class="confirmIcon" />
</template>
<span>{{ confirmLabel }}</span>
</PrimaryButton>
<SecondaryButton @click="close">
<span>{{ cancelLabel }}</span>
</SecondaryButton>
</div>
</div>
</div>
</Transition>
Expand Down Expand Up @@ -84,7 +91,7 @@ onUnmounted(() => {
}

.modal .header,
.modal .footer {
.modal .footer-content {
display: flex;
flex-direction: row-reverse;
align-items: center;
Expand Down
Loading