@rufous/ui 0.2.0-beta.0 → 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.
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  BaseDialog_default
3
- } from "../chunk-TYTZEAV5.js";
3
+ } from "../chunk-5DAOQ2V5.js";
4
4
  import "../chunk-E5RTHYCU.js";
5
+ import "../chunk-EZI3QGYJ.js";
5
6
  import "../chunk-QTGVW36I.js";
6
7
  import "../chunk-G2GZDPUL.js";
7
8
  import "../chunk-CTWVJQJ5.js";
8
9
  import "../chunk-QJPQC544.js";
10
+ import "../chunk-3Y6QBRGD.js";
9
11
  import "../chunk-JVN6QVET.js";
10
12
  import "../chunk-R4ISYGEP.js";
11
13
  import "../chunk-5JWTJ5PY.js";
@@ -13,7 +15,7 @@ import "../chunk-763IHEJ2.js";
13
15
  import "../chunk-XHY3OCAQ.js";
14
16
  import "../chunk-6KIFTMUN.js";
15
17
  import "../chunk-ZJAV3FEQ.js";
16
- import "../chunk-EZI3QGYJ.js";
18
+ import "../chunk-Q4DHI3B5.js";
17
19
  import "../chunk-YTVUM76D.js";
18
20
  import "../chunk-WG3Q6GZN.js";
19
21
  import "../chunk-RJ43D3XB.js";
@@ -21,7 +23,7 @@ import "../chunk-QDMNCTXT.js";
21
23
  import "../chunk-DMP72IAP.js";
22
24
  import "../chunk-QZFGQ5JM.js";
23
25
  import "../chunk-DK3DA5LH.js";
24
- import "../chunk-3Y6QBRGD.js";
26
+ import "../chunk-UTBCFDOX.js";
25
27
  import "../chunk-4Y7SQ5EP.js";
26
28
  import "../chunk-B2LVMM55.js";
27
29
  import "../chunk-2AJACSJ3.js";
@@ -29,7 +31,7 @@ import "../chunk-WHGVO3HV.js";
29
31
  import "../chunk-7II4Q2WY.js";
30
32
  import "../chunk-5GK5B3FD.js";
31
33
  import "../chunk-Z7USRFM2.js";
32
- import "../chunk-Q4DHI3B5.js";
34
+ import "../chunk-4BTXGP7U.js";
33
35
  import "../chunk-6SUKO6QW.js";
34
36
  import "../chunk-UTYIBUY2.js";
35
37
  import "../chunk-N4EJKMJK.js";
@@ -37,14 +39,14 @@ import "../chunk-FPRXN3DS.js";
37
39
  import "../chunk-GESVGIAP.js";
38
40
  import "../chunk-QIEQRNBE.js";
39
41
  import "../chunk-DLJHWFNG.js";
40
- import "../chunk-UTBCFDOX.js";
42
+ import "../chunk-XCE3QE6Q.js";
41
43
  import "../chunk-H372BAXA.js";
42
44
  import "../chunk-ZLJDOLXZ.js";
43
45
  import "../chunk-OJV6F5JC.js";
44
46
  import "../chunk-AXSFVJ3H.js";
45
47
  import "../chunk-WZAU77G7.js";
46
48
  import "../chunk-77QDKDFI.js";
47
- import "../chunk-4BTXGP7U.js";
49
+ import "../chunk-6FEUS4CQ.js";
48
50
  import "../chunk-5XKFPQLH.js";
49
51
  import "../chunk-JI5XMLWT.js";
50
52
  import "../chunk-WXANSSXF.js";
@@ -52,17 +54,18 @@ import "../chunk-XPJVVKOU.js";
52
54
  import "../chunk-GL43GPEM.js";
53
55
  import "../chunk-FZCFFVXW.js";
54
56
  import "../chunk-N26C33E6.js";
55
- import "../chunk-XCE3QE6Q.js";
56
57
  import "../chunk-AH6RCYDL.js";
57
58
  import "../chunk-3IBCGGN3.js";
58
59
  import "../chunk-MNPAE2ZF.js";
59
60
  import "../chunk-Q5XKCUE3.js";
