-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
128 lines (103 loc) · 4.63 KB
/
index.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Get the closes color from a different range">
<meta name="author" content="gdvalderrama">
<title>Color approximator</title>
<!-- Bootstrap core CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- Favicons -->
<link rel="icon" href="assets/icon.png">
<meta name="theme-color" content="#7952b3">
<style>
</style>
</head>
<body>
<main>
<div class="bg-dark text-secondary px-4 py-5 text-center">
<div class="py-5">
<h1 class="display-5 fw-bold text-white py-5">Color approximator</h1>
<div class="col-lg-6 mx-auto">
<p class="fs-5">
Quickly get the closest color in a different paint range.
</p>
<p class="fs-5 mb-4">
Choose the desired color range between Citadel, Vallejo, AK...
</p>
</div>
</div>
</div>
<div class="mb-0"></div>
<div class="px-4 py-5 text-center">
<form method="POST" action="https://cepd8d48ok.execute-api.eu-west-1.amazonaws.com/get_closest_color">
<div class="row g-3">
<div class="col-sm-6 col-lg-4 offset-lg-1">
<label for="range" class="form-label">Paint Range</label>
<select class="form-select" name="paint_range_id" required="">
<option value="" disabled selected>Choose...</option>
<option value="CPS">Citadel</option>
<option value="VMC">Vallejo Model</option>
<option value="VGC">Vallejo Game</option>
<option value="AKT">AK</option>
</select>
<div class="invalid-feedback">
Please provide a valid paint range.
</div>
</div>
<div class="col-sm-6 col-lg-4 offset-lg-1">
<label for="color" class="form-label">Color (hex code)</label>
<input type="text" class="form-control" name="color" placeholder="#0370b1" value="" required="">
<div class="invalid-feedback">
Valid color hex code is required.
</div>
<div>
<button id="color-picker" class="btn btn-secondary btn-sm mt-1">Use color picker</button>
</div>
</div>
</div>
<button class="w-50 btn btn-primary btn-lg m-5">
Get color!
</button>
</form>
<div id="result">
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vanilla-picker@2"></script>
<script>
var colorInput = document.querySelector('input[name="color"]');
var colorPicker = document.querySelector('#color-picker');
var picker = new Picker({parent:colorPicker, alpha:false});
picker.onChange = function(color) {
colorInput.value = color.printHex(false);
};
const form = document.querySelector('form');
let axiosConfig = {
headers: {
'Content-Type': 'application/json'
}
};
form.addEventListener('submit', async event => {
event.preventDefault();
let data = JSON.stringify(Object.fromEntries(new FormData(form)));
try {
const response = await axios.post(form.action, data, axiosConfig);
const newColor = response.data;
// {"name": "Blue Fluorescent", "paint_type": "Fluorescent", "paint_color": "#0370b1", "difference": 110.6752004741803}
document.getElementById('result').innerHTML = `<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Success!</h4>
<p>The closest color is <span class="text-primary">${newColor.name}</span> <span style="color:${newColor.paint_color}">■</span></p>`
} catch (errors) {
console.error(errors);
document.getElementById('result').innerHTML = `<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Fail!</h4>
<p>There was an error, please try again :(</p>`
}
});
</script>
</body>
</html>