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

copyable_field.vue « sidebar « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbc7e6e7a6e486d62aef6ccb4cb05cf36887225d (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
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { s__, __, sprintf } from '~/locale';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';

/**
 * Renders an inline field, whose value can be copied to the clipboard,
 * for use in the GitLab sidebar (issues, MRs, etc.).
 */
export default {
  name: 'CopyableField',
  components: {
    GlLoadingIcon,
    ClipboardButton,
  },
  props: {
    value: {
      type: String,
      required: true,
    },
    name: {
      type: String,
      required: true,
    },
    isLoading: {
      type: Boolean,
      required: false,
      default: false,
    },
    clipboardTooltipText: {
      type: String,
      required: false,
      default: undefined,
    },
  },
  computed: {
    clipboardProps() {
      return {
        category: 'tertiary',
        tooltipBoundary: 'viewport',
        tooltipPlacement: 'left',
        text: this.value,
        title:
          this.clipboardTooltipText ||
          sprintf(this.$options.i18n.clipboardTooltip, { name: this.name }),
      };
    },
    loadingIconLabel() {
      return sprintf(this.$options.i18n.loadingIconLabel, { name: this.name });
    },
    templateText() {
      return sprintf(this.$options.i18n.templateText, {
        name: this.name,
        value: this.value,
      });
    },
  },
  i18n: {
    loadingIconLabel: __('Loading %{name}'),
    clipboardTooltip: __('Copy %{name}'),
    templateText: s__('Sidebar|%{name}: %{value}'),
  },
};
</script>

<template>
  <div>
    <clipboard-button
      v-if="!isLoading"
      css-class="sidebar-collapsed-icon dont-change-state gl-rounded-0! gl-hover-bg-transparent"
      v-bind="clipboardProps"
    />

    <div
      class="gl-display-flex gl-align-items-center gl-justify-content-space-between hide-collapsed"
    >
      <span
        class="gl-overflow-hidden gl-text-overflow-ellipsis gl-white-space-nowrap"
        :title="value"
      >
        {{ templateText }}
      </span>

      <gl-loading-icon v-if="isLoading" inline :label="loadingIconLabel" />
      <clipboard-button v-else size="small" v-bind="clipboardProps" />
    </div>
  </div>
</template>