Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default class Preview extends Component {
}

fetchImage ({ url, light, oEmbedUrl }) {
if (React.isValidElement(light)) {
return
}
if (typeof light === 'string') {
this.setState({ image: light })
return
Expand Down Expand Up @@ -54,8 +57,9 @@ export default class Preview extends Component {
}

render () {
const { onClick, playIcon, previewTabIndex } = this.props
const { light, onClick, playIcon, previewTabIndex } = this.props
const { image } = this.state
const isElement = React.isValidElement(light)
const flexCenter = {
display: 'flex',
alignItems: 'center',
Expand All @@ -65,7 +69,7 @@ export default class Preview extends Component {
preview: {
width: '100%',
height: '100%',
backgroundImage: image ? `url(${image})` : undefined,
backgroundImage: image && !isElement ? `url(${image})` : undefined,
backgroundSize: 'cover',
backgroundPosition: 'center',
cursor: 'pointer',
Expand All @@ -76,6 +80,7 @@ export default class Preview extends Component {
borderRadius: ICON_SIZE,
width: ICON_SIZE,
height: ICON_SIZE,
position: isElement ? 'absolute' : undefined,
...flexCenter
},
playIcon: {
Expand All @@ -98,6 +103,7 @@ export default class Preview extends Component {
tabIndex={previewTabIndex}
onKeyPress={this.handleKeyPress}
>
{isElement ? light : null}
{playIcon || defaultPlayIcon}
</div>
Comment thread
idiglove marked this conversation as resolved.
Comment thread
idiglove marked this conversation as resolved.
)
Expand Down
2 changes: 1 addition & 1 deletion src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const propTypes = {
playsinline: bool,
pip: bool,
stopOnUnmount: bool,
light: oneOfType([bool, string]),
light: oneOfType([bool, string, object]),
playIcon: node,
previewTabIndex: number,
fallback: node,
Expand Down
2 changes: 1 addition & 1 deletion types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface BaseReactPlayerProps {
previewTabIndex?: number | null
pip?: boolean
stopOnUnmount?: boolean
light?: boolean | string
light?: boolean | string | ReactElement
fallback?: ReactElement
wrapper?: ComponentType<{ children: ReactNode }>
onReady?: (player: ReactPlayer) => void
Expand Down