@swan-io/lake 8.8.4 → 8.9.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/package.json +1 -1
- package/src/components/Flag.d.ts +11 -4
- package/src/components/Flag.js +21 -25
- package/src/utils/flagCountry.d.ts +3 -0
- package/src/utils/flagCountry.js +5 -1
- package/src/utils/object.d.ts +1 -0
- package/src/utils/object.js +20 -0
- package/src/utils/string.d.ts +1 -0
- package/src/utils/string.js +1 -0
package/package.json
CHANGED
package/src/components/Flag.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { CountryCCA3 } from "@swan-io/shared-business/src/constants/countries";
|
|
1
|
+
import { CountryCCA2, CountryCCA3 } from "@swan-io/shared-business/src/constants/countries";
|
|
2
|
+
export type FlagCode = CountryCCA2 | "EU";
|
|
2
3
|
type Props = {
|
|
4
|
+
width?: number;
|
|
5
|
+
} & ({
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use cca2 prop instead
|
|
8
|
+
*/
|
|
3
9
|
icon: CountryCCA3;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
} | {
|
|
11
|
+
code: FlagCode;
|
|
12
|
+
});
|
|
13
|
+
export declare const Flag: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
7
14
|
export {};
|
package/src/components/Flag.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Lazy } from "@swan-io/boxed";
|
|
3
|
-
import {
|
|
3
|
+
import { getCCA2forCCA3, } from "@swan-io/shared-business/src/constants/countries";
|
|
4
4
|
import { useEffect, useMemo, useState } from "react";
|
|
5
|
+
import { match } from "ts-pattern";
|
|
6
|
+
import { getFlagGlyphName } from "../utils/string";
|
|
5
7
|
import { Svg, Use } from "./Svg";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const UNICODE_OFFSET = 127462 - 65;
|
|
9
|
+
let svgUrl;
|
|
10
|
+
const svgUrlGetter = Lazy(async () => {
|
|
8
11
|
const { default: value } = await import("../assets/images/flags.svg");
|
|
9
|
-
|
|
12
|
+
svgUrl = value;
|
|
10
13
|
return value;
|
|
11
14
|
});
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
+
export const Flag = (props) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const code = "code" in props ? props.code : getCCA2forCCA3(props.icon);
|
|
18
|
+
const width = (_a = props.width) !== null && _a !== void 0 ? _a : 18;
|
|
19
|
+
const [url, setUrl] = useState(svgUrl);
|
|
15
20
|
useEffect(() => {
|
|
16
|
-
if (
|
|
17
|
-
void
|
|
21
|
+
if (svgUrl == null) {
|
|
22
|
+
void svgUrlGetter.get().then(setUrl);
|
|
18
23
|
}
|
|
19
24
|
}, []);
|
|
20
25
|
const flag = useMemo(() => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(UNICODE_OFFSET + cca2.charCodeAt(1)).toString(16));
|
|
29
|
-
}, [icon]);
|
|
30
|
-
return (_jsx(Svg, { viewBox: "0 0 18 18",
|
|
31
|
-
// eslint-disable-next-line react-native/no-inline-styles
|
|
32
|
-
style: {
|
|
33
|
-
borderRadius: 2,
|
|
34
|
-
width,
|
|
35
|
-
height: width,
|
|
36
|
-
}, children: url != null && flag != null ? _jsx(Use, { xlinkHref: `${url}#${flag}` }) : null }));
|
|
26
|
+
return match(code)
|
|
27
|
+
.with("EU", () => getFlagGlyphName("🇪🇺"))
|
|
28
|
+
.otherwise(() => {
|
|
29
|
+
return `${(UNICODE_OFFSET + code.charCodeAt(0)).toString(16)}-${(UNICODE_OFFSET + code.charCodeAt(1)).toString(16)}`;
|
|
30
|
+
});
|
|
31
|
+
}, [code]);
|
|
32
|
+
return (_jsx(Svg, { viewBox: "0 0 18 18", style: { height: width, width }, children: url != null && flag != null ? _jsx(Use, { xlinkHref: `${url}#${flag}` }) : null }));
|
|
37
33
|
};
|
package/src/utils/flagCountry.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { getFlagGlyphName as fn } from "./string";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Import this function from string.ts instead
|
|
4
|
+
*/
|
|
5
|
+
export const getFlagGlyphName = fn;
|
package/src/utils/object.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const isPlainObject: (value: unknown) => boolean;
|
|
2
2
|
export declare const pick: <T extends Record<PropertyKey, unknown>, const K extends keyof T>(object: T, keys: K[]) => Pick<T, K>;
|
|
3
3
|
export declare const omit: <T extends Record<PropertyKey, unknown>, const K extends keyof T>(object: T, keys: K[]) => Omit<T, K>;
|
|
4
|
+
export declare const deepEqual: (a: unknown, b: unknown) => boolean;
|
package/src/utils/object.js
CHANGED
|
@@ -9,3 +9,23 @@ export const omit = (object, keys) => {
|
|
|
9
9
|
const disallowedKeys = new Set(keys);
|
|
10
10
|
return Object.fromEntries(Object.entries(object).filter(([key]) => !disallowedKeys.has(key)));
|
|
11
11
|
};
|
|
12
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
13
|
+
export const deepEqual = (a, b) => {
|
|
14
|
+
if (Object.is(a, b)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const aKeys = Object.keys(a);
|
|
21
|
+
const bKeys = Object.keys(b);
|
|
22
|
+
if (aKeys.length !== bKeys.length) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
for (const key of aKeys) {
|
|
26
|
+
if (!hasOwnProperty.call(b, key) || !deepEqual(a[key], b[key])) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
};
|
package/src/utils/string.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare const upperCase: <T extends string>(value: T) => Uppercase<T>;
|
|
|
8
8
|
export declare const capitalize: <T extends string>(value: T) => Capitalize<T>;
|
|
9
9
|
export declare const uncapitalize: <T extends string>(value: T) => Uncapitalize<T>;
|
|
10
10
|
export declare const optionFromString: (value: string) => Option<string>;
|
|
11
|
+
export declare const getFlagGlyphName: (flag: string) => string;
|
package/src/utils/string.js
CHANGED
|
@@ -233,3 +233,4 @@ export const upperCase = (value) => value.toUpperCase();
|
|
|
233
233
|
export const capitalize = (value) => `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
|
|
234
234
|
export const uncapitalize = (value) => `${value.charAt(0).toLowerCase()}${value.slice(1)}`;
|
|
235
235
|
export const optionFromString = (value) => value !== "" ? Option.Some(value) : Option.None();
|
|
236
|
+
export const getFlagGlyphName = (flag) => { var _a, _b, _c, _d; return `${(_b = (_a = flag.codePointAt(0)) === null || _a === void 0 ? void 0 : _a.toString(16)) !== null && _b !== void 0 ? _b : ""}-${(_d = (_c = flag.codePointAt(2)) === null || _c === void 0 ? void 0 : _c.toString(16)) !== null && _d !== void 0 ? _d : ""}`; };
|