funda-ui 4.6.388 → 4.7.101

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,264 @@
1
+ import React, { useRef, useEffect, forwardRef, useImperativeHandle, useState } from 'react';
2
+
3
+ import { clsWrite, combinedCls } from 'funda-utils/dist/cjs/cls';
4
+
5
+ interface StepperPanelProps {
6
+ header: React.ReactNode;
7
+ children?: React.ReactNode;
8
+ style?: React.CSSProperties;
9
+ }
10
+
11
+ interface StepperProps {
12
+ wrapperClassName?: string;
13
+ indicatorClickAllowed?: boolean;
14
+ style?: React.CSSProperties;
15
+ initialStep?: number;
16
+ layout?: 'horizontal' | 'vertical';
17
+ completeIcon?: React.ReactNode;
18
+ disableCompleteIcon?: boolean;
19
+ onChange?: (index: number, isLastStepComplete: boolean) => void;
20
+ children: React.ReactElement<StepperPanelProps>[];
21
+ }
22
+
23
+ interface StepperRef {
24
+ goto: (index: number) => void;
25
+ next: () => void;
26
+ prev: () => void;
27
+ }
28
+
29
+ const StepperPanel: React.FC<StepperPanelProps> = (props) => {
30
+ const {
31
+ header,
32
+ children,
33
+ style
34
+ } = props;
35
+
36
+ return (
37
+ <div className="stepper-panel" style={style}>
38
+ <div className="stepper-panel-header">{header}</div>
39
+ <div className="stepper-panel-content">{children}</div>
40
+ </div>
41
+ );
42
+ };
43
+
44
+ const Stepper = forwardRef<StepperRef, StepperProps>((props, ref) => {
45
+ const {
46
+ wrapperClassName,
47
+ indicatorClickAllowed = false,
48
+ style,
49
+ initialStep = 0,
50
+ layout = 'horizontal',
51
+ completeIcon = <><svg width="20px" height="20px" viewBox="0 0 20 20" fill="none"><path d="M15.3742 5.98559L10.3742 14.9856C9.72664 16.1511 7.97832 15.1798 8.62585 14.0143L13.6258 5.01431C14.2734 3.84876 16.0217 4.82005 15.3742 5.98559Z" fill="#fff"/><path d="M5.1247 9.71907L10.1247 13.7191C11.1659 14.552 9.91646 16.1137 8.87531 15.2808L3.87531 11.2808C2.83415 10.4479 4.08354 8.88615 5.1247 9.71907Z" fill="#fff"/></svg></>,
52
+ disableCompleteIcon = true,
53
+ onChange,
54
+ children
55
+ } = props;
56
+
57
+
58
+ const [isLastStepComplete, setIsLastStepComplete] = useState<boolean>(false);
59
+ const [activeIndex, setActiveIndex] = useState<number>(initialStep);
60
+ const panels = React.Children.toArray(children) as React.ReactElement<StepperPanelProps>[];
61
+ const isVertical: boolean = layout === 'vertical';
62
+ const prevActiveIndexRef = useRef<number>(activeIndex);
63
+ const prevIsLastStepCompleteRef = useRef<boolean>(isLastStepComplete);
64
+
65
+ useImperativeHandle(
66
+ ref,
67
+ () => ({
68
+ goto: (index: number) => {
69
+ if (index >= 0 && index < panels.length) {
70
+ setActiveIndex(index);
71
+ }
72
+ },
73
+ next: () => {
74
+ setActiveIndex((prevState) => {
75
+ const _val = Math.min(prevState + 1, panels.length - 1);
76
+ return _val;
77
+ });
78
+ },
79
+ prev: () => {
80
+ setActiveIndex((prevState) => {
81
+ const _val = Math.max(prevState - 1, 0);
82
+ return _val;
83
+ });
84
+
85
+ setIsLastStepComplete(false);
86
+ },
87
+ setLastStepComplete: (val: boolean) => {
88
+ setIsLastStepComplete(val);
89
+ },
90
+ }),
91
+ [panels.length],
92
+ );
93
+
94
+ const horizontalPanelsGenerator = (): JSX.Element => {
95
+ return <>
96
+ <div className="stepper-header">
97
+ {panels.map((panel, index) => {
98
+ const { header } = panel.props;
99
+ const isActive = index === activeIndex;
100
+ const isCompleted = index < activeIndex || (index === panels.length - 1 && isLastStepComplete);
101
+
102
+ return (
103
+ <React.Fragment key={index}>
104
+ <div
105
+ data-step-index={index}
106
+ className={combinedCls(
107
+ 'step-item',
108
+ {
109
+ 'step-item--clickable': indicatorClickAllowed && !isLastStepComplete
110
+ }
111
+ )}
112
+ onClick={indicatorClickAllowed && !isLastStepComplete ? () => {
113
+ setActiveIndex(index);
114
+ setIsLastStepComplete(false);
115
+ } : undefined}
116
+ >
117
+ <div
118
+ className={combinedCls(
119
+ 'step-indicator',
120
+ {
121
+ 'step-indicator--active': isActive,
122
+ 'step-indicator--complete': isCompleted
123
+ }
124
+ )}
125
+ >
126
+ {isCompleted ? <>{disableCompleteIcon ? index + 1 : completeIcon}</> : index + 1}
127
+ </div>
128
+ <div
129
+ className={combinedCls(
130
+ 'step-title',
131
+ {
132
+ 'step-title--active': isActive
133
+ }
134
+ )}
135
+ >
136
+ {header}
137
+ </div>
138
+ </div>
139
+ {index < panels.length - 1 && (
140
+ <div
141
+ className={combinedCls(
142
+ 'step-line',
143
+ {
144
+ 'step-line--active': index === activeIndex - 1,
145
+ 'step-line--complete': index < activeIndex - 1
146
+ }
147
+ )}
148
+ />
149
+ )}
150
+ </React.Fragment>
151
+ );
152
+ })}
153
+ </div>
154
+
155
+ <div className="stepper-panels">
156
+ {panels[activeIndex]}
157
+ </div>
158
+ </>;
159
+ };
160
+
161
+ const verticalPanelsGenerator = (): JSX.Element => {
162
+ return <>
163
+ {panels.map((panel, index) => {
164
+ const { header } = panel.props;
165
+ const isActive = index === activeIndex;
166
+ const isCompleted = index < activeIndex || (index === panels.length - 1 && isLastStepComplete);
167
+
168
+ return (
169
+ <div key={index} className="vertical-step-row">
170
+ {/* Left */}
171
+ <div className="vertical-step-left">
172
+ <div
173
+ data-step-index={index}
174
+ className={combinedCls(
175
+ 'step-item',
176
+ {
177
+ 'step-item--clickable': indicatorClickAllowed && !isLastStepComplete
178
+ }
179
+ )}
180
+ onClick={indicatorClickAllowed && !isLastStepComplete ? () => {
181
+ setActiveIndex(index);
182
+ setIsLastStepComplete(false);
183
+ } : undefined}
184
+ >
185
+ <div
186
+ className={combinedCls(
187
+ 'step-indicator',
188
+ {
189
+ 'step-indicator--active': isActive,
190
+ 'step-indicator--complete': isCompleted
191
+ }
192
+ )}
193
+ >
194
+ {isCompleted ? <>{disableCompleteIcon ? index + 1 : completeIcon}</> : index + 1}
195
+ </div>
196
+ <div
197
+ className={combinedCls(
198
+ 'step-title',
199
+ {
200
+ 'step-title--active': isActive
201
+ }
202
+ )}
203
+ >
204
+ {header}
205
+ </div>
206
+ </div>
207
+
208
+ {index < panels.length - 1 && (
209
+ <div
210
+ className={combinedCls(
211
+ 'step-line',
212
+ {
213
+ 'step-line--active': index === activeIndex - 1,
214
+ 'step-line--complete': index < activeIndex - 1
215
+ }
216
+ )}
217
+ />
218
+ )}
219
+ </div>
220
+
221
+ {/* Right */}
222
+ {isActive && (
223
+ <div className="vertical-step-right">
224
+ {panels[activeIndex]}
225
+ </div>
226
+ )}
227
+ </div>
228
+ );
229
+ })}
230
+ </>;
231
+ };
232
+
233
+
234
+ useEffect(() => {
235
+ // Only trigger onChange if values actually changed from previous values
236
+ if (prevActiveIndexRef.current !== activeIndex ||
237
+ prevIsLastStepCompleteRef.current !== isLastStepComplete) {
238
+
239
+ prevActiveIndexRef.current = activeIndex;
240
+ prevIsLastStepCompleteRef.current = isLastStepComplete;
241
+
242
+ onChange?.(activeIndex, isLastStepComplete);
243
+ }
244
+ }, [activeIndex, isLastStepComplete]);
245
+
246
+ return (
247
+ <div
248
+ className={combinedCls(
249
+ 'stepper-container',
250
+ clsWrite(wrapperClassName, ''),
251
+ {
252
+ 'stepper-container--vertical': isVertical
253
+ }
254
+ )}
255
+ style={style}
256
+ >
257
+ {!isVertical && horizontalPanelsGenerator()}
258
+ {isVertical && verticalPanelsGenerator()}
259
+ </div>
260
+ );
261
+ });
262
+
263
+ export { Stepper, StepperPanel };
264
+ export type { StepperProps, StepperPanelProps, StepperRef };
@@ -330,7 +330,7 @@
330
330
  min-width: auto !important;