60
- import "../chunk-6FEUS4CQ.js";
61
+ import "../chunk-7KRG7VNW.js";
62
+ import "../chunk-5QEWUCKT.js";
63
+ import "../chunk-UPCMMCPQ.js";
64
+ import "../chunk-NEGQXBQV.js";
65
+ import "../chunk-HMG3FW2Q.js";
66
+ import "../chunk-YXPBXCY5.js";
61
67
  import "../chunk-GJGRMMAQ.js";
62
68
  import "../chunk-66HHM7VI.js";
63
- import "../chunk-UPCMMCPQ.js";
64
- import "../chunk-X357WQOT.js";
65
- import "../chunk-7KRG7VNW.js";
66
69
  import "../chunk-J6E3UO2W.js";
67
70
  import "../chunk-QPGJCRBS.js";
68
71
  import "../chunk-U7SARO5B.js";
@@ -70,8 +73,6 @@ import "../chunk-BMMDUQDJ.js";
70
73
  import "../chunk-R3GARAVJ.js";
71
74
  import "../chunk-YRLN3TBF.js";
72
75
  import "../chunk-CTBYVXFP.js";
73
- import "../chunk-WNZLBFLQ.js";
74
- import "../chunk-QGXXOQJF.js";
75
76
  import "../chunk-LI4N7JWK.js";
76
77
  export {
77
78
  BaseDialog_default as BaseDialog
@@ -1,304 +1,11 @@
1
1
  import {
2
- FloatingInput
3
- } from "../chunk-UPCMMCPQ.js";
4
- import {
5
- circularProgress_default
6
- } from "../chunk-CTBYVXFP.js";
7
- import {
8
- useRufousTheme
9
- } from "../chunk-WNZLBFLQ.js";
10
- import "../chunk-QGXXOQJF.js";
2
+ AddressLookup_default
3
+ } from "../chunk-5QEWUCKT.js";
4
+ import "../chunk-UPCMMCPQ.js";
5
+ import "../chunk-HMG3FW2Q.js";
6
+ import "../chunk-YXPBXCY5.js";
7
+ import "../chunk-CTBYVXFP.js";
11
8
  import "../chunk-LI4N7JWK.js";
