Skip to content

Commit 0bd1d3d

Browse files
committed
Style shuffling
1 parent a428734 commit 0bd1d3d

File tree

8 files changed

+389
-455
lines changed

8 files changed

+389
-455
lines changed

packages/shared-components/src/event-tiles/UrlPreviewView/LinkPreview.module.css

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,70 @@
1111
}
1212

1313
.container {
14-
margin: var(--cpd-space-4x) 0 var(--cpd-space-4x) auto;
15-
display: flex;
14+
display: inline flex;
1615
column-gap: var(--cpd-space-1x);
1716
border-inline-start: 2px solid var(--cpd-color-bg-subtle-primary);
1817
border-radius: 2px;
1918
color: var(--cpd-color-gray-900);
19+
min-width: 400px;
20+
2021
&.compactLayout & {
21-
margin-top: 6px;
22-
margin-bottom: 6px;
22+
margin-top: var(--cpd-space-3x);
23+
margin-bottom: var(--cpd-space-3x);
2324
}
2425

25-
/* Exclude mx_LinkPreviewGroup_hide from wrapping */
26-
.mx_LinkPreviewWidget_wrapImageCaption {
27-
display: flex;
26+
.wrapImageCaption {
27+
display: inline-flex;
28+
flex-direction: row;
2829
flex-wrap: wrap;
2930
row-gap: var(--cpd-space-2x);
3031
flex: 1;
32+
}
3133

32-
.mx_LinkPreviewWidget_image,
33-
.mx_LinkPreviewWidget_caption {
34-
margin-inline-start: var(--cpd-space-4x);
35-
min-width: 0; /* Prevent blowout */
36-
}
37-
38-
.mx_LinkPreviewWidget_image {
39-
flex: 0 0 100px;
40-
text-align: center;
41-
cursor: pointer;
34+
.image,
35+
.caption {
36+
display: inline-flex;
37+
flex-direction: column;
38+
margin-inline-start: var(--cpd-space-4x);
39+
min-width: 0; /* Prevent blowout */
40+
}
4241

43-
/* Clear default <button> styles */
44-
padding: 0;
45-
border: none;
46-
background: none;
47-
}
42+
.image {
43+
/* Clear default <button> styles */
44+
padding: 0;
45+
border: none;
46+
background: none;
47+
}
4848

49-
.mx_LinkPreviewWidget_caption {
50-
flex: 1;
51-
overflow: hidden; /* cause it to wrap rather than clip */
52-
}
49+
.caption {
50+
flex: 1;
51+
overflow: hidden; /* cause it to wrap rather than clip */
52+
}
5353

54-
.mx_LinkPreviewWidget_title,
55-
.mx_LinkPreviewWidget_description {
56-
display: -webkit-box;
57-
-webkit-box-orient: vertical;
58-
overflow: hidden;
59-
white-space: normal;
60-
}
54+
.title,
55+
.description {
56+
display: inline-block;
57+
-webkit-box-orient: vertical;
58+
overflow: hidden;
59+
white-space: normal;
60+
}
6161

62-
.mx_LinkPreviewWidget_title {
63-
font-weight: bold;
64-
-webkit-line-clamp: 2;
62+
.title {
63+
display: inline-block;
64+
line-clamp: 2;
65+
-webkit-line-clamp: 2;
66+
margin: var(--cpd-space-1x) 0;
6567

66-
.mx_LinkPreviewWidget_siteName {
67-
font-weight: normal;
68-
}
68+
> a {
69+
font-weight: var(--cpd-font-weight-semibold);
70+
text-decoration: none;
6971
}
72+
}
7073

71-
.mx_LinkPreviewWidget_description {
72-
margin-top: var(--cpd-space-2x);
73-
word-wrap: break-word;
74-
-webkit-line-clamp: 3;
75-
}
74+
.description {
75+
margin: var(--cpd-space-1x) 0;
76+
word-wrap: break-word;
77+
line-clamp: 2;
78+
-webkit-line-clamp: 3;
7679
}
7780
}

packages/shared-components/src/event-tiles/UrlPreviewView/LinkPreview.stories.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default {
1717
component: LinkPreview,
1818
tags: ["autodocs"],
1919
args: {
20-
onHideClick: fn(),
2120
onImageClick: fn(),
2221
},
2322
} satisfies Meta<typeof LinkPreview>;
@@ -69,3 +68,16 @@ WithCompactLayout.args = {
6968
imageFull: imageFile,
7069
},
7170
};
71+
72+
export const WithVeryLongText = Template.bind({});
73+
WithVeryLongText.args = {
74+
title: "GitHub - element-hq/not-a-real-repo: A very very long PR title that should be rendered nicely",
75+
description:
76+
"This PR doesn't actually exist and neither does the repository. It might exist one day if we go into the business of making paradoxical repository names.",
77+
link: "https://matrix.org",
78+
siteName: "GitHub",
79+
image: {
80+
imageThumb: imageFile,
81+
imageFull: imageFile,
82+
},
83+
};

packages/shared-components/src/event-tiles/UrlPreviewView/LinkPreview.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { describe, it, expect } from "vitest";
1111
import React from "react";
1212

1313
import * as stories from "./LinkPreview.stories.tsx";
14+
import userEvent from "@testing-library/user-event";
1415

1516
const { Default, WithCompactLayout, WithTooltip, Title, TitleAndDescription } = composeStories(stories);
1617

@@ -27,8 +28,9 @@ describe("LinkPreview", () => {
2728
const { container } = render(<TitleAndDescription />);
2829
expect(container).toMatchSnapshot();
2930
});
30-
it("renders a preview with a tooltip", () => {
31-
const { container } = render(<WithTooltip />);
31+
it("renders a preview with a tooltip", async () => {
32+
const { container, getByText } = render(<WithTooltip />);
33+
await userEvent.hover(getByText("A simple title"));
3234
expect(container).toMatchSnapshot();
3335
});
3436
it("renders a preview with a compact layout", () => {

packages/shared-components/src/event-tiles/UrlPreviewView/LinkPreview.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
*/
77

88
import React, { type MouseEventHandler, type JSX, useCallback } from "react";
9-
import { IconButton, Tooltip } from "@vector-im/compound-web";
10-
import CloseIcon from "@vector-im/compound-design-tokens/assets/web/icons/close";
9+
import { Tooltip, Text } from "@vector-im/compound-web";
1110
import classNames from "classnames";
1211

1312
import { useI18n } from "../../utils/i18nContext";
1413
import styles from "./LinkPreview.module.css";
1514
import type { UrlPreviewViewSnapshotPreview } from "./types";
1615

1716
export interface LinkPreviewActions {
18-
onHideClick?: () => Promise<void>;
1917
onImageClick: () => void;
2018
}
2119

@@ -25,13 +23,8 @@ export interface LinkPreviewAdditionalProps {
2523

2624
export type LinkPreviewProps = UrlPreviewViewSnapshotPreview & LinkPreviewActions & LinkPreviewAdditionalProps;
2725

28-
export function LinkPreview({ onHideClick, onImageClick, compactLayout, ...preview }: LinkPreviewProps): JSX.Element {
26+
export function LinkPreview({ onImageClick, compactLayout, ...preview }: LinkPreviewProps): JSX.Element {
2927
const { translate: _t } = useI18n();
30-
const hideButton = onHideClick && (
31-
<IconButton size="20px" onClick={() => onHideClick()} aria-label={_t("timeline|url_preview|close")}>
32-
<CloseIcon />
33-
</IconButton>
34-
);
3528

3629
const onImageClickHandler = useCallback<MouseEventHandler>(
3730
(ev) => {
@@ -52,7 +45,7 @@ export function LinkPreview({ onHideClick, onImageClick, compactLayout, ...previ
5245
img = (
5346
<button
5447
aria-label={_t("timeline|url_preview|view_image")}
55-
className={styles.mx_LinkPreviewWidget_image}
48+
className={styles.image}
5649
onClick={onImageClickHandler}
5750
>
5851
<img className={styles.thumbnail} src={preview.image.imageThumb} alt="" />
@@ -67,28 +60,29 @@ export function LinkPreview({ onHideClick, onImageClick, compactLayout, ...previ
6760
);
6861
return (
6962
<div className={classNames(styles.container, compactLayout && "compactLayout")}>
70-
<div className={styles.mx_LinkPreviewWidget_wrapImageCaption}>
63+
<div className={styles.wrapImageCaption}>
7164
{img}
72-
<div className={styles.mx_LinkPreviewWidget_caption}>
73-
<div className={styles.mx_LinkPreviewWidget_title}>
65+
<div className={styles.caption}>
66+
<Text type="body" size="md" className={styles.title}>
7467
{preview.showTooltipOnLink ? (
7568
<Tooltip label={new URL(preview.link, window.location.href).toString()}>{anchor}</Tooltip>
7669
) : (
7770
anchor
7871
)}
7972
{preview.siteName && (
80-
<span className={styles.mx_LinkPreviewWidget_siteName}>{" - " + preview.siteName}</span>
73+
<Text as="span" size="md" weight="regular">
74+
{" - " + preview.siteName}
75+
</Text>
8176
)}
82-
</div>
77+
</Text>
8378
{preview.description && (
84-
<div
85-
className={styles.mx_LinkPreviewWidget_description}
79+
<Text
80+
className={styles.description}
8681
dangerouslySetInnerHTML={{ __html: preview.description }}
8782
/>
8883
)}
8984
</div>
9085
</div>
91-
{hideButton}
9286
</div>
9387
);
9488
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2026 Element Creations Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
.previewGroup {
9+
display: flex;
10+
flex-direction: column;
11+
gap: var(--cpd-space-4x);
12+
.toggleButton {
13+
margin-left: auto;
14+
margin-right: auto;
15+
text-decoration: none;
16+
color: var(--cpd-color-icon-accent-primary);
17+
font-weight: var(--cpd-font-weight-regular);
18+
}
19+
}
20+
21+
.wrapper {
22+
display: flex;
23+
flex-direction: row;
24+
}

packages/shared-components/src/event-tiles/UrlPreviewView/UrlPreviewGroupView.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
*/
77

88
import React, { type JSX } from "react";
9-
import { Button } from "@vector-im/compound-web";
10-
9+
import { Button, IconButton } from "@vector-im/compound-web";
10+
import CloseIcon from "@vector-im/compound-design-tokens/assets/web/icons/close";
1111
import { useViewModel, type ViewModel } from "../../viewmodel";
1212
import { useI18n } from "../../utils/i18nContext";
1313
import type { UrlPreviewViewSnapshotPreview } from "./types";
1414
import { LinkPreview } from "./LinkPreview";
15+
import styles from "./UrlPreviewGroupView.module.css";
1516

1617
export interface UrlPreviewGroupViewSnapshot {
1718
previews: Array<UrlPreviewViewSnapshotPreview>;
@@ -49,7 +50,7 @@ export function UrlPreviewGroupView({ vm }: UrlPreviewGroupViewProps): JSX.Eleme
4950
let toggleButton: JSX.Element | undefined;
5051
if (overPreviewLimit) {
5152
toggleButton = (
52-
<Button kind="tertiary" size="sm" onClick={() => vm.onTogglePreviewLimit()}>
53+
<Button className={styles.toggleButton} kind="tertiary" size="sm" onClick={() => vm.onTogglePreviewLimit()}>
5354
{previewsLimited
5455
? _t("timeline|url_preview|show_n_more", { count: totalPreviewCount - previews.length })
5556
: _t("action|collapse")}
@@ -58,17 +59,22 @@ export function UrlPreviewGroupView({ vm }: UrlPreviewGroupViewProps): JSX.Eleme
5859
}
5960

6061
return (
61-
<div>
62-
{previews.map((preview, i) => (
63-
<LinkPreview
64-
key={preview.link}
65-
compactLayout={compactLayout}
66-
onHideClick={i == 0 ? vm.onHideClick : undefined}
67-
onImageClick={() => vm.onImageClick(preview)}
68-
{...preview}
69-
/>
70-
))}
71-
{toggleButton}
62+
<div className={styles.wrapper}>
63+
<div className={styles.previewGroup}>
64+
{previews.map((preview, i) => (
65+
<LinkPreview
66+
key={preview.link}
67+
compactLayout={compactLayout}
68+
onHideClick={i == 0 ? vm.onHideClick : undefined}
69+
onImageClick={() => vm.onImageClick(preview)}
70+
{...preview}
71+
/>
72+
))}
73+
{toggleButton}
74+
</div>
75+
<IconButton size="20px" onClick={() => vm.onHideClick()} aria-label={_t("timeline|url_preview|close")}>
76+
<CloseIcon />
77+
</IconButton>
7278
</div>
7379
);
7480
}

0 commit comments

Comments
 (0)