From bbd0e9caa67e2cc0b7b34bbc04885cef751d8d6f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 2 May 2023 14:47:04 +0200 Subject: [PATCH] [Glitch] Add ALT badges to media that has alternative text in web UI Port 8131a5b330c6fb20ca9aa5cd1ba04c7f9ddc33d2 to glitch-soc Signed-off-by: Claire --- .../glitch/components/media_gallery.jsx | 57 +++++-------------- .../glitch/styles/components/media.scss | 44 +++++++------- 2 files changed, 40 insertions(+), 61 deletions(-) diff --git a/app/javascript/flavours/glitch/components/media_gallery.jsx b/app/javascript/flavours/glitch/components/media_gallery.jsx index b455fb9a30..9bbde3b5e9 100644 --- a/app/javascript/flavours/glitch/components/media_gallery.jsx +++ b/app/javascript/flavours/glitch/components/media_gallery.jsx @@ -101,12 +101,10 @@ class Item extends React.PureComponent { render () { const { attachment, lang, index, size, standalone, letterbox, displayWidth, visible } = this.props; + let badges = [], thumbnail; + let width = 50; let height = 100; - let top = 'auto'; - let left = 'auto'; - let bottom = 'auto'; - let right = 'auto'; if (size === 1) { width = 100; @@ -116,45 +114,13 @@ class Item extends React.PureComponent { height = 50; } - if (size === 2) { - if (index === 0) { - right = '2px'; - } else { - left = '2px'; - } - } else if (size === 3) { - if (index === 0) { - right = '2px'; - } else if (index > 0) { - left = '2px'; - } - - if (index === 1) { - bottom = '2px'; - } else if (index > 1) { - top = '2px'; - } - } else if (size === 4) { - if (index === 0 || index === 2) { - right = '2px'; - } - - if (index === 1 || index === 3) { - left = '2px'; - } - - if (index < 2) { - bottom = '2px'; - } else { - top = '2px'; - } + if (attachment.get('description')?.length > 0) { + badges.push(ALT); } - let thumbnail = ''; - if (attachment.get('type') === 'unknown') { return ( -
+
GIF); + thumbnail = (
); } return ( -
+
+ {visible && thumbnail} + + {badges && ( +
+ {badges} +
+ )}
); } diff --git a/app/javascript/flavours/glitch/styles/components/media.scss b/app/javascript/flavours/glitch/styles/components/media.scss index 2f36edd19b..a708d066ae 100644 --- a/app/javascript/flavours/glitch/styles/components/media.scss +++ b/app/javascript/flavours/glitch/styles/components/media.scss @@ -43,32 +43,27 @@ font-weight: 500; } -.media-gallery__gifv__label { - display: block; +.media-gallery__item__badges { position: absolute; - color: $primary-text-color; - background: rgba($base-overlay-background, 0.5); bottom: 6px; inset-inline-start: 6px; + display: flex; + gap: 2px; +} + +.media-gallery__gifv__label { + display: block; + color: $white; + background: rgba($black, 0.65); padding: 2px 6px; - border-radius: 2px; + border-radius: 4px; font-size: 11px; - font-weight: 600; + font-weight: 700; z-index: 1; pointer-events: none; - opacity: 0.9; - transition: opacity 0.1s ease; line-height: 18px; } -.media-gallery__gifv { - &:hover { - .media-gallery__gifv__label { - opacity: 1; - } - } -} - .media-gallery { box-sizing: border-box; margin-top: 8px; @@ -77,6 +72,10 @@ position: relative; width: 100%; min-height: 64px; + display: grid; + grid-template-columns: 50% 50%; + grid-template-rows: 50% 50%; + gap: 2px; @include fullwidth-gallery; } @@ -85,13 +84,16 @@ border: 0; box-sizing: border-box; display: block; - float: left; position: relative; border-radius: 4px; overflow: hidden; - .full-width & { - border-radius: 0; + &--tall { + grid-row: span 2; + } + + &--wide { + grid-column: span 2; } &.standalone { @@ -101,6 +103,10 @@ } } + .full-width & { + border-radius: 0; + } + &.letterbox { background: $base-shadow-color; }