console
window.addEventListener("DOMContentLoaded",() => {
const checklist = new Checklist("form");
});
class Checklist {
constructor(qs) {
this.el = document.querySelector(qs);
this.el?.addEventListener("change",this.checkForSelected.bind(this));
this.init();
}
init() {
const inputs = this.el.querySelectorAll("input");
Array.from(inputs).forEach(el => {
el.checked = false;
});
}
checkForSelected(e) {
const tar = e.target;
const isTop = tar.hasAttribute("data-top");
this.updateChecks(tar.name,isTop);
}
updateChecks(name,isTop) {
if (name) {
const topCheck = this.el.querySelector(`[name="${name}"][data-top]`);
const checkItems = this.el.querySelectorAll(`[name="${name}"]:not([data-top])`);
const checked = Array.from(checkItems).filter(el => el.checked);
const notAllChecked = checked.length < checkItems.length;
if (isTop) {
Array.from(checkItems).forEach(el => {
el.checked = notAllChecked;
});
} else {
topCheck.checked = !notAllChecked;
topCheck.indeterminate = checked.length > 0 && notAllChecked;
}
}
}
}
<form>
<div class="checkbox-group">
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="desktop" value="desktop" data-top>
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<strong class="checkbox-text">Desktop Macs</strong>
</label>
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="desktop" value="mac_mini">
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<span class="checkbox-text">Mac Mini</span>
</label>
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="desktop" value="mac_studio">
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<span class="checkbox-text">Mac Studio</span>
</label>
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="desktop" value="mac_pro">
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<span class="checkbox-text">Mac Pro</span>
</label>
</div>
<div class="checkbox-group">
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="laptop" value="macbooks" data-top>
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<strong class="checkbox-text">MacBooks</strong>
</label>
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="laptop" value="macbook_pro_13-inch">
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<span class="checkbox-text">MacBook Pro 13"</span>
</label>
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="laptop" value="macbook_pro_14-inch">
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<span class="checkbox-text">MacBook Pro 14"</span>
</label>
<label class="checkbox-label">
<input class="checkbox" type="checkbox" name="laptop" value="macbook_pro_16-inch">
<svg class="check-icon" width="24px" height="24px" viewBox="0 0 24 24">
<g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect class="check-icon__box" x="1" y="1" width="22" height="22"/>
<polyline class="check-icon__box-worm" points="23,1 1,1 1,23 23,23 23,4" stroke-dasharray="30 146" stroke-dashoffset="30"/>
<polyline class="check-icon__check-worm" points="23,4 10,17 5,12 18,12" stroke-dasharray="17.38 149.68" stroke-dashoffset="103.38"/>
</g>
</svg>
<span class="checkbox-text">MacBook Pro 16"</span>
</label>
</div>
</form>
* {
border: 0;
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--hue: 223;
--bg: hsl(var(--hue),10%,90%);
--fg1: hsl(var(--hue),10%,10%);
--fg2: hsl(var(--hue),10%,30%);
--fg3: hsl(var(--hue),10%,70%);
--primary: hsl(var(--hue),90%,55%);
--primary-t: hsla(var(--hue),90%,55%,0);
--primary-t-hover: hsla(var(--hue),90%,55%,0.15);
--trans-dur1: 0.3s;
--trans-dur2: 0.9s;
font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320));
}
body,
input {
font: 1em/1.5 "DM Sans", sans-serif;
}
body {
background-color: #e9ffed;
color: var(--fg2);
height: 100vh;
display: grid;
place-items: center;
transition:
background-color var(--trans-dur1),
color var(--trans-dur1);
}
form {
min-width: 16em;
padding: 1.5em 1.5em 0 1.5em;
}
.checkbox-label {
display: flex;
align-items: center;
padding: 0.375em;
position: relative;
-webkit-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.checkbox-label + .checkbox-label {
margin-left: 2em;
}
.checkbox-group {
margin-bottom: 1.25em;
}
.checkbox {
position: absolute;
clip: rect(1px,1px,1px,1px);
width: 1px;
height: 1px;
}
.checkbox-text {
color: var(--fg1);
transition: color var(--trans-dur1);
}
.checkbox-text:after {
background-color: var(--primary-t);
border-radius: 0.375em;
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
transition: background-color 0.15s linear;
}
.check-icon {
margin-right: 0.5em;
width: 1.5em;
height: 1.5em;
}
.check-icon__box {
stroke: var(--fg3);
transition: stroke var(--trans-dur1);
}
.check-icon__box-worm,
.check-icon__check-worm {
stroke: var(--primary);
transition:
stroke var(--trans-dur1),
stroke-dashoffset var(--trans-dur2) cubic-bezier(0.42,-0.2,0.58,1.2);
}
.checkbox:focus ~ .checkbox-text:after,
.checkbox:hover ~ .checkbox-text:after {
background-color: var(--primary-t-hover);
}
.checkbox:checked + .check-icon .check-icon__box-worm,
.checkbox:indeterminate + .check-icon .check-icon__box-worm {
stroke-dashoffset: -91;
}
.checkbox:checked + .check-icon .check-icon__check-worm {
stroke-dashoffset: -6;
}
.checkbox:indeterminate + .check-icon .check-icon__box-worm {
stroke-dashoffset: -111.38;
}
.checkbox:indeterminate + .check-icon .check-icon__check-worm {
stroke-dashoffset: -26.38;
}
@supports selector(:focus-visible) {
.checkbox:focus ~ .checkbox-text:after {
background-color: var(--primary-t);
}
.checkbox:focus-visible ~ .checkbox-text:after,
.checkbox:hover ~ .checkbox-text:after {
background-color: var(--primary-t-hover);
}
}
@media (prefers-color-scheme: dark) {
:root {
--bg: hsl(var(--hue),10%,10%);
--fg1: hsl(var(--hue),10%,90%);
--fg2: hsl(var(--hue),10%,70%);
--fg3: hsl(var(--hue),10%,30%);
--primary: hsl(var(--hue),90%,65%);
--primary-t-hover: hsla(var(--hue),90%,55%,0.3);
}
}