-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbanner.vue
More file actions
274 lines (246 loc) · 6.17 KB
/
banner.vue
File metadata and controls
274 lines (246 loc) · 6.17 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!-- 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="headerId"
:aria-describedby="contentId"
>
<dt-notice-icon
v-if="showIcon"
:kind="kind"
:icon-class="iconClass"
:class="{ 'd-notice__icon--has-title': headerText || $slots.header }"
>
<!-- @slot Slot for custom icon -->
<slot name="icon" />
</dt-notice-icon>
<dt-notice-content
:header-id="headerId"
:content-id="contentId"
:header-text="headerText"
:header-class="headerClass"
:content-class="contentClass"
>
<template #header>
<!-- @slot Slot for the header -->
<slot name="header" />
</template>
<!-- @slot the main textual content of the banner -->
<slot />
</dt-notice-content>
<dt-notice-action
:show-action="showAction"
:show-close="showClose"
:action-class="actionClass"
@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 header element of the component. Useful for aria-describedby
* or aria-labelledby or any other reason you may need an id to refer to the header.
*/
headerId: {
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(); },
},
/**
* Header text of the banner. This can be left blank to remove the header from the banner entirely.
*/
headerText: {
type: String,
default: undefined,
},
/**
* 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);
},
},
/**
* Shows the close button in the banner
* @values true, false
*/
showClose: {
type: Boolean,
default: true,
},
/**
* Shows the icon in the banner
* @values true, false
*/
showIcon: {
type: Boolean,
default: true,
},
/**
* Shows the action in the banner
* @values true, false
*/
showAction: {
type: Boolean,
default: true,
},
/**
* 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',
},
/**
* Additional class name for the icon wrapper element.
*/
iconClass: {
type: [String, Array, Object],
default: '',
},
/**
* Additional class name for the header wrapper element.
*/
headerClass: {
type: [String, Array, Object],
default: '',
},
/**
* Additional class name for the content wrapper element.
*/
contentClass: {
type: [String, Array, Object],
default: '',
},
/**
* Additional class name for the action wrapper element.
*/
actionClass: {
type: [String, Array, Object],
default: '',
},
},
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>