-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from 3DStreet/notification-component
Notification component
- Loading branch information
Showing
6 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* global AFRAME */ | ||
var { Notyf } = require('../lib/notyf.min.js'); | ||
|
||
AFRAME.registerComponent('notify', { | ||
schema: { | ||
duration: { type: 'number', default: 2000 }, | ||
ripple: { type: 'boolean', default: true }, | ||
position: { | ||
type: 'string', | ||
default: { | ||
// x: left | center | right | ||
// y: top | center | bottom | ||
x: 'center', | ||
y: 'bottom' | ||
} | ||
}, | ||
dismissible: { type: 'boolean', default: false }, | ||
type: { type: 'string', default: 'info' }, | ||
message: { type: 'string', default: '' } | ||
}, | ||
init: function () { | ||
this.notify = new Notyf({ | ||
types: [ | ||
{ | ||
type: 'info', | ||
background: 'blue', | ||
icon: false | ||
} | ||
], | ||
// Set your global Notyf configuration here | ||
duration: this.data.duration, | ||
ripple: this.data.ripple, | ||
position: this.data.position, | ||
dismissible: this.data.dismissible | ||
}); | ||
this.types = this.notify.options.types.map(messType => messType.type); | ||
}, | ||
message: function (messageText, messageType = 'info') { | ||
if (messageText && this.types.includes(messageType)) { | ||
this.notify.open({ | ||
type: messageType, | ||
message: messageText | ||
}); | ||
} | ||
}, | ||
update: function (oldData) { | ||
// If `oldData` is empty, then this means we're in the initialization process. | ||
// No need to update. | ||
if (Object.keys(oldData).length === 0) { return; } | ||
|
||
const newMessage = this.data.message; | ||
const messageType = this.data.type; | ||
|
||
if (newMessage && this.types.includes(messageType)) { | ||
this.message(newMessage, messageType); | ||
this.data.message = ''; | ||
} | ||
} | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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