Skip to content

Commit

Permalink
[PLAY-1788] Avatar - Dark Mode Audit (#4185)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
[PLAY-1788](https://runway.powerhrg.com/backlog_items/PLAY-1788)

This PR addresses the following issues in the Avatar Kit:
- [x] The "Monogram" variant should use $text_dk_light as the background
color
- [x] The "Icon Circle Component Overlay" variant now follows dark mode
standards
- [x] The "Badge Component Overlay" variant now follows dark mode
standards

Out of the scope of the story:
- [x] There's a bug in light mode around the padding for the Rails "Icon
Circle Component Overlay". It was addressed in dark mode as well.

**Screenshots:** Screenshots to visualize your addition/change
"Monogram" before and after REACT and RAILS:
<img width="1728" alt="Screenshot 2025-01-29 at 8 29 18 AM"
src="https://github.com/user-attachments/assets/34d1f517-1202-4eb3-8ae0-2e6c17aa1971"
/>

"Icon Circle Component Overlay" and "Badge Component Overlay" Dark Mode
Audit
before and after
REACT and RAILS:
<img width="1723" alt="Screenshot 2025-01-29 at 8 30 56 AM"
src="https://github.com/user-attachments/assets/73503b93-fafa-405f-8c59-a819ffcda0b2"
/>

Light Mode Bug "Icon Circle Component Overlay" RAILS ONLY:
<img width="1718" alt="Screenshot 2025-01-29 at 8 32 54 AM"
src="https://github.com/user-attachments/assets/6b4e6041-02b8-4d9d-8448-fa24679cc7a3"
/>

**How to test?** Steps to confirm the desired behavior:
1. Go to /kits/avatar/rails and /kits/avatar/react
2. Enable dark mode
3. Scroll down to the Monogram, Icon Circle Component Overlay and Badge
Component Overlay
4. See dark mode applied to the three components
5. For the bug: in light mode, go to the Rails - Icon Circle Component
Overlay, see that the padding is no longer 24px

#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
- [ ] **TESTS** I have added test coverage to my code.
  • Loading branch information
gabbymassaro authored Jan 31, 2025
1 parent 8a117e8 commit 930c2f2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
9 changes: 9 additions & 0 deletions playbook/app/pb_kits/playbook/pb_avatar/_avatar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ $avatar-sizes: (
flex-basis: $size;

& > [class^=pb_flex_kit] {
[class^=pb_card_kit] {
padding: 2px;
}
[class^=pb_card_kit].overlay_bottom_center,
[class^=pb_card_kit].overlay_top_center {
left: 50%;
Expand All @@ -52,6 +55,10 @@ $avatar-sizes: (
flex-grow: 0;
flex-basis: $size;

.dark & {
background: $text_dk_light;
}

&::before {
content: attr(data-initials);
width: 100%;
Expand All @@ -78,9 +85,11 @@ $avatar-sizes: (
}
}
}

&.dark {
[class^=pb_card_kit] {
position: absolute;
padding: 2px;
}
}
}
18 changes: 11 additions & 7 deletions playbook/app/pb_kits/playbook/pb_avatar/_avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export type AvatarProps = {
variant?: string,
icon?: string
},
data?: {[key: string]: string},
dark?: boolean,
data?: {[key: string]: string},
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
id?: string,
imageAlt?: string,
Expand Down Expand Up @@ -71,13 +71,13 @@ const Avatar = (props: AvatarProps): React.ReactElement => {

const canShowImage = imageUrl && !error

const onlineStatusSize =
const onlineStatusSize =
['xxs', 'xs'].includes(size) ? 'sm' :
['sm', 'md'].includes(size) ? 'md' :
['lg', 'xl'].includes(size) ? 'lg' :
'sm';

const onlineStatusPositionProps = (["xxs", "xs", "sm"].includes(size)) ?
const onlineStatusPositionProps = (["xxs", "xs", "sm"].includes(size)) ?
{
top: { inset: true, value: "0" },
right: { inset: false, value: "xxs" }
Expand All @@ -96,10 +96,10 @@ const Avatar = (props: AvatarProps): React.ReactElement => {
id={id}
>
{componentOverlay ? (
<Flex display="display_inline_block"
<Flex display="display_inline_block"
position="relative"
>
<div className="avatar_wrapper"
<div className="avatar_wrapper"
data-initials={initials}
>
{canShowImage && (
Expand All @@ -115,12 +115,14 @@ const Avatar = (props: AvatarProps): React.ReactElement => {
<Card
borderNone
borderRadius="rounded"
dark={dark}
padding="none"
position="absolute"
{...getPlacementProps(componentOverlay.placement, size)}
>

<Badge
dark={dark}
rounded
text={componentOverlay.text}
variant={componentOverlay.variant as "error" | "info" | "neutral" | "primary" | "success" | "warning" | "notification"}
Expand All @@ -131,11 +133,13 @@ const Avatar = (props: AvatarProps): React.ReactElement => {
<Card
borderNone
borderRadius="rounded"
dark={dark}
htmlOptions={{style: {padding:"2px"}}}
position="absolute"
{...getPlacementProps(componentOverlay.placement, size)}
>
<IconCircle
dark={dark}
icon={componentOverlay.icon}
size="xxs"
variant={componentOverlay.variant as "default" | "royal" | "blue" | "purple" | "teal" | "red" | "yellow" | "orange" | "green"}
Expand All @@ -145,7 +149,7 @@ const Avatar = (props: AvatarProps): React.ReactElement => {
</Flex>
) : (
<>
<div className="avatar_wrapper"
<div className="avatar_wrapper"
data-initials={initials}
>
{canShowImage && (
Expand Down
13 changes: 6 additions & 7 deletions playbook/app/pb_kits/playbook/pb_avatar/avatar.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

<%= object.pb_content_tag(:div, data: object.data.merge(initials: object.initials)) do %>
<% if object.component_overlay && object.component_overlay[:component] == "icon_circle" %>
<%= pb_rails("flex", props: {display: "display_inline_block", position: "relative" }) do %>
<%= pb_rails("flex", props: { display: "display_inline_block", position: "relative" }) do %>
<%= content_tag(:div, data: { initials: object.initials }, class: "avatar_wrapper") do %>
<%= pb_rails("image", props: { alt: object.alt_text, url: object.image_url, on_error: object.handle_img_error }) if object.image_url.present? %>
<% end %>
<%= pb_rails("card", props: { border_none: true, border_radius: "rounded", html_options: { style: "padding: 2px" }, position: "absolute" }.merge(specific_placement_style)) do %>
<%= pb_rails("card", props: { border_none: true, border_radius: "rounded", dark: object.dark, position: "absolute" }.merge(specific_placement_style)) do %>

<%= pb_rails("icon_circle", props: { size: "xxs", icon: object.component_overlay[:icon], variant: object.component_overlay[:variant] }) %>
<%= pb_rails("icon_circle", props: { dark: object.dark, size: "xxs", icon: object.component_overlay[:icon], variant: object.component_overlay[:variant] }) %>
<% end %>
<% end %>
<% elsif object.component_overlay && object.component_overlay[:component] == "badge" %>
<%= pb_rails("flex", props: {display: "display_inline_block", position: "relative" }) do %>
<%= pb_rails("flex", props: { display: "display_inline_block", position: "relative" }) do %>
<%= content_tag(:div, data: { initials: object.initials }, class: "avatar_wrapper") do %>
<%= pb_rails("image", props: { alt: object.alt_text, url: object.image_url, on_error: object.handle_img_error }) if object.image_url.present? %>
<% end %>
<%= pb_rails("card", props: { border_none: true, border_radius: "rounded", padding: "none", position: "absolute" }.merge(specific_placement_style)) do %>
<%= pb_rails("badge", props: { rounded: true, text: object.component_overlay[:text], variant: object.component_overlay[:variant] }) %>
<%= pb_rails("card", props: { border_none: true, border_radius: "rounded", dark: object.dark, padding: "none", position: "absolute" }.merge(specific_placement_style)) do %>
<%= pb_rails("badge", props: { dark: object.dark, rounded: true, text: object.component_overlay[:text], variant: object.component_overlay[:variant] }) %>
<% end %>
<% end %>
<% else %>
Expand All @@ -26,4 +26,3 @@
<%= pb_rails("online_status", props: object.online_status_props) if object.status %>
<% end %>
<% end %>

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from "react";
import { Avatar } from 'playbook-ui'

const AvatarBadgeComponentOverlay = () => {
const AvatarBadgeComponentOverlay = (props) => {
return (
<div>
<Avatar
componentOverlay={{
component: "badge",
placement: "bottom-right",
text: "12"
text: "12",
}}
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="sm"
{...props}
/>

<Avatar
Expand All @@ -24,6 +25,8 @@ const AvatarBadgeComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="md"
{...props}

/>

<Avatar
Expand All @@ -36,6 +39,8 @@ const AvatarBadgeComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="lg"
{...props}

/>

<Avatar
Expand All @@ -48,7 +53,8 @@ const AvatarBadgeComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="xl"
/>
{...props}
/>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Avatar } from 'playbook-ui'

const AvatarCircleIconComponentOverlay = () => {
const AvatarCircleIconComponentOverlay = (props) => {
return (
<div>
<Avatar
Expand All @@ -14,6 +14,7 @@ const AvatarCircleIconComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="sm"
{...props}
/>

<Avatar
Expand All @@ -26,6 +27,7 @@ const AvatarCircleIconComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="md"
{...props}
/>

<Avatar
Expand All @@ -38,6 +40,7 @@ const AvatarCircleIconComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="lg"
{...props}
/>

<Avatar
Expand All @@ -50,7 +53,8 @@ const AvatarCircleIconComponentOverlay = () => {
imageUrl="https://randomuser.me/api/portraits/men/44.jpg"
marginBottom="sm"
size="xl"
/>
{...props}
/>
</div>
)
}
Expand Down

0 comments on commit 930c2f2

Please sign in to comment.