-
Notifications
You must be signed in to change notification settings - Fork 781
/
Copy pathindex.tsx
71 lines (64 loc) · 2.09 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import styles from "./index.module.css";
import { useEffect, useRef } from "react";
import { ChartingLibraryWidgetOptions, LanguageCode, ResolutionString, widget } from "@/public/static/charting_library";
export const TVChartContainer = (props: Partial<ChartingLibraryWidgetOptions>) => {
const chartContainerRef =
useRef<HTMLDivElement>() as React.MutableRefObject<HTMLInputElement>;
useEffect(() => {
const widgetOptions: ChartingLibraryWidgetOptions = {
symbol: props.symbol,
// BEWARE: no trailing slash is expected in feed URL
datafeed: new (window as any).Datafeeds.UDFCompatibleDatafeed(
"https://demo_feed.tradingview.com",
undefined,
{
maxResponseLength: 1000,
expectedOrder: "latestFirst",
}
),
interval: props.interval as ResolutionString,
container: chartContainerRef.current,
library_path: props.library_path,
locale: props.locale as LanguageCode,
disabled_features: ["use_localstorage_for_settings"],
enabled_features: ["study_templates"],
charts_storage_url: props.charts_storage_url,
charts_storage_api_version: props.charts_storage_api_version,
client_id: props.client_id,
user_id: props.user_id,
fullscreen: props.fullscreen,
autosize: props.autosize
};
const tvWidget = new widget(widgetOptions);
tvWidget.onChartReady(() => {
tvWidget.headerReady().then(() => {
const button = tvWidget.createButton();
button.setAttribute("title", "Click to show a notification popup");
button.classList.add("apply-common-tooltip");
button.addEventListener("click", () =>
tvWidget.showNoticeDialog({
title: "Notification",
body: "TradingView Charting Library API works correctly",
callback: () => {
console.log("Noticed!");
},
})
);
button.innerHTML = "Check API";
});
});
return () => {
tvWidget.remove();
};
}, [props]);
return (
<>
<header className={styles.VersionHeader}>
<h1>
TradingView Charting Library and Next.js Integration Example
</h1>
</header>
<div ref={chartContainerRef} className={styles.TVChartContainer} />
</>
);
};