From 0909bfeb380bd4d426327233f115608361e513e8 Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Mon, 4 Jul 2022 15:10:46 +0900 Subject: [PATCH] Improve LinkPreviewWidget (#8881) * Use shorthand for margin values Signed-off-by: Suguru Hirahara * Merge style declarations Signed-off-by: Suguru Hirahara * Merge style declarations Signed-off-by: Suguru Hirahara * Include mx_MatrixChat_useCompactLayout in mx_LinkPreviewWidget Signed-off-by: Suguru Hirahara * Include in mx_LinkPreviewWidget Signed-off-by: Suguru Hirahara * yarn run lint:style --fix Signed-off-by: Suguru Hirahara * Use spacing variables Signed-off-by: Suguru Hirahara * Use logical variables Signed-off-by: Suguru Hirahara * Prevent flex children blowout Signed-off-by: Suguru Hirahara * Wrap caption Signed-off-by: Suguru Hirahara * yarn run lint:style --fix Signed-off-by: Suguru Hirahara * Set row-gap between image and caption Signed-off-by: Suguru Hirahara * Set column-gap between the caption and close button Signed-off-by: Suguru Hirahara * Rename the class name Signed-off-by: Suguru Hirahara * Decrease inline spacing Signed-off-by: Suguru Hirahara --- res/css/views/rooms/_LinkPreviewWidget.scss | 93 ++++++++++--------- .../views/rooms/LinkPreviewWidget.tsx | 22 +++-- 2 files changed, 63 insertions(+), 52 deletions(-) diff --git a/res/css/views/rooms/_LinkPreviewWidget.scss b/res/css/views/rooms/_LinkPreviewWidget.scss index 1546164710..e274994a53 100644 --- a/res/css/views/rooms/_LinkPreviewWidget.scss +++ b/res/css/views/rooms/_LinkPreviewWidget.scss @@ -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_LinkPreviewWidget_caption { - margin-left: 15px; - flex: 1 1 auto; - overflow: hidden; // cause it to wrap rather than clip -} - -.mx_LinkPreviewWidget_title { - font-weight: bold; - white-space: normal; - display: -webkit-box; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; - overflow: hidden; - - .mx_LinkPreviewWidget_siteName { - font-weight: normal; - } -} - -.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_MatrixChat_useCompactLayout { - .mx_LinkPreviewWidget { + .mx_MatrixChat_useCompactLayout & { margin-top: 6px; margin-bottom: 6px; } + + // Exclude mx_LinkPreviewGroup_hide from wrapping + .mx_LinkPreviewWidget_wrapImageCaption { + display: flex; + flex-wrap: wrap; + row-gap: $spacing-8; + + .mx_LinkPreviewWidget_image, + .mx_LinkPreviewWidget_caption { + margin-inline-start: $spacing-16; + min-width: 0; // Prevent blowout + } + + .mx_LinkPreviewWidget_image { + flex: 0 0 100px; + text-align: center; + cursor: pointer; + } + + .mx_LinkPreviewWidget_caption { + flex: 1; + overflow: hidden; // cause it to wrap rather than clip + } + + .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; + } + } } diff --git a/src/components/views/rooms/LinkPreviewWidget.tsx b/src/components/views/rooms/LinkPreviewWidget.tsx index d14c504dd8..cb28739f17 100644 --- a/src/components/views/rooms/LinkPreviewWidget.tsx +++ b/src/components/views/rooms/LinkPreviewWidget.tsx @@ -120,16 +120,18 @@ export default class LinkPreviewWidget extends React.Component { return (
- { img } -
-
- { p["og:title"] } - { p["og:site_name"] && - { (" - " + p["og:site_name"]) } - } -
-
- { description } +
+ { img } +
+
+ { p["og:title"] } + { p["og:site_name"] && + { (" - " + p["og:site_name"]) } + } +
+
+ { description } +
{ this.props.children }