feat: Add the new Dialog component (#10266)
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import Dialog from './Dialog.vue';
|
||||||
|
import Button from 'dashboard/components-next/button/Button.vue';
|
||||||
|
import Input from 'dashboard/components-next/input/Input.vue';
|
||||||
|
|
||||||
|
const alertDialog = ref(null);
|
||||||
|
const editDialog = ref(null);
|
||||||
|
const confirmDialog = ref(null);
|
||||||
|
|
||||||
|
const openAlertDialog = () => {
|
||||||
|
alertDialog.value.open();
|
||||||
|
};
|
||||||
|
const openEditDialog = () => {
|
||||||
|
editDialog.value.open();
|
||||||
|
};
|
||||||
|
const openConfirmDialog = () => {
|
||||||
|
confirmDialog.value.open();
|
||||||
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const onConfirm = dialog => {};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Story title="Components/Dialog" :layout="{ type: 'grid', width: '100%' }">
|
||||||
|
<Variant title="Alert Dialog">
|
||||||
|
<Button label="Open Alert Dialog" @click="openAlertDialog" />
|
||||||
|
<Dialog
|
||||||
|
ref="alertDialog"
|
||||||
|
type="alert"
|
||||||
|
title="Alert"
|
||||||
|
description="This is an alert message."
|
||||||
|
/>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="Edit Dialog">
|
||||||
|
<Button label="Open Edit Dialog" @click="openEditDialog" />
|
||||||
|
<Dialog
|
||||||
|
ref="editDialog"
|
||||||
|
type="edit"
|
||||||
|
description="You can create a new portal here, by providing a name and a slug."
|
||||||
|
title="Create Portal"
|
||||||
|
confirm-button-label="Save"
|
||||||
|
@confirm="onConfirm()"
|
||||||
|
>
|
||||||
|
<template #form>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<Input
|
||||||
|
id="portal-name"
|
||||||
|
type="text"
|
||||||
|
placeholder="User Guide | Chatwoot"
|
||||||
|
label="Name"
|
||||||
|
message="This will be the name of your public facing portal"
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
id="portal-slug"
|
||||||
|
type="text"
|
||||||
|
placeholder="user-guide"
|
||||||
|
label="Slug"
|
||||||
|
message="app.chatwoot.com/hc/my-portal/en-US/categories/my-slug"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="Confirm Dialog">
|
||||||
|
<Button label="Open Confirm Dialog" @click="openConfirmDialog" />
|
||||||
|
<Dialog
|
||||||
|
ref="confirmDialog"
|
||||||
|
type="confirm"
|
||||||
|
title="Confirm Action"
|
||||||
|
description="Are you sure you want to perform this action?"
|
||||||
|
confirm-button-label="Yes, I'm sure"
|
||||||
|
cancel-button-label="No, cancel"
|
||||||
|
@confirm="onConfirm()"
|
||||||
|
/>
|
||||||
|
</Variant>
|
||||||
|
</Story>
|
||||||
|
</template>
|
||||||
109
app/javascript/dashboard/components-next/dialog/Dialog.vue
Normal file
109
app/javascript/dashboard/components-next/dialog/Dialog.vue
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { onClickOutside } from '@vueuse/core';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import Button from 'dashboard/components-next/button/Button.vue';
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'edit',
|
||||||
|
validator: value => ['alert', 'edit'].includes(value),
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
cancelButtonLabel: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
confirmButtonLabel: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['confirm']);
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const dialogRef = ref(null);
|
||||||
|
const dialogContentRef = ref(null);
|
||||||
|
|
||||||
|
const open = () => {
|
||||||
|
dialogRef.value?.showModal();
|
||||||
|
};
|
||||||
|
const close = () => {
|
||||||
|
dialogRef.value?.close();
|
||||||
|
};
|
||||||
|
const confirm = () => {
|
||||||
|
emit('confirm');
|
||||||
|
};
|
||||||
|
|
||||||
|
defineExpose({ open });
|
||||||
|
|
||||||
|
onClickOutside(dialogContentRef, event => {
|
||||||
|
if (
|
||||||
|
dialogRef.value &&
|
||||||
|
dialogRef.value.open &&
|
||||||
|
event.target === dialogRef.value
|
||||||
|
) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<dialog
|
||||||
|
ref="dialogRef"
|
||||||
|
class="w-full max-w-lg overflow-visible shadow-xl bg-modal-backdrop-light dark:bg-modal-backdrop-dark rounded-xl"
|
||||||
|
@close="close"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
ref="dialogContentRef"
|
||||||
|
class="flex flex-col w-full h-auto gap-6 p-6 overflow-visible text-left align-middle transition-all duration-300 ease-in-out transform bg-white shadow-xl dark:bg-slate-800 rounded-xl"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<h3
|
||||||
|
class="text-base font-medium leading-6 text-gray-900 dark:text-white"
|
||||||
|
>
|
||||||
|
{{ title }}
|
||||||
|
</h3>
|
||||||
|
<p
|
||||||
|
v-if="description"
|
||||||
|
class="mb-0 text-sm text-slate-500 dark:text-slate-400"
|
||||||
|
>
|
||||||
|
{{ description }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<slot name="form">
|
||||||
|
<!-- Form content will be injected here -->
|
||||||
|
</slot>
|
||||||
|
<div class="flex items-center justify-between w-full gap-3">
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
:label="cancelButtonLabel || t('DIALOG.BUTTONS.CANCEL')"
|
||||||
|
class="w-full"
|
||||||
|
size="sm"
|
||||||
|
@click="close"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
v-if="type !== 'alert'"
|
||||||
|
:variant="type === 'edit' ? 'default' : 'destructive'"
|
||||||
|
:label="confirmButtonLabel || t('DIALOG.BUTTONS.CONFIRM')"
|
||||||
|
class="w-full"
|
||||||
|
size="sm"
|
||||||
|
@click="confirm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
@@ -3,6 +3,12 @@
|
|||||||
"SHOWING": "Showing {startItem} - {endItem} of {totalItems} items",
|
"SHOWING": "Showing {startItem} - {endItem} of {totalItems} items",
|
||||||
"CURRENT_PAGE_INFO": "{currentPage} of {totalPages} pages"
|
"CURRENT_PAGE_INFO": "{currentPage} of {totalPages} pages"
|
||||||
},
|
},
|
||||||
|
"DIALOG": {
|
||||||
|
"BUTTONS": {
|
||||||
|
"CANCEL": "Cancel",
|
||||||
|
"CONFIRM": "Confirm"
|
||||||
|
}
|
||||||
|
},
|
||||||
"BREADCRUMB": {
|
"BREADCRUMB": {
|
||||||
"ARIA_LABEL": "Breadcrumb"
|
"ARIA_LABEL": "Breadcrumb"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user