solid-slider 1.1.1 → 1.2.7

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
@@ -4,7 +4,7 @@
4
4
  [![size](https://img.shields.io/npm/v/solid-slider?style=for-the-badge)](https://www.npmjs.com/package/solid-slider)
5
5
  ![npm](https://img.shields.io/npm/dw/solid-slider?style=for-the-badge)
6
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.
7
+ A carousel/slider implementation in TypeScript for SolidJS. It's built on Keen-Slider 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.
8
8
 
9
9
  ## Installation
10
10
 
@@ -16,19 +16,39 @@ yarn add solid-slider ## or in yarn
16
16
  Add as a module:
17
17
 
18
18
  ```ts
19
- import "solid-slider/dist/slider.css";
19
+ import "solid-slider/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 Keen-Slider 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. Please feel free to post requests for additional plugins or submit PRs if you decide to improve the base functionality. Some ideas for additional plugins include:
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
+ - Slider nav (dot, arrow controls even thumbnails)
32
+ - Lazy loaded images
33
+ - Slide transitions
34
+
35
+ ### Autoplay
36
+
37
+ 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.
38
+
39
+ ```ts
40
+ import createSlider from "solid-slider";
41
+ import autoplay from "solid-slider/plugins/autoplay";
42
+
43
+ const [pause, togglePause] = createSignal(false);
44
+ const [slider] = createSlider(
45
+ { loop: true },
46
+ autoplay(2000, {
47
+ pause,
48
+ pauseOnDrag: true
49
+ })
50
+ );
51
+ ```
32
52
 
33
53
  ## Example
34
54
 
@@ -68,11 +88,19 @@ const MyComponent = () => {
68
88
  };
69
89
  ```
70
90
 
91
+ ## Implementation
92
+
93
+ Solid Slider is meant to be a lightweight and compact wrapper of Keen-Slider. 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.
94
+
95
+ Thie library exports it's own CSS which is the basic Keen-Slider 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 Keen-Slider 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.
96
+
71
97
  ## Changelog
72
98
 
73
99
  - 1.0.0 - Initial release
74
100
  - 1.0.3 - Changed the exported API to be slightly more flexible.
75
- - 1.1.1 - Upgraded to KeenSlider 6 and improved general reactivity.
101
+ - 1.1.1 - Upgraded to Keen-Slider 6 and improved general reactivity.
102
+ - 1.2.5 - Added autoplay plugin and general plugin structure
103
+ - 1.2.7 - Maybe I should actually export the .css? That'd be a good idea, right?
76
104
 
77
105
  ## Keen Options API
78
106
 
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.7",
4
+ "description": "A slider utility for SolidJS.",
5
5
  "author": "David Di Biase",
6
6
  "license": "ISC",
7
7
  "bugs": {
@@ -16,6 +16,11 @@
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
+ "./slider.css": "./dist/slider.css"
23
+ },
19
24
  "types": "dist/index.d.ts",
20
25
  "sideEffects": "false",
21
26
  "files": [
@@ -38,12 +43,13 @@
38
43
  "plugin"
39
44
  ],
40
45
  "dependencies": {
46
+ "@solid-primitives/timer": "^1.1.0",
41
47
  "keen-slider": "^6.6.3",
42
48
  "rimraf": "^3.0.2",
43
49
  "solid-js": "^1.3.5",
44
50
  "typescript": "^4.5.5"
45
51
  },
46
52
  "devDependencies": {
47
- "prettier": "^2.4.1"
53
+ "prettier": "^2.5.1"
48
54
  }
49
55
  }