aboutsummaryrefslogtreecommitdiff
path: root/src/components/emoji-input/emoji-input.vue
blob: 956063055e2a989ff12963bdc4c5781628656091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template>
  <div class="emoji-input">
    <input
      class="form-control"
      :type="type"
      :value="value"
      :placeholder="placeholder"
      @input="onInput"
      @click="setCaret"
      @keyup="setCaret"
      @keydown="onKeydown"
      @keydown.down="cycleForward"
      @keydown.up="cycleBackward"
      @keydown.shift.tab="cycleBackward"
      @keydown.tab="cycleForward"
      @keydown.enter="replaceEmoji"
    />
    <div class="autocomplete-panel" v-if="suggestions">
      <div class="autocomplete-panel-body">
        <div
          v-for="(emoji, index) in suggestions"
          :key="index"
          @click="replace(emoji.utf || (emoji.shortcode + ' '))"
          class="autocomplete-item"
          :class="{ highlighted: emoji.highlighted }"
        >
          <span v-if="emoji.img">
            <img :src="emoji.img" />
          </span>
          <span v-else>{{emoji.utf}}</span>
          <span>{{emoji.shortcode}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script src="./emoji-input.js"></script>

<style lang="scss">
@import '../../_variables.scss';

.emoji-input {
  .form-control {
    width: 100%;
  }
}

.autocomplete {
  &-panel {
    position: relative;

    &-body {
      margin: 0 0.5em 0 0.5em;
      border-radius: $fallback--tooltipRadius;
      border-radius: var(--tooltipRadius, $fallback--tooltipRadius);
      position: absolute;
      z-index: 1;
      box-shadow: 1px 2px 4px rgba(0, 0, 0, 0.5);
      // this doesn't match original but i don't care, making it uniform.
      box-shadow: var(--popupShadow);
      min-width: 75%;
      background: $fallback--bg;
      background: var(--bg, $fallback--bg);
      color: $fallback--lightText;
      color: var(--lightText, $fallback--lightText);
    }
  }

  &-item {
    cursor: pointer;
    padding: 0.2em 0.4em 0.2em 0.4em;
    border-bottom: 1px solid rgba(0, 0, 0, 0.4);
    display: flex;

    img {
      width: 24px;
      height: 24px;
      object-fit: contain;
    }

    span {
      line-height: 24px;
      margin: 0 0.1em 0 0.2em;
    }

    small {
      margin-left: .5em;
      color: $fallback--faint;
      color: var(--faint, $fallback--faint);
    }

    &.highlighted {
      background-color: $fallback--fg;
      background-color: var(--lightBg, $fallback--fg);
    }
  }
}
</style>