@dgshahr/ui-kit 0.0.4 → 0.0.5

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.
@@ -0,0 +1,215 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { c as clsx } from './clsx-ChV9xqsO.js';
3
+ import { createContext, useContext, useState, useEffect, useRef, Children } from 'react';
4
+ import { A as ArrowLeft2Icon } from './ArrowLeft2-BURhvXT2.js';
5
+ import { A as ArrowRight2Icon } from './ArrowRight2-DCxJPvNC.js';
6
+ import Button from './Button/index.js';
7
+
8
+ const sliderContext = createContext({
9
+ slidesPerView: 1,
10
+ spaceBetween: 0
11
+ });
12
+ const useSliderContext = () => useContext(sliderContext);
13
+
14
+ function styleNavigationDot({ active, autoplay, variant }) {
15
+ const variantClassName = {
16
+ inside: "bg-gray-500/50 hover:bg-gray-500/80",
17
+ outside: "bg-gray-200 hover:bg-gray-300"
18
+ };
19
+ return [variantClassName[variant], active ? "w-[22px]" : "w-[6px]", autoplay ? "p-[1px]" : ""];
20
+ }
21
+ const NavigationDot = (props) => {
22
+ const { active, autoplay, variant, onClick, onNavigateToNext } = props;
23
+ const [fillPercentage, setFillPercentage] = useState(0);
24
+ useEffect(() => {
25
+ if (!active || !autoplay) return;
26
+ const autoplayTime = typeof autoplay === "boolean" ? 7e3 : autoplay?.delay ?? 7e3;
27
+ let startTime = Date.now();
28
+ const autoplayInterval = setInterval(() => {
29
+ const elapsed = Date.now() - startTime;
30
+ const percentage = elapsed / autoplayTime * 100;
31
+ setFillPercentage(Math.min(percentage, 100));
32
+ if (elapsed >= autoplayTime && typeof onNavigateToNext === "function") {
33
+ onNavigateToNext();
34
+ }
35
+ }, 100);
36
+ return function cleanup() {
37
+ setFillPercentage(0);
38
+ startTime = Date.now();
39
+ return clearInterval(autoplayInterval);
40
+ };
41
+ }, [active, autoplay, onNavigateToNext]);
42
+ return /* @__PURE__ */ jsx(
43
+ "button",
44
+ {
45
+ className: clsx(
46
+ "rounded-full overflow-hidden transition-all h-[6px]",
47
+ styleNavigationDot({ active, autoplay, variant })
48
+ ),
49
+ onClick,
50
+ children: active && /* @__PURE__ */ jsx(
51
+ "div",
52
+ {
53
+ className: clsx("h-full rounded-full", {
54
+ "bg-white": variant === "inside",
55
+ "bg-gray-700": variant === "outside"
56
+ }),
57
+ style: { width: autoplay ? `${fillPercentage}%` : "100%" }
58
+ }
59
+ )
60
+ }
61
+ );
62
+ };
63
+
64
+ const Slider = (props) => {
65
+ const {
66
+ className = "",
67
+ containerClassName = "",
68
+ showNavigationDots = true,
69
+ dotsClassName = "",
70
+ slidesPerView = 1,
71
+ autoplay,
72
+ navigationButtonsShowType = "hide",
73
+ spaceBetween = 0,
74
+ navigationVariant = "outside",
75
+ showPaginationText = false
76
+ } = props;
77
+ const [slideIndex, setSlideIndex] = useState(0);
78
+ const containerRef = useRef(null);
79
+ const childsCount = Children.count(props.children);
80
+ const slidesCount = Math.ceil(childsCount / slidesPerView);
81
+ const haveNavigation = showNavigationDots || navigationButtonsShowType && navigationButtonsShowType !== "hide" || showPaginationText;
82
+ function detectCarouselPosition(e) {
83
+ const itemsWidth = e.currentTarget.scrollWidth / slidesCount;
84
+ const position = (e.currentTarget.scrollWidth - e.currentTarget.scrollLeft) / itemsWidth;
85
+ setSlideIndex(Math.round(position % slidesCount));
86
+ }
87
+ function navigate(target) {
88
+ if (!containerRef.current) return;
89
+ const slideWidth = containerRef.current.offsetWidth;
90
+ let nextSlideScroll = -(slideWidth * target);
91
+ if (target < 0) nextSlideScroll = -(slideWidth * slidesCount);
92
+ else if (target >= slidesCount) nextSlideScroll = 0;
93
+ containerRef.current.scrollTo({
94
+ left: nextSlideScroll,
95
+ behavior: "smooth"
96
+ });
97
+ }
98
+ return /* @__PURE__ */ jsxs(
99
+ "div",
100
+ {
101
+ className: clsx("overflow-hidden relative group", className),
102
+ style: { direction: "rtl" },
103
+ children: [
104
+ /* @__PURE__ */ jsx(
105
+ "div",
106
+ {
107
+ className: clsx(
108
+ "flex snap-x snap-mandatory overflow-x-auto no-scrollbar",
109
+ containerClassName
110
+ ),
111
+ style: { marginLeft: -spaceBetween },
112
+ onScroll: detectCarouselPosition,
113
+ ref: containerRef,
114
+ children: /* @__PURE__ */ jsx(sliderContext.Provider, { value: { slidesPerView, spaceBetween }, children: props.children })
115
+ }
116
+ ),
117
+ haveNavigation && /* @__PURE__ */ jsxs(
118
+ "div",
119
+ {
120
+ className: clsx("flex", {
121
+ "items-center mt-2": navigationVariant === "outside",
122
+ "absolute bottom-4 w-full justify-center": navigationVariant === "inside",
123
+ "justify-between": navigationVariant === "outside" && navigationButtonsShowType !== "hide",
124
+ "justify-center": navigationVariant === "outside" && navigationButtonsShowType === "hide"
125
+ }),
126
+ children: [
127
+ navigationButtonsShowType && navigationButtonsShowType !== "hide" && /* @__PURE__ */ jsxs(
128
+ "div",
129
+ {
130
+ className: clsx("flex gap-2", {
131
+ "absolute bottom-0 left-[5.5%]": navigationVariant === "inside",
132
+ "opacity-0 group-hover:opacity-100 transition": navigationButtonsShowType === "hover"
133
+ }),
134
+ children: [
135
+ /* @__PURE__ */ jsx(
136
+ Button,
137
+ {
138
+ type: "button",
139
+ variant: "secondary",
140
+ onClick: () => navigate(slideIndex - 1),
141
+ rightIcon: /* @__PURE__ */ jsx(ArrowRight2Icon, {})
142
+ }
143
+ ),
144
+ /* @__PURE__ */ jsx(
145
+ Button,
146
+ {
147
+ type: "button",
148
+ variant: "secondary",
149
+ onClick: () => navigate(slideIndex + 1),
150
+ rightIcon: /* @__PURE__ */ jsx(ArrowLeft2Icon, {})
151
+ }
152
+ )
153
+ ]
154
+ }
155
+ ),
156
+ (showNavigationDots || showPaginationText) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
157
+ showPaginationText && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 font-caption-regular text-gray-400 ss02", children: [
158
+ /* @__PURE__ */ jsx(
159
+ "span",
160
+ {
161
+ className: clsx("font-bold", {
162
+ "text-gray-600": navigationVariant === "outside",
163
+ "text-white": navigationVariant === "inside"
164
+ }),
165
+ children: slideIndex + 1
166
+ }
167
+ ),
168
+ /* @__PURE__ */ jsx("span", { children: "از" }),
169
+ /* @__PURE__ */ jsx("span", { children: slidesCount })
170
+ ] }),
171
+ showNavigationDots && /* @__PURE__ */ jsx("div", { className: clsx("flex items-center justify-center gap-2", dotsClassName), children: Array.from(Array(slidesCount).keys()).map((item, index) => /* @__PURE__ */ jsx(
172
+ NavigationDot,
173
+ {
174
+ active: slideIndex === index,
175
+ autoplay: autoplay ?? false,
176
+ variant: navigationVariant,
177
+ onClick: () => navigate(index),
178
+ onNavigateToNext: () => navigate(slideIndex + 1)
179
+ },
180
+ item + slidesCount
181
+ )) })
182
+ ] })
183
+ ]
184
+ }
185
+ )
186
+ ]
187
+ }
188
+ );
189
+ };
190
+
191
+ const Slide = (props) => {
192
+ const { children, className } = props;
193
+ const { slidesPerView, spaceBetween } = useSliderContext();
194
+ const ref = useRef(null);
195
+ const [childIndex, setChildIndex] = useState(0);
196
+ useEffect(() => {
197
+ if (!ref.current) return;
198
+ setChildIndex(Array.prototype.indexOf.call(ref.current.parentNode?.children, ref.current));
199
+ }, [ref]);
200
+ return /* @__PURE__ */ jsx(
201
+ "div",
202
+ {
203
+ ref,
204
+ className: clsx("shrink-0 snap-always", className),
205
+ style: {
206
+ width: 100 / (slidesPerView ?? 1) + "%",
207
+ paddingLeft: spaceBetween,
208
+ scrollSnapAlign: childIndex % slidesPerView === 0 ? "start" : "none"
209
+ },
210
+ children
211
+ }
212
+ );
213
+ };
214
+
215
+ export { Slider as S, Slide as a };
@@ -0,0 +1,218 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const clsx = require('./clsx-BtxeOLZW.cjs');
5
+ const react = require('react');
6
+ const ArrowLeft2 = require('./ArrowLeft2-iZ0Au6Fn.cjs');
7
+ const ArrowRight2 = require('./ArrowRight2-DTuru_sP.cjs');
8
+ const Button = require('./Button/index.cjs');
9
+
10
+ const sliderContext = react.createContext({
11
+ slidesPerView: 1,
12
+ spaceBetween: 0
13
+ });
14
+ const useSliderContext = () => react.useContext(sliderContext);
15
+
16
+ function styleNavigationDot({ active, autoplay, variant }) {
17
+ const variantClassName = {
18
+ inside: "bg-gray-500/50 hover:bg-gray-500/80",
19
+ outside: "bg-gray-200 hover:bg-gray-300"
20
+ };
21
+ return [variantClassName[variant], active ? "w-[22px]" : "w-[6px]", autoplay ? "p-[1px]" : ""];
22
+ }
23
+ const NavigationDot = (props) => {
24
+ const { active, autoplay, variant, onClick, onNavigateToNext } = props;
25
+ const [fillPercentage, setFillPercentage] = react.useState(0);
26
+ react.useEffect(() => {
27
+ if (!active || !autoplay) return;
28
+ const autoplayTime = typeof autoplay === "boolean" ? 7e3 : autoplay?.delay ?? 7e3;
29
+ let startTime = Date.now();
30
+ const autoplayInterval = setInterval(() => {
31
+ const elapsed = Date.now() - startTime;
32
+ const percentage = elapsed / autoplayTime * 100;
33
+ setFillPercentage(Math.min(percentage, 100));
34
+ if (elapsed >= autoplayTime && typeof onNavigateToNext === "function") {
35
+ onNavigateToNext();
36
+ }
37
+ }, 100);
38
+ return function cleanup() {
39
+ setFillPercentage(0);
40
+ startTime = Date.now();
41
+ return clearInterval(autoplayInterval);
42
+ };
43
+ }, [active, autoplay, onNavigateToNext]);
44
+ return /* @__PURE__ */ jsxRuntime.jsx(
45
+ "button",
46
+ {
47
+ className: clsx.clsx(
48
+ "rounded-full overflow-hidden transition-all h-[6px]",
49
+ styleNavigationDot({ active, autoplay, variant })
50
+ ),
51
+ onClick,
52
+ children: active && /* @__PURE__ */ jsxRuntime.jsx(
53
+ "div",
54
+ {
55
+ className: clsx.clsx("h-full rounded-full", {
56
+ "bg-white": variant === "inside",
57
+ "bg-gray-700": variant === "outside"
58
+ }),
59
+ style: { width: autoplay ? `${fillPercentage}%` : "100%" }
60
+ }
61
+ )
62
+ }
63
+ );
64
+ };
65
+
66
+ const Slider = (props) => {
67
+ const {
68
+ className = "",
69
+ containerClassName = "",
70
+ showNavigationDots = true,
71
+ dotsClassName = "",
72
+ slidesPerView = 1,
73
+ autoplay,
74
+ navigationButtonsShowType = "hide",
75
+ spaceBetween = 0,
76
+ navigationVariant = "outside",
77
+ showPaginationText = false
78
+ } = props;
79
+ const [slideIndex, setSlideIndex] = react.useState(0);
80
+ const containerRef = react.useRef(null);
81
+ const childsCount = react.Children.count(props.children);
82
+ const slidesCount = Math.ceil(childsCount / slidesPerView);
83
+ const haveNavigation = showNavigationDots || navigationButtonsShowType && navigationButtonsShowType !== "hide" || showPaginationText;
84
+ function detectCarouselPosition(e) {
85
+ const itemsWidth = e.currentTarget.scrollWidth / slidesCount;
86
+ const position = (e.currentTarget.scrollWidth - e.currentTarget.scrollLeft) / itemsWidth;
87
+ setSlideIndex(Math.round(position % slidesCount));
88
+ }
89
+ function navigate(target) {
90
+ if (!containerRef.current) return;
91
+ const slideWidth = containerRef.current.offsetWidth;
92
+ let nextSlideScroll = -(slideWidth * target);
93
+ if (target < 0) nextSlideScroll = -(slideWidth * slidesCount);
94
+ else if (target >= slidesCount) nextSlideScroll = 0;
95
+ containerRef.current.scrollTo({
96
+ left: nextSlideScroll,
97
+ behavior: "smooth"
98
+ });
99
+ }
100
+ return /* @__PURE__ */ jsxRuntime.jsxs(
101
+ "div",
102
+ {
103
+ className: clsx.clsx("overflow-hidden relative group", className),
104
+ style: { direction: "rtl" },
105
+ children: [
106
+ /* @__PURE__ */ jsxRuntime.jsx(
107
+ "div",
108
+ {
109
+ className: clsx.clsx(
110
+ "flex snap-x snap-mandatory overflow-x-auto no-scrollbar",
111
+ containerClassName
112
+ ),
113
+ style: { marginLeft: -spaceBetween },
114
+ onScroll: detectCarouselPosition,
115
+ ref: containerRef,
116
+ children: /* @__PURE__ */ jsxRuntime.jsx(sliderContext.Provider, { value: { slidesPerView, spaceBetween }, children: props.children })
117
+ }
118
+ ),
119
+ haveNavigation && /* @__PURE__ */ jsxRuntime.jsxs(
120
+ "div",
121
+ {
122
+ className: clsx.clsx("flex", {
123
+ "items-center mt-2": navigationVariant === "outside",
124
+ "absolute bottom-4 w-full justify-center": navigationVariant === "inside",
125
+ "justify-between": navigationVariant === "outside" && navigationButtonsShowType !== "hide",
126
+ "justify-center": navigationVariant === "outside" && navigationButtonsShowType === "hide"
127
+ }),
128
+ children: [
129
+ navigationButtonsShowType && navigationButtonsShowType !== "hide" && /* @__PURE__ */ jsxRuntime.jsxs(
130
+ "div",
131
+ {
132
+ className: clsx.clsx("flex gap-2", {
133
+ "absolute bottom-0 left-[5.5%]": navigationVariant === "inside",
134
+ "opacity-0 group-hover:opacity-100 transition": navigationButtonsShowType === "hover"
135
+ }),
136
+ children: [
137
+ /* @__PURE__ */ jsxRuntime.jsx(
138
+ Button,
139
+ {
140
+ type: "button",
141
+ variant: "secondary",
142
+ onClick: () => navigate(slideIndex - 1),
143
+ rightIcon: /* @__PURE__ */ jsxRuntime.jsx(ArrowRight2.ArrowRight2Icon, {})
144
+ }
145
+ ),
146
+ /* @__PURE__ */ jsxRuntime.jsx(
147
+ Button,
148
+ {
149
+ type: "button",
150
+ variant: "secondary",
151
+ onClick: () => navigate(slideIndex + 1),
152
+ rightIcon: /* @__PURE__ */ jsxRuntime.jsx(ArrowLeft2.ArrowLeft2Icon, {})
153
+ }
154
+ )
155
+ ]
156
+ }
157
+ ),
158
+ (showNavigationDots || showPaginationText) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
159
+ showPaginationText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 font-caption-regular text-gray-400 ss02", children: [
160
+ /* @__PURE__ */ jsxRuntime.jsx(
161
+ "span",
162
+ {
163
+ className: clsx.clsx("font-bold", {
164
+ "text-gray-600": navigationVariant === "outside",
165
+ "text-white": navigationVariant === "inside"
166
+ }),
167
+ children: slideIndex + 1
168
+ }
169
+ ),
170
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "از" }),
171
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: slidesCount })
172
+ ] }),
173
+ showNavigationDots && /* @__PURE__ */ jsxRuntime.jsx("div", { className: clsx.clsx("flex items-center justify-center gap-2", dotsClassName), children: Array.from(Array(slidesCount).keys()).map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
174
+ NavigationDot,
175
+ {
176
+ active: slideIndex === index,
177
+ autoplay: autoplay ?? false,
178
+ variant: navigationVariant,
179
+ onClick: () => navigate(index),
180
+ onNavigateToNext: () => navigate(slideIndex + 1)
181
+ },
182
+ item + slidesCount
183
+ )) })
184
+ ] })
185
+ ]
186
+ }
187
+ )
188
+ ]
189
+ }
190
+ );
191
+ };
192
+
193
+ const Slide = (props) => {
194
+ const { children, className } = props;
195
+ const { slidesPerView, spaceBetween } = useSliderContext();
196
+ const ref = react.useRef(null);
197
+ const [childIndex, setChildIndex] = react.useState(0);
198
+ react.useEffect(() => {
199
+ if (!ref.current) return;
200
+ setChildIndex(Array.prototype.indexOf.call(ref.current.parentNode?.children, ref.current));
201
+ }, [ref]);
202
+ return /* @__PURE__ */ jsxRuntime.jsx(
203
+ "div",
204
+ {
205
+ ref,
206
+ className: clsx.clsx("shrink-0 snap-always", className),
207
+ style: {
208
+ width: 100 / (slidesPerView ?? 1) + "%",
209
+ paddingLeft: spaceBetween,
210
+ scrollSnapAlign: childIndex % slidesPerView === 0 ? "start" : "none"
211
+ },
212
+ children
213
+ }
214
+ );
215
+ };
216
+
217
+ exports.Slide = Slide;
218
+ exports.Slider = Slider;
@@ -1 +1 @@
1
- {"version":3,"file":"Slide.d.ts","sourceRoot":"","sources":["../../src/components/Slider/Slide.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAGnD,UAAU,UAAU;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,QAAA,MAAM,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAe5C,CAAC;AAEF,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"Slide.d.ts","sourceRoot":"","sources":["../../src/components/Slider/Slide.tsx"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAGrF,UAAU,UAAU;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,QAAA,MAAM,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAwB5C,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../src/components/Slider/Slider.tsx"],"names":[],"mappings":"AACA,OAAO,EAA8B,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAgB,MAAM,OAAO,CAAC;AAOlG,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EACL,OAAO,GACP;QACE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;IACN,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,UAAU,2BAA4B,SAAQ,eAAe;IAC3D,iBAAiB,CAAC,EAAE,QAAQ,CAAC;IAC7B,yBAAyB,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,CAAC;CAC5D;AACD,UAAU,4BAA6B,SAAQ,eAAe;IAC5D,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,yBAAyB,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAClD;AAED,MAAM,MAAM,WAAW,GAAG,2BAA2B,GAAG,4BAA4B,CAAC;AAErF,QAAA,MAAM,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CA2H9C,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../src/components/Slider/Slider.tsx"],"names":[],"mappings":"AACA,OAAO,EAA8B,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAgB,MAAM,OAAO,CAAC;AAOlG,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EACL,OAAO,GACP;QACE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;IACN,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,UAAU,2BAA4B,SAAQ,eAAe;IAC3D,iBAAiB,CAAC,EAAE,QAAQ,CAAC;IAC7B,yBAAyB,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,CAAC;CAC5D;AACD,UAAU,4BAA6B,SAAQ,eAAe;IAC5D,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,yBAAyB,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAClD;AAED,MAAM,MAAM,WAAW,GAAG,2BAA2B,GAAG,4BAA4B,CAAC;AAErF,QAAA,MAAM,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAkI9C,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  require('../assets/styles.css');;/* empty css */
6
- const Slide = require('../Slide-JxJDSGwS.cjs');
6
+ const Slide = require('../Slide-Q5_7SCZR.cjs');
7
7
 
