movie-web/src2/components/Title.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-07-14 00:31:37 +02:00
import React from 'react';
2021-08-02 14:15:18 +02:00
import { useHistory } from 'react-router-dom';
2021-07-14 00:31:37 +02:00
import { useMovie } from '../hooks/useMovie'
import { Arrow } from '../components/Arrow'
import './Title.css'
// size: "big" | "medium" | "small" | null
// accent: string | null
// accentLink: string | null
export function Title(props) {
2021-08-02 14:15:18 +02:00
const { streamData, resetStreamData } = useMovie();
const history = useHistory();
2021-07-14 00:31:37 +02:00
const size = props.size || "big";
const accentLink = props.accentLink || "";
const accent = props.accent || "";
function handleAccentClick(){
if (accentLink.length > 0) {
history.push(`/${streamData.type}`);
resetStreamData();
}
}
function handleKeyPress(event){
if (event.code === 'Enter' || event.code === 'Space'){
handleAccentClick();
}
}
2021-08-07 20:42:56 +02:00
2021-07-14 00:31:37 +02:00
return (
<div>
{accent.length > 0 ? (
<p onClick={handleAccentClick} className={`title-accent ${accentLink.length > 0 ? 'title-accent-link' : ''}`} tabIndex={accentLink.length > 0 ? 0 : undefined} onKeyPress={handleKeyPress}>
2021-07-14 00:31:37 +02:00
{accentLink.length > 0 ? (<Arrow left/>) : null}{accent}
</p>
) : null}
2021-08-07 20:42:56 +02:00
<h1 className={"title " + ( size ? `title-size-${size}` : '' )}>{props.children}</h1>
2021-07-14 00:31:37 +02:00
</div>
)
}