19
19
@click =" handleClick"
20
20
@contextmenu =" $emit('rightClick', $event)"
21
21
>
22
- <span
23
- v-if =" !isIconButton"
24
- class =" label"
25
- >
26
- {{ labelInternal }}
22
+ <span class =" label" >
23
+ <slot :state =" labelState" >
24
+ <span
25
+ v-if =" !isIconButton"
26
+ class =" default-label"
27
+ >
28
+ <template v-if =" labelState === ' idle' " >
29
+ {{ label }}
30
+ </template >
31
+ <template v-else-if =" labelState === ' confirm' " >
32
+ {{ shortConfirmationMessage ? 'Confirm?' : 'Are you sure?' }}
33
+ </template >
34
+ <template v-else-if =" labelState === ' error' " >
35
+ Error!
36
+ </template >
37
+ <template v-else-if =" labelState === ' loading' " >
38
+ Loading...
39
+ </template >
40
+ <template v-else-if =" labelState === ' success' " >
41
+ {{ successMessage }}
42
+ </template >
43
+ </span >
44
+ <font-awesome-icon
45
+ v-else
46
+ :icon =" icon"
47
+ class =" icon"
48
+ fixed-width
49
+ />
50
+ </slot >
27
51
</span >
28
- <font-awesome-icon
29
- v-else
30
- :icon =" icon"
31
- class =" icon"
32
- fixed-width
33
- />
34
52
</component >
35
53
</template >
36
54
@@ -110,10 +128,6 @@ export default defineComponent({
110
128
emits: [ ' click' , ' rightClick' ],
111
129
112
130
setup(props , { emit }) {
113
- if (props .icon == null && isBlank (props .label )) {
114
- console .warn (' ipl-button requires an icon or label to be provided.' );
115
- }
116
-
117
131
const instance = getCurrentInstance ();
118
132
let resetTimeout: number | null = null ;
119
133
let confirmationResetTimeout: number | null = null ;
@@ -210,22 +224,13 @@ export default defineComponent({
210
224
buttonState ,
211
225
isIconButton: computed (() => props .icon != null ),
212
226
disabledInternal ,
213
- labelInternal : computed (() => {
227
+ labelState : computed < ' idle ' | ' error ' | ' success ' | ' loading ' | ' confirm ' > (() => {
214
228
if (props .requiresConfirmation && isClicked .value ) {
215
- return props .shortConfirmationMessage ? ' Confirm?' : ' Are you sure?' ;
216
- }
217
- if (! props .async && ! props .disableOnSuccess ) return props .label ;
218
-
219
- switch (buttonState .value ) {
220
- case ' error' :
221
- return ' Error!' ;
222
- case ' loading' :
223
- return props .progressMessage ;
224
- case ' success' :
225
- return props .successMessage ;
226
- default :
227
- return props .label ;
229
+ return ' confirm' ;
228
230
}
231
+ if (! props .async && ! props .disableOnSuccess ) return ' idle' ;
232
+
233
+ return buttonState .value ;
229
234
}),
230
235
isBlank ,
231
236
hasLink
@@ -239,7 +244,6 @@ export default defineComponent({
239
244
240
245
.ipl-button {
241
246
text-decoration : none !important ;
242
- text-transform : uppercase ;
243
247
font-size : 1em ;
244
248
font-weight : 700 ;
245
249
font-family : constants .$body-font ;
@@ -274,21 +278,29 @@ export default defineComponent({
274
278
width : 2.4em ;
275
279
min-width : 2.4em ;
276
280
padding : 0.4em ;
281
+
282
+ :deep (.icon ) {
283
+ height : 100% ;
284
+ width : 100% ;
285
+ }
277
286
}
278
287
279
288
& .small {
280
289
font-size : 0.75em ;
281
290
}
282
291
283
- .label , .icon {
292
+ .label , :deep( .icon ) {
284
293
z-index : 3 ;
285
294
position : relative ;
286
295
user-select : none ;
287
296
}
288
297
289
- .icon {
290
- height : 100% ;
291
- width : 100% ;
298
+ .default-label {
299
+ text-transform : uppercase ;
300
+ }
301
+
302
+ & .no-text-transform .default-label {
303
+ text-transform : none ;
292
304
}
293
305
294
306
& .disabled {
0 commit comments