JSFiddle - React, Tailwind, and code Playground
HTML
<div class="control-panel">
<span data-tag="b">B</span>
<span data-tag="i">I</span>
<span data-tag="p">P</span>
<span data-tag="blockquote">Q</span>
</div>
<textarea id="full_text" cols="30" rows="10"></textarea>
CSS
.control-panel {
margin: 15px 0;
}
.control-panel span {
display: inline-block;
width: 30px;
height: 30px;
border: 1px solid #036;
text-align: center;
line-height: 30px;
cursor: pointer;
}
JavaScript
$(function() {
var fullText = $('#full_text');
$('.control-panel span').on('click', function() {
var $that = $(this),
tag = $that.data('tag'),
caretPos = fullText.get(0).selectionStart,
text = fullText.val();
fullText.val(text.substring(0, caretPos) + '<' + tag + '></' + tag + '>' + text.substring(caretPos));
});
});