refactor: Адаптив виджета переработан на использование container quries

This commit is contained in:
Ilia Mashkov
2025-11-23 16:09:23 +03:00
parent 92e0b474a4
commit 174547791b
4 changed files with 107 additions and 94 deletions

View File

@@ -33,27 +33,19 @@
} }
:global(.swiper) { :global(.swiper) {
@media (width <=768px) { @container timeframe-slider (width <=768px) {
padding: 0 20px; padding: 0 40px;
} }
} }
:global(.swiper-slide-next) { :global(.swiper-slide-visible) {
transition: opacity 0.3s ease; transition: opacity 0.3s ease;
@media (width <=768px) { @container timeframe-slider (width <768px) {
opacity: 0.4; opacity: 0.4;
} }
} }
:global(.swiper-slide-prev) { :global(.swiper-slide-fully-visible) {
transition: opacity 0.3s ease;
@media (width <=768px) {
opacity: 0.4;
}
}
:global(.swiper-slide-active) {
opacity: 1; opacity: 1;
} }

View File

@@ -16,7 +16,7 @@ export const EVENT_CAROUSEL_CONFIG: SwiperOptions = {
}, },
breakpoints: { breakpoints: {
576: { 576: {
slidesPerView: 2, slidesPerView: 2.5,
}, },
768: { 768: {
slidesPerView: 2, slidesPerView: 2,

View File

@@ -1,3 +1,10 @@
/* Wrapper для container queries - должен быть родителем контейнера */
.wrapper {
/* Включаем container queries для адаптивности виджета */
container-type: inline-size;
container-name: timeframe-slider;
}
.container { .container {
position: relative; position: relative;
@@ -23,11 +30,11 @@
overflow: hidden; overflow: hidden;
@media (width <=1024px) { @container timeframe-slider (width <=1024px) {
padding-top: 100px; padding-top: 100px;
} }
@media (width <=768px) { @container timeframe-slider (width <=576px) {
padding: 60px 20px 20px; padding: 60px 20px 20px;
background-image: unset; background-image: unset;
@@ -51,20 +58,24 @@
border-image: var(--gradient-primary) 1; border-image: var(--gradient-primary) 1;
@media (width <=1024px) { @container timeframe-slider (width <=1024px) {
top: 80px; top: 80px;
font-size: 40px; font-size: 40px;
} }
@media (width <=768px) { @container timeframe-slider (width <=768px) {
padding-left: 20px;
font-size: 34px;
}
@container timeframe-slider (width <=576px) {
position: relative; position: relative;
inset: unset; inset: unset;
margin-bottom: 20px; margin-bottom: 20px;
padding-left: 0; padding-left: 0;
font-size: 20px;
border: none; border: none;
} }
@@ -85,7 +96,7 @@
background-position: center; background-position: center;
background-size: 100% 1px; background-size: 100% 1px;
@media (width <=768px) { @container timeframe-slider (width <=576px) {
position: unset; position: unset;
display: flex; display: flex;
@@ -111,19 +122,22 @@
transform-origin: left; transform-origin: left;
@media (width <=1024px) { @container timeframe-slider (width <=1024px) {
left: 100px; left: 100px;
bottom: 40px; bottom: 40px;
} }
@media (width <=768px) { @container timeframe-slider (width <=768px) {
left: 40px;
gap: 10px;
}
@container timeframe-slider (width <=576px) {
left: 20px; left: 20px;
bottom: 13px; bottom: 13px;
order: 2; order: 2;
gap: 10px;
margin-top: 20px; margin-top: 20px;
padding: 0; padding: 0;
} }
@@ -138,7 +152,7 @@
display: flex; display: flex;
gap: 20px; gap: 20px;
@media (width <=768px) { @container timeframe-slider (width <=768px) {
gap: 8px; gap: 8px;
} }
} }
@@ -147,7 +161,7 @@
width: 9px; width: 9px;
height: 14px; height: 14px;
@media (width <=768px) { @container timeframe-slider (width <=576px) {
width: 6px; width: 6px;
height: 11.5px; height: 11.5px;
} }
@@ -156,7 +170,7 @@
.dots { .dots {
display: none; display: none;
@media (width <=768px) { @container timeframe-slider (width <=576px) {
position: absolute; position: absolute;
left: 50%; left: 50%;
bottom: 32px; bottom: 32px;
@@ -214,14 +228,19 @@
pointer-events: none; pointer-events: none;
@media (width <=1024px) { @container timeframe-slider (width <=1024px) {
gap: 40px; gap: 40px;
font-size: 140px; font-size: 140px;
line-height: 120px; line-height: 120px;
} }
@media (width <=768px) { @container timeframe-slider (width <=768px) {
font-size: 100px;
line-height: 80px;
}
@container timeframe-slider (width <=576px) {
position: static; position: static;
gap: 20px; gap: 20px;
@@ -246,7 +265,7 @@
.periodLabel { .periodLabel {
display: none; display: none;
@media (width <=768px) { @container timeframe-slider (width <=576px) {
order: 1; order: 1;
display: block; display: block;
@@ -266,7 +285,7 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
@media (width <=768px) { @container timeframe-slider (width <=576px) {
display: none; display: none;
} }
} }
@@ -274,7 +293,7 @@
.carouselContainer { .carouselContainer {
padding: 55px 80px 105px; padding: 55px 80px 105px;
@media (width <=768px) { @container timeframe-slider (width <=768px) {
width: calc(100% + 40px); width: calc(100% + 40px);
margin: 0 -20px; margin: 0 -20px;
padding: 0; padding: 0;

View File

@@ -132,6 +132,7 @@ export const TimeFrameSlider = memo(() => {
}, [totalPeriods]) }, [totalPeriods])
return ( return (
<div className={styles.wrapper}>
<div className={styles.container} ref={containerRef}> <div className={styles.container} ref={containerRef}>
<h1 className={styles.title}>Исторические даты</h1> <h1 className={styles.title}>Исторические даты</h1>
@@ -202,6 +203,7 @@ export const TimeFrameSlider = memo(() => {
))} ))}
</div> </div>
</div> </div>
</div>
) )
}) })