-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathslds-badge.vue
154 lines (125 loc) · 3.72 KB
/
slds-badge.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
<template>
<span :class="badgeClass">
<!-- Left Icon -->
<span v-if="hasLeftPositionedIcon" class="slds-badge__icon slds-badge__icon_left">
<slds-icon current-color :icon-name="iconName!" xx-small/>
</span>
<!-- Label -->
<slot>
{{ label }}
</slot>
<!-- Right Icon -->
<span v-if="hasRightPositionedIcon" class="slds-badge__icon slds-badge__icon_right">
<slds-icon current-color :icon-name="iconName!" xx-small/>
</span>
</span>
</template>
<script lang="ts">
import SldsIcon from "../slds-icon/slds-icon.vue"
import PositionableIconMixin from "../../mixins/positionable-icon-mixin.js"
import { defineComponent } from "vue"
export default defineComponent({
name: "SldsBadge",
components: {
SldsIcon,
},
mixins: [
PositionableIconMixin,
],
props: {
/**
* Indicates whether this badge has the brand theme.
*/
brand: Boolean,
/**
* Indicates whether this badge has the error theme.
*/
error: Boolean,
/**
* Indicates whether this badge has the inverse theme.
*/
inverse: Boolean,
/**
* Badge label.
* When using the default slot this prop is ignored.
*/
label: String,
/**
* Indicates whether this badge has the inverse theme.
*/
lightest: Boolean,
/**
Indicates whether this badge has the outline brand theme.
*/
outlineBrand: Boolean,
/**
Indicates whether this badge has the outline error theme.
*/
outlineError: Boolean,
/**
Indicates whether this badge has the outline success theme.
*/
outlineSuccess: Boolean,
/**
Indicates whether this badge has the outline warning theme.
*/
outlineWarning: Boolean,
/**
Indicates whether this badge has the success theme.
*/
success: Boolean,
/**
Indicates whether this badge has the warning theme.
*/
warning: Boolean,
},
computed: {
/**
* The CSS class names for the badge.
*/
badgeClass(): string {
let classNames = "slds-badge"
// Badge theme
if (this.brand) classNames += " slds-badge_brand"
else if (this.error) classNames += " slds-badge_error"
else if (this.inverse) classNames += " slds-badge_inverse"
else if (this.lightest) classNames += " slds-badge_lightest"
else if (this.outlineBrand) classNames += " slds-badge_outline-brand"
else if (this.outlineError) classNames += " slds-badge_outline-error"
else if (this.outlineSuccess) classNames += " slds-badge_outline-success"
else if (this.outlineWarning) classNames += " slds-badge_outline-warning"
else if (this.success) classNames += " slds-badge_success"
else if (this.warning) classNames += " slds-badge_warning"
return classNames
},
},
})
</script>
<style scoped lang="scss">
$colors: (
'brand': #0070d2,
'error': #ea001e,
'success': #2e844a,
'warning': #fe9339,
);
@each $name, $color in $colors {
.slds-badge_#{$name},
.slds-badge__icon_#{$name} {
color: white;
background-color: $color;
}
.slds-badge_outline-#{$name} {
border: 1px solid $color;
background-color: white;
color: $color;
padding: .125rem .5rem;
svg {
fill: $color;
}
}
}
.slds-badge_warning,
.slds-badge__icon_warning {
color: unset;
}
</style>