astro-swiper 2.0.0 → 2.1.1

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
@@ -91,6 +91,35 @@ Please check the [online doc](https://pascal-brand38.github.io/astro-dev/package
91
91
 
92
92
  Full code is provided.
93
93
 
94
+ You can also look at how others are using ```astro-swiper``` in public github repo:
95
+ * the famous astro template [astroplate](https://github.com/zeon-studio/astroplate) in the
96
+ [testominial section](https://zeon.studio/preview?project=astroplate)
97
+ (cf. ***What Users Are Saying About Astroplate***):
98
+ autoplay, pagination and breakpoints are used
99
+ * the popular astro template [pinwheel-astro](https://github.com/themefisher/pinwheel-astro)
100
+ is using ```astro-swiper``` in several places:
101
+ [testimonial section](https://pinwheel-astro.vercel.app/),
102
+ [signin](https://pinwheel-astro.vercel.app/signin),
103
+ [password reset](https://pinwheel-astro.vercel.app/password-reset) and
104
+ [signup](https://pinwheel-astro.vercel.app/signup) pages. Pagination and
105
+ breakpoints are used.
106
+ * the well-known astro template [hello-astro](https://github.com/hellotham/hello-astro)
107
+ uses swiper in the [carousel page](https://hellotham.github.io/hello-astro/carousel/)
108
+ as well as in [blog article](https://hellotham.github.io/hello-astro/blog/2022-08-19-sample-carousel/).
109
+ It makes use of navigation arrow, pagination and autoplay.
110
+ * [bigspring-light-astro](https://github.com/themefisher/bigspring-light-astro) astro theme is
111
+ also using ```astro-swiper``` in several places in the
112
+ [main page](https://tf-bigspring-light-astro.vercel.app/) with customized pagination.
113
+ * [Women Techmakers organized by GDG Madrid](https://github.com/wtmgdgmadrid/wtmgdgmadrid.github.io)
114
+ is using pagination and autoplay at different places in their
115
+ [page](http://wtmgdgmadrid.github.io/)
116
+ * [kando-menu](https://github.com/make-42/kando-menu.github.io) is using ```astro-swiper```
117
+ with pagination, card effect, and coverflow effect as displayed in [kando.menu](https://kando.menu/)
118
+ * [astroimagej](https://github.com/AstroImageJ/astroimagej) is using pagination with progress bar
119
+ * ... and many others such as
120
+ [Cinerama](https://github.com/RaiderMr3003/Cinerama) and
121
+ [pfm-landing-page](https://github.com/RichardAgain/pfm-landing-page)
122
+ using ```astro-swiper``` in the hero section
94
123
 
95
124
  # Support astro-swiper
96
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-swiper",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Astro component for swiper, dedicated to slider / carousel / photo swiper / slide, including thumbnails",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "bugs": {
18
18
  "url": "https://github.com/pascal-brand38/astro-swiper/issues"
19
19
  },
20
- "homepage": "https://pascal-brand38.github.io/astro-dev/packages/astro-swiper/",
20
+ "homepage": "https://github.com/pascal-brand38/astro-swiper",
21
21
  "exports": "./index.ts",
22
22
  "files": [
23
23
  "index.ts",
@@ -13,19 +13,34 @@ const {
13
13
  class: className = null,
14
14
  linkToThumbUniqueClass = null,
15
15
  addDefaultClass = true,
16
+ useCustomElement = true,
16
17
  ...props
17
18
  } = Astro.props;
18
19
  ---
19
20
 
20
21
  <!-- Slider main container -->
21
- <div class:list={[addDefaultClass ? 'swiper' : '', uniqueClass, className]} {...props} >
22
- <astro-swiper
23
- data-options={JSON.stringify(options)}
24
- data-linktothumbuniqueclass={linkToThumbUniqueClass}
25
- data-uniqueclass={uniqueClass}
26
- />
27
- <slot />
28
- </div>
22
+ {
23
+ useCustomElement ? (
24
+ <astro-swiper
25
+ data-options={JSON.stringify(options)}
26
+ data-linktothumbuniqueclass={linkToThumbUniqueClass}
27
+ data-uniqueclass={uniqueClass}
28
+ class:list={[addDefaultClass ? 'swiper' : '', uniqueClass, className]}
29
+ {...props}
30
+ >
31
+ <slot />
32
+ </astro-swiper>
33
+ ) : (
34
+ <div class:list={[addDefaultClass ? 'swiper' : '', uniqueClass, className]} {...props} >
35
+ <astro-swiper
36
+ data-options={JSON.stringify(options)}
37
+ data-linktothumbuniqueclass={linkToThumbUniqueClass}
38
+ data-uniqueclass={uniqueClass}
39
+ />
40
+ <slot />
41
+ </div>
42
+ )
43
+ }
29
44
 
30
45
  <script>
31
46
  import Swiper from 'swiper/bundle';
package/src/index.ts CHANGED
@@ -28,6 +28,15 @@ export interface AstroSwiperType extends HTMLAttributes<'div'> {
28
28
 
29
29
  /** add the default swiper class, true by default */
30
30
  addDefaultClass?: boolean;
31
+
32
+ /** useCustomElement, if true, the component will be rendered as a custom element, otherwise as a div.
33
+ * This option is true by default to keep legacy.
34
+ * It is there to be as close as possible to the original swiper structure, that is a div with class "swiper"
35
+ * and not a custom element.
36
+ * It is also to avoid issues with some swiper modules that are looking for the "swiper" class on the parent
37
+ * element, and not on the custom element.
38
+ */
39
+ useCustomElement?: boolean;
31
40
  }
32
41
 
33
42
  /** astro components exported, used to create a swiper */
@@ -57,5 +66,26 @@ export function getSwiperFromUniqueClass(uniqueClass: string): Swiper | undefine
57
66
  * const swiper = getSwiperFromUniqueSelector('#my-unique-id')
58
67
  */
59
68
  export function getSwiperFromUniqueSelector(uniqueSelector: string): Swiper | undefined {
60
- return (document.querySelector(uniqueSelector)?.firstElementChild as AstroSwiper)?.astroSwiper;
69
+ let swiperEl: AstroSwiper = document.querySelector(uniqueSelector) as AstroSwiper;
70
+ if (!swiperEl) {
71
+ console.warn(`astro-swiper: no element found with unique selector "${uniqueSelector}"`);
72
+ return undefined;
73
+ }
74
+ if (swiperEl.astroSwiper) {
75
+ // this is the custom element that contains the swiper instance, return it
76
+ return swiperEl.astroSwiper;
77
+ }
78
+
79
+ // this a div, with 1st child being the custom element that contains the swiper instance
80
+ swiperEl = swiperEl.firstElementChild as AstroSwiper;
81
+ if (!swiperEl) {
82
+ console.warn(`astro-swiper: no element found with unique selector "${uniqueSelector}"`);
83
+ return undefined;
84
+ }
85
+ if (swiperEl.astroSwiper) {
86
+ return swiperEl.astroSwiper;
87
+ }
88
+
89
+ console.warn(`astro-swiper: no element found with unique selector "${uniqueSelector}"`);
90
+ return undefined;
61
91
  }