@rufous/ui 0.1.63 → 0.2.0-beta.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.
- package/README.md +4 -0
- package/dist/Buttons/addButton.js +1 -0
- package/dist/Buttons/cancelButton.js +1 -0
- package/dist/Buttons/index.cjs +2 -2
- package/dist/Buttons/index.js +3 -2
- package/dist/Buttons/stdButton.js +1 -0
- package/dist/Buttons/submitButton.cjs +2 -2
- package/dist/Buttons/submitButton.js +3 -2
- package/dist/CheckBoxes/CheckBox.cjs +2 -2
- package/dist/CheckBoxes/CheckBox.js +4 -25
- package/dist/Contexts/rufousThemeProvider.cjs +132 -100
- package/dist/Contexts/rufousThemeProvider.js +3 -2
- package/dist/DataGrid/DataGrid.cjs +418 -0
- package/dist/DataGrid/DataGrid.d.cts +8 -0
- package/dist/DataGrid/DataGrid.d.ts +8 -0
- package/dist/DataGrid/DataGrid.js +9 -0
- package/dist/DataGrid/index.cjs +418 -0
- package/dist/DataGrid/index.d.cts +3 -0
- package/dist/DataGrid/index.d.ts +3 -0
- package/dist/DataGrid/index.js +8 -0
- package/dist/{TextFields/FloatingInput.d.cjs → DataGrid/types.cjs} +3 -3
- package/dist/DataGrid/types.d.cts +31 -0
- package/dist/DataGrid/types.d.ts +31 -0
- package/dist/Dialogs/BaseDialog.cjs +18 -10
- package/dist/Dialogs/BaseDialog.css +8355 -162
- package/dist/Dialogs/BaseDialog.d.cts +1 -0
- package/dist/Dialogs/BaseDialog.d.ts +1 -0
- package/dist/Dialogs/BaseDialog.js +33 -25
- package/dist/Dialogs/index.cjs +18 -10
- package/dist/Dialogs/index.css +8355 -162
- package/dist/Dialogs/index.js +33 -25
- package/dist/Editors/RichTextEditor.cjs +29477 -0
- package/dist/Editors/RichTextEditor.css +7179 -0
- package/dist/Editors/RichTextEditor.d.cts +57 -0
- package/dist/Editors/RichTextEditor.d.ts +57 -0
- package/dist/Editors/RichTextEditor.js +9 -0
- package/dist/Editors/index.cjs +29477 -0
- package/dist/Editors/index.css +7179 -0
- package/dist/Editors/index.d.cts +2 -0
- package/dist/Editors/index.d.ts +2 -0
- package/dist/Editors/index.js +8 -0
- package/dist/Progress/circularProgress.cjs +2 -2
- package/dist/Progress/circularProgress.d.cts +3 -3
- package/dist/Progress/circularProgress.d.ts +3 -3
- package/dist/Progress/circularProgress.js +2 -1
- package/dist/TextFields/AddressLookup.cjs +390 -0
- package/dist/TextFields/AddressLookup.d.cts +49 -0
- package/dist/TextFields/AddressLookup.d.ts +49 -0
- package/dist/TextFields/AddressLookup.js +11 -0
- package/dist/TextFields/FloatingInput.cjs +6 -4
- package/dist/TextFields/FloatingInput.d.cts +13 -19
- package/dist/TextFields/FloatingInput.d.ts +13 -19
- package/dist/TextFields/FloatingInput.js +4 -28
- package/dist/{chunk-AQXTOTWY.js → chunk-5DAOQ2V5.js} +19 -11
- package/dist/chunk-5QEWUCKT.js +303 -0
- package/dist/chunk-66HHM7VI.js +468 -0
- package/dist/chunk-7KRG7VNW.js +0 -0
- package/dist/{chunk-YRFUVQDN.js → chunk-CTBYVXFP.js} +2 -2
- package/dist/chunk-GJGRMMAQ.js +0 -0
- package/dist/chunk-HMG3FW2Q.js +97 -0
- package/dist/chunk-J6E3UO2W.js +402 -0
- package/dist/chunk-LI4N7JWK.js +39 -0
- package/dist/chunk-NEGQXBQV.js +29 -0
- package/dist/chunk-UPCMMCPQ.js +34 -0
- package/dist/{chunk-7YKG3WYS.js → chunk-YRLN3TBF.js} +1 -1
- package/dist/chunk-YXPBXCY5.js +89 -0
- package/dist/esm-5T53WHPT.js +27362 -0
- package/dist/icons/activateUserIcon.js +1 -0
- package/dist/icons/archivedIcon.js +1 -0
- package/dist/icons/assignGroupIcon.js +1 -0
- package/dist/icons/closeIcon.js +1 -0
- package/dist/icons/copyIcon.js +1 -0
- package/dist/icons/difficultyAllIcon.js +1 -0
- package/dist/icons/difficultyEasyIcon.js +1 -0
- package/dist/icons/difficultyHardIcon.js +1 -0
- package/dist/icons/difficultyMediumIcon.js +1 -0
- package/dist/icons/dollarIcon.js +1 -0
- package/dist/icons/downloadIcon.js +1 -0
- package/dist/icons/downloadPdfIcon.js +1 -0
- package/dist/icons/editChatIcon.js +1 -0
- package/dist/icons/editIcon.js +1 -0
- package/dist/icons/engagementIcon.js +1 -0
- package/dist/icons/functionIcon.js +1 -0
- package/dist/icons/helpOutlinedIcon.js +1 -0
- package/dist/icons/hierarchyIcon.js +1 -0
- package/dist/icons/inactiveGroupIcon.js +1 -0
- package/dist/icons/index.js +48 -47
- package/dist/icons/industryIcon.js +1 -0
- package/dist/icons/invoiceIcon.js +1 -0
- package/dist/icons/locationPinIcon.js +1 -0
- package/dist/icons/logsIcon.js +1 -0
- package/dist/icons/minExperienceIcon.js +1 -0
- package/dist/icons/nineDotMenuIcon.js +1 -0
- package/dist/icons/notificationIcon.js +1 -0
- package/dist/icons/projectIcon.js +1 -0
- package/dist/icons/qualificationsIcon.js +1 -0
- package/dist/icons/questionStatusAllIcon.js +1 -0
- package/dist/icons/questionStatusPrivateIcon.js +1 -0
- package/dist/icons/questionStatusPublicIcon.js +1 -0
- package/dist/icons/questionTypeAllIcon.js +1 -0
- package/dist/icons/questionTypeCodingIcon.js +1 -0
- package/dist/icons/questionTypeDescriptiveIcon.js +1 -0
- package/dist/icons/questionTypeMultipleIcon.js +1 -0
- package/dist/icons/questionTypeSingleIcon.js +1 -0
- package/dist/icons/refreshIcon.js +1 -0
- package/dist/icons/resendInviteIcon.js +1 -0
- package/dist/icons/rolesIcon.js +1 -0
- package/dist/icons/rufousAiIcon.js +1 -0
- package/dist/icons/rufousBirdIcon.js +1 -0
- package/dist/icons/rufousLauncherBird.js +1 -0
- package/dist/icons/sidebarIcon.js +1 -0
- package/dist/icons/softSkillsIcon.js +1 -0
- package/dist/icons/subscribeIcon.js +1 -0
- package/dist/icons/suspendUserIcon.js +1 -0
- package/dist/icons/technicalSkillsIcon.js +1 -0
- package/dist/icons/tickIcon.js +1 -0
- package/dist/icons/timerIcon.js +1 -0
- package/dist/icons/trashIcon.js +1 -0
- package/dist/icons/unArchivedIcon.js +1 -0
- package/dist/icons/unsubscribeIcon.js +1 -0
- package/dist/icons/uploadIcon.js +1 -0
- package/dist/icons/userAssignIcon.js +1 -0
- package/dist/icons/viewIcon.js +1 -0
- package/dist/icons/workItemIcon.js +1 -0
- package/dist/main.cjs +30440 -222
- package/dist/main.css +8355 -162
- package/dist/main.d.cts +7 -0
- package/dist/main.d.ts +7 -0
- package/dist/main.js +82 -56
- package/dist/style.css +1068 -163
- package/dist/styles/address-lookup.css +107 -0
- package/dist/styles/address-lookup.d.cts +2 -0
- package/dist/styles/address-lookup.d.ts +2 -0
- package/dist/styles/button.css +82 -110
- package/dist/styles/checkbox.css +60 -0
- package/dist/styles/checkbox.d.cts +2 -0
- package/dist/styles/checkbox.d.ts +2 -0
- package/dist/styles/datagrid.css +531 -0
- package/dist/styles/datagrid.d.cts +2 -0
- package/dist/styles/datagrid.d.ts +2 -0
- package/dist/styles/dialog.css +78 -51
- package/dist/styles/editor.css +211 -0
- package/dist/styles/editor.d.cts +2 -0
- package/dist/styles/editor.d.ts +2 -0
- package/dist/utils/constants.cjs +75 -69
- package/dist/utils/constants.d.cts +54 -56
- package/dist/utils/constants.d.ts +54 -56
- package/dist/utils/constants.js +2 -1
- package/package.json +13 -2
- package/dist/TextFields/FloatingInput.d.d.cts +0 -23
- package/dist/TextFields/FloatingInput.d.d.ts +0 -23
- package/dist/chunk-2FHTGYR4.js +0 -83
- package/dist/chunk-BCGCLMKA.js +0 -71
- /package/dist/{TextFields/FloatingInput.d.js → DataGrid/types.js} +0 -0
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React__default, { InputHTMLAttributes, CSSProperties } from 'react';
|
|
2
2
|
|
|
3
|
-
interface FloatingInputProps
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/** Placeholder text (defaults to label if not provided) */
|
|
15
|
-
placeholder?: string;
|
|
16
|
-
|
|
17
|
-
/** Optional class name to apply to the outer wrapper */
|
|
18
|
-
className?: string;
|
|
3
|
+
interface FloatingInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
4
|
+
/** Label text shown above the input */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Name attribute for the input (used for forms) */
|
|
7
|
+
name: string;
|
|
8
|
+
/** ID for the input and label (defaults to `name` if not provided) */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Optional class name to apply to the outer wrapper */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Inline style overrides for the wrapper */
|
|
13
|
+
style?: CSSProperties;
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
declare const FloatingInput: React.FC<FloatingInputProps>;
|
|
15
|
+
declare const FloatingInput: React__default.FC<FloatingInputProps>;
|
|
22
16
|
|
|
23
17
|
export { FloatingInput, type FloatingInputProps };
|
|
@@ -1,31 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
name,
|
|
6
|
-
id,
|
|
7
|
-
type = "text",
|
|
8
|
-
value,
|
|
9
|
-
onChange,
|
|
10
|
-
required = false,
|
|
11
|
-
placeholder,
|
|
12
|
-
className = "",
|
|
13
|
-
...props
|
|
14
|
-
}) => {
|
|
15
|
-
return /* @__PURE__ */ React.createElement("div", { className: `form__group field ${className}`, ...props }, /* @__PURE__ */ React.createElement(
|
|
16
|
-
"input",
|
|
17
|
-
{
|
|
18
|
-
type,
|
|
19
|
-
className: "form__field",
|
|
20
|
-
placeholder: placeholder || label,
|
|
21
|
-
name,
|
|
22
|
-
id: id || name,
|
|
23
|
-
value,
|
|
24
|
-
onChange,
|
|
25
|
-
required
|
|
26
|
-
}
|
|
27
|
-
), /* @__PURE__ */ React.createElement("label", { htmlFor: id || name, className: "form__label" }, label));
|
|
28
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
FloatingInput
|
|
3
|
+
} from "../chunk-UPCMMCPQ.js";
|
|
4
|
+
import "../chunk-LI4N7JWK.js";
|
|
29
5
|
export {
|
|
30
6
|
FloatingInput
|
|
31
7
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-Q5XKCUE3.js";
|
|
4
4
|
import {
|
|
5
5
|
useRufousTheme
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-HMG3FW2Q.js";
|
|
7
7
|
|
|
8
8
|
// lib/Dialogs/BaseDialog.tsx
|
|
9
9
|
import * as React from "react";
|
|
@@ -17,8 +17,8 @@ var BaseDialog = ({
|
|
|
17
17
|
minWidth,
|
|
18
18
|
minHeight,
|
|
19
19
|
customButtons,
|
|
20
|
-
cancelText = "
|
|
21
|
-
confirmText = "
|
|
20
|
+
cancelText = "CANCEL",
|
|
21
|
+
confirmText = "SUBMIT",
|
|
22
22
|
submitText = "Submit",
|
|
23
23
|
title = "",
|
|
24
24
|
isLoading = false,
|
|
@@ -31,9 +31,10 @@ var BaseDialog = ({
|
|
|
31
31
|
formatTitle = true,
|
|
32
32
|
fullWidth = false,
|
|
33
33
|
className,
|
|
34
|
-
dialogBodyStyle = {}
|
|
34
|
+
dialogBodyStyle = {},
|
|
35
|
+
size
|
|
35
36
|
}) => {
|
|
36
|
-
const {
|
|
37
|
+
const { themeConfig } = useRufousTheme();
|
|
37
38
|
const successBtnRef = useRef(null);
|
|
38
39
|
if (!open) return null;
|
|
39
40
|
const renderButtons = () => /* @__PURE__ */ React.createElement("div", { className: "dialog-footer", style: { justifyContent: buttonAlign } }, showCancelButton && /* @__PURE__ */ React.createElement(
|
|
@@ -58,17 +59,23 @@ var BaseDialog = ({
|
|
|
58
59
|
},
|
|
59
60
|
loading ? /* @__PURE__ */ React.createElement("span", { className: "spinner" }) : /* @__PURE__ */ React.createElement("span", null, confirmText)
|
|
60
61
|
));
|
|
61
|
-
return /* @__PURE__ */ React.createElement("div", { className: `dialog-overlay ${fullScreen ? "fullscreen" : ""}` }, /* @__PURE__ */ React.createElement(
|
|
62
|
+
return /* @__PURE__ */ React.createElement("div", { className: `dialog-overlay ${size === "fullScreen" ? "overlay-fullscreen" : ""}` }, /* @__PURE__ */ React.createElement(
|
|
62
63
|
"div",
|
|
63
64
|
{
|
|
64
|
-
className: `dialog-container ${className || ""}`,
|
|
65
|
+
className: `dialog-container ${size ? `size-${size}` : ""} ${className || ""}`,
|
|
65
66
|
style: {
|
|
66
|
-
minWidth
|
|
67
|
-
minHeight
|
|
68
|
-
width: fullWidth ? "100%" : "auto"
|
|
67
|
+
minWidth,
|
|
68
|
+
minHeight
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
/* @__PURE__ */ React.createElement("div", { className: "dialog-title" }, /* @__PURE__ */ React.createElement("h2", null, formatTitle ? title?.charAt(0).toUpperCase() + title?.slice(1)
|
|
71
|
+
/* @__PURE__ */ React.createElement("div", { className: "dialog-title" }, /* @__PURE__ */ React.createElement("h2", null, formatTitle ? title?.charAt(0).toUpperCase() + title?.slice(1) : title), showCloseButton && /* @__PURE__ */ React.createElement("button", { className: "btn-close", onClick: onClose }, /* @__PURE__ */ React.createElement(
|
|
72
|
+
closeIcon_default,
|
|
73
|
+
{
|
|
74
|
+
width: 20,
|
|
75
|
+
height: 20,
|
|
76
|
+
color: themeConfig?.icon || "#666666"
|
|
77
|
+
}
|
|
78
|
+
))),
|
|
72
79
|
/* @__PURE__ */ React.createElement("div", { className: "dialog-divider" }),
|
|
73
80
|
/* @__PURE__ */ React.createElement(
|
|
74
81
|
"div",
|
|
@@ -81,6 +88,7 @@ var BaseDialog = ({
|
|
|
81
88
|
},
|
|
82
89
|
children
|
|
83
90
|
),
|
|
91
|
+
/* @__PURE__ */ React.createElement("div", { className: "dialog-divider" }),
|
|
84
92
|
customButtons || renderButtons()
|
|
85
93
|
));
|
|
86
94
|
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FloatingInput
|
|
3
|
+
} from "./chunk-UPCMMCPQ.js";
|
|
4
|
+
import {
|
|
5
|
+
useRufousTheme
|
|
6
|
+
} from "./chunk-HMG3FW2Q.js";
|
|
7
|
+
import {
|
|
8
|
+
circularProgress_default
|
|
9
|
+
} from "./chunk-CTBYVXFP.js";
|
|
10
|
+
|
|
11
|
+
// lib/TextFields/AddressLookup.tsx
|
|
12
|
+
import React, { useState, useRef, useEffect } from "react";
|
|
13
|
+
import Axios from "axios";
|
|
14
|
+
import { Country, State, City } from "country-state-city";
|
|
15
|
+
var AddressLookup = ({
|
|
16
|
+
value = {},
|
|
17
|
+
onChange = () => {
|
|
18
|
+
},
|
|
19
|
+
label = "Address",
|
|
20
|
+
error = {},
|
|
21
|
+
size = "medium",
|
|
22
|
+
sx = {},
|
|
23
|
+
layout = "stack",
|
|
24
|
+
required = false,
|
|
25
|
+
token = ""
|
|
26
|
+
}) => {
|
|
27
|
+
const { theme } = useRufousTheme();
|
|
28
|
+
const [suggestions, setSuggestions] = useState([]);
|
|
29
|
+
const [loading, setLoading] = useState(false);
|
|
30
|
+
const [showSuggestions, setShowSuggestions] = useState(false);
|
|
31
|
+
const [googleFields, setGoogleFields] = useState({
|
|
32
|
+
country: false,
|
|
33
|
+
state: false,
|
|
34
|
+
city: false,
|
|
35
|
+
pincode: false
|
|
36
|
+
});
|
|
37
|
+
const debounceTimeout = useRef(null);
|
|
38
|
+
const containerRef = useRef(null);
|
|
39
|
+
const apiKey = token || "";
|
|
40
|
+
const countries = Country.getAllCountries();
|
|
41
|
+
const [states, setStates] = useState([]);
|
|
42
|
+
const [cities, setCities] = useState([]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const handleClickOutside = (event) => {
|
|
45
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
46
|
+
setShowSuggestions(false);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
50
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
51
|
+
}, []);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (value.country || value.state || value.city || value.pincode) {
|
|
54
|
+
setGoogleFields({
|
|
55
|
+
country: !!value.country,
|
|
56
|
+
state: !!value.state,
|
|
57
|
+
city: !!value.city,
|
|
58
|
+
pincode: !!value.pincode
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (value.country) {
|
|
64
|
+
const country = countries.find((c) => c.name === value.country);
|
|
65
|
+
if (country) {
|
|
66
|
+
const stateList = State.getStatesOfCountry(country.isoCode);
|
|
67
|
+
setStates(stateList);
|
|
68
|
+
} else {
|
|
69
|
+
setStates([]);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
setStates([]);
|
|
73
|
+
}
|
|
74
|
+
}, [value.country]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (value.state && value.country) {
|
|
77
|
+
const country = countries.find((c) => c.name === value.country);
|
|
78
|
+
if (country) {
|
|
79
|
+
const state = State.getStatesOfCountry(country.isoCode).find((s) => s.name === value.state);
|
|
80
|
+
if (state) {
|
|
81
|
+
const cityList = City.getCitiesOfState(country.isoCode, state.isoCode);
|
|
82
|
+
setCities(cityList);
|
|
83
|
+
} else {
|
|
84
|
+
setCities([]);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
setCities([]);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
setCities([]);
|
|
91
|
+
}
|
|
92
|
+
}, [value.state, value.country]);
|
|
93
|
+
const handleChange = (field, newVal) => {
|
|
94
|
+
onChange({
|
|
95
|
+
...value,
|
|
96
|
+
[field]: newVal
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const fetchPlaceDetails = async (placeId, mainText = "") => {
|
|
100
|
+
if (!apiKey) {
|
|
101
|
+
console.warn("Google Places API Key (token) is missing.");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
setLoading(true);
|
|
105
|
+
try {
|
|
106
|
+
const res = await Axios.get(
|
|
107
|
+
`https://places.googleapis.com/v1/places/${placeId}`,
|
|
108
|
+
{
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
"X-Goog-Api-Key": apiKey,
|
|
112
|
+
"X-Goog-FieldMask": "addressComponents,formattedAddress"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
const comps = res.data.addressComponents || [];
|
|
117
|
+
const findComp = (type) => comps.find((c) => c.types.includes(type))?.longText || "";
|
|
118
|
+
const city = findComp("locality") || findComp("sublocality_level_1");
|
|
119
|
+
const state = findComp("administrative_area_level_1");
|
|
120
|
+
const country = findComp("country");
|
|
121
|
+
const pincode = findComp("postal_code");
|
|
122
|
+
setGoogleFields({
|
|
123
|
+
country: !!country,
|
|
124
|
+
state: !!state,
|
|
125
|
+
city: !!city,
|
|
126
|
+
pincode: !!pincode
|
|
127
|
+
});
|
|
128
|
+
const updatedData = {
|
|
129
|
+
...value,
|
|
130
|
+
addressLine1: mainText || value.addressLine1,
|
|
131
|
+
addressLine2: res.data.formattedAddress || value.addressLine2,
|
|
132
|
+
city,
|
|
133
|
+
state,
|
|
134
|
+
country,
|
|
135
|
+
pincode
|
|
136
|
+
};
|
|
137
|
+
onChange(updatedData);
|
|
138
|
+
setShowSuggestions(false);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.error("Error fetching place details:", err);
|
|
141
|
+
} finally {
|
|
142
|
+
setLoading(false);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const handleQuerySuggestions = async (query) => {
|
|
146
|
+
if (!apiKey || !query || query.length < 3) {
|
|
147
|
+
setSuggestions([]);
|
|
148
|
+
setShowSuggestions(false);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
setLoading(true);
|
|
152
|
+
try {
|
|
153
|
+
const res = await Axios.post(
|
|
154
|
+
`https://places.googleapis.com/v1/places:autocomplete`,
|
|
155
|
+
{ input: query },
|
|
156
|
+
{
|
|
157
|
+
headers: {
|
|
158
|
+
"Content-Type": "application/json",
|
|
159
|
+
"X-Goog-Api-Key": apiKey
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
setSuggestions(res.data.suggestions || []);
|
|
164
|
+
setShowSuggestions(true);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
console.error("Autocomplete Error:", err);
|
|
167
|
+
} finally {
|
|
168
|
+
setLoading(false);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const handleCountryChange = (newCountry) => {
|
|
172
|
+
onChange({
|
|
173
|
+
...value,
|
|
174
|
+
country: newCountry,
|
|
175
|
+
state: "",
|
|
176
|
+
city: ""
|
|
177
|
+
});
|
|
178
|
+
setGoogleFields({ ...googleFields, country: false, state: false, city: false });
|
|
179
|
+
};
|
|
180
|
+
const handleStateChange = (newState) => {
|
|
181
|
+
onChange({
|
|
182
|
+
...value,
|
|
183
|
+
state: newState,
|
|
184
|
+
city: ""
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
return /* @__PURE__ */ React.createElement("div", { className: "address-lookup-container", style: sx, ref: containerRef }, /* @__PURE__ */ React.createElement("div", { className: `address-lookup-grid address-lookup-grid-${layout}` }, /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-l1" }, /* @__PURE__ */ React.createElement(
|
|
188
|
+
FloatingInput,
|
|
189
|
+
{
|
|
190
|
+
label,
|
|
191
|
+
name: "addressLine1",
|
|
192
|
+
value: value.addressLine1 || "",
|
|
193
|
+
required,
|
|
194
|
+
autoComplete: "off",
|
|
195
|
+
onChange: (e) => {
|
|
196
|
+
const val = e.target.value;
|
|
197
|
+
handleChange("addressLine1", val);
|
|
198
|
+
if (!val) {
|
|
199
|
+
onChange({
|
|
200
|
+
...value,
|
|
201
|
+
addressLine1: "",
|
|
202
|
+
city: "",
|
|
203
|
+
state: "",
|
|
204
|
+
country: "",
|
|
205
|
+
pincode: ""
|
|
206
|
+
});
|
|
207
|
+
setSuggestions([]);
|
|
208
|
+
setShowSuggestions(false);
|
|
209
|
+
setGoogleFields({ country: false, state: false, city: false, pincode: false });
|
|
210
|
+
} else {
|
|
211
|
+
if (debounceTimeout.current) clearTimeout(debounceTimeout.current);
|
|
212
|
+
debounceTimeout.current = setTimeout(() => {
|
|
213
|
+
handleQuerySuggestions(val);
|
|
214
|
+
}, 500);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
onFocus: () => suggestions.length > 0 && setShowSuggestions(true)
|
|
218
|
+
}
|
|
219
|
+
), loading && /* @__PURE__ */ React.createElement("div", { className: "loading-indicator" }, /* @__PURE__ */ React.createElement(circularProgress_default, { size: 20 })), showSuggestions && suggestions.length > 0 && /* @__PURE__ */ React.createElement("div", { className: "autocomplete-dropdown" }, suggestions.map((option, idx) => /* @__PURE__ */ React.createElement(
|
|
220
|
+
"div",
|
|
221
|
+
{
|
|
222
|
+
key: idx,
|
|
223
|
+
className: "autocomplete-option",
|
|
224
|
+
onClick: () => {
|
|
225
|
+
const mainText = option?.placePrediction?.structuredFormat?.mainText?.text || "";
|
|
226
|
+
handleChange("addressLine1", mainText);
|
|
227
|
+
fetchPlaceDetails(option.placePrediction.placeId, mainText);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
/* @__PURE__ */ React.createElement("div", { className: "autocomplete-main-text" }, option?.placePrediction?.structuredFormat?.mainText?.text),
|
|
231
|
+
/* @__PURE__ */ React.createElement("div", { className: "autocomplete-secondary-text" }, option?.placePrediction?.structuredFormat?.secondaryText?.text)
|
|
232
|
+
))), error.addressLine1 && /* @__PURE__ */ React.createElement("div", { className: "field-error-text" }, error.addressLine1)), layout === "compact" && /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ React.createElement(
|
|
233
|
+
FloatingInput,
|
|
234
|
+
{
|
|
235
|
+
label: "Address Line 2",
|
|
236
|
+
name: "addressLine2",
|
|
237
|
+
value: value.addressLine2 || "",
|
|
238
|
+
onChange: (e) => handleChange("addressLine2", e.target.value)
|
|
239
|
+
}
|
|
240
|
+
)), layout !== "compact" && /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ React.createElement(
|
|
241
|
+
FloatingInput,
|
|
242
|
+
{
|
|
243
|
+
label: "Address Line 2",
|
|
244
|
+
name: "addressLine2",
|
|
245
|
+
value: value.addressLine2 || "",
|
|
246
|
+
onChange: (e) => handleChange("addressLine2", e.target.value)
|
|
247
|
+
}
|
|
248
|
+
)), /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-country" }, /* @__PURE__ */ React.createElement(
|
|
249
|
+
FloatingInput,
|
|
250
|
+
{
|
|
251
|
+
label: "Country",
|
|
252
|
+
name: "country",
|
|
253
|
+
value: value.country || "",
|
|
254
|
+
required,
|
|
255
|
+
className: googleFields.country && value.country ? "field-disabled" : "",
|
|
256
|
+
readOnly: googleFields.country && !!value.country,
|
|
257
|
+
onChange: (e) => handleCountryChange(e.target.value),
|
|
258
|
+
list: "countries-list"
|
|
259
|
+
}
|
|
260
|
+
), /* @__PURE__ */ React.createElement("datalist", { id: "countries-list" }, countries.map((c) => /* @__PURE__ */ React.createElement("option", { key: c.isoCode, value: c.name }))), error.country && /* @__PURE__ */ React.createElement("div", { className: "field-error-text" }, error.country)), /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-state" }, /* @__PURE__ */ React.createElement(
|
|
261
|
+
FloatingInput,
|
|
262
|
+
{
|
|
263
|
+
label: "State",
|
|
264
|
+
name: "state",
|
|
265
|
+
value: value.state || "",
|
|
266
|
+
required,
|
|
267
|
+
disabled: !value.country,
|
|
268
|
+
className: googleFields.state && value.state ? "field-disabled" : "",
|
|
269
|
+
readOnly: googleFields.state && !!value.state,
|
|
270
|
+
onChange: (e) => handleStateChange(e.target.value),
|
|
271
|
+
list: "states-list"
|
|
272
|
+
}
|
|
273
|
+
), /* @__PURE__ */ React.createElement("datalist", { id: "states-list" }, states.map((s) => /* @__PURE__ */ React.createElement("option", { key: s.isoCode, value: s.name }))), error.state && /* @__PURE__ */ React.createElement("div", { className: "field-error-text" }, error.state)), /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-city" }, /* @__PURE__ */ React.createElement(
|
|
274
|
+
FloatingInput,
|
|
275
|
+
{
|
|
276
|
+
label: "City",
|
|
277
|
+
name: "city",
|
|
278
|
+
value: value.city || "",
|
|
279
|
+
required,
|
|
280
|
+
disabled: !value.state,
|
|
281
|
+
className: googleFields.city && value.city ? "field-disabled" : "",
|
|
282
|
+
readOnly: googleFields.city && !!value.city,
|
|
283
|
+
onChange: (e) => handleChange("city", e.target.value),
|
|
284
|
+
list: "cities-list"
|
|
285
|
+
}
|
|
286
|
+
), /* @__PURE__ */ React.createElement("datalist", { id: "cities-list" }, cities.map((c, i) => /* @__PURE__ */ React.createElement("option", { key: i, value: c.name }))), error.city && /* @__PURE__ */ React.createElement("div", { className: "field-error-text" }, error.city)), /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-pin" }, /* @__PURE__ */ React.createElement(
|
|
287
|
+
FloatingInput,
|
|
288
|
+
{
|
|
289
|
+
label: "Pincode",
|
|
290
|
+
name: "pincode",
|
|
291
|
+
value: value.pincode || "",
|
|
292
|
+
required,
|
|
293
|
+
className: googleFields.pincode && value.pincode ? "field-disabled" : "",
|
|
294
|
+
readOnly: googleFields.pincode && !!value.pincode,
|
|
295
|
+
onChange: (e) => handleChange("pincode", e.target.value)
|
|
296
|
+
}
|
|
297
|
+
), error.pincode && /* @__PURE__ */ React.createElement("div", { className: "field-error-text" }, error.pincode))));
|
|
298
|
+
};
|
|
299
|
+
var AddressLookup_default = AddressLookup;
|
|
300
|
+
|
|
301
|
+
export {
|
|
302
|
+
AddressLookup_default
|
|
303
|
+
};
|