-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for watermark component
- Loading branch information
Showing
10 changed files
with
406 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.player .watermark { | ||
position: absolute; | ||
padding: 5px; | ||
z-index: 11; | ||
transition: visibility 0s 1s, opacity 1s linear, transform ease-out 100ms; | ||
&.hide-watermark { | ||
visibility: hidden; | ||
opacity: 0; | ||
} | ||
&.top { | ||
top: 0; | ||
} | ||
&.bottom { | ||
bottom: 0; | ||
} | ||
&.right { | ||
right: 0; | ||
} | ||
&.left { | ||
left: 0; | ||
} | ||
} | ||
|
||
.player { | ||
&:not(.pre-playback):not(.overlay-active) { | ||
&.state-paused :global(.playkit-watermark.playkit-bottom), | ||
&.hover :global(.playkit-watermark.playkit-bottom) { | ||
transform: translateY(-60px); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './watermark'; |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//@flow | ||
import style from '../../styles/style.scss'; | ||
import {h} from 'preact'; | ||
import BaseComponent from '../base'; | ||
import {connect} from "preact-redux"; | ||
|
||
/** | ||
* mapping state to props | ||
* @param {*} state - redux store state | ||
* @returns {Object} - mapped state to this component | ||
*/ | ||
const mapStateToProps = state => ({ | ||
config: Object.assign({ | ||
placement: 'top-left', | ||
timeout: 0 | ||
}, state.config.components.watermark) | ||
}); | ||
|
||
@connect(mapStateToProps) | ||
/** | ||
* Watermark component | ||
* @class Watermark | ||
* @example <Watermark player={this.player} /> | ||
* @extends {BaseComponent} | ||
*/ | ||
class Watermark extends BaseComponent { | ||
/** | ||
* @static | ||
* @type {string} - Component display name | ||
*/ | ||
static displayName = 'watermark'; | ||
|
||
/** | ||
* Creates an instance of Watermark. | ||
* @param {Object} obj - object | ||
* @memberof Watermark | ||
*/ | ||
constructor(obj: Object) { | ||
super({name: 'Watermark', player: obj.player}); | ||
this.setState({show: true}); | ||
} | ||
|
||
/** | ||
* After component mounted, listen to relevant player event for updating the state of the component | ||
* @method componentDidMount | ||
* @returns {void} | ||
* @memberof Watermark | ||
*/ | ||
componentDidMount() { | ||
/** | ||
* playing handler | ||
* @returns {void} | ||
*/ | ||
const onPlaying = () => { | ||
this.player.removeEventListener(this.player.Event.PLAYING, onPlaying); | ||
if (this.props.config.timeout > 0) { | ||
setTimeout(() => this.setState({show: false}), this.props.config.timeout); | ||
} | ||
}; | ||
this.player.addEventListener(this.player.Event.PLAYING, onPlaying); | ||
this.player.addEventListener(this.player.Event.CHANGE_SOURCE_ENDED, () => { | ||
this.setState({show: true}); | ||
this.player.addEventListener(this.player.Event.PLAYING, onPlaying) | ||
}); | ||
} | ||
|
||
/** | ||
* Render component | ||
* @param {*} props - component props | ||
* @returns {?React$Element} - component element | ||
* @memberof Watermark | ||
*/ | ||
render(props: any): ?React$Element<any> { | ||
if (props.config.img) { | ||
const styleClass = [style.watermark]; | ||
props.config.placement.split('-').forEach((side) => { | ||
styleClass.push(style[side]); | ||
}); | ||
if (!this.state.show) { | ||
styleClass.push(style.hideWatermark); | ||
} | ||
return ( | ||
<div className={styleClass.join(' ')}> | ||
<a href={props.config.url} target='_blank' rel='noopener noreferrer'> | ||
<img src={props.config.img}/> | ||
</a> | ||
</div> | ||
) | ||
} | ||
} | ||
} | ||
|
||
export default Watermark; |
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