solid-slider 1.1.0 → 1.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 +13 -3
- package/dist/index.d.ts +12 -13
- package/dist/index.js +21 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Solid Slider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://bundlephobia.com/package/solid-slider)
|
|
4
|
+
[](https://www.npmjs.com/package/solid-slider)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A carousel/slider implementation in TypeScript for SolidJS. It's built on KeenSlider 6, an open-source library agnostic touch slider with native touch/swipe behavior and great performance. It comes with no dependencies, TypeScript support, multitouch support and is compatible with all common browsers.
|
|
4
8
|
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
@@ -16,6 +20,12 @@ import "solid-slider/dist/slider.css";
|
|
|
16
20
|
import createSlider from "solid-slider";
|
|
17
21
|
```
|
|
18
22
|
|
|
23
|
+
## Implementation
|
|
24
|
+
|
|
25
|
+
Solid Slider is meant to be a lightweight and compact wrapper of KeenSlider. It exposes helpers to make working with the slider convenient. Note that the when the slider mounts it assumes all children in the el are slides. You can override this functionality by passing in a "selector" value to target the specific slides you'd like to include.
|
|
26
|
+
|
|
27
|
+
Thie library exports it's own CSS which is the basic KeenSlider implementation for convenience. If you supply options as an accessor function, the slider will reactively update the configuration so that you don't have to destroy and recreate the slider. As of KeenSlider 6 plugins are now fully supported. You may supply them as a param in createSlider. Note that plugins are not reactively updated and must be supplied on creation.
|
|
28
|
+
|
|
19
29
|
## Demo
|
|
20
30
|
|
|
21
31
|
You can find a functional demo of the slider with most features implemented here: https://codesandbox.io/s/solid-slider-j0x2g
|
|
@@ -62,7 +72,7 @@ const MyComponent = () => {
|
|
|
62
72
|
|
|
63
73
|
- 1.0.0 - Initial release
|
|
64
74
|
- 1.0.3 - Changed the exported API to be slightly more flexible.
|
|
65
|
-
- 1.1.
|
|
75
|
+
- 1.1.1 - Upgraded to KeenSlider 6 and improved general reactivity.
|
|
66
76
|
|
|
67
77
|
## Keen Options API
|
|
68
78
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,18 +10,17 @@ declare module "solid-js" {
|
|
|
10
10
|
/**
|
|
11
11
|
* Creates a slider powered by KeenSlider.
|
|
12
12
|
*
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
15
|
-
* @returns {Object}
|
|
16
|
-
* @returns {
|
|
17
|
-
* @returns {
|
|
18
|
-
* @returns {
|
|
19
|
-
* @returns {
|
|
20
|
-
* @returns {
|
|
21
|
-
* @returns {
|
|
22
|
-
* @returns {
|
|
23
|
-
* @returns {
|
|
24
|
-
* @returns {destroy} Destroy the entire slider (this is automatically handled)
|
|
13
|
+
* @param {Object} options Values to initialize the slider with
|
|
14
|
+
* @param {Array} plugins Extensions that enhance KeenSlider options
|
|
15
|
+
* @returns {[create: Function, helpers: Object]} Returns mount and helper methods
|
|
16
|
+
* @returns {Function} create Mounts the slider on provided element
|
|
17
|
+
* @returns {Function} helpers.current Current slide number
|
|
18
|
+
* @returns {Function} helpers.current Current slide number
|
|
19
|
+
* @returns {Function} helpers.next Function to trigger the next slide
|
|
20
|
+
* @returns {Function} helpers.prev Function to trigger the previous slide
|
|
21
|
+
* @returns {Function<Object>} helpers.details Provides details about the current slider
|
|
22
|
+
* @returns {Function} helpers.slider Returns the KeenSlider instance
|
|
23
|
+
* @returns {Function} helpers.destroy Manual destroy function
|
|
25
24
|
*
|
|
26
25
|
* @example
|
|
27
26
|
* ```ts
|
|
@@ -29,7 +28,7 @@ declare module "solid-js" {
|
|
|
29
28
|
* <div use:slider>...</div>
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
|
-
declare const createSlider: <O = {}, P = {}, H extends string = KeenSliderHooks>(options?: KeenSliderOptions<O, P, H> | undefined, plugins?: KeenSliderPlugin<O, P, H>[] | undefined) => [create: (el: HTMLElement) => void, helpers: {
|
|
31
|
+
declare const createSlider: <O = {}, P = {}, H extends string = KeenSliderHooks>(options?: KeenSliderOptions<O, P, H> | Accessor<KeenSliderOptions<O, P, H>> | undefined, plugins?: KeenSliderPlugin<O, P, H>[] | undefined) => [create: (el: HTMLElement) => void, helpers: {
|
|
33
32
|
current: Accessor<number>;
|
|
34
33
|
next: Accessor<void>;
|
|
35
34
|
prev: Accessor<void>;
|
package/dist/index.js
CHANGED
|
@@ -3,18 +3,17 @@ import KeenSlider from "keen-slider";
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a slider powered by KeenSlider.
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
8
|
-
* @returns {Object}
|
|
9
|
-
* @returns {
|
|
10
|
-
* @returns {
|
|
11
|
-
* @returns {
|
|
12
|
-
* @returns {
|
|
13
|
-
* @returns {
|
|
14
|
-
* @returns {
|
|
15
|
-
* @returns {
|
|
16
|
-
* @returns {
|
|
17
|
-
* @returns {destroy} Destroy the entire slider (this is automatically handled)
|
|
6
|
+
* @param {Object} options Values to initialize the slider with
|
|
7
|
+
* @param {Array} plugins Extensions that enhance KeenSlider options
|
|
8
|
+
* @returns {[create: Function, helpers: Object]} Returns mount and helper methods
|
|
9
|
+
* @returns {Function} create Mounts the slider on provided element
|
|
10
|
+
* @returns {Function} helpers.current Current slide number
|
|
11
|
+
* @returns {Function} helpers.current Current slide number
|
|
12
|
+
* @returns {Function} helpers.next Function to trigger the next slide
|
|
13
|
+
* @returns {Function} helpers.prev Function to trigger the previous slide
|
|
14
|
+
* @returns {Function<Object>} helpers.details Provides details about the current slider
|
|
15
|
+
* @returns {Function} helpers.slider Returns the KeenSlider instance
|
|
16
|
+
* @returns {Function} helpers.destroy Manual destroy function
|
|
18
17
|
*
|
|
19
18
|
* @example
|
|
20
19
|
* ```ts
|
|
@@ -30,13 +29,19 @@ const createSlider = (options, plugins) => {
|
|
|
30
29
|
const create = (el) => {
|
|
31
30
|
el.classList.add("keen-slider");
|
|
32
31
|
// @ts-ignore
|
|
33
|
-
const opts = () => ({
|
|
32
|
+
const opts = () => ({
|
|
33
|
+
selector: el.childNodes,
|
|
34
|
+
...(typeof options == 'function' ? options() : options)
|
|
35
|
+
});
|
|
34
36
|
onMount(() => {
|
|
35
37
|
slider = new KeenSlider(el, opts(), plugins);
|
|
36
|
-
slider.on(
|
|
38
|
+
slider.on("slideChanged", () => setCurrent(slider.track.details.rel));
|
|
37
39
|
});
|
|
38
40
|
onCleanup(destroy);
|
|
39
|
-
|
|
41
|
+
// Only watch the options of an accessor is provided
|
|
42
|
+
if (typeof options === 'function') {
|
|
43
|
+
createEffect(on(() => options(), () => slider && slider.update(opts())));
|
|
44
|
+
}
|
|
40
45
|
};
|
|
41
46
|
return [
|
|
42
47
|
create,
|
|
@@ -44,7 +49,7 @@ const createSlider = (options, plugins) => {
|
|
|
44
49
|
current,
|
|
45
50
|
next: () => slider && slider.next(),
|
|
46
51
|
prev: () => slider && slider.prev(),
|
|
47
|
-
details: () => slider ? slider.track.details : {},
|
|
52
|
+
details: () => (slider ? slider.track.details : {}),
|
|
48
53
|
slider: () => slider,
|
|
49
54
|
moveTo: (id, duration = 250, absolute = false, easing) => slider?.moveToIdx(id, absolute, { duration, easing: easing }),
|
|
50
55
|
destroy
|