UNPKG

react-tradingview-technical-analysis

Version:

React component for rendering the TradingView Technical Analysis Widget

140 lines (111 loc) 6.4 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["react-tradingview-technical-analysis"] = factory(); else root["react-tradingview-technical-analysis"] = factory(); })(typeof self !== 'undefined' ? self : this, function() { return webpackJsonpreact_tradingview_technical_analysis([1],{ /***/ 5: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "INTERVALS", function() { return INTERVALS; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "THEMES", function() { return THEMES; }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(6); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_react__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types__ = __webpack_require__(9); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_prop_types__); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var INTERVALS = { ONE_MINUTE: '1m', FIVE_MINUTES: '5m', FIFTEEN_MINUTES: '15m', ONE_HOUR: '1h', FOUR_HOURS: '4h', ONE_WEEK: '1W', ONE_MONTH: '1M' }; var THEMES = { LIGHT: 'light', DARK: 'dark' }; var TechnicalAnalysis = function (_React$Component) { _inherits(TechnicalAnalysis, _React$Component); function TechnicalAnalysis() { var _ref; var _temp, _this, _ret; _classCallCheck(this, TechnicalAnalysis); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TechnicalAnalysis.__proto__ || Object.getPrototypeOf(TechnicalAnalysis)).call.apply(_ref, [this].concat(args))), _this), _this.appendElement = function () { if (_this.script) { var elem = document.querySelector('#data'); elem.parentNode.removeChild(elem); } _this.script = document.createElement('script'); _this.script.id = 'data'; _this.script.type = 'text/javascript'; _this.script.async = true; _this.script.src = 'https://s3.tradingview.com/external-embedding/embed-widget-technical-analysis.js'; var config = _extends({}, _this.props); if (config.autoSize) { config.width = '100%'; config.height = '100%'; } _this.script.text = JSON.stringify(config); document.getElementsByClassName(_this.props.containerId)[0].appendChild(_this.script); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(TechnicalAnalysis, [{ key: 'componentDidMount', value: function componentDidMount() { this.script = null; this.appendElement(); } }, { key: 'render', value: function render() { var containerId = this.props.containerId; return __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement('div', { className: containerId }); } }]); return TechnicalAnalysis; }(__WEBPACK_IMPORTED_MODULE_0_react___default.a.Component); TechnicalAnalysis.INTERVALS = INTERVALS; TechnicalAnalysis.THEMES = THEMES; TechnicalAnalysis.propTypes = { containerId: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string, interval: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.oneOf(Object.values(INTERVALS)), width: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.number, height: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.number, colorTheme: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.oneOf(Object.values(THEMES)), isTransparent: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool, showIntervalTabs: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool, symbol: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string.isRequired, locale: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string, autoSize: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool }; TechnicalAnalysis.defaultProps = { containerId: 'tradingview-widget-container', interval: INTERVALS.ONE_MINUTE, width: 425, height: 450, colorTheme: THEMES.LIGHT, isTransparent: false, showIntervalTabs: true, locale: 'en', autoSize: false }; /* harmony default export */ __webpack_exports__["default"] = (TechnicalAnalysis); /***/ }) },[5]); });