Skip to content

Commit

Permalink
panel.notification.info(message)
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Apr 30, 2024
1 parent ca7966d commit 154a573
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
13 changes: 13 additions & 0 deletions panel/lab/internals/panel/notification/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@
/>
</k-text>
</k-lab-example>
<k-lab-example label="info" :code="false">
<k-text>
<k-code language="js"
>window.panel.notification.info(notification);</k-code
>
<p>Displays an info notification</p>
<k-button
icon="megaphone"
variant="filled"
@click="$panel.notification.info('Did you know?')"
/>
</k-text>
</k-lab-example>
<k-lab-example label="message" :code="false">
<k-text>
<p>
Expand Down
2 changes: 1 addition & 1 deletion panel/src/panel/modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ describe.concurrent("panel/modal.js", () => {
message: "Test"
});

expect(panel.notification.type).toStrictEqual("success");
expect(panel.notification.message).toStrictEqual("Test");
expect(panel.notification.theme).toStrictEqual("positive");
});

it("should emit panel events after submit", async () => {
Expand Down
26 changes: 21 additions & 5 deletions panel/src/panel/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ export default (panel = {}) => {
});
},

/**
* Shortcut to create an info
* notification. You can pass a simple
* string or a state object.
*
* @param {Object|String} info
* @returns {Object} The notification state
*/
info(info = {}) {
if (typeof info === "string") {
info = { message: info };
}

return this.open({
icon: "info",
theme: "info",
...info
});
},

/**
* Checks if the notification is a fatal
* error. Those are displayed in the <k-fatal>
Expand Down Expand Up @@ -204,11 +224,7 @@ export default (panel = {}) => {
* @param {Object|String} success
* @returns {Object} The notification state
*/
success(success) {
if (!success) {
success = {};
}

success(success = {}) {
if (typeof success === "string") {
success = { message: success };
}
Expand Down
8 changes: 6 additions & 2 deletions panel/src/panel/notification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ describe("panel.notification", () => {
const notification = Notification(panel);

notification.success("Test");

expect(notification.theme).toStrictEqual("positive");

notification.error("Test");
notification.info("Test");
expect(notification.theme).toStrictEqual("info");

notification.error("Test");
expect(notification.theme).toStrictEqual("negative");

notification.open({ theme: "love" });
expect(notification.theme).toStrictEqual("love");
});

it("should set a timer for success notifications", async () => {
Expand Down

0 comments on commit 154a573

Please sign in to comment.