Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-button): add badge to ui5-button #10642

Merged
merged 14 commits into from
Jan 29, 2025
Merged

Conversation

tsanislavgatev
Copy link
Contributor

@tsanislavgatev tsanislavgatev commented Jan 23, 2025

Implementing the badge concept in theui5-button component.

How to use:

<ui5-button design="Emphasized" icon="employee">Notifications
       <ui5-button-badge design="OverlayText" text="999+" slot="badge"></ui5-button-badge>
</ui5-button>

The badge in ui5-button provides 3 designs: InlineText, OverlayText and AttentionDot looking like:
Screenshot 2025-01-28 at 13 51 00

fixes: #10683

@vladitasev
Copy link
Contributor

vladitasev commented Jan 23, 2025

Another API idea:

  • we don't talk about Top/TopRight(TopEnd) but instead use completely different terms that are independent of top/right: OverlyText (top right), InlineText (right) and AttentionDot
  • we don't assume that empty text means "dot"

Variant 1:

  • badgeDesign: None (default), OverlayText, InlineText, AttentionDot
  • badgeText: string (this property is ignored when badgeDesign is set to Dot or None)

Example:

<ui5-button badge-design="AttentionDot">Messages</ui5-button>
<ui5-button badge-design="InlineText" badge-text="99+">Messages</ui5-button> 
<ui5-button badge-design="OverlayText" badge-text="99+">Messages</ui5-button>

Variant 2:

  • badgeDesign: OverlayText, InlineText (default), AttentionDot
  • badgeText: string (this property is ignored when badgeDesign is set to AttentionDot)

there is no None option, badgeDesign is InlineText by default, but if there is no badgeText, we show nothing

Same as 1) but there is no None option

Example:

<ui5-button badge-design="AttentionDot">Messages</ui5-button>
<ui5-button badge-text="99+">Messages</ui5-button> <!-- inline by default as it works for cozy/compact -->
<ui5-button badge-text="99+" badge-design="OverlayText">Messages</ui5-button>

Variant 3:

We split the enum.

  • attentionDot: boolean
  • badgeText: string. This property is ignored when attentionDot is set to true.
  • badgeDesign: Overlay, Inline (default). This property is ignored when attentionDot is set to true.

Example:

<ui5-button attention-dot>Messages</ui5-button>
<ui5-button badge-text="99+">Messages</ui5-button> <!-- inline by default as it works for cozy/compact -->
<ui5-button badge-text="99+" badge-design="Overlay">Messages</ui5-button>

Variant 4:

  • attentionDot: boolean
  • badgeText: string. This property is ignored when attentionDot is set to true.
  • badgeTextOverlaid: boolean. This property is ignored when attentionDot is set to true.

Same as 3) but the enum is now a boolean (which however sounds strange)

Example:

<ui5-button attention-dot>Messages</ui5-button>
<ui5-button badge-text="99+">Messages</ui5-button> <!-- inline by default as it works for cozy/compact -->
<ui5-button badge-text="99+" badge-text-overlaid>Messages</ui5-button>

@tsanislavgatev tsanislavgatev marked this pull request as ready for review January 28, 2025 11:50
Copy link
Contributor Author

@tsanislavgatev tsanislavgatev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add website sample

@tsanislavgatev tsanislavgatev changed the title WIP(ui5-button): add badge functionality feat(ui5-button): add badge to ui5-button Jan 28, 2025
Copy link
Contributor

@vladitasev vladitasev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I have a few very minor comments.

Let's discuss the idea of making the badge an optional feature tomorrow. We can do it exactly like in ColorPalette - just import the extra template with the <ui5-tag> dynamically.

packages/main/src/Button.ts Outdated Show resolved Hide resolved
packages/main/src/Button.ts Outdated Show resolved Hide resolved
packages/main/src/Button.ts Outdated Show resolved Hide resolved
packages/main/src/Button.ts Outdated Show resolved Hide resolved
packages/main/src/ButtonBadge.ts Outdated Show resolved Hide resolved
packages/main/src/ButtonBadge.ts Show resolved Hide resolved
packages/main/src/ButtonBadge.ts Show resolved Hide resolved
packages/main/src/ButtonTemplate.tsx Outdated Show resolved Hide resolved
packages/main/src/types/BadgeDesign.ts Outdated Show resolved Hide resolved
packages/main/src/Button.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@vladitasev vladitasev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's a separate component, add it in bundle.common.ts after the Button import.

packages/main/README.md Outdated Show resolved Hide resolved
packages/main/src/Button.ts Outdated Show resolved Hide resolved
packages/main/src/Button.ts Outdated Show resolved Hide resolved
packages/main/src/ButtonBadge.ts Show resolved Hide resolved
packages/main/src/ButtonBadge.ts Outdated Show resolved Hide resolved
packages/main/src/types/BadgeDesign.ts Outdated Show resolved Hide resolved
packages/main/src/types/BadgeDesign.ts Outdated Show resolved Hide resolved
packages/main/src/types/BadgeDesign.ts Outdated Show resolved Hide resolved
packages/main/src/types/BadgeDesign.ts Outdated Show resolved Hide resolved
packages/main/src/types/BadgeDesign.ts Outdated Show resolved Hide resolved
@dimovpetar
Copy link
Contributor

Approving new part of Tag

import type Button from "./Button.js";
import Tag from "./Tag.js";

export default function ButtonTemplate(this: Button) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here this must be ButtonBadge (but works with Button too, because they both have a text property). We can fix this later in another PR along with something else, do not push again just for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsanislavgatev tsanislavgatev merged commit 1e693fd into main Jan 29, 2025
10 checks passed
@tsanislavgatev tsanislavgatev deleted the badge-button-poc branch January 29, 2025 14:32
@ui5-webcomponents-bot
Copy link
Collaborator

🎉 This PR is included in version v2.7.0-rc.2 🎉

The release is available on v2.7.0-rc.2

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui5-button: Add Badge
4 participants