Skip to content

Commit

Permalink
Add user menu with logout button
Browse files Browse the repository at this point in the history
Includes a change that lets dropdown menus get smaller (but not too
small) if their contents aren’t wide. This looks better for emptier
menus like the user menu.

(The user menu will gain more functionality with #618.)

Issue #619 Add ability to log out from the front end
  • Loading branch information
reefdog committed Apr 20, 2024
1 parent 74b2b57 commit 1452c4c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
color: var(--color--red);
}

.App-navbar .logout {
color: var(--color--red);
}

.App-main {
grid-area: main;
position: relative;
Expand Down
7 changes: 5 additions & 2 deletions src/components/Dropdown/Dropdown.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
:root {
--dropdown--menu--border-radius: 8px;
--dropdown--menu--spacing: var(--accessible-spacing--1x);
--dropdown--menu--width: 30ch;
--dropdown--menu--min-width: 20ch;
--dropdown--menu--max-width: 30ch;
--dropdown--menu-item--icon-size: 1.5em;
}

Expand Down Expand Up @@ -44,7 +45,9 @@
.dropdown-menu {
position: absolute;
z-index: 100;
width: var(--dropdown--menu--width);
inline-size: max-content;
min-inline-size: var(--dropdown--menu--min-width);
max-inline-size: var(--dropdown--menu--max-width);

background-color: white;
border-radius: var(--dropdown--menu--border-radius);
Expand Down
35 changes: 29 additions & 6 deletions src/components/User.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import React from 'react';
import { useOidc, useOidcUser, OidcUserStatus } from '@axa-fr/react-oidc';
import { UserIcon as UserIconOutline } from '@heroicons/react/24/outline';
import {
PowerIcon,
UserIcon as UserIconOutline,
} from '@heroicons/react/24/outline';
import { UserIcon as UserIconSolid } from '@heroicons/react/24/solid';
import {
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownMenuButton,
} from './Dropdown';
import { getLogger } from '../logger';

const logger = getLogger('<User>');

const User = () => {
const { oidcUser, oidcUserLoadingState } = useOidcUser();
const { login } = useOidc();
const { login, logout } = useOidc();

switch (oidcUserLoadingState) {
case OidcUserStatus.Loading:
Expand Down Expand Up @@ -40,10 +49,24 @@ const User = () => {
);
default:
return (
<div className="App-navbar__item">
<UserIconSolid />
{oidcUser.name}
</div>
<Dropdown name="navbar-dropdown">
<DropdownTrigger type="navbar-item">
<UserIconSolid />
{oidcUser.name}
</DropdownTrigger>
<DropdownMenu align="right">
<DropdownMenuButton
icon={<PowerIcon />}
className="logout"
onClick={() => {
logout('/').catch(logger.error);
}}
key="logout"
>
Log out
</DropdownMenuButton>
</DropdownMenu>
</Dropdown>
);
}
};
Expand Down

0 comments on commit 1452c4c

Please sign in to comment.