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: add badge and counter badge as new components #26357

Conversation

chrisdholt
Copy link
Member

Previous Behavior

Badge did not exist as a Fluent 2 aligned web component for v3.

New Behavior

Now it does - and so does CounterBadge!

Related Issue(s)

n/a

  • Fixes #

@chrisdholt chrisdholt force-pushed the users/chhol/add-badge-as-new-component branch from 6c2f5aa to e238735 Compare January 14, 2023 07:36
@fabricteam
Copy link
Collaborator

fabricteam commented Jan 14, 2023

📊 Bundle size report

🤖 This report was generated against be3d30fcbe222be34b02a554e948d14bb2d730df

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 14, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 33ce22b:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor
Copy link

size-auditor bot commented Jan 14, 2023

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: be3d30fcbe222be34b02a554e948d14bb2d730df (build)

* The template for the Badge component.
* @public
*/
export function badgeTemplate<T extends Badge>(options: BadgeOptions = {}): ElementViewTemplate<T> {
Copy link
Member

Choose a reason for hiding this comment

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

This is the first component which export its template function. How do we decide whether we export it or not?
Only when we have a internal use case for it (like in the counter-badge here) or always?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there's value if someone needs to create their own badge or extend the Fluent badge to get all the goodness and not have to recreate. One of the benefits of that would be more shared code and less repeated. Now, in the case that they need to "fork" the template that would result in duplication. I don't think we need to advertise it necessarily, but in terms of enabling teams to reuse and compose, etc...we've found it to be fairly helpful. Text is technically exporting the used template from the index as well.

I'm open.

With that said, in this specific case, it's definitely exported here to enable shared reuse and code for badge + counter badge. Whether we want to export from the index or not we can discuss.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this being exported, if we are not sure, we can keep it private and wait for the demand.
Personally I would prefer every component to export its template 👍

* @public
* The badge's size styles
*/
export const badgeSizeStyles = css.partial`
Copy link
Member

Choose a reason for hiding this comment

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

What is the motivation for having the partials away from the component? I would expect these to be in badge, owned by it and other component(s) importing from there.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was primarily thinking of keeping shared things in a shared location which has greater visibility than within the component styles file as that could get bulky. Additionally one thought that I had was that not all partials may be as intuitive with regard to what the actual "primary" component this would be inheriting from. Consider scenarios where we have the same visuals across a functional button/anchor for example or across text field/number field, or select and combobox (currently two implementations because the behavior and functionality is different, we'll need to dig in here I know). In those cases, which one does the styles live in? They're kind of both on the same level with shared appearances but where would I look for the shared styles? In my mind having a dedicated place where we keep composable styles or partials made a lot of sense.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's start with a shared location and see how that goes (and tree-shakes).
From my experience, when an engineer will need to update the shared style, they will be afraid to change it and will rather copy it anyway. But I strongly believe we will do better :-D

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's strive to do just that!

*/
/* eslint-disable-next-line */
export interface Badge extends StartEnd {}
applyMixins(Badge, StartEnd);
Copy link
Member

Choose a reason for hiding this comment

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

I would appreciate more context and explanation for these.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will go away once the Badge base class is updated w/ Start/End slots. Ultimately start and end have refs in case someone needs to access the node or child nodes of start/end from a given class. So, there is a StartEnd class which enumerates the observables for these slots and here we are combining it with the Badge class to ensure that the final class includes everything from Badge + StartEnd support. The interface specifically exists to ensure typings are all good for "Badge" and I'm disabling that line because something in the lint config is converting it to a type.

@chrisdholt chrisdholt force-pushed the users/chhol/add-badge-as-new-component branch from 4c201ca to cf32618 Compare January 17, 2023 20:15
* HTML Attribute: overflow-count
*/
@attr({ attribute: 'overflow-count', converter: nullableNumberConverter })
public overflowCount: number = 99;
Copy link
Member

Choose a reason for hiding this comment

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

This is my only remaining concern for the PR - there are still attributes with default values reflected back to DOM.
This is a case which cannot be solved by pure CSS and would require additional JS boilerplate :-(

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly - if we don't need a default we can pull it but this is really the most cost effective way...

@miroslavstastny we could not set it and just have an internal default when not set...but I really don't like that because it seems like a side effect here. Slightly more JS cost too (but only slight)

@chrisdholt chrisdholt merged commit eead74f into microsoft:web-components-v3 Jan 18, 2023
@chrisdholt chrisdholt deleted the users/chhol/add-badge-as-new-component branch January 18, 2023 17:22
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
chrisdholt added a commit that referenced this pull request Apr 29, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request Apr 30, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 2, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 2, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 2, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 3, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 6, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 6, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 8, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

* update api report
radium-v pushed a commit that referenced this pull request May 10, 2024
* add badge as a new component

* add counter badge as a new component

* fix broken import and add export paths

* use badge template for counter badge to render count

* update badge svg styles and fix import syntax

* fixup imports for stories

* update partial with default styles

* js extension missing from partial imports

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

Successfully merging this pull request may close these issues.

5 participants