@nucleux/carousel 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nucleux
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,26 @@
1
+ # @nucleux/carousel
2
+
3
+ Swipeable content carousel — Nucleux agentic UI for React.
4
+
5
+ Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @nucleux/carousel @nucleux/tokens
11
+ ```
12
+
13
+ `react` / `react-dom` are peer dependencies.
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { Carousel } from "@nucleux/carousel";
19
+ ```
20
+
21
+ Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
22
+ and the Tailwind preset from `@nucleux/tokens/preset`.
23
+
24
+ ## License
25
+
26
+ MIT © Nucleux
package/dist/index.cjs ADDED
@@ -0,0 +1,185 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var lucideReact = require('lucide-react');
6
+ var useEmblaCarousel = require('embla-carousel-react');
7
+ var utils = require('@nucleux/utils');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n.default = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
+ var useEmblaCarousel__default = /*#__PURE__*/_interopDefault(useEmblaCarousel);
32
+
33
+ // src/index.tsx
34
+ var CarouselContext = React__namespace.createContext(null);
35
+ var useCarousel = (component) => {
36
+ const ctx = React__namespace.useContext(CarouselContext);
37
+ if (!ctx) throw new Error(`${component} must be used within a Carousel`);
38
+ return ctx;
39
+ };
40
+ var Carousel = React__namespace.forwardRef(
41
+ ({ orientation = "horizontal", opts, setApi, className, children, ...props }, ref) => {
42
+ const [carouselRef, api] = useEmblaCarousel__default.default({
43
+ ...opts,
44
+ axis: orientation === "horizontal" ? "x" : "y"
45
+ });
46
+ const [canScrollPrev, setCanScrollPrev] = React__namespace.useState(false);
47
+ const [canScrollNext, setCanScrollNext] = React__namespace.useState(false);
48
+ const onSelect = React__namespace.useCallback((embla) => {
49
+ setCanScrollPrev(embla.canScrollPrev());
50
+ setCanScrollNext(embla.canScrollNext());
51
+ }, []);
52
+ const scrollPrev = React__namespace.useCallback(() => api?.scrollPrev(), [api]);
53
+ const scrollNext = React__namespace.useCallback(() => api?.scrollNext(), [api]);
54
+ React__namespace.useEffect(() => {
55
+ if (!api) return;
56
+ setApi?.(api);
57
+ onSelect(api);
58
+ api.on("reInit", onSelect);
59
+ api.on("select", onSelect);
60
+ return () => {
61
+ api.off("reInit", onSelect);
62
+ api.off("select", onSelect);
63
+ };
64
+ }, [api, setApi, onSelect]);
65
+ const handleKeyDown = (e) => {
66
+ if (e.key === "ArrowLeft") {
67
+ e.preventDefault();
68
+ scrollPrev();
69
+ } else if (e.key === "ArrowRight") {
70
+ e.preventDefault();
71
+ scrollNext();
72
+ }
73
+ };
74
+ return /* @__PURE__ */ jsxRuntime.jsx(
75
+ CarouselContext.Provider,
76
+ {
77
+ value: { carouselRef, api, orientation, scrollPrev, scrollNext, canScrollPrev, canScrollNext },
78
+ children: /* @__PURE__ */ jsxRuntime.jsx(
79
+ "div",
80
+ {
81
+ ref,
82
+ role: "region",
83
+ "aria-roledescription": "carousel",
84
+ onKeyDownCapture: handleKeyDown,
85
+ className: utils.cn("relative", className),
86
+ ...props,
87
+ children
88
+ }
89
+ )
90
+ }
91
+ );
92
+ }
93
+ );
94
+ Carousel.displayName = "Carousel";
95
+ var CarouselContent = React__namespace.forwardRef(
96
+ ({ className, ...props }, ref) => {
97
+ const { carouselRef, orientation } = useCarousel("CarouselContent");
98
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: carouselRef, className: "overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
99
+ "div",
100
+ {
101
+ ref,
102
+ className: utils.cn("flex", orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col", className),
103
+ ...props
104
+ }
105
+ ) });
106
+ }
107
+ );
108
+ CarouselContent.displayName = "CarouselContent";
109
+ var CarouselItem = React__namespace.forwardRef(
110
+ ({ className, ...props }, ref) => {
111
+ const { orientation } = useCarousel("CarouselItem");
112
+ return /* @__PURE__ */ jsxRuntime.jsx(
113
+ "div",
114
+ {
115
+ ref,
116
+ role: "group",
117
+ "aria-roledescription": "slide",
118
+ className: utils.cn(
119
+ "min-w-0 shrink-0 grow-0 basis-full",
120
+ orientation === "horizontal" ? "pl-4" : "pt-4",
121
+ className
122
+ ),
123
+ ...props
124
+ }
125
+ );
126
+ }
127
+ );
128
+ CarouselItem.displayName = "CarouselItem";
129
+ var navBase = "inline-flex h-8 w-8 items-center justify-center rounded-full border border-input bg-background text-foreground shadow-sm transition-colors hover:bg-accent disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
130
+ var CarouselPrevious = React__namespace.forwardRef(
131
+ ({ className, ...props }, ref) => {
132
+ const { scrollPrev, canScrollPrev, orientation } = useCarousel("CarouselPrevious");
133
+ return /* @__PURE__ */ jsxRuntime.jsx(
134
+ "button",
135
+ {
136
+ ref,
137
+ type: "button",
138
+ "aria-label": "Previous slide",
139
+ disabled: !canScrollPrev,
140
+ onClick: scrollPrev,
141
+ className: utils.cn(
142
+ navBase,
143
+ "absolute",
144
+ orientation === "horizontal" ? "-left-4 top-1/2 -translate-y-1/2" : "-top-4 left-1/2 -translate-x-1/2 rotate-90",
145
+ className
146
+ ),
147
+ ...props,
148
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowLeft, { className: "h-4 w-4" })
149
+ }
150
+ );
151
+ }
152
+ );
153
+ CarouselPrevious.displayName = "CarouselPrevious";
154
+ var CarouselNext = React__namespace.forwardRef(
155
+ ({ className, ...props }, ref) => {
156
+ const { scrollNext, canScrollNext, orientation } = useCarousel("CarouselNext");
157
+ return /* @__PURE__ */ jsxRuntime.jsx(
158
+ "button",
159
+ {
160
+ ref,
161
+ type: "button",
162
+ "aria-label": "Next slide",
163
+ disabled: !canScrollNext,
164
+ onClick: scrollNext,
165
+ className: utils.cn(
166
+ navBase,
167
+ "absolute",
168
+ orientation === "horizontal" ? "-right-4 top-1/2 -translate-y-1/2" : "-bottom-4 left-1/2 -translate-x-1/2 rotate-90",
169
+ className
170
+ ),
171
+ ...props,
172
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowRight, { className: "h-4 w-4" })
173
+ }
174
+ );
175
+ }
176
+ );
177
+ CarouselNext.displayName = "CarouselNext";
178
+
179
+ exports.Carousel = Carousel;
180
+ exports.CarouselContent = CarouselContent;
181
+ exports.CarouselItem = CarouselItem;
182
+ exports.CarouselNext = CarouselNext;
183
+ exports.CarouselPrevious = CarouselPrevious;
184
+ //# sourceMappingURL=index.cjs.map
185
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["React","useEmblaCarousel","jsx","cn","ArrowLeft","ArrowRight"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,IAAM,eAAA,GAAwBA,+BAA2C,IAAI,CAAA;AAC7E,IAAM,WAAA,GAAc,CAAC,SAAA,KAAsB;AACzC,EAAA,MAAM,GAAA,GAAYA,4BAAW,eAAe,CAAA;AAC5C,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,+BAAA,CAAiC,CAAA;AACvE,EAAA,OAAO,GAAA;AACT,CAAA;AAUO,IAAM,QAAA,GAAiBA,gBAAA,CAAA,UAAA;AAAA,EAC5B,CAAC,EAAE,WAAA,GAAc,YAAA,EAAc,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAW,QAAA,EAAU,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AACpF,IAAA,MAAM,CAAC,WAAA,EAAa,GAAG,CAAA,GAAIC,iCAAA,CAAiB;AAAA,MAC1C,GAAG,IAAA;AAAA,MACH,IAAA,EAAM,WAAA,KAAgB,YAAA,GAAe,GAAA,GAAM;AAAA,KAC5C,CAAA;AACD,IAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,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,SAAA,EAAW,GAAG,KAAA,IAAS,GAAA,KAAQ;AAChC,IAAA,MAAM,EAAE,UAAA,EAAY,aAAA,EAAe,WAAA,EAAY,GAAI,YAAY,cAAc,CAAA;AAC7E,IAAA,uBACEE,cAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA,EAAK,QAAA;AAAA,QACL,YAAA,EAAW,YAAA;AAAA,QACX,UAAU,CAAC,aAAA;AAAA,QACX,OAAA,EAAS,UAAA;AAAA,QACT,SAAA,EAAWC,QAAA;AAAA,UACT,OAAA;AAAA,UACA,UAAA;AAAA,UACA,WAAA,KAAgB,eACZ,mCAAA,GACA,+CAAA;AAAA,UACJ;AAAA,SACF;AAAA,QACC,GAAG,KAAA;AAAA,QAEJ,QAAA,kBAAAD,cAAA,CAACG,sBAAA,EAAA,EAAW,SAAA,EAAU,SAAA,EAAU;AAAA;AAAA,KAClC;AAAA,EAEJ;AACF;AACA,YAAA,CAAa,WAAA,GAAc,cAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { ArrowLeft, ArrowRight } from \"lucide-react\";\nimport useEmblaCarousel from \"embla-carousel-react\";\nimport type { EmblaCarouselType, EmblaOptionsType } from \"embla-carousel\";\nimport { cn } from \"@nucleux/utils\";\n\ntype Orientation = \"horizontal\" | \"vertical\";\n\ninterface CarouselContextValue {\n carouselRef: ReturnType<typeof useEmblaCarousel>[0];\n api: EmblaCarouselType | undefined;\n orientation: Orientation;\n scrollPrev: () => void;\n scrollNext: () => void;\n canScrollPrev: boolean;\n canScrollNext: boolean;\n}\n\nconst CarouselContext = React.createContext<CarouselContextValue | null>(null);\nconst useCarousel = (component: string) => {\n const ctx = React.useContext(CarouselContext);\n if (!ctx) throw new Error(`${component} must be used within a Carousel`);\n return ctx;\n};\n\nexport interface CarouselProps extends React.HTMLAttributes<HTMLDivElement> {\n orientation?: Orientation;\n opts?: EmblaOptionsType;\n /** Receive the Embla API instance once ready. */\n setApi?: (api: EmblaCarouselType | undefined) => void;\n}\n\n/** A swipeable/keyboard-navigable carousel built on Embla. */\nexport const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(\n ({ orientation = \"horizontal\", opts, setApi, className, children, ...props }, ref) => {\n const [carouselRef, api] = useEmblaCarousel({\n ...opts,\n axis: orientation === \"horizontal\" ? \"x\" : \"y\",\n });\n const [canScrollPrev, setCanScrollPrev] = React.useState(false);\n const [canScrollNext, setCanScrollNext] = React.useState(false);\n\n const onSelect = React.useCallback((embla: EmblaCarouselType) => {\n setCanScrollPrev(embla.canScrollPrev());\n setCanScrollNext(embla.canScrollNext());\n }, []);\n\n const scrollPrev = React.useCallback(() => api?.scrollPrev(), [api]);\n const scrollNext = React.useCallback(() => api?.scrollNext(), [api]);\n\n React.useEffect(() => {\n if (!api) return;\n setApi?.(api);\n onSelect(api);\n api.on(\"reInit\", onSelect);\n api.on(\"select\", onSelect);\n return () => {\n api.off(\"reInit\", onSelect);\n api.off(\"select\", onSelect);\n };\n }, [api, setApi, onSelect]);\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n scrollPrev();\n } else if (e.key === \"ArrowRight\") {\n e.preventDefault();\n scrollNext();\n }\n };\n\n return (\n <CarouselContext.Provider\n value={{ carouselRef, api, orientation, scrollPrev, scrollNext, canScrollPrev, canScrollNext }}\n >\n <div\n ref={ref}\n role=\"region\"\n aria-roledescription=\"carousel\"\n onKeyDownCapture={handleKeyDown}\n className={cn(\"relative\", className)}\n {...props}\n >\n {children}\n </div>\n </CarouselContext.Provider>\n );\n },\n);\nCarousel.displayName = \"Carousel\";\n\nexport type CarouselContentProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** The scrolling viewport holding {@link CarouselItem}s. */\nexport const CarouselContent = React.forwardRef<HTMLDivElement, CarouselContentProps>(\n ({ className, ...props }, ref) => {\n const { carouselRef, orientation } = useCarousel(\"CarouselContent\");\n return (\n <div ref={carouselRef} className=\"overflow-hidden\">\n <div\n ref={ref}\n className={cn(\"flex\", orientation === \"horizontal\" ? \"-ml-4\" : \"-mt-4 flex-col\", className)}\n {...props}\n />\n </div>\n );\n },\n);\nCarouselContent.displayName = \"CarouselContent\";\n\nexport type CarouselItemProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** A single slide. */\nexport const CarouselItem = React.forwardRef<HTMLDivElement, CarouselItemProps>(\n ({ className, ...props }, ref) => {\n const { orientation } = useCarousel(\"CarouselItem\");\n return (\n <div\n ref={ref}\n role=\"group\"\n aria-roledescription=\"slide\"\n className={cn(\n \"min-w-0 shrink-0 grow-0 basis-full\",\n orientation === \"horizontal\" ? \"pl-4\" : \"pt-4\",\n className,\n )}\n {...props}\n />\n );\n },\n);\nCarouselItem.displayName = \"CarouselItem\";\n\nconst navBase =\n \"inline-flex h-8 w-8 items-center justify-center rounded-full border border-input bg-background text-foreground shadow-sm transition-colors hover:bg-accent disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\";\n\n/** Scrolls to the previous slide. */\nexport const CarouselPrevious = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>(\n ({ className, ...props }, ref) => {\n const { scrollPrev, canScrollPrev, orientation } = useCarousel(\"CarouselPrevious\");\n return (\n <button\n ref={ref}\n type=\"button\"\n aria-label=\"Previous slide\"\n disabled={!canScrollPrev}\n onClick={scrollPrev}\n className={cn(\n navBase,\n \"absolute\",\n orientation === \"horizontal\"\n ? \"-left-4 top-1/2 -translate-y-1/2\"\n : \"-top-4 left-1/2 -translate-x-1/2 rotate-90\",\n className,\n )}\n {...props}\n >\n <ArrowLeft className=\"h-4 w-4\" />\n </button>\n );\n },\n);\nCarouselPrevious.displayName = \"CarouselPrevious\";\n\n/** Scrolls to the next slide. */\nexport const CarouselNext = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>(\n ({ className, ...props }, ref) => {\n const { scrollNext, canScrollNext, orientation } = useCarousel(\"CarouselNext\");\n return (\n <button\n ref={ref}\n type=\"button\"\n aria-label=\"Next slide\"\n disabled={!canScrollNext}\n onClick={scrollNext}\n className={cn(\n navBase,\n \"absolute\",\n orientation === \"horizontal\"\n ? \"-right-4 top-1/2 -translate-y-1/2\"\n : \"-bottom-4 left-1/2 -translate-x-1/2 rotate-90\",\n className,\n )}\n {...props}\n >\n <ArrowRight className=\"h-4 w-4\" />\n </button>\n );\n },\n);\nCarouselNext.displayName = \"CarouselNext\";\n"]}
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ import { EmblaOptionsType, EmblaCarouselType } from 'embla-carousel';
3
+
4
+ type Orientation = "horizontal" | "vertical";
5
+ interface CarouselProps extends React.HTMLAttributes<HTMLDivElement> {
6
+ orientation?: Orientation;
7
+ opts?: EmblaOptionsType;
8
+ /** Receive the Embla API instance once ready. */
9
+ setApi?: (api: EmblaCarouselType | undefined) => void;
10
+ }
11
+ /** A swipeable/keyboard-navigable carousel built on Embla. */
12
+ declare const Carousel: React.ForwardRefExoticComponent<CarouselProps & React.RefAttributes<HTMLDivElement>>;
13
+ type CarouselContentProps = React.HTMLAttributes<HTMLDivElement>;
14
+ /** The scrolling viewport holding {@link CarouselItem}s. */
15
+ declare const CarouselContent: React.ForwardRefExoticComponent<CarouselContentProps & React.RefAttributes<HTMLDivElement>>;
16
+ type CarouselItemProps = React.HTMLAttributes<HTMLDivElement>;
17
+ /** A single slide. */
18
+ declare const CarouselItem: React.ForwardRefExoticComponent<CarouselItemProps & React.RefAttributes<HTMLDivElement>>;
19
+ /** Scrolls to the previous slide. */
20
+ declare const CarouselPrevious: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
21
+ /** Scrolls to the next slide. */
22
+ declare const CarouselNext: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
23
+
24
+ export { Carousel, CarouselContent, type CarouselContentProps, CarouselItem, type CarouselItemProps, CarouselNext, CarouselPrevious, type CarouselProps };
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ import { EmblaOptionsType, EmblaCarouselType } from 'embla-carousel';
3
+
4
+ type Orientation = "horizontal" | "vertical";
5
+ interface CarouselProps extends React.HTMLAttributes<HTMLDivElement> {
6
+ orientation?: Orientation;
7
+ opts?: EmblaOptionsType;
8
+ /** Receive the Embla API instance once ready. */
9
+ setApi?: (api: EmblaCarouselType | undefined) => void;
10
+ }
11
+ /** A swipeable/keyboard-navigable carousel built on Embla. */
12
+ declare const Carousel: React.ForwardRefExoticComponent<CarouselProps & React.RefAttributes<HTMLDivElement>>;
13
+ type CarouselContentProps = React.HTMLAttributes<HTMLDivElement>;
14
+ /** The scrolling viewport holding {@link CarouselItem}s. */
15
+ declare const CarouselContent: React.ForwardRefExoticComponent<CarouselContentProps & React.RefAttributes<HTMLDivElement>>;
16
+ type CarouselItemProps = React.HTMLAttributes<HTMLDivElement>;
17
+ /** A single slide. */
18
+ declare const CarouselItem: React.ForwardRefExoticComponent<CarouselItemProps & React.RefAttributes<HTMLDivElement>>;
19
+ /** Scrolls to the previous slide. */
20
+ declare const CarouselPrevious: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
21
+ /** Scrolls to the next slide. */
22
+ declare const CarouselNext: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
23
+
24
+ export { Carousel, CarouselContent, type CarouselContentProps, CarouselItem, type CarouselItemProps, CarouselNext, CarouselPrevious, type CarouselProps };
package/dist/index.js ADDED
@@ -0,0 +1,156 @@
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { ArrowLeft, ArrowRight } from 'lucide-react';
4
+ import useEmblaCarousel from 'embla-carousel-react';
5
+ import { cn } from '@nucleux/utils';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ // src/index.tsx
9
+ var CarouselContext = React.createContext(null);
10
+ var useCarousel = (component) => {
11
+ const ctx = React.useContext(CarouselContext);
12
+ if (!ctx) throw new Error(`${component} must be used within a Carousel`);
13
+ return ctx;
14
+ };
15
+ var Carousel = React.forwardRef(
16
+ ({ orientation = "horizontal", opts, setApi, className, children, ...props }, ref) => {
17
+ const [carouselRef, api] = useEmblaCarousel({
18
+ ...opts,
19
+ axis: orientation === "horizontal" ? "x" : "y"
20
+ });
21
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false);
22
+ const [canScrollNext, setCanScrollNext] = React.useState(false);
23
+ const onSelect = React.useCallback((embla) => {
24
+ setCanScrollPrev(embla.canScrollPrev());
25
+ setCanScrollNext(embla.canScrollNext());
26
+ }, []);
27
+ const scrollPrev = React.useCallback(() => api?.scrollPrev(), [api]);
28
+ const scrollNext = React.useCallback(() => api?.scrollNext(), [api]);
29
+ React.useEffect(() => {
30
+ if (!api) return;
31
+ setApi?.(api);
32
+ onSelect(api);
33
+ api.on("reInit", onSelect);
34
+ api.on("select", onSelect);
35
+ return () => {
36
+ api.off("reInit", onSelect);
37
+ api.off("select", onSelect);
38
+ };
39
+ }, [api, setApi, onSelect]);
40
+ const handleKeyDown = (e) => {
41
+ if (e.key === "ArrowLeft") {
42
+ e.preventDefault();
43
+ scrollPrev();
44
+ } else if (e.key === "ArrowRight") {
45
+ e.preventDefault();
46
+ scrollNext();
47
+ }
48
+ };
49
+ return /* @__PURE__ */ jsx(
50
+ CarouselContext.Provider,
51
+ {
52
+ value: { carouselRef, api, orientation, scrollPrev, scrollNext, canScrollPrev, canScrollNext },
53
+ children: /* @__PURE__ */ jsx(
54
+ "div",
55
+ {
56
+ ref,
57
+ role: "region",
58
+ "aria-roledescription": "carousel",
59
+ onKeyDownCapture: handleKeyDown,
60
+ className: cn("relative", className),
61
+ ...props,
62
+ children
63
+ }
64
+ )
65
+ }
66
+ );
67
+ }
68
+ );
69
+ Carousel.displayName = "Carousel";
70
+ var CarouselContent = React.forwardRef(
71
+ ({ className, ...props }, ref) => {
72
+ const { carouselRef, orientation } = useCarousel("CarouselContent");
73
+ return /* @__PURE__ */ jsx("div", { ref: carouselRef, className: "overflow-hidden", children: /* @__PURE__ */ jsx(
74
+ "div",
75
+ {
76
+ ref,
77
+ className: cn("flex", orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col", className),
78
+ ...props
79
+ }
80
+ ) });
81
+ }
82
+ );
83
+ CarouselContent.displayName = "CarouselContent";
84
+ var CarouselItem = React.forwardRef(
85
+ ({ className, ...props }, ref) => {
86
+ const { orientation } = useCarousel("CarouselItem");
87
+ return /* @__PURE__ */ jsx(
88
+ "div",
89
+ {
90
+ ref,
91
+ role: "group",
92
+ "aria-roledescription": "slide",
93
+ className: cn(
94
+ "min-w-0 shrink-0 grow-0 basis-full",
95
+ orientation === "horizontal" ? "pl-4" : "pt-4",
96
+ className
97
+ ),
98
+ ...props
99
+ }
100
+ );
101
+ }
102
+ );
103
+ CarouselItem.displayName = "CarouselItem";
104
+ var navBase = "inline-flex h-8 w-8 items-center justify-center rounded-full border border-input bg-background text-foreground shadow-sm transition-colors hover:bg-accent disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
105
+ var CarouselPrevious = React.forwardRef(
106
+ ({ className, ...props }, ref) => {
107
+ const { scrollPrev, canScrollPrev, orientation } = useCarousel("CarouselPrevious");
108
+ return /* @__PURE__ */ jsx(
109
+ "button",
110
+ {
111
+ ref,
112
+ type: "button",
113
+ "aria-label": "Previous slide",
114
+ disabled: !canScrollPrev,
115
+ onClick: scrollPrev,
116
+ className: cn(
117
+ navBase,
118
+ "absolute",
119
+ orientation === "horizontal" ? "-left-4 top-1/2 -translate-y-1/2" : "-top-4 left-1/2 -translate-x-1/2 rotate-90",
120
+ className
121
+ ),
122
+ ...props,
123
+ children: /* @__PURE__ */ jsx(ArrowLeft, { className: "h-4 w-4" })
124
+ }
125
+ );
126
+ }
127
+ );
128
+ CarouselPrevious.displayName = "CarouselPrevious";
129
+ var CarouselNext = React.forwardRef(
130
+ ({ className, ...props }, ref) => {
131
+ const { scrollNext, canScrollNext, orientation } = useCarousel("CarouselNext");
132
+ return /* @__PURE__ */ jsx(
133
+ "button",
134
+ {
135
+ ref,
136
+ type: "button",
137
+ "aria-label": "Next slide",
138
+ disabled: !canScrollNext,
139
+ onClick: scrollNext,
140
+ className: cn(
141
+ navBase,
142
+ "absolute",
143
+ orientation === "horizontal" ? "-right-4 top-1/2 -translate-y-1/2" : "-bottom-4 left-1/2 -translate-x-1/2 rotate-90",
144
+ className
145
+ ),
146
+ ...props,
147
+ children: /* @__PURE__ */ jsx(ArrowRight, { className: "h-4 w-4" })
148
+ }
149
+ );
150
+ }
151
+ );
152
+ CarouselNext.displayName = "CarouselNext";
153
+
154
+ export { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious };
155
+ //# sourceMappingURL=index.js.map
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;AAkBA,IAAM,eAAA,GAAwB,oBAA2C,IAAI,CAAA;AAC7E,IAAM,WAAA,GAAc,CAAC,SAAA,KAAsB;AACzC,EAAA,MAAM,GAAA,GAAY,iBAAW,eAAe,CAAA;AAC5C,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,+BAAA,CAAiC,CAAA;AACvE,EAAA,OAAO,GAAA;AACT,CAAA;AAUO,IAAM,QAAA,GAAiB,KAAA,CAAA,UAAA;AAAA,EAC5B,CAAC,EAAE,WAAA,GAAc,YAAA,EAAc,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAW,QAAA,EAAU,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AACpF,IAAA,MAAM,CAAC,WAAA,EAAa,GAAG,CAAA,GAAI,gBAAA,CAAiB;AAAA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;AACF;AACA,gBAAA,CAAiB,WAAA,GAAc,kBAAA;AAGxB,IAAM,YAAA,GAAqB,KAAA,CAAA,UAAA;AAAA,EAChC,CAAC,EAAE,SAAA,EAAW,GAAG,KAAA,IAAS,GAAA,KAAQ;AAChC,IAAA,MAAM,EAAE,UAAA,EAAY,aAAA,EAAe,WAAA,EAAY,GAAI,YAAY,cAAc,CAAA;AAC7E,IAAA,uBACE,GAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA,EAAK,QAAA;AAAA,QACL,YAAA,EAAW,YAAA;AAAA,QACX,UAAU,CAAC,aAAA;AAAA,QACX,OAAA,EAAS,UAAA;AAAA,QACT,SAAA,EAAW,EAAA;AAAA,UACT,OAAA;AAAA,UACA,UAAA;AAAA,UACA,WAAA,KAAgB,eACZ,mCAAA,GACA,+CAAA;AAAA,UACJ;AAAA,SACF;AAAA,QACC,GAAG,KAAA;AAAA,QAEJ,QAAA,kBAAA,GAAA,CAAC,UAAA,EAAA,EAAW,SAAA,EAAU,SAAA,EAAU;AAAA;AAAA,KAClC;AAAA,EAEJ;AACF;AACA,YAAA,CAAa,WAAA,GAAc,cAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { ArrowLeft, ArrowRight } from \"lucide-react\";\nimport useEmblaCarousel from \"embla-carousel-react\";\nimport type { EmblaCarouselType, EmblaOptionsType } from \"embla-carousel\";\nimport { cn } from \"@nucleux/utils\";\n\ntype Orientation = \"horizontal\" | \"vertical\";\n\ninterface CarouselContextValue {\n carouselRef: ReturnType<typeof useEmblaCarousel>[0];\n api: EmblaCarouselType | undefined;\n orientation: Orientation;\n scrollPrev: () => void;\n scrollNext: () => void;\n canScrollPrev: boolean;\n canScrollNext: boolean;\n}\n\nconst CarouselContext = React.createContext<CarouselContextValue | null>(null);\nconst useCarousel = (component: string) => {\n const ctx = React.useContext(CarouselContext);\n if (!ctx) throw new Error(`${component} must be used within a Carousel`);\n return ctx;\n};\n\nexport interface CarouselProps extends React.HTMLAttributes<HTMLDivElement> {\n orientation?: Orientation;\n opts?: EmblaOptionsType;\n /** Receive the Embla API instance once ready. */\n setApi?: (api: EmblaCarouselType | undefined) => void;\n}\n\n/** A swipeable/keyboard-navigable carousel built on Embla. */\nexport const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(\n ({ orientation = \"horizontal\", opts, setApi, className, children, ...props }, ref) => {\n const [carouselRef, api] = useEmblaCarousel({\n ...opts,\n axis: orientation === \"horizontal\" ? \"x\" : \"y\",\n });\n const [canScrollPrev, setCanScrollPrev] = React.useState(false);\n const [canScrollNext, setCanScrollNext] = React.useState(false);\n\n const onSelect = React.useCallback((embla: EmblaCarouselType) => {\n setCanScrollPrev(embla.canScrollPrev());\n setCanScrollNext(embla.canScrollNext());\n }, []);\n\n const scrollPrev = React.useCallback(() => api?.scrollPrev(), [api]);\n const scrollNext = React.useCallback(() => api?.scrollNext(), [api]);\n\n React.useEffect(() => {\n if (!api) return;\n setApi?.(api);\n onSelect(api);\n api.on(\"reInit\", onSelect);\n api.on(\"select\", onSelect);\n return () => {\n api.off(\"reInit\", onSelect);\n api.off(\"select\", onSelect);\n };\n }, [api, setApi, onSelect]);\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n scrollPrev();\n } else if (e.key === \"ArrowRight\") {\n e.preventDefault();\n scrollNext();\n }\n };\n\n return (\n <CarouselContext.Provider\n value={{ carouselRef, api, orientation, scrollPrev, scrollNext, canScrollPrev, canScrollNext }}\n >\n <div\n ref={ref}\n role=\"region\"\n aria-roledescription=\"carousel\"\n onKeyDownCapture={handleKeyDown}\n className={cn(\"relative\", className)}\n {...props}\n >\n {children}\n </div>\n </CarouselContext.Provider>\n );\n },\n);\nCarousel.displayName = \"Carousel\";\n\nexport type CarouselContentProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** The scrolling viewport holding {@link CarouselItem}s. */\nexport const CarouselContent = React.forwardRef<HTMLDivElement, CarouselContentProps>(\n ({ className, ...props }, ref) => {\n const { carouselRef, orientation } = useCarousel(\"CarouselContent\");\n return (\n <div ref={carouselRef} className=\"overflow-hidden\">\n <div\n ref={ref}\n className={cn(\"flex\", orientation === \"horizontal\" ? \"-ml-4\" : \"-mt-4 flex-col\", className)}\n {...props}\n />\n </div>\n );\n },\n);\nCarouselContent.displayName = \"CarouselContent\";\n\nexport type CarouselItemProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** A single slide. */\nexport const CarouselItem = React.forwardRef<HTMLDivElement, CarouselItemProps>(\n ({ className, ...props }, ref) => {\n const { orientation } = useCarousel(\"CarouselItem\");\n return (\n <div\n ref={ref}\n role=\"group\"\n aria-roledescription=\"slide\"\n className={cn(\n \"min-w-0 shrink-0 grow-0 basis-full\",\n orientation === \"horizontal\" ? \"pl-4\" : \"pt-4\",\n className,\n )}\n {...props}\n />\n );\n },\n);\nCarouselItem.displayName = \"CarouselItem\";\n\nconst navBase =\n \"inline-flex h-8 w-8 items-center justify-center rounded-full border border-input bg-background text-foreground shadow-sm transition-colors hover:bg-accent disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\";\n\n/** Scrolls to the previous slide. */\nexport const CarouselPrevious = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>(\n ({ className, ...props }, ref) => {\n const { scrollPrev, canScrollPrev, orientation } = useCarousel(\"CarouselPrevious\");\n return (\n <button\n ref={ref}\n type=\"button\"\n aria-label=\"Previous slide\"\n disabled={!canScrollPrev}\n onClick={scrollPrev}\n className={cn(\n navBase,\n \"absolute\",\n orientation === \"horizontal\"\n ? \"-left-4 top-1/2 -translate-y-1/2\"\n : \"-top-4 left-1/2 -translate-x-1/2 rotate-90\",\n className,\n )}\n {...props}\n >\n <ArrowLeft className=\"h-4 w-4\" />\n </button>\n );\n },\n);\nCarouselPrevious.displayName = \"CarouselPrevious\";\n\n/** Scrolls to the next slide. */\nexport const CarouselNext = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>(\n ({ className, ...props }, ref) => {\n const { scrollNext, canScrollNext, orientation } = useCarousel(\"CarouselNext\");\n return (\n <button\n ref={ref}\n type=\"button\"\n aria-label=\"Next slide\"\n disabled={!canScrollNext}\n onClick={scrollNext}\n className={cn(\n navBase,\n \"absolute\",\n orientation === \"horizontal\"\n ? \"-right-4 top-1/2 -translate-y-1/2\"\n : \"-bottom-4 left-1/2 -translate-x-1/2 rotate-90\",\n className,\n )}\n {...props}\n >\n <ArrowRight className=\"h-4 w-4\" />\n </button>\n );\n },\n);\nCarouselNext.displayName = \"CarouselNext\";\n"]}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@nucleux/carousel",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "description": "Swipeable content carousel — Nucleux agentic UI for React.",
7
+ "keywords": [
8
+ "nucleux",
9
+ "react",
10
+ "ui",
11
+ "components",
12
+ "agentic",
13
+ "ai",
14
+ "tailwind",
15
+ "carousel"
16
+ ],
17
+ "main": "./dist/index.cjs",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md"
30
+ ],
31
+ "peerDependencies": {
32
+ "react": ">=18",
33
+ "react-dom": ">=18"
34
+ },
35
+ "dependencies": {
36
+ "lucide-react": "^0.469.0",
37
+ "embla-carousel-react": "^8.5.1",
38
+ "embla-carousel": "^8.5.1",
39
+ "@nucleux/utils": "0.2.0"
40
+ },
41
+ "devDependencies": {
42
+ "tsup": "^8.3.5",
43
+ "typescript": "^5.7.2",
44
+ "@types/react": "^18.3.18",
45
+ "react": "^18.3.1"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "license": "MIT",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
54
+ "directory": "packages/carousel"
55
+ },
56
+ "homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
57
+ "scripts": {
58
+ "build": "tsup"
59
+ }
60
+ }