Skip to content
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
3 changes: 3 additions & 0 deletions src/assets/icons/bars.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 31 additions & 7 deletions src/components/Menu.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Props = HTMLAttributes<'details'> & {
align?: 'start' | 'end';
density?: 'default' | 'compact';
width?: string;
// Render inline rather than as a popup
inline?: boolean;
};

const {
Expand All @@ -41,6 +43,7 @@ const {
align = 'start',
density = 'default',
width,
inline = false,
class: className,
...rest
} = Astro.props satisfies Props;
Expand Down Expand Up @@ -73,14 +76,15 @@ const iconDetails = (name: string | undefined) => {
'menu',
`menu--${align}`,
density === 'compact' && 'menu--compact',
inline && 'menu--inline',
className,
]}
style={width ? `--menu-width: ${width}` : undefined}
data-menu
style={width && !inline ? `--menu-width: ${width}` : undefined}
data-menu={inline ? undefined : ''}
{...rest}
>
<slot name="trigger" />
<ul class="menu__list" role="menu" aria-label={label}>
<ul class="menu__list" role={inline ? undefined : 'menu'} aria-label={label}>
{
items.map((item) => {
if (item.kind === 'divider') {
Expand All @@ -91,7 +95,7 @@ const iconDetails = (name: string | undefined) => {
return (
<li
class="menu__item menu__item--detail"
role="presentation"
role={inline ? undefined : 'presentation'}
{...item.data}
>
<span class="menu__label" data-menu-label>
Expand Down Expand Up @@ -121,11 +125,11 @@ const iconDetails = (name: string | undefined) => {
// The list is the menu, so the items between it and the actions are
// not part of that structure; `menuitem` goes on the action so it is
// the thing announced and the thing arrow keys move between.
<li role="none">
<li role={inline ? undefined : 'none'}>
<Action
class={actionClass}
role="menuitem"
tabindex="-1"
role={inline ? undefined : 'menuitem'}
tabindex={inline ? undefined : '-1'}
{...actionProps}
{...item.data}
>
Expand Down Expand Up @@ -351,4 +355,24 @@ const iconDetails = (name: string | undefined) => {
img.menu__icon {
object-fit: contain;
}

.menu--inline .menu__list {
position: static;
position-area: none;
width: auto;
min-width: 0;
max-width: none;
margin: 0;
padding: 0;
background: none;
border-radius: 0;
box-shadow: none;
opacity: 1;
transform: none;
transition: none;
}

.menu--inline:not([open])::details-content {
transition: none;
}
</style>
139 changes: 119 additions & 20 deletions src/components/ProfileMenu.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Props = HTMLAttributes<'div'> & {
controlCenterHref?: string;
profileHref?: string;
signOutHref?: string;
inline?: boolean;
};

const {
Expand All @@ -18,6 +19,8 @@ const {
// Arbitrary subpaths of /docs are blocked on the server side, returning to /docs is the best we can do
signOutHref = 'https://octopus.com/signout?ReturnUrl=/docs',

inline = false,

class: className,
...rest
} = Astro.props satisfies Props;
Expand All @@ -30,32 +33,58 @@ const leaving = {
};

const items: MenuItem[] = [
{
// Details start out empty, signed-in-user.ts fills things in through Menu's hooks
kind: 'detail',
label: '',
description: '',
data: { 'data-user-details': '' },
},
// Omit name/email when inline, as they're used as the row you press to expand the menu
...(inline
? []
: [
{
// Details start out empty, signed-in-user.ts fills things in through Menu's hooks
kind: 'detail' as const,
label: '',
description: '',
data: { 'data-user-details': '' },
},
]),
{ label: 'Control Center', href: controlCenterHref, ...leaving },
{ label: 'Profile', href: profileHref, ...leaving },
{ kind: 'divider' },
...(inline ? [] : [{ kind: 'divider' as const }]),
{ label: 'Sign out', href: signOutHref },
];
---

<div class:list={['profile-menu', className]} {...rest}>
<Menu label={label} items={items} align="end" width="16rem">
<summary
slot="trigger"
class="profile-menu__trigger"
aria-label={label}
aria-haspopup="menu"
>
<Avatar size="medium" shape="circle" alt="" data-user-avatar>
<span data-user-initials></span>
</Avatar>
</summary>
<div
class:list={['profile-menu', inline && 'profile-menu--inline', className]}
{...rest}
>
<Menu
label={label}
items={items}
align="end"
width="16rem"
inline={inline}
density={inline ? 'compact' : 'default'}
>
{
inline ? (
<summary slot="trigger" class="profile-menu__row" data-user-details>
<span class="profile-menu__labels">
<span class="profile-menu__name" data-menu-label />
<span class="profile-menu__email" data-menu-description />
</span>
</summary>
) : (
<summary
slot="trigger"
class="profile-menu__trigger"
aria-label={label}
aria-haspopup="menu"
>
<Avatar size="medium" shape="circle" alt="" data-user-avatar>
<span data-user-initials />
</Avatar>
</summary>
)
}
</Menu>
</div>

Expand Down Expand Up @@ -93,4 +122,74 @@ const items: MenuItem[] = [
background-color: currentColor;
mask: url('../assets/icons/external-link.svg') center / 80% no-repeat;
}

.profile-menu--inline {
display: block;
}

.profile-menu__row {
display: flex;
align-items: center;
gap: var(--space8);
padding-block: var(--space6);
list-style: none;
color: var(--colorTextPrimary);
text-decoration: none;
cursor: pointer;
}

.profile-menu__row::-webkit-details-marker {
display: none;
}

.profile-menu__row:focus-visible {
outline: var(--borderWidth2) solid var(--colorBorderSelected);
outline-offset: var(--borderWidth2);
}

.profile-menu__labels {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-width: 0;
color: var(--colorTextPrimary);
text-decoration: none;
}

.profile-menu__name {
font: var(--textBodyRegularLarge);
overflow-wrap: anywhere;
}

.profile-menu__email {
color: var(--colorTextSecondary);
font: var(--textBodyRegularSmall);
overflow-wrap: anywhere;
}

.profile-menu__row::after {
content: '';
flex: none;
width: 1.25rem;
height: 1.25rem;
background-color: var(--colorIconTertiary);
mask: url('../assets/icons/chevron-right.svg') center / contain no-repeat;
}

:global([open]) > .profile-menu__row::after {
mask-image: url('../assets/icons/chevron-down.svg');
}

.profile-menu--inline :global(.menu__item) {
padding-inline: 0;
padding-block: var(--space6);
font: var(--textBodyRegularLarge);
}

.profile-menu--inline :global(.menu--inline .menu__list) {
display: flex;
flex-direction: column;
gap: var(--space12);
margin-block-start: var(--space12);
}
</style>
Loading