Problem/Motivation
Logo images that are designed as white on transparent are invisible in the media library.
Before:

After:

Proposed resolution
Add a checkered background on all images in media library. this will not only help white images on transparent background, but will help identify any image that has a transparency layer.
To achieve the checkered background, we can use a well-vetted pure CSS solution approach already used by Claro theme for the "image-preview" (upload widget) and expand it for use in the Media Library, by making it a SASS mixin.
We can add new color variables --colorPatternFallback, --colorPattern and --sizePattern.
We can leverage all Media Library admin views including the modal media library (grid and table displays) as well as the admin page at /admin/content/media (grid and table displays). Note: the table display on /admin/content/media currently requires a core patch to see the checkered background properly: #3279578: Media Library Page Table view should have same classes as Media Library Modal Table view
Remaining tasks
approve approachwrite patch- community review & testing
User interface changes
Images with transparency will now be detectable in the media library.
API changes
n/a
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | pattern_darkmode.png | 1.2 MB | saschaeggi |
| #15 | pattern.png | 1.21 MB | saschaeggi |
| #13 | Screen Shot 2022-05-09 at 6.18.46 PM.png | 172.14 KB | jwilson3 |
| #13 | Screen Shot 2022-05-09 at 8.03.40 PM.png | 622.36 KB | jwilson3 |
| #13 | Screen Shot 2022-05-09 at 8.03.52 PM.png | 90.26 KB | jwilson3 |
Issue fork gin-3278033
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jwilson3While testing, I just found code in Claro theme that already does the checkered box background image on the image upload preview widget.
I guess it probably makes sense to open a sister ticket for this in Claro theme issue queue, instead of fixing it in Gin theme.
Comment #4
jwilson3Comment #5
saschaeggi@jwilson3 I think we can already include this improvement in Gin and open a ticket for Claro afterwards to "up-port" the changes.
Do you want to update the MR to use the same pattern as the media detail page?
Comment #6
jwilson3Following up here,
I was actually able to solve this by simply editing the media library views to add `image-preview` class.Edit: nevermind, see comment #8 below on why this didnt end up working.
On the one hand this seems like a cleaner approach (no new css required!) on the other hand, this approach feels hacky to have to add the class in the view config when in theory it should just be part of the display. The main problem i see is that several display styles are affected in the different views including "thumbnail" (used on table display) as well as "rendered entity" view modes (used on the grid displays). When the raw field is rendered, there is rarely an opportunity to decorate the twig template with a class, so the best place really is on the view config.
Comment #7
jwilson3Given #6, do you still think we should take an approach to fix this using appropriately targeted css classes based on the views dom structure? or propose a core issue to add `image-preview` class to these views?
Comment #8
jwilson3As it turns out, adding the
image-previewclass to the view has caused a visual regression where the title of the image now overflows on top of itself! Too funny.In an ideal world, we could leverage this single utility class on any wrapper element around the img tag to provide the checkered background.
In reality, due to the clashing styles, we need to:
Then I suppose, we could also:
image-previewstyles in-line with Gin colors, AND targets these media displays with SCSS in Gin theme.Comment #9
jwilson3Comment #10
jwilson3Force-pushed to MR to update commit message to match clearer issue title from #9 and take a new approach, leveraging a SASS mixin so this can be used without altering views to add classes (the previous flawed approach).
The attached patch is the same as MR, which I'll use from composer.json in my project.
While working on this, I uncovered a core bug and created #3279578: Media Library Page Table view should have same classes as Media Library Modal Table view to add missing classes to /admin/content/media table view so we can consistently apply the checkered background in multiple cases, namely
.image-preview imgand.media-library-item img.Comment #11
jwilson3Comment #12
jwilson3Comment #13
jwilson3Screenshots after:
Comment #14
jwilson3Comment #15
saschaeggiLove to see this change! This is great!
I did some slight changes to the CSS3 variables to align with all other vars.
Other than that it looks good, here is a test:
Looks great in Darkmode, too!

Comment #16
saschaeggiComment #17
saschaeggiComment #19
saschaeggi