@yamada-ui/carousel 0.1.0
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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/carousel-control.d.ts +8 -0
- package/dist/carousel-control.js +154 -0
- package/dist/carousel-control.mjs +9 -0
- package/dist/carousel-indicators.d.ts +14 -0
- package/dist/carousel-indicators.js +120 -0
- package/dist/carousel-indicators.mjs +7 -0
- package/dist/carousel-slide.d.ts +15 -0
- package/dist/carousel-slide.js +86 -0
- package/dist/carousel-slide.mjs +7 -0
- package/dist/carousel.d.ts +38 -0
- package/dist/carousel.js +519 -0
- package/dist/carousel.mjs +10 -0
- package/dist/chunk-4P3A5PTO.mjs +246 -0
- package/dist/chunk-BWFAE3UJ.mjs +29 -0
- package/dist/chunk-FDF2QUCY.mjs +85 -0
- package/dist/chunk-PQ3S6YEB.mjs +139 -0
- package/dist/chunk-UMRTZXZW.mjs +51 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +529 -0
- package/dist/index.mjs +21 -0
- package/dist/use-carousel.d.ts +82 -0
- package/dist/use-carousel.js +279 -0
- package/dist/use-carousel.mjs +16 -0
- package/package.json +81 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/use-carousel.ts
|
|
31
|
+
var use_carousel_exports = {};
|
|
32
|
+
__export(use_carousel_exports, {
|
|
33
|
+
CarouselProvider: () => CarouselProvider,
|
|
34
|
+
useCarousel: () => useCarousel,
|
|
35
|
+
useCarouselContext: () => useCarouselContext,
|
|
36
|
+
useCarouselControl: () => useCarouselControl,
|
|
37
|
+
useCarouselIndicators: () => useCarouselIndicators,
|
|
38
|
+
useCarouselSlide: () => useCarouselSlide
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(use_carousel_exports);
|
|
41
|
+
var import_core = require("@yamada-ui/core");
|
|
42
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
43
|
+
var import_utils = require("@yamada-ui/utils");
|
|
44
|
+
var import_embla_carousel_react = __toESM(require("embla-carousel-react"));
|
|
45
|
+
var import_react = require("react");
|
|
46
|
+
var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
|
|
47
|
+
name: "CarouselContext",
|
|
48
|
+
errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
|
|
49
|
+
});
|
|
50
|
+
var useCarousel = ({
|
|
51
|
+
index,
|
|
52
|
+
defaultIndex = 0,
|
|
53
|
+
onChange,
|
|
54
|
+
align = "center",
|
|
55
|
+
orientation = "horizontal",
|
|
56
|
+
autoplay = false,
|
|
57
|
+
stopMouseEnterAutoplay = true,
|
|
58
|
+
loop = true,
|
|
59
|
+
speed = 10,
|
|
60
|
+
delay = 4e3,
|
|
61
|
+
gap = "md",
|
|
62
|
+
slidesToScroll = 1,
|
|
63
|
+
draggable = true,
|
|
64
|
+
dragFree = false,
|
|
65
|
+
inViewThreshold = 0,
|
|
66
|
+
skipSnaps = false,
|
|
67
|
+
containScroll = "",
|
|
68
|
+
slideSize = "100%",
|
|
69
|
+
includeGapInSize = true,
|
|
70
|
+
onScrollProgress,
|
|
71
|
+
children,
|
|
72
|
+
...rest
|
|
73
|
+
}) => {
|
|
74
|
+
const computedProps = (0, import_utils.splitObject)(rest, import_core.layoutStylesProperties);
|
|
75
|
+
const [selectedIndex, setSelectedIndex] = (0, import_use_controllable_state.useControllableState)({
|
|
76
|
+
value: index,
|
|
77
|
+
defaultValue: defaultIndex,
|
|
78
|
+
onChange
|
|
79
|
+
});
|
|
80
|
+
const isVertical = orientation === "vertical";
|
|
81
|
+
const [carouselRef, carousel] = (0, import_embla_carousel_react.default)({
|
|
82
|
+
axis: isVertical ? "y" : "x",
|
|
83
|
+
startIndex: defaultIndex,
|
|
84
|
+
loop,
|
|
85
|
+
align,
|
|
86
|
+
slidesToScroll,
|
|
87
|
+
draggable,
|
|
88
|
+
dragFree,
|
|
89
|
+
speed,
|
|
90
|
+
inViewThreshold,
|
|
91
|
+
skipSnaps,
|
|
92
|
+
containScroll
|
|
93
|
+
});
|
|
94
|
+
const [indexes, setIndexes] = (0, import_react.useState)([]);
|
|
95
|
+
const [isMouseEnter, setIsMouseEnter] = (0, import_react.useState)(false);
|
|
96
|
+
const timeoutId = (0, import_react.useRef)(void 0);
|
|
97
|
+
const onScroll = (0, import_react.useCallback)(() => {
|
|
98
|
+
if (!carousel)
|
|
99
|
+
return;
|
|
100
|
+
const progress = Math.round(Math.max(0, Math.min(1, carousel.scrollProgress())) * 100);
|
|
101
|
+
onScrollProgress == null ? void 0 : onScrollProgress(progress);
|
|
102
|
+
}, [carousel, onScrollProgress]);
|
|
103
|
+
const onSelect = (0, import_react.useCallback)(() => {
|
|
104
|
+
if (!carousel)
|
|
105
|
+
return;
|
|
106
|
+
const index2 = carousel.selectedScrollSnap();
|
|
107
|
+
setSelectedIndex(index2);
|
|
108
|
+
}, [carousel, setSelectedIndex]);
|
|
109
|
+
(0, import_react.useEffect)(() => {
|
|
110
|
+
const isStop = isMouseEnter && stopMouseEnterAutoplay;
|
|
111
|
+
const isLast = !(carousel == null ? void 0 : carousel.canScrollNext());
|
|
112
|
+
if (carousel && autoplay && !isStop && !isLast) {
|
|
113
|
+
timeoutId.current = setInterval(() => {
|
|
114
|
+
carousel.scrollNext();
|
|
115
|
+
}, delay);
|
|
116
|
+
} else {
|
|
117
|
+
if (timeoutId.current)
|
|
118
|
+
clearInterval(timeoutId.current);
|
|
119
|
+
timeoutId.current = void 0;
|
|
120
|
+
}
|
|
121
|
+
return () => {
|
|
122
|
+
if (timeoutId.current)
|
|
123
|
+
clearInterval(timeoutId.current);
|
|
124
|
+
};
|
|
125
|
+
}, [autoplay, delay, stopMouseEnterAutoplay, carousel, isMouseEnter, loop, selectedIndex]);
|
|
126
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
127
|
+
if (!carousel)
|
|
128
|
+
return;
|
|
129
|
+
carousel.reInit();
|
|
130
|
+
const snapList = carousel.scrollSnapList();
|
|
131
|
+
const indexes2 = snapList.map((_, i) => i);
|
|
132
|
+
setIndexes(indexes2);
|
|
133
|
+
}, [
|
|
134
|
+
import_react.Children.toArray(children).length,
|
|
135
|
+
align,
|
|
136
|
+
orientation,
|
|
137
|
+
loop,
|
|
138
|
+
speed,
|
|
139
|
+
gap,
|
|
140
|
+
slidesToScroll,
|
|
141
|
+
draggable,
|
|
142
|
+
dragFree,
|
|
143
|
+
inViewThreshold,
|
|
144
|
+
skipSnaps,
|
|
145
|
+
containScroll,
|
|
146
|
+
slideSize,
|
|
147
|
+
includeGapInSize
|
|
148
|
+
]);
|
|
149
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
150
|
+
if (!carousel)
|
|
151
|
+
return;
|
|
152
|
+
const snapList = carousel.scrollSnapList();
|
|
153
|
+
const indexes2 = snapList.map((_, i) => i);
|
|
154
|
+
setIndexes(indexes2);
|
|
155
|
+
}, [carousel]);
|
|
156
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
157
|
+
if (carousel) {
|
|
158
|
+
carousel.on("select", onSelect);
|
|
159
|
+
carousel.on("scroll", onScroll);
|
|
160
|
+
onScroll();
|
|
161
|
+
return () => {
|
|
162
|
+
carousel.off("select", onSelect);
|
|
163
|
+
carousel.off("scroll", onScroll);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}, [carousel, onScroll]);
|
|
167
|
+
const getContainerProps = (0, import_react.useCallback)(
|
|
168
|
+
(props = {}, ref = null) => ({
|
|
169
|
+
...computedProps[0],
|
|
170
|
+
...props,
|
|
171
|
+
ref,
|
|
172
|
+
onMouseEnter: (0, import_utils.handlerAll)(props.onMouseEnter, () => {
|
|
173
|
+
setIsMouseEnter(true);
|
|
174
|
+
}),
|
|
175
|
+
onMouseLeave: (0, import_utils.handlerAll)(props.onMouseLeave, () => {
|
|
176
|
+
setIsMouseEnter(false);
|
|
177
|
+
})
|
|
178
|
+
}),
|
|
179
|
+
[computedProps]
|
|
180
|
+
);
|
|
181
|
+
const getSlidesProps = (0, import_react.useCallback)(
|
|
182
|
+
(props = {}) => ({
|
|
183
|
+
...computedProps[1],
|
|
184
|
+
...props,
|
|
185
|
+
ref: carouselRef
|
|
186
|
+
}),
|
|
187
|
+
[computedProps, carouselRef]
|
|
188
|
+
);
|
|
189
|
+
return {
|
|
190
|
+
carousel,
|
|
191
|
+
children,
|
|
192
|
+
indexes,
|
|
193
|
+
selectedIndex,
|
|
194
|
+
orientation,
|
|
195
|
+
slideSize,
|
|
196
|
+
gap,
|
|
197
|
+
slidesToScroll,
|
|
198
|
+
includeGapInSize,
|
|
199
|
+
getContainerProps,
|
|
200
|
+
getSlidesProps
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
var useCarouselSlide = ({ index }) => {
|
|
204
|
+
const { selectedIndex, slidesToScroll } = useCarouselContext();
|
|
205
|
+
index = Math.floor((index != null ? index : 0) / (slidesToScroll != null ? slidesToScroll : 1));
|
|
206
|
+
const isSelected = index === selectedIndex;
|
|
207
|
+
const getSlideProps = (0, import_react.useCallback)(
|
|
208
|
+
(props = {}) => ({
|
|
209
|
+
...props,
|
|
210
|
+
role: "carousel-slide",
|
|
211
|
+
"data-index": index,
|
|
212
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected)
|
|
213
|
+
}),
|
|
214
|
+
[isSelected, index]
|
|
215
|
+
);
|
|
216
|
+
return { getSlideProps };
|
|
217
|
+
};
|
|
218
|
+
var useCarouselControl = ({ operation, ...rest }) => {
|
|
219
|
+
var _a, _b;
|
|
220
|
+
const { carousel } = useCarouselContext();
|
|
221
|
+
const isPrev = operation === "prev";
|
|
222
|
+
const disabled = (_b = (_a = rest.disabled) != null ? _a : rest.isDisabled) != null ? _b : isPrev ? !(carousel == null ? void 0 : carousel.canScrollPrev()) : !(carousel == null ? void 0 : carousel.canScrollNext());
|
|
223
|
+
const onClick = (0, import_react.useCallback)(() => {
|
|
224
|
+
if (!carousel)
|
|
225
|
+
return;
|
|
226
|
+
if (isPrev) {
|
|
227
|
+
carousel.scrollPrev();
|
|
228
|
+
} else {
|
|
229
|
+
carousel.scrollNext();
|
|
230
|
+
}
|
|
231
|
+
}, [carousel, isPrev]);
|
|
232
|
+
const getControlProps = (0, import_react.useCallback)(
|
|
233
|
+
(props = {}, ref = null) => ({
|
|
234
|
+
...props,
|
|
235
|
+
ref,
|
|
236
|
+
disabled,
|
|
237
|
+
role: "carousel-control",
|
|
238
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, onClick)
|
|
239
|
+
}),
|
|
240
|
+
[disabled, onClick]
|
|
241
|
+
);
|
|
242
|
+
return { getControlProps };
|
|
243
|
+
};
|
|
244
|
+
var useCarouselIndicators = () => {
|
|
245
|
+
const { selectedIndex, carousel, indexes } = useCarouselContext();
|
|
246
|
+
const onClick = (0, import_react.useCallback)(
|
|
247
|
+
(ev, index) => {
|
|
248
|
+
if (!carousel)
|
|
249
|
+
return;
|
|
250
|
+
ev.stopPropagation();
|
|
251
|
+
carousel.scrollTo(index);
|
|
252
|
+
},
|
|
253
|
+
[carousel]
|
|
254
|
+
);
|
|
255
|
+
const getIndicatorProps = (0, import_react.useCallback)(
|
|
256
|
+
({ index, ...props } = {}) => {
|
|
257
|
+
const isSelected = index === selectedIndex;
|
|
258
|
+
return {
|
|
259
|
+
...props,
|
|
260
|
+
key: index,
|
|
261
|
+
role: "carousel-indicator",
|
|
262
|
+
"data-index": index,
|
|
263
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected),
|
|
264
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, (ev) => onClick(ev, index))
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
[onClick, selectedIndex]
|
|
268
|
+
);
|
|
269
|
+
return { indexes, getIndicatorProps };
|
|
270
|
+
};
|
|
271
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
272
|
+
0 && (module.exports = {
|
|
273
|
+
CarouselProvider,
|
|
274
|
+
useCarousel,
|
|
275
|
+
useCarouselContext,
|
|
276
|
+
useCarouselControl,
|
|
277
|
+
useCarouselIndicators,
|
|
278
|
+
useCarouselSlide
|
|
279
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CarouselProvider,
|
|
3
|
+
useCarousel,
|
|
4
|
+
useCarouselContext,
|
|
5
|
+
useCarouselControl,
|
|
6
|
+
useCarouselIndicators,
|
|
7
|
+
useCarouselSlide
|
|
8
|
+
} from "./chunk-4P3A5PTO.mjs";
|
|
9
|
+
export {
|
|
10
|
+
CarouselProvider,
|
|
11
|
+
useCarousel,
|
|
12
|
+
useCarouselContext,
|
|
13
|
+
useCarouselControl,
|
|
14
|
+
useCarouselIndicators,
|
|
15
|
+
useCarouselSlide
|
|
16
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yamada-ui/carousel",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Yamada UI carousel component",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"yamada",
|
|
7
|
+
"yamada ui",
|
|
8
|
+
"react",
|
|
9
|
+
"emotion",
|
|
10
|
+
"component",
|
|
11
|
+
"carousel",
|
|
12
|
+
"ui",
|
|
13
|
+
"uikit",
|
|
14
|
+
"styled",
|
|
15
|
+
"style-props",
|
|
16
|
+
"styled-component",
|
|
17
|
+
"css-in-js"
|
|
18
|
+
],
|
|
19
|
+
"author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/hirotomoyamada/yamada-ui",
|
|
32
|
+
"directory": "packages/components/carousel"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"embla-carousel-react": "^7.0.0",
|
|
39
|
+
"@yamada-ui/core": "0.1.0",
|
|
40
|
+
"@yamada-ui/icon": "0.1.0",
|
|
41
|
+
"@yamada-ui/button": "0.1.0",
|
|
42
|
+
"@yamada-ui/use-controllable-state": "0.1.0",
|
|
43
|
+
"@yamada-ui/utils": "0.1.0",
|
|
44
|
+
"@yamada-ui/use-token": "0.1.0",
|
|
45
|
+
"@yamada-ui/use-value": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"clean-package": "2.2.0",
|
|
49
|
+
"react": "^18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"clean-package": "../../../clean-package.config.json",
|
|
55
|
+
"tsup": {
|
|
56
|
+
"clean": true,
|
|
57
|
+
"target": "es2019",
|
|
58
|
+
"format": [
|
|
59
|
+
"cjs",
|
|
60
|
+
"esm"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"module": "dist/index.mjs",
|
|
64
|
+
"types": "dist/index.d.ts",
|
|
65
|
+
"exports": {
|
|
66
|
+
".": {
|
|
67
|
+
"types": "./dist/index.d.ts",
|
|
68
|
+
"import": "./dist/index.mjs",
|
|
69
|
+
"require": "./dist/index.js"
|
|
70
|
+
},
|
|
71
|
+
"./package.json": "./package.json"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"dev": "pnpm build:fast -- --watch",
|
|
75
|
+
"build": "tsup src --dts",
|
|
76
|
+
"build:fast": "tsup src",
|
|
77
|
+
"clean": "rimraf dist .turbo",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"gen:docs": "tsx ../../../scripts/generate-docs"
|
|
80
|
+
}
|
|
81
|
+
}
|