@dgshahr/ui-kit 1.4.0 → 1.5.1

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.
@@ -1,331 +0,0 @@
1
- "use client";
2
- import { jsx as r, jsxs as N, Fragment as V } from "react/jsx-runtime";
3
- import { c as p } from "./clsx-OuTLNxxd.js";
4
- import { createContext as F, useContext as $, useState as C, useEffect as x, forwardRef as K, useRef as M, useImperativeHandle as z, useId as X } from "react";
5
- import { I as q } from "./IconArrowLeft2-cxcPyDqS.js";
6
- import { I as H } from "./IconArrowRight2-BoXg0Gkw.js";
7
- import A from "./Button/index.mjs";
8
- const B = F({
9
- slidesPerView: 1,
10
- spaceBetween: 0,
11
- navigationVariant: "outside",
12
- showNavigationDots: !0,
13
- showPaginationText: !1,
14
- childrenCount: 0,
15
- sliderId: ""
16
- }), L = () => $(B);
17
- function G({
18
- active: i,
19
- autoplay: e,
20
- variant: n = "outside"
21
- }) {
22
- return [
23
- {
24
- inside: "dgsuikit:bg-gray-500/50 dgsuikit:hover:bg-gray-500/80",
25
- outside: "dgsuikit:bg-gray-200 dgsuikit:hover:bg-gray-300"
26
- }[n],
27
- i ? "dgsuikit:w-[22px]" : "dgsuikit:w-[6px]",
28
- e ? "dgsuikit:p-[1px]" : ""
29
- ];
30
- }
31
- const J = (i) => {
32
- const { active: e, onClick: n, onNavigateToNext: o, index: t } = i, { autoplay: a, navigationVariant: k = "outside" } = L(), [d, l] = C(0);
33
- return x(() => {
34
- if (!e || !a) return;
35
- const f = typeof a == "boolean" ? 7e3 : a?.delay ?? 7e3;
36
- let m = Date.now();
37
- const u = setInterval(() => {
38
- const c = Date.now() - m, g = c / f * 100;
39
- l(Math.min(g, 100)), c >= f && typeof o == "function" && (o(), l(0), clearInterval(u));
40
- }, 100);
41
- return function() {
42
- return l(0), m = Date.now(), clearInterval(u);
43
- };
44
- }, [e, a, o]), /* @__PURE__ */ r(
45
- "button",
46
- {
47
- className: p(
48
- "dgsuikit:rounded-full dgsuikit:overflow-hidden dgsuikit:transition-all dgsuikit:h-[6px]",
49
- G({ active: e, autoplay: a, variant: k })
50
- ),
51
- onClick: n,
52
- "aria-label": `slider-navigation-dot-${t + 1}`,
53
- children: e && /* @__PURE__ */ r(
54
- "div",
55
- {
56
- className: p("dgsuikit:h-full dgsuikit:rounded-full", {
57
- "dgsuikit:bg-white": k === "inside",
58
- "dgsuikit:bg-gray-700": k === "outside"
59
- }),
60
- style: { width: a ? `${d}%` : "100%" }
61
- }
62
- )
63
- }
64
- );
65
- }, Q = (i) => {
66
- const { onNavigate: e, slideIndex: n, slidesCount: o } = i, {
67
- navigationButtonsShowType: t = "hide",
68
- dotsClassName: a,
69
- navigationContainerClassName: k,
70
- navigationVariant: d = "outside",
71
- showNavigationDots: l = !0,
72
- showPaginationText: f
73
- } = L(), m = /* @__PURE__ */ N(
74
- "div",
75
- {
76
- className: p("dgsuikit:flex dgsuikit:gap-2", {
77
- "dgsuikit:absolute dgsuikit:bottom-0 dgsuikit:left-[5.5%]": d === "inside" && t !== "onSides",
78
- "dgsuikit:absolute dgsuikit:justify-between dgsuikit:top-1/2 dgsuikit:-translate-y-1/2 dgsuikit:w-full dgsuikit:px-[5.5%]": t === "onSides",
79
- "dgsuikit:opacity-0 dgsuikit:group-hover:opacity-100 dgsuikit:transition": t === "hover" || t === "onSides"
80
- }),
81
- children: [
82
- /* @__PURE__ */ r(
83
- A,
84
- {
85
- type: "button",
86
- variant: "secondary",
87
- onClick: () => e(n - 1),
88
- rightIcon: /* @__PURE__ */ r(H, {}),
89
- "aria-label": "slider-previous-button"
90
- }
91
- ),
92
- /* @__PURE__ */ r(
93
- A,
94
- {
95
- type: "button",
96
- variant: "secondary",
97
- onClick: () => e(n + 1),
98
- rightIcon: /* @__PURE__ */ r(q, {}),
99
- "aria-label": "slider-next-button"
100
- }
101
- )
102
- ]
103
- }
104
- );
105
- return /* @__PURE__ */ N(V, { children: [
106
- t && t !== "hide" && t === "onSides" && m,
107
- /* @__PURE__ */ N(
108
- "div",
109
- {
110
- className: p(
111
- "dgsuikit:flex",
112
- {
113
- "dgsuikit:items-center dgsuikit:mt-2": d === "outside",
114
- "dgsuikit:absolute dgsuikit:bottom-4 dgsuikit:w-full dgsuikit:justify-center": d === "inside",
115
- "dgsuikit:justify-between": d === "outside" && t !== "hide" && t !== "onSides",
116
- "dgsuikit:justify-center": d === "outside" && (t === "hide" || t === "onSides")
117
- },
118
- k
119
- ),
120
- children: [
121
- t && t !== "hide" && t !== "onSides" && m,
122
- (l || f) && /* @__PURE__ */ N("div", { className: "dgsuikit:flex dgsuikit:items-center dgsuikit:gap-3", children: [
123
- f && /* @__PURE__ */ N("div", { className: "dgsuikit:flex dgsuikit:items-center dgsuikit:gap-1 dgsuikit:font-caption-regular dgsuikit:text-gray-400 dgsuikit:ss02", children: [
124
- /* @__PURE__ */ r(
125
- "span",
126
- {
127
- className: p("dgsuikit:font-bold", {
128
- "dgsuikit:text-gray-600": d === "outside",
129
- "dgsuikit:text-white": d === "inside"
130
- }),
131
- children: n + 1
132
- }
133
- ),
134
- /* @__PURE__ */ r("span", { children: "از" }),
135
- /* @__PURE__ */ r("span", { children: o })
136
- ] }),
137
- l && /* @__PURE__ */ r(
138
- "div",
139
- {
140
- className: p(
141
- "dgsuikit:flex dgsuikit:items-center dgsuikit:justify-center dgsuikit:gap-2",
142
- a
143
- ),
144
- children: Array.from(Array(o).keys()).map((u, c) => /* @__PURE__ */ r(
145
- J,
146
- {
147
- active: n === c,
148
- index: c,
149
- onClick: () => e(c),
150
- onNavigateToNext: () => e(n + 1)
151
- },
152
- u + o
153
- ))
154
- }
155
- )
156
- ] })
157
- ]
158
- }
159
- )
160
- ] });
161
- }, U = K((i, e) => {
162
- const [n, o] = C(i), {
163
- className: t = "",
164
- containerClassName: a = "",
165
- showNavigationDots: k = !0,
166
- slidesPerView: d = 1,
167
- navigationButtonsShowType: l = "hide",
168
- spaceBetween: f = 0,
169
- showPaginationText: m,
170
- onSlideIndexChange: u,
171
- initialSlide: c,
172
- containerXPadding: g = 0
173
- } = n, [S, I] = C(0), [W, D] = C(0), R = Object.fromEntries(
174
- Object.entries(n).filter(([s]) => s !== "children")
175
- ), h = M(null), v = Math.ceil(W / Math.floor(d)), E = (k || l && l !== "hide" || m) && v > 1;
176
- function O(s) {
177
- if (Math.ceil(Math.abs(s.currentTarget.scrollLeft)) + s.currentTarget.clientWidth + 1 + g >= s.currentTarget.scrollWidth) {
178
- I(v - 1);
179
- return;
180
- }
181
- const w = s.currentTarget.scrollWidth - g * 2, b = w / v, y = (w - s.currentTarget.scrollLeft - g) / b;
182
- if (y <= v) {
183
- I(0);
184
- return;
185
- }
186
- I(Math.round(y % v));
187
- }
188
- function P(s) {
189
- if (!h.current) return;
190
- const w = h.current.offsetWidth, b = S - s, y = h.current.scrollWidth / v, j = b * y;
191
- s < 0 ? h.current.scrollTo({ behavior: "smooth", left: -(w * v) }) : s >= v ? h.current.scrollTo({ behavior: "smooth", left: 0 }) : h.current.scrollBy({ behavior: "smooth", left: j });
192
- }
193
- function T() {
194
- const w = Object.keys(i.responsive).sort(
195
- (y, j) => Number(y) - Number(j)
196
- ).findLast(
197
- (y) => Number(y) <= window.innerWidth
198
- ), b = w ? i.responsive[Number(w)] : null;
199
- o(b ? { ...n, ...b } : i);
200
- }
201
- return z(e, () => ({
202
- element: h.current,
203
- navigate: (s) => P(Math.max(0, s - 1))
204
- })), x(() => {
205
- if (!h.current) return;
206
- let s = h.current.childElementCount;
207
- g > 0 && (s -= 2), D(s);
208
- }, [i.children, h, g]), x(() => {
209
- if (!(!i.responsive || Object.keys(i.responsive).length <= 0))
210
- return T(), window.addEventListener("resize", T), () => {
211
- window.removeEventListener("resize", T);
212
- };
213
- }, [i.responsive]), x(() => {
214
- u && typeof u == "function" && u(S);
215
- }, [S]), x(() => {
216
- typeof c == "number" && h.current && P(Math.max(0, c - 1));
217
- }, [c, h.current]), /* @__PURE__ */ r(B.Provider, { value: { ...R, childrenCount: W, sliderId: X() }, children: /* @__PURE__ */ N(
218
- "div",
219
- {
220
- className: p("dgsuikit:overflow-hidden dgsuikit:relative dgsuikit:group", t),
221
- style: { direction: "rtl" },
222
- children: [
223
- /* @__PURE__ */ N(
224
- "div",
225
- {
226
- className: p(
227
- "dgsuikit:flex dgsuikit:snap-x dgsuikit:snap-mandatory dgsuikit:overflow-x-auto dgsuikit:no-scrollbar",
228
- a
229
- ),
230
- style: { marginLeft: -f },
231
- onScroll: O,
232
- ref: h,
233
- children: [
234
- g > 0 && /* @__PURE__ */ r(
235
- "div",
236
- {
237
- className: "dgsuikit:shrink-0",
238
- style: {
239
- width: g,
240
- paddingLeft: f
241
- }
242
- }
243
- ),
244
- i.children,
245
- g > 0 && /* @__PURE__ */ r(
246
- "div",
247
- {
248
- className: "dgsuikit:shrink-0",
249
- style: {
250
- width: g,
251
- paddingLeft: f
252
- }
253
- }
254
- )
255
- ]
256
- }
257
- ),
258
- E && /* @__PURE__ */ r(
259
- Q,
260
- {
261
- onNavigate: P,
262
- slideIndex: S,
263
- slidesCount: v
264
- }
265
- )
266
- ]
267
- }
268
- ) });
269
- });
270
- U.displayName = "Slider";
271
- function Y({
272
- slidesPerView: i,
273
- childIndex: e,
274
- centerMode: n,
275
- childrenCount: o,
276
- haveContainerPadding: t
277
- }) {
278
- const a = e % Math.floor(i) === 0, k = i % 1 !== 0, d = e === 0, l = e === o - 1;
279
- if (!a) return "none";
280
- if (n) {
281
- if (k && !t) {
282
- if (d) return "start";
283
- if (l) return "end";
284
- }
285
- return "center";
286
- }
287
- return "start";
288
- }
289
- const st = (i) => {
290
- const { children: e, className: n, style: o, ...t } = i, {
291
- slidesPerView: a = 1,
292
- spaceBetween: k = 0,
293
- centerMode: d = !1,
294
- containerXPadding: l = 0,
295
- childrenCount: f = 0,
296
- sliderId: m
297
- } = L(), u = M(null), [c, g] = C(0);
298
- return x(() => {
299
- u.current && g(
300
- Array.prototype.indexOf.call(
301
- document.querySelectorAll(`[id='slide-item-${m}']`),
302
- u.current
303
- )
304
- );
305
- }, [u, f, l]), /* @__PURE__ */ r(
306
- "div",
307
- {
308
- ...t,
309
- ref: u,
310
- id: `slide-item-${m}`,
311
- className: p("dgsuikit:shrink-0 dgsuikit:snap-normal", n),
312
- style: {
313
- width: 100 / (a ?? 1) + "%",
314
- paddingLeft: k,
315
- scrollSnapAlign: Y({
316
- slidesPerView: a,
317
- childIndex: c,
318
- centerMode: d,
319
- childrenCount: f || 0,
320
- haveContainerPadding: l > 0
321
- }),
322
- ...o
323
- },
324
- children: e
325
- }
326
- );
327
- };
328
- export {
329
- U as S,
330
- st as a
331
- };