mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-12-03 21:51:06 +00:00
UI for setting user status (#33856)
* First stage 1. Make avatar BIGGER! 2. Move status button out to its own component so we can reuse it * Working version but using context menu rather than dropdown menu which almost looks right but not quite. * Commit the set status view component * Change to use dropdown with custom trigger * Show full set status component in user menu and styling tweaks * In user menu, clicking takes you to settings * Add the view model * oxfmt because apparently mine had decided to go away * Fix type import * Pass set status viewmodel in story * Bump compound-web for customisable dropdown * Snapshot * Add explicit aria label as combobox role things don't just inherit from their inner text * snapshot again * Only show user status if feature flag enabled * Make status btton view not a button because it doesn't need to be. Also rename accordingly. * Screenshots * Disable in settings if feature flag off * Snapshot * Snapshot again * Update screenshots including room settings one which wasn't really supposed to change although the avatar now takes up the space it's in - leaving it for design to check. * Fix size & positioning of the status button * Update screenshots * Screenshots * Test for SetStatusViewModel * Update set status view on status change * Use a link component for the status button which has built in hover state * Float the status button in a 28px container vs making it actually 28px min height * Separate user menu profile into two sections With 8px gap between things in the two sections and 12px gap between sections (ie. in practice, 12px gap between the status control and username). * Screenshot * Screenshots * Pass set status view model in the state rather than as an extra prop. Fixes it in the story too. * Pass ownprofilestore into the viewmodel * Don't use snapshot for testing the view model Avoids getting all the random stuff from the sub VM in the snapshot and better to test what we care about anyway. * don't mention the bad word * Here too * Don't show user status for guests * Update guest story to remove user status
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
/* Override menu defaults */
|
||||
padding-block: 0 !important;
|
||||
section.profile {
|
||||
margin: var(--cpd-space-8x) var(--cpd-space-6x);
|
||||
margin-bottom: var(--cpd-space-3x);
|
||||
margin-left: var(--cpd-space-6x);
|
||||
margin-right: var(--cpd-space-6x);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--cpd-space-2x);
|
||||
@@ -48,6 +48,13 @@
|
||||
margin-bottom: var(--cpd-space-2x);
|
||||
}
|
||||
}
|
||||
.profilePrimary {
|
||||
margin-top: var(--cpd-space-8x);
|
||||
margin-bottom: var(--cpd-space-3x);
|
||||
}
|
||||
.profileSecondary {
|
||||
margin-bottom: var(--cpd-space-4x);
|
||||
}
|
||||
section.actions {
|
||||
margin: var(--cpd-space-2x) 0;
|
||||
margin-bottom: var(--cpd-space-3x);
|
||||
@@ -85,33 +92,6 @@
|
||||
background-color: var(--cpd-color-bg-canvas-default);
|
||||
}
|
||||
|
||||
.statusButton {
|
||||
border-radius: 30px;
|
||||
background: var(--cpd-color-bg-subtle-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-inline-start: var(--cpd-space-2x);
|
||||
gap: 6px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
max-width: 100%;
|
||||
|
||||
.menuStatusEmoji {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.menuStatusText {
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
span {
|
||||
font: var(--cpd-font-body-md-medium);
|
||||
color: var(--cpd-color-text-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.triggerButton {
|
||||
border: none;
|
||||
background: none;
|
||||
|
||||
@@ -11,8 +11,14 @@ import { fn } from "storybook/test";
|
||||
|
||||
import { UserMenuView, type UserMenuViewSnapshot, type UserMenuViewActions } from "./UserMenu";
|
||||
import avatarUrl from "../../../static/element.png";
|
||||
import { useMockedViewModel } from "../../core/viewmodel";
|
||||
import { MockViewModel, useMockedViewModel } from "../../core/viewmodel";
|
||||
import { withViewDocs } from "../../../.storybook/withViewDocs";
|
||||
import { type SetStatusViewSnapshot } from "../..";
|
||||
|
||||
class MockSetStatusViewModel extends MockViewModel<SetStatusViewSnapshot> {
|
||||
public setStatus = fn();
|
||||
public clearStatus = fn();
|
||||
}
|
||||
|
||||
const UserMenuWrapperImpl = (snapshot: UserMenuViewSnapshot): JSX.Element => {
|
||||
const vm = useMockedViewModel<UserMenuViewSnapshot, UserMenuViewActions>(snapshot, {
|
||||
@@ -26,6 +32,7 @@ const UserMenuWrapperImpl = (snapshot: UserMenuViewSnapshot): JSX.Element => {
|
||||
openSettings: fn(),
|
||||
clearStatus: fn(),
|
||||
});
|
||||
|
||||
return <UserMenuView vm={vm} />;
|
||||
};
|
||||
|
||||
@@ -60,11 +67,16 @@ const meta = {
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Default: Story = {};
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
};
|
||||
|
||||
export const LongerName: Story = {
|
||||
args: {
|
||||
displayName: "Sally Sanderson with a longer name",
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -90,6 +102,7 @@ export const Open: Story = {
|
||||
userId: "@person-name:homeserver.com",
|
||||
expanded: true,
|
||||
showAvatar: true,
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
parameters: {
|
||||
a11y: {
|
||||
@@ -115,6 +128,7 @@ export const OpenVeryLongName: Story = {
|
||||
userId: "@person-whose-username-some-might-consider-to-be-a-little-overly-long-although-thats-their-choice-and-we-must-respect-it:homeserver.com",
|
||||
expanded: true,
|
||||
showAvatar: true,
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
parameters: {
|
||||
a11y: {
|
||||
@@ -132,6 +146,7 @@ export const Condensed: Story = {
|
||||
args: {
|
||||
displayName: "Sally Sanderson with a longer name",
|
||||
expanded: false,
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -142,6 +157,7 @@ export const NoAvatar: Story = {
|
||||
expanded: true,
|
||||
open: true,
|
||||
showAvatar: false,
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
parameters: Open.parameters,
|
||||
};
|
||||
@@ -152,6 +168,8 @@ export const Guest: Story = {
|
||||
userId: "@guest:attendees.example.org",
|
||||
manageAccountHref: undefined,
|
||||
showAvatar: false,
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
showUserStatus: false,
|
||||
actions: {
|
||||
createAccount: true,
|
||||
signIn: true,
|
||||
@@ -190,6 +208,7 @@ export const WithStatus: Story = {
|
||||
emoji: "🐹",
|
||||
text: "On the wheel",
|
||||
},
|
||||
setStatusViewModel: new MockSetStatusViewModel({}),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -200,6 +219,12 @@ export const WithStatusOpen: Story = {
|
||||
emoji: "🐹",
|
||||
text: "On the wheel",
|
||||
},
|
||||
setStatusViewModel: new MockSetStatusViewModel({
|
||||
userStatus: {
|
||||
emoji: "🐹",
|
||||
text: "On the wheel",
|
||||
},
|
||||
}),
|
||||
},
|
||||
parameters: {
|
||||
a11y: {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import React, { type JSX } from "react";
|
||||
import { Avatar, Button, IconButton, Link, Menu, MenuItem, Separator, Text } from "@vector-im/compound-web";
|
||||
import { Avatar, Button, Link, Menu, MenuItem, Separator, Text } from "@vector-im/compound-web";
|
||||
import {
|
||||
ChatProblemIcon,
|
||||
DevicesIcon,
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
LockIcon,
|
||||
PopOutIcon,
|
||||
SettingsIcon,
|
||||
CloseIcon,
|
||||
} from "@vector-im/compound-design-tokens/assets/web/icons";
|
||||
import classNames from "classnames";
|
||||
|
||||
@@ -22,7 +21,7 @@ import styles from "./UserMenu.module.css";
|
||||
import { useViewModel, type ViewModel } from "../../core/viewmodel";
|
||||
import { useI18n } from "../../core/i18n/i18nContext";
|
||||
import { type UserStatus } from "../../core/userStatus";
|
||||
import { _t } from "../..";
|
||||
import { SetStatusView, type SetStatusViewModel } from "../../status/SetStatusView";
|
||||
|
||||
export interface UserMenuViewSnapshot {
|
||||
/**
|
||||
@@ -57,6 +56,16 @@ export interface UserMenuViewSnapshot {
|
||||
* The user status to display, or undefined for no icon / status.
|
||||
*/
|
||||
userStatus?: UserStatus;
|
||||
/**
|
||||
* Whether to show UI for user status.
|
||||
* Temporary while user status is in labs.
|
||||
* Default: true
|
||||
*/
|
||||
showUserStatus?: boolean;
|
||||
/**
|
||||
* ViewModel for the set status view.
|
||||
*/
|
||||
setStatusViewModel: SetStatusViewModel;
|
||||
/**
|
||||
* A set of actions that the user can perform from the menu.
|
||||
*/
|
||||
@@ -105,7 +114,7 @@ export declare interface UserMenuViewActions {
|
||||
*/
|
||||
openSettings: () => void;
|
||||
/**
|
||||
* Called when the user clicks the button to clear theirt status.
|
||||
* Called when the user clicks the button to clear their status.
|
||||
*/
|
||||
clearStatus: () => void;
|
||||
}
|
||||
@@ -118,30 +127,20 @@ export type UserMenuViewProps = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
function StatusButton({ status, clearStatus }: { status: UserStatus; clearStatus: () => void }): JSX.Element {
|
||||
return (
|
||||
<div className={styles.statusButton}>
|
||||
<Text as="span" className={styles.menuStatusEmoji}>
|
||||
{status.emoji}
|
||||
</Text>
|
||||
<Text as="span" className={styles.menuStatusText}>
|
||||
{status.text}
|
||||
</Text>
|
||||
<IconButton
|
||||
onClick={clearStatus}
|
||||
aria-label={_t("menus|user_menu|clear_status")}
|
||||
tooltip={_t("menus|user_menu|clear_status")}
|
||||
size="28px"
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserMenuView({ vm, className }: UserMenuViewProps): JSX.Element {
|
||||
const { userId, displayName, avatarUrl, expanded, open, manageAccountHref, actions, showAvatar, userStatus } =
|
||||
useViewModel(vm);
|
||||
const {
|
||||
userId,
|
||||
displayName,
|
||||
avatarUrl,
|
||||
expanded,
|
||||
open,
|
||||
manageAccountHref,
|
||||
actions,
|
||||
showAvatar,
|
||||
userStatus,
|
||||
setStatusViewModel,
|
||||
showUserStatus = true,
|
||||
} = useViewModel(vm);
|
||||
const { translate: _t } = useI18n();
|
||||
const trigger = (
|
||||
<button className={styles.triggerButton} aria-label={_t("menus|user_menu|title")}>
|
||||
@@ -170,12 +169,14 @@ export function UserMenuView({ vm, className }: UserMenuViewProps): JSX.Element
|
||||
side="right"
|
||||
className={styles.container}
|
||||
>
|
||||
<section className={styles.profile}>
|
||||
<section className={classNames(styles.profile, styles.profilePrimary)}>
|
||||
{showAvatar && <Avatar id={userId} name={displayName} type="round" size="64px" src={avatarUrl} />}
|
||||
<Text className={styles.displayname} type="body" size="lg" weight="semibold" as="span">
|
||||
{displayName}
|
||||
</Text>
|
||||
{userStatus && <StatusButton status={userStatus} clearStatus={vm.clearStatus} />}
|
||||
{showUserStatus && <SetStatusView vm={setStatusViewModel} />}
|
||||
</section>
|
||||
<section className={classNames(styles.profile, styles.profileSecondary)}>
|
||||
<Text data-testid="userId" size="md" as="span" type="body" className={styles.userId}>
|
||||
{userId}
|
||||
</Text>
|
||||
|
||||
+190
-2
@@ -286,13 +286,107 @@ exports[`UserMenu > renders a menu without an avatar 1`] = `
|
||||
tabindex="-1"
|
||||
>
|
||||
<section
|
||||
class="UserMenu-module_profile"
|
||||
class="UserMenu-module_profile UserMenu-module_profilePrimary"
|
||||
>
|
||||
<span
|
||||
class="_typography_6v6n8_153 _font-body-lg-semibold_6v6n8_74 UserMenu-module_displayname"
|
||||
>
|
||||
Sally Sanderson
|
||||
</span>
|
||||
<div
|
||||
aria-invalid="false"
|
||||
class="_container_1xtut_8"
|
||||
>
|
||||
<div
|
||||
class="SetStatusView-module_setStatusContainer"
|
||||
>
|
||||
<a
|
||||
aria-controls="react-use-id-3"
|
||||
aria-expanded="false"
|
||||
aria-haspopup="listbox"
|
||||
aria-label="What's your status?"
|
||||
class="_link_k9ljz_8 SetStatusView-module_setStatusTrigger"
|
||||
data-kind="primary"
|
||||
data-size="md"
|
||||
rel="noreferrer noopener"
|
||||
role="combobox"
|
||||
>
|
||||
<svg
|
||||
fill="currentColor"
|
||||
height="1em"
|
||||
viewBox="0 0 24 24"
|
||||
width="1em"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M15.536 15.536a1 1 0 0 0-1.415-1.415 3 3 0 0 1-2.12.879 3 3 0 0 1-2.122-.879 1 1 0 1 0-1.414 1.415A5 5 0 0 0 12 17c1.38 0 2.632-.56 3.536-1.464M10 10.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m5.5 1.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3"
|
||||
/>
|
||||
<path
|
||||
d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10m-2 0a8 8 0 1 0-16 0 8 8 0 0 0 16 0"
|
||||
/>
|
||||
</svg>
|
||||
<span
|
||||
class="_typography_6v6n8_153 _font-body-md-medium_6v6n8_60"
|
||||
>
|
||||
What's your status?
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
<div
|
||||
class="_content_1xtut_62"
|
||||
>
|
||||
<ul
|
||||
class="_content_1xtut_62"
|
||||
id="react-use-id-3"
|
||||
role="listbox"
|
||||
>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
💬 In a meeting
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
💡 Focus Time
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
🚙 On the road
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
☕️ Be right back
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
🌴 Away
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section
|
||||
class="UserMenu-module_profile UserMenu-module_profileSecondary"
|
||||
>
|
||||
<span
|
||||
class="_typography_6v6n8_153 _font-body-md-regular_6v6n8_50 UserMenu-module_userId"
|
||||
data-testid="userId"
|
||||
@@ -599,7 +693,7 @@ exports[`UserMenu > renders an open menu 1`] = `
|
||||
tabindex="-1"
|
||||
>
|
||||
<section
|
||||
class="UserMenu-module_profile"
|
||||
class="UserMenu-module_profile UserMenu-module_profilePrimary"
|
||||
>
|
||||
<span
|
||||
aria-label="@person-name:homeserver.com"
|
||||
@@ -625,6 +719,100 @@ exports[`UserMenu > renders an open menu 1`] = `
|
||||
>
|
||||
Sally Sanderson with a longer name
|
||||
</span>
|
||||
<div
|
||||
aria-invalid="false"
|
||||
class="_container_1xtut_8"
|
||||
>
|
||||
<div
|
||||
class="SetStatusView-module_setStatusContainer"
|
||||
>
|
||||
<a
|
||||
aria-controls="react-use-id-3"
|
||||
aria-expanded="false"
|
||||
aria-haspopup="listbox"
|
||||
aria-label="What's your status?"
|
||||
class="_link_k9ljz_8 SetStatusView-module_setStatusTrigger"
|
||||
data-kind="primary"
|
||||
data-size="md"
|
||||
rel="noreferrer noopener"
|
||||
role="combobox"
|
||||
>
|
||||
<svg
|
||||
fill="currentColor"
|
||||
height="1em"
|
||||
viewBox="0 0 24 24"
|
||||
width="1em"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M15.536 15.536a1 1 0 0 0-1.415-1.415 3 3 0 0 1-2.12.879 3 3 0 0 1-2.122-.879 1 1 0 1 0-1.414 1.415A5 5 0 0 0 12 17c1.38 0 2.632-.56 3.536-1.464M10 10.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m5.5 1.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3"
|
||||
/>
|
||||
<path
|
||||
d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10m-2 0a8 8 0 1 0-16 0 8 8 0 0 0 16 0"
|
||||
/>
|
||||
</svg>
|
||||
<span
|
||||
class="_typography_6v6n8_153 _font-body-md-medium_6v6n8_60"
|
||||
>
|
||||
What's your status?
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
<div
|
||||
class="_content_1xtut_62"
|
||||
>
|
||||
<ul
|
||||
class="_content_1xtut_62"
|
||||
id="react-use-id-3"
|
||||
role="listbox"
|
||||
>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
💬 In a meeting
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
💡 Focus Time
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
🚙 On the road
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
☕️ Be right back
|
||||
|
||||
</li>
|
||||
<li
|
||||
aria-selected="false"
|
||||
role="option"
|
||||
tabindex="0"
|
||||
>
|
||||
🌴 Away
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section
|
||||
class="UserMenu-module_profile UserMenu-module_profileSecondary"
|
||||
>
|
||||
<span
|
||||
class="_typography_6v6n8_153 _font-body-md-regular_6v6n8_50 UserMenu-module_userId"
|
||||
data-testid="userId"
|
||||
|
||||
Reference in New Issue
Block a user