@dgshahr/ui-kit 0.0.4 → 0.0.6

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.
Files changed (55) hide show
  1. package/dist/Accordion/AccordionItem.d.ts.map +1 -1
  2. package/dist/Accordion/index.cjs +1 -1
  3. package/dist/Accordion/index.js +1 -1
  4. package/dist/{AccordionItem-DN7bi5kw.js → AccordionItem-BFDuboYi.js} +11 -11
  5. package/dist/{AccordionItem-lq6ehxKe.cjs → AccordionItem-C3MiOBH7.cjs} +11 -11
  6. package/dist/Alert/index.cjs +69 -57
  7. package/dist/Alert/index.d.ts.map +1 -1
  8. package/dist/Alert/index.js +69 -57
  9. package/dist/Badge/index.cjs +22 -22
  10. package/dist/Badge/index.d.ts.map +1 -1
  11. package/dist/Badge/index.js +22 -22
  12. package/dist/Breadcrumb/index.cjs +31 -22
  13. package/dist/Breadcrumb/index.d.ts.map +1 -1
  14. package/dist/Breadcrumb/index.js +31 -22
  15. package/dist/Button/index.cjs +34 -34
  16. package/dist/Button/index.d.ts.map +1 -1
  17. package/dist/Button/index.js +34 -34
  18. package/dist/Button/variants.d.ts.map +1 -1
  19. package/dist/Divider/index.cjs +6 -6
  20. package/dist/Divider/index.js +6 -6
  21. package/dist/Form/Checkbox/index.cjs +2 -2
  22. package/dist/Form/Checkbox/index.js +2 -2
  23. package/dist/Form/Input/index.cjs +10 -10
  24. package/dist/Form/Input/index.d.ts.map +1 -1
  25. package/dist/Form/Input/index.js +10 -10
  26. package/dist/Form/RadioButton/index.cjs +3 -3
  27. package/dist/Form/RadioButton/index.js +3 -3
  28. package/dist/Form/Textarea/index.cjs +4 -4
  29. package/dist/Form/Textarea/index.d.ts.map +1 -1
  30. package/dist/Form/Textarea/index.js +4 -4
  31. package/dist/Form/Wrappers/SelectableInputWrapper/SelectableInputWrapper.d.ts.map +1 -1
  32. package/dist/Pagination/index.cjs +51 -42
  33. package/dist/Pagination/index.d.ts.map +1 -1
  34. package/dist/Pagination/index.js +51 -42
  35. package/dist/SelectableInputWrapper-BIBVazbq.js +77 -0
  36. package/dist/SelectableInputWrapper-g7YtIiBW.cjs +79 -0
  37. package/dist/Slide-BhWFQV8r.js +234 -0
  38. package/dist/Slide-BzXDEkqH.cjs +237 -0
  39. package/dist/Slider/NavigationDot.d.ts.map +1 -1
  40. package/dist/Slider/Slide.d.ts.map +1 -1
  41. package/dist/Slider/Slider.d.ts +2 -1
  42. package/dist/Slider/Slider.d.ts.map +1 -1
  43. package/dist/Slider/index.cjs +1 -1
  44. package/dist/Slider/index.js +1 -1
  45. package/dist/{TextFieldWrapper--hxpmYuz.js → TextFieldWrapper-BkoKcbvs.js} +16 -16
  46. package/dist/{TextFieldWrapper-DaoZxs1E.cjs → TextFieldWrapper-D-DH5_DG.cjs} +16 -16
  47. package/dist/assets/Button.css +355 -317
  48. package/dist/assets/styles.css +343 -305
  49. package/dist/index.cjs +2 -2
  50. package/dist/index.js +2 -2
  51. package/package.json +5 -4
  52. package/dist/SelectableInputWrapper-D2aYQb9J.cjs +0 -71
  53. package/dist/SelectableInputWrapper-DAj8v1nv.js +0 -69
  54. package/dist/Slide-B4sbGo5D.js +0 -198
  55. package/dist/Slide-JxJDSGwS.cjs +0 -201
package/dist/index.cjs CHANGED
@@ -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 AccordionItem = require('./AccordionItem-lq6ehxKe.cjs');
6
+ const AccordionItem = require('./AccordionItem-C3MiOBH7.cjs');
7
7
  const Alert = require('./Alert/index.cjs');
8
8
  const Badge = require('./Badge/index.cjs');
9
9
  const Breadcrumb = require('./Breadcrumb/index.cjs');
@@ -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-BzXDEkqH.cjs');
18
18
 
