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

fix(#19): support HTML content #27

Merged
merged 1 commit into from
Sep 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
6 changes: 4 additions & 2 deletions src/Snackbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 !== '';
}
9 changes: 7 additions & 2 deletions src/components/Snackbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -46,7 +50,8 @@ function close(){
:dark="level === 'warning' || level === 'error'"
@update:model-value="close()"
>
{{text}}
<span v-if="text">{{text}}</span>
<div v-if="htmlContent" v-html="htmlContent"></div>
</VSnackbar>
</VLayout>
</template>
Expand Down
3 changes: 2 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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. */
Expand Down Expand Up @@ -46,4 +46,4 @@
"**/cypress",
"**/node_modules",
]
}
}