solid-slider 1.1.1 → 1.2.5

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
@@ -20,15 +20,31 @@ import "solid-slider/dist/slider.css";
20
20
  import createSlider from "solid-slider";
21
21
  ```
22
22
 
23
- ## Implementation
23
+ ## Demo
24
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.
25
+ You can find a functional demo of the slider with most features implemented here: https://codesandbox.io/s/solid-slider-j0x2g
26
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.
27
+ ## Plugins
28
28
 
29
- ## Demo
29
+ Plugins may be added directly via the createSlider primitive. You may add a KeenSlider plugin directly or built-in plugins shipped with this package. Currently an autoplay plugin is available that will assist with autoplaying actions in the slider. Simply add the plugins after the options parameter.
30
30
 
31
- You can find a functional demo of the slider with most features implemented here: https://codesandbox.io/s/solid-slider-j0x2g
31
+ ### Autoplay
32
+
33
+ The autoplay function extends the slider with pausable playing. You can even supply a signal to control toggling autoplay. [Click here](https://codesandbox.io/s/solid-slider-autoplay-plugin-h2wphk?file=/src/index.tsx) for a demo of autoplay.
34
+
35
+ ```ts
36
+ import createSlider from "solid-slider";
37
+ import autoplay from "solid-slider/plugins/autoplay";
38
+
39
+ const [pause, togglePause] = createSignal(false);
40
+ const [slider] = createSlider(
41
+ { loop: true },
42
+ autoplay(2000, {
43
+ pause,
44
+ pauseOnDrag: true
45
+ })
46
+ );
47
+ ```
32
48
 
33
49
  ## Example
34
50
 
@@ -68,11 +84,18 @@ const MyComponent = () => {
68
84
  };
69
85
  ```
70
86
 
87
+ ## Implementation
88
+
89
+ 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.
90
+
91
+ 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.
92
+
71
93
  ## Changelog
72
94
 
73
95
  - 1.0.0 - Initial release
74
96
  - 1.0.3 - Changed the exported API to be slightly more flexible.
75
97
  - 1.1.1 - Upgraded to KeenSlider 6 and improved general reactivity.
98
+ - 1.2.5 - Added autoplay plugin and general plugin structure
76
99
 
77
100
  ## Keen Options API
