-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbanner.vue
More file actions
238 lines (214 loc) · 5.38 KB
/
banner.vue
File metadata and controls
238 lines (214 loc) · 5.38 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!-- eslint-disable vuejs-accessibility/no-static-element-interactions -->
<template>
<aside
:class="bannerClass"
:style="bannerBackgroundImage"
@keydown.tab="trapFocus"
>
<div
class="d-banner__dialog"
:class="dialogClass"
:role="role"
:aria-labelledby="titleId"
:aria-describedby="contentId"
>
<dt-notice-icon
v-if="!hideIcon"
:kind="kind"
:class="{ 'd-notice__icon--has-title': title || $slots.title }"
>
<!-- @slot Slot for custom icon -->
<slot name="icon" />
</dt-notice-icon>
<dt-notice-content
:title-id="titleId"
:content-id="contentId"
:title="title"
>
<template #title>
<!-- @slot Slot for the title -->
<slot name="title" />
</template>
<!-- @slot the main textual content of the banner -->
<slot />
</dt-notice-content>
<dt-notice-action
:hide-action="hideAction"
:hide-close="hideClose"
@close="$emit('close')"
>
<!-- @slot Enter a possible action for the user to take, such as a link to another page -->
<slot name="action" />
</dt-notice-action>
</div>
</aside>
</template>
<script>
import { DtNoticeIcon, DtNoticeContent, DtNoticeAction, NOTICE_KINDS } from '@/components/notice';
import Modal from '@/common/mixins/modal';
import utils from '@/common/utils';
/**
* Banners are a type of notice, delivering system and engagement messaging.
* These are highly intrusive notices and should be used sparingly and appropriately.
* @see https://dialtone.dialpad.com/components/banner.html
*/
export default {
compatConfig: { MODE: 3 },
name: 'DtBanner',
components: {
DtNoticeIcon,
DtNoticeContent,
DtNoticeAction,
},
mixins: [Modal],
props: {
/**
* Sets an ID on the title element of the component. Useful for aria-describedby
* or aria-labelledby or any other reason you may need an id to refer to the title.
*/
titleId: {
type: String,
default () { return utils.getUniqueString(); },
},
/**
* Sets an ID on the content element of the component. Useful for aria-describedby
* or aria-labelledby or any other reason you may need an id to refer to the content.
*/
contentId: {
type: String,
default () { return utils.getUniqueString(); },
},
/**
* Title header of the notice. This can be left blank to remove the title from the notice entirely.
*/
title: {
type: String,
default: '',
},
/**
* Used in scenarios where the message needs to visually dominate the screen.
* This will also change the aria role from status to alertdialog.
* and will modally trap the keyboard focus in the dialog as soon as it displays.
* @values true, false
*/
important: {
type: Boolean,
default: false,
},
/**
* Pins the banner to the top of the window and pushes all app content down.
* @values true, false
*/
pinned: {
type: Boolean,
default: false,
},
/**
* Severity level of the notice, sets the icon and background
* @values base, critical, info, positive, warning
*/
kind: {
type: String,
default: 'base',
validator (kind) {
return NOTICE_KINDS.includes(kind);
},
},
/**
* Hides the close button from the notice
* @values true, false
*/
hideClose: {
type: Boolean,
default: false,
},
/**
* Hides the icon from the notice
* @values true, false
*/
hideIcon: {
type: Boolean,
default: false,
},
/**
* Hides the action from the notice
* @values true, false
*/
hideAction: {
type: Boolean,
default: false,
},
/**
* Inner dialog class
*/
dialogClass: {
type: String,
default: '',
},
/**
* Banner background image
*/
backgroundImage: {
type: String,
default: '',
},
/**
* Background image size, follows the background-size CSS property values
* <a class="d-link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-size" target="_blank">
* CSS background-sizes
* </a>
*/
backgroundSize: {
type: String,
default: 'cover',
},
},
emits: [
/**
* Close button click event
*
* @event close
*/
'close',
],
computed: {
role () {
return this.important ? 'alertdialog' : 'status';
},
bannerClass () {
const kindClasses = {
critical: 'd-banner--critical',
info: 'd-banner--info',
positive: 'd-banner--positive',
warning: 'd-banner--warning',
base: 'd-banner--base',
};
return [
'd-banner',
kindClasses[this.kind],
{
'd-banner--important': this.important,
'd-banner--pinned': this.pinned,
},
];
},
bannerBackgroundImage () {
if (this.backgroundImage === '') return null;
return `background-image: url(${this.backgroundImage});
background-size: ${this.backgroundSize};`;
},
},
mounted () {
if (this.important) {
this.focusFirstElement();
}
},
methods: {
trapFocus (e) {
if (this.important) {
this.focusTrappedTabPress(e);
}
},
},
};
</script>