Skip to content

Commit

Permalink
add position context
Browse files Browse the repository at this point in the history
  • Loading branch information
sansil committed Sep 21, 2020
1 parent eac80ca commit 7de5310
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vt-notifications",
"description": "A headless vue notification library to use with tailwind",
"version": "0.2.1",
"version": "0.3.1",
"author": "sansil",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -38,4 +38,4 @@
"toast"
],
"license": "MIT"
}
}
7 changes: 5 additions & 2 deletions src/VTNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { state, methods } from "./notifications.js";
export default {
inject: {
context: { default: { group: "" } },
context: { default: { group: "", position: "top" } },
},
props: {
maxNotifications: {
Expand All @@ -22,7 +22,7 @@ export default {
leaveActiveClass: "transition ease-in duration-500",
leaveClass: "opacity-100",
leaveToClass: "opacity-0",
moveClass: "transition duration-500 ",
moveClass: "transition duration-500",
};
},
},
Expand Down Expand Up @@ -59,6 +59,9 @@ export default {
},
computed: {
sortedNotifications() {
if (this.context.position === "bottom")
return [...this.notificationsByGroup].slice(0, this.maxNotifications);
// if not bottom reverse the array
return [...this.notificationsByGroup]
.reverse()
.slice(0, this.maxNotifications);
Expand Down
10 changes: 9 additions & 1 deletion src/VTNotificationGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ export default {
type: String,
default: "",
},
position: {
type: String,
default: "top",
validator(value) {
return ["top", "bottom"].includes(value);
},
},
},
provide() {
return {
["context"]: { group: this.group },
["context"]: { group: this.group, position: this.position },
};
},
render() {
Expand Down

0 comments on commit 7de5310

Please sign in to comment.