forked from danielbayerlein/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 882 Bytes
/
index.js
File metadata and controls
43 lines (36 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Component } from 'react'
import tinytime from 'tinytime'
import styled from 'styled-components'
import Widget from '../../widget'
const TimeItem = styled.div`
font-size: 4em;
text-align: center;
`
const DateItem = styled.div`
font-size: 1.5em;
text-align: center;
`
export default class DateTime extends Component {
static defaultProps = {
interval: 1000 * 10
}
state = {
date: new Date()
}
componentDidMount () {
const { interval } = this.props
this.timeout = setTimeout(() => this.setState({ date: new Date() }), interval)
}
componentWillUnmount () {
clearTimeout(this.timeout)
}
render () {
const { date } = this.state
return (
<Widget>
<TimeItem>{tinytime('{H}:{mm}').render(date)}</TimeItem>
<DateItem>{tinytime('{DD}.{Mo}.{YYYY}').render(date)}</DateItem>
</Widget>
)
}
}