12
-
13
- // lib/TextFields/AddressLookup.tsx
14
- import React, { useState, useRef, useEffect } from "react";
15
- import Axios from "axios";
16
- import { Country, State, City } from "country-state-city";
17
- var AddressLookup = ({
18
- value = {},
19
- onChange = () => {
20
- },
21
- label = "Address",
22
- error = {},
23
- size = "medium",
24
- sx = {},
25
- layout = "stack",
26
- required = false,
27
- token = ""
28
- }) => {
29
- const { theme } = useRufousTheme();
30
- const [suggestions, setSuggestions] = useState([]);
31
- const [loading, setLoading] = useState(false);
32
- const [showSuggestions, setShowSuggestions] = useState(false);
33
- const [googleFields, setGoogleFields] = useState({
34
- country: false,
35
- state: false,
36
- city: false,
37
- pincode: false
38
- });
39
- const debounceTimeout = useRef(null);
40
- const containerRef = useRef(null);
41
- const apiKey = token || "";
42
- const countries = Country.getAllCountries();
43
- const [states, setStates] = useState([]);
44
- const [cities, setCities] = useState([]);
45
- useEffect(() => {
46
- const handleClickOutside = (event) => {
47
- if (containerRef.current && !containerRef.current.contains(event.target)) {
48
- setShowSuggestions(false);
49
- }
50
- };
51
- document.addEventListener("mousedown", handleClickOutside);
52
- return () => document.removeEventListener("mousedown", handleClickOutside);
53
- }, []);
54
- useEffect(() => {
55
- if (value.country || value.state || value.city || value.pincode) {
56
- setGoogleFields({
57
- country: !!value.country,
58
- state: !!value.state,
59
- city: !!value.city,
60
- pincode: !!value.pincode
61
- });
62
- }
63
- }, []);
64
- useEffect(() => {
65
- if (value.country) {
66
- const country = countries.find((c) => c.name === value.country);
67
- if (country) {
68
- const stateList = State.getStatesOfCountry(country.isoCode);
69
- setStates(stateList);
70
- } else {
71
- setStates([]);
72
- }
73
- } else {
74
- setStates([]);
75
- }
76
- }, [value.country]);
77
- useEffect(() => {
78
- if (value.state && value.country) {
79
- const country = countries.find((c) => c.name === value.country);
80
- if (country) {
81
- const state = State.getStatesOfCountry(country.isoCode).find((s) => s.name === value.state);
82
- if (state) {
83
- const cityList = City.getCitiesOfState(country.isoCode, state.isoCode);
84
- setCities(cityList);
85
- } else {
86
- setCities([]);
87
- }
88
- } else {
89
- setCities([]);
90
- }
91
- } else {
92
- setCities([]);
93
- }
94
- }, [value.state, value.country]);
95
- const handleChange = (field, newVal) => {
96
- onChange({
97
- ...value,
98
- [field]: newVal
99
- });
100
- };
101
- const fetchPlaceDetails = async (placeId, mainText = "") => {
102
- if (!apiKey) {
103
- console.warn("Google Places API Key (token) is missing.");
104
- return;
105
- }
106
- setLoading(true);
107
- try {
108
- const res = await Axios.get(
109
- `https://places.googleapis.com/v1/places/${placeId}`,
110
- {
111
- headers: {
112
- "Content-Type": "application/json",
113
- "X-Goog-Api-Key": apiKey,
114
- "X-Goog-FieldMask": "addressComponents,formattedAddress"
115
- }
116
- }
117
- );
118
- const comps = res.data.addressComponents || [];
119
- const findComp = (type) => comps.find((c) => c.types.includes(type))?.longText || "";
120
- const city = findComp("locality") || findComp("sublocality_level_1");
121
- const state = findComp("administrative_area_level_1");
122
- const country = findComp("country");
123
- const pincode = findComp("postal_code");
124
- setGoogleFields({
125
- country: !!country,
126
- state: !!state,
127
- city: !!city,
128
- pincode: !!pincode
129
- });
130
- const updatedData = {
131
- ...value,
132
- addressLine1: mainText || value.addressLine1,
133
- addressLine2: res.data.formattedAddress || value.addressLine2,
134
- city,
135
- state,
136
- country,
137
- pincode
138
- };
139
- onChange(updatedData);
140
- setShowSuggestions(false);
141
- } catch (err) {
142
- console.error("Error fetching place details:", err);
143
- } finally {
144
- setLoading(false);
145
- }
146
- };
147
- const handleQuerySuggestions = async (query) => {
148
- if (!apiKey || !query || query.length < 3) {
149
- setSuggestions([]);
150
- setShowSuggestions(false);
151
- return;
152
- }
153
- setLoading(true);
154
- try {
155
- const res = await Axios.post(
156
- `https://places.googleapis.com/v1/places:autocomplete`,
157
- { input: query },
158
- {
159
- headers: {
160
- "Content-Type": "application/json",
161
- "X-Goog-Api-Key": apiKey
162
- }
163
- }
164
- );
165
- setSuggestions(res.data.suggestions || []);
166
- setShowSuggestions(true);
167
- } catch (err) {
168
- console.error("Autocomplete Error:", err);
169
- } finally {
170
- setLoading(false);
171
- }
172
- };
173
- const handleCountryChange = (newCountry) => {
174
- onChange({
175
- ...value,
176
- country: newCountry,
177
- state: "",
178
- city: ""
179
- });
180
- setGoogleFields({ ...googleFields, country: false, state: false, city: false });
181
- };
182
- const handleStateChange = (newState) => {
183
- onChange({
184
- ...value,
185
- state: newState,
186
- city: ""
187
- });
188
- };
189
- 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(
190
- FloatingInput,
191
- {
192
- label,
193
- name: "addressLine1",
194
- value: value.addressLine1 || "",
195
- required,
196
- autoComplete: "off",
197
- onChange: (e) => {
198
- const val = e.target.value;
199
- handleChange("addressLine1", val);
200
- if (!val) {
201
- onChange({
202
- ...value,
203
- addressLine1: "",
204
- city: "",
205
- state: "",
206
- country: "",
207
- pincode: ""
208
- });
209
- setSuggestions([]);
210
- setShowSuggestions(false);
211
- setGoogleFields({ country: false, state: false, city: false, pincode: false });
212
- } else {
213
- if (debounceTimeout.current) clearTimeout(debounceTimeout.current);
214
- debounceTimeout.current = setTimeout(() => {
215
- handleQuerySuggestions(val);
216
- }, 500);
217
- }
218
- },
219
- onFocus: () => suggestions.length > 0 && setShowSuggestions(true)
220
- }
221
- ), 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(
222
- "div",
223
- {
224
- key: idx,
225
- className: "autocomplete-option",
226
- onClick: () => {
227
- const mainText = option?.placePrediction?.structuredFormat?.mainText?.text || "";
228
- handleChange("addressLine1", mainText);
229
- fetchPlaceDetails(option.placePrediction.placeId, mainText);
230
- }
231
- },
232
- /* @__PURE__ */ React.createElement("div", { className: "autocomplete-main-text" }, option?.placePrediction?.structuredFormat?.mainText?.text),
233
- /* @__PURE__ */ React.createElement("div", { className: "autocomplete-secondary-text" }, option?.placePrediction?.structuredFormat?.secondaryText?.text)
234
- ))), 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(
235
- FloatingInput,
236
- {
237
- label: "Address Line 2",
238
- name: "addressLine2",
239
- value: value.addressLine2 || "",
240
- onChange: (e) => handleChange("addressLine2", e.target.value)
241
- }
242
- )), layout !== "compact" && /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-l2" }, /* @__PURE__ */ React.createElement(
243
- FloatingInput,
244
- {
245
- label: "Address Line 2",
246
- name: "addressLine2",
247
- value: value.addressLine2 || "",
248
- onChange: (e) => handleChange("addressLine2", e.target.value)
249
- }
250
- )), /* @__PURE__ */ React.createElement("div", { className: "address-lookup-grid-item col-country" }, /* @__PURE__ */ React.createElement(
251
- FloatingInput,
252
- {
253
- label: "Country",
254
- name: "country",
255
- value: value.country || "",
256
- required,
257
- className: googleFields.country && value.country ? "field-disabled" : "",
258
- readOnly: googleFields.country && !!value.country,
259
- onChange: (e) => handleCountryChange(e.target.value),
260
- list: "countries-list"
261
- }
262
- ), /* @__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(
263
- FloatingInput,
264
- {
265
- label: "State",
266
- name: "state",
267
- value: value.state || "",
268
- required,
269
- disabled: !value.country,
270
- className: googleFields.state && value.state ? "field-disabled" : "",
271
- readOnly: googleFields.state && !!value.state,
272
- onChange: (e) => handleStateChange(e.target.value),
273
- list: "states-list"
274
- }
275
- ), /* @__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(
276
- FloatingInput,
277
- {
278
- label: "City",
279
- name: "city",
280
- value: value.city || "",
281
- required,
282
- disabled: !value.state,
283
- className: googleFields.city && value.city ? "field-disabled" : "",
284
- readOnly: googleFields.city && !!value.city,
285
- onChange: (e) => handleChange("city", e.target.value),
286
- list: "cities-list"
287
- }
288
- ), /* @__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(
289
- FloatingInput,
290
- {
291
- label: "Pincode",
292
- name: "pincode",
293
- value: value.pincode || "",
294
- required,
295
- className: googleFields.pincode && value.pincode ? "field-disabled" : "",
296
- readOnly: googleFields.pincode && !!value.pincode,
297
- onChange: (e) => handleChange("pincode", e.target.value)
298
- }
299
- ), error.pincode && /* @__PURE__ */ React.createElement("div", { className: "field-error-text" }, error.pincode))));
300
- };
301
- var AddressLookup_default = AddressLookup;
302
9
  export {
303
10
  AddressLookup_default as default
304
11
  };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-Q5XKCUE3.js";
4
4
  import {
5
5
  useRufousTheme
6
- } from "./chunk-WNZLBFLQ.js";
6
+ } from "./chunk-HMG3FW2Q.js";
7
7
 
8
8
  // lib/Dialogs/BaseDialog.tsx
9
9
  import * as React from "react";