ad-feature-components 0.0.3 → 0.0.5

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.
@@ -0,0 +1,582 @@
1
+ import * as React$1 from 'react';
2
+ import React__default, { Component, ReactNode } from 'react';
3
+ import * as _azure_msal_browser from '@azure/msal-browser';
4
+ import { Configuration, PopupRequest, RedirectRequest, InteractionType } from '@azure/msal-browser';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { NavigateFunction } from 'react-router-dom';
7
+ import * as _tanstack_react_query from '@tanstack/react-query';
8
+
9
+ interface AppInsightProps {
10
+ instrumentationKey: string;
11
+ }
12
+ declare const AppInsight: React__default.FC<AppInsightProps>;
13
+
14
+ type AuthProviderProps = {
15
+ config: Configuration;
16
+ children: React__default.ReactNode;
17
+ };
18
+ declare const AuthProvider: React__default.FC<AuthProviderProps>;
19
+
20
+ type Options = {
21
+ loginType?: "popup" | "redirect";
22
+ defaultScopes?: string[];
23
+ };
24
+ declare function useAuth(options?: Options): {
25
+ isAuthenticated: boolean;
26
+ account: _azure_msal_browser.AccountInfo | null;
27
+ login: (request?: PopupRequest | RedirectRequest) => Promise<void>;
28
+ logout: () => Promise<void>;
29
+ acquireToken: (scopes: string[]) => Promise<string>;
30
+ InteractionType: typeof InteractionType;
31
+ };
32
+
33
+ declare const Protected: React__default.FC<{
34
+ children: React__default.ReactNode;
35
+ }>;
36
+
37
+ interface RouteConfig {
38
+ path: string;
39
+ component: React__default.ComponentType;
40
+ errorFallback?: React__default.ReactNode;
41
+ }
42
+ interface RouterProviderProps {
43
+ routes: RouteConfig[];
44
+ fallbackUI?: React__default.ReactNode;
45
+ }
46
+
47
+ declare const RouterProvider: React__default.FC<RouterProviderProps>;
48
+
49
+ interface ErrorBoundaryProps {
50
+ fallback?: ReactNode;
51
+ children: ReactNode;
52
+ }
53
+ interface ErrorBoundaryState {
54
+ hasError: boolean;
55
+ }
56
+ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
57
+ constructor(props: ErrorBoundaryProps);
58
+ static getDerivedStateFromError(_: Error): ErrorBoundaryState;
59
+ componentDidCatch(error: Error, info: React__default.ErrorInfo): void;
60
+ render(): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
61
+ }
62
+
63
+ declare const getNavigate: () => NavigateFunction;
64
+
65
+ interface ClientConfig {
66
+ endpoint: string;
67
+ headers?: Record<string, string>;
68
+ }
69
+ declare const configureClient: ({ endpoint, headers }: ClientConfig) => void;
70
+ declare const get: <T>(url: string) => Promise<T>;
71
+ declare const post: <T>(url: string, data: any) => Promise<T>;
72
+ declare const put: <T>(url: string, data: any) => Promise<T>;
73
+ declare const del: <T>(url: string) => Promise<T>;
74
+
75
+ declare const useGetQuery: <T>(key: string, url: string) => _tanstack_react_query.UseQueryResult<_tanstack_react_query.NoInfer<T>, Error>;
76
+ declare const usePostMutation: <T>() => _tanstack_react_query.UseMutationResult<T, Error, {
77
+ url: string;
78
+ data: any;
79
+ invalidateKeys?: string[];
80
+ }, unknown>;
81
+ declare const usePutMutation: <T>() => _tanstack_react_query.UseMutationResult<T, Error, {
82
+ url: string;
83
+ data: any;
84
+ invalidateKeys?: string[];
85
+ }, unknown>;
86
+ declare const useDeleteMutation: <T>() => _tanstack_react_query.UseMutationResult<T, Error, {
87
+ url: string;
88
+ invalidateKeys?: string[];
89
+ }, unknown>;
90
+
91
+ interface QueryProviderProps {
92
+ children: ReactNode;
93
+ }
94
+ declare const QueryProvider: React__default.FC<QueryProviderProps>;
95
+
96
+ type Values = Record<string, string>;
97
+ type SyncOrAsync<T> = T | Promise<T>;
98
+ type Validator = ((value: string, values: Values) => SyncOrAsync<boolean | string>) | undefined;
99
+
100
+ interface FormProps {
101
+ initialValues?: Values;
102
+ /** Async submit handler from target application */
103
+ onSubmit: (values: Values) => Promise<void>;
104
+ /** Optional error callback when onSubmit throws */
105
+ onSubmitError?: (error: unknown) => void;
106
+ /** Optional reset side-effect */
107
+ onReset?: () => void;
108
+ /** Children should include InputField and buttons */
109
+ children: React__default.ReactNode;
110
+ }
111
+ declare const Form: React__default.FC<FormProps>;
112
+
113
+ interface InputFieldProps extends Omit<React__default.InputHTMLAttributes<HTMLInputElement>, "name" | "onChange" | "value"> {
114
+ /** Unique field name */
115
+ name: string;
116
+ /** Visible label (optional) */
117
+ label?: string;
118
+ /** Show a clear icon inside input (default true) */
119
+ clearable?: boolean;
120
+ /** Validator function; can be sync or async and return boolean or string */
121
+ validator?: Validator;
122
+ /**
123
+ * Fallback error message to show if validator returns false.
124
+ * This satisfies: "take error message as a prop from target application"
125
+ */
126
+ errorMessage?: string;
127
+ /** Additional CSS class name */
128
+ className?: string;
129
+ }
130
+ declare const InputField: React__default.FC<InputFieldProps>;
131
+
132
+ interface DropdownOption {
133
+ value: string;
134
+ label: string;
135
+ }
136
+ interface InputDropdownProps {
137
+ /** Unique field name */
138
+ name: string;
139
+ /** Visible label (optional) */
140
+ label?: string;
141
+ /** Array of dropdown options */
142
+ options: DropdownOption[];
143
+ /** Placeholder text for empty selection */
144
+ placeholder?: string;
145
+ /** Show a clear icon (default true) */
146
+ clearable?: boolean;
147
+ /** Validator function; can be sync or async and return boolean or string */
148
+ validator?: Validator;
149
+ /**
150
+ * Fallback error message to show if validator returns false.
151
+ * This satisfies: "take error message as a prop from target application"
152
+ */
153
+ errorMessage?: string;
154
+ /** Whether the dropdown is disabled */
155
+ disabled?: boolean;
156
+ /** Additional CSS class name */
157
+ className?: string;
158
+ /** Additional inline styles */
159
+ style?: React__default.CSSProperties;
160
+ /** Accessibility attributes */
161
+ 'aria-label'?: string;
162
+ 'aria-describedby'?: string;
163
+ }
164
+ declare const InputDropdown: React__default.FC<InputDropdownProps>;
165
+
166
+ interface RadioOption {
167
+ value: string;
168
+ label: string;
169
+ }
170
+ interface InputRadioProps {
171
+ /** Unique field name */
172
+ name: string;
173
+ /** Visible label (optional) */
174
+ label?: string;
175
+ /** Array of radio options */
176
+ options: RadioOption[];
177
+ /** Validator function; can be sync or async and return boolean or string */
178
+ validator?: Validator;
179
+ /**
180
+ * Fallback error message to show if validator returns false.
181
+ * This satisfies: "take error message as a prop from target application"
182
+ */
183
+ errorMessage?: string;
184
+ /** Whether the radio group is disabled */
185
+ disabled?: boolean;
186
+ /** Additional CSS class name */
187
+ className?: string;
188
+ /** Accessibility attributes */
189
+ 'aria-label'?: string;
190
+ 'aria-describedby'?: string;
191
+ }
192
+ declare const InputRadio: React__default.FC<InputRadioProps>;
193
+
194
+ interface CheckboxOption {
195
+ value: string;
196
+ label: string;
197
+ }
198
+ interface InputCheckboxProps {
199
+ /** Unique field name */
200
+ name: string;
201
+ /** Visible label (optional) */
202
+ label?: string;
203
+ /** Array of checkbox options */
204
+ options: CheckboxOption[];
205
+ /** Validator function; can be sync or async and return boolean or string */
206
+ validator?: Validator;
207
+ /**
208
+ * Fallback error message to show if validator returns false.
209
+ * This satisfies: "take error message as a prop from target application"
210
+ */
211
+ errorMessage?: string;
212
+ /** Whether the checkbox group is disabled */
213
+ disabled?: boolean;
214
+ /** Additional CSS class name */
215
+ className?: string;
216
+ /** Accessibility attributes */
217
+ 'aria-label'?: string;
218
+ 'aria-describedby'?: string;
219
+ }
220
+ declare const InputCheckbox: React__default.FC<InputCheckboxProps>;
221
+
222
+ interface InputTextareaProps {
223
+ /** Unique field name */
224
+ name: string;
225
+ /** Visible label (optional) */
226
+ label?: string;
227
+ /** Placeholder text */
228
+ placeholder?: string;
229
+ /** Show a clear icon (default true) */
230
+ clearable?: boolean;
231
+ /** Validator function; can be sync or async and return boolean or string */
232
+ validator?: Validator;
233
+ /**
234
+ * Fallback error message to show if validator returns false.
235
+ * This satisfies: "take error message as a prop from target application"
236
+ */
237
+ errorMessage?: string;
238
+ /** Whether the textarea is disabled */
239
+ disabled?: boolean;
240
+ /** Number of rows */
241
+ rows?: number;
242
+ /** Maximum length */
243
+ maxLength?: number;
244
+ /** Additional CSS class name */
245
+ className?: string;
246
+ /** Additional inline styles */
247
+ style?: React__default.CSSProperties;
248
+ /** Accessibility attributes */
249
+ 'aria-label'?: string;
250
+ 'aria-describedby'?: string;
251
+ }
252
+ declare const InputTextarea: React__default.FC<InputTextareaProps>;
253
+
254
+ interface ResetButtonProps extends Omit<React__default.ButtonHTMLAttributes<HTMLButtonElement>, "type" | "onClick"> {
255
+ /** Optional custom text (default: "Reset") */
256
+ children?: React__default.ReactNode;
257
+ }
258
+ declare const ResetButton: React__default.FC<ResetButtonProps>;
259
+
260
+ interface InputFileProps {
261
+ name?: string;
262
+ label?: string;
263
+ accept?: string;
264
+ maxLength?: number;
265
+ maxFileSize?: number;
266
+ uploadUrl?: string;
267
+ onFileChange?: (file: File | null) => void;
268
+ disabled?: boolean;
269
+ validator?: (value: string) => boolean | string;
270
+ errorMessage?: string;
271
+ /** Additional CSS class name */
272
+ className?: string;
273
+ }
274
+ declare const InputFile: React__default.FC<InputFileProps>;
275
+
276
+ interface ToastProviderProps {
277
+ children: ReactNode;
278
+ /** Default duration in milliseconds (default: 3000) */
279
+ defaultDuration?: number;
280
+ /** Maximum number of toasts to show at once (default: 5) */
281
+ maxToasts?: number;
282
+ }
283
+ declare const ToastProvider: React__default.FC<ToastProviderProps>;
284
+
285
+ type ToastType = 'success' | 'error' | 'info' | 'warning';
286
+ interface Toast {
287
+ id: string;
288
+ message: string;
289
+ type: ToastType;
290
+ duration: number;
291
+ }
292
+ interface ToastContextValue {
293
+ toasts: Toast[];
294
+ showToast: (message: string, type: ToastType, duration?: number) => void;
295
+ showSuccess: (message: string, duration?: number) => void;
296
+ showError: (message: string, duration?: number) => void;
297
+ showInfo: (message: string, duration?: number) => void;
298
+ showWarning: (message: string, duration?: number) => void;
299
+ removeToast: (id: string) => void;
300
+ }
301
+
302
+ declare const useToast: () => ToastContextValue;
303
+
304
+ interface ToastContainerProps {
305
+ /** Position of toast container (default: 'top-right') */
306
+ position?: 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center';
307
+ /** Additional CSS class name */
308
+ className?: string;
309
+ }
310
+ declare const ToastContainer: React__default.FC<ToastContainerProps>;
311
+
312
+ interface InlineAlertProps {
313
+ /** Type of alert */
314
+ type: 'success' | 'error' | 'warning' | 'info';
315
+ /** Alert message */
316
+ message: string;
317
+ /** Optional title */
318
+ title?: string;
319
+ /** Whether to show close button */
320
+ dismissible?: boolean;
321
+ /** Callback when alert is dismissed */
322
+ onDismiss?: () => void;
323
+ /** Additional CSS class name */
324
+ className?: string;
325
+ }
326
+ declare const InlineAlert: React__default.FC<InlineAlertProps>;
327
+
328
+ type StorageType = 'local' | 'session' | 'memory';
329
+ interface StorageOptions {
330
+ /**
331
+ * Type of storage to use
332
+ * @default 'local'
333
+ */
334
+ storageType?: StorageType;
335
+ /**
336
+ * Namespace prefix for all keys to avoid collisions
337
+ * @default ''
338
+ */
339
+ namespace?: string;
340
+ /**
341
+ * Enable JSON serialization/deserialization
342
+ * @default true
343
+ */
344
+ serialize?: boolean;
345
+ /**
346
+ * Enable encryption for sensitive data (basic obfuscation)
347
+ * @default false
348
+ */
349
+ encrypt?: boolean;
350
+ }
351
+ interface StorageContextValue {
352
+ /**
353
+ * Get an item from storage
354
+ */
355
+ getItem: <T = string>(key: string, defaultValue?: T) => T | null;
356
+ /**
357
+ * Set an item in storage
358
+ */
359
+ setItem: <T = unknown>(key: string, value: T) => void;
360
+ /**
361
+ * Remove an item from storage
362
+ */
363
+ removeItem: (key: string) => void;
364
+ /**
365
+ * Clear all items from storage (respects namespace)
366
+ */
367
+ clear: () => void;
368
+ /**
369
+ * Check if a key exists in storage
370
+ */
371
+ hasItem: (key: string) => boolean;
372
+ /**
373
+ * Get all keys in storage (respects namespace)
374
+ */
375
+ getAllKeys: () => string[];
376
+ /**
377
+ * Get the current storage type
378
+ */
379
+ storageType: StorageType;
380
+ }
381
+
382
+ interface StorageProviderProps extends StorageOptions {
383
+ children: ReactNode;
384
+ }
385
+ declare const StorageProvider: React__default.FC<StorageProviderProps>;
386
+
387
+ declare const StorageContext: React$1.Context<StorageContextValue | undefined>;
388
+ /**
389
+ * Hook to access storage functionality
390
+ * Must be used within a StorageProvider
391
+ *
392
+ * @example
393
+ * ```tsx
394
+ * const storage = useStorage();
395
+ *
396
+ * // Store data
397
+ * storage.setItem('user', { name: 'John', age: 30 });
398
+ *
399
+ * // Retrieve data
400
+ * const user = storage.getItem('user', { name: '', age: 0 });
401
+ *
402
+ * // Remove data
403
+ * storage.removeItem('user');
404
+ *
405
+ * // Check if key exists
406
+ * if (storage.hasItem('user')) {
407
+ * console.log('User exists');
408
+ * }
409
+ *
410
+ * // Clear all storage
411
+ * storage.clear();
412
+ * ```
413
+ */
414
+ declare function useStorage(): StorageContextValue;
415
+
416
+ interface ContextConfig<T> {
417
+ /**
418
+ * Display name for the context (used in error messages and DevTools)
419
+ */
420
+ name: string;
421
+ /**
422
+ * Error message to show when hook is used outside provider
423
+ */
424
+ errorMessage?: string;
425
+ /**
426
+ * Default value for the context (optional)
427
+ */
428
+ defaultValue?: T;
429
+ }
430
+ interface ProviderProps<T> {
431
+ children: ReactNode;
432
+ value: T;
433
+ }
434
+ interface CreateContextResult<T> {
435
+ /**
436
+ * The React Context object
437
+ */
438
+ Context: React.Context<T | undefined>;
439
+ /**
440
+ * Provider component to wrap your app/component tree
441
+ */
442
+ Provider: React.FC<ProviderProps<T>>;
443
+ /**
444
+ * Hook to access the context value
445
+ * @throws Error if used outside the Provider
446
+ */
447
+ useContext: () => T;
448
+ }
449
+
450
+ /**
451
+ * Factory function to create a type-safe context with provider and hook
452
+ *
453
+ * @example
454
+ * ```tsx
455
+ * // Define your context value type
456
+ * interface ThemeContextValue {
457
+ * theme: 'light' | 'dark';
458
+ * toggleTheme: () => void;
459
+ * }
460
+ *
461
+ * // Create the context
462
+ * const { Provider: ThemeProvider, useContext: useTheme } = createContext<ThemeContextValue>({
463
+ * name: 'Theme',
464
+ * });
465
+ *
466
+ * // Use in your app
467
+ * function App() {
468
+ * const [theme, setTheme] = useState<'light' | 'dark'>('light');
469
+ *
470
+ * const toggleTheme = () => {
471
+ * setTheme(prev => prev === 'light' ? 'dark' : 'light');
472
+ * };
473
+ *
474
+ * return (
475
+ * <ThemeProvider value={{ theme, toggleTheme }}>
476
+ * <YourComponents />
477
+ * </ThemeProvider>
478
+ * );
479
+ * }
480
+ *
481
+ * // Access in child components
482
+ * function ChildComponent() {
483
+ * const { theme, toggleTheme } = useTheme();
484
+ * return <button onClick={toggleTheme}>Current: {theme}</button>;
485
+ * }
486
+ * ```
487
+ */
488
+ declare function createContext<T>(config: ContextConfig<T>): CreateContextResult<T>;
489
+
490
+ interface ContextWithHookConfig<T, P> {
491
+ /**
492
+ * Display name for the context (used in error messages and DevTools)
493
+ */
494
+ name: string;
495
+ /**
496
+ * Hook that provides the context value based on props
497
+ */
498
+ useValue: (props: P) => T;
499
+ /**
500
+ * Error message to show when hook is used outside provider
501
+ */
502
+ errorMessage?: string;
503
+ }
504
+ interface ProviderWithHookProps {
505
+ children: ReactNode;
506
+ }
507
+ interface CreateContextWithHookResult<T, P> {
508
+ /**
509
+ * The React Context object
510
+ */
511
+ Context: React__default.Context<T | undefined>;
512
+ /**
513
+ * Provider component that uses the hook internally
514
+ */
515
+ Provider: React__default.FC<ProviderWithHookProps & P>;
516
+ /**
517
+ * Hook to access the context value
518
+ * @throws Error if used outside the Provider
519
+ */
520
+ useContext: () => T;
521
+ }
522
+ /**
523
+ * Factory function to create a context with a custom hook that manages state
524
+ * This pattern is useful when you want to encapsulate state logic in the provider
525
+ *
526
+ * @example
527
+ * ```tsx
528
+ * // Define your context value and props types
529
+ * interface CounterContextValue {
530
+ * count: number;
531
+ * increment: () => void;
532
+ * decrement: () => void;
533
+ * reset: () => void;
534
+ * }
535
+ *
536
+ * interface CounterProviderProps {
537
+ * initialCount?: number;
538
+ * }
539
+ *
540
+ * // Create the context with a custom hook
541
+ * const { Provider: CounterProvider, useContext: useCounter } = createContextWithHook<
542
+ * CounterContextValue,
543
+ * CounterProviderProps
544
+ * >({
545
+ * name: 'Counter',
546
+ * useValue: ({ initialCount = 0 }) => {
547
+ * const [count, setCount] = useState(initialCount);
548
+ *
549
+ * return {
550
+ * count,
551
+ * increment: () => setCount(prev => prev + 1),
552
+ * decrement: () => setCount(prev => prev - 1),
553
+ * reset: () => setCount(initialCount),
554
+ * };
555
+ * },
556
+ * });
557
+ *
558
+ * // Use in your app
559
+ * function App() {
560
+ * return (
561
+ * <CounterProvider initialCount={10}>
562
+ * <YourComponents />
563
+ * </CounterProvider>
564
+ * );
565
+ * }
566
+ *
567
+ * // Access in child components
568
+ * function ChildComponent() {
569
+ * const { count, increment, decrement } = useCounter();
570
+ * return (
571
+ * <div>
572
+ * <p>Count: {count}</p>
573
+ * <button onClick={increment}>+</button>
574
+ * <button onClick={decrement}>-</button>
575
+ * </div>
576
+ * );
577
+ * }
578
+ * ```
579
+ */
580
+ declare function createContextWithHook<T, P = Record<string, never>>(config: ContextWithHookConfig<T, P>): CreateContextWithHookResult<T, P>;
581
+
582
+ export { AppInsight, AuthProvider, type AuthProviderProps, type CheckboxOption, type ClientConfig, type ContextConfig, type ContextWithHookConfig, type CreateContextResult, type CreateContextWithHookResult, type DropdownOption, ErrorBoundary, Form, type FormProps, InlineAlert, type InlineAlertProps, InputCheckbox, type InputCheckboxProps, InputDropdown, type InputDropdownProps, InputField, type InputFieldProps, InputFile, InputRadio, type InputRadioProps, InputTextarea, type InputTextareaProps, Protected, type ProviderProps, type ProviderWithHookProps, QueryProvider, type RadioOption, ResetButton, type RouteConfig, RouterProvider, type RouterProviderProps, StorageContext, type StorageContextValue, type StorageOptions, StorageProvider, type StorageProviderProps, type StorageType, type Toast, ToastContainer, type ToastContextValue, ToastProvider, type ToastType, type Validator, type Values, configureClient, createContext, createContextWithHook, del, get, getNavigate, post, put, useAuth, useDeleteMutation, useGetQuery, usePostMutation, usePutMutation, useStorage, useToast };