forked from MrBlenny/react-flow-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zoom.tsx
74 lines (68 loc) · 1.64 KB
/
Zoom.tsx
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { cloneDeep, mapValues } from 'lodash'
import * as React from 'react'
import styled from 'styled-components'
import { FlowChart } from '../src'
import * as actions from '../src/container/actions'
import { Content, Page, Sidebar } from './components'
import { chartSimple } from './misc/exampleChartState'
export const Message = styled.div`
margin: 10px;
padding: 10px;
line-height: 1.4em;
`
export const Button = styled.div`
padding: 10px;
background: cornflowerblue;
color: white;
border-radius: 3px;
text-align: center;
transition: 0.3s ease all;
margin: 10px;
cursor: pointer;
&:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
&:active {
background: #5682d2;
}
`
export class Zoom extends React.Component {
public state = cloneDeep(chartSimple)
public render () {
const chart = this.state
const stateActions = mapValues(actions, (func: any) => (...args: any) =>
this.setState(func(...args)),
) as typeof actions
return (
<Page>
<Content>
<FlowChart chart={chart} callbacks={stateActions} />
</Content>
<Sidebar>
<Message>
Current zoom:
{chart.scale}
</Message>
<Button
onClick={() => {
this.setState({
scale: this.state.scale + 0.1 ,
})
}}
>
+
</Button>
<Button
onClick={() => {
this.setState({
scale: this.state.scale - 0.1 ,
})
}}
>
-
</Button>
</Sidebar>
</Page>
)
}
}