@arkyn/components 1.3.96 → 1.3.98

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ import { GoogleSearchPlacesProps } from "@arkyn/types";
2
+ declare function GoogleSearchPlaces({ googleMapsApiKey, onChange, options, ...rest }: GoogleSearchPlacesProps): import("react/jsx-runtime").JSX.Element;
3
+ export { GoogleSearchPlaces };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GoogleSearchPlaces/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAYvD,iBAAS,kBAAkB,CAAC,EAC1B,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,GAAG,IAAI,EACR,EAAE,uBAAuB,2CA4CzB;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { LoadScript, StandaloneSearchBox } from "@react-google-maps/api";
3
+ import { useState } from "react";
4
+ import { Input } from "../Input";
5
+ function GoogleSearchPlaces({ googleMapsApiKey, onChange, options, ...rest }) {
6
+ const [searchBox, setSearchBox] = useState(null);
7
+ const handleLoad = (ref) => setSearchBox(ref);
8
+ const handlePlacesChanged = () => {
9
+ const places = searchBox.getPlaces();
10
+ const place = places[0];
11
+ const address_components = place?.address_components;
12
+ function findData(key) {
13
+ const data = address_components.find((item) => item.types[0] === key);
14
+ if (data)
15
+ return data.long_name;
16
+ return "";
17
+ }
18
+ if (place) {
19
+ const street = findData("route");
20
+ const district = findData("sublocality_level_1");
21
+ const city = findData("administrative_area_level_2");
22
+ const state = findData("administrative_area_level_1");
23
+ const cep = findData("postal_code");
24
+ const sendPlace = { street, city, state, district, cep };
25
+ onChange && onChange(sendPlace);
26
+ }
27
+ };
28
+ return (_jsx(LoadScript, { libraries: ["places"], googleMapsApiKey: googleMapsApiKey, loadingElement: _jsx(Input, { type: "text", ...rest }), children: _jsx(StandaloneSearchBox, { onLoad: handleLoad, onPlacesChanged: handlePlacesChanged, options: options, children: _jsx(Input, { type: "text", ...rest }) }) }));
29
+ }
30
+ export { GoogleSearchPlaces };
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { RadioBox, RadioGroup } from "./components/Radio";
14
14
  export { Select } from "./components/Select";
15
15
  export { Switch } from "./components/Switch";
16
16
  export { Textarea } from "./components/Textarea";
17
+ export { GoogleSearchPlaces } from "./components/GoogleSearchPlaces";
17
18
  export { BreadcrumbContainer, BreadcrumbLink } from "./components/Breadcrumb";
18
19
  export { Pagination } from "./components/Pagination";
19
20
  export { TabButton, TabContainer } from "./components/Tabs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,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c,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ export { RadioBox, RadioGroup } from "./components/Radio";
16
16
  export { Select } from "./components/Select";
17
17
  export { Switch } from "./components/Switch";
18
18
  export { Textarea } from "./components/Textarea";
19
+ export { GoogleSearchPlaces } from "./components/GoogleSearchPlaces";
19
20
  // Navigation
20
21
  export { BreadcrumbContainer, BreadcrumbLink } from "./components/Breadcrumb";
21
22
  export { Pagination } from "./components/Pagination";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.96",
3
+ "version": "1.3.98",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -0,0 +1,64 @@
1
+ import { GoogleSearchPlacesProps } from "@arkyn/types";
2
+ import { LoadScript, StandaloneSearchBox } from "@react-google-maps/api";
3
+ import { useState } from "react";
4
+
5
+ import { Input } from "../Input";
6
+
7
+ type AddressComponentsType = {
8
+ long_name: string;
9
+ short_name: string;
10
+ types: string[];
11
+ }[];
12
+
13
+ function GoogleSearchPlaces({
14
+ googleMapsApiKey,
15
+ onChange,
16
+ options,
17
+ ...rest
18
+ }: GoogleSearchPlacesProps) {
19
+ const [searchBox, setSearchBox] = useState<any>(null);
20
+ const handleLoad = (ref: any) => setSearchBox(ref);
21
+
22
+ const handlePlacesChanged = () => {
23
+ const places = searchBox.getPlaces();
24
+ const place = places[0];
25
+
26
+ const address_components =
27
+ place?.address_components as AddressComponentsType;
28
+
29
+ function findData(key: string) {
30
+ const data = address_components.find((item) => item.types[0] === key);
31
+ if (data) return data.long_name;
32
+ return "";
33
+ }
34
+
35
+ if (place) {
36
+ const street = findData("route");
37
+ const district = findData("sublocality_level_1");
38
+ const city = findData("administrative_area_level_2");
39
+ const state = findData("administrative_area_level_1");
40
+ const cep = findData("postal_code");
41
+
42
+ const sendPlace = { street, city, state, district, cep };
43
+ onChange && onChange(sendPlace);
44
+ }
45
+ };
46
+
47
+ return (
48
+ <LoadScript
49
+ libraries={["places"]}
50
+ googleMapsApiKey={googleMapsApiKey}
51
+ loadingElement={<Input type="text" {...rest} />}
52
+ >
53
+ <StandaloneSearchBox
54
+ onLoad={handleLoad}
55
+ onPlacesChanged={handlePlacesChanged}
56
+ options={options}
57
+ >
58
+ <Input type="text" {...rest} />
59
+ </StandaloneSearchBox>
60
+ </LoadScript>
61
+ );
62
+ }
63
+
64
+ export { GoogleSearchPlaces };
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export { RadioBox, RadioGroup } from "./components/Radio";
29
29
  export { Select } from "./components/Select";
30
30
  export { Switch } from "./components/Switch";
31
31
  export { Textarea } from "./components/Textarea";
32
+ export { GoogleSearchPlaces } from "./components/GoogleSearchPlaces";
32
33
 
33
34
  // Navigation
34
35
  export { BreadcrumbContainer, BreadcrumbLink } from "./components/Breadcrumb";