Created
January 27, 2020 11:28
-
-
Save msjavan/5a30b1855542916037cbe35f863cb293 to your computer and use it in GitHub Desktop.
MyWidget
This file contains hidden or 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
import {Widget} from '@osjs/widgets'; | |
export default class MyWidget extends Widget { | |
constructor(core, options) { | |
super(core, options, { | |
// This widget uses a canvas | |
canvas: true, | |
fps: 1, | |
// Our default dimension | |
dimension: { | |
width: 300, | |
height: 50 | |
} | |
}, { | |
// Custom options that can be saved | |
myText: 'Hello World' | |
}); | |
// Other attributes are registered on your class: | |
this.color = '#ffffff'; | |
} | |
// When widget is destructed | |
onDestroy() {} | |
// When widget was resized | |
onResize() {} | |
// When widget was moved | |
onMove() {} | |
// Every rendering tick (or just once if no canvas) | |
render({canvas, context, width, height}) { | |
const text = this.options.myText; | |
context.font = 'monospace'; | |
context.fillStyle = this.color; | |
context.textAlign = 'center'; | |
context.textBaseline = 'middle'; | |
context.clearRect(0, 0, width, height); | |
context.fillText(text, width / 2, height / 2); | |
// The DOM elements is: | |
//this.$element | |
} | |
// A custom set of menu entries | |
getContextMenu() { | |
return [{ | |
label: 'My Menu Item', | |
onclick: () => console.log('Hello!') | |
}]; | |
} | |
} |
src/client/index.js :
import {WidgetServiceProvider} from '@osjs/widgets';
import {MyWidget} from '@osjs/widgets';
osjs.register(WidgetServiceProvider, { args: { registry: { 'my-widget': MyWidget } } });
What else are inside your folder src/widgets/MyWidget/
?
Is src/widgets
some sort of registered path with the build system?
I only see src/package
mentioned in documentation.
Sorry, This is very old issue, I can't remember the details.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I put this into src/widgets/MyWidget/index.js, and run build install.
got this error:
Uncaught TypeError: (0 , n.registry[t.name]) is not a constructor
at Object.create (provider.js:82)
at Object.onclick (provider.js:130)
at Object.onclick [as click] (Menu.js:90)
at HTMLDivElement.g (index.js:156)