-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathslds-button-icon.vue
157 lines (121 loc) · 4.02 KB
/
slds-button-icon.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
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
<template>
<button
:class="buttonClassNames"
:disabled="disabled"
:title="title"
:type="type"
@click="onClick"
>
<!-- Button icon -->
<slds-svg :class="iconClassNames" :icon="iconName"/>
<!-- Dropdown icon -->
<slds-svg
v-if="hasDropdown && !bare"
class="slds-button__icon slds-button__icon_x-small"
icon="utility:down"
/>
<!-- Assistive text -->
<span v-if="assistiveText" class="slds-assistive-text">
{{ assistiveText }}
</span>
</button>
</template>
<script lang="ts">
import SldsSvg from "../slds-svg/slds-svg.vue"
import { defineComponent } from "vue"
export default defineComponent({
name: "SldsButtonIcon",
components: {
SldsSvg,
},
props: {
/**
* Icon assistive text.
*/
assistiveText: String,
bare: Boolean,
bordered: Boolean,
borderedFilled: Boolean,
borderedInverse: Boolean,
/**
* Indicates whether the button has the brand theme.
*/
brand: Boolean,
/**
* Indicates whether the button is disabled.
*/
disabled: Boolean,
error: Boolean,
hasDropdown: Boolean,
iconClass: String,
/**
* The Lightning Design System name of the icon.
* Names are written in the format 'utility:down' where 'utility' is the category, and 'down' is the specific icon to be displayed.
*/
iconName: { type: String, required: true },
inverse: Boolean,
large: Boolean,
small: Boolean,
title: String,
/**
* Button type.
*/
type: { type: String, default: "button" },
xSmall: Boolean,
xxSmall: Boolean,
},
computed: {
/**
* The CSS class names for the button.
*/
buttonClassNames(): string {
let classNames = "slds-button slds-button_icon"
// Disabled
if (!this.disabled) classNames += " slds-has-animation"
// Button theme
if (this.brand) classNames += " slds-button_icon-brand"
else if (this.inverse) classNames += " slds-button_icon-inverse"
else if (this.error) classNames += " slds-button_icon-error"
// Container type
if (this.bordered) classNames += " slds-button_icon-border"
else if (this.borderedFilled) classNames += " slds-button_icon-border-filled"
else if (this.borderedInverse) classNames += " slds-button_icon-border-inverse"
else if (!this.bare) classNames += " slds-button_icon-container"
// Size
if (!this.bare) {
if (this.xxSmall) classNames += " slds-button_icon-xx-small"
else if (this.xSmall) classNames += " slds-button_icon-x-small"
else if (this.small) classNames += " slds-button_icon-small"
else if (this.large) classNames += " slds-button_icon-large"
}
// Overflow
if (this.hasDropdown && !this.bare) classNames += " slds-button_icon-container-more"
return classNames
},
/**
* The CSS class names for the icon element.
*/
iconClassNames(): string {
let classNames = `slds-button__icon ${this.iconClass || ""}`
// Size
if (this.bare) {
if (this.xSmall) classNames += " slds-button__icon_x-small"
if (this.small) classNames += " slds-button__icon_small"
if (this.large) classNames += " slds-button__icon_large"
}
return classNames
},
},
methods: {
/**
* Handles the click event on the button.
* @param event The fired event.
*/
onClick(event: Event): void {
if (this.disabled) {
event.preventDefault()
}
},
},
})
</script>