summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/groups/components/group_identicon.vue
blob: 0edd820743f4955edd3c4d7552016d5838ebc3e8 (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
<script>
export default {
  props: {
    entityId: {
      type: Number,
      required: true,
    },
    entityName: {
      type: String,
      required: true,
    },
  },
  computed: {
    /**
     * This method is based on app/helpers/application_helper.rb#project_identicon
     */
    identiconStyles() {
      const allowedColors = [
        '#FFEBEE',
        '#F3E5F5',
        '#E8EAF6',
        '#E3F2FD',
        '#E0F2F1',
        '#FBE9E7',
        '#EEEEEE',
      ];

      const backgroundColor = allowedColors[this.entityId % 7];

      return `background-color: ${backgroundColor}; color: #555;`;
    },
    identiconTitle() {
      return this.entityName.charAt(0).toUpperCase();
    },
  },
};
</script>

<template>
  <div
    class="avatar s40 identicon"
    :style="identiconStyles">
    {{identiconTitle}}
  </div>
</template>