@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Hirotomo Yamada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @yamada-ui/carousel
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
$ pnpm add @yamada-ui/carousel
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ yarn add @yamada-ui/carousel
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ npm install @yamada-ui/carousel
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contribution
|
|
22
|
+
|
|
23
|
+
Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
|
|
24
|
+
|
|
25
|
+
## Licence
|
|
26
|
+
|
|
27
|
+
This package is licensed under the terms of the
|
|
28
|
+
[MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { IconButtonProps } from '@yamada-ui/button';
|
|
3
|
+
|
|
4
|
+
type CarouselControlProps = IconButtonProps;
|
|
5
|
+
declare const CarouselControlPrev: _yamada_ui_core.Component<"button", IconButtonProps>;
|
|
6
|
+
declare const CarouselControlNext: _yamada_ui_core.Component<"button", IconButtonProps>;
|
|
7
|
+
|
|
8
|
+
export { CarouselControlNext, CarouselControlPrev, CarouselControlProps };
|
|
@@ -0,0 +1,154 @@
|
|
|
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/carousel-control.tsx
|
|
31
|
+
var carousel_control_exports = {};
|
|
32
|
+
__export(carousel_control_exports, {
|
|
33
|
+
CarouselControlNext: () => CarouselControlNext,
|
|
34
|
+
CarouselControlPrev: () => CarouselControlPrev
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(carousel_control_exports);
|
|
37
|
+
var import_button = require("@yamada-ui/button");
|
|
38
|
+
var import_core2 = require("@yamada-ui/core");
|
|
39
|
+
var import_icon = require("@yamada-ui/icon");
|
|
40
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
41
|
+
|
|
42
|
+
// src/use-carousel.ts
|
|
43
|
+
var import_core = require("@yamada-ui/core");
|
|
44
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
45
|
+
var import_utils = require("@yamada-ui/utils");
|
|
46
|
+
var import_embla_carousel_react = __toESM(require("embla-carousel-react"));
|
|
47
|
+
var import_react = require("react");
|
|
48
|
+
var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
|
|
49
|
+
name: "CarouselContext",
|
|
50
|
+
errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
|
|
51
|
+
});
|
|
52
|
+
var useCarouselControl = ({ operation, ...rest }) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const { carousel } = useCarouselContext();
|
|
55
|
+
const isPrev = operation === "prev";
|
|
56
|
+
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());
|
|
57
|
+
const onClick = (0, import_react.useCallback)(() => {
|
|
58
|
+
if (!carousel)
|
|
59
|
+
return;
|
|
60
|
+
if (isPrev) {
|
|
61
|
+
carousel.scrollPrev();
|
|
62
|
+
} else {
|
|
63
|
+
carousel.scrollNext();
|
|
64
|
+
}
|
|
65
|
+
}, [carousel, isPrev]);
|
|
66
|
+
const getControlProps = (0, import_react.useCallback)(
|
|
67
|
+
(props = {}, ref = null) => ({
|
|
68
|
+
...props,
|
|
69
|
+
ref,
|
|
70
|
+
disabled,
|
|
71
|
+
role: "carousel-control",
|
|
72
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, onClick)
|
|
73
|
+
}),
|
|
74
|
+
[disabled, onClick]
|
|
75
|
+
);
|
|
76
|
+
return { getControlProps };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/carousel-control.tsx
|
|
80
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
81
|
+
var CarouselControlPrev = (0, import_core2.forwardRef)(
|
|
82
|
+
({ className, ...rest }, ref) => {
|
|
83
|
+
const { orientation } = useCarouselContext();
|
|
84
|
+
const { getControlProps } = useCarouselControl({ operation: "prev" });
|
|
85
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
86
|
+
CarouselControl,
|
|
87
|
+
{
|
|
88
|
+
operation: "prev",
|
|
89
|
+
className: (0, import_utils2.cx)("ui-carousel-control-prev", className),
|
|
90
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
91
|
+
import_icon.ChevronIcon,
|
|
92
|
+
{
|
|
93
|
+
__css: {
|
|
94
|
+
fontSize: "1.5em",
|
|
95
|
+
transform: orientation === "vertical" ? "rotate(180deg)" : "rotate(90deg)"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
...getControlProps(rest, ref)
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
var CarouselControlNext = (0, import_core2.forwardRef)(
|
|
105
|
+
({ className, ...rest }, ref) => {
|
|
106
|
+
const { orientation } = useCarouselContext();
|
|
107
|
+
const { getControlProps } = useCarouselControl({ operation: "next" });
|
|
108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
109
|
+
CarouselControl,
|
|
110
|
+
{
|
|
111
|
+
operation: "next",
|
|
112
|
+
className: (0, import_utils2.cx)("ui-carousel-control-next", className),
|
|
113
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
114
|
+
import_icon.ChevronIcon,
|
|
115
|
+
{
|
|
116
|
+
__css: {
|
|
117
|
+
fontSize: "1.5em",
|
|
118
|
+
transform: orientation === "vertical" ? "rotate(0deg)" : "rotate(-90deg)"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
...getControlProps(rest, ref)
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
var CarouselControl = (0, import_core2.forwardRef)(
|
|
128
|
+
({ className, operation, ...rest }, ref) => {
|
|
129
|
+
const { styles } = useCarouselContext();
|
|
130
|
+
const colorScheme = (0, import_core2.useColorModetValue)("whiteAlpha", "blackAlpha");
|
|
131
|
+
const css = {
|
|
132
|
+
position: "absolute",
|
|
133
|
+
zIndex: "kurillin",
|
|
134
|
+
...styles.control,
|
|
135
|
+
...styles[operation]
|
|
136
|
+
};
|
|
137
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
138
|
+
import_button.IconButton,
|
|
139
|
+
{
|
|
140
|
+
ref,
|
|
141
|
+
className: (0, import_utils2.cx)("ui-carousel-control", className),
|
|
142
|
+
colorScheme,
|
|
143
|
+
isRound: true,
|
|
144
|
+
__css: css,
|
|
145
|
+
...rest
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
CarouselControlNext,
|
|
153
|
+
CarouselControlPrev
|
|
154
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
|
|
5
|
+
type CarouselIndicatorsOptions = {
|
|
6
|
+
component?: FC<{
|
|
7
|
+
index: number;
|
|
8
|
+
isSelected: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
type CarouselIndicatorsProps = Omit<HTMLUIProps<'div'>, 'children'> & CarouselIndicatorsOptions;
|
|
12
|
+
declare const CarouselIndicators: _yamada_ui_core.Component<"div", CarouselIndicatorsProps>;
|
|
13
|
+
|
|
14
|
+
export { CarouselIndicators, CarouselIndicatorsProps };
|
|
@@ -0,0 +1,120 @@
|
|
|
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/carousel-indicators.tsx
|
|
31
|
+
var carousel_indicators_exports = {};
|
|
32
|
+
__export(carousel_indicators_exports, {
|
|
33
|
+
CarouselIndicators: () => CarouselIndicators
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(carousel_indicators_exports);
|
|
36
|
+
var import_core2 = require("@yamada-ui/core");
|
|
37
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
38
|
+
var import_react2 = require("react");
|
|
39
|
+
|
|
40
|
+
// src/use-carousel.ts
|
|
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 useCarouselIndicators = () => {
|
|
51
|
+
const { selectedIndex, carousel, indexes } = useCarouselContext();
|
|
52
|
+
const onClick = (0, import_react.useCallback)(
|
|
53
|
+
(ev, index) => {
|
|
54
|
+
if (!carousel)
|
|
55
|
+
return;
|
|
56
|
+
ev.stopPropagation();
|
|
57
|
+
carousel.scrollTo(index);
|
|
58
|
+
},
|
|
59
|
+
[carousel]
|
|
60
|
+
);
|
|
61
|
+
const getIndicatorProps = (0, import_react.useCallback)(
|
|
62
|
+
({ index, ...props } = {}) => {
|
|
63
|
+
const isSelected = index === selectedIndex;
|
|
64
|
+
return {
|
|
65
|
+
...props,
|
|
66
|
+
key: index,
|
|
67
|
+
role: "carousel-indicator",
|
|
68
|
+
"data-index": index,
|
|
69
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected),
|
|
70
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, (ev) => onClick(ev, index))
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
[onClick, selectedIndex]
|
|
74
|
+
);
|
|
75
|
+
return { indexes, getIndicatorProps };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/carousel-indicators.tsx
|
|
79
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
80
|
+
var CarouselIndicators = (0, import_core2.forwardRef)(
|
|
81
|
+
({ className, component = CarouselIndicator, ...rest }, ref) => {
|
|
82
|
+
const { selectedIndex, orientation, styles } = useCarouselContext();
|
|
83
|
+
const { indexes, getIndicatorProps } = useCarouselIndicators();
|
|
84
|
+
const cloneChildren = indexes.map((index) => {
|
|
85
|
+
const isSelected = index === selectedIndex;
|
|
86
|
+
const child = component({ index, isSelected });
|
|
87
|
+
if (!child)
|
|
88
|
+
return null;
|
|
89
|
+
const props = getIndicatorProps({ ...child.props, index });
|
|
90
|
+
return (0, import_react2.cloneElement)(child, props);
|
|
91
|
+
});
|
|
92
|
+
const css = {
|
|
93
|
+
position: "absolute",
|
|
94
|
+
zIndex: "kurillin",
|
|
95
|
+
display: "flex",
|
|
96
|
+
justifyContent: "center",
|
|
97
|
+
...styles.indicators,
|
|
98
|
+
...orientation === "vertical" ? { flexDirection: "column" } : { flexDirection: "row" }
|
|
99
|
+
};
|
|
100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core2.ui.div, { ref, className: (0, import_utils2.cx)("ui-carousel-indicators", className), __css: css, ...rest, children: cloneChildren });
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
var CarouselIndicator = ({ className, ...rest }) => {
|
|
104
|
+
const { styles } = useCarouselContext();
|
|
105
|
+
const css = { ...styles.indicator };
|
|
106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
107
|
+
import_core2.ui.button,
|
|
108
|
+
{
|
|
109
|
+
type: "button",
|
|
110
|
+
tabIndex: -1,
|
|
111
|
+
className: (0, import_utils2.cx)("ui-carousel-indicator", className),
|
|
112
|
+
__css: css,
|
|
113
|
+
...rest
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
CarouselIndicators
|
|
120
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { HTMLUIProps, UIProps } from '@yamada-ui/core';
|
|
3
|
+
import { UseCarouselSlideProps } from './use-carousel.js';
|
|
4
|
+
import '@yamada-ui/utils';
|
|
5
|
+
import 'react';
|
|
6
|
+
import '@yamada-ui/button';
|
|
7
|
+
import 'embla-carousel-react';
|
|
8
|
+
|
|
9
|
+
type CarouselSlideOptions = {
|
|
10
|
+
size?: UIProps['width'];
|
|
11
|
+
};
|
|
12
|
+
type CarouselSlideProps = HTMLUIProps<'div'> & UseCarouselSlideProps & CarouselSlideOptions;
|
|
13
|
+
declare const CarouselSlide: _yamada_ui_core.Component<"div", CarouselSlideProps>;
|
|
14
|
+
|
|
15
|
+
export { CarouselSlide, CarouselSlideProps };
|
|
@@ -0,0 +1,86 @@
|
|
|
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/carousel-slide.tsx
|
|
31
|
+
var carousel_slide_exports = {};
|
|
32
|
+
__export(carousel_slide_exports, {
|
|
33
|
+
CarouselSlide: () => CarouselSlide
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(carousel_slide_exports);
|
|
36
|
+
var import_core2 = require("@yamada-ui/core");
|
|
37
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
38
|
+
|
|
39
|
+
// src/use-carousel.ts
|
|
40
|
+
var import_core = require("@yamada-ui/core");
|
|
41
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
42
|
+
var import_utils = require("@yamada-ui/utils");
|
|
43
|
+
var import_embla_carousel_react = __toESM(require("embla-carousel-react"));
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
|
|
46
|
+
name: "CarouselContext",
|
|
47
|
+
errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
|
|
48
|
+
});
|
|
49
|
+
var useCarouselSlide = ({ index }) => {
|
|
50
|
+
const { selectedIndex, slidesToScroll } = useCarouselContext();
|
|
51
|
+
index = Math.floor((index != null ? index : 0) / (slidesToScroll != null ? slidesToScroll : 1));
|
|
52
|
+
const isSelected = index === selectedIndex;
|
|
53
|
+
const getSlideProps = (0, import_react.useCallback)(
|
|
54
|
+
(props = {}) => ({
|
|
55
|
+
...props,
|
|
56
|
+
role: "carousel-slide",
|
|
57
|
+
"data-index": index,
|
|
58
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected)
|
|
59
|
+
}),
|
|
60
|
+
[isSelected, index]
|
|
61
|
+
);
|
|
62
|
+
return { getSlideProps };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/carousel-slide.tsx
|
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
67
|
+
var CarouselSlide = (0, import_core2.forwardRef)(
|
|
68
|
+
({ className, size, ...rest }, ref) => {
|
|
69
|
+
const { slideSize, includeGapInSize, orientation, gap } = useCarouselContext();
|
|
70
|
+
const { getSlideProps } = useCarouselSlide(rest);
|
|
71
|
+
size != null ? size : size = slideSize;
|
|
72
|
+
const css = {
|
|
73
|
+
position: "relative",
|
|
74
|
+
flex: `0 0 ${size}`,
|
|
75
|
+
...includeGapInSize ? { [orientation === "vertical" ? "pb" : "pr"]: gap } : { [orientation === "vertical" ? "mb" : "mr"]: gap }
|
|
76
|
+
};
|
|
77
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core2.ui.div, { className: (0, import_utils2.cx)("ui-carousel-slide", className), __css: css, ...getSlideProps({}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CarouselSlideInner, { ref, ...rest }) });
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
var CarouselSlideInner = (0, import_core2.forwardRef)(({ ...rest }, ref) => {
|
|
81
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core2.ui.div, { ref, className: "ui-carousel-slide-inner", w: "100%", h: "100%", ...rest });
|
|
82
|
+
});
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
CarouselSlide
|
|
86
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { ThemeProps, HTMLUIProps, Token, UIProps } from '@yamada-ui/core';
|
|
3
|
+
import { UseCarouselProps, Orientation, Align, ContainScroll } from './use-carousel.js';
|
|
4
|
+
import { CarouselControlProps } from './carousel-control.js';
|
|
5
|
+
import { CarouselIndicatorsProps } from './carousel-indicators.js';
|
|
6
|
+
import '@yamada-ui/utils';
|
|
7
|
+
import 'react';
|
|
8
|
+
import '@yamada-ui/button';
|
|
9
|
+
import 'embla-carousel-react';
|
|
10
|
+
|
|
11
|
+
type CarouselOptions = {
|
|
12
|
+
orientation?: Token<Orientation>;
|
|
13
|
+
align?: Token<Align>;
|
|
14
|
+
containScroll?: Token<ContainScroll>;
|
|
15
|
+
slidesToScroll?: Token<number>;
|
|
16
|
+
dragFree?: Token<boolean>;
|
|
17
|
+
draggable?: Token<boolean>;
|
|
18
|
+
inViewThreshold?: Token<number>;
|
|
19
|
+
loop?: Token<boolean>;
|
|
20
|
+
skipSnaps?: Token<boolean>;
|
|
21
|
+
speed?: Token<number>;
|
|
22
|
+
delay?: Token<number>;
|
|
23
|
+
autoplay?: Token<boolean>;
|
|
24
|
+
stopMouseEnterAutoplay?: Token<boolean>;
|
|
25
|
+
includeGapInSize?: Token<boolean>;
|
|
26
|
+
slideSize?: UIProps['width'];
|
|
27
|
+
inner?: HTMLUIProps<'div'>;
|
|
28
|
+
withControls?: Token<boolean>;
|
|
29
|
+
controlProps?: CarouselControlProps;
|
|
30
|
+
controlPrevProps?: CarouselControlProps;
|
|
31
|
+
controlNextProps?: CarouselControlProps;
|
|
32
|
+
withIndicators?: Token<boolean>;
|
|
33
|
+
indicatorsProps?: CarouselIndicatorsProps;
|
|
34
|
+
};
|
|
35
|
+
type CarouselProps = ThemeProps<'Carousel'> & Omit<HTMLUIProps<'div'>, 'onChange' | 'draggable'> & Pick<UseCarouselProps, 'index' | 'defaultIndex' | 'onChange' | 'onScrollProgress'> & CarouselOptions;
|
|
36
|
+
declare const Carousel: _yamada_ui_core.Component<"div", CarouselProps>;
|
|
37
|
+
|
|
38
|
+
export { Carousel, CarouselProps };
|