-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathPreview.js
59 lines (57 loc) · 1.47 KB
/
Preview.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
import React, { useEffect, useRef } from 'react'
import { LightSource } from './App.style'
const Preview = ({ previewBox, setActiveLightSource }) => {
const lightSources = useRef([])
useEffect(() => {
lightSources.current = [...document.querySelectorAll('.light-source')]
}, [])
const setLightSource = e => {
lightSources.current.forEach(element => {
element.classList.remove('active')
})
e.target.classList.add('active')
setActiveLightSource(parseInt(e.target.dataset.value))
}
return (
<div className="preview">
<LightSource
top="0"
bottom="unset"
right="0"
left="unset"
data-value="2"
onClick={setLightSource}
className="light-source"
></LightSource>
<LightSource
top="0"
bottom="unset"
right="unset"
left="0"
data-value="1"
onClick={setLightSource}
className="light-source active"
></LightSource>
<LightSource
top="unset"
bottom="0"
right="0"
left="unset"
data-value="3"
onClick={setLightSource}
className="light-source"
></LightSource>
<LightSource
top="unset"
bottom="0"
right="unset"
left="0"
data-value="4"
onClick={setLightSource}
className="light-source"
></LightSource>
<div ref={previewBox} className="soft-element soft-shadow"></div>
</div>
)
}
export default Preview