331
331
  width: auto !important;
332
332
 
333
- &:not(last-child) {
333
+ &:not(:last-child) {
334
334
  border-bottom: 0;
335
335
  }
336
336
 
@@ -390,7 +390,7 @@
390
390
  border-top: 0;
391
391
  }
392
392
 
393
- &:not(last-child) {
393
+ &:not(:last-child) {
394
394
  border-bottom: 0;
395
395
  border-right: 0;
396
396
  }
@@ -7,6 +7,7 @@ import { clsWrite, combinedCls } from 'funda-utils/dist/cjs/cls';
7
7
  import { actualPropertyValue, getTextTop } from 'funda-utils/dist/cjs/inputsCalculation';
8
8
  import useDebounce from 'funda-utils/dist/cjs/useDebounce';
9
9
 
10
+
10
11
  export type TextareaProps = {
11
12
  contentRef?: React.ForwardedRef<any>; // could use "Array" on contentRef.current, such as contentRef.current[0], contentRef.current[1]
12
13
  wrapperClassName?: string;
package/lib/esm/index.js CHANGED
@@ -33,6 +33,7 @@ export { default as Scrollbar } from './Scrollbar';
33
33
  export { default as SearchBar } from './SearchBar';
34
34
  export { default as Select } from './Select';
35
35
  export { default as ShowMoreLess } from './ShowMoreLess';
36
+ export { default as Stepper } from './Stepper';
36
37
  export { default as Switch } from './Switch';
37
38
  export { default as Table } from './Table';
38
39
  export { default as Tabs } from './Tabs';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "UIUX Lab",
3
3
  "email": "uiuxlab@gmail.com",
4
4
  "name": "funda-ui",
5
- "version": "4.6.388",
5
+ "version": "4.7.101",
6
6
  "description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
7
7
  "repository": {
8
8
  "type": "git",