discourse/app/assets/stylesheets/common/base/d-image-grid.scss
chapoi 3698aa898b
UX: image grid carousel max-height (#39962)
The children werent inheriting the max height, making them awkwardly cut
off on occasion
2026-05-13 10:21:27 +02:00

256 lines
5.1 KiB
SCSS
Vendored

.d-image-grid:not([data-disabled]) {
$grid-column-gap: 6px;
&[data-columns] {
display: flex;
flex-wrap: wrap;
}
&[data-columns="2"] > * {
flex-basis: calc(50% - ($grid-column-gap / 2));
margin-right: $grid-column-gap;
}
&[data-columns="3"] > * {
flex-basis: calc(33.33% - ($grid-column-gap * 0.667));
margin-right: $grid-column-gap;
}
.d-image-grid-column {
box-sizing: border-box;
// use flex layout, flex-grow and object-fit: cover
// to better have the images fill their containers
// and line up vertically (it's not perfect!)
display: flex;
flex-direction: column;
justify-content: flex-start;
.button-wrapper {
bottom: 0;
min-width: unset;
}
> div,
> span {
flex-grow: 1;
overflow: hidden;
// hardcoded max-height here prevents extra tall images
// from having an outsized effect on the grid
max-height: 1200px;
img:not(.thumbnail, .ytp-thumbnail-image, .emoji) {
height: 100%;
object-fit: cover;
}
}
&:last-child {
margin-right: 0;
}
> img,
> div {
margin-bottom: $grid-column-gap;
}
// Forces images in the grid to fill each column width-wise
img,
> .lightbox-wrapper,
> .lightbox-wrapper > .lightbox {
width: 100%;
}
.lightbox-wrapper {
.meta .informations {
display: none;
}
.meta .filename {
flex-grow: 3;
}
// full-height lightbox element in container
> .lightbox {
height: 100%;
}
}
// when staging edits
.image-wrapper {
display: block;
margin-bottom: $grid-column-gap;
padding-bottom: 0;
}
}
.d-editor-preview & {
.image-wrapper {
margin-bottom: $grid-column-gap;
padding-bottom: 0;
.button-wrapper {
.scale-btn-container,
&[editing] .wrap-image-grid-button {
display: none;
}
}
}
}
}
.d-image-carousel {
position: relative;
width: 100%;
display: flex;
flex-direction: column;
gap: var(--space-1);
&__track {
display: flex;
width: 100%;
height: 400px;
overflow-x: auto;
overflow-y: hidden;
scroll-snap-type: x mandatory;
scroll-behavior: smooth;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
&__slide {
.d-image-carousel--carousel & {
flex: 0 0 100%;
width: 100%;
height: 100%;
max-height: inherit;
scroll-snap-align: center;
scroll-snap-stop: always;
display: flex;
align-items: center;
justify-content: center;
img:not(.thumbnail, .ytp-thumbnail-image, .emoji) {
max-width: 100% !important;
max-height: 100% !important;
width: auto !important;
height: auto !important;
object-fit: contain !important;
border-radius: var(--d-border-radius);
}
}
.lightbox-wrapper {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: 100%;
max-height: 100%;
height: 100%;
// Ensure the lightbox link itself doesn't force a crop
.lightbox {
display: flex;
align-items: center;
justify-content: center;
max-width: 100%;
max-height: 100%;
}
}
}
&__controls {
display: flex;
align-items: center;
justify-content: center;
gap: var(--space-2);
padding-block: var(--space-2);
}
&__nav {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
border: 0;
padding: 0;
background: none;
color: var(--primary-medium);
cursor: pointer;
font-size: var(--font-down-1);
touch-action: manipulation;
&:hover {
background: none;
color: var(--primary);
}
&:disabled {
cursor: default;
opacity: 0.6;
}
}
&__dots {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.5rem 0.75rem;
background: var(--primary-very-low);
border-radius: 1rem;
}
&__dot {
height: 0.6rem;
width: 0.6rem;
padding: 0;
background: var(--primary-low-mid);
border: none;
border-radius: 1rem;
cursor: pointer;
transition:
width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.15s ease-out;
touch-action: manipulation;
&:hover {
transform: scale(1.2);
}
&.active {
background: var(--primary-medium);
width: 1.4rem;
}
}
&__counter {
padding: 0.5rem 0.75rem;
background: var(--primary-very-low);
border-radius: 1rem;
font-size: var(--font-down-1);
color: var(--primary-medium);
font-variant-numeric: tabular-nums;
text-align: center;
}
&--single {
.d-image-carousel__controls {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.d-image-carousel__track {
scroll-behavior: auto;
}
}
}