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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<script>
import { GlSafeHtmlDirective, GlLink } from '@gitlab/ui';
import { __ } from '~/locale';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
import ActionButtons from '../action_buttons.vue';
import { EXTENSION_ICONS } from '../../constants';
import { generateText } from '../extensions/utils';
import StatusIcon from './status_icon.vue';
export default {
components: {
StatusIcon,
HelpPopover,
GlLink,
ActionButtons,
},
directives: {
SafeHtml: GlSafeHtmlDirective,
},
props: {
level: {
type: Number,
required: true,
validator: (value) => value === 2 || value === 3,
},
statusIconName: {
type: String,
required: false,
default: '',
validator: (value) => value === '' || Object.keys(EXTENSION_ICONS).includes(value),
},
widgetName: {
type: String,
required: true,
},
header: {
type: [String, Array],
required: false,
default: '',
},
/**
* @typedef {Object} helpPopover
* @property {Object} options
* @property {String} options.title
* @property {Object} content
* @property {String} content.text
* @property {String} content.learnMorePath
*/
helpPopover: {
type: Object,
required: false,
default: null,
},
actionButtons: {
type: Array,
required: false,
default: () => [],
},
},
computed: {
generatedHeader() {
return generateText(Array.isArray(this.header) ? this.header[0] : this.header);
},
generatedSubheader() {
return Array.isArray(this.header) && this.header[1] ? generateText(this.header[1]) : '';
},
shouldShowHeaderActions() {
return Boolean(this.helpPopover) || this.actionButtons?.length > 0;
},
},
i18n: {
learnMore: __('Learn more'),
},
};
</script>
<template>
<div
class="gl-w-full gl-display-flex mr-widget-content-row gl-align-items-baseline"
:class="{ 'gl-border-t gl-py-3 gl-pl-7': level === 2 }"
>
<status-icon v-if="statusIconName" :level="2" :name="widgetName" :icon-name="statusIconName" />
<div class="gl-w-full">
<div class="gl-display-flex">
<slot name="header">
<div v-if="header" class="gl-mb-2">
<strong v-safe-html="generatedHeader" class="gl-display-block"></strong
><span
v-if="generatedSubheader"
v-safe-html="generatedSubheader"
class="gl-display-block"
></span>
</div>
</slot>
<div
v-if="shouldShowHeaderActions"
class="gl-ml-auto gl-display-flex gl-align-items-baseline"
>
<help-popover v-if="helpPopover" :options="helpPopover.options">
<template v-if="helpPopover.content">
<p
v-if="helpPopover.content.text"
v-safe-html="helpPopover.content.text"
class="gl-mb-0"
></p>
<gl-link
v-if="helpPopover.content.learnMorePath"
:href="helpPopover.content.learnMorePath"
target="_blank"
class="gl-font-sm"
>{{ $options.i18n.learnMore }}</gl-link
>
</template>
</help-popover>
<action-buttons
v-if="actionButtons.length > 0"
:widget="widgetName"
:tertiary-buttons="actionButtons"
:class="{ 'gl-ml-2': helpPopover }"
/>
</div>
</div>
<div class="gl-display-flex gl-align-items-baseline gl-w-full">
<slot name="body"></slot>
</div>
</div>
</div>
</template>
|