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 17 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
10 changes: 9 additions & 1 deletion packages/main/src/Badge.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<div class="ui5-badge-root">
<div class="ui5-badge-root"
tabindex="{{_tabIndex}}"
@keydown={{_onkeydown}}
@keyup={{_onkeyup}}
>
<slot name="icon"></slot>

{{#if this._semanticIconName}}
<ui5-icon class="ui5-badge-semantic-icon" name="{{_semanticIconName}}"></ui5-icon>
{{/if}}

{{#if hasText}}
<label class="ui5-badge-text"><bdi><slot></slot></bdi></label>
{{/if}}
Expand Down
130 changes: 128 additions & 2 deletions packages/main/src/Badge.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
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 { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
import willShowContent from "@ui5/webcomponents-base/dist/util/willShowContent.js";

import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
import WrappingType from "./types/WrappingType.js";
import BadgeIndicationColorType from "./types/BadgeIndicationColorType.js";
import BadgeDesignType from "./types/BadgeDesignType.js";
// Template
import BadgeTemplate from "./generated/templates/BadgeTemplate.lit.js";

Expand Down Expand Up @@ -48,7 +53,26 @@ import badgeCss from "./generated/themes/Badge.css.js";
template: BadgeTemplate,
styles: badgeCss,
})

/**
* Fired on mouseup, <code>SPACE</code> and <code>ENTER</code>.
* - on mouse click, the icon fires native <code>click</code> event
* - on <code>SPACE</code> and <code>ENTER</code>, the badge fires custom <code>click</code> event
* @private
* @since 1.19
*/
@event("click")
class Badge extends UI5Element {
/**
* Defines the design type of the component.
* @type {string}
* @name sap.ui.webc.main.Badge.prototype.designType
* @defaultvalue "ColorScheme"
* @public
*/
@property({ defaultValue: BadgeDesignType.ColorScheme })
designType!: `${BadgeDesignType}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use just "design"? we already have "design" in other controls


/**
* Defines the color scheme of the component.
* There are 10 predefined schemes.
Expand All @@ -63,6 +87,65 @@ 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 the value state of the component.
*
* @type {sap.ui.webc.base.types.ValueState}
* @defaultvalue "None"
* @name sap.ui.webc.main.Badge.prototype.valueState
* @public
* @since 1.19
*/
@property({ type: ValueState, defaultValue: ValueState.None })
valueState!: `${ValueState}`;

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

can we combine this with colorScheme property. Both actually have colors from 1 to 10 and we can reuse the same enumeration?

* Defines the indication color type of the component.
*
* @type {sap.ui.webc.base.types.BadgeIndicationColorType}
* @defaultvalue "DarkRed"
* @name sap.ui.webc.main.Badge.prototype.indicationColor
* @public
* @since 1.19
*/
@property({ type: ValueState, defaultValue: BadgeIndicationColorType.DarkRed })
indicationColor!: `${BadgeIndicationColorType}`;

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

/**
* Defines if the component is interactive (focusable and pressable).
* @type {boolean}
* @name sap.ui.webc.main.Badge.prototype.interactive
* @defaultValue false
* @public
* @since 1.19
*/
@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.
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
*
* @name sap.ui.webc.main.Badge.prototype.wrappingType
* @type {sap.ui.webc.main.types.WrappingType}
* @defaultvalue "None"
* @public
* @since 1.19
*/
@property({ type: WrappingType, defaultValue: WrappingType.None })
wrappingType!: `${WrappingType}`;

/**
* Defines if the badge has an icon.
* @private
Expand Down Expand Up @@ -107,7 +190,7 @@ class Badge extends UI5Element {
}

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

Expand All @@ -126,6 +209,49 @@ class Badge extends UI5Element {
get badgeDescription() {
return Badge.i18nBundle.getText(BADGE_DESCRIPTION);
}

get _semanticIconName() {
if (!this.showStateIcon || this.hasIcon || this.designType !== BadgeDesignType.ValueState) {
return null;
}

switch (this.valueState) {
case ValueState.Success:
return "sys-enter-2";
case ValueState.Error:
return "error";
case ValueState.Warning:
return "alert";
case ValueState.Information:
return "information";
default:
return null;
}
}

get _tabIndex() {
return this.interactive ? "0" : undefined;
}

_onkeydown(e: KeyboardEvent) {
if (!this.interactive) {
return;
}

if (isEnter(e)) {
this.fireEvent("click");
}

if (isSpace(e)) {
e.preventDefault(); // prevent scrolling
}
}

_onkeyup(e: KeyboardEvent) {
if (this.interactive && isSpace(e)) {
this.fireEvent("click");
}
}
}

Badge.define();
Expand Down
Loading
Loading