-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
51 lines (46 loc) · 1.4 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
import { isCalledWithNew } from '../utils';
import Button from './Button';
import Heading from './Heading';
import '../styles/index.scss';
import ColorSpan from './ColorSpan';
function App({ $target }) {
isCalledWithNew(new.target);
this.$target = $target;
this.setState = (nextState) => {
this.state = nextState;
this.render();
};
(() =>
new Heading({
$target,
text: 'CLICK THE BUTTON BELLOW TO GENERATE A RANDOM GRADIENT HEX COLOR COMBINATION',
}))();
(() =>
new Heading({
$target,
text: 'background: linear-gradient(to right, <span id="hexcode1"></span>, <span id="hexcode2"></span>);',
}))();
const $colorSpan1 = new ColorSpan({
$target: document.querySelector('#hexcode1'),
initialState: '#ffffff',
});
const $colorSpan2 = new ColorSpan({
$target: document.querySelector('#hexcode2'),
initialState: '#ffffff',
});
(() =>
new Button({
$target,
text: 'Click Me',
handleBtnClick: (color1, color2) => {
this.setState({ ...this.state, colors: [color1, color2] });
$colorSpan1.setState({ ...$colorSpan1.state, color: color1 });
$colorSpan2.setState({ ...$colorSpan2.state, color: color2 });
},
}))();
this.render = () => {
document.body.style.background = `linear-gradient(to right, ${this.state.colors[0]}, ${this.state.colors[1]})`;
};
this.render();
}
export default App;