19
19
 
20
20
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import './assets/styles.css';/* empty css */
2
- export { A as AccordionGroup, a as AccordionItem } from './AccordionItem-DN7bi5kw.js';
2
+ export { A as AccordionGroup, a as AccordionItem } from './AccordionItem-BFDuboYi.js';
3
3
  export { default as Alert } from './Alert/index.js';
4
4
  export { default as Badge } from './Badge/index.js';
5
5
  export { default as Breadcrumb } from './Breadcrumb/index.js';
@@ -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-BhWFQV8r.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.6",
4
4
  "description": "dgshahr ui-kit",
5
5
  "author": "dgshahr",
6
6
  "license": "MIT",
@@ -151,9 +151,10 @@
151
151
  },
152
152
  "scripts": {
153
153
  "dev": "storybook dev -p 6006",
154
- "build": "tsc && vite build && node scripts/generate-exports.js",
154
+ "build": "rm -rf dist && tsc && vite build && node scripts/generate-exports.js",
155
155
  "build:story": "storybook build",
156
- "lint": "eslint --fix src/**/* --report-unused-disable-directives --max-warnings 0 -f codeframe",
156
+ "start:story": "npx http-server storybook-static",
157
+ "lint": "eslint --fix src/**/* --report-unused-disable-directives --max-warnings 0 --no-warn-ignored -f codeframe",
157
158
  "format": "prettier src/**/* --write --ignore-unknown",
158
159
  "prepublishOnly": "npm run build",
159
160
  "prepare": "husky",
@@ -217,4 +218,4 @@
217
218
  "yarn format"
218
219
  ]
219
220
  }
