Breakpoints feature

Created on 18 April 2024, 2 months ago
Updated 28 April 2024, 2 months ago

The new 2.0.x version is pushed and ready for testing (also 2.0.1-beta4 release) on this feature that was requested through several issues here. Please take a look into attached screenshots, the idea was to reference other Swiper templates (via entity_reference field) that would serve as a breakpoint templates. Rather than adding more options directly into a main template/config form, which can make the whole UI more messy, but also would require more work in perspective, in case there are new properties (options) to be added to a breakpoint template as breakpoints properties.

Note also that when you check the template to be a breakpoint template (checkbox) many unsupported properties/fields on the form will be invisible and disabled, for three reasons:

  1. Swiper template flagged as a breakpoint won't be visible where it's not applicable, on various formatters settings, as it is always meant to be bind to a parent/main template.
  2. Make Swiper template form more condensed, UX wise, in case of breakpoint kind of template
  3. Secure that no unsupported option ends into breakpoint property object in JS. Swiper is very "delicate" on this things.

For the moment the following breakpoint properties are included:

  • breakpointsBase
  • slidesPerView
  • spaceBetween
  • slidesPerGroup
  • navigation
  • pagination (with clickable and dynamicBullets flags)

It should be possible to use breakpoints defined in pixels but also as "ratio breakpoints" with values like @0.75 etc. See here.

Because of the new properties, as well as some other properties (unrelated to breakpoints) added and coming in this version, make sure to run DB update script
drush updb

I am attaching 3 templates seen on screenshots, as an example of the setup with main template and two breakpoints (480 and 960). These will be added to a new installations but can be also imported (for existing installations) through Config sync UI in Drupal or via drush:
drush cim --partial --source="modules/contrib/swiper_formatter/config/install/optional"

In favor of this feature there are a couple of related Swiper's options added as well, such as Breakpoint base, Update on window resize, Use ResizeObserver, Space between slides and Number of slides per group. As usual - careful with combinations :)

There is also a new method in JS, Swiper's _beforeBreakpoint event listener for a proper handling of (browser) window resize action in case of pagination with different properties in main and breakpoint templates. In fact, this method is made only to slightly improve and be useful for developers, because without it pagination breakpoint specifics are actually also working on defined viewports/devices or on page reload in browser.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands nk_

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024