|
1 | | -import React, { CSSProperties } from 'react'; |
2 | | - |
3 | | -interface TimeWidgetProps { |
4 | | - size: number; |
5 | | -}; |
6 | | - |
7 | | -interface TimeWidgetState { |
8 | | - time: Date; |
9 | | -}; |
10 | | - |
11 | | -class TimeWidget extends React.Component<TimeWidgetProps, TimeWidgetState> { |
12 | | - interval: NodeJS.Timer | null; |
13 | | - |
14 | | - constructor(props: TimeWidgetProps) { |
15 | | - super(props) |
16 | | - this.state = { |
17 | | - time: new Date() |
18 | | - }; |
19 | | - } |
20 | | - |
21 | | - render() { |
22 | | - const { size } = this.props |
23 | | - |
24 | | - const style: CSSProperties = { |
25 | | - display: 'flex', |
26 | | - justifyContent: 'center', |
27 | | - alignItems: 'center', |
28 | | - textAlign: 'center', |
29 | | - position: 'absolute', |
30 | | - bottom: 0, |
31 | | - right: 0, |
32 | | - width: `${size*9.5}px`, |
33 | | - height: `${size*9.5}px`, |
34 | | - borderRadius: '50%', |
35 | | - color: 'white', |
36 | | - background: 'rgba(0, 128, 128, 0.75)', |
37 | | - transform: `translate(${size*1.25}px, ${size*2.4}px) rotate(-20deg)`, |
38 | | - fontSize: `${size}px`, |
39 | | - fontWeight: 'bold' |
40 | | - } |
41 | | - |
42 | | - return ( |
43 | | - <div style={style}> |
44 | | - {this.formattedTime(this.state.time)} |
45 | | - </div> |
46 | | - ) |
47 | | - } |
48 | | - |
49 | | - formattedTime(time) { |
50 | | - return ` |
51 | | - ${time.getFullYear()}/${this.zero_fill(time.getMonth() + 1)}/${this.zero_fill(time.getDate())}(${this.day2str(time.getDay())})\n |
52 | | - ${this.zero_fill(time.getHours())}:${this.zero_fill(time.getMinutes())}:${this.zero_fill(time.getSeconds())} |
53 | | - ` |
54 | | - } |
55 | | - |
56 | | - zero_fill(str) { |
57 | | - return `0${str}`.slice(-2) |
58 | | - } |
59 | | - |
60 | | - day2str(n) { |
61 | | - return [ |
62 | | - '日', |
63 | | - '月', |
64 | | - '火', |
65 | | - '水', |
66 | | - '木', |
67 | | - '金', |
68 | | - '土' |
69 | | - ][n] |
70 | | - } |
71 | | - |
72 | | - tick() { |
73 | | - this.setState({ time: new Date() }) |
74 | | - } |
75 | | - |
76 | | - componentDidMount() { |
77 | | - this.interval = setInterval(this.tick.bind(this), 500) |
78 | | - } |
79 | | - |
80 | | - componentWillUnmpount() { |
81 | | - clearInterval(this.interval) |
82 | | - } |
83 | | -} |
84 | | - |
85 | | -export { TimeWidget } |
| 1 | +export { TimeWidget } from './widget'; |
| 2 | +export { TimeWidgetEditor } from './editor'; |
0 commit comments