Skip to content

Commit

Permalink
Feat(web): Introduce NavigationAvatar subcomponent DS-1666
Browse files Browse the repository at this point in the history
  • Loading branch information
crishpeen committed Feb 5, 2025
1 parent f6bd0e8 commit 09742b6
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 27 deletions.
40 changes: 39 additions & 1 deletion packages/web/src/scss/components/Navigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@ is also turned on by the `aria-expanded` attribute.
If the `box` variant of `NavigationAction` is inside a [`UNSTABLE_Header`][web-unstable-header] component, it will
inherit the height of the `Header`.

## Navigation Avatar

The `NavigationAvatar` is component that is styled to be used as a navigation action with an avatar.

```html
<a href="#" class="NavigationAvatar">
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
</a>
```

If you want the avatar to be square, don't forget to add the `NavigationAvatar--square` modifier to the `NavigationAvatar` component.

```html
<a href="#" class="NavigationAvatar NavigationAvatar--square">
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--square UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
</a>
```

### Full Example

With NavigationAction components:
Expand All @@ -118,7 +146,7 @@ With NavigationAction components:
</nav>
```

With Buttons:
With Buttons and NavigationAvatar:

```html
<nav class="Navigation Navigation--horizontal" aria-label="Secondary Navigation">
Expand All @@ -129,6 +157,16 @@ With Buttons:
<li class="NavigationItem NavigationItem--alignmentYCenter">
<a href="#" class="Button Button--medium Button--secondary">Button</a>
</li>
<li class="NavigationItem NavigationItem--alignmentYCenter">
<a href="#" class="NavigationAvatar">
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
</a>
</li>
</ul>
</nav>
```
Expand Down
42 changes: 42 additions & 0 deletions packages/web/src/scss/components/Navigation/_NavigationAvatar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 1. We want specific typography for nested items in the Navigation component.
// 2. In the vertical Navigation component, the stripe is placed outside the NavigationAvatar element,
// so we need to disable pointer events on it.
// 3. We want the selected and expanded states to override the hover and active states.

@use '../../tools/reset';
@use '../../tools/typography';
@use 'theme';

.NavigationAvatar:where(button) {
@include reset.button();
}

.NavigationAvatar {
display: flex;
gap: theme.$avatar-gap;
align-items: center;
padding-inline-start: theme.$avatar-padding-start;
padding-inline-end: theme.$avatar-padding-end;
padding-block: theme.$avatar-padding-y;
color: theme.$avatar-color-state-default;
border-radius: theme.$avatar-border-radius;
background-color: theme.$avatar-background-color-state-default;

@media (hover: hover) {
&:hover {
text-decoration: none;
color: theme.$avatar-color-state-hover;
background-color: theme.$avatar-background-color-state-hover;
}
}

&:active {
text-decoration: none;
color: theme.$avatar-color-state-active;
background-color: theme.$avatar-background-color-state-active;
}
}

.NavigationAvatar--square {
border-radius: theme.$avatar-border-radius-square;
}
16 changes: 16 additions & 0 deletions packages/web/src/scss/components/Navigation/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ $vertical-action-spacing-y: tokens.$space-600;
$vertical-action-stripe-size: 4px;
$vertical-action-typography-nested: tokens.$body-medium-regular;
$vertical-action-typography: tokens.$body-medium-semibold;

$avatar-gap: tokens.$space-600;
$avatar-padding-y: tokens.$space-400;
$avatar-padding-end: tokens.$space-700;
$avatar-padding-start: tokens.$space-400;

$avatar-color-state-default: tokens.$component-header-item-state-default;
$avatar-color-state-hover: tokens.$component-header-item-state-hover;
$avatar-color-state-active: tokens.$component-header-item-state-active;

$avatar-border-radius: tokens.$radius-full;
$avatar-border-radius-square: tokens.$radius-200;

$avatar-background-color-state-default: tokens.$component-header-item-background-state-default;
$avatar-background-color-state-hover: tokens.$component-header-item-background-state-hover;
$avatar-background-color-state-active: tokens.$component-header-item-background-state-active;
129 changes: 129 additions & 0 deletions packages/web/src/scss/components/Navigation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,133 @@ <h2 class="docs-Heading">Vertical Navigation with Pill NavigationAction</h2>

</section>

<section class="UNSTABLE_Section">

<div class="Container">

<h2 class="docs-Heading">NavigationAvatar</h2>

<div class="docs-Stack docs-Stack--stretch">

<nav class="Navigation Navigation--horizontal" aria-label="NavigationAvatar">
<ul>
<li class="NavigationItem NavigationItem--alignmentYCenter">
<a href="#" class="NavigationAvatar">
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
</a>
</li>
<li class="NavigationItem NavigationItem--alignmentYCenter">
<a href="#" class="NavigationAvatar NavigationAvatar--square">
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--square UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
</a>
</li>
<li class="NavigationItem NavigationItem--alignmentYStretch">
<div class="Dropdown Dropdown--alignmentXStretch Dropdown--alignmentYStretch">
<button
type="button"
class="NavigationAvatar"
data-spirit-toggle="dropdown"
data-spirit-target="#navigation-avatar"
aria-expanded="false"
aria-controls="navigation-avatar"
data-spirit-autoclose="true"
>
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
<svg width="20" height="20" aria-hidden="true" class="accessibility-open">
<use xlink:href="/assets/icons/svg/sprite.svg#chevron-up" />
</svg>
<svg width="20" height="20" aria-hidden="true" class="accessibility-closed">
<use xlink:href="/assets/icons/svg/sprite.svg#chevron-down" />
</svg>
</button>
<div class="DropdownPopover" data-spirit-placement="bottom-end" id="navigation-avatar">
<ul class="list-unstyled">
<li>
<a href="https://www.example.com" class="Item">
<span class="Item__label">My Account</span>
</a>
</li>
<li>
<a href="https://www.example.com" class="Item">
<span class="Item__label">Settings</span>
</a>
</li>
<li>
<a href="https://www.example.com" class="Item">
<span class="Item__label">Log Out</span>
</a>
</li>
</ul>
</div>
</div>
</li>
<li class="NavigationItem NavigationItem--alignmentYStretch">
<div class="Dropdown Dropdown--alignmentXStretch Dropdown--alignmentYStretch">
<button
type="button"
class="NavigationAvatar NavigationAvatar--square"
data-spirit-toggle="dropdown"
data-spirit-target="#navigation-avatar-square"
aria-expanded="false"
aria-controls="navigation-avatar-square"
data-spirit-autoclose="true"
>
<span class="UNSTABLE_Avatar UNSTABLE_Avatar--square UNSTABLE_Avatar--small" aria-label="Profile of Jiří Bárta">
<svg width="20" height="20" aria-hidden="true">
<use xlink:href="/assets/icons/svg/sprite.svg#profile" />
</svg>
</span>
<span class="typography-body-small-semibold">My Account</span>
<svg width="20" height="20" aria-hidden="true" class="accessibility-open">
<use xlink:href="/assets/icons/svg/sprite.svg#chevron-up" />
</svg>
<svg width="20" height="20" aria-hidden="true" class="accessibility-closed">
<use xlink:href="/assets/icons/svg/sprite.svg#chevron-down" />
</svg>
</button>
<div class="DropdownPopover" data-spirit-placement="bottom-end" id="navigation-avatar-square">
<ul class="list-unstyled">
<li>
<a href="https://www.example.com" class="Item">
<span class="Item__label">My Account</span>
</a>
</li>
<li>
<a href="https://www.example.com" class="Item">
<span class="Item__label">Settings</span>
</a>
</li>
<li>
<a href="https://www.example.com" class="Item">
<span class="Item__label">Log Out</span>
</a>
</li>
</ul>
</div>
</div>
</li>
</ul>
</nav>

</div>

</div>

</section>

{{/web/layout/default }}
1 change: 1 addition & 0 deletions packages/web/src/scss/components/Navigation/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@forward 'Navigation';
@forward 'NavigationAction';
@forward 'NavigationAvatar';
@forward 'NavigationItem';
Loading

0 comments on commit 09742b6

Please sign in to comment.