diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js
index 35020cfa4..5fec19f72 100644
--- a/src/public/javascripts/widgets/component.js
+++ b/src/public/javascripts/widgets/component.js
@@ -2,19 +2,19 @@ import utils from '../services/utils.js';
import Mutex from "../services/mutex.js";
export default class Component {
- /**
- * @param {Component} parent
- */
- constructor(parent) {
+ constructor() {
this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6);
- /** @type Component */
- this.parent = parent;
/** @type Component[] */
this.children = [];
this.initialized = Promise.resolve();
this.mutex = new Mutex();
}
+ setParent(parent) {
+ /** @type Component */
+ this.parent = parent;
+ }
+
async handleEvent(name, data) {
await this.initialized;
diff --git a/src/public/javascripts/widgets/flex_container.js b/src/public/javascripts/widgets/flex_container.js
index cfe56b697..549618298 100644
--- a/src/public/javascripts/widgets/flex_container.js
+++ b/src/public/javascripts/widgets/flex_container.js
@@ -1,25 +1,62 @@
import BasicWidget from "./basic_widget.js";
export default class FlexContainer extends BasicWidget {
- constructor(parent, attrs, widgetFactories) {
- super(parent);
+ constructor(direction) {
+ super();
- this.attrs = attrs;
- this.children = widgetFactories.map(wf => wf(this));
+ if (!direction) {
+ throw new Error(`Direction argument missing, use either 'row' or 'column'`);
+ }
+
+ this.attrs = {
+ style: 'display: flex;'
+ };
+
+ this.children = [];
+ }
+
+ id(id) {
+ this.attrs.id = id;
+ return this;
+ }
+
+ css(name, value) {
+ this.attrs.style += `${name}: ${value};`;
+ return this;
+ }
+
+ rowFlex() {
+ this.css('flex-direction', 'row');
+ return this;
+ }
+
+ columnFlex() {
+ this.css('flex-direction', 'column');
+ return this;
+ }
+
+ cssBlock(block) {
+ this.cssEl = block;
+ return this;
+ }
+
+ child(widgetFactory) {
+ this.children = widgetFactory(this);
}
doRender() {
- this.$widget = $(`
`);
+ this.$widget = $(`
`);
+
+ if (this.cssEl) {
+ this.$widget.append($(`
+