@vincentgraul/react-components 1.0.30 → 1.0.32
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CountrySelector.d.ts","sourceRoot":"","sources":["../../src/country-selector/CountrySelector.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAI9D,UAAU,KAAK;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"CountrySelector.d.ts","sourceRoot":"","sources":["../../src/country-selector/CountrySelector.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAI9D,UAAU,KAAK;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE,KAAK,2CA8CnD"}
|
|
@@ -12,11 +12,18 @@ import { useEffect, useState } from "react";
|
|
|
12
12
|
import Select from "../select/Select";
|
|
13
13
|
import { capitalize } from "@vincentgraul/utils/word";
|
|
14
14
|
export default function CountrySelector(props) {
|
|
15
|
-
const { className, languages, onChange } = props;
|
|
15
|
+
const { className, languages, onChange, flagWidth = "30px" } = props;
|
|
16
16
|
const [options, setOptions] = useState(null);
|
|
17
|
+
const fileExtension = import.meta ? import.meta.env.STORYBOOK_SVG_FILE_EXTENSION : "js";
|
|
18
|
+
const FlagStyle = {
|
|
19
|
+
display: "block",
|
|
20
|
+
width: flagWidth,
|
|
21
|
+
margin: "auto",
|
|
22
|
+
borderRadius: "2px",
|
|
23
|
+
};
|
|
17
24
|
useEffect(() => {
|
|
18
25
|
const fetchIcon = (name) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const { default: Flag } = yield import(`./icons/${capitalize(name)}
|
|
26
|
+
const { default: Flag } = yield import(`./icons/${capitalize(name)}.${fileExtension}`);
|
|
20
27
|
return Flag;
|
|
21
28
|
});
|
|
22
29
|
const prepareOptions = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,9 +42,3 @@ export default function CountrySelector(props) {
|
|
|
35
42
|
}
|
|
36
43
|
return (_jsx(Select, { className: `country-selector ${className}`, options: options, onChange: onChange }));
|
|
37
44
|
}
|
|
38
|
-
const FlagStyle = {
|
|
39
|
-
display: "block",
|
|
40
|
-
width: "30px",
|
|
41
|
-
margin: "auto",
|
|
42
|
-
borderRadius: "2px",
|
|
43
|
-
};
|
package/build/modal/Modal.js
CHANGED
|
@@ -5,7 +5,7 @@ import useOutsideAlerter from "../outside-alerter/useOutsideAlerter";
|
|
|
5
5
|
export default function Modal(props) {
|
|
6
6
|
const { className, children, onClickedOutside } = props;
|
|
7
7
|
const ref = useRef(null);
|
|
8
|
-
const hasClickedOutside = useOutsideAlerter(ref);
|
|
8
|
+
const { hasClickedOutside } = useOutsideAlerter(ref);
|
|
9
9
|
useEffect(() => {
|
|
10
10
|
if (onClickedOutside && hasClickedOutside) {
|
|
11
11
|
onClickedOutside();
|
|
@@ -4,20 +4,19 @@ export default function useOutsideAlerter(ref) {
|
|
|
4
4
|
const handleOnReset = () => {
|
|
5
5
|
setClickedOutside(false);
|
|
6
6
|
};
|
|
7
|
-
const handleOnClickOutside = (event) => {
|
|
8
|
-
if (event.target && ref.current) {
|
|
9
|
-
if (!ref.current.contains(event.target)) {
|
|
10
|
-
setClickedOutside(true);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
7
|
useEffect(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const handleOnClickOutside = (event) => {
|
|
9
|
+
if (event.target && ref.current) {
|
|
10
|
+
const value = !ref.current.contains(event.target);
|
|
11
|
+
if (value !== hasClickedOutside) {
|
|
12
|
+
setClickedOutside(value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
document.addEventListener("mousedown", handleOnClickOutside);
|
|
18
17
|
return () => {
|
|
19
|
-
document.removeEventListener("mousedown",
|
|
18
|
+
document.removeEventListener("mousedown", handleOnClickOutside);
|
|
20
19
|
};
|
|
21
|
-
}, [ref]);
|
|
20
|
+
}, [ref, hasClickedOutside]);
|
|
22
21
|
return { hasClickedOutside, onReset: handleOnReset };
|
|
23
22
|
}
|