Skip to content

Commit

Permalink
Merge pull request #319 from 3DStreet/notification-component
Browse files Browse the repository at this point in the history
Notification component
  • Loading branch information
kfarr authored Jul 28, 2023
2 parents 278c40f + dfcf91a commit 9e7ef92
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
vr-mode-ui-if-headset
renderer="colorManagement: true; physicallyCorrectLights: true;"
inspector="url: //3dstreet.app/dist/3dstreet-editor.js"
notify
>
<a-assets>
<!-- uncomment the line below to load assets from local github submodule -->
Expand Down Expand Up @@ -176,6 +177,7 @@
}

createEntities(streetObject.data, streetContainerEl);
AFRAME.scenes[0].components['notify'].message('Scene loaded from JSON', 'success')
}

function inputJSON() {
Expand Down
59 changes: 59 additions & 0 deletions src/components/notify.js
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 = '';
}
}
});
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require('./components/gltf-part');
require('./lib/aframe-cursor-teleport-component.min.js');
require('./lib/animation-mixer.js');
require('./assets.js');
require('./components/notify.js');
require('./components/create-from-json');
require('./components/screentock.js');
require('aframe-atlas-uvs-component');
Expand Down
16 changes: 16 additions & 0 deletions src/lib/notyf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/notyf.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/viewer-styles.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import url("notyf.min.css");
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;500');

html {
font-family: 'Lato', sans-serif;
}
Expand Down

0 comments on commit 9e7ef92

Please sign in to comment.