@quen-ui/components 1.1.0 → 1.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.
Files changed (71) hide show
  1. package/dist/Banner/Banner.cjs.js +96 -0
  2. package/dist/Banner/Banner.d.ts +4 -0
  3. package/dist/Banner/Banner.es.js +96 -0
  4. package/dist/Banner/index.d.ts +2 -0
  5. package/dist/Banner/styles.cjs.js +113 -0
  6. package/dist/Banner/styles.d.ts +12 -0
  7. package/dist/Banner/styles.es.js +113 -0
  8. package/dist/Banner/types.d.ts +40 -0
  9. package/dist/Dropdown/Dropdown.cjs.js +47 -43
  10. package/dist/Dropdown/Dropdown.d.ts +1 -1
  11. package/dist/Dropdown/Dropdown.es.js +48 -44
  12. package/dist/Dropdown/DropdownItem.cjs.js +10 -13
  13. package/dist/Dropdown/DropdownItem.es.js +10 -13
  14. package/dist/Dropdown/DropdownList.cjs.js +0 -2
  15. package/dist/Dropdown/DropdownList.es.js +0 -2
  16. package/dist/InputBase/InputBase.cjs.js +55 -12
  17. package/dist/InputBase/InputBase.d.ts +1 -1
  18. package/dist/InputBase/InputBase.es.js +57 -14
  19. package/dist/InputBase/styles.cjs.js +44 -4
  20. package/dist/InputBase/styles.d.ts +7 -1
  21. package/dist/InputBase/styles.es.js +45 -5
  22. package/dist/InputBase/types.d.ts +5 -1
  23. package/dist/InputDate/styles.d.ts +1 -1
  24. package/dist/InputNumber/styles.d.ts +1 -1
  25. package/dist/Select/Select.cjs.js +2 -5
  26. package/dist/Select/Select.es.js +2 -5
  27. package/dist/Select/helpers.d.ts +8 -0
  28. package/dist/Select/styles.d.ts +1 -1
  29. package/dist/Select/useSelect.d.ts +8 -0
  30. package/dist/Slider/Slider.cjs.js +122 -224
  31. package/dist/Slider/Slider.d.ts +1 -1
  32. package/dist/Slider/Slider.es.js +125 -227
  33. package/dist/Slider/styles.cjs.js +49 -32
  34. package/dist/Slider/styles.d.ts +1 -1
  35. package/dist/Slider/styles.es.js +49 -32
  36. package/dist/Slider/useSlider.cjs.js +194 -0
  37. package/dist/Slider/useSlider.d.ts +11 -0
  38. package/dist/Slider/useSlider.es.js +194 -0
  39. package/dist/Stepper/Step.cjs.js +114 -0
  40. package/dist/Stepper/Step.d.ts +2 -0
  41. package/dist/Stepper/Step.es.js +114 -0
  42. package/dist/Stepper/StepContent.cjs.js +10 -0
  43. package/dist/Stepper/StepContent.d.ts +4 -0
  44. package/dist/Stepper/StepContent.es.js +10 -0
  45. package/dist/Stepper/StepLabel.cjs.js +28 -0
  46. package/dist/Stepper/StepLabel.d.ts +2 -0
  47. package/dist/Stepper/StepLabel.es.js +28 -0
  48. package/dist/Stepper/Stepper.cjs.js +54 -0
  49. package/dist/Stepper/Stepper.d.ts +2 -0
  50. package/dist/Stepper/Stepper.es.js +54 -0
  51. package/dist/Stepper/StepperContext.cjs.js +13 -0
  52. package/dist/Stepper/StepperContext.d.ts +3 -0
  53. package/dist/Stepper/StepperContext.es.js +13 -0
  54. package/dist/Stepper/index.cjs.js +10 -0
  55. package/dist/Stepper/index.d.ts +12 -0
  56. package/dist/Stepper/index.es.js +11 -0
  57. package/dist/Stepper/styles.cjs.js +149 -0
  58. package/dist/Stepper/styles.d.ts +44 -0
  59. package/dist/Stepper/styles.es.js +149 -0
  60. package/dist/Stepper/types.d.ts +70 -0
  61. package/dist/TextField/TextField.cjs.js +4 -0
  62. package/dist/TextField/TextField.d.ts +1 -1
  63. package/dist/TextField/TextField.es.js +4 -0
  64. package/dist/TextField/styles.d.ts +1 -1
  65. package/dist/Textarea/styles.d.ts +1 -1
  66. package/dist/Tooltip/Tooltip.cjs.js +3 -1
  67. package/dist/Tooltip/Tooltip.es.js +4 -2
  68. package/dist/index.cjs.js +4 -0
  69. package/dist/index.d.ts +2 -0
  70. package/dist/index.es.js +4 -0
  71. package/package.json +1 -1
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const useSlider = ({
5
+ value,
6
+ min = 0,
7
+ max = 100,
8
+ step = 1,
9
+ onChange,
10
+ range = false,
11
+ disabled = false,
12
+ orientation = "horizontal",
13
+ draggableTrack = false
14
+ }) => {
15
+ const normalize = (v, isRange) => {
16
+ if (isRange) return Array.isArray(v) ? v : [min, max];
17
+ const singleVal = typeof v === "number" ? v : min;
18
+ return [singleVal, singleVal];
19
+ };
20
+ const [values, setValues] = React.useState(
21
+ () => normalize(value, range)
22
+ );
23
+ const valuesRef = React.useRef(values);
24
+ valuesRef.current = values;
25
+ React.useEffect(() => {
26
+ const next = normalize(value, range);
27
+ setValues(
28
+ (prev) => prev[0] === next[0] && prev[1] === next[1] ? prev : next
29
+ );
30
+ }, [value, range, min, max]);
31
+ const clamp = (v) => Math.min(max, Math.max(min, v));
32
+ const snap = React.useCallback(
33
+ (raw) => clamp(Number((Math.round(raw / step) * step).toFixed(10))),
34
+ [min, max, step]
35
+ );
36
+ const percentOf = (v) => (v - min) / (max - min) * 100;
37
+ const trackRef = React.useRef(null);
38
+ const isDraggingRef = React.useRef(false);
39
+ const dragTargetRef = React.useRef(null);
40
+ const isDraggingRangeRef = React.useRef(false);
41
+ const rangeOffsetRef = React.useRef(0);
42
+ const [isDragging, setIsDragging] = React.useState(false);
43
+ const getRawValue = React.useCallback(
44
+ (clientX, clientY) => {
45
+ if (!trackRef.current) return min;
46
+ const rect = trackRef.current.getBoundingClientRect();
47
+ const ratio = orientation === "vertical" ? 1 - (clientY - rect.top) / rect.height : (clientX - rect.left) / rect.width;
48
+ return min + Math.min(1, Math.max(0, ratio)) * (max - min);
49
+ },
50
+ [orientation, min, max]
51
+ );
52
+ const update = React.useCallback(
53
+ (next) => {
54
+ const [s, e] = next[0] > next[1] ? [next[1], next[0]] : next;
55
+ setValues((prev) => {
56
+ if (prev[0] === s && prev[1] === e) return prev;
57
+ onChange?.(range ? [s, e] : e);
58
+ return [s, e];
59
+ });
60
+ },
61
+ [onChange, range]
62
+ );
63
+ const attachDragListeners = (target, e, rangeOffset) => {
64
+ if (disabled) return;
65
+ isDraggingRef.current = true;
66
+ dragTargetRef.current = target;
67
+ isDraggingRangeRef.current = rangeOffset !== void 0;
68
+ if (rangeOffset !== void 0) rangeOffsetRef.current = rangeOffset;
69
+ setIsDragging(true);
70
+ e.target?.setPointerCapture?.(e.pointerId);
71
+ const onMove = (ev) => {
72
+ if (!isDraggingRef.current || !trackRef.current) return;
73
+ ev.preventDefault();
74
+ const raw = getRawValue(ev.clientX, ev.clientY);
75
+ const current = valuesRef.current;
76
+ if (isDraggingRangeRef.current) {
77
+ const rangeSize = current[1] - current[0];
78
+ const newStart = snap(raw - rangeOffsetRef.current);
79
+ let finalStart = clamp(newStart);
80
+ let finalEnd = clamp(finalStart + rangeSize);
81
+ if (finalEnd > max) {
82
+ finalEnd = max;
83
+ finalStart = clamp(max - rangeSize);
84
+ }
85
+ update([finalStart, finalEnd]);
86
+ } else if (target === "start") {
87
+ update([snap(raw), current[1]]);
88
+ } else if (target === "end") {
89
+ update([current[0], snap(raw)]);
90
+ }
91
+ };
92
+ const onUp = () => {
93
+ isDraggingRef.current = false;
94
+ dragTargetRef.current = null;
95
+ isDraggingRangeRef.current = false;
96
+ setIsDragging(false);
97
+ window.removeEventListener("pointermove", onMove);
98
+ window.removeEventListener("pointerup", onUp);
99
+ window.removeEventListener("pointercancel", onUp);
100
+ };
101
+ window.addEventListener("pointermove", onMove);
102
+ window.addEventListener("pointerup", onUp);
103
+ window.addEventListener("pointercancel", onUp);
104
+ };
105
+ const onPointerDownThumb = React.useCallback(
106
+ (target, e) => {
107
+ if (disabled) return;
108
+ attachDragListeners(target, e.nativeEvent);
109
+ },
110
+ [disabled, attachDragListeners]
111
+ );
112
+ const onPointerDownTrack = React.useCallback(
113
+ (e) => {
114
+ if (disabled) return;
115
+ const nativeEvent = e.nativeEvent;
116
+ const raw = getRawValue(nativeEvent.clientX, nativeEvent.clientY);
117
+ const current = valuesRef.current;
118
+ if (draggableTrack && range && raw >= current[0] && raw <= current[1]) {
119
+ if (trackRef.current)
120
+ trackRef.current.setPointerCapture(nativeEvent.pointerId);
121
+ const offset = raw - current[0];
122
+ attachDragListeners(null, nativeEvent, offset);
123
+ return;
124
+ }
125
+ const snapped = snap(raw);
126
+ if (range) {
127
+ const distStart = Math.abs(snapped - current[0]);
128
+ const distEnd = Math.abs(snapped - current[1]);
129
+ const target = distStart <= distEnd ? "start" : "end";
130
+ update(
131
+ target === "start" ? [snapped, current[1]] : [current[0], snapped]
132
+ );
133
+ } else {
134
+ update([snapped, snapped]);
135
+ }
136
+ },
137
+ [
138
+ disabled,
139
+ getRawValue,
140
+ draggableTrack,
141
+ range,
142
+ snap,
143
+ update,
144
+ attachDragListeners
145
+ ]
146
+ );
147
+ const onKeyDown = React.useCallback(
148
+ (target, e) => {
149
+ if (disabled) return;
150
+ const pageStep = Math.max(step, (max - min) / 10);
151
+ let delta = 0;
152
+ switch (e.key) {
153
+ case "ArrowUp":
154
+ case "ArrowRight":
155
+ delta = step;
156
+ break;
157
+ case "ArrowDown":
158
+ case "ArrowLeft":
159
+ delta = -step;
160
+ break;
161
+ case "Home":
162
+ delta = min - values[target === "start" ? 0 : 1];
163
+ break;
164
+ case "End":
165
+ delta = max - values[target === "start" ? 0 : 1];
166
+ break;
167
+ case "PageUp":
168
+ delta = pageStep;
169
+ break;
170
+ case "PageDown":
171
+ delta = -pageStep;
172
+ break;
173
+ default:
174
+ return;
175
+ }
176
+ e.preventDefault();
177
+ const current = values[target === "start" ? 0 : 1];
178
+ const newVal = snap(current + delta);
179
+ update(target === "start" ? [newVal, values[1]] : [values[0], newVal]);
180
+ },
181
+ [disabled, values, step, min, max, snap, update]
182
+ );
183
+ return {
184
+ values,
185
+ trackRef,
186
+ percentStart: percentOf(values[0]),
187
+ percentEnd: percentOf(values[1]),
188
+ onPointerDownThumb,
189
+ onPointerDownTrack,
190
+ onKeyDown,
191
+ isDragging
192
+ };
193
+ };
194
+ exports.useSlider = useSlider;
@@ -0,0 +1,11 @@
1
+ import { ISliderProps, TSliderRangeValue } from './types';
2
+ export declare const useSlider: ({ value, min, max, step, onChange, range, disabled, orientation, draggableTrack }: ISliderProps) => {
3
+ values: TSliderRangeValue;
4
+ trackRef: import('react').RefObject<HTMLDivElement | null>;
5
+ percentStart: number;
6
+ percentEnd: number;
7
+ onPointerDownThumb: (target: "start" | "end", e: React.PointerEvent) => void;
8
+ onPointerDownTrack: (e: React.PointerEvent) => void;
9
+ onKeyDown: (target: "start" | "end", e: React.KeyboardEvent) => void;
10
+ isDragging: boolean;
11
+ };
@@ -0,0 +1,194 @@
1
+ import { useState, useRef, useEffect, useCallback } from "react";
2
+ const useSlider = ({
3
+ value,
4
+ min = 0,
5
+ max = 100,
6
+ step = 1,
7
+ onChange,
8
+ range = false,
9
+ disabled = false,
10
+ orientation = "horizontal",
11
+ draggableTrack = false
12
+ }) => {
13
+ const normalize = (v, isRange) => {
14
+ if (isRange) return Array.isArray(v) ? v : [min, max];
15
+ const singleVal = typeof v === "number" ? v : min;
16
+ return [singleVal, singleVal];
17
+ };
18
+ const [values, setValues] = useState(
19
+ () => normalize(value, range)
20
+ );
21
+ const valuesRef = useRef(values);
22
+ valuesRef.current = values;
23
+ useEffect(() => {
24
+ const next = normalize(value, range);
25
+ setValues(
26
+ (prev) => prev[0] === next[0] && prev[1] === next[1] ? prev : next
27
+ );
28
+ }, [value, range, min, max]);
29
+ const clamp = (v) => Math.min(max, Math.max(min, v));
30
+ const snap = useCallback(
31
+ (raw) => clamp(Number((Math.round(raw / step) * step).toFixed(10))),
32
+ [min, max, step]
33
+ );
34
+ const percentOf = (v) => (v - min) / (max - min) * 100;
35
+ const trackRef = useRef(null);
36
+ const isDraggingRef = useRef(false);
37
+ const dragTargetRef = useRef(null);
38
+ const isDraggingRangeRef = useRef(false);
39
+ const rangeOffsetRef = useRef(0);
40
+ const [isDragging, setIsDragging] = useState(false);
41
+ const getRawValue = useCallback(
42
+ (clientX, clientY) => {
43
+ if (!trackRef.current) return min;
44
+ const rect = trackRef.current.getBoundingClientRect();
45
+ const ratio = orientation === "vertical" ? 1 - (clientY - rect.top) / rect.height : (clientX - rect.left) / rect.width;
46
+ return min + Math.min(1, Math.max(0, ratio)) * (max - min);
47
+ },
48
+ [orientation, min, max]
49
+ );
50
+ const update = useCallback(
51
+ (next) => {
52
+ const [s, e] = next[0] > next[1] ? [next[1], next[0]] : next;
53
+ setValues((prev) => {
54
+ if (prev[0] === s && prev[1] === e) return prev;
55
+ onChange?.(range ? [s, e] : e);
56
+ return [s, e];
57
+ });
58
+ },
59
+ [onChange, range]
60
+ );
61
+ const attachDragListeners = (target, e, rangeOffset) => {
62
+ if (disabled) return;
63
+ isDraggingRef.current = true;
64
+ dragTargetRef.current = target;
65
+ isDraggingRangeRef.current = rangeOffset !== void 0;
66
+ if (rangeOffset !== void 0) rangeOffsetRef.current = rangeOffset;
67
+ setIsDragging(true);
68
+ e.target?.setPointerCapture?.(e.pointerId);
69
+ const onMove = (ev) => {
70
+ if (!isDraggingRef.current || !trackRef.current) return;
71
+ ev.preventDefault();
72
+ const raw = getRawValue(ev.clientX, ev.clientY);
73
+ const current = valuesRef.current;
74
+ if (isDraggingRangeRef.current) {
75
+ const rangeSize = current[1] - current[0];
76
+ const newStart = snap(raw - rangeOffsetRef.current);
77
+ let finalStart = clamp(newStart);
78
+ let finalEnd = clamp(finalStart + rangeSize);
79
+ if (finalEnd > max) {
80
+ finalEnd = max;
81
+ finalStart = clamp(max - rangeSize);
82
+ }
83
+ update([finalStart, finalEnd]);
84
+ } else if (target === "start") {
85
+ update([snap(raw), current[1]]);
86
+ } else if (target === "end") {
87
+ update([current[0], snap(raw)]);
88
+ }
89
+ };
90
+ const onUp = () => {
91
+ isDraggingRef.current = false;
92
+ dragTargetRef.current = null;
93
+ isDraggingRangeRef.current = false;
94
+ setIsDragging(false);
95
+ window.removeEventListener("pointermove", onMove);
96
+ window.removeEventListener("pointerup", onUp);
97
+ window.removeEventListener("pointercancel", onUp);
98
+ };
99
+ window.addEventListener("pointermove", onMove);
100
+ window.addEventListener("pointerup", onUp);
101
+ window.addEventListener("pointercancel", onUp);
102
+ };
103
+ const onPointerDownThumb = useCallback(
104
+ (target, e) => {
105
+ if (disabled) return;
106
+ attachDragListeners(target, e.nativeEvent);
107
+ },
108
+ [disabled, attachDragListeners]
109
+ );
110
+ const onPointerDownTrack = useCallback(
111
+ (e) => {
112
+ if (disabled) return;
113
+ const nativeEvent = e.nativeEvent;
114
+ const raw = getRawValue(nativeEvent.clientX, nativeEvent.clientY);
115
+ const current = valuesRef.current;
116
+ if (draggableTrack && range && raw >= current[0] && raw <= current[1]) {
117
+ if (trackRef.current)
118
+ trackRef.current.setPointerCapture(nativeEvent.pointerId);
119
+ const offset = raw - current[0];
120
+ attachDragListeners(null, nativeEvent, offset);
121
+ return;
122
+ }
123
+ const snapped = snap(raw);
124
+ if (range) {
125
+ const distStart = Math.abs(snapped - current[0]);
126
+ const distEnd = Math.abs(snapped - current[1]);
127
+ const target = distStart <= distEnd ? "start" : "end";
128
+ update(
129
+ target === "start" ? [snapped, current[1]] : [current[0], snapped]
130
+ );
131
+ } else {
132
+ update([snapped, snapped]);
133
+ }
134
+ },
135
+ [
136
+ disabled,
137
+ getRawValue,
138
+ draggableTrack,
139
+ range,
140
+ snap,
141
+ update,
142
+ attachDragListeners
143
+ ]
144
+ );
145
+ const onKeyDown = useCallback(
146
+ (target, e) => {
147
+ if (disabled) return;
148
+ const pageStep = Math.max(step, (max - min) / 10);
149
+ let delta = 0;
150
+ switch (e.key) {
151
+ case "ArrowUp":
152
+ case "ArrowRight":
153
+ delta = step;
154
+ break;
155
+ case "ArrowDown":
156
+ case "ArrowLeft":
157
+ delta = -step;
158
+ break;
159
+ case "Home":
160
+ delta = min - values[target === "start" ? 0 : 1];
161
+ break;
162
+ case "End":
163
+ delta = max - values[target === "start" ? 0 : 1];
164
+ break;
165
+ case "PageUp":
166
+ delta = pageStep;
167
+ break;
168
+ case "PageDown":
169
+ delta = -pageStep;
170
+ break;
171
+ default:
172
+ return;
173
+ }
174
+ e.preventDefault();
175
+ const current = values[target === "start" ? 0 : 1];
176
+ const newVal = snap(current + delta);
177
+ update(target === "start" ? [newVal, values[1]] : [values[0], newVal]);
178
+ },
179
+ [disabled, values, step, min, max, snap, update]
180
+ );
181
+ return {
182
+ values,
183
+ trackRef,
184
+ percentStart: percentOf(values[0]),
185
+ percentEnd: percentOf(values[1]),
186
+ onPointerDownThumb,
187
+ onPointerDownTrack,
188
+ onKeyDown,
189
+ isDragging
190
+ };
191
+ };
192
+ export {
193
+ useSlider
194
+ };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const StepperContext = require("./StepperContext.cjs.js");
6
+ const styles = require("./styles.cjs.js");
7
+ const StepContent = require("./StepContent.cjs.js");
8
+ const DefaultStepIcon = ({ index, completed, error, icon }) => {
9
+ if (icon) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: icon });
10
+ if (completed) return /* @__PURE__ */ jsxRuntime.jsx("span", { children: "✓" });
11
+ if (error) return /* @__PURE__ */ jsxRuntime.jsx("span", { children: "!" });
12
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { children: index });
13
+ };
14
+ const Step = (props) => {
15
+ const context = StepperContext.useStepperContext();
16
+ const index = props.index ?? 0;
17
+ const isActive = context.activeStep === index;
18
+ const isCompleted = props.completed ?? context.activeStep > index;
19
+ const isLast = props.last ?? false;
20
+ const handleClick = (event) => {
21
+ if (props.disabled) return;
22
+ if (!isActive) {
23
+ props.onClick?.(event);
24
+ context.onStepClick?.(index);
25
+ }
26
+ };
27
+ const iconProps = {
28
+ index: index + 1,
29
+ active: isActive,
30
+ completed: isCompleted,
31
+ error: props.error,
32
+ icon: props.icon
33
+ };
34
+ const connectorElement = React.useMemo(() => {
35
+ if (isLast || !React.isValidElement(context.connector))
36
+ return null;
37
+ return React.cloneElement(context.connector, {
38
+ orientation: context.orientation,
39
+ completed: isCompleted,
40
+ active: isActive
41
+ });
42
+ }, [context.connector, context.orientation, isCompleted, isActive, isLast]);
43
+ const extendedContext = {
44
+ ...context,
45
+ __stepActive: isActive,
46
+ __stepCompleted: isCompleted
47
+ };
48
+ const childrenArray = React.Children.toArray(props.children);
49
+ const contentChildren = childrenArray.filter(
50
+ (child) => React.isValidElement(child) && child.type === StepContent.StepContent
51
+ );
52
+ const headerChildren = childrenArray.filter(
53
+ (child) => !React.isValidElement(child) || child.type !== StepContent.StepContent
54
+ );
55
+ const renderMiddleBlock = () => /* @__PURE__ */ jsxRuntime.jsxs(styles.StepMiddleBlock, { orientation: context.orientation, children: [
56
+ React.Children.map(
57
+ headerChildren,
58
+ (child, i) => React.isValidElement(child) ? React.cloneElement(child, { key: i }) : child
59
+ ),
60
+ contentChildren.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: React.Children.map(
61
+ contentChildren,
62
+ (child, i) => React.isValidElement(child) ? React.cloneElement(child, { key: i }) : child
63
+ ) })
64
+ ] });
65
+ const renderConnector = () => connectorElement && /* @__PURE__ */ jsxRuntime.jsx(
66
+ styles.ConnectorContainerStyled,
67
+ {
68
+ orientation: context.orientation,
69
+ children: connectorElement
70
+ }
71
+ );
72
+ return /* @__PURE__ */ jsxRuntime.jsx(
73
+ styles.StepContainerStyled,
74
+ {
75
+ className: props.className,
76
+ orientation: context.orientation,
77
+ active: isActive,
78
+ completed: isCompleted,
79
+ disabled: props.disabled,
80
+ clickable: !!props.onClick,
81
+ onClick: handleClick,
82
+ children: /* @__PURE__ */ jsxRuntime.jsx(StepperContext.StepperContext.Provider, { value: extendedContext, children: context.orientation === "horizontal" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
83
+ /* @__PURE__ */ jsxRuntime.jsx(
84
+ styles.StepIconWrapper,
85
+ {
86
+ className: "step-icon-wrapper",
87
+ active: isActive,
88
+ completed: isCompleted,
89
+ error: props.error,
90
+ children: /* @__PURE__ */ jsxRuntime.jsx(DefaultStepIcon, { ...iconProps })
91
+ }
92
+ ),
93
+ renderMiddleBlock(),
94
+ renderConnector()
95
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
96
+ /* @__PURE__ */ jsxRuntime.jsxs(styles.LeftColumnStyled, { children: [
97
+ /* @__PURE__ */ jsxRuntime.jsx(
98
+ styles.StepIconWrapper,
99
+ {
100
+ className: "step-icon-wrapper",
101
+ active: isActive,
102
+ completed: isCompleted,
103
+ error: props.error,
104
+ children: /* @__PURE__ */ jsxRuntime.jsx(DefaultStepIcon, { ...iconProps })
105
+ }
106
+ ),
107
+ renderConnector()
108
+ ] }),
109
+ renderMiddleBlock()
110
+ ] }) })
111
+ }
112
+ );
113
+ };
114
+ exports.Step = Step;
@@ -0,0 +1,2 @@
1
+ import { IStepProps } from './types';
2
+ export declare const Step: (props: IStepProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,114 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useMemo, isValidElement, cloneElement, Children } from "react";
3
+ import { useStepperContext, StepperContext } from "./StepperContext.es.js";
4
+ import { StepContainerStyled, StepIconWrapper, LeftColumnStyled, StepMiddleBlock, ConnectorContainerStyled } from "./styles.es.js";
5
+ import { StepContent } from "./StepContent.es.js";
6
+ const DefaultStepIcon = ({ index, completed, error, icon }) => {
7
+ if (icon) return /* @__PURE__ */ jsx(Fragment, { children: icon });
8
+ if (completed) return /* @__PURE__ */ jsx("span", { children: "✓" });
9
+ if (error) return /* @__PURE__ */ jsx("span", { children: "!" });
10
+ return /* @__PURE__ */ jsx("span", { children: index });
11
+ };
12
+ const Step = (props) => {
13
+ const context = useStepperContext();
14
+ const index = props.index ?? 0;
15
+ const isActive = context.activeStep === index;
16
+ const isCompleted = props.completed ?? context.activeStep > index;
17
+ const isLast = props.last ?? false;
18
+ const handleClick = (event) => {
19
+ if (props.disabled) return;
20
+ if (!isActive) {
21
+ props.onClick?.(event);
22
+ context.onStepClick?.(index);
23
+ }
24
+ };
25
+ const iconProps = {
26
+ index: index + 1,
27
+ active: isActive,
28
+ completed: isCompleted,
29
+ error: props.error,
30
+ icon: props.icon
31
+ };
32
+ const connectorElement = useMemo(() => {
33
+ if (isLast || !isValidElement(context.connector))
34
+ return null;
35
+ return cloneElement(context.connector, {
36
+ orientation: context.orientation,
37
+ completed: isCompleted,
38
+ active: isActive
39
+ });
40
+ }, [context.connector, context.orientation, isCompleted, isActive, isLast]);
41
+ const extendedContext = {
42
+ ...context,
43
+ __stepActive: isActive,
44
+ __stepCompleted: isCompleted
45
+ };
46
+ const childrenArray = Children.toArray(props.children);
47
+ const contentChildren = childrenArray.filter(
48
+ (child) => isValidElement(child) && child.type === StepContent
49
+ );
50
+ const headerChildren = childrenArray.filter(
51
+ (child) => !isValidElement(child) || child.type !== StepContent
52
+ );
53
+ const renderMiddleBlock = () => /* @__PURE__ */ jsxs(StepMiddleBlock, { orientation: context.orientation, children: [
54
+ Children.map(
55
+ headerChildren,
56
+ (child, i) => isValidElement(child) ? cloneElement(child, { key: i }) : child
57
+ ),
58
+ contentChildren.length > 0 && /* @__PURE__ */ jsx("div", { children: Children.map(
59
+ contentChildren,
60
+ (child, i) => isValidElement(child) ? cloneElement(child, { key: i }) : child
61
+ ) })
62
+ ] });
63
+ const renderConnector = () => connectorElement && /* @__PURE__ */ jsx(
64
+ ConnectorContainerStyled,
65
+ {
66
+ orientation: context.orientation,
67
+ children: connectorElement
68
+ }
69
+ );
70
+ return /* @__PURE__ */ jsx(
71
+ StepContainerStyled,
72
+ {
73
+ className: props.className,
74
+ orientation: context.orientation,
75
+ active: isActive,
76
+ completed: isCompleted,
77
+ disabled: props.disabled,
78
+ clickable: !!props.onClick,
79
+ onClick: handleClick,
80
+ children: /* @__PURE__ */ jsx(StepperContext.Provider, { value: extendedContext, children: context.orientation === "horizontal" ? /* @__PURE__ */ jsxs(Fragment, { children: [
81
+ /* @__PURE__ */ jsx(
82
+ StepIconWrapper,
83
+ {
84
+ className: "step-icon-wrapper",
85
+ active: isActive,
86
+ completed: isCompleted,
87
+ error: props.error,
88
+ children: /* @__PURE__ */ jsx(DefaultStepIcon, { ...iconProps })
89
+ }
90
+ ),
91
+ renderMiddleBlock(),
92
+ renderConnector()
93
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
94
+ /* @__PURE__ */ jsxs(LeftColumnStyled, { children: [
95
+ /* @__PURE__ */ jsx(
96
+ StepIconWrapper,
97
+ {
98
+ className: "step-icon-wrapper",
99
+ active: isActive,
100
+ completed: isCompleted,
101
+ error: props.error,
102
+ children: /* @__PURE__ */ jsx(DefaultStepIcon, { ...iconProps })
103
+ }
104
+ ),
105
+ renderConnector()
106
+ ] }),
107
+ renderMiddleBlock()
108
+ ] }) })
109
+ }
110
+ );
111
+ };
112
+ export {
113
+ Step
114
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const styles = require("./styles.cjs.js");
5
+ const StepperContext = require("./StepperContext.cjs.js");
6
+ const StepContent = ({ children }) => {
7
+ const context = StepperContext.useStepperContext();
8
+ return /* @__PURE__ */ jsxRuntime.jsx(styles.StepContentContainerStyled, { orientation: context.orientation, children });
9
+ };
10
+ exports.StepContent = StepContent;
@@ -0,0 +1,4 @@
1
+ import { ReactNode } from 'react';
2
+ export declare const StepContent: ({ children }: {
3
+ children?: ReactNode;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { StepContentContainerStyled } from "./styles.es.js";
3
+ import { useStepperContext } from "./StepperContext.es.js";
4
+ const StepContent = ({ children }) => {
5
+ const context = useStepperContext();
6
+ return /* @__PURE__ */ jsx(StepContentContainerStyled, { orientation: context.orientation, children });
7
+ };
8
+ export {
9
+ StepContent
10
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const styles = require("./styles.cjs.js");
5
+ const StepperContext = require("./StepperContext.cjs.js");
6
+ const Text = require("../typography/Text/Text.cjs.js");
7
+ const StepLabel = ({
8
+ children,
9
+ optional,
10
+ error,
11
+ className
12
+ }) => {
13
+ const context = StepperContext.useStepperContext();
14
+ return /* @__PURE__ */ jsxRuntime.jsxs(
15
+ styles.StepLabelContainerStyled,
16
+ {
17
+ className,
18
+ orientation: context.orientation,
19
+ active: context.__stepActive,
20
+ completed: context.__stepCompleted,
21
+ children: [
22
+ /* @__PURE__ */ jsxRuntime.jsx(Text, { size: "l", className: "step-label-text", type: error ? "danger" : void 0, children }),
23
+ optional && /* @__PURE__ */ jsxRuntime.jsx(Text, { size: "s", type: "secondary", children: optional })
24
+ ]
25
+ }
26
+ );
27
+ };
28
+ exports.StepLabel = StepLabel;
@@ -0,0 +1,2 @@
1
+ import { IStepLabelProps } from './types';
2
+ export declare const StepLabel: ({ children, optional, error, className }: IStepLabelProps) => import("react/jsx-runtime").JSX.Element;