Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gl_icon.vue « components « shared « frontend « content - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 73bd01241591a65a061b92e83e17451fe54ebe00 (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
<script>
import data from '@gitlab/svgs/dist/icons.json';
import { iconSizeOptions } from '../constants';

let iconValidator = () => true;

const { icons } = data;
iconValidator = (value) => {
  if (icons.includes(value)) {
    return true;
  }
  // eslint-disable-next-line no-console
  console.warn(`Icon '${value}' is not a known icon of @gitlab/svgs`);
  return false;
};

/** This is a re-usable vue component for rendering a svg sprite icon
 *  @example
 *  <icon
 *    name="retry"
 *    :size="32"
 *    class="top"
 *  />
 */
export default {
  props: {
    name: {
      type: String,
      required: true,
      validator: iconValidator,
    },
    size: {
      type: Number,
      required: false,
      default: 16,
      validator: (value) => iconSizeOptions.includes(value),
    },
    className: {
      type: String,
      required: false,
      default: '',
    },
  },

  computed: {
    iconSizeClass() {
      return this.size ? `s${this.size}` : '';
    },
    iconHref() {
      return `#${this.name}`;
    },
  },
};
</script>

<template>
  <svg :class="['gl-icon', iconSizeClass, className]">
    <use :href="iconHref" />
  </svg>
</template>