Skip to content

Instantly share code, notes, and snippets.

@kgsnipes
Created May 26, 2023 12:54
Show Gist options
  • Save kgsnipes/fa91f01aa2962781b9ecdf6aaa9c4ebc to your computer and use it in GitHub Desktop.
Save kgsnipes/fa91f01aa2962781b9ecdf6aaa9c4ebc to your computer and use it in GitHub Desktop.
Template pills demo
function init()
{
document.querySelectorAll(".placeholderbtn").forEach(function(item){
item.addEventListener("click",function(e){
if(e.target.getAttribute("data")=="text")
{
let div=document.createElement('div')
div.classList.add("template_pill_text");
div.contentEditable=true
div.innerText="some text"
document.getElementById("template").appendChild(div)
}
else{
let div=document.createElement('div')
div.classList.add("template_pill");
div.innerText=e.target.getAttribute("data")
document.getElementById("template").appendChild(div)
}
})
})
}
init()
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<style>
.pill
{
height:50px;
}
.template_pill
{
height:50px;
background-color: greenyellow;
color: black;
width:fit-content;
float: left;
padding-right: 5px;
}
.template_pill_text
{
height:50px;
width:fit-content;
float: left;
padding-right: 5px;
}
#template
{
width:50%;
height: 500px;
border-width: 1px;
border-color: black;
border-style: solid;
overflow: auto;
}
</style>
</head>
<body>
<h1>Pills demo</h1>
<div id="constructs">
<button class="placeholderbtn pill" data="text">T</button>
<button class="placeholderbtn pill" data="$product.name">product.name</button>
<button class="placeholderbtn pill" data="$product.id">product.id</button>
<button class="placeholderbtn pill" data="$product.weight">product.attr['weight']</button>
<button class="placeholderbtn pill" data="$product.height">product.attr['height']</button>
<button class="placeholderbtn pill" data="$product.color">product.attr['color']</button>
<button class="placeholderbtn pill" data="$product.volume">product.attr['volume']</button>
</div>
<div id="template">
</div>
<script src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment