From 76b88a508a4e74340ca02c8fd7dbaf7b114cd0f5 Mon Sep 17 00:00:00 2001 From: pk Date: Fri, 9 May 2025 13:43:33 +0200 Subject: [PATCH] Add initialRightWidth and allow for number values too. --- package.json | 2 +- tp-vsplitter.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 31a0d9f..b9d08c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-splitter", - "version": "1.5.1", + "version": "1.6.0", "description": "", "main": "tp-splitter.js", "scripts": { diff --git a/tp-vsplitter.js b/tp-vsplitter.js index 4d0bc22..8ee88d1 100644 --- a/tp-vsplitter.js +++ b/tp-vsplitter.js @@ -61,6 +61,7 @@ class TpVSplitter extends LitElement { minSideWidth: { type: Number }, lateResize: { type: Boolean }, // if true, the panels will not be reized until the dragging is finished. initialLeftWidth: { type: String }, + initialRightWidth: { type: String }, }; } @@ -86,7 +87,15 @@ class TpVSplitter extends LitElement { firstUpdated() { if (this.initialLeftWidth) { - this.style.gridTemplateColumns = `${this.initialLeftWidth} var(--tp-splitter-width, 5px) 1fr`; + if (this.initialRightWidth) { + console.warn('Both initialLeftWidth and initialRightWidth are set. Using initialLeftWidth.'); + } + + const leftWidth = parseInt(this.initialLeftWidth, 10); + this.style.gridTemplateColumns = `${leftWidth}px var(--tp-splitter-width, 5px) 1fr`; + } else if (this.initialRightWidth) { + const rightWidth = parseInt(this.initialRightWidth, 10); + this.style.gridTemplateColumns = `1fr var(--tp-splitter-width, 5px) ${rightWidth}px`; } }