Skip to content

Commit 4fb0136

Browse files
committed
feat(chart): add BBChart component for billboard.js integration
Signed-off-by: Amit Amrutiya <amitamrutiya2210@gmail.com>
1 parent c1ae425 commit 4fb0136

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/custom/BBChart/BBChart.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ChartOptions, bb } from 'billboard.js';
2+
import { memo, useEffect, useRef } from 'react';
3+
4+
interface BBChartProps {
5+
options: ChartOptions;
6+
}
7+
8+
const BBChart = ({ options }: BBChartProps) => {
9+
const _chartRef = useRef<HTMLDivElement | null>(null);
10+
11+
useEffect(() => {
12+
if (!_chartRef.current) return;
13+
14+
const chart = bb.generate({
15+
bindto: _chartRef.current,
16+
...options
17+
});
18+
19+
return () => {
20+
chart.destroy();
21+
};
22+
}, [options]);
23+
24+
return <div ref={_chartRef} onClickCapture={(e) => e.stopPropagation()} />;
25+
};
26+
27+
export default memo(BBChart);

src/custom/BBChart/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import BBChart from './BBChart';
2+
3+
export { BBChart };

src/custom/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ActionButton } from './ActionButton';
2+
import { BBChart } from './BBChart';
23
import { BookmarkNotification } from './BookmarkNotification';
34
import CatalogFilter, { CatalogFilterProps } from './CatalogFilter/CatalogFilter';
45
import { ChapterCard } from './ChapterCard';
@@ -67,6 +68,7 @@ export { UserSearchField } from './UserSearchField';
6768

6869
export {
6970
ActionButton,
71+
BBChart,
7072
BookmarkNotification,
7173
CatalogCardDesignLogo,
7274
CatalogFilter,
@@ -148,6 +150,7 @@ export type {
148150
export * from './CatalogDesignTable';
149151
export * from './CatalogDetail';
150152
export * from './Dialog';
153+
export * from './ResourceDetailFormatters';
151154
export * from './ShareModal';
152155
export * from './UserSearchField';
153156
export * from './Workspaces';

0 commit comments

Comments
 (0)