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

[PLAY-1788] Avatar - Dark Mode Audit #4185

Merged
merged 13 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
nidaqg marked this conversation as resolved.
Show resolved Hide resolved
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
Loading