@swan-io/lake 8.9.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/lake",
3
- "version": "8.9.0",
3
+ "version": "8.9.1",
4
4
  "engines": {
5
5
  "node": ">=20.9.0",
6
6
  "yarn": "^1.22.0"
@@ -1,4 +1,5 @@
1
1
  import { CountryCCA2, CountryCCA3 } from "@swan-io/shared-business/src/constants/countries";
2
+ export type FlagCode = CountryCCA2 | "EU";
2
3
  type Props = {
3
4
  width?: number;
4
5
  } & ({
@@ -7,7 +8,7 @@ type Props = {
7
8
  */
8
9
  icon: CountryCCA3;
9
10
  } | {
10
- cca2: CountryCCA2;
11
+ code: FlagCode;
11
12
  });
12
13
  export declare const Flag: (props: Props) => import("react/jsx-runtime").JSX.Element;
13
14
  export {};
@@ -2,6 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Lazy } from "@swan-io/boxed";
3
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
8
  const UNICODE_OFFSET = 127462 - 65;
7
9
  let svgUrl;
@@ -12,7 +14,7 @@ const svgUrlGetter = Lazy(async () => {
12
14
  });
13
15
  export const Flag = (props) => {
14
16
  var _a;
15
- const cca2 = "cca2" in props ? props.cca2 : getCCA2forCCA3(props.icon);
17
+ const code = "code" in props ? props.code : getCCA2forCCA3(props.icon);
16
18
  const width = (_a = props.width) !== null && _a !== void 0 ? _a : 18;
17
19
  const [url, setUrl] = useState(svgUrl);
18
20
  useEffect(() => {
@@ -20,6 +22,12 @@ export const Flag = (props) => {
20
22
  void svgUrlGetter.get().then(setUrl);
21
23
  }
22
24
  }, []);
23
- const flag = useMemo(() => `${(UNICODE_OFFSET + cca2.charCodeAt(0)).toString(16)}-${(UNICODE_OFFSET + cca2.charCodeAt(1)).toString(16)}`, [cca2]);
25
+ const flag = useMemo(() => {
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]);
24
32
  return (_jsx(Svg, { viewBox: "0 0 18 18", style: { height: width, width }, children: url != null && flag != null ? _jsx(Use, { xlinkHref: `${url}#${flag}` }) : null }));
25
33
  };
@@ -1,4 +1,4 @@
1
1
  /**
2
- * @deprecated Use the Flag component instead
2
+ * @deprecated Import this function from string.ts instead
3
3
  */
4
4
  export declare const getFlagGlyphName: (flag: string) => string;
@@ -1,4 +1,5 @@
1
+ import { getFlagGlyphName as fn } from "./string";
1
2
  /**
2
- * @deprecated Use the Flag component instead
3
+ * @deprecated Import this function from string.ts instead
3
4
  */
4
- 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 : ""}`; };
5
+ export const getFlagGlyphName = fn;
@@ -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;
@@ -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 : ""}`; };