summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/runner/components/helpers/masked_value.vue
blob: feccb37de81d3a9a2afde9b70422f92122dba8ca (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 { GlButton } from '@gitlab/ui';
import { __ } from '~/locale';

export default {
  components: {
    GlButton,
  },
  props: {
    value: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      isMasked: true,
    };
  },
  computed: {
    label() {
      if (this.isMasked) {
        return __('Click to reveal');
      }
      return __('Click to hide');
    },
    icon() {
      if (this.isMasked) {
        return 'eye';
      }
      return 'eye-slash';
    },
    displayedValue() {
      if (this.isMasked && this.value?.length) {
        return '*'.repeat(this.value.length);
      }
      return this.value;
    },
  },
  methods: {
    toggleMasked() {
      this.isMasked = !this.isMasked;
    },
  },
};
</script>
<template>
  <span
    >{{ displayedValue }}
    <gl-button
      :aria-label="label"
      :icon="icon"
      class="gl-text-body!"
      data-testid="toggle-masked"
      variant="link"
      @click="toggleMasked"
    />
  </span>
</template>