JSFiddle - React, Tailwind, and code Playground

by huppen

HTML

<div class="slideout active">
  <div class="caret"></div>
  <div class="body">
    <p>
      Text
    </p>
  </div>
</div>

CSS

body {
  margin: 0;
}

.slideout {
    position: fixed;
    width: 30%;
    height: 100%;
    right: -30%;
    transition: right .3s ease-out;
}

.slideout.active {
  right: 0;
}
/*
.handle {
  position: absolute;
  top: 10px;
  left: -20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: darkred;
  cursor: pointer;
}

.body {
  position: absolute;
  width: 100%;
  height: 100%;
  border-left: 1px solid #CCC;
  background:#FFF;
}


.caret {
    border-style: solid;
    border-width: 0px 10px 10px 10px;
    border-top-color: #CCC;
    border-left-color: transparent;
    border-bottom-color: #CCC;
    border-right-color: transparent;
    width: 0px;
    height: 0px;
    display: block;
    position: absolute;
    top: 40px;
    left: -15px;
    transform: rotate(270deg);
    cursor: pointer;
    z-index: 1;
}

.caret span {
    display: block;
    border-style: solid;
    border-width: 0px 10px 10px 10px;
    border-top-color: transparent;
    border-left-color: transparent;
    border-bottom-color: #fff;
    border-right-color: transparent;
    width: 0px;
    height: 0px;
    margin: 1px -10px -9px;
}

.active .caret {
    transform: rotate(90deg);
    left: -4px;
}
*/

.caret {
    display: inline-block;
    position: absolute;
    top: 30%;
    left: -30px;
    width: 60px;
    height: 60px;
    background: #fff;
    border-top: 1px solid #CCC;
    border-left: 1px solid #CCC;
    transition: all .3s ease-in-out;
    text-decoration: none;
    color: transparent;
    cursor: pointer;
    z-index: 1;
    transform: rotate(-45deg);
}

.caret:after {
    content: "+";
    color: #CCC;
    display: inline-block;
    transform: rotate(45deg);
    width: 18px;
    height: 50px;
    line-height: 25px;
}

.active .caret {
    left: -30px;
    transform: rotate(135deg);
}

.active .caret:after {
    content: "–";
}

JavaScript

var slideout = document.querySelector('.slideout')

var handle = slideout.querySelector('.caret')

handle.onclick = function() {
  slideout.classList.toggle('active');
}