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

(web-components): add avatar as a new Fluent 2 aligned component #26729

Conversation

chrisdholt
Copy link
Member

@chrisdholt chrisdholt commented Feb 7, 2023

Previous Behavior

We did not have a Fluent 2 aligned Avatar Component.

New Behavior

Now we do! closes #26672

This PR provides pretty much parity of API but proposes a flat structure to limit the size of our element by leveraging the default slot for string attributes. Additionally, I'm proposing a property/attribute delta - color-id rather than id-for-color, but I'm open to changing it back to align here.

  • If we do not have initials or any slotted items in the default slot, a default SVG is returned in the template.
  • If we have a name or initials, we'll get the correct initials based on what's provided.
  • If we have a slotted item (such as an image) that will be projected into the DOM.

Lastly, this does not include the manipulation of aria-label and aria-labelledby automatically. There are a couple of considerations I think we should look at given the potential perf cost of "covering the sins" of consuming teams. If we went the guidance method, teams would construct their labels (we can provide specific examples!) and the cost is basically free as we're leveraging the native API's on the element. If we want to provide this by default then we need to observe and manage the lifecycle of both aria-label and aria-labelledby as well as observe the badge slot and then likely manipulate or modify slotted elements such as the badge slot as well. Finally, we'd need a method of providing a localized string to create this I think...which is easy enough with a formatter - but it encourages both us handling it and encourages us taking on the cost. Miro and I discussed this in our sync this week and agreed it isn't a blocker but I do think it's worth discussing the trade offs.

Related Issue(s)

  • Fixes #

@fabricteam
Copy link
Collaborator

fabricteam commented Feb 7, 2023

📊 Bundle size report

🤖 This report was generated against 7d9573d73b4be010c2b07540fa0c23c27aba2821

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 7, 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 34ea6e8:

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

@chrisdholt chrisdholt force-pushed the users/chhol/add-avatar-as-new-component branch from c00523f to 0f44ff9 Compare February 14, 2023 01:04
@chrisdholt chrisdholt requested a review from a team as a code owner February 14, 2023 01:04
@size-auditor
Copy link

size-auditor bot commented Feb 14, 2023

Asset size changes

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

Baseline commit: 7d9573d73b4be010c2b07540fa0c23c27aba2821 (build)

@chrisdholt chrisdholt force-pushed the users/chhol/add-avatar-as-new-component branch from 0f44ff9 to 0e1a331 Compare February 14, 2023 04:36
:host([shape='square'][size='96']),
:host([shape='square'][size='120']),
:host([shape='square'][size='128']) {
border-radius: ${borderRadiusXLarge};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to get docs up with all these values for reference.

@chrisdholt chrisdholt force-pushed the users/chhol/add-avatar-as-new-component branch 3 times, most recently from 630fab7 to 021cf99 Compare February 21, 2023 00:04
Copy link
Contributor

@tudorpopams tudorpopams left a comment

Choose a reason for hiding this comment

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

Approving for v-build owned files.

Copy link
Member

@miroslavstastny miroslavstastny left a comment

Choose a reason for hiding this comment

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

I think all the *Changed callbacks which call either setInitials() or setColor() are unnecessary asboth are just compute functions which do not alter anything.
When any of name, initials, color or color-id attributes changes, the relevant part of the template is invalidated and re-rendered.

packages/web-components/src/avatar/avatar.styles.ts Outdated Show resolved Hide resolved
* HTML Attribute: active
*/
@attr
public active?: AvatarActive | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Besides active and inactive, FUIR9 also uses unset (which is default).

Copy link
Member Author

Choose a reason for hiding this comment

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

@miroslavstastny this is one where I think we need to figure out the right thing...am I mistaken that the intent of "unset" is undefined? Basically "removing" the state itself? While I'm more than happy to align on including "unset", it's basically a noop here, and our approach was to not provide default values to attributes when possible to avoid cluttering DOM. Happy to align, but I think these are places where I'm a bit lost on why certain decisions were made.

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 this is the only outstanding instance, I'm going to look for detail on this in past issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I've found what I think is precedent from FUIR9 for adopting undefined here instead of "unset". This specific instance seems to be a large part of prompting this RFC: #23304. Given we're doing new work here, I'd rather align with this forward-thinking direction which I assume will be adopted into the React Avatar implementation when we can next make a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, let's go with undefined. Do you plan to add a spec documenting the differences between FUIR9 and WC3?

packages/web-components/src/avatar/avatar.ts Outdated Show resolved Hide resolved
packages/web-components/src/avatar/avatar.styles.ts Outdated Show resolved Hide resolved
packages/web-components/src/avatar/avatar.styles.ts Outdated Show resolved Hide resolved
packages/web-components/src/avatar/avatar.template.ts Outdated Show resolved Hide resolved
packages/web-components/src/avatar/avatar.ts Outdated Show resolved Hide resolved
packages/web-components/src/avatar/avatar.ts Outdated Show resolved Hide resolved
Copy link
Member

@miroslavstastny miroslavstastny left a comment

Choose a reason for hiding this comment

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

Unblocking the PR, I still would like to understand colorIdChanged()

@chrisdholt
Copy link
Member Author

Unblocking the PR, I still would like to understand colorIdChanged()

Removed/resolved - I think I might have misspelled or typed a value which doesn't exist. 👀

@chrisdholt chrisdholt force-pushed the users/chhol/add-avatar-as-new-component branch from 0ff51f6 to 4006a9f Compare February 25, 2023 00:32
@chrisdholt chrisdholt merged commit 4309a0d into microsoft:web-components-v3 Feb 25, 2023
chrisdholt added a commit that referenced this pull request Apr 29, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
…rosoft#26729)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
…rosoft#26729)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
…rosoft#26729)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request Apr 30, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 2, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 2, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 2, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 3, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 6, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 6, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 8, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* update api report
radium-v pushed a commit that referenced this pull request May 10, 2024
)

* add avatar as a new component

* add export path

* update helpers path in avatar stories

* create public static value for named colors

* update styles to support any slotted badge

* add size 16 styles and stories

* update animations to use tokens

* add support for prefers reduced motion on active and inactive transitions

* change set to generate for color and initials fns

* add large badge styles

* remove unnecessary badge cchange handlers

* fix brand color in dark mode with static inverted value

* update change file

* remove unnecessary lifecycle event

* add avatar readme for react deltas

* update attributes as optional

* 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.

7 participants