@ews-admin/global-design-system 1.25.0 → 1.27.0

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.
@@ -2,7 +2,7 @@ import { type ClassValue } from "clsx";
2
2
  export { createEnvConfig } from "./env-config";
3
3
  export { SupportedCountry, getRegionsByCountry, getRegionOptions, } from "./locations";
4
4
  export type {} from "./locations";
5
- export { COUNTRY_CODES, extractCountryCodeFromPhoneNumber, formatPhoneNumberWithCountryCode, getDefaultCountryCode, } from "./phone";
5
+ export { COUNTRY_CODES, extractCountryCodeFromPhoneNumber, formatPhoneNumberForDisplay, formatPhoneNumberWithCountryCode, getDefaultCountryCode, } from "./phone";
6
6
  export type { CountryCodeOption, CountryCodeSelectProps } from "./phone";
7
7
  export type { EnvConfig, EnvConfigOverrides, Environment, } from "./env-config";
8
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,aAAa,EACb,iCAAiC,EACjC,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACzE,YAAY,EACV,SAAS,EACT,kBAAkB,EAClB,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAE9B;;;;GAIG;AACH,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc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AG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAMlC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAQ,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAE7C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAMzD;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,WAAW,QAAQ;IACnB,WAAW,QAAQ;IACnB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,OAAO,YAAY;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,EAUlC,CAAC"}
@@ -51,4 +51,18 @@ export declare function extractCountryCodeFromPhoneNumber(phoneNumber: string, c
51
51
  * // don't re-prepend the dial code)
52
52
  */
53
53
  export declare function formatPhoneNumberWithCountryCode(phoneNumber: string, countryCode?: string): string;
54
+ /**
55
+ * Formats a phone number for display only: the country code, then the
56
+ * national digits in their usual groups. Do not use it for values sent to the
57
+ * API, form values or tel: links; formatPhoneNumberWithCountryCode gives the
58
+ * unspaced value for those. A number from another country, or of an
59
+ * unexpected length, is returned as formatPhoneNumberWithCountryCode returns it.
60
+ *
61
+ * @example
62
+ * formatPhoneNumberForDisplay("221771234567") // "+221 77 123 45 67" (backend's storage format)
63
+ * formatPhoneNumberForDisplay("771234567") // "+221 77 123 45 67"
64
+ * formatPhoneNumberForDisplay("+23566123456") // "+235 66 12 34 56"
65
+ * formatPhoneNumberForDisplay("+22177123") // "+22177123" (unexpected length, unchanged)
66
+ */
67
+ export declare function formatPhoneNumberForDisplay(phoneNumber: string, countryCode?: string): string;
54
68
  //# sourceMappingURL=phone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,iBAAiB,EAG5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAgBR;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CA+BrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAAe,GAC3B,MAAM,CA2BR"}
1
+ {"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,iBAAiB,EAG5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAgBR;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,GACf;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CA+BrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAAe,GAC3B,MAAM,CA2BR;AAYD;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAAe,GAC3B,MAAM,CAiBR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ews-admin/global-design-system",
3
- "version": "1.25.0",
3
+ "version": "1.27.0",
4
4
  "description": "EWS Global Design System - Reusable components for EWS applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -50,6 +50,7 @@
50
50
  "eslint": "^9.36.0",
51
51
  "eslint-plugin-react": "^7.37.5",
52
52
  "eslint-plugin-react-hooks": "^5.2.0",
53
+ "jest": "29",
53
54
  "postcss": "^8.5.6",
54
55
  "rollup": "^4.6.1",
55
56
  "rollup-plugin-dts": "^6.1.0",
@@ -57,6 +58,7 @@
57
58
  "rollup-plugin-postcss": "^4.0.2",
58
59
  "storybook": "^7.5.0",
59
60
  "tailwindcss": "^3.4.0",
61
+ "ts-jest": "29",
60
62
  "typescript": "^5.2.2",
61
63
  "vite": "^4.5.0"
62
64
  },
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { Lock } from "lucide-react";
3
+
4
+ /**
5
+ * The loader is purely presentational: the caller decides when to render it
6
+ * (while the session is validated, fetched or terminated) and provides
7
+ * already-translated labels.
8
+ */
9
+ export interface SecureLoaderProps {
10
+ label: string;
11
+ /** Extra line shown under the label. */
12
+ description?: string;
13
+ }
14
+
15
+ /**
16
+ * Full-screen loader (lock icon with a spinner) shown while the user's
17
+ * session is being checked.
18
+ */
19
+ const SecureLoader: React.FC<SecureLoaderProps> = ({ label, description }) => (
20
+ <div
21
+ data-testid="secure-loader"
22
+ className="flex min-h-screen items-center justify-center bg-gray-100"
23
+ >
24
+ <div className="flex flex-col items-center rounded-lg bg-white p-6 shadow-lg">
25
+ <div className="relative">
26
+ <Lock className="h-16 w-16 text-gray-500" />
27
+ <div className="absolute bottom-2 right-1 h-6 w-6 animate-spin rounded-full border-4 border-gray-300 border-t-green-500"></div>
28
+ </div>
29
+ <p className="mt-4 text-lg text-gray-600">{label}</p>
30
+ {description && (
31
+ <p className="mt-2 text-sm text-gray-500">{description}</p>
32
+ )}
33
+ </div>
34
+ </div>
35
+ );
36
+
37
+ export default SecureLoader;
@@ -0,0 +1,2 @@
1
+ export { default as SecureLoader } from "./SecureLoader";
2
+ export type { SecureLoaderProps } from "./SecureLoader";
package/src/index.ts CHANGED
@@ -52,6 +52,9 @@ export type { TagListProps } from "./components/TagList";
52
52
  export { PaymentDueBanner } from "./components/PaymentDueBanner";
53
53
  export type { PaymentDueBannerProps } from "./components/PaymentDueBanner";
54
54
 
55
+ export { SecureLoader } from "./components/SecureLoader";
56
+ export type { SecureLoaderProps } from "./components/SecureLoader";
57
+
55
58
  // Molecules
56
59
  export { SpecialtySearchAutocomplete } from "./molecules";
57
60
  export type { Specialty, SpecialtySearchAutocompleteProps } from "./molecules";
@@ -73,6 +76,7 @@ export {
73
76
  formatDate,
74
77
  type FormatDateOptions,
75
78
  formatNumeric,
79
+ formatPhoneNumberForDisplay,
76
80
  formatPhoneNumberWithCountryCode,
77
81
  generateId,
78
82
  getDefaultCountryCode,
@@ -10,6 +10,7 @@ export type {} from "./locations";
10
10
  export {
11
11
  COUNTRY_CODES,
12
12
  extractCountryCodeFromPhoneNumber,
13
+ formatPhoneNumberForDisplay,
13
14
  formatPhoneNumberWithCountryCode,
14
15
  getDefaultCountryCode,
15
16
  } from "./phone";
@@ -139,3 +139,48 @@ export function formatPhoneNumberWithCountryCode(
139
139
 
140
140
  return `${countryCode}${cleaned}`;
141
141
  }
142
+
143
+ /**
144
+ * National digit groups used to display a phone number, per country code:
145
+ * Senegal numbers have 9 national digits (77 123 45 67, 33 823 45 67), Chad
146
+ * numbers 8 (66 12 34 56).
147
+ */
148
+ const DISPLAY_DIGIT_GROUPS: Record<string, number[]> = {
149
+ "+221": [2, 3, 2, 2],
150
+ "+235": [2, 2, 2, 2],
151
+ };
152
+
153
+ /**
154
+ * Formats a phone number for display only: the country code, then the
155
+ * national digits in their usual groups. Do not use it for values sent to the
156
+ * API, form values or tel: links; formatPhoneNumberWithCountryCode gives the
157
+ * unspaced value for those. A number from another country, or of an
158
+ * unexpected length, is returned as formatPhoneNumberWithCountryCode returns it.
159
+ *
160
+ * @example
161
+ * formatPhoneNumberForDisplay("221771234567") // "+221 77 123 45 67" (backend's storage format)
162
+ * formatPhoneNumberForDisplay("771234567") // "+221 77 123 45 67"
163
+ * formatPhoneNumberForDisplay("+23566123456") // "+235 66 12 34 56"
164
+ * formatPhoneNumberForDisplay("+22177123") // "+22177123" (unexpected length, unchanged)
165
+ */
166
+ export function formatPhoneNumberForDisplay(
167
+ phoneNumber: string,
168
+ countryCode: string = "+221"
169
+ ): string {
170
+ const canonical = formatPhoneNumberWithCountryCode(phoneNumber, countryCode);
171
+ const code = COUNTRY_CODES.find(({ code: c }) => canonical.startsWith(c))?.code;
172
+ const groups = code ? DISPLAY_DIGIT_GROUPS[code] : undefined;
173
+ if (!code || !groups) return canonical;
174
+
175
+ const national = canonical.slice(code.length).replace(/[\s-]/g, "");
176
+ const expectedLength = groups.reduce((sum, size) => sum + size, 0);
177
+ if (!/^\d+$/.test(national) || national.length !== expectedLength) return canonical;
178
+
179
+ const parts: string[] = [];
180
+ let start = 0;
181
+ for (const size of groups) {
182
+ parts.push(national.slice(start, start + size));
183
+ start += size;
184
+ }
185
+ return `${code} ${parts.join(" ")}`;
186
+ }