2021-07-31 14:45:28 -08:00
|
|
|
<template>
|
|
|
|
<v-btn
|
2021-08-02 22:15:11 -08:00
|
|
|
:color="color || btnAttrs.color"
|
2025-06-20 00:09:12 +07:00
|
|
|
:size="small ? 'small' : 'default'"
|
2021-07-31 14:45:28 -08:00
|
|
|
:x-small="xSmall"
|
|
|
|
:loading="loading"
|
|
|
|
:disabled="disabled"
|
2025-06-20 00:09:12 +07:00
|
|
|
:variant="disabled ? 'tonal' : btnStyle.outlined ? 'outlined' : btnStyle.text ? 'text' : 'elevated'"
|
2021-07-31 14:45:28 -08:00
|
|
|
:to="to"
|
2021-10-19 18:45:03 -08:00
|
|
|
v-bind="$attrs"
|
2021-08-21 00:46:43 -08:00
|
|
|
@click="download ? downloadFile() : undefined"
|
2021-07-31 14:45:28 -08:00
|
|
|
>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-icon
|
|
|
|
v-if="!iconRight"
|
|
|
|
start
|
|
|
|
>
|
2021-07-31 14:45:28 -08:00
|
|
|
<slot name="icon">
|
2024-05-22 16:58:16 -05:00
|
|
|
{{ icon || btnAttrs.icon }}
|
2021-07-31 14:45:28 -08:00
|
|
|
</slot>
|
|
|
|
</v-icon>
|
|
|
|
<slot name="default">
|
2024-05-22 16:58:16 -05:00
|
|
|
{{ text || btnAttrs.text }}
|
2021-07-31 14:45:28 -08:00
|
|
|
</slot>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-icon
|
|
|
|
v-if="iconRight"
|
|
|
|
end
|
|
|
|
>
|
2021-11-05 15:48:10 -08:00
|
|
|
<slot name="icon">
|
2024-05-22 16:58:16 -05:00
|
|
|
{{ icon || btnAttrs.icon }}
|
2021-11-05 15:48:10 -08:00
|
|
|
</slot>
|
|
|
|
</v-icon>
|
2021-07-31 14:45:28 -08:00
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
<script lang="ts">
|
2021-11-06 11:28:47 -08:00
|
|
|
import { useUserApi } from "~/composables/api";
|
2022-01-09 07:15:23 +01:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
export default defineNuxtComponent({
|
2021-07-31 14:45:28 -08:00
|
|
|
name: "BaseButton",
|
|
|
|
props: {
|
|
|
|
// Types
|
|
|
|
cancel: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
create: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
update: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-08-31 14:39:02 -08:00
|
|
|
save: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-07-31 14:45:28 -08:00
|
|
|
delete: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-08-21 00:46:43 -08:00
|
|
|
// Download
|
|
|
|
download: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
downloadUrl: {
|
|
|
|
type: String,
|
|
|
|
default: "",
|
|
|
|
},
|
2021-07-31 14:45:28 -08:00
|
|
|
// Property
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
// Styles
|
|
|
|
small: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
xSmall: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
secondary: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
minor: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-08-02 22:15:11 -08:00
|
|
|
color: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
2024-05-22 16:58:16 -05:00
|
|
|
text: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-11-05 15:48:10 -08:00
|
|
|
iconRight: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-07-31 14:45:28 -08:00
|
|
|
},
|
2022-01-09 07:15:23 +01:00
|
|
|
setup(props) {
|
2025-06-20 00:09:12 +07:00
|
|
|
const i18n = useI18n();
|
|
|
|
const { $globals } = useNuxtApp();
|
2022-01-09 07:15:23 +01:00
|
|
|
const buttonOptions = {
|
|
|
|
create: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.create"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.createAlt,
|
|
|
|
color: "success",
|
|
|
|
},
|
|
|
|
update: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.update"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.edit,
|
|
|
|
color: "success",
|
|
|
|
},
|
|
|
|
save: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.save"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.save,
|
|
|
|
color: "success",
|
|
|
|
},
|
|
|
|
edit: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.edit"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.edit,
|
|
|
|
color: "info",
|
2021-07-31 14:45:28 -08:00
|
|
|
},
|
2022-01-09 07:15:23 +01:00
|
|
|
delete: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.delete"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.delete,
|
|
|
|
color: "error",
|
|
|
|
},
|
|
|
|
cancel: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.cancel"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.close,
|
|
|
|
color: "grey",
|
|
|
|
},
|
|
|
|
download: {
|
2022-08-15 23:55:51 +02:00
|
|
|
text: i18n.t("general.download"),
|
2022-01-09 07:15:23 +01:00
|
|
|
icon: $globals.icons.download,
|
|
|
|
color: "info",
|
2021-07-31 14:45:28 -08:00
|
|
|
},
|
|
|
|
};
|
2022-01-09 07:15:23 +01:00
|
|
|
|
|
|
|
const btnAttrs = computed(() => {
|
|
|
|
if (props.delete) {
|
|
|
|
return buttonOptions.delete;
|
2025-06-20 00:09:12 +07:00
|
|
|
}
|
|
|
|
else if (props.update) {
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonOptions.update;
|
2025-06-20 00:09:12 +07:00
|
|
|
}
|
|
|
|
else if (props.edit) {
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonOptions.edit;
|
2025-06-20 00:09:12 +07:00
|
|
|
}
|
|
|
|
else if (props.cancel) {
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonOptions.cancel;
|
2025-06-20 00:09:12 +07:00
|
|
|
}
|
|
|
|
else if (props.save) {
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonOptions.save;
|
2025-06-20 00:09:12 +07:00
|
|
|
}
|
|
|
|
else if (props.download) {
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonOptions.download;
|
2021-07-31 14:45:28 -08:00
|
|
|
}
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonOptions.create;
|
|
|
|
});
|
|
|
|
|
|
|
|
const buttonStyles = {
|
|
|
|
defaults: {
|
|
|
|
text: false,
|
|
|
|
outlined: false,
|
|
|
|
},
|
|
|
|
secondary: {
|
|
|
|
text: false,
|
|
|
|
outlined: true,
|
|
|
|
},
|
|
|
|
minor: {
|
|
|
|
text: true,
|
|
|
|
outlined: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const btnStyle = computed(() => {
|
|
|
|
if (props.secondary) {
|
|
|
|
return buttonStyles.secondary;
|
2025-06-20 00:09:12 +07:00
|
|
|
}
|
|
|
|
else if (props.minor || props.cancel) {
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonStyles.minor;
|
2021-07-31 14:45:28 -08:00
|
|
|
}
|
2022-01-09 07:15:23 +01:00
|
|
|
return buttonStyles.defaults;
|
|
|
|
});
|
|
|
|
|
|
|
|
const api = useUserApi();
|
|
|
|
function downloadFile() {
|
|
|
|
api.utils.download(props.downloadUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
btnAttrs,
|
|
|
|
btnStyle,
|
|
|
|
downloadFile,
|
|
|
|
};
|
2021-07-31 14:45:28 -08:00
|
|
|
},
|
2022-01-09 07:15:23 +01:00
|
|
|
});
|
2021-07-31 14:45:28 -08:00
|
|
|
</script>
|