8
8
 
9
9
 
@@ -1,2 +1,2 @@
1
1
  import '../assets/styles.css';/* empty css */
2
- export { a as Slide, S as Slider } from '../Slide-B4sbGo5D.js';
2
+ export { a as Slide, S as Slider } from '../Slide-BDD1_RXD.js';
@@ -629,6 +629,9 @@ video {
629
629
  .h-\[1px\] {
630
630
  height: 1px;
631
631
  }
632
+ .h-\[200px\] {
633
+ height: 200px;
634
+ }
632
635
  .h-\[6px\] {
633
636
  height: 6px;
634
637
  }
@@ -669,6 +672,9 @@ video {
669
672
  .w-\[22px\] {
670
673
  width: 22px;
671
674
  }
675
+ .w-\[400px\] {
676
+ width: 400px;
677
+ }
672
678
  .w-\[6px\] {
673
679
  width: 6px;
674
680
  }
@@ -717,6 +723,9 @@ video {
717
723
  .snap-mandatory {
718
724
  --tw-scroll-snap-strictness: mandatory;
719
725
  }
726
+ .snap-always {
727
+ scroll-snap-stop: always;
728
+ }
720
729
  .appearance-none {
721
730
  -webkit-appearance: none;
722
731
  -moz-appearance: none;
@@ -792,6 +801,9 @@ video {
792
801
  .overflow-hidden {
793
802
  overflow: hidden;
794
803
  }
804
+ .overflow-x-auto {
805
+ overflow-x: auto;
806
+ }
795
807
  .overflow-x-hidden {
796
808
  overflow-x: hidden;
797
809
  }
@@ -1667,9 +1679,3 @@ button svg {
1667
1679
  margin-right: 0px;
1668
1680
  }
1669
1681
  }
1670
- .\[\&\>\*\]\:snap-start>* {
1671
- scroll-snap-align: start;
1672
- }
1673
- .\[\&\>\*\]\:snap-always>* {
1674
- scroll-snap-stop: always;
1675
- }
@@ -629,6 +629,9 @@ video {
629
629
  .h-\[1px\] {
630
630
  height: 1px;
631
631
  }
632
+ .h-\[200px\] {
633
+ height: 200px;
634
+ }
632
635
  .h-\[6px\] {
633
636
  height: 6px;
634
637
  }
@@ -669,6 +672,9 @@ video {
669
672
  .w-\[22px\] {
670
673
  width: 22px;
671
674
  }
675
+ .w-\[400px\] {
676
+ width: 400px;
677
+ }
672
678
  .w-\[6px\] {
673
679
  width: 6px;
674
680
  }
@@ -717,6 +723,9 @@ video {
717
723
  .snap-mandatory {
718
724
  --tw-scroll-snap-strictness: mandatory;
719
725
  }
726
+ .snap-always {
727
+ scroll-snap-stop: always;
728
+ }
720
729
  .appearance-none {
721
730
  -webkit-appearance: none;
722
731
  -moz-appearance: none;
@@ -792,6 +801,9 @@ video {
792
801
  .overflow-hidden {
793
802
  overflow: hidden;
794
803
  }
804
+ .overflow-x-auto {
805
+ overflow-x: auto;
806
+ }
795
807
  .overflow-x-hidden {
796
808
  overflow-x: hidden;
797
809
  }
@@ -1603,9 +1615,3 @@ video {
1603
1615
  margin-right: 0px;
1604
1616
  }
1605
1617
  }
1606
- .\[\&\>\*\]\:snap-start>* {
1607
- scroll-snap-align: start;
1608
- }
1609
- .\[\&\>\*\]\:snap-always>* {
1610
- scroll-snap-stop: always;
1611
- }
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ const Form_Input = require('./Form/Input/index.cjs');
14
14
  const Form_RadioButton = require('./Form/RadioButton/index.cjs');
15
15
  const Form_Textarea = require('./Form/Textarea/index.cjs');
16
16
  const Pagination = require('./Pagination/index.cjs');
17
- const Slide = require('./Slide-JxJDSGwS.cjs');
17
+ const Slide = require('./Slide-Q5_7SCZR.cjs');
18
18
 
19
19
 
20
20
 
package/dist/index.js CHANGED
@@ -10,4 +10,4 @@ export { default as Input } from './Form/Input/index.js';
10
10
  export { default as RadioButton } from './Form/RadioButton/index.js';
11
11
  export { default as Textarea } from './Form/Textarea/index.js';
12
12
  export { default as Pagination } from './Pagination/index.js';
13
- export { a as Slide, S as Slider } from './Slide-B4sbGo5D.js';
13
+ export { a as Slide, S as Slider } from './Slide-BDD1_RXD.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dgshahr/ui-kit",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "dgshahr ui-kit",
5
5
  "author": "dgshahr",
6
6
  "license": "MIT",
@@ -1,198 +0,0 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { c as clsx } from './clsx-ChV9xqsO.js';
3
- import { createContext, useContext, useState, useEffect, useRef, Children } from 'react';
4
- import { A as ArrowLeft2Icon } from './ArrowLeft2-BURhvXT2.js';
5
- import { A as ArrowRight2Icon } from './ArrowRight2-DCxJPvNC.js';
6
- import Button from './Button/index.js';
7
-
8
- const sliderContext = createContext({
9
- slidesPerView: 1,
10
- spaceBetween: 0
11
- });
12
- const useSliderContext = () => useContext(sliderContext);
13
-
14
- function styleNavigationDot({ active, autoplay, variant }) {
15
- const variantClassName = {
16
- inside: "bg-gray-500/50 hover:bg-gray-500/80",
17
- outside: "bg-gray-200 hover:bg-gray-300"
18
- };
19
- return [variantClassName[variant], active ? "w-[22px]" : "w-[6px]", autoplay ? "p-[1px]" : ""];
20
- }
21
- const NavigationDot = (props) => {
22
- const { active, autoplay, variant, onClick, onNavigateToNext } = props;
23
- const [fillPercentage, setFillPercentage] = useState(0);
24
- useEffect(() => {
25
- if (!active || !autoplay) return;
26
- const autoplayTime = typeof autoplay === "boolean" ? 7e3 : autoplay?.delay ?? 7e3;
27
- let startTime = Date.now();
28
- const autoplayInterval = setInterval(() => {
29
- const elapsed = Date.now() - startTime;
30
- const percentage = elapsed / autoplayTime * 100;
31
- setFillPercentage(Math.min(percentage, 100));
32
- if (elapsed >= autoplayTime && typeof onNavigateToNext === "function") {
33
- onNavigateToNext();
34
- }
35
- }, 100);
36
- return function cleanup() {
37
- setFillPercentage(0);
38
- startTime = Date.now();
39
- return clearInterval(autoplayInterval);
40
- };
41
- }, [active, autoplay, onNavigateToNext]);
42
- return /* @__PURE__ */ jsx(
43
- "button",
44
- {
45
- className: clsx(
46
- "rounded-full overflow-hidden transition-all h-[6px]",
47
- styleNavigationDot({ active, autoplay, variant })
48
- ),
49
- onClick,
50
- children: active && /* @__PURE__ */ jsx(
51
- "div",
52
- {
53
- className: clsx("h-full rounded-full", {
54
- "bg-white": variant === "inside",
55
- "bg-gray-700": variant === "outside"
56
- }),
57
- style: { width: autoplay ? `${fillPercentage}%` : "100%" }
58
- }
59
- )
60
- }
61
- );
62
- };
63
-
64
- const Slider = (props) => {
65
- const {
66
- className = "",
67
- containerClassName = "",
68
- showNavigationDots = true,
69
- dotsClassName = "",
70
- slidesPerView = 1,
71
- autoplay,
72
- navigationButtonsShowType = "hide",
73
- spaceBetween = 0,
74
- navigationVariant = "outside",
75
- showPaginationText = false
76
- } = props;
77
- const [slideIndex, setSlideIndex] = useState(0);
78
- const containerRef = useRef(null);
79
- const childsCount = Children.count(props.children);
80
- const slidesCount = Math.ceil(childsCount / slidesPerView);
81
- const haveNavigation = showNavigationDots || navigationButtonsShowType && navigationButtonsShowType !== "hide" || showPaginationText;
82
- function detectCarouselPosition(e) {
83
- const itemsWidth = e.currentTarget.scrollWidth / slidesCount;
84
- const position = (e.currentTarget.scrollWidth - e.currentTarget.scrollLeft) / itemsWidth;
85
- setSlideIndex(Math.round(position % slidesCount));
86
- }
87
- function navigate(target) {
88
- if (!containerRef.current) return;
89
- const slideWidth = containerRef.current.offsetWidth;
90
- let nextSlideScroll = -(slideWidth * target);
91
- if (target < 0) nextSlideScroll = -(slideWidth * slidesCount);
92
- else if (target >= slidesCount) nextSlideScroll = 0;
93
- containerRef.current.scrollTo({
94
- left: nextSlideScroll,
95
- behavior: "smooth"
96
- });
97
- }
98
- return /* @__PURE__ */ jsxs("div", { className: clsx("overflow-hidden relative group", className), children: [
99
- /* @__PURE__ */ jsx(
100
- "div",
101
- {
102
- className: clsx(
103
- "flex snap-x snap-mandatory overflow-x-hidden [&>*]:snap-start no-scrollbar [&>*]:snap-always",
104
- containerClassName
105
- ),
106
- style: { marginLeft: -spaceBetween },
107
- onScroll: detectCarouselPosition,
108
- ref: containerRef,
109
- children: /* @__PURE__ */ jsx(sliderContext.Provider, { value: { slidesPerView, spaceBetween }, children: props.children })
110
- }
111
- ),
112
- haveNavigation && /* @__PURE__ */ jsxs(
113
- "div",
114
- {
115
- className: clsx("flex", {
116
- "items-center justify-between mt-2": navigationVariant === "outside",
117
- "absolute bottom-4 w-full justify-center": navigationVariant === "inside"
118
- }),
119
- children: [
120
- navigationButtonsShowType && navigationButtonsShowType !== "hide" && /* @__PURE__ */ jsxs(
121
- "div",
122
- {
123
- className: clsx("flex gap-2", {
124
- "absolute bottom-0 left-[5.5%]": navigationVariant === "inside",
125
- "opacity-0 group-hover:opacity-100 transition": navigationButtonsShowType === "hover"
126
- }),
127
- children: [
128
- /* @__PURE__ */ jsx(
129
- Button,
130
- {
131
- type: "button",
132
- variant: "secondary",
133
- onClick: () => navigate(slideIndex - 1),
134
- rightIcon: /* @__PURE__ */ jsx(ArrowRight2Icon, {})
135
- }
136
- ),
137
- /* @__PURE__ */ jsx(
138
- Button,
139
- {
140
- type: "button",
141
- variant: "secondary",
142
- onClick: () => navigate(slideIndex + 1),
143
- rightIcon: /* @__PURE__ */ jsx(ArrowLeft2Icon, {})
144
- }
145
- )
146
- ]
147
- }
148
- ),
149
- (showNavigationDots || showPaginationText) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
150
- showPaginationText && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 font-caption-regular text-gray-400 ss02", children: [
151
- /* @__PURE__ */ jsx(
152
- "span",
153
- {
154
- className: clsx("font-bold", {
155
- "text-gray-600": navigationVariant === "outside",
156
- "text-white": navigationVariant === "inside"
157
- }),
158
- children: slideIndex + 1
159
- }
160
- ),
161
- /* @__PURE__ */ jsx("span", { children: "از" }),
162
- /* @__PURE__ */ jsx("span", { children: slidesCount })
163
- ] }),
164
- showNavigationDots && /* @__PURE__ */ jsx("div", { className: clsx("flex items-center justify-center gap-2", dotsClassName), children: Array.from(Array(slidesCount).keys()).map((item, index) => /* @__PURE__ */ jsx(
165
- NavigationDot,
166
- {
167
- active: slideIndex === index,
168
- autoplay: autoplay ?? false,
169
- variant: navigationVariant,
170
- onClick: () => navigate(index),
171
- onNavigateToNext: () => navigate(slideIndex + 1)
172
- },
173
- item + slidesCount
174
- )) })
175
- ] })
176
- ]
177
- }
178
- )
179
- ] });
180
- };
181
-
182
- const Slide = (props) => {
183
- const { children, className } = props;
184
- const { slidesPerView, spaceBetween } = useSliderContext();
185
- return /* @__PURE__ */ jsx(
186
- "div",
187
- {
188
- className: clsx("shrink-0", className),
189
- style: {
190
- width: 100 / (slidesPerView ?? 1) + "%",
191
- paddingLeft: spaceBetween
192
- },
193
- children
194
- }
195
- );
196
- };
197
-
198
- export { Slider as S, Slide as a };
@@ -1,201 +0,0 @@
1
- 'use strict';
2
-
3
- const jsxRuntime = require('react/jsx-runtime');
4
- const clsx = require('./clsx-BtxeOLZW.cjs');
5
- const react = require('react');
6
- const ArrowLeft2 = require('./ArrowLeft2-iZ0Au6Fn.cjs');
7
- const ArrowRight2 = require('./ArrowRight2-DTuru_sP.cjs');
8
- const Button = require('./Button/index.cjs');
9
-
10
- const sliderContext = react.createContext({
11
- slidesPerView: 1,
12
- spaceBetween: 0
13
- });
14
- const useSliderContext = () => react.useContext(sliderContext);
15
-
16
- function styleNavigationDot({ active, autoplay, variant }) {
17
- const variantClassName = {
18
- inside: "bg-gray-500/50 hover:bg-gray-500/80",
19
- outside: "bg-gray-200 hover:bg-gray-300"
20
- };
21
- return [variantClassName[variant], active ? "w-[22px]" : "w-[6px]", autoplay ? "p-[1px]" : ""];
22
- }
23
- const NavigationDot = (props) => {
24
- const { active, autoplay, variant, onClick, onNavigateToNext } = props;
25
- const [fillPercentage, setFillPercentage] = react.useState(0);
26
- react.useEffect(() => {
27
- if (!active || !autoplay) return;
28
- const autoplayTime = typeof autoplay === "boolean" ? 7e3 : autoplay?.delay ?? 7e3;
29
- let startTime = Date.now();
30
- const autoplayInterval = setInterval(() => {
31
- const elapsed = Date.now() - startTime;
32
- const percentage = elapsed / autoplayTime * 100;
33
- setFillPercentage(Math.min(percentage, 100));
34
- if (elapsed >= autoplayTime && typeof onNavigateToNext === "function") {
35
- onNavigateToNext();
36
- }
37
- }, 100);
38
- return function cleanup() {
39
- setFillPercentage(0);
40
- startTime = Date.now();
41
- return clearInterval(autoplayInterval);
42
- };
43
- }, [active, autoplay, onNavigateToNext]);
44
- return /* @__PURE__ */ jsxRuntime.jsx(
45
- "button",
46
- {
47
- className: clsx.clsx(
48
- "rounded-full overflow-hidden transition-all h-[6px]",
49
- styleNavigationDot({ active, autoplay, variant })
50
- ),
51
- onClick,
52
- children: active && /* @__PURE__ */ jsxRuntime.jsx(
53
- "div",
54
- {
55
- className: clsx.clsx("h-full rounded-full", {
56
- "bg-white": variant === "inside",
57
- "bg-gray-700": variant === "outside"
58
- }),
59
- style: { width: autoplay ? `${fillPercentage}%` : "100%" }
60
- }
61
- )
62
- }
63
- );
64
- };
65
-
66
- const Slider = (props) => {
67
- const {
68
- className = "",
69
- containerClassName = "",
70
- showNavigationDots = true,
71
- dotsClassName = "",
72
- slidesPerView = 1,
73
- autoplay,
74
- navigationButtonsShowType = "hide",
75
- spaceBetween = 0,
76
- navigationVariant = "outside",
77
- showPaginationText = false
78
- } = props;
79
- const [slideIndex, setSlideIndex] = react.useState(0);
80
- const containerRef = react.useRef(null);
81
- const childsCount = react.Children.count(props.children);
82
- const slidesCount = Math.ceil(childsCount / slidesPerView);
83
- const haveNavigation = showNavigationDots || navigationButtonsShowType && navigationButtonsShowType !== "hide" || showPaginationText;
84
- function detectCarouselPosition(e) {
85
- const itemsWidth = e.currentTarget.scrollWidth / slidesCount;
86
- const position = (e.currentTarget.scrollWidth - e.currentTarget.scrollLeft) / itemsWidth;
87
- setSlideIndex(Math.round(position % slidesCount));
88
- }
89
- function navigate(target) {
90
- if (!containerRef.current) return;
91
- const slideWidth = containerRef.current.offsetWidth;
92
- let nextSlideScroll = -(slideWidth * target);
93
- if (target < 0) nextSlideScroll = -(slideWidth * slidesCount);
94
- else if (target >= slidesCount) nextSlideScroll = 0;
95
- containerRef.current.scrollTo({
96
- left: nextSlideScroll,
97
- behavior: "smooth"
98
- });
99
- }
100
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: clsx.clsx("overflow-hidden relative group", className), children: [
101
- /* @__PURE__ */ jsxRuntime.jsx(
102
- "div",
103
- {
104
- className: clsx.clsx(
105
- "flex snap-x snap-mandatory overflow-x-hidden [&>*]:snap-start no-scrollbar [&>*]:snap-always",
106
- containerClassName
107
- ),
108
- style: { marginLeft: -spaceBetween },
109
- onScroll: detectCarouselPosition,
110
- ref: containerRef,
111
- children: /* @__PURE__ */ jsxRuntime.jsx(sliderContext.Provider, { value: { slidesPerView, spaceBetween }, children: props.children })
112
- }
113
- ),
114
- haveNavigation && /* @__PURE__ */ jsxRuntime.jsxs(
115
- "div",
116
- {
117
- className: clsx.clsx("flex", {
118
- "items-center justify-between mt-2": navigationVariant === "outside",
119
- "absolute bottom-4 w-full justify-center": navigationVariant === "inside"
120
- }),
121
- children: [
122
- navigationButtonsShowType && navigationButtonsShowType !== "hide" && /* @__PURE__ */ jsxRuntime.jsxs(
123
- "div",
124
- {
125
- className: clsx.clsx("flex gap-2", {
126
- "absolute bottom-0 left-[5.5%]": navigationVariant === "inside",
127
- "opacity-0 group-hover:opacity-100 transition": navigationButtonsShowType === "hover"
128
- }),
129
- children: [
130
- /* @__PURE__ */ jsxRuntime.jsx(
131
- Button,
132
- {
133
- type: "button",
134
- variant: "secondary",
135
- onClick: () => navigate(slideIndex - 1),
136
- rightIcon: /* @__PURE__ */ jsxRuntime.jsx(ArrowRight2.ArrowRight2Icon, {})
137
- }
138
- ),
139
- /* @__PURE__ */ jsxRuntime.jsx(
140
- Button,
141
- {
142
- type: "button",
143
- variant: "secondary",
144
- onClick: () => navigate(slideIndex + 1),
145
- rightIcon: /* @__PURE__ */ jsxRuntime.jsx(ArrowLeft2.ArrowLeft2Icon, {})
146
- }
147
- )
148
- ]
149
- }
150
- ),
151
- (showNavigationDots || showPaginationText) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
152
- showPaginationText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 font-caption-regular text-gray-400 ss02", children: [
153
- /* @__PURE__ */ jsxRuntime.jsx(
154
- "span",
155
- {
156
- className: clsx.clsx("font-bold", {
157
- "text-gray-600": navigationVariant === "outside",
158
- "text-white": navigationVariant === "inside"
159
- }),
160
- children: slideIndex + 1
161
- }
162
- ),
163
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: "از" }),
164
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: slidesCount })
165
- ] }),
166
- showNavigationDots && /* @__PURE__ */ jsxRuntime.jsx("div", { className: clsx.clsx("flex items-center justify-center gap-2", dotsClassName), children: Array.from(Array(slidesCount).keys()).map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
167
- NavigationDot,
168
- {
169
- active: slideIndex === index,
170
- autoplay: autoplay ?? false,
171
- variant: navigationVariant,
172
- onClick: () => navigate(index),
173
- onNavigateToNext: () => navigate(slideIndex + 1)
174
- },
175
- item + slidesCount
176
- )) })
177
- ] })
178
- ]
179
- }
180
- )
181
- ] });
182
- };
183
-
184
- const Slide = (props) => {
185
- const { children, className } = props;
186
- const { slidesPerView, spaceBetween } = useSliderContext();
187
- return /* @__PURE__ */ jsxRuntime.jsx(
188
- "div",
189
- {
190
- className: clsx.clsx("shrink-0", className),
191
- style: {
192
- width: 100 / (slidesPerView ?? 1) + "%",
193
- paddingLeft: spaceBetween
194
- },
195
- children
196
- }
197
- );
198
- };
199
-
200
- exports.Slide = Slide;
201
- exports.Slider = Slider;