astro-swiper 2.1.1 → 2.2.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 +49 -61
- package/package.json +11 -6
- package/src/components/Swiper.astro +5 -5
- package/src/components/SwiperButtonNext.astro +2 -2
- package/src/components/SwiperButtonPrev.astro +2 -2
- package/src/components/SwiperPagination.astro +2 -2
- package/src/components/SwiperScrollbar.astro +2 -2
- package/src/components/SwiperSlide.astro +1 -1
- package/src/components/SwiperWrapper.astro +2 -2
- package/src/index.ts +23 -21
package/README.md
CHANGED
|
@@ -1,66 +1,46 @@
|
|
|
1
|
-
<div align="center" style="background-color:
|
|
2
|
-
<a href="https://swiperjs.com" target="_blank"><img width="70" src="images/swiper-logo.svg"></a>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
<div align="center" style="background-color: dark-grey; padding: 1rem;">
|
|
2
|
+
<a href="https://swiperjs.com" target="_blank"><img width="70" width="auto" src="images/swiper-logo.svg"></a>
|
|
3
|
+
<a href="https://astro.build/" target="_blank"><img height="68" width="auto" src="images/astro-logo.svg"></a>
|
|
4
|
+
|
|
6
5
|
# Astro Swiper
|
|
7
6
|
|
|
7
|
+
> Astro Swiper - native component for [Swiper](https://github.com/nolimits4web/swiper).
|
|
8
|
+
> Use for slides, carousel, photo swiper.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
<a href="https://github.com/nolimits4web/swiper">Swiper</a>,
|
|
11
|
-
dedicated to slides / carousel / photo swiper.
|
|
12
|
-
|
|
13
|
-
# [Demo](https://pascal-brand38.github.io/astro-dev/packages/astro-swiper)
|
|
10
|
+
<img src="images/astro-swiper.gif" />
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
<img src="images/astro-swiper.gif">
|
|
17
|
-
</a>
|
|
12
|
+
## [Check demo](https://pascal-brand38.github.io/astro-dev/packages/astro-swiper)
|
|
18
13
|
|
|
19
14
|
</div>
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
<br>
|
|
23
|
-
|
|
24
|
-
# Help needed
|
|
16
|
+
## Installation
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
in ```astro-swiper``` github
|
|
31
|
-
|
|
32
|
-
I'll be happy to help!
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<br>
|
|
36
|
-
|
|
37
|
-
# Installation
|
|
38
|
-
Get the latest version from NPM:
|
|
39
|
-
```
|
|
40
|
-
$ npm install astro-swiper
|
|
18
|
+
```bash
|
|
19
|
+
npm install astro-swiper
|
|
20
|
+
pnpm add astro-swiper
|
|
21
|
+
bun install astro-swiper
|
|
41
22
|
```
|
|
42
23
|
|
|
43
|
-
|
|
24
|
+
## Usage
|
|
44
25
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Here is the astro code of a loop carousel, of 3 pictures, with 1 second interval:
|
|
26
|
+
Carousel with loop, 3 pictures, 1 second interval:
|
|
48
27
|
|
|
49
28
|
```jsx
|
|
50
29
|
---
|
|
51
30
|
import { Swiper, SwiperWrapper, SwiperSlide } from "astro-swiper";
|
|
52
31
|
---
|
|
32
|
+
|
|
53
33
|
<Swiper
|
|
54
|
-
|
|
34
|
+
// check options at https://swiperjs.com/swiper-api
|
|
35
|
+
options={{
|
|
36
|
+
loop: true,
|
|
55
37
|
autoplay: {
|
|
56
38
|
delay: 700,
|
|
57
39
|
disableOnInteraction: false,
|
|
58
|
-
waitForTransition: false
|
|
59
|
-
}
|
|
60
|
-
loop: true,
|
|
40
|
+
waitForTransition: false
|
|
41
|
+
}
|
|
61
42
|
}}>
|
|
62
43
|
<SwiperWrapper>
|
|
63
|
-
<!-- Slides -->
|
|
64
44
|
<SwiperSlide>
|
|
65
45
|
<img src="https://picsum.photos/455/256?nb=1" alt="" />
|
|
66
46
|
</SwiperSlide>
|
|
@@ -85,42 +65,50 @@ import { Swiper, SwiperWrapper, SwiperSlide } from "astro-swiper";
|
|
|
85
65
|
</style>
|
|
86
66
|
```
|
|
87
67
|
|
|
88
|
-
##
|
|
68
|
+
## Examples
|
|
89
69
|
|
|
90
|
-
|
|
70
|
+
Check the [online doc](https://pascal-brand38.github.io/astro-dev/packages/astro-swiper) for a fullset of examples, including navigation and thumbnails. Full code is provided.
|
|
91
71
|
|
|
92
|
-
|
|
72
|
+
You can also look at how others are using `astro-swiper` in public github repo:
|
|
93
73
|
|
|
94
|
-
|
|
95
|
-
* the famous astro template [astroplate](https://github.com/zeon-studio/astroplate) in the
|
|
74
|
+
- the famous astro template [astroplate](https://github.com/zeon-studio/astroplate) in the
|
|
96
75
|
[testominial section](https://zeon.studio/preview?project=astroplate)
|
|
97
|
-
(cf.
|
|
76
|
+
(cf. **_What Users Are Saying About Astroplate_**):
|
|
98
77
|
autoplay, pagination and breakpoints are used
|
|
99
|
-
|
|
100
|
-
is using
|
|
78
|
+
- the popular astro template [pinwheel-astro](https://github.com/themefisher/pinwheel-astro)
|
|
79
|
+
is using `astro-swiper` in several places:
|
|
101
80
|
[testimonial section](https://pinwheel-astro.vercel.app/),
|
|
102
81
|
[signin](https://pinwheel-astro.vercel.app/signin),
|
|
103
82
|
[password reset](https://pinwheel-astro.vercel.app/password-reset) and
|
|
104
83
|
[signup](https://pinwheel-astro.vercel.app/signup) pages. Pagination and
|
|
105
84
|
breakpoints are used.
|
|
106
|
-
|
|
85
|
+
- the well-known astro template [hello-astro](https://github.com/hellotham/hello-astro)
|
|
107
86
|
uses swiper in the [carousel page](https://hellotham.github.io/hello-astro/carousel/)
|
|
108
87
|
as well as in [blog article](https://hellotham.github.io/hello-astro/blog/2022-08-19-sample-carousel/).
|
|
109
88
|
It makes use of navigation arrow, pagination and autoplay.
|
|
110
|
-
|
|
111
|
-
also using
|
|
89
|
+
- [bigspring-light-astro](https://github.com/themefisher/bigspring-light-astro) astro theme is
|
|
90
|
+
also using `astro-swiper` in several places in the
|
|
112
91
|
[main page](https://tf-bigspring-light-astro.vercel.app/) with customized pagination.
|
|
113
|
-
|
|
92
|
+
- [Women Techmakers organized by GDG Madrid](https://github.com/wtmgdgmadrid/wtmgdgmadrid.github.io)
|
|
114
93
|
is using pagination and autoplay at different places in their
|
|
115
94
|
[page](http://wtmgdgmadrid.github.io/)
|
|
116
|
-
|
|
95
|
+
- [kando-menu](https://github.com/make-42/kando-menu.github.io) is using `astro-swiper`
|
|
117
96
|
with pagination, card effect, and coverflow effect as displayed in [kando.menu](https://kando.menu/)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
[Cinerama](https://github.com/RaiderMr3003/Cinerama) and
|
|
121
|
-
[pfm-landing-page](https://github.com/RichardAgain/pfm-landing-page)
|
|
122
|
-
using
|
|
97
|
+
- [astroimagej](https://github.com/AstroImageJ/astroimagej) is using pagination with progress bar
|
|
98
|
+
- ... and many others such as
|
|
99
|
+
[Cinerama](https://github.com/RaiderMr3003/Cinerama) and
|
|
100
|
+
[pfm-landing-page](https://github.com/RichardAgain/pfm-landing-page)
|
|
101
|
+
using `astro-swiper` in the hero section
|
|
102
|
+
|
|
103
|
+
## Help needed?
|
|
104
|
+
|
|
105
|
+
**Do you need help to integrate `astro-swiper` in your astro template / component?**
|
|
106
|
+
I'll be happy to help!
|
|
107
|
+
|
|
108
|
+
- mention me with `@pascal-brand38` in an issue on your own github repo
|
|
109
|
+
- or [fill a GitHub issue](https://github.com/pascal-brand38/astro-swiper/issues/new?template=help-needed.md)
|
|
110
|
+
in `astro-swiper` github
|
|
123
111
|
|
|
124
|
-
|
|
112
|
+
### Support us
|
|
125
113
|
|
|
126
|
-
|
|
114
|
+
**Let's star the project as you like it.**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-swiper",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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": {
|
|
@@ -23,13 +23,18 @@
|
|
|
23
23
|
"index.ts",
|
|
24
24
|
"src/**"
|
|
25
25
|
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"pnpm": ">=10.30.3",
|
|
28
|
+
"node": ">=22"
|
|
29
|
+
},
|
|
30
|
+
"packageManager": "pnpm@10.30.3",
|
|
26
31
|
"devDependencies": {
|
|
27
|
-
"@biomejs/biome": "^2.
|
|
28
|
-
"@types/node": "^24.
|
|
29
|
-
"astro": "^5.
|
|
32
|
+
"@biomejs/biome": "^2.4.4",
|
|
33
|
+
"@types/node": "^24.11.0",
|
|
34
|
+
"astro": "^5.18.0",
|
|
30
35
|
"prettier": "^3.8.1",
|
|
31
36
|
"prettier-plugin-astro": "^0.14.1",
|
|
32
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.9.3"
|
|
33
38
|
},
|
|
34
39
|
"keywords": [
|
|
35
40
|
"swiper",
|
|
@@ -47,6 +52,6 @@
|
|
|
47
52
|
"thumbnail"
|
|
48
53
|
],
|
|
49
54
|
"dependencies": {
|
|
50
|
-
"swiper": "^12.
|
|
55
|
+
"swiper": "^12.1.2"
|
|
51
56
|
}
|
|
52
57
|
}
|
|
@@ -18,20 +18,19 @@ const {
|
|
|
18
18
|
} = Astro.props;
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
<!-- Slider main container -->
|
|
22
|
-
{
|
|
21
|
+
<!-- Slider main container -->{
|
|
23
22
|
useCustomElement ? (
|
|
24
23
|
<astro-swiper
|
|
25
24
|
data-options={JSON.stringify(options)}
|
|
26
25
|
data-linktothumbuniqueclass={linkToThumbUniqueClass}
|
|
27
26
|
data-uniqueclass={uniqueClass}
|
|
28
|
-
class:list={[addDefaultClass ? 'swiper' :
|
|
27
|
+
class:list={[addDefaultClass ? 'swiper' : null, uniqueClass, className]}
|
|
29
28
|
{...props}
|
|
30
29
|
>
|
|
31
30
|
<slot />
|
|
32
31
|
</astro-swiper>
|
|
33
32
|
) : (
|
|
34
|
-
<div class:list={[addDefaultClass ? 'swiper' :
|
|
33
|
+
<div class:list={[addDefaultClass ? 'swiper' : null, uniqueClass, className]} {...props}>
|
|
35
34
|
<astro-swiper
|
|
36
35
|
data-options={JSON.stringify(options)}
|
|
37
36
|
data-linktothumbuniqueclass={linkToThumbUniqueClass}
|
|
@@ -69,7 +68,8 @@ const {
|
|
|
69
68
|
|
|
70
69
|
// Read the message from the data attribute.
|
|
71
70
|
const options = JSON.parse(this.dataset.options || '{}');
|
|
72
|
-
|
|
71
|
+
// to have more than 1 swiper in a single page
|
|
72
|
+
const uniqueClass = this.dataset.uniqueclass || '';
|
|
73
73
|
const linkToThumbUniqueClass = this.dataset.linktothumbuniqueclass || '';
|
|
74
74
|
|
|
75
75
|
if (linkToThumbUniqueClass === '') {
|
|
@@ -11,9 +11,9 @@ interface Props extends HTMLAttributes<'div'> {
|
|
|
11
11
|
addDefaultClass?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const { class: className =
|
|
14
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
<div class:list={[addDefaultClass ? 'swiper-button-next' :
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-button-next' : null, className]} {...props}>
|
|
18
18
|
<slot />
|
|
19
19
|
</div>
|
|
@@ -11,9 +11,9 @@ interface Props extends HTMLAttributes<'div'> {
|
|
|
11
11
|
addDefaultClass?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const { class: className =
|
|
14
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
<div class:list={[addDefaultClass ? 'swiper-button-prev' :
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-button-prev' : null, className]} {...props}>
|
|
18
18
|
<slot />
|
|
19
19
|
</div>
|
|
@@ -11,9 +11,9 @@ interface Props extends HTMLAttributes<'div'> {
|
|
|
11
11
|
addDefaultClass?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const { class: className =
|
|
14
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
<div class:list={[addDefaultClass ? 'swiper-pagination' :
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-pagination' : null, className]} {...props}>
|
|
18
18
|
<slot />
|
|
19
19
|
</div>
|
|
@@ -11,9 +11,9 @@ interface Props extends HTMLAttributes<'div'> {
|
|
|
11
11
|
addDefaultClass?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const { class: className =
|
|
14
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
<div class:list={[addDefaultClass ? 'swiper-scrollbar' :
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-scrollbar' : null, className]} {...props}>
|
|
18
18
|
<slot />
|
|
19
19
|
</div>
|
|
@@ -10,7 +10,7 @@ interface Props extends HTMLAttributes<'div'> {
|
|
|
10
10
|
addDefaultClass?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const { class: className =
|
|
13
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
<div class:list={[addDefaultClass ? 'swiper-slide' : null, className]} {...props}>
|
|
@@ -11,9 +11,9 @@ interface Props extends HTMLAttributes<'div'> {
|
|
|
11
11
|
addDefaultClass?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const { class: className =
|
|
14
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
<div class:list={[addDefaultClass ? 'swiper-wrapper' :
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-wrapper' : null, className]} {...props}>
|
|
18
18
|
<slot />
|
|
19
19
|
</div>
|
package/src/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface AstroSwiperType extends HTMLAttributes<'div'> {
|
|
|
39
39
|
useCustomElement?: boolean;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
42
|
+
/** Astro components exports, used to create a swiper */
|
|
43
43
|
export { default as Swiper } from './components/Swiper.astro';
|
|
44
44
|
export { default as SwiperButtonNext } from './components/SwiperButtonNext.astro';
|
|
45
45
|
export { default as SwiperButtonPrev } from './components/SwiperButtonPrev.astro';
|
|
@@ -48,44 +48,46 @@ export { default as SwiperScrollbar } from './components/SwiperScrollbar.astro';
|
|
|
48
48
|
export { default as SwiperSlide } from './components/SwiperSlide.astro';
|
|
49
49
|
export { default as SwiperWrapper } from './components/SwiperWrapper.astro';
|
|
50
50
|
|
|
51
|
+
/** pointer to the swiper structure that was created using "new", even when not initialized */
|
|
51
52
|
declare class AstroSwiper extends HTMLElement {
|
|
52
|
-
/** pointer to the swiper structure that was created using "new",
|
|
53
|
-
* even when not initialized */
|
|
54
53
|
astroSwiper: Swiper | undefined;
|
|
55
54
|
}
|
|
56
55
|
|
|
56
|
+
// !TODO Deprecate fully in next major version
|
|
57
57
|
/** @deprecated: use getSwiperFromUniqueSelector() instead */
|
|
58
58
|
export function getSwiperFromUniqueClass(uniqueClass: string): Swiper | undefined {
|
|
59
59
|
return getSwiperFromUniqueSelector(`.${uniqueClass}`);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/** Retrieve the swiper instance from the unique selector provided
|
|
63
|
-
* when creating the swiper
|
|
62
|
+
/** Retrieve the swiper instance from the unique selector provided when creating the swiper
|
|
64
63
|
* @param uniqueSelector the unique selector provided when creating the swiper,
|
|
65
64
|
* @example const swiper = getSwiperFromUniqueSelector('.my-unique-class')
|
|
66
65
|
* const swiper = getSwiperFromUniqueSelector('#my-unique-id')
|
|
67
66
|
*/
|
|
68
67
|
export function getSwiperFromUniqueSelector(uniqueSelector: string): Swiper | undefined {
|
|
69
|
-
|
|
70
|
-
|
|
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;
|
|
68
|
+
if (!/^[.#]/.test(uniqueSelector)) {
|
|
69
|
+
console.warn("Used selector doesn't contain class or ID selector sign");
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!
|
|
82
|
-
console.warn(`astro-swiper: no element found with
|
|
72
|
+
const element = document.querySelector(uniqueSelector);
|
|
73
|
+
|
|
74
|
+
if (!element) {
|
|
75
|
+
console.warn(`astro-swiper: no element found with selector "${uniqueSelector}"`);
|
|
83
76
|
return undefined;
|
|
84
77
|
}
|
|
85
|
-
if (swiperEl.astroSwiper) {
|
|
86
|
-
return swiperEl.astroSwiper;
|
|
87
|
-
}
|
|
88
78
|
|
|
89
|
-
|
|
79
|
+
// Check if element is the customElement with astroSwiper property
|
|
80
|
+
const customElement = element as AstroSwiper;
|
|
81
|
+
if (customElement.astroSwiper) return customElement.astroSwiper;
|
|
82
|
+
|
|
83
|
+
// Check if element is a <div/> wrapper with customElement child
|
|
84
|
+
const childElement = element.firstElementChild as AstroSwiper;
|
|
85
|
+
if (childElement?.astroSwiper) return childElement.astroSwiper;
|
|
86
|
+
|
|
87
|
+
console.warn(
|
|
88
|
+
`astro-swiper: element found with selector "${uniqueSelector}" but no swiper instance found. ` +
|
|
89
|
+
`Expected either a custom element with astroSwiper property or a <div/> containing such an element.`,
|
|
90
|
+
);
|
|
91
|
+
|
|
90
92
|
return undefined;
|
|
91
93
|
}
|