mp-design-system 2.0.74 → 2.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1119,20 +1119,10 @@
1119
1119
  document.querySelectorAll('[data-carousel="cards"]').forEach((el) => {
1120
1120
  const type = el.dataset.carouselType || "slide";
1121
1121
  const rewind = el.dataset.carouselRewind === "true";
1122
- let perPage = parseInt(el.dataset.carouselPerPage) || 4;
1123
1122
  const perMove = parseInt(el.dataset.carouselPerMove) || 1;
1124
- const wrapper = getComputedStyle(document.documentElement).getPropertyValue("--wrapper").trim();
1125
- const wrapperWidth = parseInt(wrapper);
1126
- const gap = parseInt(getComputedStyle(el).getPropertyValue("--row-gap"));
1127
- const cardWidth = (wrapperWidth + "px" - (perPage - 1) * gap) / perPage;
1128
- el.querySelectorAll(".splide__slide").forEach((slide) => {
1129
- slide.style.width = `${cardWidth}`;
1130
- });
1131
1123
  const splide = new import_splide_min.default(el, {
1132
1124
  type,
1133
- perPage,
1134
1125
  perMove,
1135
- gap,
1136
1126
  focus: 0,
1137
1127
  arrows: false,
1138
1128
  drag: true,
@@ -1140,12 +1130,28 @@
1140
1130
  preventClick: true,
1141
1131
  rewind,
1142
1132
  clones: 0,
1143
- breakpoints: {
1144
- 768: { perPage: 3 },
1145
- 608: { perPage: 2 },
1146
- 320: { perPage: 1 }
1147
- }
1133
+ autoWidth: true
1148
1134
  });
1135
+ function setSlideWidths() {
1136
+ const wrapperWidth = parseInt(
1137
+ getComputedStyle(document.documentElement).getPropertyValue(
1138
+ "--wrapper"
1139
+ )
1140
+ );
1141
+ const gap = parseInt(getComputedStyle(el).getPropertyValue("--row-gap"));
1142
+ let cardWidth;
1143
+ if (window.innerWidth >= 1024) cardWidth = (wrapperWidth - 3 * gap) / 4;
1144
+ else if (window.innerWidth >= 768)
1145
+ cardWidth = (wrapperWidth - 2 * gap) / 3;
1146
+ else if (window.innerWidth >= 680) cardWidth = (wrapperWidth - gap) / 2;
1147
+ else cardWidth = wrapperWidth;
1148
+ el.querySelectorAll(".splide__slide").forEach((slide) => {
1149
+ slide.style.width = `${cardWidth}px`;
1150
+ });
1151
+ splide.refresh();
1152
+ }
1153
+ window.addEventListener("resize", setSlideWidths);
1154
+ setSlideWidths();
1149
1155
  el.querySelector(".c-carousel__arrow--prev")?.addEventListener(
1150
1156
  "click",
1151
1157
  () => splide.go("<")
@@ -1154,12 +1160,6 @@
1154
1160
  "click",
1155
1161
  () => splide.go(">")
1156
1162
  );
1157
- const list = el.querySelector(".splide__list");
1158
- if (list) {
1159
- const padding = `calc((100vw - var(--wrapper)) * 0.5)`;
1160
- list.style.paddingInlineStart = padding;
1161
- list.style.paddingInlineEnd = padding;
1162
- }
1163
1163
  el.querySelectorAll("a").forEach((link) => {
1164
1164
  link.addEventListener("click", (e) => e.stopPropagation());
1165
1165
  });