@crestbase/web-shared-ui 1.0.0 → 1.0.2

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.
Files changed (91) hide show
  1. package/README.md +119 -6
  2. package/dist/components/button/CircleBtn.d.ts +9 -0
  3. package/dist/components/button/CircleBtn.js +5 -0
  4. package/dist/components/button/ShadowButton.d.ts +8 -0
  5. package/dist/components/button/ShadowButton.js +5 -0
  6. package/dist/components/button/index.d.ts +12 -3
  7. package/dist/components/button/index.js +17 -3
  8. package/dist/components/core/Accordion.d.ts +11 -0
  9. package/dist/components/core/Accordion.js +7 -0
  10. package/dist/components/core/AddressInput.d.ts +34 -0
  11. package/dist/components/core/AddressInput.js +88 -0
  12. package/dist/components/core/BottomSheet.d.ts +10 -0
  13. package/dist/components/core/BottomSheet.js +15 -0
  14. package/dist/components/core/Calendar.d.ts +9 -0
  15. package/dist/components/core/Calendar.js +98 -0
  16. package/dist/components/core/CalendarExtended.d.ts +27 -0
  17. package/dist/components/core/CalendarExtended.js +147 -0
  18. package/dist/components/core/Checkbox.d.ts +13 -0
  19. package/dist/components/core/Checkbox.js +10 -0
  20. package/dist/components/core/CustomDropdown.d.ts +19 -0
  21. package/dist/components/core/CustomDropdown.js +41 -0
  22. package/dist/components/core/Modal.d.ts +12 -0
  23. package/dist/components/core/Modal.js +12 -0
  24. package/dist/components/core/NumberInput.d.ts +12 -0
  25. package/dist/components/core/NumberInput.js +34 -0
  26. package/dist/components/core/NumberInputWithCommas.d.ts +10 -0
  27. package/dist/components/core/NumberInputWithCommas.js +19 -0
  28. package/dist/components/core/OptionsDropdown.d.ts +17 -0
  29. package/dist/components/core/OptionsDropdown.js +44 -0
  30. package/dist/components/core/OtpInput.d.ts +9 -0
  31. package/dist/components/core/OtpInput.js +54 -0
  32. package/dist/components/core/PreviewArea.d.ts +18 -0
  33. package/dist/components/core/PreviewArea.js +31 -0
  34. package/dist/components/core/SelectionList.d.ts +16 -0
  35. package/dist/components/core/SelectionList.js +9 -0
  36. package/dist/components/core/SquareCheckbox.d.ts +10 -0
  37. package/dist/components/core/SquareCheckbox.js +5 -0
  38. package/dist/components/core/TabNavigation.d.ts +19 -0
  39. package/dist/components/core/TabNavigation.js +11 -0
  40. package/dist/components/core/Textarea.d.ts +10 -0
  41. package/dist/components/core/Textarea.js +8 -0
  42. package/dist/components/core/Toggle.d.ts +10 -0
  43. package/dist/components/core/Toggle.js +11 -0
  44. package/dist/components/core/Upload.d.ts +28 -0
  45. package/dist/components/core/Upload.js +76 -0
  46. package/dist/components/core/UploadArea.d.ts +14 -0
  47. package/dist/components/core/UploadArea.js +13 -0
  48. package/dist/components/core/input.d.ts +11 -0
  49. package/dist/components/core/input.js +24 -0
  50. package/dist/components/index.d.ts +41 -1
  51. package/dist/components/index.js +25 -1
  52. package/dist/components/navigation/Logo.d.ts +7 -0
  53. package/dist/components/navigation/Logo.js +7 -0
  54. package/dist/components/notification/GlobalNotificationProvider.d.ts +4 -0
  55. package/dist/components/notification/GlobalNotificationProvider.js +6 -0
  56. package/dist/components/notification/NotificationPopup.d.ts +1 -0
  57. package/dist/components/notification/NotificationPopup.js +73 -0
  58. package/dist/components/notification/notificationStore.d.ts +15 -0
  59. package/dist/components/notification/notificationStore.js +12 -0
  60. package/dist/components/svg/Crestbase.d.ts +6 -0
  61. package/dist/components/svg/Crestbase.js +5 -0
  62. package/dist/components/svg/CrestbaseColored.d.ts +6 -0
  63. package/dist/components/svg/CrestbaseColored.js +5 -0
  64. package/dist/components/svg/UploadIcon.d.ts +5 -0
  65. package/dist/components/svg/UploadIcon.js +4 -0
  66. package/dist/hooks/index.d.ts +4 -0
  67. package/dist/hooks/index.js +4 -0
  68. package/dist/hooks/useFileUpload.d.ts +35 -0
  69. package/dist/hooks/useFileUpload.js +219 -0
  70. package/dist/hooks/useFileUploadWithNotifications.d.ts +36 -0
  71. package/dist/hooks/useFileUploadWithNotifications.js +39 -0
  72. package/dist/hooks/useResponsive.d.ts +38 -0
  73. package/dist/hooks/useResponsive.js +97 -0
  74. package/dist/index.d.ts +3 -1
  75. package/dist/index.js +3 -1
  76. package/dist/styles.css +2 -0
  77. package/dist/types/property.d.ts +17 -0
  78. package/dist/types/property.js +2 -0
  79. package/dist/utils/fileValidation.d.ts +21 -0
  80. package/dist/utils/fileValidation.js +82 -0
  81. package/dist/utils/googleMapsLoader.d.ts +40 -0
  82. package/dist/utils/googleMapsLoader.js +108 -0
  83. package/dist/utils/index.d.ts +3 -0
  84. package/dist/utils/index.js +13 -0
  85. package/package.json +22 -12
  86. package/dist/components/button/index.d.ts.map +0 -1
  87. package/dist/components/button/index.js.map +0 -1
  88. package/dist/components/index.d.ts.map +0 -1
  89. package/dist/components/index.js.map +0 -1
  90. package/dist/index.d.ts.map +0 -1
  91. package/dist/index.js.map +0 -1
