Skip to content

Commit

Permalink
Made the emoji picker function better
Browse files Browse the repository at this point in the history
  • Loading branch information
JostCrow committed Jun 13, 2022
1 parent f58922d commit 29459bb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n button_tags form_tags messages_tags %}
{% load i18n button_tags form_tags messages_tags icon_tags %}

<section class="messages">
<header class="messages__header">
Expand Down Expand Up @@ -48,7 +48,11 @@ <h4 class="p p--muted">{{ day.text }}</h4>
<div class="emoji">
{% button class="emoji__button" icon="tag_faces" text=_('Selecteer emoji') hide_text=True type="button" %}
<div class="emoji__popup">
<input class="emoji__search input" type="search">
<div class="emoji__header">
<input class="emoji__search input input--bordered" type="search" placeholder="{% trans "Zoek emoji" %}">
{% icon icon="close" %}
</div>
<div class="emoji__emojis"></div>
</div>
</div>
</div>
Expand Down
33 changes: 22 additions & 11 deletions src/open_inwoner/js/components/emoji-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class Emoji {
this.search = node.querySelector('.emoji__search')
this.button = node.querySelector('.emoji__button')
this.popup = node.querySelector('.emoji__popup')
this.container = node.querySelector('.emoji__emojis')
this.close = this.popup.querySelector('.material-icons')
this.populatePopup()
this.addListeners()
}

addListeners() {
this.button.addEventListener('click', (event) => {
event.preventDefault()
this.popup.classList.toggle('emoji__popup--open')
Expand All @@ -19,16 +25,21 @@ class Emoji {
this.popup.classList.remove('emoji__popup--open')
}
})
this.search.addEventListener('keyup', (event) => {
const searchValue = event.currentTarget.value.toUpperCase()
document.querySelectorAll('.emoji__emoji-button').forEach((button) => {
const label = button.dataset.label.toUpperCase()
if (label.includes(searchValue)) {
button.classList.remove('emoji__emoji-button--hidden')
} else {
button.classList.add('emoji__emoji-button--hidden')
}
})
this.close.addEventListener('click', (event) => {
this.popup.classList.remove('emoji__popup--open')
})
this.search.addEventListener('keyup', this.searchEmoji.bind(this))
}

searchEmoji(event) {
const searchValue = event.currentTarget.value.toUpperCase()
document.querySelectorAll('.emoji__emoji-button').forEach((button) => {
const label = button.dataset.label.toUpperCase()
if (label.includes(searchValue)) {
button.classList.remove('emoji__emoji-button--hidden')
} else {
button.classList.add('emoji__emoji-button--hidden')
}
})
}

Expand All @@ -42,7 +53,7 @@ class Emoji {
emojiButton.addEventListener('click', (event) => {
this.content.append(emoji.emoji)
})
this.popup.append(emojiButton)
this.container.append(emojiButton)
})
}
}
Expand Down
32 changes: 24 additions & 8 deletions src/open_inwoner/scss/components/Emoji/Emoji.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
.emoji {
&__button {
&__header {
display: grid;
grid-template-columns: 1fr 25px;
align-items: center;
padding: 8px 0 0 8px;
gap: 8px;
}

&__search {
grid-column: 1 / span 8;
// grid-column: 1 / span 8;
min-width: 0;
}

.material-icons {
cursor: pointer;
}

&__emoji-button {
Expand All @@ -16,17 +26,23 @@

&__popup {
display: none;
grid-template-columns: repeat(8, 1fr);
position: absolute;
max-height: 200px;
overflow: auto;
background-color: #fff;
padding: var(--spacing-medium);
border: 1px solid #000;
gap: var(--spacing-medium);
width: 260px;

&--open {
display: grid;
display: block;
}
}

&__emojis {
display: grid;
gap: var(--spacing-medium);
grid-template-columns: repeat(8, 1fr);
padding: var(--spacing-medium);
max-height: 200px;
overflow: auto;
text-align: center;
}
}
4 changes: 4 additions & 0 deletions src/open_inwoner/scss/components/Form/Input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
font-family: var(--font-family-body);
font-size: var(--font-size-body);
background-color: var(--color-white);

&.input--bordered {
border: 1px solid var(--color-mute);
}
}

textarea.input {
Expand Down
6 changes: 5 additions & 1 deletion src/open_inwoner/scss/components/Messages/_Messages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@
}

.message {
max-width: 50%;
max-width: 85%;
align-self: baseline;

@media (min-width: 768px) {
max-width: 50%;
}
}

.message--ours {
Expand Down

0 comments on commit 29459bb

Please sign in to comment.