From e8b06776e14fda61e36bd5e6f144a56c607d9fd2 Mon Sep 17 00:00:00 2001 From: solstice23 Date: Mon, 4 Apr 2022 17:34:49 +0800 Subject: [PATCH] Support adaptive width (column=-1) (#130) * Support adaptive width * Update readme * Fix typo error * Delete package-lock.json --- README.md | 7 +++++++ src/card.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index dbaccd4..b4d09bf 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,13 @@ https://github-profile-trophy.vercel.app/?username=ryo-ma&row=2&column=3

+Adaptive column +``` +https://github-profile-trophy.vercel.app/?username=ryo-ma&column=-1 +``` + +You can set `columns` to `-1` to adapt the width to the number of trophies, the parameter `row` will be ignored. + ## Apply theme Available themes. diff --git a/src/card.ts b/src/card.ts index 1763a31..3403c97 100644 --- a/src/card.ts +++ b/src/card.ts @@ -38,6 +38,12 @@ export class Card { trophyList.sortByRank(); + if (this.maxColumn == -1) { + this.maxColumn = trophyList.length; + this.width = this.panelSize * this.maxColumn + + this.marginWidth * (this.maxColumn - 1); + } + const row = this.getRow(trophyList); this.height = this.getHeight(row);