From a2765d93837b3bbb6035ad9717286e4a0043e664 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 7 Oct 2024 21:21:15 +0200 Subject: [PATCH] FEAT,IMPRO: added linkBorder functionallity --- src/modifier.js | 12 ++++++++++ src/sizeSide/border.js | 50 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/modifier.js b/src/modifier.js index e6f153c..4902796 100644 --- a/src/modifier.js +++ b/src/modifier.js @@ -193,6 +193,18 @@ class Modifier { return new ShapeChain(this).all(cornerRadius); } } + + /** + * + * @param {number} borderWidth sets the width of all four border sides + * @returns {BorderChain} + */ + linkBorder(borderWidth = -1) { + if (borderWidth === -1) { + return new BorderChain(this); + } else { + return new BorderChain(this).all(borderWidth); + } } /** diff --git a/src/sizeSide/border.js b/src/sizeSide/border.js index 3313b39..336d0e0 100644 --- a/src/sizeSide/border.js +++ b/src/sizeSide/border.js @@ -159,4 +159,52 @@ class Border extends Sides { ] }) } -} \ No newline at end of file +} + + +class BorderChain extends Border { + constructor(modifier){ + super(); + this._modifier = modifier; + } + + /** + * + * @returns {Modifier|ChainableModifier} + */ + toModifier() { + return this._modifier + .border(this); + } + + /** + * + * @returns {Modifier|ChainableModifier} + */ + ensureModifier() { + return this.toModifier() + } + + /** + * Applies the border modification on the modifier + * and returns (through the modifier) to the corresponding component. + * @returns {Component} + */ + toComponent() { + return this._modifier + .dimensions(this) + .toComponent(); + } + + /** + * + * @param {Component} innerComponent will be set to the corresponding component + * @returns {Component} the corr. Component after the childContext was applied. + */ + childContext(innerComponent) { + return this._modifier + .dimensions(this) + .toComponent() + .childContext(innerComponent); + } +}