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 CHANGED
@@ -1,6 +1,10 @@
1
- # <img width="27px" src="https://github.com/solidjs/solid-site/raw/master/src/assets/logo.png" alt="Solid logo"> &nbsp;Solid Slider
1
+ # Solid Slider
2
2
 
3
- A carousel/slider implementation in TypeScript for Solid using KeenSlider. keen-slider is a free 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.
3
+ [![size](https://img.shields.io/bundlephobia/minzip/solid-slider?style=for-the-badge)](https://bundlephobia.com/package/solid-slider)
4
+ [![size](https://img.shields.io/npm/v/solid-slider?style=for-the-badge)](https://www.npmjs.com/package/solid-slider)
5
+ ![npm](https://img.shields.io/npm/dw/solid-slider?style=for-the-badge)
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.0 - Upgraded to KeenSlider 6 and improved general reactivity.
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 {options} Options to initialize the slider with
14
- * @param {plugins} Plugins that enhance KeenSlider options
15
- * @returns {Object} An object of useful helpers
16
- * @returns {create} Register and creation function to call on setup
17
- * @returns {current} Current slide number
18
- * @returns {next} Function to trigger the next slide
19
- * @returns {prev} Function to trigger the previous slide
20
- * @returns {moveTo} Allow you to change the slider to a specific slide
21
- * @returns {refresh} Refresh trigger
22
- * @returns {details} Retrieve a list of SliderDetails
23
- * @returns {slider} Gain access to the slider itself
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 {options} Options to initialize the slider with
7
- * @param {plugins} Plugins that enhance KeenSlider options
8
- * @returns {Object} An object of useful helpers
9
- * @returns {create} Register and creation function to call on setup
10
- * @returns {current} Current slide number
11
- * @returns {next} Function to trigger the next slide
12
- * @returns {prev} Function to trigger the previous slide
13
- * @returns {moveTo} Allow you to change the slider to a specific slide
14
- * @returns {refresh} Refresh trigger
15
- * @returns {details} Retrieve a list of SliderDetails
16
- * @returns {slider} Gain access to the slider itself
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 = () => ({ selector: el.childNodes, ...options });
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('slideChanged', () => setCurrent(slider.track.details.rel));
38
+ slider.on("slideChanged", () => setCurrent(slider.track.details.rel));
37
39
  });
38
40
  onCleanup(destroy);
39
- createEffect(on(() => options, () => slider && slider.update(opts())));
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-slider",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A slider/carousel component for Solid powered by KeenSlider.",
5
5
  "author": "David Di Biase",
6
6
  "license": "ISC",