JSFiddle - React, Tailwind, and code Playground

by giovanni gokhan morkoc

HTML

<div class="dialog-panel">
  <span class="dialog-panel-postEdit-list--option edit">edit</span>
  <span class="save">save</span>
  <div class="dialog-panel--postContent text">
    I am working hard, really hard. May god hopefully will let me succeed with all of my efforts and i believe my sleepless nights will pay off! <a href="/Home/Search?search=Experiance">#Experiance</a> <a href="/Home/Search?search=Truth">#Truth</a>
  </div>
</div>

CSS

.dialog-panel {
  position: relative;
  margin: 20px;
  padding: 30px 10px 5px;
  width: 400px;
  min-height: 150px;
  border: 1px solid grey;
  border-radius: 3px;
  background: #fff;
}

.editable {
  border-color: #bd0f18;
  box-shadow: inset 0 0 10px #555;
  background: #f2f2f2;
}

.dialog-panel--postContent {
  outline: none;
}

.edit,
.save {
  width: 30px;
  display: block;
  position: absolute;
  top: 0px;
  right: 0px;
  padding: 4px 10px;
  border-top-right-radius: 2px;
  border-bottom-left-radius: 10px;
  text-align: center;
  cursor: pointer;
  box-shadow: -1px 1px 4px rgba(0, 0, 0, 0.5);
}

.edit {
  background: blue;
  color: #f0f0f0;
  opacity: 0;
  transition: opacity .2s ease-in-out;
}

.save {
  display: none;
  background: red;
  color: #f0f0f0;
}

.dialog-panel:hover .edit {
  opacity: 1;
}

JavaScript

$('.edit').click(function() {
  $(this).hide();
  $('.dialog-panel').addClass('editable');
  $('.dialog-panel--postContent').attr('contenteditable', 'true');
  $('.save').show();
});

$('.save').click(function() {
  $(this).hide();
  $('.dialog-panel').removeClass('editable');
  $('.dialog-panel--postContent').removeAttr('contenteditable');
  $('.edit').show();
});