jws-frontend/src/components/DrawerInfo.vue

250 lines
6 KiB
Vue
Raw Normal View History

2024-04-18 18:27:22 +07:00
<script setup lang="ts">
2024-08-01 08:44:40 +00:00
import { ref } from 'vue';
2024-08-08 04:59:57 +00:00
import {
EditButton,
DeleteButton,
CancelButton,
SaveButton,
UndoButton,
2024-08-09 14:02:40 +07:00
} from 'components/button';
const props = withDefaults(
defineProps<{
title: string;
category?: string;
isEdit?: boolean;
bgOn?: boolean;
statusBranch?: string;
badgeLabel?: string;
badgeClass?: string;
2024-09-17 18:01:13 +07:00
badgeStyle?: string;
bgColor?: string;
2024-08-09 02:10:06 +00:00
hideAction?: boolean;
editData?: (...args: unknown[]) => void;
deleteData?: (...args: unknown[]) => void;
submit?: (...args: unknown[]) => void;
close?: (...args: unknown[]) => void;
undo?: (...args: unknown[]) => void;
2024-08-06 16:33:17 +07:00
beforeClose?: (...args: unknown[]) => boolean;
2024-09-05 15:01:35 +07:00
show?: (...args: unknown[]) => void;
}>(),
{
2024-08-09 02:10:06 +00:00
hideAction: false,
},
);
2024-04-18 18:27:22 +07:00
const windowSize = ref(window.innerWidth);
2024-04-18 18:27:22 +07:00
const drawerOpen = defineModel<boolean>('drawerOpen', {
default: false,
});
const myForm = ref();
function reset() {
if (props.beforeClose) {
drawerOpen.value = props.beforeClose
? props.beforeClose()
: !drawerOpen.value;
}
if (myForm.value) {
myForm.value.resetValidation();
}
}
async function onValidationError(ref: any) {
const el = ref.$el as Element;
el.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest',
});
}
2024-04-18 18:27:22 +07:00
</script>
<template>
<q-drawer
2024-07-03 09:31:56 +00:00
no-swipe-open
2024-09-05 15:01:35 +07:00
@show="show"
@before-hide="reset"
2024-04-18 18:27:22 +07:00
@hide="close"
2024-08-02 13:59:02 +07:00
:width="$q.screen.gt.xs ? windowSize * 0.85 : windowSize"
2024-04-18 18:27:22 +07:00
v-model="drawerOpen"
behavior="mobile"
side="right"
show-if-above
>
<q-form
ref="myForm"
class="full-height"
greedy
@submit.prevent
@validation-success="submit"
@validation-error="onValidationError"
2024-04-18 18:27:22 +07:00
>
2024-07-01 08:40:37 +00:00
<div
class="column justify-between full-height"
style="padding: 0; border-radius: var(--radius-2)"
>
2024-07-30 09:44:21 +00:00
<!-- header -->
2024-09-27 15:21:19 +07:00
<div
class="bordered-b row items-center"
:class="{
'q-px-lg q-py-md': $q.screen.gt.sm,
'q-py-xs': !$q.screen.gt.sm,
}"
>
2024-08-09 02:10:06 +00:00
<div v-if="!hideAction">
<div v-if="isEdit" class="row">
2024-08-09 02:27:08 +00:00
<UndoButton id="btn-info-undo" iconOnly @click="undo" />
2024-08-09 02:10:06 +00:00
<div style="width: 38.8px"></div>
</div>
2024-08-08 04:59:57 +00:00
<div v-else class="row">
2024-08-09 02:27:08 +00:00
<EditButton id="btn-info-edit" iconOnly @click="editData" />
2024-08-08 04:59:57 +00:00
<DeleteButton id="btn-info-delete" iconOnly @click="deleteData" />
</div>
</div>
2024-08-09 02:10:06 +00:00
<div v-else style="width: 38.8px"></div>
2024-08-20 18:04:42 +07:00
<div
class="col text-weight-bold text-center ellipsis"
style="width: 0px"
>
<text
v-if="badgeLabel"
class="badge-label badge text-caption q-px-sm q-mr-sm"
:class="badgeClass"
2024-09-17 18:01:13 +07:00
:style="badgeStyle"
>
{{ badgeLabel }}
</text>
<text v-if="category" class="app-text-muted q-mr-sm">
{{ category }}
</text>
2024-09-04 14:35:53 +07:00
<slot name="badgeList">
<span>
{{ title }}
</span>
2024-04-19 13:12:56 +07:00
2024-09-04 14:35:53 +07:00
<text
v-if="!!statusBranch"
class="branch-badge branch-card__badge q-ml-sm"
:class="{
'branch-card__inactive ': statusBranch === 'INACTIVE',
}"
>
{{
statusBranch === 'INACTIVE'
? $t('status.INACTIVE')
: $t('status.ACTIVE')
}}
</text>
</slot>
</div>
2024-04-18 18:27:22 +07:00
2024-08-09 02:10:06 +00:00
<div v-if="!hideAction" class="q-mr-md" style="width: 38.8px"></div>
2024-08-08 04:59:57 +00:00
<CancelButton
icon-only
2024-08-08 06:11:47 +00:00
id="btn-info-close"
2024-08-06 16:33:17 +07:00
@click="
() => {
drawerOpen = beforeClose ? beforeClose() : !drawerOpen;
close?.();
}
"
2024-08-08 04:59:57 +00:00
type="reset"
resetValidation
/>
2024-04-18 18:27:22 +07:00
</div>
2024-07-25 10:48:04 +00:00
2024-07-30 09:44:21 +00:00
<!-- body -->
<div
2024-07-30 09:44:21 +00:00
class="col form-body full-width"
2024-10-04 09:45:05 +07:00
:class="`${bgColor || 'surface-2'} ${$q.dark.isActive && 'dark'}`"
>
<slot></slot>
<slot name="info"></slot>
</div>
2024-04-18 18:27:22 +07:00
2024-07-30 09:44:21 +00:00
<!-- footer -->
2024-09-27 15:21:19 +07:00
<div
class="bordered-t row items-center justify-end"
:class="{
'q-pr-lg q-py-md': $q.screen.gt.sm,
'q-pr-xs q-py-xs': !$q.screen.gt.sm,
}"
>
2024-09-05 15:01:35 +07:00
<CancelButton
id="btn-info-cancel"
outlined
@click="
() => {
drawerOpen = beforeClose ? beforeClose() : !drawerOpen;
close?.();
}
"
/>
2024-08-08 04:59:57 +00:00
<SaveButton
class="q-ml-md"
id="btn-info-save"
2024-08-09 02:10:06 +00:00
v-if="isEdit && !hideAction"
type="submit"
2024-08-08 04:59:57 +00:00
solid
/>
</div>
2024-07-01 08:40:37 +00:00
</div>
</q-form>
2024-04-18 18:27:22 +07:00
</q-drawer>
</template>
<style scoped lang="scss">
.close-btn {
color: hsl(var(--negative-bg));
background-color: hsla(var(--negative-bg) / 0.1);
&.dark {
background-color: transparent;
border: 1px solid hsl(var(--negative-bg));
}
}
.form-body {
--_body-bg: var(--sand-0);
background-color: var(--_body-bg);
background-repeat: no-repeat;
background-size: cover;
&.dark {
--_body-bg: var(--gray-10);
}
}
2024-04-19 13:12:56 +07:00
.branch-badge {
--_branch-badge-fg: var(--green-8-hsl);
--_branch-badge-bg: var(--green-6-hsl);
&.branch-card__inactive {
--_branch-badge-fg: var(--red-4-hsl);
--_branch-badge-bg: var(--red-4-hsl);
}
&.branch-card__badge {
display: inline-block;
border-radius: 999rem;
padding-inline: var(--size-2);
color: hsl(var(--_branch-badge-fg));
background-color: hsla(var(--_branch-badge-bg) / 0.1);
}
}
2024-04-22 14:04:06 +07:00
.badge-label {
display: inline-block;
text-wrap: nowrap;
}
.badge {
display: inline-block;
border-radius: var(--radius-6);
2024-07-03 02:46:27 +00:00
background-color: var(--surface-tab);
text-wrap: nowrap;
}
2024-04-18 18:27:22 +07:00
</style>