@myop/react 0.0.30 → 0.0.32

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
@@ -91,6 +91,8 @@ You can also override the environment directly on a specific component:
91
91
 
92
92
  Environments are fully configurable in the [dashboard](https://dashboard.myop.dev/), allowing you to test changes in staging before publishing to production.
93
93
 
94
+ For more details on auto-generated packages, see the [Auto-Generated Packages documentation](https://docs.myop.dev/docs/learnMyop/AutoGeneratedPackages).
95
+
94
96
  ## Requirements
95
97
 
96
98
  - React 18.0+
@@ -142,8 +144,8 @@ import { MyopComponent } from "@myop/react";
142
144
  | `onLoad` | `(component) => void` | Called when the component finishes loading |
143
145
  | `onError` | `(error: string) => void` | Called when loading fails |
144
146
  | `style` | `CSSProperties` | CSS styles for the container |
145
- | `loader` | `ReactNode` | Custom loading indicator |
146
- | `fallback` | `ReactNode` | Custom error fallback UI |
147
+ | `loader` | `ReactNode` | Loading indicator (default: `null` - no loader). Use `loader={<MyopLoader />}` for default Myop loader |
148
+ | `fallback` | `ReactNode` | Error fallback UI (default: `<MyopFallback />`). Override with custom component |
147
149
  | `fadeDuration` | `number` | Loader fade-out duration in ms (default: `200`) |
148
150
  | `environment` | `string` | Load from a specific environment (e.g., `"staging"`, `"prod"`) |
149
151
  | `preview` | `boolean` | Load the unpublished preview version of the component |
@@ -282,7 +284,23 @@ setCloudRepository(customRepo);
282
284
  const repo = getCloudRepository();
283
285
  ```
284
286
 
285
- ## Custom Loading & Error States
287
+ ## Loading & Error States
288
+
289
+ By default, no loader is shown while the component loads. The Myop-branded fallback is displayed automatically on error.
290
+
291
+ ### Using the Default Myop Loader
292
+
293
+ ```tsx
294
+ import { MyopComponent, MyopLoader } from "@myop/react";
295
+
296
+ <MyopComponent
297
+ componentId="my-component"
298
+ loader={<MyopLoader />} // Opt-in to default Myop loader
299
+ fadeDuration={300}
300
+ />
301
+ ```
302
+
303
+ ### Custom Loading State
286
304
 
287
305
  ```tsx
288
306
  <MyopComponent
@@ -293,13 +311,29 @@ const repo = getCloudRepository();
293
311
  <p>Loading component...</p>
294
312
  </div>
295
313
  }
314
+ fadeDuration={300}
315
+ />
316
+ ```
317
+
318
+ ### Custom Error Fallback
319
+
320
+ ```tsx
321
+ import { MyopComponent, MyopFallback } from "@myop/react";
322
+
323
+ <MyopComponent
324
+ componentId="my-component"
296
325
  fallback={
297
326
  <div className="error-state">
298
327
  <p>Failed to load component</p>
299
328
  <button onClick={() => window.location.reload()}>Retry</button>
300
329
  </div>
301
330
  }
302
- fadeDuration={300}
331
+ />
332
+
333
+ // Or use the default Myop fallback explicitly
334
+ <MyopComponent
335
+ componentId="my-component"
336
+ fallback={<MyopFallback />}
303
337
  />
304
338
  ```
305
339
 
@@ -310,6 +344,8 @@ const repo = getCloudRepository();
310
344
  | Export | Description |
311
345
  |--------|-------------|
312
346
  | `MyopComponent` | Main component for embedding Myop components |
347
+ | `MyopLoader` | Default Myop-branded loading indicator (opt-in) |
348
+ | `MyopFallback` | Default Myop-branded error fallback |
313
349
  | `preloadComponents` | Preload components for faster rendering |
314
350
  | `isPreloaded` | Check if a component is cached |
315
351
  | `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 }