-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathslds-prompt.vue
122 lines (92 loc) · 3.18 KB
/
slds-prompt.vue
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
<template>
<div
ref="root"
tabindex="0"
@keyup.esc="handleClose"
@keyup.enter="handleSubmit"
>
<!-- Prompt -->
<transition appear :name="transitionName">
<section tabindex="-1" class="slds-modal slds-fade-in-open slds-modal_prompt">
<div class="slds-modal__container">
<!-- Header -->
<header :class="headerClassNames">
<slot name="header"/>
</header>
<!-- Content -->
<div class="slds-modal__content slds-p-around_medium">
<slot name="content"/>
</div>
<!-- Footer -->
<footer class="slds-modal__footer slds-theme_default">
<slds-button :label="buttonLabel" neutral @click="handleSubmit"/>
</footer>
</div>
</section>
</transition>
<!-- Backdrop -->
<div class="slds-backdrop slds-backdrop_open"/>
</div>
</template>
<script lang="ts">
import SldsButton from "../slds-button/slds-button.vue"
import { EVENTS } from "../../constants"
import { defineComponent } from "vue"
export default defineComponent({
name: "SldsPrompt",
components: { SldsButton },
props: {
alternativeInverseTheme: Boolean,
buttonLabel: { type: String, default: "Okay" },
errorTheme: Boolean,
hasTexture: Boolean,
infoTheme: Boolean,
inverseTheme: Boolean,
noAnimation: Boolean,
offlineTheme: Boolean,
shadeTheme: Boolean,
successTheme: Boolean,
warningTheme: Boolean,
},
computed: {
headerClassNames(): string {
let classNames = "slds-modal__header"
if (this.hasTexture) classNames += " slds-theme_alert-texture"
if (this.alternativeInverseTheme) classNames += " slds-theme_alt-inverse"
else if (this.errorTheme) classNames += " slds-theme_error"
else if (this.infoTheme) classNames += " slds-theme_info"
else if (this.inverseTheme) classNames += " slds-theme_inverse"
else if (this.offlineTheme) classNames += " slds-theme_offline"
else if (this.shadeTheme) classNames += " slds-theme_shade"
else if (this.successTheme) classNames += " slds-theme_success"
else if (this.warningTheme) classNames += " slds-theme_warning"
else classNames += " slds-theme_default"
return classNames
},
/**
* Transition name, if any.
*/
transitionName(): string {
return this.noAnimation ? "" : "blow-up"
},
},
mounted() {
const root = this.$refs.root as HTMLDivElement
root.focus()
},
methods: {
/**
* Handles the key up event on the esc key.
*/
handleClose(): void {
this.$emit(EVENTS.CLOSE)
},
/**
* Handles the key up event on the enter key.
*/
handleSubmit(): void {
this.$emit(EVENTS.SUBMIT)
},
},
})
</script>