Open ilhan007 opened 2 years ago
This planed approach doesn't seem to be optimal to me. This applies to Badge in UI5 webc 1.0 and the renamed Tag in 2.0.
Using badge as a slot, the parents of badge need to be adjusted to support positioning badge. This needs to be done for all the controls that need to support badge one by one.
It is better to implement badge as a container using a structure like this:
<badge-root>
<slot><slot>
<badge-div></badge-div>
</badge-root>
The div that hold the badge rendering<badge-div>
is the 2nd child so that it has higher z-index over slot. You only need to update the badge implementation, and any other webcomponent can have the badge attached to it without any modifications.
You can take a look at popular UI frameworks and they use badge as container:
Material UI: https://mui.com/material-ui/react-badge/ Ant Design: https://ant.design/components/badge
@niyap Thanks for reviewing the issues I created. Since this issue already exists, I didn't created a new one and instead I commented my request above. Could you also review this request?
Hello there and really sorry for the delay in our answer...
If I understood the suggestion, it is to wrap a given web component like this:
<Badge badgeContent={4} color="secondary">
<MailIcon color="action" />
</Badge>
The problem that we have seen with that, because I think we discussed it also, is that we have cases like with the tabs and tab container, where the component with a badge is slotted/aggregated into other component
<TabContainer>
<Badge badgeContent={4} color="secondary">
<Tab><Tab/>
</Badge>
</TabContainer>
And the TabContainer expects tabs and this leads to other complications.
So I would even be more in favour for built-in functionality as there are only 3/4 components with badging design (of course we can think how to generally provide it, but then we have to think for the case with the tabs I mentioned) like: ui5-tab badge={} ui5-button badge={}
However I think you are talking about the topic from component development aspect not just using the button, tab, etc that are supposed to have badging. Is it the case that you want to create a ui5 web component that should have badge, and you find difficult the part we describe: use the slotted selector to place/style the badge? In this aspect we can think about some reuse of styles, but I think that the badges across components are not like at the same place, maybe the layering is the same - the badge is always on top of the component that is associated with.
Did I get more or less the topic you are bringing, or I am going into different direction
Br ilhan
Hi @ilhan007
Thanks a lot for the detailed explanation. Now I understand the original design choice better.
I would still suggest using badge as a container and workaround for tab case. Please see below:
So I would even be more in favour for built-in functionality as there are only 3/4 components with badging design
<ui5-tabcontainer>
<ui5-tab icon="menu" text="Tab 1">
<ui5-tab-content slot="tab-content">
<ui5-badge>...</ui5-badge>
</ui5-tab-content>
<ui5-label>Quibusdam, veniam! Architecto debitis iusto ad et, asperiores quisquam perferendis reprehenderit ipsa voluptate minus minima, perspiciatis cum. Totam harum necessitatibus numquam voluptatum.</ui5-label>
</ui5-tab>
</ui5-tabcontainer>
E.g. Teletrik badge placement design spec Google Material badge alignment design spec
Overall, I think implementing badge as container would gives benefits:
Description
In UI5 Web Components it is necessary to enable the same badge functionality as in UI5 Controls - https://blogs.sap.com/2021/02/04/badge-support-in-ui5-controls/. Please carefully consider how the implentation will work in the enablement context.
Implementation
After discussions, we've come to a common agreement to implement badge support in each component using a slot - #5418, instead of a feature - #5469. Keep in mind that this is just a general guideline.
The slot may accept:
ui5-badge
, as implemented forui5-avatar
- https://github.com/SAP/ui5-webcomponents/pull/5418ui5-badge
as it's taken. Perhapsui5-badge-enablement
is a good name? https://github.com/SAP/ui5-webcomponents/pull/5469How to implement:
To implement badge support (e.g. for
ui5-button
):badge
slot:packages/main/src/Button.js
:packages/main/src/Button.hbs
:::slotted([slot="badge"])
selector to apply styles:packages/main/src/themes/Button.css
:Example usage:
In UI5 Web Components:
In UI5 Enablement:
Implemented components:
ui5-avatar
- #5418ui5-button
ui5-tabcontainer
ui5-card