@myop/react 0.0.30 → 0.0.31

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/README.md CHANGED
@@ -142,8 +142,8 @@ import { MyopComponent } from "@myop/react";
142
142
  | `onLoad` | `(component) => void` | Called when the component finishes loading |
143
143
  | `onError` | `(error: string) => void` | Called when loading fails |
144
144
  | `style` | `CSSProperties` | CSS styles for the container |
145
- | `loader` | `ReactNode` | Custom loading indicator |
146
- | `fallback` | `ReactNode` | Custom error fallback UI |
145
+ | `loader` | `ReactNode` | Loading indicator (default: `null` - no loader). Use `loader={<MyopLoader />}` for default Myop loader |
146
+ | `fallback` | `ReactNode` | Error fallback UI (default: `<MyopFallback />`). Override with custom component |
147
147
  | `fadeDuration` | `number` | Loader fade-out duration in ms (default: `200`) |
148
148
  | `environment` | `string` | Load from a specific environment (e.g., `"staging"`, `"prod"`) |
149
149
  | `preview` | `boolean` | Load the unpublished preview version of the component |
@@ -282,7 +282,23 @@ setCloudRepository(customRepo);
282
282
  const repo = getCloudRepository();
283
283
  ```
284
284
 
285
- ## Custom Loading & Error States
285
+ ## Loading & Error States
286
+
287
+ By default, no loader is shown while the component loads. The Myop-branded fallback is displayed automatically on error.
288
+
289
+ ### Using the Default Myop Loader
290
+
291
+ ```tsx
292
+ import { MyopComponent, MyopLoader } from "@myop/react";
293
+
294
+ <MyopComponent
295
+ componentId="my-component"
296
+ loader={<MyopLoader />} // Opt-in to default Myop loader
297
+ fadeDuration={300}
298
+ />
299
+ ```
300
+
301
+ ### Custom Loading State
286
302
 
287
303
  ```tsx
288
304
  <MyopComponent
@@ -293,13 +309,29 @@ const repo = getCloudRepository();
293
309
  <p>Loading component...</p>
294
310
  </div>
295
311
  }
312
+ fadeDuration={300}
313
+ />
314
+ ```
315
+
316
+ ### Custom Error Fallback
317
+
318
+ ```tsx
319
+ import { MyopComponent, MyopFallback } from "@myop/react";
320
+
321
+ <MyopComponent
322
+ componentId="my-component"
296
323
  fallback={
297
324
  <div className="error-state">
298
325
  <p>Failed to load component</p>
299
326
  <button onClick={() => window.location.reload()}>Retry</button>
300
327
  </div>
301
328
  }
302
- fadeDuration={300}
329
+ />
330
+
331
+ // Or use the default Myop fallback explicitly
332
+ <MyopComponent
333
+ componentId="my-component"
334
+ fallback={<MyopFallback />}
303
335
  />
304
336
  ```
305
337
 
@@ -310,6 +342,8 @@ const repo = getCloudRepository();
310
342
  | Export | Description |
311
343
  |--------|-------------|
312
344
  | `MyopComponent` | Main component for embedding Myop components |
345
+ | `MyopLoader` | Default Myop-branded loading indicator (opt-in) |
346
+ | `MyopFallback` | Default Myop-branded error fallback |
313
347
  | `preloadComponents` | Preload components for faster rendering |
314
348
  | `isPreloaded` | Check if a component is cached |
315
349
  | `enableLocalDev` | Enable local development mode |
package/dist/index.d.ts CHANGED
@@ -39,7 +39,7 @@ declare interface IBasePropTypes<TData = any, TCtaPayloads extends Record<string
39
39
  style?: CSSProperties;
40
40
  componentId?: string;
41
41
  componentConfig?: IComponentInstanceConfig;
42
- onLoad?: (myopComponent: IMyopComponent) => void;
42
+ onLoad?: (myopComponent: ITypedMyopComponent<TData, TCtaPayloads>) => void;
43
43
  onError?: (error: string) => void;
44
44
  on?: OnCallback<TCtaPayloads>;
45
45
  data?: TData;
@@ -86,6 +86,17 @@ export declare interface IComponentInstanceConfig {
86
86
 
87
87
  export { IMyopComponent }
88
88
 
89
+ /**
90
+ * Typed props interface for accessing component.props with autocomplete.
91
+ * Contains myop_init_interface and myop_cta_handler with proper types.
92
+ */
93
+ export declare interface IMyopComponentProps<TData = any, TCtaPayloads extends Record<string, any> = Record<string, any>> {
94
+ /** Initialize the component with data */
95
+ myop_init_interface?: (data: TData) => void;
96
+ /** Handle CTA events from the component */
97
+ myop_cta_handler?: <K extends keyof TCtaPayloads>(action: K, payload: TCtaPayloads[K]) => void;
98
+ }
99
+
89
100
  /**
90
101
  * Full props type including generated event handlers.
91
102
  * Supports both generic `on` callback and individual typed handlers like `onRowClicked`.
@@ -105,6 +116,15 @@ declare interface IPropTypes_2 {
105
116
  */
106
117
  export declare const isPreloaded: (componentId: string, env?: string, preview?: boolean) => boolean;
107
118
 
119
+ /**
120
+ * Typed Myop component interface with typed props.
121
+ * Use this type for the component returned in onLoad callback.
122
+ */
123
+ export declare type ITypedMyopComponent<TData = any, TCtaPayloads extends Record<string, any> = Record<string, any>> = Omit<IMyopComponent, 'props'> & {
124
+ /** Typed props for the component */
125
+ props: IMyopComponentProps<TData, TCtaPayloads> | null;
126
+ };
127
+
108
128
  /**
109
129
  * Converts kebab-case string to PascalCase
110
130
  * e.g., 'column-reordered' -> 'ColumnReordered'
@@ -113,6 +133,20 @@ declare type KebabToPascal<S extends string> = S extends `${infer First}-${infer
113
133
 
114
134
  export declare const MyopContainer: (props: IPropTypes_2) => JSX.Element;
115
135
 
136
+ export declare const MyopFallback: ({ children }: MyopFallbackProps) => JSX.Element;
137
+
138
+ declare interface MyopFallbackProps {
139
+ children?: ReactNode;
140
+ }
141
+
142
+ export declare const MyopLoader: ({ opacity, fadeDuration, children, }: MyopLoaderProps) => JSX.Element;
143
+
144
+ declare interface MyopLoaderProps {
145
+ opacity?: number;
146
+ fadeDuration?: number;
147
+ children?: ReactNode;
148
+ }
149
+
116
150
  declare const MyopV2ReactComponent: <TData = any, TCtaPayloads extends Record<string, any> = Record<string, any>>(props: IPropTypes<TData, TCtaPayloads>) => JSX.Element;
117
151
  export { MyopV2ReactComponent as MyopComponent }
118
152
  export { MyopV2ReactComponent as MyopV2Container }