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

Persona component #571

Merged
merged 15 commits into from
Sep 26, 2023
5 changes: 5 additions & 0 deletions .changeset/cold-radios-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@microsoft/atlas-css': minor
---

Adding persona component.
5 changes: 5 additions & 0 deletions .changeset/eleven-seals-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@microsoft/atlas-site': minor
---

Adding doc page for persona component.
ollips marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions css/src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import './notification.scss';
@import './icon.scss';
@import './image.scss';
@import './persona.scss';
@import './popover.scss';
@import './pagination.scss';
@import './table.scss';
Expand Down
179 changes: 179 additions & 0 deletions css/src/components/persona.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
$persona-avatar-xs: 28px !default;
$persona-avatar-sm: 32px !default;
$persona-avatar-md: 36px !default;
$persona-avatar-lg: 42px !default;
$persona-avatar-xl: 48px !default;

$persona-avatar-font-size-ratio: 0.45;
$persona-avatar-background-color: $alternate-background-medium !default;
$persona-avatar-font-color: $text-invert !default;

$persona-metadata-font-size: $font-size-9 !default;
$persona-metadata-font-color: $text-subtle !default;

$persona-font-size: $font-size-7 !default;
$persona-gap-size: $layout-1 !default;

.persona {
display: flex;
position: relative;
gap: $persona-gap-size;
font-size: $persona-font-size;

.persona-avatar {
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
align-items: center;
justify-content: center;
width: $persona-avatar-md;
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
height: $persona-avatar-md;
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
border-radius: $border-radius-rounded;
background-color: $persona-avatar-background-color;
color: $persona-avatar-font-color;
font-size: $persona-avatar-md * $persona-avatar-font-size-ratio;
overflow: hidden;
wibjorn marked this conversation as resolved.
Show resolved Hide resolved

img,
svg {
display: block;
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
width: 100%;
height: auto;
max-height: 100%;
}

span {
line-height: 1;
text-transform: uppercase;
}
BenDMyers marked this conversation as resolved.
Show resolved Hide resolved
}

.persona-description :not(:first-child) {
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
color: $persona-metadata-font-color;
font-size: $persona-metadata-font-size;
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
}

// Sizes

&.persona-xs {
.persona-avatar {
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
width: $persona-avatar-xs;
height: $persona-avatar-xs;
font-size: $persona-avatar-xs * $persona-avatar-font-size-ratio;
}
}

&.persona-sm {
.persona-avatar {
width: $persona-avatar-sm;
height: $persona-avatar-sm;
font-size: $persona-avatar-sm * $persona-avatar-font-size-ratio;
}
}

&.persona-md {
.persona-avatar {
width: $persona-avatar-md;
height: $persona-avatar-md;
font-size: $persona-avatar-md * $persona-avatar-font-size-ratio;
}
}

&.persona-lg {
.persona-avatar {
width: $persona-avatar-lg;
height: $persona-avatar-lg;
font-size: $persona-avatar-lg * $persona-avatar-font-size-ratio;
}
}

&.persona-xl {
.persona-avatar {
width: $persona-avatar-xl;
height: $persona-avatar-xl;
font-size: $persona-avatar-xl * $persona-avatar-font-size-ratio;
}
}

@include tablet {
wibjorn marked this conversation as resolved.
Show resolved Hide resolved
&.persona-xs-tablet {
.persona-avatar {
width: $persona-avatar-xs;
height: $persona-avatar-xs;
font-size: $persona-avatar-xs * $persona-avatar-font-size-ratio;
}
}

&.persona-sm-tablet {
.persona-avatar {
width: $persona-avatar-sm;
height: $persona-avatar-sm;
font-size: $persona-avatar-sm * $persona-avatar-font-size-ratio;
}
}

&.persona-md-tablet {
.persona-avatar {
width: $persona-avatar-md;
height: $persona-avatar-md;
font-size: $persona-avatar-md * $persona-avatar-font-size-ratio;
}
}

&.persona-lg-tablet {
.persona-avatar {
width: $persona-avatar-lg;
height: $persona-avatar-lg;
font-size: $persona-avatar-lg * $persona-avatar-font-size-ratio;
}
}

&.persona-xl-tablet {
.persona-avatar {
width: $persona-avatar-xl;
height: $persona-avatar-xl;
font-size: $persona-avatar-xl * $persona-avatar-font-size-ratio;
}
}
}

@include desktop {
&.persona-xs-desktop {
.persona-avatar {
width: $persona-avatar-xs;
height: $persona-avatar-xs;
font-size: $persona-avatar-xs * $persona-avatar-font-size-ratio;
}
}

&.persona-sm-desktop {
.persona-avatar {
width: $persona-avatar-sm;
height: $persona-avatar-sm;
font-size: $persona-avatar-sm * $persona-avatar-font-size-ratio;
}
}

&.persona-md-desktop {
.persona-avatar {
width: $persona-avatar-md;
height: $persona-avatar-md;
font-size: $persona-avatar-md * $persona-avatar-font-size-ratio;
}
}

&.persona-lg-desktop {
.persona-avatar {
width: $persona-avatar-lg;
height: $persona-avatar-lg;
font-size: $persona-avatar-lg * $persona-avatar-font-size-ratio;
}
}

&.persona-xl-desktop {
.persona-avatar {
width: $persona-avatar-xl;
height: $persona-avatar-xl;
font-size: $persona-avatar-xl * $persona-avatar-font-size-ratio;
}
}
}
}
156 changes: 156 additions & 0 deletions site/src/components/persona.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
title: Persona
description: Persona component in the Atlas Design System
template: standard
figmaEmbed: https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FuVA2amRR71yJZ0GS6RI6zL%2F%25F0%259F%258C%259E-Atlas-Design-Library%3Ftype%3Ddesign%26node-id%3D1284%253A2163%26mode%3Ddesign%26t%3DklysUJ7ALWgcF1SQ-1 allowfullscreen
classType: Component
classPrefixes:
- persona
---

