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-badge): add different design types #7564

Merged
merged 59 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
372ac20
feat(ui5-badge): add different design types
TeodorTaushanov Sep 8, 2023
11f6a03
feat(ui5-badge): fix lint errors
TeodorTaushanov Sep 8, 2023
5229942
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Sep 18, 2023
8d72e9c
feat(ui5-badge): fix lint errors
TeodorTaushanov Sep 18, 2023
79bcff8
feat(ui5-badge): fix typo
TeodorTaushanov Sep 18, 2023
a616b57
feat(ui5-badge): rename enums and properties
TeodorTaushanov Sep 18, 2023
ae3c053
feat(ui5-badge): rename enums and properties
TeodorTaushanov Sep 18, 2023
1a9ae93
feat(ui5-badge): rename enums and properties
TeodorTaushanov Sep 18, 2023
2e9ae0e
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Sep 20, 2023
11f538d
feat(ui5-badge): improve example
TeodorTaushanov Sep 20, 2023
33e06b9
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Sep 25, 2023
9ed9478
feat(ui5-badge): add "click" event
TeodorTaushanov Sep 25, 2023
847687e
feat(ui5-badge): value state desing types
TeodorTaushanov Sep 25, 2023
269d91c
feat(ui5-badge): add different design types
TeodorTaushanov Sep 26, 2023
ab45cd5
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Sep 26, 2023
a8e4853
feat(ui5-badge): add default state icon
TeodorTaushanov Sep 26, 2023
bde4f8d
feat(ui5-badge): fix lint errors
TeodorTaushanov Sep 26, 2023
94bc65f
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Sep 27, 2023
1e72921
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Oct 9, 2023
70f52a7
feat(ui5-badge): add samples with only styles
TeodorTaushanov Oct 9, 2023
018a351
feat(ui5-badge): improve styling
TeodorTaushanov Oct 10, 2023
6666e96
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Oct 10, 2023
9799f66
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Nov 20, 2023
b12f75b
refactor(ui5-badge): change properties
TeodorTaushanov Nov 20, 2023
0ff75fd
refactor(ui5-badge): fix button-like styles
TeodorTaushanov Nov 20, 2023
1e56f76
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Nov 21, 2023
d599679
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Nov 22, 2023
ce3f7e3
fix(ui5-badge): test wrapping mode
TeodorTaushanov Nov 22, 2023
c94fc0e
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Nov 23, 2023
3f9b174
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Nov 24, 2023
d39c743
fix(ui5-badge): add wrapping mode
TeodorTaushanov Nov 24, 2023
17dab20
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 4, 2023
6e0795e
fix(ui5-badge): use flex layout
TeodorTaushanov Dec 4, 2023
c600de7
fix(ui5-badge): tag styles
TeodorTaushanov Dec 5, 2023
ecc2c03
fix(ui5-badge): fix shadows
TeodorTaushanov Dec 5, 2023
50dc0b2
fix(ui5-badge): improve styles
TeodorTaushanov Dec 5, 2023
fd49d0b
fix(ui5-badge): add tests
TeodorTaushanov Dec 5, 2023
cb97ba1
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 5, 2023
070fbe1
fix(ui5-badge): improve documentation
TeodorTaushanov Dec 5, 2023
24685d7
fix(ui5-badge): improve documentation
TeodorTaushanov Dec 6, 2023
0ad1767
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 6, 2023
15f010c
fix(ui5-badge): improve documentation
TeodorTaushanov Dec 6, 2023
a4b5180
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 7, 2023
a6d2b16
fix(ui5-badge): fix accessibility
TeodorTaushanov Dec 7, 2023
e166b3c
fix(ui5-badge): add samples
TeodorTaushanov Dec 8, 2023
b796426
fix(ui5-badge): add tests
TeodorTaushanov Dec 8, 2023
06b9654
fix(ui5-badge): fix typo
TeodorTaushanov Dec 8, 2023
e03b8a5
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 8, 2023
4c4cf17
fix(ui5-badge): improve test page
TeodorTaushanov Dec 8, 2023
6709e57
fix(ui5-badge): hc themes
TeodorTaushanov Dec 12, 2023
b112aed
fix(ui5-badge): styles
TeodorTaushanov Dec 12, 2023
ce01e1a
Merge remote-tracking branch 'origin' into badge_interactive
TeodorTaushanov Dec 13, 2023
045e025
fix(ui5-badge): fix comments
TeodorTaushanov Dec 13, 2023
816888f
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 21, 2023
2a5d378
fix(ui5-badge): add more descriptions for design types
TeodorTaushanov Dec 21, 2023
11b28a8
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Dec 22, 2023
60a022d
fix(ui5-badge): fix comments
TeodorTaushanov Dec 22, 2023
4b94c75
Merge remote-tracking branch 'origin/main' into badge_interactive
TeodorTaushanov Jan 8, 2024
778b4cd
fix(ui5-badge): fix css styles
TeodorTaushanov Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions packages/main/src/Badge.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
<div class="ui5-badge-root">
<slot name="icon"></slot>
{{#if interactive}}
<button class="ui5-badge-root"
title="{{_title}}"
aria-roledescription="{{_roleDescription}}"
aria-description="{{_valueState}}"
@onclick={{_onclick}}
>
{{> content}}
</button>
{{else}}
<div class="ui5-badge-root"
title="{{_title}}">
{{> content}}
</div>
{{/if}}

{{#*inline "content"}}
<slot name="icon"></slot>
{{#if this._semanticIconName}}
<ui5-icon class="ui5-badge-semantic-icon" name="{{_semanticIconName}}"></ui5-icon>
{{/if}}
<span class="ui5-hidden-text">{{badgeDescription}}</span>
{{#if hasText}}
<label class="ui5-badge-text"><bdi><slot></slot></bdi></label>
<span class="ui5-badge-text"><bdi><slot></slot></bdi></span>
{{/if}}
{{/inline}}




<span class="ui5-hidden-text">{{badgeDescription}}</span>
</div>
167 changes: 158 additions & 9 deletions packages/main/src/Badge.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import event from "@ui5/webcomponents-base/dist/decorators/event.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import willShowContent from "@ui5/webcomponents-base/dist/util/willShowContent.js";

import Icon from "./Icon.js";
import "@ui5/webcomponents-icons/dist/sys-help-2.js";
import "@ui5/webcomponents-icons/dist/sys-enter-2.js";
import "@ui5/webcomponents-icons/dist/error.js";
import "@ui5/webcomponents-icons/dist/alert.js";
import "@ui5/webcomponents-icons/dist/information.js";
import WrappingType from "./types/WrappingType.js";
import BadgeDesign from "./types/BadgeDesign.js";
// Template
import BadgeTemplate from "./generated/templates/BadgeTemplate.lit.js";

import { BADGE_DESCRIPTION } from "./generated/i18n/i18n-defaults.js";
import {
BADGE_DESCRIPTION_BADGE,
BADGE_DESCRIPTION_TAG,
BADGE_ROLE_DESCRIPTION,
BADGE_ERROR,
BADGE_WARNING,
BADGE_SUCCESS,
BADGE_INFORMATION,
} from "./generated/i18n/i18n-defaults.js";

// Styles
import badgeCss from "./generated/themes/Badge.css.js";
Expand All @@ -19,14 +35,15 @@ import badgeCss from "./generated/themes/Badge.css.js";
* @class
* <h3 class="comment-api-title">Overview</h3>
*
* The <code>ui5-badge</code> is a small non-interactive component which contains text information and color chosen from a list of predefined color schemes.
* It serves the purpose to attract the user attention to some piece of information (state, quantity, condition, etc.).
* The <code>ui5-badge</code> is a component which serves
* the purpose to attract the user attention to some piece
* of information (state, quantity, condition, etc.).
* It can contain icon and text information, and its design can be chosen from specific design types.
*
* <h3>Usage Guidelines</h3>
* <ul>
* <li>If the text is longer than the width of the component, it doesn’t wrap, it shows ellipsis.</li>
* <li>When truncated, the full text is not visible, therefore, it’s recommended to make more space for longer texts to be fully displayed.</li>
* <li>Colors are not semantic and have no visual representation in High Contrast Black (sap_belize_hcb) theme.</li>
* <li>If the text is longer than the width of the component, it can wrap, or it can show ellipsis, depending on the <code>wrappingType</code> property.</li>
* <li>Colors can be semantic or not semantic.</li>
* </ul>
*
* <h3>ES6 Module Import</h3>
Expand All @@ -47,8 +64,31 @@ import badgeCss from "./generated/themes/Badge.css.js";
renderer: litRender,
template: BadgeTemplate,
styles: badgeCss,
dependencies: [
Icon,
],
})

/**
* Fired when the user clicks on an interactive badge.
* <b>Note:</b> The event will be fired if the <code>interactive</code> property is <code>true</code>
* @event sap.ui.webc.main.Badge#click
* @public
* @since 1.20
*/
@event("click")
class Badge extends UI5Element {
/**
* Defines the design type of the component.
* @type {string}
* @name sap.ui.webc.main.Badge.prototype.design
* @defaultvalue "Set3"
* @public
* @since 1.20
*/
@property({ defaultValue: BadgeDesign.Set3 })
design!: `${BadgeDesign}`;

/**
* Defines the color scheme of the component.
* There are 10 predefined schemes.
Expand All @@ -63,6 +103,44 @@ class Badge extends UI5Element {
@property({ defaultValue: "1" })
colorScheme!: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

enum?


/**
* Defines if the default state icon is shown.
* @type {boolean}
* @name sap.ui.webc.main.Badge.prototype.hideStateIcon
* @defaultValue false
* @public
* @since 1.20
*/
@property({ type: Boolean })
hideStateIcon!: boolean;

/**
* Defines if the component is interactive (focusable and pressable).
* <br><b>Note:</b> The badge cannot be <code>interactive</code>
* when <code>design</code> property is <code>BadgeDesign.Set3</code>
* @type {boolean}
* @name sap.ui.webc.main.Badge.prototype.interactive
* @defaultValue false
* @public
* @since 1.20
*/
@property({ type: Boolean })
interactive!: boolean;

/**
* Defines how the text of a component will be displayed when there is not enough space.
* <br><b>Note:</b> For option "Normal" the text will wrap and the
* words will not be broken based on hyphenation.
*
* @name sap.ui.webc.main.Badge.prototype.wrappingType
* @type {sap.ui.webc.main.types.WrappingType}
* @defaultvalue "None"
* @public
* @since 1.20
*/
@property({ type: WrappingType, defaultValue: WrappingType.None })
wrappingType!: `${WrappingType}`;

/**
* Defines if the badge has an icon.
* @private
Expand All @@ -77,6 +155,13 @@ class Badge extends UI5Element {
@property({ type: Boolean })
_iconOnly!: boolean;

/**
* Defines if the badge has "Tag" design type.
* @private
*/
@property({ type: Boolean })
_isTagDesign!: boolean;

/**
* Defines the text of the component.
* <br><b>Note:</b> Although this slot accepts HTML Elements, it is strongly recommended that you only use text in order to preserve the intended design.
Expand Down Expand Up @@ -107,8 +192,28 @@ class Badge extends UI5Element {
}

onBeforeRendering() {
this._hasIcon = this.hasIcon;
this._hasIcon = this.hasIcon || !!this._semanticIconName;
this._iconOnly = this.iconOnly;
this._isTagDesign = this.design !== BadgeDesign.Set3;
}

get _roleDescription() {
return Badge.i18nBundle.getText(BADGE_ROLE_DESCRIPTION);
}

get _valueState() {
switch (this.design) {
case BadgeDesign.Positive:
return Badge.i18nBundle.getText(BADGE_SUCCESS);
case BadgeDesign.Negative:
return Badge.i18nBundle.getText(BADGE_ERROR);
case BadgeDesign.Critical:
return Badge.i18nBundle.getText(BADGE_WARNING);
case BadgeDesign.Information:
return Badge.i18nBundle.getText(BADGE_INFORMATION);
}

return undefined;
}

get hasText() {
Expand All @@ -123,8 +228,52 @@ class Badge extends UI5Element {
return this.hasIcon && !this.hasText;
}

get _title() {
return this.title || undefined;
}

get badgeDescription() {
return Badge.i18nBundle.getText(BADGE_DESCRIPTION);
if (this.interactive) {
return undefined;
}

if (this.design === BadgeDesign.Set3) {
return Badge.i18nBundle.getText(BADGE_DESCRIPTION_BADGE);
}

const valueState = this._valueState;
let description = Badge.i18nBundle.getText(BADGE_DESCRIPTION_TAG);

if (valueState) {
description = `${description} ${valueState}`;
}

return description;
}

get _semanticIconName() {
if (this.hideStateIcon || this.hasIcon) {
return null;
}

switch (this.design) {
case BadgeDesign.Neutral:
return "sys-help-2";
case BadgeDesign.Positive:
return "sys-enter-2";
case BadgeDesign.Negative:
return "error";
case BadgeDesign.Critical:
return "alert";
case BadgeDesign.Information:
return "information";
default:
return null;
}
}

_onclick() {
this.fireEvent("click");
}
}

Expand Down
20 changes: 19 additions & 1 deletion packages/main/src/i18n/messagebundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,25 @@ AVATAR_GROUP_ARIA_LABEL_GROUP=Conjoined avatars.
AVATAR_GROUP_MOVE=Press ARROW keys to move.

#XACT: ARIA announcement for the badge
BADGE_DESCRIPTION=Badge
BADGE_DESCRIPTION_BADGE=Badge

#XACT: ARIA announcement for the badge with "Tag" design
BADGE_DESCRIPTION_TAG=Tag

#XACT: ARIA announcement for the roledescription attribute
BADGE_ROLE_DESCRIPTION=Tag button

#XACT: ARIA announcement for the "Error" state
BADGE_ERROR=Error

#XACT: ARIA announcement for the "Warning" state
BADGE_WARNING=Warning

#XACT: ARIA announcement for the "Success" state
BADGE_SUCCESS=Success

#XACT: ARIA announcement for the "Information" state
BADGE_INFORMATION=Information

#XACT: position (current and max. value) of a Breadcrumb item which should be announced by screenreaders
BREADCRUMB_ITEM_POS={0} of {1}
Expand Down
Loading
Loading