diff --git a/src/Snackbar.ts b/src/Snackbar.ts index 0b0ed58..cf9bbed 100644 --- a/src/Snackbar.ts +++ b/src/Snackbar.ts @@ -43,11 +43,13 @@ export function createNotification(options: CreateNotifyOptions) { let locationX = potentialLocation.split(' ')[1] || 'right'; let div = document.createElement('div'); - if (!isNotEmptyAndNotNull(options.text)) throw new Error('text is required'); + if (!isNotEmptyAndNotNull(options.text) && !isNotEmptyAndNotNull(options.htmlContent)) + throw new Error('text or htmlContent is required'); return new Promise((resolve, reject) => { const props = { text: options.text, + htmlContent: options.htmlContent, level: options.level, location: potentialLocation, notifyOptions: options.notifyOptions || PluginContext.getPluginOptions()?.defaults?.notify || undefined, @@ -98,6 +100,6 @@ export function createNotification(options: CreateNotifyOptions) { } } -function isNotEmptyAndNotNull(value: string): boolean { +function isNotEmptyAndNotNull(value?: string): boolean { return value !== undefined && value !== null && value.trim().length > 0 && value !== ''; } diff --git a/src/components/Snackbar.vue b/src/components/Snackbar.vue index 97fa1d1..b1e6902 100644 --- a/src/components/Snackbar.vue +++ b/src/components/Snackbar.vue @@ -5,7 +5,11 @@ import { VSnackbar, VLayout } from 'vuetify/lib/components/index.mjs'; const props = defineProps({ text: { type: String, - required: true + required: false + }, + htmlContent: { + type: String, + default: false }, location: { type: String, @@ -46,7 +50,8 @@ function close(){ :dark="level === 'warning' || level === 'error'" @update:model-value="close()" > - {{text}} + {{text}} +
diff --git a/src/index.d.ts b/src/index.d.ts index 6d50a52..fec5678 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -59,7 +59,8 @@ export type CreateDialogOptions = { }; export type CreateNotifyOptions = { - text: string; + text?: string; + htmlContent?: string; level?: Level; location?: VSnackbar['$props']['location']; notifyOptions?: VSnackbar['$props']; diff --git a/src/types.ts b/src/types.ts index 8398431..aa7caaf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -59,7 +59,8 @@ export type CreateDialogOptions = { }; export type CreateNotifyOptions = { - text: string; + text?: string; + htmlContent?: string; level?: Level; location?: VSnackbar['$props']['location']; notifyOptions?: VSnackbar['$props']; diff --git a/tsconfig.json b/tsconfig.json index a9899a1..eb19b72 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - /* Set the JavaScript language version for emitted JavaScript and include + /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "target": "ESNext", /* Specify what JSX code is generated. */ @@ -46,4 +46,4 @@ "**/cypress", "**/node_modules", ] -} \ No newline at end of file +}