Compare commits

...

4 Commits

Author SHA1 Message Date
chris c0171aa8d8 IMPRO,FEAT: added modifyChildren 1 month ago
chris 6933a89111 IMPRO,REFA,FEAT: extended distributeSpacingEvengly 1 month ago
chris 7a40c27712 REFA,IMPRO: select elements are InputComponents as well 1 month ago
chris 6de0aca195 REFA,FIX,IMPRO: changed default behaviour of text() 1 month ago
  1. 16
      src/builder.js
  2. 6
      src/component/ChildbearerComponent.js
  3. 108
      src/component/FlexContainerComponent.js
  4. 18
      src/component/InputComponent.js

16
src/builder.js

@ -272,7 +272,21 @@ const builder = {
* @param {Modifier} modifier * @param {Modifier} modifier
* @returns {Component} * @returns {Component}
*/ */
select: function (attr = {}, modifier = null) { return builder.genTag("select", attr, modifier); }, select: function (attr = {}, modifier = null) {
let comp = new InputComponent(
document.createElement("select"),
attr,
modifier
)
.addStyleClass(`el-input`);
if (this.components.previous) {
comp._parentComponent = this.components.previous;
this.components.previous = null;
}
return comp;
},
/** /**
* *

6
src/component/ChildbearerComponent.js

@ -61,11 +61,7 @@ class ElementWrapper {
* @returns {Component} this component object * @returns {Component} this component object
*/ */
text(text) { text(text) {
if (this._element instanceof HTMLInputElement && this._element.type === "text") { this._element.innerText = text;
this._element.value = text;
} else {
this._element.innerText = text;
}
return this; return this;
} }

108
src/component/FlexContainerComponent.js

@ -9,6 +9,15 @@ class FlexContainerComponent extends Component {
* @type {boolean} * @type {boolean}
*/ */
_distributeEvenglyAfterGenerate; _distributeEvenglyAfterGenerate;
/**
* @type {number} the amount that should be left out of the total space before the children
* space is set.
*/
#distributionRecess;
/**
* @type {number} the additional gap that should be left for children before their space is set
*/
#distributionGapPerChild;
/** /**
* @type {string} * @type {string}
*/ */
@ -68,14 +77,86 @@ class FlexContainerComponent extends Component {
} }
/** /**
* *
* @param {number} [recessFraction=0.0] recessFraction a fraction/percentage of the recess
* that should be left out before distributing the remaining space.
* @param {number} [gapPerChild=1] gapPerChild the gap per child, therefore inbetween children
* that shouldn't be distributed to the children
*/
_distributingSpacing(recessFraction = 0.0, gapPerChild = 1) {
if (this._children && this._children.length > 1) {
let distributableSpace = 100 - 100 * recessFraction - (this._children.length - 1) * gapPerChild;
let childDistributionFraction = Math.floor(
(distributableSpace / this._children.length) * 100
) / 100;
let direction = (this._flexDirection === 'column' ? 'height' : "width");
for (const icomp of this._children) {
/* sets the width for all elements,
to avoid overlapping or line break because of lacking width,
a percent is subtracted for every child element */
/* To enable "override" a new Modifier is generated and joined
with the modifier of the component */
icomp._modifier._modifications[direction] = childDistributionFraction + "%";
icomp._modifier._modifications["max-" + direction] = childDistributionFraction + "%";
}
}
}
/**
* Distributes the spacing of the childrens evengly,
* according to the flexdirection of this component.
* By default this will be executed imediately when called.
*
* @param {boolean} [rightNow=true] if set to false it will set properties accordingly
* so that the distribution will be executed on generate
* @param {number} [recessFraction=0.0] recessFraction a fraction/percentage of the recess
* that should be left out before distributing the remaining space.
* @param {number} [gapPerChild=1] gapPerChild the gap per child, therefore inbetween children
* that shouldn't be distributed to the children
* @returns {FlexContainerComponent} * @returns {FlexContainerComponent}
*/ */
distibuteSpacingEvenly() { distibuteSpacingEvenly(rightNow = true, recessFraction = 0.0, gapPerChild = 1) {
this._distributeEvenglyAfterGenerate = true; if (rightNow) {
this._distributingSpacing(recessFraction, gapPerChild);
} else {
this.#distributionRecess = recessFraction;
this.#distributionGapPerChild = gapPerChild;
this._distributeEvenglyAfterGenerate = true;
}
return this; return this;
} }
/**
* Adds, sets, updates or overwrites the Modification of/for the children of this component.
* Just calls .modifier(modifier) on each child.
*
* @param {Modifier} modifier
* @param {boolean|ExtStorage|ExtStoreType|OverwriteBehaviour} [extStore=null]
* @returns {FlexContainerComponent} this component object
*/
modifyChildren(modifier, underTheName = "", extStore = false) {
if (underTheName === "") {
underTheName = `.${this._compName}-style-children`;
}
if (!extStore) {
for (const child of this._children) {
child.modifier(modifier)
}
} else {
this.addStyleClass(underTheName);
this._styles.push(
new SStoreDefinition(
underTheName,
modifier.ensureModifier()
)
);
}
return this;
}
/** /**
* @override * @override
@ -83,25 +164,8 @@ class FlexContainerComponent extends Component {
* @extends Component.generate() * @extends Component.generate()
*/ */
generate(generator = singlepage, styleStore = null, functionStore = null) { generate(generator = singlepage, styleStore = null, functionStore = null) {
if (this._children && this._children.length > 1) { if (this._distributeEvenglyAfterGenerate) {
this._distributingSpacing(this.#distributionRecess, this.#distributionGapPerChild);
if (this._distributeEvenglyAfterGenerate) {
let childDistributionFraction = Math.floor(
((100 - this._children.length) / this._children.length) * 100
) / 100;
let direction = (this._flexDirection === 'column' ? 'height' : "width");
for (const icomp of this._children) {
/* sets the width for all elements,
to avoid overlapping or line break because of lacking width,
a percent is subtracted for every child element */
/* To enable "override" a new Modifier is generated and joined
with the modifier of the component */
icomp._modifier._modifications[direction] = childDistributionFraction + "%";
icomp._modifier._modifications["max-" + direction] = childDistributionFraction + "%";
}
}
} }
return super.generate(generator, styleStore, functionStore); return super.generate(generator, styleStore, functionStore);

18
src/component/InputComponent.js

@ -18,6 +18,24 @@ class InputComponent extends Component {
} }
} }
/**
* This overrides the text() method in such a way,
* that it sets the value attribute for input elements instead.
*
* @override
* @inheritdoc
* @param {string} text
* @returns {InputComponent}
*/
text(text){
if (this._element instanceof HTMLInputElement) {
this._element.value = text;
} else {
super.text(text);
}
return this;
}
/** /**
* The parameter makes it optional to trigger the state by a variable * The parameter makes it optional to trigger the state by a variable
* @param {boolean} readonly * @param {boolean} readonly

Loading…
Cancel
Save