# Persona

Persona component comes in handy for user's representation. It consists of two parts - user's avatar and description. Description has their name and optional metadata.

| Class pattern | Sizes | screensize |
| ------------------------- | ---------------------------------- | ------------------- |
| `.persona.persona-<size>` | `xs` `sm` `md (default)` `lg` `xl` | `tablet`, `desktop` |
wibjorn marked this conversation as resolved.
Show resolved Hide resolved

## Usage

Below are examples of the most common persona component use-cases - one with an image avatar and another with user's initials.

```html
<div class="persona">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="username" />
</figure>
<div class="persona-description">
<p>Jane Doe</p>
<p>Software Engineer</p>
</div>
</div>

<div class="persona margin-top-md">
<div class="persona-avatar">
<span>JD</span>
</div>
<div class="persona-description">
<p>John Doe</p>
<p>Software Engineer</p>
</div>
</div>
```

Persona component might contain a link to user's profile, and with help of the [`.stretched-link` component](../components/stretched-link.md) the whole area persona takes becomes clickable:
wibjorn marked this conversation as resolved.
Show resolved Hide resolved

```html
<div class="persona position-relative">
<div class="persona-avatar">
<span>JD</span>
</div>
<div class="persona-description">
<a class="justify-self-stretch stretched-link" href="#">John Doe</a>
<p>Software Engineer</p>
</div>
</div>
```

Persona might have both avatar and description parts presented at the same time or just one of them.

```html
<div class="persona">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="username" />
</figure>
</div>

<div class="persona margin-top-md">
<div class="persona-description">
<p>John Doe</p>
<p>Software Engineer</p>
</div>
</div>
```

### Sizes

The following classes are available for resizing avatar: `persona-xs` (28x28px), `persona-sm`, `persona-md`, `persona-lg`, `persona-xl`.

| Class | Avatar's size in px |
| ------------ | ------------------- |
| `persona-xs` | 28px |
| `persona-sm` | 32px |
| `persona-md` | 36px |
| `persona-lg` | 42px |
| `persona-xl` | 48px |

```html
<div class="display-flex flex-wrap-wrap gap-xxs">
<div class="persona persona-xs">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="User name" />
</figure>
</div>
<div class="persona persona-sm">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="User name" />
</figure>
</div>
<div class="persona persona-md">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="User name" />
</figure>
</div>
<div class="persona persona-lg">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="User name" />
</figure>
</div>
<div class="persona persona-xl">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="User name" />
</figure>
</div>
</div>

<div class="display-flex flex-wrap-wrap gap-xxs margin-top-md">
<div class="persona persona-xs">
<div class="persona-avatar">
<span>ww</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to support styled-text avatars, we should ensure we demo accessible markup for these:

Could you please add role=img and an aria-label?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

</div>
</div>
<div class="persona persona-sm">
<div class="persona-avatar">
<span>ww</span>
</div>
</div>
<div class="persona persona-md">
<div class="persona-avatar">
<span>ww</span>
</div>
</div>
<div class="persona persona-lg">
<div class="persona-avatar">
<span>ww</span>
</div>
</div>
<div class="persona persona-xl">
<div class="persona-avatar">
<span>ww</span>
</div>
</div>
</div>
```

### Responsive sizes

Tablet and desktop versions of all classes are also available. Resize your browser window to see the differences in sizes.

```html
<div class="persona persona-xs persona-md-tablet persona-xl-desktop">
<figure class="persona-avatar">
<img src="~/src/scaffold/media/avatar.png" alt="User name" />
</figure>
</div>
```
Binary file added site/src/scaffold/media/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.