import React, { useEffect, useState } from 'react';
import './App.scss';
const Input = () => {
const [text, setText] = useState('text');
return
{text}
setText(e.target.value)} />
}
const LoginForm = ({onLogin}) => {
const [login, setLogin] = useState('');
const [pswd, setPswd] = useState('');
return
setLogin(e.target.value)}/>
setPswd(e.target.value)}/>
}
const Counter = ({ms=1000}) => {
const [counter, setCounter] = useState(0)
useEffect(() => {
const interval = setInterval (() => setCounter(counter => counter+1), ms)
return () => {
console.log('DID UNMOUNT')
clearInterval(interval)
}
}, [ms])
/* setInterval (() => setCounter(counter+1), 1000) */
return (
{counter}
)
}
const Spoiler = ({header="+",children, opened=true}) => {
const [open, setOpen] = useState(opened)
return (
setOpen(!open)}>{header}
{open && children}
)
}
const Counters = () => {
const [cntrs, setCntrs] = useState([])
const [ms, setMs] = useState(1000)
return (
{cntrs.map(() => )}
)
}
const RangeInput = ({min,max}) => {
const [value, SetValue] = useState(0);
let color = "white";
/* useEffect(() => {
if(value < min || value > max){
color = "red";
console.log(color);
} else {
color = '';
}
}, [value]) */
if(value < min || value > max) {
color = "red"
} else {
color = "";
}
return (
SetValue(e.target.value.length)} style={{backgroundColor:color}}/>
)
}
const PasswordConfirm = ({min}) => {
const[value1,SetValue1] = useState('');
const[value2,SetValue2] = useState('');
let color = "";
let pattern = /^[0-9a-zA-Z]+$/;
if(value1.length > min && value2.length > min && value1.match(pattern) && value2.match(pattern) && value1 === value2) {
color="green"
} else {
color="red";
}
return(
SetValue1(e.target.value)} style={{borderColor:color}}/>
SetValue2(e.target.value)} style={{borderColor:color}}/>
)
}
class Timer extends React.Component {
constructor(props) {
super(props)
this.state = {seconds: 0,
minutes:0,
hour:0,
propsTime: props.time
}
this.Pause = this.Pause.bind(this);
this.tick = this.tick.bind(this);
}
static getDerivedStateFromProps(props, state){
console.log('get derived state');
return /* ({propsTime: props.time}) */ null
}
componentDidMount() {
this.timerID = setInterval(this.tick,1000)
}
Pause() {
clearInterval(this.timerID);
}
tick() {
let t = this.state.propsTime -1
let hours = Math.floor(t/3600);
let minutes = Math.floor((t - hours*3600)/60);
let seconds = Math.floor(t - hours*3600-minutes*60)
this.setState({
seconds,minutes,hours, propsTime: t
})
/* this.setState({
seconds: this.state.seconds - 1
}) */
/* console.log(t); */
if (t <= 0){
clearInterval(this.timerID)
}
}
render() {
const {seconds, minutes, hours} = this.state
return(
TIMER
hours :{hours}
minutes: {minutes}
seconds: {seconds}
)
}
}
class TimerControl extends React.Component {
constructor(props){
super(props)
this.state = {hours:0,
minutes:0,
seconds:0,
toSeconds:0,
addTimer: false}
this.handlerHours = this.handlerHours.bind(this);
this.handlerMinutes = this.handlerMinutes.bind(this);
this.handlerSeconds = this.handlerSeconds.bind(this);
this.handleAddTimer = this.handleAddTimer.bind(this);
}
handlerHours(e){
let hourToSeconds = +e*3600
console.log(hourToSeconds);
this.setState({hours: hourToSeconds})
}
handlerMinutes(e){
let minuteToSeconds = +e*60
console.log(minuteToSeconds);
this.setState({minutes: minuteToSeconds})
}
handlerSeconds(e){
console.log(+e);
this.setState({seconds: +e})
}
handleAddTimer() {
let allTime = this.state.hours + this.state.minutes + this.state.seconds
this.setState({addTimer:!this.state.addTimer, toSeconds: allTime})
}
render() {
return(
{this.state.addTimer && }
)
}
}
const SecondsTimer = ({seconds}) => {seconds}
class TimerContainer extends React.Component {
constructor(props){
super(props)
this.state = {
secToEnd:0,
seconds: this.props.seconds,
refresh: this.props.refresh
}
this.tick = this.tick.bind(this);
}
componentDidMount() {
this.timerID = setInterval(this.tick, this.state.refresh)
}
tick() {
let startTime = performance.now();
this.setState({seconds: this.state.seconds - ((performance.now() - startTime)/1000)})
/* let setSec = this.state.seconds - Math.floor((performance.now() - startTime)/1000);
console.log(setSec); */
}
render(){
const Render = this.props.render
return(
)
}
}
function App () {
return(
{/*
*/}
{/*
console.log(login,password)}/> */}
Hello} opened={false}>
Hello
blabla
);
}
export default App;