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

Improve LinkPreviewWidget #8881

Merged
merged 16 commits into from
Jul 4, 2022
Merged
87 changes: 48 additions & 39 deletions res/css/views/rooms/_LinkPreviewWidget.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,62 @@ limitations under the License.
*/

.mx_LinkPreviewWidget {
margin-top: 15px;
margin-right: 15px;
margin-bottom: 15px;
margin: $spacing-16 0 $spacing-16 auto;
display: flex;
border-left: 2px solid $preview-widget-bar-color;
column-gap: $spacing-4;
border-inline-start: 2px solid $preview-widget-bar-color;
border-radius: 2px;
color: $info-plinth-fg-color;
}

.mx_LinkPreviewWidget_image {
flex: 0 0 100px;
margin-left: 15px;
text-align: center;
cursor: pointer;
}
.mx_MatrixChat_useCompactLayout & {
margin-top: 6px;
margin-bottom: 6px;
}

.mx_LinkPreviewWidget_caption {
margin-left: 15px;
flex: 1 1 auto;
overflow: hidden; // cause it to wrap rather than clip
}
// Exclude mx_LinkPreviewGroup_hide from wrapping
.mx_LinkPreviewWidget_wrapImageCaption {
display: flex;
flex-wrap: wrap;
row-gap: $spacing-8;

.mx_LinkPreviewWidget_title {
font-weight: bold;
white-space: normal;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
.mx_LinkPreviewWidget_image,
.mx_LinkPreviewWidget_caption {
margin-inline-start: $spacing-16;
min-width: 0; // Prevent blowout
}

.mx_LinkPreviewWidget_siteName {
font-weight: normal;
}
}
.mx_LinkPreviewWidget_image {
flex: 0 0 100px;
text-align: center;
cursor: pointer;
}

.mx_LinkPreviewWidget_description {
margin-top: 8px;
white-space: normal;
word-wrap: break-word;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.mx_LinkPreviewWidget_caption {
flex: 1;
overflow: hidden; // cause it to wrap rather than clip
}

.mx_MatrixChat_useCompactLayout {
.mx_LinkPreviewWidget {
margin-top: 6px;
margin-bottom: 6px;
.mx_LinkPreviewWidget_title,
.mx_LinkPreviewWidget_description {
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
white-space: normal;
}

.mx_LinkPreviewWidget_title {
font-weight: bold;
-webkit-line-clamp: 2;

.mx_LinkPreviewWidget_siteName {
font-weight: normal;
}
}

.mx_LinkPreviewWidget_description {
margin-top: $spacing-8;
word-wrap: break-word;
-webkit-line-clamp: 3;
}
}
}
22 changes: 12 additions & 10 deletions src/components/views/rooms/LinkPreviewWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,18 @@ export default class LinkPreviewWidget extends React.Component<IProps> {

return (
<div className="mx_LinkPreviewWidget">
{ img }
<div className="mx_LinkPreviewWidget_caption">
<div className="mx_LinkPreviewWidget_title">
<a href={this.props.link} target="_blank" rel="noreferrer noopener">{ p["og:title"] }</a>
{ p["og:site_name"] && <span className="mx_LinkPreviewWidget_siteName">
{ (" - " + p["og:site_name"]) }
</span> }
</div>
<div className="mx_LinkPreviewWidget_description" ref={this.description}>
{ description }
<div className="mx_LinkPreviewWidget_wrapImageCaption">
{ img }
<div className="mx_LinkPreviewWidget_caption">
<div className="mx_LinkPreviewWidget_title">
<a href={this.props.link} target="_blank" rel="noreferrer noopener">{ p["og:title"] }</a>
{ p["og:site_name"] && <span className="mx_LinkPreviewWidget_siteName">
{ (" - " + p["og:site_name"]) }
</span> }
</div>
<div className="mx_LinkPreviewWidget_description" ref={this.description}>
{ description }
</div>
</div>
</div>
{ this.props.children }
Expand Down