Refactor pallette file

This commit is contained in:
Talia 2022-09-07 14:38:27 +02:00
parent 0d790155ba
commit 55e87ce242

View file

@ -6,19 +6,19 @@
</section>
<!-- TODO: Change the base hue and offset here -->
<section style="--base-hue: 200deg; --saturation: 80%; --offset: calc(360deg / 3)">
<section style="--base-hue: 280deg; --saturation: 50%; --offset: calc(360deg / 6)">
<h2>Primary</h2>
<!-- Only override values here for slight tweaking -->
<div class="colors" style="--hue: var(--base-hue);">
<span style="--lightness: 05%"></span>
<span style="--lightness: 15%"></span>
<span style="--lightness: 30%"></span>
<span style="--lightness: 40%"></span>
<span style="--lightness: 50%"></span>
<span style="--lightness: 60%"></span>
<span style="--lightness: 70%"></span>
<span style="--lightness: 80%"></span>
<span style="--lightness: 95%"></span>
<button style="--lightness: 05%"></button>
<button style="--lightness: 15%"></button>
<button style="--lightness: 30%"></button>
<button style="--lightness: 40%"></button>
<button style="--lightness: 50%"></button>
<button style="--lightness: 60%"></button>
<button style="--lightness: 70%"></button>
<button style="--lightness: 80%"></button>
<button style="--lightness: 95%"></button>
</div>
<section class="hint box">
@ -28,15 +28,15 @@
<h2>Secondary</h2>
<div class="colors" style="--hue: calc(var(--base-hue) + var(--offset));">
<span style="--lightness: 05%"></span>
<span style="--lightness: 15%"></span>
<span style="--lightness: 30%"></span>
<span style="--lightness: 40%"></span>
<span style="--lightness: 50%"></span>
<span style="--lightness: 60%"></span>
<span style="--lightness: 70%"></span>
<span style="--lightness: 80%"></span>
<span style="--lightness: 95%"></span>
<button style="--lightness: 05%"></button>
<button style="--lightness: 15%"></button>
<button style="--lightness: 30%"></button>
<button style="--lightness: 40%"></button>
<button style="--lightness: 50%"></button>
<button style="--lightness: 60%"></button>
<button style="--lightness: 70%"></button>
<button style="--lightness: 80%"></button>
<button style="--lightness: 95%"></button>
</div>
<section class="hint box">
@ -47,15 +47,15 @@
<h2>Tertiary</h2>
<div class="colors" style="--hue: calc(var(--base-hue) - var(--offset));">
<span style="--lightness: 05%"></span>
<span style="--lightness: 15%"></span>
<span style="--lightness: 30%"></span>
<span style="--lightness: 40%"></span>
<span style="--lightness: 50%"></span>
<span style="--lightness: 60%"></span>
<span style="--lightness: 70%"></span>
<span style="--lightness: 80%"></span>
<span style="--lightness: 95%"></span>
<button style="--lightness: 05%"></button>
<button style="--lightness: 15%"></button>
<button style="--lightness: 30%"></button>
<button style="--lightness: 40%"></button>
<button style="--lightness: 50%"></button>
<button style="--lightness: 60%"></button>
<button style="--lightness: 70%"></button>
<button style="--lightness: 80%"></button>
<button style="--lightness: 95%"></button>
</div>
<section class="hint box">
@ -64,16 +64,16 @@
</section>
<h2>Neutral</h2>
<div class="colors" style="--hue: var(--base-hue); --saturation: 5%;">
<span style="--lightness: 05%"></span>
<span style="--lightness: 15%"></span>
<span style="--lightness: 30%"></span>
<span style="--lightness: 40%"></span>
<span style="--lightness: 50%"></span>
<span style="--lightness: 60%"></span>
<span style="--lightness: 70%"></span>
<span style="--lightness: 80%"></span>
<span style="--lightness: 95%"></span>
<div class="colors" style="--hue: 210deg; --saturation: 5%;">
<button style="--lightness: 05%"></button>
<button style="--lightness: 15%"></button>
<button style="--lightness: 30%"></button>
<button style="--lightness: 40%"></button>
<button style="--lightness: 50%"></button>
<button style="--lightness: 60%"></button>
<button style="--lightness: 70%"></button>
<button style="--lightness: 80%"></button>
<button style="--lightness: 95%"></button>
</div>
<section class="hint box">
@ -82,9 +82,6 @@
</section>
</section>
<!-- ======================================== -->
<!-- ===== STYLES AND APPLICATION LOGIC ===== -->
<!-- ======================================== -->
@ -131,55 +128,38 @@
font-size: 2em;
}
.box {
--radius: .3em;
width: calc((3rem + .6rem * 2) * 9);
font-style: italic;
border-radius: var(--radius);
background: hsla(200deg, 5%, 92%, 1);
box-shadow: .0em .1em .2em inset hsl(220deg, 8%, 80%);
padding: 1em 2em;
position: relative;
margin: 2em 0em;
}
.hint, .info { --color: hsla(calc( 200deg - calc(360deg / 3)), 80%, 50%, 1) }
.box::after {
display: block;
position: absolute;
left: 0;
top: 0;
height: 100%;
width: .4em;
background-color: var(--color, transparent);
border-radius: var(--radius) 0 0 var(--radius);
content: '';
}
.box.hint::before {
content: "Hint: ";
display: inline-block;
font-weight: bold;
}
div.colors {
--separation2: .6em; /* Halved separation */
display: flex;
/* padding: var(--separation2); */
}
div.colors span {
background: hsl(var(--hue), var(--saturation, 50%), var(--lightness, 50%));
div.colors button {
all: unset;
margin: var(--separation2);
cursor: pointer;
border-radius: .4em;
overflow: hidden;
transition: box-shadow 0.3s;
} div.colors button::before {
content: '';
background: hsl(var(--hue), var(--saturation, 50%), var(--lightness, 50%));
box-shadow: .1em .1em .8em hsla(calc(var(--hue) + 30deg), calc(100% - var(--lightness) - 10%), calc(var(--lightness) - 40%), .4) inset;
width: 3em;
height: 3em;
margin: var(--separation2);
box-shadow: .1em .1em .8em hsla(calc(var(--hue) + 30deg), calc(100% - var(--lightness) - 10%), calc(var(--lightness) - 40%), .4) inset;
display: block;
transition: box-shadow 0.3s;
}
div.colors button:hover {
box-shadow: .4em .4em .6em #0004;
}
div.colors button:hover::before {
box-shadow: none;
}
/* === Popup notification shenanigans === */
@keyframes fade {
0% { opacity: 0; transform: translate(-50%, -10%)}
20% { opacity: 1;}
@ -199,11 +179,48 @@
text-align: center;
}
/* === Info Boxes === */
.box {
--radius: .3em;
width: calc((3rem + .6rem * 2) * 9);
font-style: italic;
border-radius: var(--radius);
background: hsla(200deg, 5%, 92%, 1);
box-shadow: .0em .1em .2em inset hsl(220deg, 8%, 80%);
padding: 1em 2em;
position: relative;
margin: 2em 0em;
}
.hint, .info { --color: hsla(calc( 280deg - calc(360deg / 6)), 50%, 50%, 1) }
.box::after {
display: block;
position: absolute;
left: 0;
top: 0;
height: 100%;
width: .4em;
background-color: var(--color, transparent);
border-radius: var(--radius) 0 0 var(--radius);
content: '';
}
.box.hint::before {
content: "Hint: ";
display: inline-block;
font-weight: bold;
}
/* === Utility === */
[center] { text-align: center; }
</style>
<script>
const show_message = function(message, color, x, y) {
const showMessage = function(message, color, x, y) {
let box = document.createElement('div');
box.innerHTML = message;
box.classList.add('notification');
@ -221,17 +238,15 @@
}
window.addEventListener("load", function() {
document.querySelectorAll('div.colors span').forEach(function(span) {
span.addEventListener('click', function(event) {
let prop = name => getComputedStyle(event.target).getPropertyValue(name).replace(/^ *| *$/g, "")
let hsla = `hsla(${prop("--hue")}, ${prop("--saturation")}, ${prop("--lightness")}, 1)`
navigator.clipboard.writeText(hsla).then(function() {
show_message(`Copied to Clipboard:<br>${hsla}`, hsla, event.clientX, event.clientY);
}, function(err) {
console.error('Async: Could not copy text: ', err);
document.querySelectorAll('div.colors button').forEach(button => {
button.addEventListener('click', event => {
const prop = name => getComputedStyle(button).getPropertyValue(name).replace(/^ *| *$/g, "")
const hsla = `hsla(${prop("--hue")}, ${prop("--saturation")}, ${prop("--lightness")}, 1)`
navigator.clipboard.writeText(hsla).then(() => {
const box = button.getBoundingClientRect()
showMessage(`Copied to Clipboard:<br>${hsla}`, hsla, box.x+box.width/2, box.y+box.height/2);
});
});
span.style.setProperty('cursor', 'pointer');
});
})
</script>