gbs-add-block 0.0.45 → 0.0.46
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.
- package/README.md +4 -3
- package/index.js +0 -18
- package/package.json +1 -1
- package/source/components/datepicker/index.tsx +87 -72
- package/source/components/formrenderer/{CheckBoxHandles.tsx → componentHandles/CheckBoxHandles.tsx} +1 -1
- package/source/components/formrenderer/{DatePickerHandles.tsx → componentHandles/DatePickerHandles.tsx} +2 -2
- package/source/components/formrenderer/{InputHandles.tsx → componentHandles/InputHandles.tsx} +3 -3
- package/source/components/formrenderer/{MultiHandles.tsx → componentHandles/MultiHandles.tsx} +2 -2
- package/source/components/formrenderer/{SelectHandles.tsx → componentHandles/SelectHandles.tsx} +1 -1
- package/source/components/formrenderer/index.tsx +6 -6
- package/source/components/multiselect/index.tsx +7 -3
- package/source/components/select/{Select.tsx → index.tsx} +11 -5
- package/source/components/datepicker/DatePickerHelper.ts +0 -42
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# GBS Building Blocks 2.0 (v0.0.
|
|
1
|
+
# GBS Building Blocks 2.0 (v0.0.46)
|
|
2
2
|
|
|
3
3
|
Latest and upgraded version of GBS building blocks with headless UI and removed dependencies.
|
|
4
4
|
|
|
@@ -6,9 +6,10 @@ Latest and upgraded version of GBS building blocks with headless UI and removed
|
|
|
6
6
|
|
|
7
7
|
For detailed documentation on usage and props, Please visit: [Building Block Documentation v2.0](https://blackmax-designs.gitbook.io/building-block-v2.0)
|
|
8
8
|
|
|
9
|
-
## What's New 🎉 (Ver 0.0.
|
|
9
|
+
## What's New 🎉 (Ver 0.0.46)
|
|
10
10
|
|
|
11
|
-
- Refactored Code for Better Readability
|
|
11
|
+
- Refactored Code for Better Readability
|
|
12
|
+
- Code Reusablity and hook update
|
|
12
13
|
|
|
13
14
|
## Authors
|
|
14
15
|
|
package/index.js
CHANGED
|
@@ -70,20 +70,6 @@ const copyCommonFiles = async (destPath) => {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
const copySelectionHooks = async (destPath) => {
|
|
74
|
-
const hooksSrc = path.join(SOURCE_PATH, "..", "hooks", "SelectionHooks");
|
|
75
|
-
const hooksDest = path.join(destPath, "hooks", "SelectionHooks");
|
|
76
|
-
|
|
77
|
-
await fs.ensureDir(path.dirname(hooksDest));
|
|
78
|
-
|
|
79
|
-
if (!fs.existsSync(hooksSrc)) {
|
|
80
|
-
throw new Error(`SelectionHooks not found at ${hooksSrc}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
await fs.copy(hooksSrc, hooksDest, { overwrite: true });
|
|
84
|
-
console.log(`SelectionHooks copied successfully to ${hooksDest}`);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
73
|
const copyComponent = async (component, destPath) => {
|
|
88
74
|
try {
|
|
89
75
|
const componentSrc = path.join(SOURCE_PATH, component.toLowerCase());
|
|
@@ -103,10 +89,6 @@ const copyComponent = async (component, destPath) => {
|
|
|
103
89
|
isFirstCopy = false;
|
|
104
90
|
}
|
|
105
91
|
|
|
106
|
-
if (["Select", "MultiSelect"].includes(component)) {
|
|
107
|
-
await copySelectionHooks(destPath);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
92
|
console.log(`\nFor Props and Usage Guides Visit: ${CONFIG.docs}\n`);
|
|
111
93
|
} catch (error) {
|
|
112
94
|
console.error(`Error copying component ${component}:`, error.message);
|
package/package.json
CHANGED
|
@@ -5,8 +5,15 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {
|
|
9
|
-
import {
|
|
8
|
+
import React, { useRef } from "react";
|
|
9
|
+
import {
|
|
10
|
+
useDatePickerState,
|
|
11
|
+
useYearMonthNavigation,
|
|
12
|
+
useClickOutside,
|
|
13
|
+
isAtYearLimit,
|
|
14
|
+
months,
|
|
15
|
+
applyScrollbarStyles,
|
|
16
|
+
} from "@grampro/headless-helpers";
|
|
10
17
|
import Icon from "../icon/Icon";
|
|
11
18
|
import { calender, down, leftArrows, rightArrows } from "../icon/iconPaths";
|
|
12
19
|
import type { DatePickerProps } from "./types";
|
|
@@ -23,59 +30,51 @@ export const DatePicker = ({
|
|
|
23
30
|
error,
|
|
24
31
|
placeholder = "Select a date",
|
|
25
32
|
}: DatePickerProps) => {
|
|
26
|
-
|
|
27
|
-
const [showYearMonthPicker, setShowYearMonthPicker] = useState(false);
|
|
28
|
-
const [currentMonth, setCurrentMonth] = useState(new Date().getMonth());
|
|
29
|
-
const [currentYear, setCurrentYear] = useState(new Date().getFullYear());
|
|
30
|
-
const [days, setDays] = useState<(Date | null)[][]>([]);
|
|
31
|
-
const [selectedDate, setSelectedDate] = useState<Date | null>(
|
|
32
|
-
selectedDateValue || null
|
|
33
|
-
);
|
|
34
|
-
const [tempSelectedDate, setTempSelectedDate] = useState<Date | null>(
|
|
35
|
-
selectedDateValue || new Date()
|
|
36
|
-
);
|
|
37
|
-
const [hasMounted, setHasMounted] = useState(false);
|
|
33
|
+
applyScrollbarStyles();
|
|
38
34
|
|
|
39
35
|
const dateRef = useRef<HTMLDivElement>(null);
|
|
40
36
|
const today = new Date();
|
|
41
|
-
|
|
42
37
|
const actualCurrentYear = today.getFullYear();
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
showDatepicker,
|
|
41
|
+
setShowDatepicker,
|
|
42
|
+
showYearMonthPicker,
|
|
43
|
+
setShowYearMonthPicker,
|
|
44
|
+
currentMonth,
|
|
45
|
+
setCurrentMonth,
|
|
46
|
+
currentYear,
|
|
47
|
+
setCurrentYear,
|
|
48
|
+
days,
|
|
49
|
+
selectedDate,
|
|
50
|
+
setSelectedDate,
|
|
51
|
+
tempSelectedDate,
|
|
52
|
+
setTempSelectedDate,
|
|
53
|
+
hasMounted,
|
|
54
|
+
} = useDatePickerState(selectedDateValue || null);
|
|
55
|
+
|
|
56
|
+
const { prevMonth, nextMonth } = useYearMonthNavigation(
|
|
57
|
+
currentMonth,
|
|
58
|
+
currentYear,
|
|
59
|
+
yearLimitStart,
|
|
60
|
+
yearLimitEnd,
|
|
61
|
+
setCurrentMonth,
|
|
62
|
+
setCurrentYear
|
|
63
|
+
);
|
|
64
|
+
useClickOutside(
|
|
65
|
+
dateRef as React.RefObject<HTMLElement>,
|
|
66
|
+
() => {
|
|
67
|
+
setShowDatepicker(false);
|
|
68
|
+
setTempSelectedDate(selectedDate || new Date());
|
|
69
|
+
},
|
|
70
|
+
[selectedDate]
|
|
71
|
+
);
|
|
72
|
+
|
|
43
73
|
const years = Array.from(
|
|
44
74
|
{ length: yearLimitStart + yearLimitEnd + 1 },
|
|
45
75
|
(_, i) => actualCurrentYear - yearLimitStart + i
|
|
46
76
|
).sort((a, b) => b - a);
|
|
47
77
|
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (selectedDateValue) {
|
|
50
|
-
setSelectedDate(selectedDateValue);
|
|
51
|
-
setTempSelectedDate(selectedDateValue);
|
|
52
|
-
setCurrentMonth(selectedDateValue.getMonth());
|
|
53
|
-
setCurrentYear(selectedDateValue.getFullYear());
|
|
54
|
-
}
|
|
55
|
-
}, [selectedDateValue]);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
setHasMounted(true);
|
|
59
|
-
}, []);
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
function handleClickOutside(event: MouseEvent) {
|
|
63
|
-
if (dateRef.current && !dateRef.current.contains(event.target as Node)) {
|
|
64
|
-
setShowDatepicker(false);
|
|
65
|
-
setTempSelectedDate(selectedDate || new Date());
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
70
|
-
return () => {
|
|
71
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
72
|
-
};
|
|
73
|
-
}, [selectedDate]);
|
|
74
|
-
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
setDays(generateCalendarHelper(currentYear, currentMonth));
|
|
77
|
-
}, [currentYear, currentMonth]);
|
|
78
|
-
|
|
79
78
|
const toggleDatepicker = () => {
|
|
80
79
|
setShowDatepicker(!showDatepicker);
|
|
81
80
|
setShowYearMonthPicker(false);
|
|
@@ -102,25 +101,6 @@ export const DatePicker = ({
|
|
|
102
101
|
setCurrentYear(year);
|
|
103
102
|
setCurrentMonth(month);
|
|
104
103
|
setShowYearMonthPicker(false);
|
|
105
|
-
setDays(generateCalendarHelper(year, month));
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const prevMonth = () => {
|
|
109
|
-
if (currentMonth === 0) {
|
|
110
|
-
setCurrentMonth(11);
|
|
111
|
-
setCurrentYear(currentYear - 1);
|
|
112
|
-
} else {
|
|
113
|
-
setCurrentMonth(currentMonth - 1);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const nextMonth = () => {
|
|
118
|
-
if (currentMonth === 11) {
|
|
119
|
-
setCurrentMonth(0);
|
|
120
|
-
setCurrentYear(currentYear + 1);
|
|
121
|
-
} else {
|
|
122
|
-
setCurrentMonth(currentMonth + 1);
|
|
123
|
-
}
|
|
124
104
|
};
|
|
125
105
|
|
|
126
106
|
const goToToday = () => {
|
|
@@ -157,7 +137,6 @@ export const DatePicker = ({
|
|
|
157
137
|
</button>
|
|
158
138
|
{error && <p className={primary["error-primary"]}>{error}</p>}
|
|
159
139
|
|
|
160
|
-
{/* Hidden input to integrate with the form */}
|
|
161
140
|
<input
|
|
162
141
|
type="hidden"
|
|
163
142
|
name={name}
|
|
@@ -171,11 +150,28 @@ export const DatePicker = ({
|
|
|
171
150
|
<button
|
|
172
151
|
type="button"
|
|
173
152
|
onClick={prevMonth}
|
|
174
|
-
|
|
153
|
+
disabled={isAtYearLimit(
|
|
154
|
+
"prev",
|
|
155
|
+
currentMonth,
|
|
156
|
+
currentYear,
|
|
157
|
+
yearLimitStart,
|
|
158
|
+
yearLimitEnd
|
|
159
|
+
)}
|
|
160
|
+
className={`text-gray-500 hover:text-gray-700 w-8 h-8 rounded-full flex items-center justify-center hover:bg-gray-100 ${
|
|
161
|
+
isAtYearLimit(
|
|
162
|
+
"prev",
|
|
163
|
+
currentMonth,
|
|
164
|
+
currentYear,
|
|
165
|
+
yearLimitStart,
|
|
166
|
+
yearLimitEnd
|
|
167
|
+
)
|
|
168
|
+
? "opacity-50"
|
|
169
|
+
: ""
|
|
170
|
+
}`}
|
|
175
171
|
>
|
|
176
172
|
<Icon
|
|
177
173
|
elements={leftArrows}
|
|
178
|
-
svgClass={"stroke-
|
|
174
|
+
svgClass={"stroke-black fill-none dark:stroke-white"}
|
|
179
175
|
/>
|
|
180
176
|
</button>
|
|
181
177
|
<div className="flex items-center space-x-2">
|
|
@@ -199,7 +195,24 @@ export const DatePicker = ({
|
|
|
199
195
|
<button
|
|
200
196
|
type="button"
|
|
201
197
|
onClick={nextMonth}
|
|
202
|
-
|
|
198
|
+
disabled={isAtYearLimit(
|
|
199
|
+
"next",
|
|
200
|
+
currentMonth,
|
|
201
|
+
currentYear,
|
|
202
|
+
yearLimitStart,
|
|
203
|
+
yearLimitEnd
|
|
204
|
+
)}
|
|
205
|
+
className={`text-gray-500 hover:text-gray-700 w-8 h-8 rounded-full flex items-center justify-center hover:bg-gray-100 ${
|
|
206
|
+
isAtYearLimit(
|
|
207
|
+
"next",
|
|
208
|
+
currentMonth,
|
|
209
|
+
currentYear,
|
|
210
|
+
yearLimitStart,
|
|
211
|
+
yearLimitEnd
|
|
212
|
+
)
|
|
213
|
+
? "opacity-50"
|
|
214
|
+
: ""
|
|
215
|
+
}`}
|
|
203
216
|
>
|
|
204
217
|
<Icon
|
|
205
218
|
elements={rightArrows}
|
|
@@ -219,7 +232,7 @@ export const DatePicker = ({
|
|
|
219
232
|
onClick={() => selectYearMonth(currentYear, index)}
|
|
220
233
|
className={`w-full text-left p-2 cursor-pointer rounded hover:bg-gray-200 transition duration-150 ease-in-out ${
|
|
221
234
|
index === currentMonth
|
|
222
|
-
? "bg-
|
|
235
|
+
? "bg-black text-white hover:bg-blue-600"
|
|
223
236
|
: ""
|
|
224
237
|
}`}
|
|
225
238
|
>
|
|
@@ -238,7 +251,7 @@ export const DatePicker = ({
|
|
|
238
251
|
onClick={() => selectYearMonth(year, currentMonth)}
|
|
239
252
|
className={`w-full text-left p-2 cursor-pointer rounded hover:bg-gray-200 transition duration-150 ease-in-out ${
|
|
240
253
|
year === currentYear
|
|
241
|
-
? "bg-
|
|
254
|
+
? "bg-black text-white hover:bg-blue-600"
|
|
242
255
|
: ""
|
|
243
256
|
}`}
|
|
244
257
|
>
|
|
@@ -277,7 +290,9 @@ export const DatePicker = ({
|
|
|
277
290
|
onClick={() => !isDisabled && selectDate(day)}
|
|
278
291
|
disabled={isDisabled}
|
|
279
292
|
className={`text-center p-1 w-8 h-8 cursor-pointer rounded-md hover:bg-gray-200 transition duration-150 ease-in-out ${
|
|
280
|
-
isSelected
|
|
293
|
+
isSelected
|
|
294
|
+
? "bg-black text-white hover:bg-gray-800 dark:bg-white"
|
|
295
|
+
: ""
|
|
281
296
|
} ${
|
|
282
297
|
isDisabled
|
|
283
298
|
? "bg-gray-100 text-gray-400 cursor-not-allowed"
|
package/source/components/formrenderer/{InputHandles.tsx → componentHandles/InputHandles.tsx}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { validateEmail, validatePhoneNumber } from "
|
|
3
|
-
import { Input } from "
|
|
4
|
-
import { FieldValue, FormContext, FormItem } from "
|
|
2
|
+
import { validateEmail, validatePhoneNumber } from "../helperFunctions";
|
|
3
|
+
import { Input } from "../../input";
|
|
4
|
+
import { FieldValue, FormContext, FormItem } from "../types";
|
|
5
5
|
import { evaluateExpression } from "@grampro/expression-evaluator";
|
|
6
6
|
import { twMerge } from "tailwind-merge";
|
|
7
7
|
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React, { useRef, useState } from "react";
|
|
9
|
-
import InputHandles from "./InputHandles";
|
|
10
|
-
import SelectHandles from "./SelectHandles";
|
|
11
|
-
import { FormElement, FormItem, FormRendererProps } from "./types";
|
|
12
|
-
import MultiHandles from "./MultiHandles";
|
|
13
|
-
import DatePickerHandles from "./DatePickerHandles";
|
|
14
|
-
import CheckboxHandles from "./CheckBoxHandles";
|
|
15
9
|
import { useFormContext } from "@grampro/expression-evaluator";
|
|
10
|
+
import { FormElement, FormItem, FormRendererProps } from "./types";
|
|
11
|
+
import InputHandles from "./componentHandles/InputHandles";
|
|
12
|
+
import SelectHandles from "./componentHandles/SelectHandles";
|
|
13
|
+
import MultiHandles from "./componentHandles/MultiHandles";
|
|
14
|
+
import DatePickerHandles from "./componentHandles/DatePickerHandles";
|
|
15
|
+
import CheckboxHandles from "./componentHandles/CheckBoxHandles";
|
|
16
16
|
|
|
17
17
|
const FormRenderer = ({
|
|
18
18
|
onSubmit,
|
|
@@ -13,9 +13,11 @@ import {
|
|
|
13
13
|
memo,
|
|
14
14
|
useImperativeHandle,
|
|
15
15
|
} from "react";
|
|
16
|
-
import { useClickOutside } from "../hooks/SelectionHooks/useClickOutside";
|
|
17
16
|
import type { MultiSelectHandle, MultiSelectProps } from "./types";
|
|
18
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
useMultiSelectState,
|
|
19
|
+
useClickOutside,
|
|
20
|
+
} from "@grampro/headless-helpers";
|
|
19
21
|
import Icon from "../icon/Icon";
|
|
20
22
|
import { check, search, upDown, x } from "../icon/iconPaths";
|
|
21
23
|
import { iconClass, popUp, primary } from "../globalStyle";
|
|
@@ -51,7 +53,9 @@ const MultiSelect = forwardRef<MultiSelectHandle, MultiSelectProps>(
|
|
|
51
53
|
getSelectItems,
|
|
52
54
|
} = useMultiSelectState(items, selectedItems, lazy, onSelect);
|
|
53
55
|
|
|
54
|
-
useClickOutside(selectRef
|
|
56
|
+
useClickOutside(selectRef as React.RefObject<HTMLElement>, () =>
|
|
57
|
+
setShowPopover(false)
|
|
58
|
+
);
|
|
55
59
|
|
|
56
60
|
useEffect(() => {
|
|
57
61
|
if (showPopover) {
|
|
@@ -18,9 +18,11 @@ import { check, search, upDown, x } from "../icon/iconPaths";
|
|
|
18
18
|
import type { SelectHandle, SelectProps } from "./types";
|
|
19
19
|
import { selectStyle } from "./style";
|
|
20
20
|
import { iconClass, popUp, primary } from "../globalStyle";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
import {
|
|
22
|
+
useSelectState,
|
|
23
|
+
useSelectData,
|
|
24
|
+
useClickOutside,
|
|
25
|
+
} from "@grampro/headless-helpers";
|
|
24
26
|
|
|
25
27
|
const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
|
|
26
28
|
const {
|
|
@@ -61,7 +63,9 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
|
|
|
61
63
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
62
64
|
const selectRef = useRef<HTMLDivElement>(null);
|
|
63
65
|
|
|
64
|
-
useClickOutside(selectRef
|
|
66
|
+
useClickOutside(selectRef as React.RefObject<HTMLElement>, () =>
|
|
67
|
+
setShowPopover(false)
|
|
68
|
+
);
|
|
65
69
|
|
|
66
70
|
useEffect(() => {
|
|
67
71
|
if (showPopover) {
|
|
@@ -70,7 +74,9 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
|
|
|
70
74
|
}, [showPopover]);
|
|
71
75
|
|
|
72
76
|
useEffect(() => {
|
|
73
|
-
|
|
77
|
+
if (initialSelectedItem) {
|
|
78
|
+
setSelectedItem(initialSelectedItem);
|
|
79
|
+
}
|
|
74
80
|
}, [initialSelectedItem, setSelectedItem]);
|
|
75
81
|
|
|
76
82
|
const handleSelect = useCallback(
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const getDaysInMonth = (year: number, month: number) => {
|
|
2
|
-
return new Date(year, month + 1, 0).getDate();
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export const generateCalendarHelper = (year: number, month: number) => {
|
|
6
|
-
const daysInMonth = getDaysInMonth(year, month);
|
|
7
|
-
const firstDay = new Date(year, month, 1).getDay();
|
|
8
|
-
const weeks = [];
|
|
9
|
-
let day = 1;
|
|
10
|
-
|
|
11
|
-
for (let i = 0; i < 6; i++) {
|
|
12
|
-
const week = [];
|
|
13
|
-
for (let j = 0; j < 7; j++) {
|
|
14
|
-
if (i === 0 && j < firstDay) {
|
|
15
|
-
week.push(null);
|
|
16
|
-
} else if (day > daysInMonth) {
|
|
17
|
-
week.push(null);
|
|
18
|
-
} else {
|
|
19
|
-
const date = new Date(year, month, day);
|
|
20
|
-
week.push(date);
|
|
21
|
-
day++;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
weeks.push(week);
|
|
25
|
-
}
|
|
26
|
-
return weeks;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const months = [
|
|
30
|
-
'January',
|
|
31
|
-
'February',
|
|
32
|
-
'March',
|
|
33
|
-
'April',
|
|
34
|
-
'May',
|
|
35
|
-
'June',
|
|
36
|
-
'July',
|
|
37
|
-
'August',
|
|
38
|
-
'September',
|
|
39
|
-
'October',
|
|
40
|
-
'November',
|
|
41
|
-
'December'
|
|
42
|
-
];
|