astro-swiper 2.5.1 → 2.5.2

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.
package/README.md CHANGED
@@ -31,9 +31,8 @@ import { Swiper, SwiperWrapper, SwiperSlide } from "astro-swiper";
31
31
  ---
32
32
 
33
33
  <Swiper
34
- // check options at https://swiperjs.com/swiper-api
35
34
  options={{
36
- loop: true,
35
+ loop: true, // check options at https://swiperjs.com/swiper-api
37
36
  autoplay: {
38
37
  delay: 700,
39
38
  disableOnInteraction: false,
@@ -104,6 +103,96 @@ You can also look at how others are using `astro-swiper` in public github repo:
104
103
  [folex-lite-astro](https://github.com/getastrothemes/folex-lite-astro)
105
104
  using it in the portfolio page,...
106
105
 
106
+ ## API
107
+
108
+ ### `<Swiper/>`
109
+ Main Swiper element. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
110
+ | Name | Type | Default | Description |
111
+ | ---- | -----|-------- | -----------|
112
+ | options | SwiperOptions | Swiperjs default | cf. [Swiperjs doc](https://swiperjs.com/swiper-api#parameters) |
113
+ | options.astro | Cf. below description | undefined | astro specific options |
114
+ | addDefaultClass | Boolean | true | Add class `.swiper` when true |
115
+
116
+ `options.astro` is as follows:
117
+ | Name | Type | Default | Description |
118
+ | ---- | -----|-------- | -----------|
119
+ | useCustomElement | boolean | true | when false, use a `<div>` to be as close as possible to swiperjs default. Use a custom element `<astro-swiper>` otherwise. |
120
+ | thumbSwiperUniqueSelector | string starting with `#` or `.` | undefined | unique selector of the thumbnail swiper to link with, when using the thumbs module. When a thumbnail swiper is build, this parameter is provided on the main slider (the one with big slides, not the one to track the progress) and equal the unique selector of the thumbnail swiper (the one to track the progress). It is used to link the main swiper with the thumbnail swiper when using the thumbs module. |
121
+ | intersectionObserver.initSwiper | boolean | false | true to initialize the swiper when the element appears in the screen |
122
+ | intersectionObserver.disconnectOnInit | boolean | false | true to disconnect the observer once the swiper is initialized |
123
+ | intersectionObserver.controlAutoplay | boolean | false | true to start and stop the autoplay when the swiper appears and disappears from the screen, respectively |
124
+ | intersectionObserver.options | IntersectionObserverInit | undefined | cf. [mdn docs](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) |
125
+
126
+ ### `<SwiperWrapper/>`
127
+ Wrapper of all slides. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
128
+ | Name | Type | Default | Description |
129
+ | ---- | -----|-------- | -----------|
130
+ | addDefaultClass | Boolean | true | Add class `.swiper-wrapper` when true |
131
+
132
+ ### `<SwiperSlide/>`
133
+ A single slide. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
134
+ | Name | Type | Default | Description |
135
+ | ---- | -----|-------- | -----------|
136
+ | addDefaultClass | Boolean | true | Add class `.swiper-slide` when true |
137
+
138
+ ### `<SwiperPagination/>`
139
+ Pagination dots. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
140
+ | Name | Type | Default | Description |
141
+ | ---- | -----|-------- | -----------|
142
+ | addDefaultClass | Boolean | true | Add class `.swiper-pagination` when true |
143
+
144
+ ### `<SwiperButtonPrev/>` and `<SwiperButtonNext/>`
145
+ Navigation arrows. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
146
+ | Name | Type | Default | Description |
147
+ | ---- | -----|-------- | -----------|
148
+ | addDefaultClass | Boolean | true | Add class `.swiper-button-prev` or `swiper-button-next` when true |
149
+
150
+ ### `<SwiperScrollbar/>`
151
+ Scrollbar. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
152
+ | Name | Type | Default | Description |
153
+ | ---- | -----|-------- | -----------|
154
+ | addDefaultClass | Boolean | true | Add class `.swiper-scrollbar` when true |
155
+
156
+ ### `<SwiperLazyPreloader/>`
157
+ Slide lazy loader. To be used inside a `<SwiperSlide/>`. Inherits all `HTMLAttributes<'div'>` (class...) attributes.
158
+ | Name | Type | Default | Description |
159
+ | ---- | -----|-------- | -----------|
160
+ | addDefaultClass | Boolean | true | Add class `.swiper-lazy-preloader` when true |
161
+
162
+ ### `getSwiperFromUniqueSelector()`
163
+ Function to be used in script part, to be able to retrieve the swiper instance given
164
+ a unique selector (starting with a `.` or a `#`), once the `load` event is fired.
165
+ This allows to use functions and events in swiper.
166
+
167
+ Here is a snipset of the
168
+ [Custom Pagination Demo](https://github.com/pascal-brand38/astro-dev/blob/main/src/content/docs/packages/astro-swiper/DemoPaginationCustom.astro):
169
+
170
+ ```jsx
171
+ <Swiper
172
+ class="swiper-demo-pagination-custom"
173
+ options={{
174
+ ...
175
+ init: false, // init in the script part
176
+ }}
177
+ >
178
+ ...
179
+ <SwiperPagination />
180
+ </Swiper>
181
+
182
+ <script>
183
+ import type { PaginationOptions } from 'swiper/types';
184
+ import { getSwiperFromUniqueSelector } from 'astro-swiper'
185
+ window.addEventListener('load', () => {
186
+ const swiper = getSwiperFromUniqueSelector('.swiper-demo-pagination-custom');
187
+ (swiper!.params.pagination as PaginationOptions)!.renderBullet = function (index: number, className: string) {
188
+ return '<span class="' + className + '">' + (index + 1) + "</span>";
189
+ }
190
+ swiper!.init()
191
+ })
192
+ </script>
193
+ ```
194
+
195
+
107
196
  ## Help needed?
108
197
 
109
198
  **Do you need help to integrate `astro-swiper` in your astro template / component?**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-swiper",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "Astro component for swiper, dedicated to slider / carousel / photo swiper / slide, including thumbnails",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/index.ts CHANGED
@@ -96,6 +96,7 @@ export function getSwiperFromUniqueClass(uniqueClass: string): Swiper | undefine
96
96
 
97
97
  /** Retrieve the swiper instance from the unique selector provided when creating the swiper
98
98
  * @param uniqueSelector the unique selector provided when creating the swiper,
99
+ * @param options mayBeUndefined set to true to avoid warning when the swiper is not initialized yet, but will be in the future (for example when using thumbnails, the main swiper is created before the thumbnail swiper, so it is normal that it is not found at this moment)
99
100
  * @example const swiper = getSwiperFromUniqueSelector('.my-unique-class')
100
101
  * const swiper = getSwiperFromUniqueSelector('#my-unique-id')
101
102
  */