-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtoast_layout_default.vue
More file actions
191 lines (172 loc) · 4.35 KB
/
toast_layout_default.vue
File metadata and controls
191 lines (172 loc) · 4.35 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
<template>
<div
v-if="isShown"
:class="[
'd-toast',
kindClass,
$attrs.class,
{ 'd-toast--important': important },
]"
data-qa="dt-toast"
:aria-hidden="(!isShown).toString()"
>
<div class="d-toast__dialog">
<dt-notice-icon
v-if="!hideIcon"
:kind="kind"
:class="{ 'd-notice__icon--has-title': title || $slots.title }"
v-bind="toastListeners"
>
<!-- @slot Slot for custom icon -->
<slot name="icon" />
</dt-notice-icon>
<dt-notice-content
:title-id="titleId"
:content-id="contentId"
:title="title"
:role="role"
v-bind="toastListeners"
>
<template #title>
<!-- @slot Slot for the title -->
<slot name="title" />
</template>
<!-- @slot the main textual content of the toast -->
<slot>
{{ message }}
</slot>
</dt-notice-content>
<dt-notice-action
:hide-action="hideAction"
:hide-close="hideClose"
v-bind="toastListeners"
@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>
</div>
</template>
<script>
import utils from '@/common/utils';
import { DtNoticeIcon, DtNoticeContent, DtNoticeAction, NOTICE_KINDS } from '@/components/notice';
import { TOAST_ROLES } from '../toast_constants.js';
import { extractVueListeners } from '@/common/utils/index.js';
export default {
name: 'ToastLayoutDefault',
components: {
DtNoticeIcon,
DtNoticeContent,
DtNoticeAction,
},
inheritAttrs: false,
props: {
isShown: {
type: Boolean,
default: false,
},
/**
* 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 toast. This can be left blank to remove the title from the toast entirely.
*/
title: {
type: String,
default: '',
},
/**
* Message of the toast. Overridden by default slot.
*/
message: {
type: String,
default: '',
},
/**
* Provides a role for the toast. 'status' is used by default to communicate a message. 'alert' is used to
* communicate an important message like an error that does not contain any interactive elements.
* @values status, alert
*/
role: {
type: String,
default: 'status',
validator: (role) => {
return TOAST_ROLES.includes(role);
},
},
/**
* Severity level of the toast, sets the icon and background
* @values base, critical, info, positive, warning
*/
kind: {
type: String,
default: 'base',
validator: (kind) => {
return NOTICE_KINDS.includes(kind);
},
},
/**
* Used in scenarios where the message needs to visually dominate the screen.
* @values true, false
*/
important: {
type: Boolean,
default: false,
},
/**
* Hides the close button from the toast
* @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,
},
},
emits: ['close'],
computed: {
kindClass () {
const kindClasses = {
critical: 'd-toast--critical',
info: 'd-toast--info',
positive: 'd-toast--positive',
warning: 'd-toast--warning',
base: 'd-toast--base',
};
return kindClasses[this.kind];
},
toastListeners () {
return extractVueListeners(this.$attrs);
},
},
};
</script>