<form class="search-form">
<input type="text" class="search" placeholder="Type in Emoji name/code"> <br/>
<ul class="results">
<li>Find an emoji</li>
</ul>
</form>
body {
box-sizing: border-box;
background: #2759c4; /* Old browsers */
background: -moz-linear-gradient(-45deg, #2759c4 0%, #2f94f9 100%, #7db9e8 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(-45deg, #2759c4 0%,#2f94f9 100%,#7db9e8 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(135deg, #2759c4 0%,#2f94f9 100%,#7db9e8 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
font-family:'helvetica neue';
height: 100vh;
overflow-y: scroll;
}
input {
width: 100%;
padding: 20px 0;
border-radius: 50px;
border: 0;
margin: 100px 0 50px 0;
}
input[placeholder] {
text-align: center;
text-transform: uppercase;
}
.search-form {
max-width: 450px;
margin: 0 auto;
}
.results {
margin: 0;
padding: 0;
position: relative;
}
.results li {
background:rgba(255, 255, 255, 0.3);
list-style: none;
width: 100%;
padding: 15px 0;
border-radius: 50px;
transition: background 0.2s;
display:flex;
justify-content:center;
text-transform: capitalize;
border: 1px solid #ccc;
margin: 10px 0;
display: none;
}
img{
width: 20px;
height: 20px;
padding: 0 10px;
}
.hl{
background: #F76565;
font-style: bold;
}
const endpoint =
"https://dl.dropboxusercontent.com/s/gcw5qo612ea63yb/emoji_new.json?dl=1";
const search = document.querySelector('.search');
const result = document.querySelector('.results');
let emojis = [];
fetch(endpoint)
.then(blob => blob.json())
.then(data => emojis.push(...data));
function find(query, emojis)
{
return emojis.filter(emoji => {
const regex = new RegExp(query, 'gi');
return emoji.name.match(regex);
})
}
function display()
{
const matchArr = find(this.value, emojis);
const diplayList = matchArr.map(emoji => {
const regex = new RegExp(this.value, 'gi');
console.log(regex);
const emojiTag = emoji.name.replace(regex, `<span class="hl">${this.value}</span>`)
return `
<li style="display: flex">
<span>[ ${emojiTag} ]</span>
<span><img src=${emoji.url}/></span>
</li>`
}).join('');
result.innerHTML = diplayList;
}
search.addEventListener("change", display);
search.addEventListener("keyup", display);
As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.
Also see: Tab Triggers