78
101
 
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ declare module "solid-js" {
28
28
  * <div use:slider>...</div>
29
29
  * ```
30
30
  */
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: {
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>[]) => [create: (el: HTMLElement) => void, helpers: {
32
32
  current: Accessor<number>;
33
33
  next: Accessor<void>;
34
34
  prev: Accessor<void>;
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import KeenSlider from "keen-slider";
21
21
  * <div use:slider>...</div>
22
22
  * ```
23
23
  */
24
- const createSlider = (options, plugins) => {
24
+ const createSlider = (options, ...plugins) => {
25
25
  let slider;
26
26
  const [current, setCurrent] = createSignal(0);
27
27
  const destroy = () => slider && slider.destroy();
@@ -31,16 +31,15 @@ const createSlider = (options, plugins) => {
31
31
  // @ts-ignore
32
32
  const opts = () => ({
33
33
  selector: el.childNodes,
34
- ...(typeof options == 'function' ? options() : options)
34
+ ...(typeof options == "function" ? options() : options)
35
35
  });
36
36
  onMount(() => {
37
37
  slider = new KeenSlider(el, opts(), plugins);
38
38
  slider.on("slideChanged", () => setCurrent(slider.track.details.rel));
39
39
  });
40
40
  onCleanup(destroy);
41
- // Only watch the options of an accessor is provided
42
- if (typeof options === 'function') {
43
- createEffect(on(() => options(), () => slider && slider.update(opts())));
41
+ if (typeof options === "function") {
42
+ createEffect(on(() => options, () => slider && slider.update(opts())));
44
43
  }
45
44
  };
46
45
  return [
@@ -0,0 +1,28 @@
1
+ import { Accessor } from "solid-js";
2
+ import { KeenSliderInstance } from "keen-slider";
3
+ /**
4
+ * Provides an autoplay plugin.
5
+ *
6
+ * @param {number} interval Interval in milliseconds for switching slides
7
+ * @param {object} options Options to customize the autoplay
8
+ * @param {Function} options.pause A pause signal to control the autoplay
9
+ * @param {boolean} options.pauseOnDrag Denotes of the autoplay should pause on drag.
10
+ * @param {object} options.animation Allows for control of duration and easing.
11
+ * @param {number} options.duration Duration for transitioning the slide.
12
+ * @param {number} options.easing Easing function for the transition animation.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const [create, { prev, next }] = createSlider();
17
+ * <div use:slider>...</div>
18
+ * ```
19
+ */
20
+ declare const autoplay: (interval: number | undefined, options: {
21
+ pause?: Accessor<boolean> | undefined;
22
+ pauseOnDrag?: boolean | undefined;
23
+ animation?: {
24
+ duration?: number | undefined;
25
+ easing?: ((t: number) => number) | undefined;
26
+ } | undefined;
27
+ }) => (slider: KeenSliderInstance) => void;
28
+ export default autoplay;
@@ -0,0 +1,33 @@
1
+ import { createEffect } from "solid-js";
2
+ import createTimer, { Schedule } from "@solid-primitives/timer";
3
+ /**
4
+ * Provides an autoplay plugin.
5
+ *
6
+ * @param {number} interval Interval in milliseconds for switching slides
7
+ * @param {object} options Options to customize the autoplay
8
+ * @param {Function} options.pause A pause signal to control the autoplay
9
+ * @param {boolean} options.pauseOnDrag Denotes of the autoplay should pause on drag.
10
+ * @param {object} options.animation Allows for control of duration and easing.
11
+ * @param {number} options.duration Duration for transitioning the slide.
12
+ * @param {number} options.easing Easing function for the transition animation.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const [create, { prev, next }] = createSlider();
17
+ * <div use:slider>...</div>
18
+ * ```
19
+ */
20
+ const autoplay = (interval = 1000, options) => {
21
+ return (slider) => {
22
+ let clear;
23
+ const start = () => {
24
+ clear = createTimer(() => slider.moveToIdx(slider.track.details.position + 1, true, options.animation), interval, Schedule.Interval);
25
+ };
26
+ // Pause the slider on drag
27
+ if (options.pauseOnDrag || true) {
28
+ slider.on("dragStarted", () => clear());
29
+ }
30
+ createEffect(() => (!options.pause || options.pause() === false ? start() : clear()));
31
+ };
32
+ };
33
+ export default autoplay;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solid-slider",
3
- "version": "1.1.1",
4
- "description": "A slider/carousel component for Solid powered by KeenSlider.",
3
+ "version": "1.2.5",
4
+ "description": "A slider utility for SolidJS.",
5
5
  "author": "David Di Biase",
6
6
  "license": "ISC",
7
7
  "bugs": {
@@ -16,6 +16,10 @@
16
16
  },
17
17
  "main": "dist/index.js",
18
18
  "module": "dist/index.js",
19
+ "exports": {
20
+ ".": "./dist/index.js",
21
+ "./plugins/autoplay": "./dist/plugins/autoplay.js"
22
+ },
19
23
  "types": "dist/index.d.ts",
20
24
  "sideEffects": "false",
21
25
  "files": [
@@ -38,12 +42,13 @@
38
42
  "plugin"
39
43
  ],
40
44
  "dependencies": {
45
+ "@solid-primitives/timer": "^1.1.0",
41
46
  "keen-slider": "^6.6.3",
42
47
  "rimraf": "^3.0.2",
43
48
  "solid-js": "^1.3.5",
44
49
  "typescript": "^4.5.5"
45
50
  },
46
51
  "devDependencies": {
47
- "prettier": "^2.4.1"
52
+ "prettier": "^2.5.1"
48
53
  }
49
54
  }