Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit d110660

Browse files
authored
Make the unread badge component more reusable (#12163)
Add a paramter to make it a dot rather than a badge rather than mangling it to a dot with CSS in EventTile. Move it to a place in the DOM that reflects where it's actually supposed to sit rather than repositioning it with CSS. Tweak sizes to match what figma says (8px everywhere for dots rather than 6px in some places as it was).
1 parent 4e68b91 commit d110660

File tree

5 files changed

+19
-36
lines changed

5 files changed

+19
-36
lines changed

res/css/views/rooms/_EventTile.pcss

-25
Original file line numberDiff line numberDiff line change
@@ -1053,23 +1053,6 @@ $left-gutter: 64px;
10531053
pointer-events: none; /* ensures the title for the sender name can be correctly displayed */
10541054
}
10551055

1056-
/* Display notification dot */
1057-
&[data-notification]::before,
1058-
.mx_NotificationBadge {
1059-
position: absolute;
1060-
$notification-inset-block-start: 14px; /* 14px: align the dot with the timestamp row */
1061-
1062-
/* !important to fix overly specific CSS selector applied on mx_NotificationBadge */
1063-
width: $notification-dot-size !important;
1064-
height: $notification-dot-size !important;
1065-
border-radius: 50%;
1066-
inset: $notification-inset-block-start $spacing-8 auto auto;
1067-
}
1068-
1069-
.mx_NotificationBadge_count {
1070-
display: none;
1071-
}
1072-
10731056
&[data-notification="total"]::before {
10741057
background-color: $room-icon-unread-color;
10751058
}
@@ -1441,14 +1424,6 @@ $left-gutter: 64px;
14411424
margin-bottom: $spacing-4; /* 1/4 of the non-compact margin-bottom */
14421425
}
14431426
}
1444-
1445-
&[data-shape="ThreadsList"][data-notification]::before,
1446-
.mx_NotificationBadge {
1447-
/* stylelint-disable-next-line declaration-colon-space-after */
1448-
inset-block-start: calc(
1449-
$notification-inset-block-start - var(--MatrixChat_useCompactLayout_group-padding-top)
1450-
);
1451-
}
14521427
}
14531428
}
14541429

res/css/views/rooms/_NotificationBadge.pcss

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ limitations under the License.
4141
/* These are the 3 background types */
4242

4343
&.mx_NotificationBadge_dot {
44-
background-color: $primary-content; /* increased visibility */
44+
width: 8px;
45+
height: 8px;
46+
border-radius: 8px;
4547

46-
width: 6px;
47-
height: 6px;
48-
border-radius: 6px;
48+
.mx_NotificationBadge_count {
49+
display: none;
50+
}
4951
}
5052

5153
&.mx_NotificationBadge_knocked {

src/components/views/rooms/EventTile.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,11 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
13081308
""
13091309
)}
13101310
{timestamp}
1311+
<UnreadNotificationBadge
1312+
room={room || undefined}
1313+
threadId={this.props.mxEvent.getId()}
1314+
type="dot"
1315+
/>
13111316
</div>
13121317
{isRenderingNotification && room ? (
13131318
<div className="mx_EventTile_avatar">
@@ -1336,7 +1341,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
13361341
)}
13371342

13381343
{msgOption}
1339-
<UnreadNotificationBadge room={room || undefined} threadId={this.props.mxEvent.getId()} />
13401344
</>,
13411345
);
13421346
}

src/components/views/rooms/NotificationBadge/StatelessNotificationBadge.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface Props {
2828
count: number;
2929
level: NotificationLevel;
3030
knocked?: boolean;
31+
type?: "badge" | "dot";
3132
}
3233

3334
interface ClickableProps extends Props {
@@ -39,7 +40,7 @@ interface ClickableProps extends Props {
3940
}
4041

4142
export const StatelessNotificationBadge = forwardRef<HTMLDivElement, XOR<Props, ClickableProps>>(
42-
({ symbol, count, level, knocked, ...props }, ref) => {
43+
({ symbol, count, level, knocked, type = "badge", ...props }, ref) => {
4344
const hideBold = useSettingValue("feature_hidebold");
4445

4546
// Don't show a badge if we don't need to
@@ -59,10 +60,10 @@ export const StatelessNotificationBadge = forwardRef<HTMLDivElement, XOR<Props,
5960
mx_NotificationBadge: true,
6061
mx_NotificationBadge_visible: isEmptyBadge || knocked ? true : hasUnreadCount,
6162
mx_NotificationBadge_highlighted: level >= NotificationLevel.Highlight,
62-
mx_NotificationBadge_dot: isEmptyBadge && !knocked,
63+
mx_NotificationBadge_dot: (isEmptyBadge && !knocked) || type === "dot",
6364
mx_NotificationBadge_knocked: knocked,
64-
mx_NotificationBadge_2char: symbol && symbol.length > 0 && symbol.length < 3,
65-
mx_NotificationBadge_3char: symbol && symbol.length > 2,
65+
mx_NotificationBadge_2char: type === "badge" && symbol && symbol.length > 0 && symbol.length < 3,
66+
mx_NotificationBadge_3char: type === "badge" && symbol && symbol.length > 2,
6667
});
6768

6869
if (props.onClick) {

src/components/views/rooms/NotificationBadge/UnreadNotificationBadge.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import { StatelessNotificationBadge } from "./StatelessNotificationBadge";
2323
interface Props {
2424
room?: Room;
2525
threadId?: string;
26+
type?: "badge" | "dot";
2627
}
2728

28-
export function UnreadNotificationBadge({ room, threadId }: Props): JSX.Element {
29+
export function UnreadNotificationBadge({ room, threadId, type }: Props): JSX.Element {
2930
const { symbol, count, level } = useUnreadNotifications(room, threadId);
3031

31-
return <StatelessNotificationBadge symbol={symbol} count={count} level={level} />;
32+
return <StatelessNotificationBadge symbol={symbol} count={count} level={level} type={type} />;
3233
}

0 commit comments

Comments
 (0)