From b88beffe499249f9d2742802339bcf27c171087d Mon Sep 17 00:00:00 2001 From: Paola De Bartolo Date: Fri, 19 Apr 2024 12:41:06 -0300 Subject: [PATCH 1/3] feat: add label support Close #19 --- .../vaadin/addons/badgelist/BadgeList.java | 14 ++++++- .../resources/frontend/src/fc-badge-list.ts | 40 +++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java b/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java index eca46dc..a66d963 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java +++ b/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java @@ -20,6 +20,7 @@ package com.flowingcode.vaadin.addons.badgelist; import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.HasLabel; import com.vaadin.flow.component.HasSize; import com.vaadin.flow.component.HasTheme; import com.vaadin.flow.component.Tag; @@ -36,7 +37,7 @@ @JsModule("@vaadin/vaadin-lumo-styles/badge-global.js") @JsModule("./src/fc-badge-list.ts") @Tag("fc-badge-list") -public class BadgeList extends Component implements HasTheme, HasSize { +public class BadgeList extends Component implements HasTheme, HasSize, HasLabel { private List badges = new ArrayList<>(); @@ -44,6 +45,16 @@ public class BadgeList extends Component implements HasTheme, HasSize { * Creates a new instance of BadgeList. */ public BadgeList() {} + + /** + * Creates a new instance of BadgeList with the given label. + * + * @param label the BadgeList label + */ + public BadgeList(String label) { + this(); + this.setLabel(label); + } /** * Creates a new instance of BadgeList with the supplied list of {@link Badge badges}. @@ -78,4 +89,5 @@ private void clearBadges() { badge.removeFromParent(); }); } + } diff --git a/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts b/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts index 928218a..624a10f 100644 --- a/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts +++ b/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts @@ -42,7 +42,10 @@ export class BadgeList extends ResizeMixin(ThemableMixin(LitElement)) { @property() theme : string | null = null; - + + @property() + label : '' + @state() private overflowItems: ContextMenuItem[] = []; @@ -52,11 +55,19 @@ export class BadgeList extends ResizeMixin(ThemableMixin(LitElement)) { :host { --badge-list-badges-margin: 0 calc(var(--lumo-space-s) / 2); + --badge-list-label-color: var(--lumo-secondary-text-color); + --badge-list-label-font-weight: 500; + --badge-list-label-font-size: var(--lumo-font-size-s); + --badge-list-label-margin-left: calc(var(--lumo-border-radius-m) / 4); } [part="container"] ::slotted(span[theme~="badge"]) { margin: var(--badge-list-badges-margin); } + + [part="container"] ::slotted(span[theme~="badge"]:first-child) { + margin-left: 0; + } [hidden] { display: none; @@ -73,6 +84,26 @@ export class BadgeList extends ResizeMixin(ThemableMixin(LitElement)) { [part="overflow-badge"] { margin: var(--badge-list-badges-margin); } + + [part="label"] { + align-self: flex-start; + color: var(--badge-list-label-color); + font-weight: var(--badge-list-label-font-weight); + font-size: var(--badge-list-label-font-size); + margin-left: var(--badge-list-label-margin-left); + transition: color 0.2s; + line-height: inherit; + padding-right: 1em; + padding-bottom: 0.5em; + padding-top: 0.25em; + margin-top: -0.25em; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + position: relative; + max-width: 100%; + box-sizing: border-box; + } ` ]; @@ -185,8 +216,11 @@ export class BadgeList extends ResizeMixin(ThemableMixin(LitElement)) { render() { return html` -
- +
+ +
+
+