imageslider-next 1.2.1 → 1.3.2
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 +90 -53
- package/dist/imageslider-next.js +50 -21
- package/dist/imageslider-next.stories.js +68 -8
- package/dist/types/src/imageslider-next.d.ts.map +1 -1
- package/dist/types/src/imageslider-next.stories.d.ts +3 -2
- package/dist/types/src/imageslider-next.stories.d.ts.map +1 -1
- package/dist/types/src/imagesliderprops.d.ts +15 -3
- package/dist/types/src/imagesliderprops.d.ts.map +1 -1
- package/package.json +11 -14
package/README.md
CHANGED
|
@@ -1,79 +1,116 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
imageslider-next is a simple image slider using tailwind css.
|
|
1
|
+
# imageslider-next
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
A small, framework-agnostic image slider component built with Tailwind CSS and TypeScript. This package now supports passing a custom image component (for example, Next.js `Image`) so you can enable optimized images inside Next.js projects.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```zsh
|
|
8
8
|
npm i imageslider-next
|
|
9
|
+
# or
|
|
10
|
+
pnpm add imageslider-next
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Lightweight, accessible image slider.
|
|
16
|
+
- Accepts a custom `ImageComponent` (e.g. `next/image`) for optimized images.
|
|
17
|
+
- `imageProps` forwarding for responsive behavior (e.g. `sizes`, `priority`, `objectFit`).
|
|
18
|
+
- Responsive native `<img>` fallback when no `ImageComponent` is provided.
|
|
19
|
+
- Fixed: each slider instance is independent; controls no longer collide across multiple instances.
|
|
20
|
+
|
|
21
|
+
## Basic usage
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import ImageSliderNext from 'imageslider-next';
|
|
25
|
+
|
|
26
|
+
const data = [
|
|
27
|
+
{ id: 1, imageUrl: '/images/1.jpg', title: 'One', alt: 'One', width: 1200, height: 800 },
|
|
28
|
+
{ id: 2, imageUrl: '/images/2.jpg', title: 'Two', alt: 'Two', width: 1200, height: 800 },
|
|
29
|
+
{ id: 3, imageUrl: '/images/3.jpg', title: 'Three', alt: 'Three', width: 1200, height: 800 },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
<ImageSliderNext
|
|
33
|
+
data={data}
|
|
34
|
+
sliderClassName="w-full shadow-md h-64 sm:h-80 rounded-lg"
|
|
35
|
+
slideClassName=""
|
|
36
|
+
buttonClassName="w-3 h-3 rounded-full bg-black/50"
|
|
37
|
+
imageWidth={1200}
|
|
38
|
+
imageHeight={800}
|
|
39
|
+
/>
|
|
40
|
+
```
|
|
12
41
|
|
|
13
|
-
|
|
14
|
-
[Tailwind CSS Installation](https://tailwindcss.com/docs/installation)
|
|
42
|
+
## Using Next.js `Image` for optimization
|
|
15
43
|
|
|
16
|
-
|
|
44
|
+
If you use Next.js, pass `Image` as the `ImageComponent` prop and optionally forward `imageProps` to enable responsive loading. Example:
|
|
17
45
|
|
|
18
|
-
```
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
46
|
+
```tsx
|
|
47
|
+
import Image from 'next/image';
|
|
48
|
+
import ImageSliderNext from 'imageslider-next';
|
|
49
|
+
import img1 from '@/public/1.jpg';
|
|
50
|
+
|
|
51
|
+
const slides = [
|
|
52
|
+
{ id: 1, imageSrc: img1, title: 'First', alt: 'first', width: 1200, height: 800 },
|
|
53
|
+
// ...
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
<ImageSliderNext
|
|
57
|
+
data={slides}
|
|
58
|
+
sliderClassName="w-full shadow-md h-[50vh] rounded-lg"
|
|
59
|
+
ImageComponent={Image}
|
|
60
|
+
imageProps={{ sizes: '100vw', priority: true }}
|
|
61
|
+
imageWidth={1200}
|
|
62
|
+
imageHeight={800}
|
|
63
|
+
/>
|
|
30
64
|
```
|
|
31
65
|
|
|
32
|
-
|
|
66
|
+
Notes:
|
|
67
|
+
- We intentionally strip `fill: true` when forwarded to avoid layout issues inside the slider (the slider manages layout). If you need `fill` behavior, you can implement a wrapper with an explicit aspect ratio on your slide.
|
|
68
|
+
- Provide `width`/`height` per item or use `imageWidth`/`imageHeight` defaults to help the component calculate correct sizes.
|
|
33
69
|
|
|
34
|
-
|
|
70
|
+
## Storybook
|
|
35
71
|
|
|
36
|
-
|
|
37
|
-
<ImageSliderNext data={imageData} sliderClassName={"w-full shadow-md h-48 sm:h-64 xl:h-80 2xl:h-96 rounded-lg"} slideClassName={""} buttonClassName={"w-3 h-3 rounded-full bg-black/50"} buttonLabelClassName={"hidden"} imageHeight={300} imageWidth={500} />
|
|
38
|
-
</div>
|
|
72
|
+
To run the component locally with Storybook:
|
|
39
73
|
|
|
74
|
+
```bash
|
|
75
|
+
npm run storybook
|
|
76
|
+
# or
|
|
77
|
+
pnpm storybook
|
|
40
78
|
```
|
|
41
79
|
|
|
42
|
-
|
|
43
|
-
```ts
|
|
80
|
+
There are example stories that show a native `<img>` fallback and usage with a mock `Image` component. Use the `With Image Component` story to test integration.
|
|
44
81
|
|
|
45
|
-
|
|
46
|
-
[
|
|
47
|
-
{
|
|
48
|
-
id: 1,
|
|
49
|
-
imageUrl: 'https://www.w3schools.com/w3images/workbench.jpg',
|
|
50
|
-
title: 'Image 1',
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: 2,
|
|
54
|
-
imageUrl: 'https://www.w3schools.com/w3images/coffee.jpg',
|
|
55
|
-
title: 'Image 2',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: 3,
|
|
59
|
-
imageUrl: 'https://www.w3schools.com/w3images/sound.jpg',
|
|
60
|
-
title: 'Image 3',
|
|
61
|
-
},
|
|
62
|
-
// Add more images as needed
|
|
63
|
-
]
|
|
82
|
+
Hosted Storybook: https://imageslider-next.vercel.app/
|
|
64
83
|
|
|
65
|
-
|
|
84
|
+
## TypeScript / image imports
|
|
85
|
+
|
|
86
|
+
If your TypeScript setup complains about importing image files, add a simple declaration file `src/types/images.d.ts`:
|
|
66
87
|
|
|
67
|
-
### import in NextJS via external json file
|
|
68
88
|
```ts
|
|
89
|
+
declare module '*.jpg';
|
|
90
|
+
declare module '*.png';
|
|
91
|
+
declare module '*.svg';
|
|
92
|
+
declare module '*.webp';
|
|
93
|
+
declare module '*.avif';
|
|
94
|
+
```
|
|
69
95
|
|
|
70
|
-
|
|
71
|
-
import imageData from '@/public/your-data.json';
|
|
96
|
+
Also, for local development you may want to add React type declarations if you see missing types:
|
|
72
97
|
|
|
98
|
+
```bash
|
|
99
|
+
npm install -D @types/react @types/react-dom
|
|
73
100
|
```
|
|
74
101
|
|
|
75
|
-
##
|
|
102
|
+
## API
|
|
103
|
+
|
|
104
|
+
`ImageSliderNext` props (high level):
|
|
105
|
+
|
|
106
|
+
- `data: ItemData[]` — items to render. Each item supports `imageUrl`, `imageSrc` (imported images), `title`, `alt`, `width`, `height`.
|
|
107
|
+
- `sliderClassName: string` — classes applied to slider root.
|
|
108
|
+
- `slideClassName: string` — classes applied to each slide.
|
|
109
|
+
- `buttonClassName: string` — classes applied to pagination buttons.
|
|
110
|
+
- `imageWidth?: number`, `imageHeight?: number` — defaults used when per-item sizes missing.
|
|
111
|
+
- `ImageComponent?: React.ComponentType<any>` — optional image component (pass Next's `Image`).
|
|
112
|
+
- `imageProps?: Record<string, any>` — forwarded props for the image component (we strip `fill`).
|
|
76
113
|
|
|
77
|
-
|
|
114
|
+
## Contributing
|
|
78
115
|
|
|
79
|
-
|
|
116
|
+
PRs welcome — please run `npm run build` and `npm run storybook` to test changes locally.
|
package/dist/imageslider-next.js
CHANGED
|
@@ -9,6 +9,12 @@ exports["default"] = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
12
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
18
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
19
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
20
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -22,56 +28,79 @@ var ImageSliderNext = function ImageSliderNext(_ref) {
|
|
|
22
28
|
buttonClassName = _ref.buttonClassName,
|
|
23
29
|
imageWidth = _ref.imageWidth,
|
|
24
30
|
imageHeight = _ref.imageHeight,
|
|
25
|
-
buttonLabelClassName = _ref.buttonLabelClassName
|
|
31
|
+
buttonLabelClassName = _ref.buttonLabelClassName,
|
|
32
|
+
ImageComponent = _ref.ImageComponent,
|
|
33
|
+
imageProps = _ref.imageProps;
|
|
26
34
|
var _useState = (0, _react.useState)(0),
|
|
27
35
|
_useState2 = _slicedToArray(_useState, 2),
|
|
28
36
|
current = _useState2[0],
|
|
29
37
|
setCurrent = _useState2[1];
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
slides = _useState4[0],
|
|
33
|
-
setSlides = _useState4[1];
|
|
38
|
+
var slidesRef = (0, _react.useRef)(null);
|
|
39
|
+
var rootRef = (0, _react.useRef)(null);
|
|
34
40
|
(0, _react.useEffect)(function () {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
setSlides(slider.querySelector('.slides'));
|
|
41
|
+
if (rootRef.current) {
|
|
42
|
+
slidesRef.current = rootRef.current.querySelector('.slides');
|
|
38
43
|
}
|
|
39
44
|
}, []);
|
|
40
45
|
var handlePrev = function handlePrev() {
|
|
41
|
-
if (
|
|
42
|
-
setCurrent((current - 1 +
|
|
46
|
+
if (slidesRef.current) {
|
|
47
|
+
setCurrent((current - 1 + slidesRef.current.children.length) % slidesRef.current.children.length);
|
|
43
48
|
}
|
|
44
49
|
};
|
|
45
50
|
var handleNext = function handleNext() {
|
|
46
|
-
if (
|
|
47
|
-
setCurrent((current + 1) %
|
|
51
|
+
if (slidesRef.current) {
|
|
52
|
+
setCurrent((current + 1) % slidesRef.current.children.length);
|
|
48
53
|
}
|
|
49
54
|
};
|
|
50
55
|
var goToNext = function goToNext(index) {
|
|
51
56
|
setCurrent(index);
|
|
52
57
|
};
|
|
53
58
|
(0, _react.useEffect)(function () {
|
|
54
|
-
if (
|
|
55
|
-
|
|
59
|
+
if (slidesRef.current) {
|
|
60
|
+
slidesRef.current.style.transform = 'translateX(' + -current * 100 + '%)';
|
|
56
61
|
}
|
|
57
|
-
}, [current,
|
|
62
|
+
}, [current, slidesRef]);
|
|
58
63
|
var baseSliderCssClass = "overflow-hidden relative flex items-center justify-center";
|
|
59
64
|
var baseSlideCssClass = "slide flex-none w-full h-full items-center justify-center overflow-hidden";
|
|
60
65
|
var baseButtonCssClass = buttonClassName === "" ? "w-3 h-3 rounded-full bg-black/50" : buttonClassName;
|
|
61
66
|
var baseButtonLabelCssClass = buttonLabelClassName === null ? "" : buttonLabelClassName;
|
|
62
67
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
ref: rootRef,
|
|
69
|
+
className: "".concat(baseSliderCssClass, " ").concat(sliderClassName)
|
|
65
70
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
66
71
|
className: "slides flex transition-transform duration-700 ease-in-out"
|
|
67
72
|
}, data.map(function (itemData, index) {
|
|
73
|
+
var _ref2, _itemData$width, _ref3, _itemData$height, _ref4, _itemData$imageSrc, _itemData$alt, _itemData$width2, _itemData$height2, _ref5, _itemData$imageUrl, _itemData$alt2;
|
|
74
|
+
var itemWidth = (_ref2 = (_itemData$width = itemData.width) !== null && _itemData$width !== void 0 ? _itemData$width : imageWidth) !== null && _ref2 !== void 0 ? _ref2 : 1;
|
|
75
|
+
var itemHeight = (_ref3 = (_itemData$height = itemData.height) !== null && _itemData$height !== void 0 ? _itemData$height : imageHeight) !== null && _ref3 !== void 0 ? _ref3 : 1;
|
|
76
|
+
// keep paddingTop calculation available if needed elsewhere
|
|
77
|
+
var paddingTop = "".concat(itemHeight / itemWidth * 100, "%");
|
|
78
|
+
var forwardedImageProps = _objectSpread({}, imageProps !== null && imageProps !== void 0 ? imageProps : {});
|
|
79
|
+
// Always ignore fill to avoid absolute/fill behavior which can cause layout issues in the slider
|
|
80
|
+
if ('fill' in forwardedImageProps) delete forwardedImageProps.fill;
|
|
68
81
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
69
82
|
key: itemData.id,
|
|
70
83
|
className: "".concat(baseSlideCssClass, " ").concat(slideClassName)
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
}, ImageComponent ?
|
|
85
|
+
/*#__PURE__*/
|
|
86
|
+
// Always render the provided Image component in non-fill mode (width/height or responsive)
|
|
87
|
+
_react["default"].createElement(ImageComponent, _extends({
|
|
88
|
+
src: (_ref4 = (_itemData$imageSrc = itemData.imageSrc) !== null && _itemData$imageSrc !== void 0 ? _itemData$imageSrc : itemData.imageUrl) !== null && _ref4 !== void 0 ? _ref4 : '',
|
|
89
|
+
alt: (_itemData$alt = itemData.alt) !== null && _itemData$alt !== void 0 ? _itemData$alt : itemData.title,
|
|
90
|
+
width: (_itemData$width2 = itemData.width) !== null && _itemData$width2 !== void 0 ? _itemData$width2 : imageWidth,
|
|
91
|
+
height: (_itemData$height2 = itemData.height) !== null && _itemData$height2 !== void 0 ? _itemData$height2 : imageHeight,
|
|
92
|
+
className: "w-full h-auto"
|
|
93
|
+
}, forwardedImageProps)) :
|
|
94
|
+
/*#__PURE__*/
|
|
95
|
+
// native img fallback: make responsive via width 100% and height auto
|
|
96
|
+
_react["default"].createElement("img", {
|
|
97
|
+
src: (_ref5 = (_itemData$imageUrl = itemData.imageUrl) !== null && _itemData$imageUrl !== void 0 ? _itemData$imageUrl : itemData.imageSrc) !== null && _ref5 !== void 0 ? _ref5 : '',
|
|
98
|
+
alt: (_itemData$alt2 = itemData.alt) !== null && _itemData$alt2 !== void 0 ? _itemData$alt2 : itemData.title,
|
|
99
|
+
style: {
|
|
100
|
+
width: '100%',
|
|
101
|
+
height: 'auto',
|
|
102
|
+
display: 'block'
|
|
103
|
+
}
|
|
75
104
|
}));
|
|
76
105
|
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
77
106
|
className: "flex flex-wrap absolute bottom-2 z-50 space-x-3"
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports["default"] = exports.Default = void 0;
|
|
7
|
+
exports["default"] = exports.WithImageComponent = exports.Default = void 0;
|
|
7
8
|
var _react = _interopRequireDefault(require("react"));
|
|
8
9
|
var _imagesliderNext = _interopRequireDefault(require("./imageslider-next"));
|
|
9
10
|
require("tailwindcss/tailwind.css");
|
|
11
|
+
var _excluded = ["src", "alt", "width", "height", "fill", "style"];
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
|
|
20
|
+
var img1 = require('./stories/assets/images/1.jpg');
|
|
21
|
+
var img2 = require('./stories/assets/images/2.jpg');
|
|
22
|
+
var img3 = require('./stories/assets/images/3.jpg');
|
|
11
23
|
var _default = exports["default"] = {
|
|
12
24
|
title: 'ImageSliderNext',
|
|
13
25
|
component: _imagesliderNext["default"],
|
|
@@ -20,16 +32,19 @@ var Default = exports.Default = Template.bind({});
|
|
|
20
32
|
Default.args = {
|
|
21
33
|
data: [{
|
|
22
34
|
id: 1,
|
|
23
|
-
|
|
24
|
-
title: 'Image 1'
|
|
35
|
+
imageSrc: img1,
|
|
36
|
+
title: 'Image 1',
|
|
37
|
+
alt: 'Image 1'
|
|
25
38
|
}, {
|
|
26
39
|
id: 2,
|
|
27
|
-
|
|
28
|
-
title: 'Image 2'
|
|
40
|
+
imageSrc: img2,
|
|
41
|
+
title: 'Image 2',
|
|
42
|
+
alt: 'Image 2'
|
|
29
43
|
}, {
|
|
30
44
|
id: 3,
|
|
31
|
-
|
|
32
|
-
title: 'Image 3'
|
|
45
|
+
imageSrc: img3,
|
|
46
|
+
title: 'Image 3',
|
|
47
|
+
alt: 'Image 3'
|
|
33
48
|
}
|
|
34
49
|
// Add more images as needed
|
|
35
50
|
],
|
|
@@ -39,4 +54,49 @@ Default.args = {
|
|
|
39
54
|
buttonLabelClassName: 'hidden',
|
|
40
55
|
imageWidth: 500,
|
|
41
56
|
imageHeight: 300
|
|
42
|
-
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// A tiny Mock Image component that mimics next/image API just for Storybook preview.
|
|
60
|
+
var MockImage = function MockImage(_ref) {
|
|
61
|
+
var src = _ref.src,
|
|
62
|
+
alt = _ref.alt,
|
|
63
|
+
width = _ref.width,
|
|
64
|
+
height = _ref.height,
|
|
65
|
+
fill = _ref.fill,
|
|
66
|
+
style = _ref.style,
|
|
67
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
68
|
+
if (fill) {
|
|
69
|
+
var _rest$objectFit;
|
|
70
|
+
return /*#__PURE__*/_react["default"].createElement("img", {
|
|
71
|
+
src: src,
|
|
72
|
+
alt: alt,
|
|
73
|
+
style: {
|
|
74
|
+
position: 'absolute',
|
|
75
|
+
inset: 0,
|
|
76
|
+
width: '100%',
|
|
77
|
+
height: '100%',
|
|
78
|
+
objectFit: (_rest$objectFit = rest.objectFit) !== null && _rest$objectFit !== void 0 ? _rest$objectFit : 'cover'
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return /*#__PURE__*/_react["default"].createElement("img", {
|
|
83
|
+
src: src,
|
|
84
|
+
alt: alt,
|
|
85
|
+
width: width,
|
|
86
|
+
height: height,
|
|
87
|
+
style: _objectSpread({
|
|
88
|
+
width: '100%',
|
|
89
|
+
height: 'auto',
|
|
90
|
+
display: 'block'
|
|
91
|
+
}, style)
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
var WithImageComponent = exports.WithImageComponent = Template.bind({});
|
|
95
|
+
WithImageComponent.args = _objectSpread(_objectSpread({}, Default.args), {}, {
|
|
96
|
+
ImageComponent: MockImage,
|
|
97
|
+
imageProps: {
|
|
98
|
+
fill: false,
|
|
99
|
+
sizes: '100vw'
|
|
100
|
+
},
|
|
101
|
+
sliderClassName: 'm-5 shadow-md h-[50vh] rounded-lg'
|
|
102
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageslider-next.d.ts","sourceRoot":"","sources":["../../../src/imageslider-next.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"imageslider-next.d.ts","sourceRoot":"","sources":["../../../src/imageslider-next.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAsG/C,CAAA;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ImageSliderProps } from './imagesliderprops';
|
|
2
2
|
import 'tailwindcss/tailwind.css';
|
|
3
|
-
declare const _default: import("
|
|
3
|
+
declare const _default: import("storybook/internal/csf").ComponentAnnotations<import("@storybook/react-webpack5").ReactRenderer, import("@storybook/react-webpack5").Args>;
|
|
4
4
|
export default _default;
|
|
5
|
-
export declare const Default: import("
|
|
5
|
+
export declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-webpack5").ReactRenderer, ImageSliderProps>;
|
|
6
|
+
export declare const WithImageComponent: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-webpack5").ReactRenderer, ImageSliderProps>;
|
|
6
7
|
//# sourceMappingURL=imageslider-next.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageslider-next.stories.d.ts","sourceRoot":"","sources":["../../../src/imageslider-next.stories.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"imageslider-next.stories.d.ts","sourceRoot":"","sources":["../../../src/imageslider-next.stories.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,0BAA0B,CAAC;;AAElC,wBAIU;AAIV,eAAO,MAAM,OAAO,wHAAoB,CAAC;AA0BzC,eAAO,MAAM,kBAAkB,wHAAoB,CAAC"}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
export interface ItemData {
|
|
2
3
|
id: number;
|
|
3
|
-
|
|
4
|
+
/** string URL or imported image (StaticImageData) */
|
|
5
|
+
imageUrl?: string;
|
|
6
|
+
imageSrc?: string | any;
|
|
4
7
|
title: string;
|
|
8
|
+
alt?: string;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
5
11
|
}
|
|
6
12
|
export interface ImageSliderProps {
|
|
7
13
|
data: ItemData[];
|
|
8
14
|
sliderClassName: string;
|
|
9
15
|
slideClassName: string;
|
|
10
16
|
buttonClassName: string;
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
/** default width applied when individual item width is not provided */
|
|
18
|
+
imageWidth?: number;
|
|
19
|
+
/** default height applied when individual item height is not provided */
|
|
20
|
+
imageHeight?: number;
|
|
13
21
|
buttonLabelClassName?: string | null;
|
|
22
|
+
/** Optional image component to render images. Pass Next.js `Image` here for optimized images. */
|
|
23
|
+
ImageComponent?: React.ComponentType<any>;
|
|
24
|
+
/** Optional props forwarded to the image component or native img element (e.g. { fill: true, sizes: '100vw' }) */
|
|
25
|
+
imageProps?: Record<string, any>;
|
|
14
26
|
}
|
|
15
27
|
//# sourceMappingURL=imagesliderprops.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imagesliderprops.d.ts","sourceRoot":"","sources":["../../../src/imagesliderprops.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,QAAQ;
|
|
1
|
+
{"version":3,"file":"imagesliderprops.d.ts","sourceRoot":"","sources":["../../../src/imagesliderprops.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,iGAAiG;IACjG,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,kHAAkH;IAClH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imageslider-next",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"main": "dist/imageslider-next.js",
|
|
5
5
|
"types": "dist/types/src/imageslider-next.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -30,29 +30,26 @@
|
|
|
30
30
|
"@babel/preset-env": "^7.24.5",
|
|
31
31
|
"@babel/preset-react": "^7.24.1",
|
|
32
32
|
"@babel/preset-typescript": "^7.24.6",
|
|
33
|
-
"@storybook/addon-docs": "^
|
|
33
|
+
"@storybook/addon-docs": "^9.1.3",
|
|
34
|
+
"@types/react": "^18.3.24",
|
|
34
35
|
"react": "^18.3.1",
|
|
35
36
|
"react-dom": "^18.3.1",
|
|
36
37
|
"typescript": "^5.4.5"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@babel/cli": "^7.24.5",
|
|
40
|
-
"@chromatic-com/storybook": "^1.
|
|
41
|
-
"@storybook/addon-
|
|
42
|
-
"@storybook/addon-
|
|
43
|
-
"@storybook/addon-links": "^8.1.3",
|
|
44
|
-
"@storybook/addon-onboarding": "^8.1.3",
|
|
41
|
+
"@chromatic-com/storybook": "^4.1.1",
|
|
42
|
+
"@storybook/addon-links": "^9.1.3",
|
|
43
|
+
"@storybook/addon-onboarding": "^9.1.3",
|
|
45
44
|
"@storybook/addon-styling-webpack": "^1.0.0",
|
|
46
|
-
"@storybook/addon-webpack5-compiler-swc": "^
|
|
47
|
-
"@storybook/
|
|
48
|
-
"@storybook/react": "^8.1.3",
|
|
49
|
-
"@storybook/react-webpack5": "^8.1.3",
|
|
50
|
-
"@storybook/test": "^8.1.3",
|
|
45
|
+
"@storybook/addon-webpack5-compiler-swc": "^3.0.0",
|
|
46
|
+
"@storybook/react-webpack5": "^9.1.3",
|
|
51
47
|
"autoprefixer": "^10.4.19",
|
|
52
48
|
"cross-env": "^7.0.3",
|
|
53
49
|
"postcss-loader": "^8.1.1",
|
|
54
50
|
"rimraf": "^5.0.7",
|
|
55
|
-
"storybook": "^
|
|
56
|
-
"tailwindcss": "^3.4.3"
|
|
51
|
+
"storybook": "^9.1.3",
|
|
52
|
+
"tailwindcss": "^3.4.3",
|
|
53
|
+
"@storybook/addon-docs": "^9.1.3"
|
|
57
54
|
}
|
|
58
55
|
}
|