Skip to content

Commit

Permalink
feat: add renderPluginLoader property (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
korvin89 authored Jun 30, 2023
1 parent 7d8f894 commit 3955d2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/ChartKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ChartKitComponentProps<T extends ChartKitType> = Omit<ChartKitProps<T>, 'on

const ChartKitComponent = <T extends ChartKitType>(props: ChartKitComponentProps<T>) => {
const widgetRef = React.useRef<ChartKitWidgetRef>();
const {instanceRef, id: propsId, type, isMobile, ...restProps} = props;
const {instanceRef, id: propsId, type, isMobile, renderPluginLoader, ...restProps} = props;

const ckId = React.useMemo(() => getRandomCKId(), []);
const id = propsId || ckId;
Expand Down Expand Up @@ -48,7 +48,7 @@ const ChartKitComponent = <T extends ChartKitType>(props: ChartKitComponentProps
);

return (
<React.Suspense fallback={<Loader />}>
<React.Suspense fallback={renderPluginLoader?.() || <Loader />}>
<div className={b({mobile: isMobile}, 'chartkit-theme_common')}>
<ChartComponent ref={widgetRef} id={id} lang={lang} {...restProps} />
</div>
Expand Down
16 changes: 7 additions & 9 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ export type ChartKitProps<T extends ChartKitType> = {
id?: string;
isMobile?: boolean;
onLoad?: (data?: ChartKitOnLoadData<T>) => void;
/**
* called on each render
* @param data
*/
/** Fires on each chartkit plugin's component render */
onRender?: (data: ChartKitOnRenderData) => void;
/**
* called on chart mount
* @param data
*/
/** Fires on chartkit plugin's component mount */
onChartLoad?: (data: ChartKitOnChartLoad<T>) => void;
renderError?: RenderError;
/** Fires in case of unhandled plugin's exception */
onError?: ChartKitOnError;
/** Used to render user's error component */
renderError?: RenderError;
/** Used to render user's plugin loader component */
renderPluginLoader?: () => React.ReactNode;
} & {[key in keyof Omit<ChartKitWidget[T], 'data' | 'widget'>]: ChartKitWidget[T][key]};

export type ChartKitPlugin = {
Expand Down

0 comments on commit 3955d2f

Please sign in to comment.