Fixed #2911 - New iconClass property for Button component

pull/2929/head
Tuğçe Küçükoğlu 2022-08-31 11:42:27 +03:00
parent 35291dfde6
commit 400cabe01f
4 changed files with 24 additions and 4 deletions

View File

@ -17,6 +17,12 @@ const ButtonProps = [
default: "left", default: "left",
description: 'Position of the icon, valid values are "left", "right", "bottom" and "top".' description: 'Position of the icon, valid values are "left", "right", "bottom" and "top".'
}, },
{
name: "iconClass",
type: "string",
default: "null",
description: "Style class of the icon."
},
{ {
name: "badge", name: "badge",
type: "string", type: "string",

View File

@ -25,6 +25,10 @@ export interface ButtonProps extends ButtonHTMLAttributes {
* Default value is 'left'. * Default value is 'left'.
*/ */
iconPos?: ButtonIconPosType; iconPos?: ButtonIconPosType;
/**
* Style class of the icon.
*/
iconClass?: string | undefined;
/** /**
* Value of the badge. * Value of the badge.
*/ */

View File

@ -1,8 +1,8 @@
<template> <template>
<button :class="buttonClass" type="button" :aria-label="defaultAriaLabel" v-ripple :disabled="disabled"> <button :class="buttonClass" type="button" :aria-label="defaultAriaLabel" v-ripple :disabled="disabled">
<slot> <slot>
<span v-if="loading && !icon" :class="iconClass"></span> <span v-if="loading && !icon" :class="iconStyleClass"></span>
<span v-if="icon" :class="iconClass"></span> <span v-if="icon" :class="iconStyleClass"></span>
<span class="p-button-label">{{label||'&nbsp;'}}</span> <span class="p-button-label">{{label||'&nbsp;'}}</span>
<span v-if="badge" :class="badgeStyleClass">{{badge}}</span> <span v-if="badge" :class="badgeStyleClass">{{badge}}</span>
</slot> </slot>
@ -25,6 +25,10 @@ export default {
type: String, type: String,
default: 'left' default: 'left'
}, },
iconClass: {
type: String,
default: null
},
badge: { badge: {
type: String type: String
}, },
@ -52,10 +56,10 @@ export default {
'p-button-loading-label-only': this.loading && !this.icon && this.label 'p-button-loading-label-only': this.loading && !this.icon && this.label
} }
}, },
iconClass() { iconStyleClass() {
return [ return [
this.loading ? 'p-button-loading-icon ' + this.loadingIcon : this.icon, this.loading ? 'p-button-loading-icon ' + this.loadingIcon : this.icon,
'p-button-icon', 'p-button-icon', this.iconClass,
{ {
'p-button-icon-left': this.iconPos === 'left' && this.label, 'p-button-icon-left': this.iconPos === 'left' && this.label,
'p-button-icon-right': this.iconPos === 'right' && this.label, 'p-button-icon-right': this.iconPos === 'right' && this.label,

View File

@ -177,6 +177,12 @@ import Button from 'primevue/button';
<td>left</td> <td>left</td>
<td>Position of the icon, valid values are "left", "right", "bottom" and "top".</td> <td>Position of the icon, valid values are "left", "right", "bottom" and "top".</td>
</tr> </tr>
<tr>
<td>iconClass</td>
<td>string</td>
<td>null</td>
<td>Style class of the icon.</td>
</tr>
<tr> <tr>
<td>badge</td> <td>badge</td>
<td>string</td> <td>string</td>