-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6474b7
commit c4f13e7
Showing
5 changed files
with
47 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
import { Notice, Plugin } from "obsidian"; | ||
|
||
// map the color to the color of the notice | ||
const colorMap = { | ||
success: "green", | ||
warning: "yellow", | ||
error: "red", | ||
info: "blue", | ||
}; | ||
|
||
export class NoticeManager { | ||
plugin: Plugin; | ||
constructor(plugin: Plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
createNotice = ( | ||
message: string | DocumentFragment, | ||
duration?: number | undefined | ||
message: string, | ||
duration?: number | undefined, | ||
color?: "success" | "warning" | "error" | "info" | ||
): Notice => { | ||
const notice = new Notice( | ||
`${this.plugin.manifest.name}: ${message}`, | ||
duration | ||
); | ||
let notice: Notice; | ||
if (color) { | ||
// create a fragment, create a div inside, set the color and text of the div | ||
const fragment = document.createDocumentFragment(); | ||
const div = document.createElement("div"); | ||
div.style.color = colorMap[color]; | ||
div.setText(`${this.plugin.manifest.name}: ${message}`); | ||
fragment.appendChild(div); | ||
|
||
notice = new Notice(fragment, duration); | ||
} else { | ||
notice = new Notice( | ||
`${this.plugin.manifest.name}: ${message}`, | ||
duration | ||
); | ||
} | ||
return notice; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"1.0.4": "0.15.0", | ||
"1.0.5": "0.15.0", | ||
"1.0.6": "0.15.0", | ||
"1.0.7": "0.15.0" | ||
"1.0.7": "0.15.0", | ||
"1.0.8": "0.15.0" | ||
} |