Search input SVG
by Sandhose
HTML
<div class="container">
<input id="theInput" />
<svg height="31" width="200" id="searchSvg">
<path d="M0 30 L200 30 L192 22 a10,10 0 1 0 -1,1 L192 22" />
</svg>
</div>
CSS
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
width: 100%;
background-color: #1A805A;
}
.container {
flex: 0 0 200px;
height: 30px;
width: 200px;
position: relative;
}
#theInput {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
z-index: 2;
background-color: transparent;
border: none;
color: white;
opacity: 0;
transition: opacity .5s;
padding: 5px;
}
.open #theInput {
opacity: 1;
}
#theInput:focus {
outline: none;
}
#searchSvg {
margin-left: -92px;
transition: margin-left .6s ease-in-out;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
z-index: 1;
}
#searchSvg path {
stroke: white;
stroke-width: 2px;
fill: transparent;
stroke-dasharray: 75,200;
stroke-dashoffset: 75;
stroke-linejoin: round;
transition: stroke-dasharray .6s ease-in-out, stroke-dashoffset .6s ease-in-out;
}
.open #searchSvg {
margin-left: 0;
}
.open #searchSvg path {
stroke-dashoffset: 275;
stroke-dasharray: 200,76;
}
JavaScript
var input = document.getElementById("theInput"),
container = document.querySelector(".container");
input.addEventListener("focus", function() {
container.classList.add("open");
});
input.addEventListener("blur", function() {
if(!input.value) {
container.classList.remove("open");
}
});