Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 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
25 changes: 17 additions & 8 deletions res/css/structures/_ThreadsActivityCentre.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@
*/

.mx_ThreadsActivityCentreButton {
color: $secondary-content;
height: 32px;
min-width: 32px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 8px;
margin: 18px auto auto auto;

&.expanded {
/* align with settings icon */
margin-left: 25px;
margin-left: 21px;

& > .mx_ThreadsActivityCentreButton_IndicatorIcon {
/**
* modify internal css of the compound component
* dirty but we need to add the `Threads` label into the indicator icon button
**/
& > div {
display: flex;
align-items: center;
}

& .mx_ThreadsActivityCentreButton_Icon {
/* align with settings label */
margin-right: 14px;
/* required to set the icon width when into a flex container */
min-width: 24px;
}

& .mx_ThreadsActivityCentreButton_Text {
color: $secondary-content;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import React, { forwardRef, HTMLProps } from "react";
import { Icon } from "@vector-im/compound-design-tokens/icons/threads-solid.svg";
import classNames from "classnames";
import { IndicatorIcon } from "@vector-im/compound-web";
import { IconButton, Text, Tooltip } from "@vector-im/compound-web";

import { _t } from "../../../../languageHandler";
import AccessibleTooltipButton from "../../elements/AccessibleTooltipButton";
import { NotificationLevel } from "../../../../stores/notifications/NotificationLevel";
import { notificationLevelToIndicator } from "../../../../utils/notifications";

Expand All @@ -42,26 +41,36 @@ interface ThreadsActivityCentreButtonProps extends HTMLProps<HTMLDivElement> {
*/
export const ThreadsActivityCentreButton = forwardRef<HTMLDivElement, ThreadsActivityCentreButtonProps>(
function ThreadsActivityCentreButton({ displayLabel, notificationLevel, ...props }, ref): React.JSX.Element {
// Disable tooltip when the label is displayed
const openTooltip = displayLabel ? false : undefined;

return (
<AccessibleTooltipButton
className={classNames("mx_ThreadsActivityCentreButton", { expanded: displayLabel })}
title={_t("common|threads")}
// @ts-ignore
// ref nightmare...
ref={ref}
forceHide={displayLabel}
aria-expanded={displayLabel}
{...props}
>
<IndicatorIcon
className="mx_ThreadsActivityCentreButton_IndicatorIcon"
<Tooltip label={_t("common|threads")} side="right" open={openTooltip}>
<IconButton
aria-label={_t("common|threads")}
className={classNames("mx_ThreadsActivityCentreButton", { expanded: displayLabel })}
indicator={notificationLevelToIndicator(notificationLevel)}
size="24px"
// @ts-ignore
// ref nightmare...
ref={ref}
Comment thread
t3chguy marked this conversation as resolved.
Outdated
{...props}
>
<Icon className="mx_ThreadsActivityCentreButton_Icon" />
</IndicatorIcon>
{displayLabel && _t("common|threads")}
</AccessibleTooltipButton>
<>
<Icon className="mx_ThreadsActivityCentreButton_Icon" />
{/* This is dirty, but we need to add the label to the indicator icon */}
Comment thread
t3chguy marked this conversation as resolved.
{displayLabel && (
<Text
className="mx_ThreadsActivityCentreButton_Text"
as="span"
size="md"
title={_t("common|threads")}
>
{_t("common|threads")}
</Text>
)}
</>
</IconButton>
</Tooltip>
);
},
);
19 changes: 15 additions & 4 deletions test/components/views/spaces/ThreadsActivityCentre-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* /
*/

import React from "react";
import React, { ComponentProps } from "react";
import { getByText, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { NotificationCountType, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
import { TooltipProvider } from "@vector-im/compound-web";

import { ThreadsActivityCentre } from "../../../../src/components/views/spaces/threads-activity-centre";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
Expand All @@ -37,12 +38,16 @@ describe("ThreadsActivityCentre", () => {
return screen.getByRole("menu");
};

const renderTAC = () => {
const getTACDescription = () => {
return screen.getByText("Threads");
};

const renderTAC = (props?: ComponentProps<typeof ThreadsActivityCentre>) => {
render(
<MatrixClientContext.Provider value={cli}>
<ThreadsActivityCentre />
);
<ThreadsActivityCentre {...props} />
</MatrixClientContext.Provider>,
{ wrapper: TooltipProvider },
);
};

Expand Down Expand Up @@ -105,6 +110,12 @@ describe("ThreadsActivityCentre", () => {
expect(getTACButton()).toBeInTheDocument();
});

it("should render the threads activity centre button and the display label", async () => {
renderTAC({ displayButtonLabel: true });
expect(getTACButton()).toBeInTheDocument();
expect(getTACDescription()).toBeInTheDocument();
});

it("should render the threads activity centre menu when the button is clicked", async () => {
renderTAC();
await userEvent.click(getTACButton());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] = `
<div
aria-labelledby="radix-12"
aria-labelledby="radix-20"
aria-orientation="vertical"
class="_menu_1x5h1_17"
data-align="end"
Expand All @@ -11,7 +11,7 @@ exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] =
data-side="right"
data-state="open"
dir="ltr"
id="radix-13"
id="radix-21"
role="menu"
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;"
tabindex="-1"
Expand Down Expand Up @@ -127,7 +127,7 @@ exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] =

exports[`ThreadsActivityCentre should match snapshot when empty 1`] = `
<div
aria-labelledby="radix-18"
aria-labelledby="radix-28"
aria-orientation="vertical"
class="_menu_1x5h1_17"
data-align="end"
Expand All @@ -136,7 +136,7 @@ exports[`ThreadsActivityCentre should match snapshot when empty 1`] = `
data-side="right"
data-state="open"
dir="ltr"
id="radix-19"
id="radix-29"
role="menu"
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;"
tabindex="-1"
Expand Down