journal.pl/src/pages/main.tsx

94 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-11-27 16:34:37 +03:00
import React, { useState, useCallback } from 'react';
2022-11-27 17:45:32 +03:00
import { getFeatures } from '@ijl/cli';
2022-11-27 16:34:37 +03:00
import logo from '../assets/logo-white.svg';
import arrow from '../assets/36-arrow-right.svg';
2022-11-27 17:45:32 +03:00
import { Keyboard } from '../components/keyboard';
2022-11-27 16:34:37 +03:00
import {
MainWrapper,
InputElement,
InputLabel,
InputWrapper,
LogoImg,
ArrowImg,
IconButton,
StartWrapper,
StartI,
StartInput,
StartLabel,
} from './style';
2022-11-27 17:45:32 +03:00
const keyboardFeature = getFeatures('hub-video-start')?.keyboard;
2022-11-27 16:34:37 +03:00
const Input = ({ onStart }) => {
const [value, setValue] = useState('');
2022-11-27 17:45:32 +03:00
const [inFocuse, setInfocuse] = useState(false);
2022-11-27 16:34:37 +03:00
const handleChange = useCallback(event => {
setValue(event.target.value.toUpperCase())
}, [setValue]);
const handleSubmit = useCallback((event) => {
event.preventDefault();
if (value === 'SBER') {
onStart()
}
}, [value])
return (
2022-11-27 17:45:32 +03:00
<>
<form onSubmit={handleSubmit}>
<InputWrapper>
<InputLabel
htmlFor='input'
>
Ввод:
</InputLabel>
<InputElement
value={value}
onChange={handleChange}
onFocus={() => setInfocuse(true)}
id="input"
autoComplete="off"
/>
<IconButton type="submit">
<ArrowImg src={arrow} />
</IconButton>
</InputWrapper>
</form>
{keyboardFeature && inFocuse && (
<Keyboard onChange={setValue} />
)}
</>
2022-11-27 16:34:37 +03:00
)
}
const Start = () => {
return (
<StartWrapper>
<StartInput
id="check"
type="checkbox"
/>
<StartLabel
htmlFor='check'
>
<StartI>СТАРТ</StartI>
</StartLabel>
</StartWrapper>
)
}
export const MainPage = () => {
const [showStart, setShowStart] = useState(false);
return (
<MainWrapper>
<LogoImg src={logo} />
{!showStart && <Input onStart={() => setShowStart(true)} />}
{showStart && <Start />}
</MainWrapper>
);
};