@@ -0,0 +1,40 @@
1
+ declare global {
2
+ interface Window {
3
+ google?: {
4
+ maps?: {
5
+ places?: {
6
+ Autocomplete: new (input: HTMLInputElement, options?: Record<string, unknown>) => {
7
+ addListener: (event: string, callback: () => void) => void;
8
+ getPlace: () => {
9
+ geometry?: {
10
+ location: {
11
+ lat: () => number;
12
+ lng: () => number;
13
+ };
14
+ };
15
+ formatted_address?: string;
16
+ name?: string;
17
+ };
18
+ };
19
+ };
20
+ };
21
+ };
22
+ }
23
+ }
24
+ declare class GoogleMapsLoader {
25
+ private state;
26
+ private scriptId;
27
+ load(callback?: () => void): void;
28
+ isLoaded(): boolean;
29
+ isLoading(): boolean;
30
+ private isGoogleMapsAvailable;
31
+ private loadScript;
32
+ private getApiKey;
33
+ private markAsLoaded;
34
+ }
35
+ export declare const googleMapsLoader: GoogleMapsLoader;
36
+ export declare const useGoogleMaps: (callback?: () => void) => {
37
+ isLoaded: boolean;
38
+ isLoading: boolean;
39
+ };
40
+ export {};
@@ -0,0 +1,108 @@
1
+ // Global Google Maps API loader utility for shared UI
2
+ // Prevents multiple script inclusions and manages loading state
3
+ import React from "react";
4
+ class GoogleMapsLoader {
5
+ constructor() {
6
+ this.state = {
7
+ isLoaded: false,
8
+ isLoading: false,
9
+ callbacks: [],
10
+ };
11
+ this.scriptId = "google-maps-script";
12
+ }
13
+ load(callback) {
14
+ if (this.state.isLoaded) {
15
+ callback?.();
16
+ return;
17
+ }
18
+ if (callback) {
19
+ this.state.callbacks.push(callback);
20
+ }
21
+ if (this.state.isLoading) {
22
+ return;
23
+ }
24
+ if (this.isGoogleMapsAvailable()) {
25
+ this.markAsLoaded();
26
+ return;
27
+ }
28
+ const existingScript = document.getElementById(this.scriptId);
29
+ if (existingScript) {
30
+ this.state.isLoading = true;
31
+ return;
32
+ }
33
+ this.state.isLoading = true;
34
+ this.loadScript();
35
+ }
36
+ isLoaded() {
37
+ return this.state.isLoaded || this.isGoogleMapsAvailable();
38
+ }
39
+ isLoading() {
40
+ return this.state.isLoading;
41
+ }
42
+ isGoogleMapsAvailable() {
43
+ return typeof window !== "undefined" && !!(window.google && window.google.maps);
44
+ }
45
+ loadScript() {
46
+ const script = document.createElement("script");
47
+ script.id = this.scriptId;
48
+ const apiKey = this.getApiKey();
49
+ script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places`;
50
+ script.async = true;
51
+ script.defer = true;
52
+ script.onload = () => {
53
+ this.markAsLoaded();
54
+ };
55
+ script.onerror = () => {
56
+ console.error("Failed to load Google Maps API");
57
+ this.state.isLoading = false;
58
+ };
59
+ document.head.appendChild(script);
60
+ }
61
+ getApiKey() {
62
+ try {
63
+ const fromProcess = typeof process !== "undefined" ? process?.env?.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY : undefined;
64
+ const fromWindow = typeof window !== "undefined" ? window?.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY : undefined;
65
+ const key = fromProcess || fromWindow || "";
66
+ if (!key) {
67
+ console.warn("Google Maps API key is missing. Set NEXT_PUBLIC_GOOGLE_MAPS_API_KEY.");
68
+ }
69
+ return key;
70
+ }
71
+ catch {
72
+ return "";
73
+ }
74
+ }
75
+ markAsLoaded() {
76
+ this.state.isLoaded = true;
77
+ this.state.isLoading = false;
78
+ this.state.callbacks.forEach((callback) => {
79
+ try {
80
+ callback();
81
+ }
82
+ catch (error) {
83
+ console.error("Error executing Google Maps callback:", error);
84
+ }
85
+ });
86
+ this.state.callbacks = [];
87
+ }
88
+ }
89
+ export const googleMapsLoader = new GoogleMapsLoader();
90
+ export const useGoogleMaps = (callback) => {
91
+ const [isLoaded, setIsLoaded] = React.useState(googleMapsLoader.isLoaded());
92
+ const [isLoading, setIsLoading] = React.useState(googleMapsLoader.isLoading());
93
+ React.useEffect(() => {
94
+ if (googleMapsLoader.isLoaded()) {
95
+ setIsLoaded(true);
96
+ setIsLoading(false);
97
+ callback?.();
98
+ return;
99
+ }
100
+ setIsLoading(true);
101
+ googleMapsLoader.load(() => {
102
+ setIsLoaded(true);
103
+ setIsLoading(false);
104
+ callback?.();
105
+ });
106
+ }, [callback]);
107
+ return { isLoaded, isLoading };
108
+ };
@@ -0,0 +1,3 @@
1
+ export declare function formatNumberWithCommas(value: string | number): string;
2
+ export declare function getCleanNumber(value: string | number): string;
3
+ export { isImageFile, isVideoFile, isVideoFileGeneric, validateImageRequirement, separateFilesByType, getFileType, validateFileCollection, } from "./fileValidation";
@@ -0,0 +1,13 @@
1
+ export function formatNumberWithCommas(value) {
2
+ const str = String(value ?? "").replace(/[^\d.]/g, "");
3
+ if (!str)
4
+ return "";
5
+ const [intPart, decimalPart] = str.split(".");
6
+ const withCommas = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
7
+ return decimalPart ? `${withCommas}.${decimalPart}` : withCommas;
8
+ }
9
+ export function getCleanNumber(value) {
10
+ return String(value ?? "").replace(/[^\d.]/g, "");
11
+ }
12
+ // File validation utils
13
+ export { isImageFile, isVideoFile, isVideoFileGeneric, validateImageRequirement, separateFilesByType, getFileType, validateFileCollection, } from "./fileValidation";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crestbase/web-shared-ui",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Shared UI components for Crestbase web app and admin",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,9 +9,11 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "build": "tsc",
13
- "dev": "tsc --watch",
14
- "prepublishOnly": "yarn build",
12
+ "build": "rm -rf dist && tsc && tailwindcss -i ./src/styles.css -o ./dist/styles.css --minify && node scripts/strip-preflight.js",
13
+ "dev:ts": "tsc --watch --preserveWatchOutput",
14
+ "dev:css": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --watch",
15
+ "dev": "sh -c 'npm run dev:ts & npm run dev:css'",
16
+ "prepublishOnly": "npm run build",
15
17
  "lint": "eslint src --ext .ts,.tsx"
16
18
  },
17
19
  "keywords": [
@@ -24,17 +26,25 @@
24
26
  "author": "EmmanuelChika <Developer.mycrestbase@gmail.com>",
25
27
  "license": "MIT",
26
28
  "peerDependencies": {
27
- "@types/react": "^18.0.0",
28
- "@types/react-dom": "^18.0.0",
29
- "react": "^18.0.0",
30
- "react-dom": "^18.0.0"
29
+ "react": "^18 || ^19",
30
+ "react-dom": "^18 || ^19",
31
+ "zustand": "^4 || ^5",
32
+ "lucide-react": ">=0.470.0 <1"
31
33
  },
34
+ "dependencies": {},
32
35
  "devDependencies": {
33
36
  "@types/react": "^19.2.2",
34
37
  "@types/react-dom": "^19.2.2",
35
- "@typescript-eslint/eslint-plugin": "^8.46.2",
36
- "@typescript-eslint/parser": "^8.46.2",
37
38
  "eslint": "^9.38.0",
38
- "typescript": "^5.9.3"
39
- }
39
+ "typescript": "^5.9.3",
40
+ "react": "^19.1.0",
41
+ "react-dom": "^19.1.0",
42
+ "zustand": "^5.0.6",
43
+ "lucide-react": "^0.525.0",
44
+ "tailwindcss": "4.1.16",
45
+ "@tailwindcss/cli": "4.1.16"
46
+ },
47
+ "sideEffects": [
48
+ "dist/styles.css"
49
+ ]
40
50
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/button/index.tsx"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM,+CAEX,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/button/index.tsx"],"names":[],"mappings":";AAEA,MAAM,MAAM,GAAG,GAAG,EAAE;IAClB,OAAO,mCAAiB,CAAC;AAC3B,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,cAAc,cAAc,CAAC"}