-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
options now named "lolptions", no SvelteImpl
- Loading branch information
1 parent
f356fa5
commit a1e578a
Showing
5 changed files
with
59 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
import { KpiCard as _KpiCard, KpiCardOptions } from '@opendatasoft/visualizations'; | ||
import { FC } from 'react'; | ||
import { Props } from './Props'; | ||
import wrap from './ReactImpl'; | ||
import { KpiCard as _KpiCard, KpiCardImpl, KpiCardOptions } from '@opendatasoft/visualizations'; | ||
import React, { useLayoutEffect, useRef } from 'react'; | ||
|
||
// export const useSvelteComponent = <P extends object>({ | ||
// Component, | ||
// props, | ||
// svelteRef, | ||
// }: SvelteComponentProps<P> & { | ||
// svelteRef: RefObject<HTMLDivElement>; | ||
// }) => { | ||
// useLayoutEffect(() => { | ||
// while (svelteRef.current?.firstChild) { | ||
// svelteRef.current?.firstChild?.remove(); | ||
// } | ||
// new Component({ | ||
// target: svelteRef.current, | ||
// props, | ||
// }); | ||
// }, [Component, props, svelteRef]); | ||
// }; | ||
|
||
// Explicit name and type are needed for storybook | ||
const KpiCard: FC<Props<number, KpiCardOptions>> = wrap(_KpiCard); | ||
const KpiCard = (props: any) => { | ||
const svelteRef = useRef<HTMLDivElement>(null); | ||
|
||
useLayoutEffect(() => { | ||
if (svelteRef?.current) { | ||
new KpiCardImpl({ | ||
target: svelteRef.current, | ||
props, | ||
}); | ||
} | ||
}, [props, svelteRef]); | ||
|
||
return <div ref={svelteRef} />; | ||
}; | ||
|
||
export default KpiCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters