JSFiddle - React, Tailwind, and code Playground
by Josh Pullen
HTML
<div id="button-container">
<a id="newFileButton">+</a>
</div>
<div id="newFilePopup">
<h2>
New file
</h2>
<div class="content">
Pick a file type:
<div id="buttons">
<div class="fileTypeButton checked">HTML</div>
<div class="fileTypeButton">CSS</div>
<div class="fileTypeButton">JavaScript</div>
</div>
Pick a name:
<div id="fileNameContainer">
<div id="fileNameSpoof">
<span id="fileNameSpoofText">untitled</span><span id="dot">.html</span>
</div>
<input type="text" id="fileName" value="untitled"/>
</div>
</div>
<div class = "footer">
<div class="footer-button" id="closeFileName">Close</div>
<div class="footer-button" id="createFileName">Create</div>
</div>
</div>
CSS
@import url(https://fonts.googleapis.com/css?family=Raleway:400,700);
body {
font-family: "Open Sans", sans-serif;
}
h2 {
font-family: Raleway;
}
#button-container {
width: 100%;
height: 100%;
display:flex;
justify-content:center;
align-items:center;
}
#newFileButton {
font-size: 30px;
font-weight: 100;
color: gray;
border: 1px solid gray;
margin: 10px 10px 10px 10px;
padding: 10px 20px 10px 20px;
border-radius: 5px;
cursor:pointer;
}
#newFileButton:hover {
background-color: lightgray;
}
#newFilePopup {
margin: auto;
width: 500px;
border: 1px solid #42ba92;
border-radius: 5px;
padding: 10px;
background-color: #42ba92;
color: white;
text-align: center;
display: none;
}
#buttons {
display:flex;
justify-content: center;
align-content: center;
}
.fileTypeButton {
display: inline-block;
width: 100px;
height: 100px;
margin: 10px;
padding: 10px;
border: 1px solid coral;
border-radius: 5px;
font-size: 16px;
line-height: 100px;
text-align: center;
background-color: coral;
cursor: pointer;
}
.fileTypeButton:hover {
opacity: .9;
}
.fileTypeButton.checked {
box-shadow: inset 0 0 0 5px white;
}
#fileNameContainer {
display: block;
width: 100%;
height: 1.5em;
font-size: 12pt;
position: relative;
}
#fileName, #fileNameSpoof {
text-align: left;
background: white;
appearance: none;
box-sizing: border-box;
font-size: 12pt;
border-radius: 5px;
border: 1px solid coral;
font-family: "Open Sans", sans-serif;
width: 100%;
color: black;
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
padding: 2px;
}
#fileName {
background: transparent;
}
#dot {
color: gray;
}
.content {
margin-bottom: 10px;
}
.footer {
background: rgba(0, 0, 0, 0.1);
padding: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px
}
.footer-button {
border: 1px solid coral;
border-radius: 5px;
display: inline-block;
background-color: coral;
...
JavaScript
document.getElementById("newFileButton").addEventListener("click", function() {
document.getElementById("newFilePopup").style.display = "block";
});
var checkedFileType = 0;
var fileTypeExtensions = [".html", ".css", ".js"]
var fileTypeButtons = document.getElementsByClassName("fileTypeButton");
for(let i = 0; i < fileTypeButtons.length; i++) {
fileTypeButtons[i].addEventListener("click", function() {
checkedFileType = i;
for(let j = 0; j < fileTypeButtons.length; j++) {
fileTypeButtons[j].classList.remove("checked");
}
fileTypeButtons[checkedFileType].classList.add("checked");
document.getElementById("dot").innerHTML = fileTypeExtensions[checkedFileType];
});
}
document.getElementById("fileName").addEventListener("input", function() {
document.getElementById("fileNameSpoofText").innerHTML = this.value;
});
document.getElementById("closeFileName").addEventListener("click", function() {
document.getElementById("newFilePopup").style.display = "none";
});
document.getElementById("createFileName").addEventListener("click", function() {
document.getElementById("newFilePopup").style.display = "none";
alert("file created!");
});