-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
93 lines (81 loc) · 2.58 KB
/
App.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { Component } from 'react';
import { connect } from 'react-redux';
import {
setLayers,
setSelectedColor,
setCurrentLayer,
setEdting,
} from './actions/layers';
import './App.css';
import Layer from './components/Layer';
import CustomPicker from './components/CustomPicker';
import HideContainerButton, { Header, Title } from './components/Header';
import Tab from './components/Tab';
import Background from './styledComponents/Background';
import Container from './styledComponents/Container';
import ControlPanel from './styledComponents/ControlPanel';
class App extends Component {
componentDidMount() {
this.props.dispatch(setLayers(
[
{degree: 93, hidden: false, colors:[{h: '188', s: '90', l: '50', a: '0.73', amount: 25, name: "color01", id: "color01"},
{h: '301', s: '100', l: '60', a: '0.3', amount: 75, name: "color02", id: "color02"}]},
{degree: 0, hidden: false, colors:[{h: '53', s: '93', l: '50', a: '0.75', amount: 30, name: "color11", id: "color11"},
{h: '291', s: '92', l: '50', a: '0.5', amount: 70, name: "color12", id: "color12"}]}
]
));
this.props.dispatch(setSelectedColor('color01'))
this.props.dispatch(setCurrentLayer({ layerIndex: 0 }))
this.props.dispatch(setEdting(false))
}
handleColorChange = (color) => {
const { layerData, selectedColorId } = this.props.layers;
this.props.dispatch(setEdting('color'))
layerData.forEach(layer => {
layer.colors.forEach(c => {
if(selectedColorId === c.id) {
c.h = Number(color.hsl.h.toFixed(2));
c.s = Number((color.hsl.s * 100).toFixed(2));
c.l = Number((color.hsl.l * 100).toFixed(2));
c.a = color.hsl.a;
}
});
});
this.props.dispatch(setLayers(layerData))
}
finishEditing = () => {
this.props.dispatch(setEdting(false))
}
render() {
const { layerData, selectedColor, editing, hidden, gradientString } = this.props.layers;
let {h, s, l, a} = selectedColor || {h:1, s:1, l:1, a:1}
return (
<Background className="gradientr" background={gradientString}>
<Header>
<Title>Gradientr</Title>
<HideContainerButton />
</Header>
{layerData && layerData.length > 0 ? (
<Container hide={hidden}>
<Tab index={0} />
<Tab index={1} />
<ControlPanel editing={editing}>
<Layer/>
<CustomPicker
opacity={editing && editing !== 'color' ? "0" : "1"}
onChange={ this.handleColorChange }
onChangeComplete={ this.finishEditing }
color={ {h, s, l, a} }
/>
</ControlPanel>
</Container>) : null}
</Background>
);
}
}
function mapStateToProps({ layers }) {
return {
layers,
}
}
export default connect(mapStateToProps)(App);