forked from Matias-Aranda/color-scheme-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 1.03 KB
/
index.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
const colorContainer = document.getElementById("color-container")
const selectEl = document.querySelector("select")
let colorPickedEl = document.querySelector("input")
let defaultColor = "F55A5A"
document.addEventListener("submit",function(e){
let colorInput = colorPickedEl.value.replace("#","")
e.preventDefault()
renderColors(colorInput)
})
function renderColors(colorPicked) {
fetch(`https://www.thecolorapi.com/scheme?hex=${colorPicked}&mode=${selectEl.value}`)
.then(res => res.json())
.then(data => {
let colorsArray = data.colors.map(color => color.hex.value)
let html = ""
for(let color of colorsArray){
html += `<div class="color" style="background: ${color}">
<div class="hex">
<h3 class="hex-text">${color}</h3>
</div>
</div>`
}
colorContainer.innerHTML = html
})
}
renderColors(defaultColor)