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

fix: Make border around Avatar's badge transparent using a mask #27527

Merged
merged 18 commits into from
Apr 24, 2023

Conversation

behowell
Copy link
Contributor

@behowell behowell commented Apr 12, 2023

Previous Behavior

The gap between the Avatar and its badge is a solid color border, which matches the default background color. This results in a visible border around the badge when it is placed on another color background.

image

New Behavior

  • Apply a mask-image: radial-gradient(...) to punch out a circle for the badge.
    • This can't be done on the root slot or it would mask out the badge itself: instead apply it to whichever slot(s) are rendered: the image, icon, or initials slots.
  • Have the icon or initials slot display the background-color, instead of the root, so the background is properly masked.
  • Move the shadow to the ::after element, and leave the active ring on the ::before element.
    • The mask-image property clips everything outside of the element's border-box, which prevents the shadow from rendering when activeDisplay="shadow" since shadows render outside of the border ox.. To fix this, need to put the ring and shadow on separate elements, and only apply the mask to the ring.
  • Use CSS variables for some properties related to the badge size. This avoids having to repeat a large radial-gradient definition with slightly different parameters.
  • Move the base styles for the ::before and ::after elements into the root resetStyles. This reduces bundle size and improves perf when the active prop is used. This is not strictly related to this change, but it is enabled by the new ringWidth variable, and offsets the bundle size increases from the rest of this PR.

image

Related Issue(s)

@behowell behowell self-assigned this Apr 12, 2023
@github-actions github-actions bot added this to the April Project Cycle Q2 2023 milestone Apr 12, 2023
@behowell behowell changed the title Avatar/badge mask fix: Make border around Avatar's badge transparent using a mask Apr 12, 2023
@fabricteam
Copy link
Collaborator

fabricteam commented Apr 12, 2023

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-alert
Alert
95.74 kB
23.13 kB
96.487 kB
22.975 kB
747 B
-155 B
react-avatar
Avatar
59.494 kB
15.587 kB
60.241 kB
15.431 kB
747 B
-156 B
react-avatar
AvatarGroupItem
75.719 kB
20.079 kB
76.466 kB
19.939 kB
747 B
-140 B
react-persona
Persona
66.426 kB
17.533 kB
67.173 kB
17.367 kB
747 B
-166 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-avatar
AvatarGroup
18.223 kB
6.7 kB
react-components
react-components: Button, FluentProvider & webLightTheme
67.986 kB
18.429 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
207.27 kB
57.634 kB
react-components
react-components: FluentProvider & webLightTheme
38.773 kB
12.375 kB
react-portal-compat
PortalCompatProvider
6.446 kB
2.186 kB
react-table
DataGrid
150.617 kB
41.075 kB
react-table
Table (Primitives only)
47.03 kB
12.784 kB
react-table
Table as DataGrid
133.181 kB
33.644 kB
react-table
Table (Selection only)
81.092 kB
19.641 kB
react-table
Table (Sort only)
80.422 kB
19.453 kB
🤖 This report was generated against 999a7998e3913ab823fe24069f0b5d1aab2b2ce0

@size-auditor
Copy link

size-auditor bot commented Apr 12, 2023

Asset size changes

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

Baseline commit: 999a7998e3913ab823fe24069f0b5d1aab2b2ce0 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Apr 12, 2023

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 714 720 5000
Button mount 373 376 5000
Field mount 1292 1273 5000
FluentProvider mount 917 915 5000
FluentProviderWithTheme mount 117 114 10
FluentProviderWithTheme virtual-rerender 101 101 10
FluentProviderWithTheme virtual-rerender-with-unmount 112 108 10
InfoButton mount 20 22 5000
MakeStyles mount 1121 1128 50000
Persona mount 2043 1962 5000
SpinButton mount 1616 1604 5000

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 12, 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 d501da0:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration
sharp-allen-k7eyys Issue #26274

@behowell behowell force-pushed the avatar/badge-mask branch from f784832 to 3ccfcf9 Compare April 13, 2023 23:43
@behowell behowell marked this pull request as ready for review April 14, 2023 00:11
@behowell behowell requested review from a team, khmakoto and sopranopillow as code owners April 14, 2023 00:11
Copy link
Contributor

@sopranopillow sopranopillow left a comment

Choose a reason for hiding this comment

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

Other than the minor comment, lgtm

@behowell behowell merged commit c7424d1 into microsoft:master Apr 24, 2023
@behowell behowell deleted the avatar/badge-mask branch April 24, 2023 20:03
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Apr 25, 2023
* master:
  applying package updates
  microsoft#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates (microsoft#26482)
  docs(react-datepicker-compat): Add description to README.md (microsoft#27677)
  Updated to use single hook selector (microsoft#27491)
  fix: Make border around Avatar's badge transparent using a mask (microsoft#27527)
  Disable focus on non-interactive elements (microsoft#27580)
  feat(react-drawer): implement "prevent close on click outside" feature (microsoft#27551)
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Apr 25, 2023
* master:
  applying package updates
  microsoft#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates (microsoft#26482)
  docs(react-datepicker-compat): Add description to README.md (microsoft#27677)
  Updated to use single hook selector (microsoft#27491)
  fix: Make border around Avatar's badge transparent using a mask (microsoft#27527)
  Disable focus on non-interactive elements (microsoft#27580)
  feat(react-drawer): implement "prevent close on click outside" feature (microsoft#27551)
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Apr 25, 2023
* feat/drawer-components: (81 commits)
  docs: remove TODO marks
  fix: remove conflict code leftover
  applying package updates
  microsoft#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates (microsoft#26482)
  docs(react-datepicker-compat): Add description to README.md (microsoft#27677)
  Updated to use single hook selector (microsoft#27491)
  fix: Make border around Avatar's badge transparent using a mask (microsoft#27527)
  Disable focus on non-interactive elements (microsoft#27580)
  feat(react-drawer): implement "prevent close on click outside" feature (microsoft#27551)
  fix(react-datepicker-compat): Make onValidationError onValidationResult so the error is updated when there's no longer an error (microsoft#27655)
  Fix `@fluentui/react-portal-compat`: to be compatible with React 18 (microsoft#27577)
  chore: fix versions of @fluentui/react-datepicker-compat (microsoft#27666)
  applying package updates
  applying package updates
  Make line chart screen reader accessible (microsoft#27632)
  fix(react-examples): Improve keyboard navigation in ContextualMenu.CustomMenuList (microsoft#25172)
  docs(react-textarea): Update examples to use Field (microsoft#27644)
  bugfix(react-dialog): `DialogTitle` root as `h2` by default (microsoft#27555)
  applying package updates
  chore: restructure stories, add separate category for flat tree (microsoft#27586)
  ...
@msft-fluent-ui-bot
Copy link
Collaborator

🎉@fluentui/react-avatar@v9.5.0 has been released which incorporates this pull request.:tada:

Handy links:

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.

[Bug]: Avatar's badge has a solid color border instead of being transparent to the background
4 participants