Box-shadow live visualize
by Julien Roche
HTML
<body class="main">
<section class="main__visualizer">
<div class="main__visualizer__rect"></div>
</section>
<footer class="main__editor">
<label>
<span>Offset X</span>
<input type="range" min="0" max="250" value="10" step="1" name="offsetX" />
</label>
<label>
<span>Offset Y</span>
<input type="range" min="0" max="250" value="10" step="1" name="offsetY" />
</label>
<label>
<span>Blur radius</span>
<input type="range" min="0" max="50" value="0" step="1" name="blurRadius" />
</label>
<label>
<span>Spread radius</span>
<input type="range" min="0" max="50" value="0" step="1" name="spreadRadius" />
</label>
<label>
<span>Inset</span>
<input type="checkbox" value="inset" name="inset" />
</label>
<br />
<br />
<output name="cssConfiguration"></output>
</footer>
</body>
CSS
html,
body {
border: none;
height: 100%;
margin: 0 0 0 0;
padding: 0 0 0 0;
width: 100%;
}
:root {
--offsetX: 10px;
--offsetY: 10px;
--blurRadius: 0px;
--spreadRadius: 0px;
}
.main {
background-color: white;
display: flex;
flex-direction: column;
}
.main__visualizer {
align-items: center;
display: flex;
flex: 1 1 auto;
justify-content: center;
margin-bottom: 1rem;
}
.main__visualizer__rect {
border: 1px solid black;
box-shadow: var(--offsetX) var(--offsetY) var(--blurRadius) var(--spreadRadius) red;
height: 5rem;
width: 20rem;
}
.inset .main__visualizer__rect {
box-shadow: inset var(--offsetX) var(--offsetY) var(--blurRadius) var(--spreadRadius) red;
}
.main__editor {
border-top: 1px solid black;
flex: 0 0 150px;
margin-top: 1rem;
}
Babel + JSX
// https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
let cssConfigurationOutputElement = document.querySelector('[name="cssConfiguration"');
let sampleElement = document.querySelector('.main__visualizer__text');
document.addEventListener('input', event => {
let inputName = event.target.name;
document.documentElement.style.setProperty(`--${inputName}`, `${event.target.value}px`);
updateCssConfigurationOutput();
}, false);
document.addEventListener('change', event => {
let inputName = event.target.name;
let inputType = event.target.type;
if (inputType === 'checkbox') {
event.target.checked ? document.body.classList.add(inputName) : document.body.classList.remove(inputName);
}
updateCssConfigurationOutput();
}, false);
function updateCssConfigurationOutput() {
cssConfigurationOutputElement.value = `text-shadow: ${window.getComputedStyle(sampleElement)['text-shadow']}`;
}
updateCssConfigurationOutput();