-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnotice.vue
More file actions
193 lines (177 loc) · 4.47 KB
/
notice.vue
File metadata and controls
193 lines (177 loc) · 4.47 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
<template>
<aside
:class="noticeClass"
data-qa="notice"
>
<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"
:role="role"
>
<template #title>
<!-- @slot Slot for the title -->
<slot name="title" />
</template>
<!-- @slot the main textual content of the notice -->
<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>
</aside>
</template>
<script>
import DtNoticeIcon from './notice_icon.vue';
import DtNoticeContent from './notice_content.vue';
import DtNoticeAction from './notice_action.vue';
import { NOTICE_KINDS, NOTICE_ROLES } from './notice_constants';
/**
* A notice is an informational and assistive message that appears inline with content.
* @see https://dialtone.dialpad.com/components/notice.html
*/
export default {
compatConfig: { MODE: 3 },
name: 'DtNotice',
components: {
DtNoticeIcon,
DtNoticeContent,
DtNoticeAction,
},
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: undefined,
},
/**
* 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: undefined,
},
/**
* Title header of the notice. This can be left blank to remove the title from the notice entirely.
*/
title: {
type: String,
default: '',
},
/**
* Provides a role for the notice. 'status' is used to communicate a message. 'alert' is used to communicate an
* important message that does not contain any interactive elements. 'alertdialog' is used to communicate an
* important message that does contain interactive elements.
* @values alert, alertdialog, status
*/
role: {
type: String,
default: 'status',
validate (role) {
return NOTICE_ROLES.includes(role);
},
},
/**
* Used in scenarios where the message needs to visually dominate the screen.
* This will also change the aria role from status to alert.
* @values true, false
*/
important: {
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,
},
/**
* Truncates the content instead of wrapping.
* Used when the notice needs to have a fixed height.
* @values true, false
*/
truncateText: {
type: Boolean,
default: false,
},
},
emits: [
/**
* Close button click event
*
* @event close
*/
'close',
/**
* Native button click event
*
* @event click
* @type {PointerEvent | KeyboardEvent}
*/
'click',
],
computed: {
noticeClass () {
const noticeKinds = {
critical: 'd-notice--critical',
info: 'd-notice--info',
positive: 'd-notice--positive',
warning: 'd-notice--warning',
base: 'd-notice--base',
};
return [
'd-notice',
noticeKinds[this.kind],
{ 'd-notice--important': this.important, 'd-notice--truncate': this.truncateText },
];
},
},
};
</script>