import React, { Component } from 'react'; import PropTypes from 'prop-types'; import ReactHtmlParser from 'react-html-parser'; import './StartVideoModal.scss'; import { SVGIcon } from 'ca-ui-toolkit'; import play32 from '@ba-ui-toolkit/ba-graphics/dist/icons/play_32.svg'; import { Dialog } from 'ca-ui-toolkit'; const DASHBOARD_TUTORIAL_IMG_PATH = 'images/tutVideo_Dashboard.png'; const EXPLORE_TUTORIAL_IMG_PATH = 'images/tutVideo_Explore.png'; const OVERVIEW_TUTORIAL_IMG_PATH = 'images/tutVideo_Overview.png'; /* Metadata for three videos: - Thumbnail & title are hard-coded in this repo - For video replacement, contact Reimar S. to change the mapping of tiny URLs */ const metadata = { 0:{ thumbnail: OVERVIEW_TUTORIAL_IMG_PATH, link: 'https://ibm.biz/BdzbpD', title_string: 'modal_how_video_title_overview' }, 1:{ thumbnail: DASHBOARD_TUTORIAL_IMG_PATH, link: 'https://ibm.biz/BdzbpF', title_string: 'modal_how_video_title_dashboard' }, 2:{ thumbnail: EXPLORE_TUTORIAL_IMG_PATH, link: 'https://ibm.biz/BdzbpR', title_string: 'modal_how_video_title_exploration' } }; export class StartVideoModal extends Component { static propTypes = { /** Handler to close the modal */ closeHandler: PropTypes.func.isRequired, /** A copy of the i18n object used to translate strings */ stringGetter: PropTypes.object }; state = { selectedVideo: 0, playing: false }; // Click handler called when user clicks on the video option _selectVideo = (index) => { this.setState({ playing: false, selectedVideo: index }); } // Click handler called when user clicks play button _playVideo = () => { this.setState({ playing: true }); } // Return the generic youtube iframe for embedded video _youtubeVideoSrc = (link) => { return (); } // Handler to open the video via tabbing action _selectVideoViaTabbing = (e, index) => { e.stopPropagation(); // If not a shift click, ctrl click or a right click or the user pressed enter on the context menu if((e.type == 'click' && !e.shiftKey && !e.ctrlKey && e.nativeEvent.which !== 3) || (e.type=='keyup' && e.keyCode === 13)) { e.persist(); this._selectVideo(index); } } // Handler to play the video via tabbing action _playVideoViaTabbing = (e) => { e.stopPropagation(); // If not a shift click, ctrl click or a right click or the user pressed enter on the context menu if((e.type == 'click' && !e.shiftKey && !e.ctrlKey && e.nativeEvent.which !== 3) || (e.type=='keyup' && e.keyCode === 13)) { e.persist(); this._playVideo(); } } render() { const dialogProps = { size: 'large', width: '804px', minWidth: '804px', clickaway: true, theme: 'ba-theme-default', className: 'startVideoModal_dialog', style: { 'padding-bottom': '64px' }, startingFocusIndex: -1 }; const { stringGetter } = this.props; const mainScreen = this.state.playing ? (
{this._youtubeVideoSrc(metadata[this.state.selectedVideo].link)}
): (
{this._playVideoViaTabbing(e);}} onClick={() => this._playVideo()}> {stringGetter.get('modal_how_play')}
); return ( { this.props.closeHandler(); }} > {stringGetter.get('modal_how_title')}
{mainScreen}
{this._selectVideoViaTabbing(e, 0);}} onClick={() => this._selectVideo(0)} className={this.state.selectedVideo === 0 ? 'optionSelected optionBlock optionBlockSeprator' : 'optionBlock optionBlockSeprator'}>
{this._selectVideoViaTabbing(e, 1);}} onClick={() => this._selectVideo(1)} className={this.state.selectedVideo === 1 ? 'optionSelected optionBlock optionBlockSeprator' : 'optionBlock optionBlockSeprator'}>
{this._selectVideoViaTabbing(e, 2);}} onClick={() => this._selectVideo(2)} className={this.state.selectedVideo === 2 ? 'optionSelected optionBlock' : 'optionBlock' }>
); } }