JSFiddle - React, Tailwind, and code Playground
HTML
<div class="slide">
</div>
CSS
.slide{
width: 0;
border-left: 200px solid #ff5400;
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
background-color: rgba(0,0,0,0.15);
cursor: pointer;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.slide.hover, .slide.active{
width: 180px;
background-color: #ddd;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
JavaScript
$(".slide").on({
mouseenter: function() {
$(this).addClass('hover');
},
mouseleave: function() {
$(this).removeClass('hover');
},
click: function() {
$(this).toggleClass('active');
}
});
$(document).on('click', function(e) {
if (!$(e.target).is('.slide') && $('.slide').is('.active')) $('.slide').removeClass('active');
});