220
- }
221
+ }
@@ -1,71 +0,0 @@
1
- 'use strict';
2
-
3
- require('./assets/styles.css');const jsxRuntime = require('react/jsx-runtime');
4
- const clsx = require('./clsx-BtxeOLZW.cjs');
5
- ;/* empty css */
6
-
7
- const SelectableInputWrapper = (props) => {
8
- const {
9
- children,
10
- containerClassName,
11
- errorMessage,
12
- helperMessage,
13
- isError,
14
- label,
15
- variant = "default"
16
- } = props;
17
- const icon = props.icon;
18
- return /* @__PURE__ */ jsxRuntime.jsxs(
19
- "label",
20
- {
21
- className: clsx.clsx(
22
- "flex w-fit justify-between items-center group has-[:disabled]:opacity-40 has-[:disabled]:cursor-not-allowed transition",
23
- {
24
- "p-3 border w-full border-solid rounded-xl bg-white has-[:checked]:bg-primary-50": variant === "bordered",
25
- "has-[:checked]:border-primary-500 border-gray-200 hover:ring-4 hover:ring-gray-100 has-[:focus]:ring has-[:focus]:ring-primary-300 has-[:focus]:ring-offset-1 has-[:focus]:ring-offset-white": variant === "bordered" && !isError,
26
- "border-error-500 hover:ring-4 hover:ring-error-50 has-[:focus]:ring has-[:focus]:ring-error-300 has-[:focus]:ring-offset-1 has-[:focus]:ring-offset-white": variant === "bordered" && isError
27
- },
28
- containerClassName
29
- ),
30
- children: [
31
- /* @__PURE__ */ jsxRuntime.jsxs(
32
- "div",
33
- {
34
- className: clsx.clsx(
35
- "flex space-x-2 space-x-reverse",
36
- errorMessage ?? helperMessage ? "items-start" : "items-center"
37
- ),
38
- children: [
39
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: clsx.clsx("relative h-[18px] w-[18px]", { "mt-1": label }), children: children({
40
- inputClassName: clsx.clsx(
41
- "peer w-full h-full disabled:bg-gray-200 appearance-none border border-gray-300 group-hover:border-primary-500 checked:bg-primary-500 checked:border-transparent transition-all",
42
- {
43
- "group-hover:ring-4 group-hover:ring-gray-100 focus:!ring focus:!ring-primary-300 focus:ring-offset-1 focus:ring-offset-white": variant !== "bordered" && !isError,
44
- "!border-error-500 group-hover:ring-4 group-hover:ring-error-50 focus:!ring focus:!ring-error-300 focus:ring-offset-1 focus:ring-offset-white": variant !== "bordered" && isError
45
- }
46
- ),
47
- checkedInputClassName: "absolute top-0 left-0 w-full h-full flex items-center justify-center text-white opacity-0 peer-checked:opacity-100 transition-opacity"
48
- }) }),
49
- Boolean(label) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
50
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-p2-medium text-gray-700 transition group-hover:text-primary-500", children: label }),
51
- Boolean(errorMessage ?? helperMessage) && /* @__PURE__ */ jsxRuntime.jsx(
52
- "div",
53
- {
54
- className: clsx.clsx(
55
- "font-p3-regular",
56
- errorMessage && isError ? "text-error-500" : "text-gray-500"
57
- ),
58
- children: isError && errorMessage ? errorMessage : helperMessage
59
- }
60
- )
61
- ] })
62
- ]
63
- }
64
- ),
65
- variant === "bordered" && icon ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-600 group-hover:text-primary-500 group-checked:text-primary-500", children: icon }) : null
66
- ]
67
- }
68
- );
69
- };
70
-
71
- exports.SelectableInputWrapper = SelectableInputWrapper;
@@ -1,69 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { c as clsx } from './clsx-ChV9xqsO.js';
3
- import './assets/styles.css';/* empty css */
4
-
5
- const SelectableInputWrapper = (props) => {
6
- const {
7
- children,
8
- containerClassName,
9
- errorMessage,
10
- helperMessage,
11
- isError,
12
- label,
13
- variant = "default"
14
- } = props;
15
- const icon = props.icon;
16
- return /* @__PURE__ */ jsxs(
17
- "label",
18
- {
19
- className: clsx(
20
- "flex w-fit justify-between items-center group has-[:disabled]:opacity-40 has-[:disabled]:cursor-not-allowed transition",
21
- {
22
- "p-3 border w-full border-solid rounded-xl bg-white has-[:checked]:bg-primary-50": variant === "bordered",
23
- "has-[:checked]:border-primary-500 border-gray-200 hover:ring-4 hover:ring-gray-100 has-[:focus]:ring has-[:focus]:ring-primary-300 has-[:focus]:ring-offset-1 has-[:focus]:ring-offset-white": variant === "bordered" && !isError,
24
- "border-error-500 hover:ring-4 hover:ring-error-50 has-[:focus]:ring has-[:focus]:ring-error-300 has-[:focus]:ring-offset-1 has-[:focus]:ring-offset-white": variant === "bordered" && isError
25
- },
26
- containerClassName
27
- ),
28
- children: [
29
- /* @__PURE__ */ jsxs(
30
- "div",
31
- {
32
- className: clsx(
33
- "flex space-x-2 space-x-reverse",
34
- errorMessage ?? helperMessage ? "items-start" : "items-center"
35
- ),
36
- children: [
37
- /* @__PURE__ */ jsx("div", { className: clsx("relative h-[18px] w-[18px]", { "mt-1": label }), children: children({
38
- inputClassName: clsx(
39
- "peer w-full h-full disabled:bg-gray-200 appearance-none border border-gray-300 group-hover:border-primary-500 checked:bg-primary-500 checked:border-transparent transition-all",
40
- {
41
- "group-hover:ring-4 group-hover:ring-gray-100 focus:!ring focus:!ring-primary-300 focus:ring-offset-1 focus:ring-offset-white": variant !== "bordered" && !isError,
42
- "!border-error-500 group-hover:ring-4 group-hover:ring-error-50 focus:!ring focus:!ring-error-300 focus:ring-offset-1 focus:ring-offset-white": variant !== "bordered" && isError
43
- }
44
- ),
45
- checkedInputClassName: "absolute top-0 left-0 w-full h-full flex items-center justify-center text-white opacity-0 peer-checked:opacity-100 transition-opacity"
46
- }) }),
47
- Boolean(label) && /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
48
- /* @__PURE__ */ jsx("div", { className: "font-p2-medium text-gray-700 transition group-hover:text-primary-500", children: label }),
49
- Boolean(errorMessage ?? helperMessage) && /* @__PURE__ */ jsx(
50
- "div",
51
- {
52
- className: clsx(
53
- "font-p3-regular",
54
- errorMessage && isError ? "text-error-500" : "text-gray-500"
55
- ),
56
- children: isError && errorMessage ? errorMessage : helperMessage
57
- }
58
- )
59
- ] })
60
- ]
61
- }
62
- ),
63
- variant === "bordered" && icon ? /* @__PURE__ */ jsx("div", { className: "text-gray-600 group-hover:text-primary-500 group-checked:text-primary-500", children: icon }) : null
64
- ]
65
- }
66
- );
67
- };
68
-
69
- export { SelectableInputWrapper as S };
@@ -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;