igloo-d2c-components 1.0.6 → 1.0.8

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/dist/cjs/index.js CHANGED
@@ -1,2 +1,497 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("@mui/material");const n=t.createContext(void 0);function a(){const e=t.useContext(n);if(void 0===e)throw new Error("useTenantTheme must be used within a TenantThemeProvider");return e}exports.Banner=function({title:t,description:n,action:o,gradient:i=!0,sx:p,...s}){const{theme:c}=a(),l=i?`linear-gradient(135deg, ${c.palette.primary?.main} 0%, ${c.palette.primary?.light||c.palette.primary?.main} 100%)`:c.palette.primary?.main;return e.jsxs(r.Box,{sx:{background:l,color:"white",padding:"32px",borderRadius:"12px",textAlign:"center",...p},...s,children:[e.jsx(r.Typography,{variant:"h4",component:"h2",gutterBottom:!0,fontWeight:"bold",children:t}),n&&e.jsx(r.Typography,{variant:"body1",sx:{opacity:.95,mb:o?2:0},children:n}),o&&e.jsx(r.Box,{sx:{mt:2},children:o})]})},exports.Button=function({tenantColored:t=!1,variant:n="contained",sx:o,color:i,...p}){const{theme:s}=a(),c=t?{backgroundColor:s.palette.primary?.main,color:"#fff","&:hover":{backgroundColor:s.palette.primary?.dark||s.palette.primary?.main},...o}:o;return e.jsx(r.Button,{variant:n,color:t?void 0:i,sx:c,...p})},exports.Card=function({title:t,headerAction:n,content:o,actions:i,tenantAccent:p=!1,sx:s,children:c,...l}){const{theme:d}=a(),m=p?{borderTop:`4px solid ${d.palette.primary?.main}`,...s}:s;return e.jsxs(r.Card,{sx:m,...l,children:[t&&e.jsx(r.CardHeader,{title:t,action:n}),(o||c)&&e.jsx(r.CardContent,{children:o||c}),i&&e.jsx(r.CardActions,{children:i})]})},exports.TenantThemeProvider=function({children:r,tenantId:a,theme:o}){const i=t.useMemo(()=>({tenantId:a,theme:o}),[a,o]);return e.jsx(n.Provider,{value:i,children:r})},exports.createThemeCSSVariables=function(e,t="--tenant"){const r={};return e.palette.primary&&Object.entries(e.palette.primary).forEach(([e,n])=>{"string"==typeof n&&(r[`${t}-primary-${e}`]=n)}),e.palette.secondary&&Object.entries(e.palette.secondary).forEach(([e,n])=>{"string"==typeof n&&(r[`${t}-secondary-${e}`]=n)}),e.typography?.fontFamily&&(r[`${t}-font-family`]=e.typography.fontFamily),r},exports.getThemeColor=function(e,t,r="#000000"){const n=t.split(".");let a=e.palette;for(const e of n){if(!a||"object"!=typeof a||!(e in a))return r;a=a[e]}return"string"==typeof a?a:r},exports.mergeTenantTheme=function(e,t){return{...e,palette:{...e.palette,...t.palette,primary:{...e.palette?.primary||{},...t.palette.primary||{}},secondary:{...e.palette?.secondary||{},...t.palette.secondary||{}}},typography:{...e.typography,...t.typography}}},exports.useIsTenant=function(e){const{tenantId:t}=a();return t===e},exports.useTenantId=function(){const{tenantId:e}=a();return e},exports.useTenantTheme=a;
2
- //# sourceMappingURL=index.js.map
1
+ "use client"
2
+ 'use strict';
3
+
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var react = require('react');
6
+ var material = require('@mui/material');
7
+
8
+ const TenantThemeContext = react.createContext(undefined);
9
+ /**
10
+ * TenantThemeProvider
11
+ * Wraps components to provide tenant-specific theming
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * <TenantThemeProvider
16
+ * tenantId="cimb"
17
+ * theme={cimbTheme}
18
+ * >
19
+ * <App />
20
+ * </TenantThemeProvider>
21
+ * ```
22
+ */
23
+ function TenantThemeProvider({ children, tenantId, theme, }) {
24
+ const value = react.useMemo(() => ({
25
+ tenantId,
26
+ theme,
27
+ }), [tenantId, theme]);
28
+ return (jsxRuntime.jsx(TenantThemeContext.Provider, Object.assign({ value: value }, { children: children })));
29
+ }
30
+ /**
31
+ * Hook to access tenant theme configuration
32
+ * @throws Error if used outside TenantThemeProvider
33
+ */
34
+ function useTenantTheme() {
35
+ const context = react.useContext(TenantThemeContext);
36
+ if (context === undefined) {
37
+ throw new Error('useTenantTheme must be used within a TenantThemeProvider');
38
+ }
39
+ return context;
40
+ }
41
+ /**
42
+ * Hook to get tenant ID
43
+ */
44
+ function useTenantId() {
45
+ const { tenantId } = useTenantTheme();
46
+ return tenantId;
47
+ }
48
+ /**
49
+ * Hook to check if current tenant matches given tenant ID
50
+ */
51
+ function useIsTenant(checkTenantId) {
52
+ const { tenantId } = useTenantTheme();
53
+ return tenantId === checkTenantId;
54
+ }
55
+
56
+ /**
57
+ * Tenant Theme Configurations
58
+ * Centralized theme definitions for all tenants
59
+ */
60
+ /**
61
+ * Igloo Theme Configuration
62
+ */
63
+ const iglooTheme = {
64
+ palette: {
65
+ primary: {
66
+ dark: '#1300A9',
67
+ main: '#5656F6',
68
+ light: '#8183FF',
69
+ bright: '#C1C1FF',
70
+ plain: '#E1DFFF',
71
+ border: '#5656F6',
72
+ },
73
+ secondary: {
74
+ dim: '#650713',
75
+ dark: '#C55153',
76
+ main: '#FF7D7D',
77
+ bright: '#FF7378',
78
+ mediumBright: '#FF7062',
79
+ light: '#FFB3B1',
80
+ lighter: '#FFEBEB',
81
+ },
82
+ tertiary: {
83
+ dim: '#C5C6CF',
84
+ dark: '#E1E2EB',
85
+ main: '#F5F5FF',
86
+ light: '#FEFBFF',
87
+ bright: '#F9F9F9',
88
+ },
89
+ natural: {
90
+ dim: '#13131B',
91
+ dark: '#5F5E62',
92
+ main: '#929094',
93
+ light: '#C8C5CA',
94
+ bright: '#fff',
95
+ granite: '#666',
96
+ },
97
+ motor: {
98
+ main: '#00CCFF',
99
+ light: 'rgba(0, 208, 255, 0.10)',
100
+ bright: '#DFF9FF',
101
+ },
102
+ car: {
103
+ main: '#00CCFF',
104
+ light: 'rgba(0, 208, 255, 0.10)',
105
+ darkAI: '#06BDCE',
106
+ },
107
+ travel: {
108
+ main: '#00E08B',
109
+ light: 'rgba(0, 228, 130, 0.10)',
110
+ },
111
+ health: {
112
+ main: '#FD72E7',
113
+ },
114
+ life: {
115
+ main: '#C3214B',
116
+ light: 'rgba(195, 33, 75, 0.10)',
117
+ },
118
+ pet: {
119
+ main: '#F3A100',
120
+ },
121
+ },
122
+ typography: {
123
+ fontFamily: '"Manrope", "Roboto", "Helvetica", "Arial", sans-serif',
124
+ },
125
+ logo: '/assets/igloo_nobeta.svg',
126
+ favicon: 'https://static.iglooinsure.com/icons/favicon.ico',
127
+ };
128
+ /**
129
+ * CIMB Theme Configuration
130
+ */
131
+ const cimbTheme = {
132
+ palette: {
133
+ paCimb: {
134
+ main: '#C3214B',
135
+ light: 'rgba(195, 33, 75, 0.10)',
136
+ bright: '#EE0500',
137
+ buttonBg: 'linear-gradient(90deg, color(display-p3 0.6941 0.1961 0.3059) 0%, color(display-p3 0.8941 0.2745 0.1843) 100%)',
138
+ },
139
+ primary: {
140
+ dark: '#A01B3D',
141
+ main: '#C3214B',
142
+ light: '#D04C6F',
143
+ bright: '#E07A92',
144
+ plain: '#F5E6EA',
145
+ border: '#C3214B',
146
+ },
147
+ secondary: {
148
+ dim: '#B71C1C',
149
+ dark: '#D32F2F',
150
+ main: '#EE0500',
151
+ bright: '#F44336',
152
+ mediumBright: '#EF5350',
153
+ light: '#FFCDD2',
154
+ lighter: '#FFEBEE',
155
+ },
156
+ tertiary: {
157
+ dim: '#C5C6CF',
158
+ dark: '#E1E2EB',
159
+ main: '#F5F5FF',
160
+ light: '#FEFBFF',
161
+ bright: '#F9F9F9',
162
+ },
163
+ natural: {
164
+ dim: '#13131B',
165
+ dark: '#5F5E62',
166
+ main: '#929094',
167
+ light: '#C8C5CA',
168
+ bright: '#fff',
169
+ granite: '#666',
170
+ },
171
+ motor: {
172
+ main: '#C3214B',
173
+ light: 'rgba(195, 33, 75, 0.10)',
174
+ bright: '#F5E6EA',
175
+ },
176
+ car: {
177
+ main: '#C3214B',
178
+ light: 'rgba(195, 33, 75, 0.10)',
179
+ darkAI: '#A01B3D',
180
+ },
181
+ travel: {
182
+ main: '#EE0500',
183
+ light: 'rgba(238, 5, 0, 0.10)',
184
+ },
185
+ health: {
186
+ main: '#E91E63',
187
+ light: 'rgba(233, 30, 99, 0.10)',
188
+ },
189
+ life: {
190
+ main: '#C3214B',
191
+ light: 'rgba(195, 33, 75, 0.10)',
192
+ },
193
+ pet: {
194
+ main: '#F3A100',
195
+ },
196
+ },
197
+ typography: {
198
+ fontFamily: '"CIMB Sans", "Roboto", "Helvetica", "Arial", sans-serif',
199
+ },
200
+ logo: '/assets/cimb/cimb-logo.svg',
201
+ favicon: 'https://static.iglooinsure.com/icons/favicon.ico',
202
+ };
203
+ /**
204
+ * Ammetlife Theme Configuration
205
+ */
206
+ const ammetlifeTheme = {
207
+ palette: {
208
+ primary: {
209
+ dark: '#0D47A1',
210
+ main: '#1976D2',
211
+ light: '#42A5F5',
212
+ bright: '#90CAF9',
213
+ plain: '#E3F2FD',
214
+ border: '#1976D2',
215
+ },
216
+ secondary: {
217
+ dim: '#E65100',
218
+ dark: '#EF6C00',
219
+ main: '#FFA726',
220
+ bright: '#FFB74D',
221
+ mediumBright: '#FFCC80',
222
+ light: '#FFE0B2',
223
+ lighter: '#FFF3E0',
224
+ },
225
+ tertiary: {
226
+ dim: '#B0BEC5',
227
+ dark: '#CFD8DC',
228
+ main: '#ECEFF1',
229
+ light: '#FAFAFA',
230
+ bright: '#FFFFFF',
231
+ },
232
+ natural: {
233
+ dim: '#263238',
234
+ dark: '#546E7A',
235
+ main: '#78909C',
236
+ light: '#B0BEC5',
237
+ bright: '#fff',
238
+ granite: '#666',
239
+ },
240
+ motor: {
241
+ main: '#1976D2',
242
+ light: 'rgba(25, 118, 210, 0.10)',
243
+ bright: '#E3F2FD',
244
+ },
245
+ car: {
246
+ main: '#1976D2',
247
+ light: 'rgba(25, 118, 210, 0.10)',
248
+ darkAI: '#1565C0',
249
+ },
250
+ travel: {
251
+ main: '#00C853',
252
+ light: 'rgba(0, 200, 83, 0.10)',
253
+ },
254
+ health: {
255
+ main: '#E91E63',
256
+ light: 'rgba(233, 30, 99, 0.10)',
257
+ },
258
+ life: {
259
+ main: '#9C27B0',
260
+ light: 'rgba(156, 39, 176, 0.10)',
261
+ },
262
+ pet: {
263
+ main: '#FF9800',
264
+ },
265
+ },
266
+ typography: {
267
+ fontFamily: '"Open Sans", "Roboto", "Helvetica", "Arial", sans-serif',
268
+ },
269
+ logo: '/assets/ammetlife/logo-AmMetLife.svg',
270
+ favicon: 'https://static.iglooinsure.com/icons/favicon.ico',
271
+ };
272
+ /**
273
+ * Theme Registry
274
+ * Map of tenant IDs to their theme configurations
275
+ */
276
+ const tenantThemes = {
277
+ igloo: iglooTheme,
278
+ cimb: cimbTheme,
279
+ ammetlife: ammetlifeTheme,
280
+ };
281
+ /**
282
+ * Get theme configuration by tenant ID
283
+ * @param tenantId - The tenant identifier
284
+ * @returns Theme configuration for the specified tenant
285
+ * @throws Error if tenant ID is not found
286
+ */
287
+ function getTenantTheme(tenantId) {
288
+ const theme = tenantThemes[tenantId];
289
+ if (!theme) {
290
+ throw new Error(`Theme not found for tenant: ${tenantId}. Available tenants: ${Object.keys(tenantThemes).join(', ')}`);
291
+ }
292
+ return theme;
293
+ }
294
+ /**
295
+ * Check if a tenant ID is valid
296
+ * @param tenantId - The tenant identifier to validate
297
+ * @returns True if the tenant ID is valid
298
+ */
299
+ function isValidTenantId(tenantId) {
300
+ return tenantId in tenantThemes;
301
+ }
302
+ /**
303
+ * Get all available tenant IDs
304
+ * @returns Array of all registered tenant IDs
305
+ */
306
+ function getAvailableTenants() {
307
+ return Object.keys(tenantThemes);
308
+ }
309
+
310
+ /******************************************************************************
311
+ Copyright (c) Microsoft Corporation.
312
+
313
+ Permission to use, copy, modify, and/or distribute this software for any
314
+ purpose with or without fee is hereby granted.
315
+
316
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
317
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
318
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
319
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
320
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
321
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
322
+ PERFORMANCE OF THIS SOFTWARE.
323
+ ***************************************************************************** */
324
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
325
+
326
+
327
+ function __rest(s, e) {
328
+ var t = {};
329
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
330
+ t[p] = s[p];
331
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
332
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
333
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
334
+ t[p[i]] = s[p[i]];
335
+ }
336
+ return t;
337
+ }
338
+
339
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
340
+ var e = new Error(message);
341
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
342
+ };
343
+
344
+ /**
345
+ * Button component with tenant theme support
346
+ *
347
+ * @example
348
+ * ```tsx
349
+ * // Uses tenant primary color
350
+ * <Button tenantColored>Click Me</Button>
351
+ *
352
+ * // Uses MUI default color
353
+ * <Button color="primary">Click Me</Button>
354
+ * ```
355
+ */
356
+ function Button(_a) {
357
+ var _b, _c, _d;
358
+ var { tenantColored = false, variant = 'contained', sx, color } = _a, props = __rest(_a, ["tenantColored", "variant", "sx", "color"]);
359
+ const { theme } = useTenantTheme();
360
+ const buttonSx = tenantColored
361
+ ? Object.assign({ backgroundColor: (_b = theme.palette.primary) === null || _b === void 0 ? void 0 : _b.main, color: '#fff', '&:hover': {
362
+ backgroundColor: ((_c = theme.palette.primary) === null || _c === void 0 ? void 0 : _c.dark) || ((_d = theme.palette.primary) === null || _d === void 0 ? void 0 : _d.main),
363
+ } }, sx) : sx;
364
+ return (jsxRuntime.jsx(material.Button, Object.assign({ variant: variant, color: tenantColored ? undefined : color, sx: buttonSx }, props)));
365
+ }
366
+
367
+ /**
368
+ * Card component with tenant theme support
369
+ *
370
+ * @example
371
+ * ```tsx
372
+ * <Card
373
+ * title="My Card"
374
+ * content="Card content"
375
+ * actions={<Button>Action</Button>}
376
+ * tenantAccent
377
+ * />
378
+ * ```
379
+ */
380
+ function Card(_a) {
381
+ var _b;
382
+ var { title, headerAction, content, actions, tenantAccent = false, sx, children } = _a, props = __rest(_a, ["title", "headerAction", "content", "actions", "tenantAccent", "sx", "children"]);
383
+ const { theme } = useTenantTheme();
384
+ const cardSx = tenantAccent
385
+ ? Object.assign({ borderTop: `4px solid ${(_b = theme.palette.primary) === null || _b === void 0 ? void 0 : _b.main}` }, sx) : sx;
386
+ return (jsxRuntime.jsxs(material.Card, Object.assign({ sx: cardSx }, props, { children: [title && jsxRuntime.jsx(material.CardHeader, { title: title, action: headerAction }), (content || children) && (jsxRuntime.jsx(material.CardContent, { children: content || children })), actions && jsxRuntime.jsx(material.CardActions, { children: actions })] })));
387
+ }
388
+
389
+ /**
390
+ * Banner component with tenant theme support
391
+ *
392
+ * @example
393
+ * ```tsx
394
+ * <Banner
395
+ * title="Welcome to Our Platform"
396
+ * description="Get started today"
397
+ * action={<Button>Get Started</Button>}
398
+ * gradient
399
+ * />
400
+ * ```
401
+ */
402
+ function Banner(_a) {
403
+ var _b, _c, _d, _e;
404
+ var { title, description, action, gradient = true, sx } = _a, props = __rest(_a, ["title", "description", "action", "gradient", "sx"]);
405
+ const { theme } = useTenantTheme();
406
+ const background = gradient
407
+ ? `linear-gradient(135deg, ${(_b = theme.palette.primary) === null || _b === void 0 ? void 0 : _b.main} 0%, ${((_c = theme.palette.primary) === null || _c === void 0 ? void 0 : _c.light) || ((_d = theme.palette.primary) === null || _d === void 0 ? void 0 : _d.main)} 100%)`
408
+ : (_e = theme.palette.primary) === null || _e === void 0 ? void 0 : _e.main;
409
+ return (jsxRuntime.jsxs(material.Box, Object.assign({ sx: Object.assign({ background, color: 'white', padding: '32px', borderRadius: '12px', textAlign: 'center' }, sx) }, props, { children: [jsxRuntime.jsx(material.Typography, Object.assign({ variant: "h4", component: "h2", gutterBottom: true, fontWeight: "bold" }, { children: title })), description && (jsxRuntime.jsx(material.Typography, Object.assign({ variant: "body1", sx: { opacity: 0.95, mb: action ? 2 : 0 } }, { children: description }))), action && jsxRuntime.jsx(material.Box, Object.assign({ sx: { mt: 2 } }, { children: action }))] })));
410
+ }
411
+
412
+ /**
413
+ * Theme Utility Functions
414
+ * Helper functions for working with tenant themes
415
+ */
416
+ /**
417
+ * Get color value from theme palette path
418
+ * @param theme - Tenant theme configuration
419
+ * @param path - Dot-notation path to color (e.g., 'primary.main')
420
+ * @param defaultColor - Fallback color if path not found
421
+ * @returns Color string
422
+ */
423
+ function getThemeColor(theme, path, defaultColor = '#000000') {
424
+ const keys = path.split('.');
425
+ let value = theme.palette;
426
+ for (const key of keys) {
427
+ if (value && typeof value === 'object' && key in value) {
428
+ value = value[key];
429
+ }
430
+ else {
431
+ return defaultColor;
432
+ }
433
+ }
434
+ return typeof value === 'string' ? value : defaultColor;
435
+ }
436
+ /**
437
+ * Merge tenant theme with base MUI theme
438
+ * @param baseTheme - Base MUI theme
439
+ * @param tenantTheme - Tenant-specific theme configuration
440
+ * @returns Merged theme
441
+ */
442
+ function mergeTenantTheme(baseTheme, tenantTheme) {
443
+ var _a, _b;
444
+ return Object.assign(Object.assign({}, baseTheme), { palette: Object.assign(Object.assign(Object.assign({}, baseTheme.palette), tenantTheme.palette), {
445
+ // Deep merge for nested objects
446
+ primary: Object.assign(Object.assign({}, (((_a = baseTheme.palette) === null || _a === void 0 ? void 0 : _a.primary) || {})), (tenantTheme.palette.primary || {})), secondary: Object.assign(Object.assign({}, (((_b = baseTheme.palette) === null || _b === void 0 ? void 0 : _b.secondary) || {})), (tenantTheme.palette.secondary || {})) }), typography: Object.assign(Object.assign({}, baseTheme.typography), tenantTheme.typography) });
447
+ }
448
+ /**
449
+ * Create CSS variables from tenant theme
450
+ * Useful for using theme values in CSS
451
+ * @param theme - Tenant theme configuration
452
+ * @param prefix - Prefix for CSS variable names
453
+ * @returns Object with CSS variable definitions
454
+ */
455
+ function createThemeCSSVariables(theme, prefix = '--tenant') {
456
+ var _a;
457
+ const variables = {};
458
+ // Add primary colors
459
+ if (theme.palette.primary) {
460
+ Object.entries(theme.palette.primary).forEach(([key, value]) => {
461
+ if (typeof value === 'string') {
462
+ variables[`${prefix}-primary-${key}`] = value;
463
+ }
464
+ });
465
+ }
466
+ // Add secondary colors
467
+ if (theme.palette.secondary) {
468
+ Object.entries(theme.palette.secondary).forEach(([key, value]) => {
469
+ if (typeof value === 'string') {
470
+ variables[`${prefix}-secondary-${key}`] = value;
471
+ }
472
+ });
473
+ }
474
+ // Add font family
475
+ if ((_a = theme.typography) === null || _a === void 0 ? void 0 : _a.fontFamily) {
476
+ variables[`${prefix}-font-family`] = theme.typography.fontFamily;
477
+ }
478
+ return variables;
479
+ }
480
+
481
+ exports.Banner = Banner;
482
+ exports.Button = Button;
483
+ exports.Card = Card;
484
+ exports.TenantThemeProvider = TenantThemeProvider;
485
+ exports.ammetlifeTheme = ammetlifeTheme;
486
+ exports.cimbTheme = cimbTheme;
487
+ exports.createThemeCSSVariables = createThemeCSSVariables;
488
+ exports.getAvailableTenants = getAvailableTenants;
489
+ exports.getTenantTheme = getTenantTheme;
490
+ exports.getThemeColor = getThemeColor;
491
+ exports.iglooTheme = iglooTheme;
492
+ exports.isValidTenantId = isValidTenantId;
493
+ exports.mergeTenantTheme = mergeTenantTheme;
494
+ exports.tenantThemes = tenantThemes;
495
+ exports.useIsTenant = useIsTenant;
496
+ exports.useTenantId = useTenantId;
497
+ exports.useTenantTheme = useTenantTheme;