Refactor #3889 - For Button
parent
c9f6c31462
commit
bd48603c39
|
@ -94,6 +94,12 @@ const ButtonProps = [
|
|||
type: 'boolean',
|
||||
default: 'false',
|
||||
description: 'Add a plain textual class to the button without a background initially.'
|
||||
},
|
||||
{
|
||||
name: 'pt',
|
||||
type: 'any',
|
||||
default: 'null',
|
||||
description: 'Uses to pass attributes to DOM elements inside the component.'
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -10,6 +10,49 @@
|
|||
import { ButtonHTMLAttributes, VNode } from 'vue';
|
||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||
|
||||
export declare type ButtonPassThroughOptionType = ButtonPassThroughAttributes | ((options: ButtonPassThroughMethodOptions) => ButtonPassThroughAttributes) | null | undefined;
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) option method.
|
||||
*/
|
||||
export interface ButtonPassThroughMethodOptions {
|
||||
props: ButtonProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) options.
|
||||
* @see {@link ButtonProps.pt}
|
||||
*/
|
||||
export interface ButtonPassThroughOptions {
|
||||
/**
|
||||
* Uses to pass attributes to the root's DOM element.
|
||||
*/
|
||||
root?: ButtonPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the loading icon's DOM element.
|
||||
*/
|
||||
loadingIcon?: ButtonPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the icon's DOM element.
|
||||
*/
|
||||
icon?: ButtonPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the label's DOM element.
|
||||
*/
|
||||
label?: ButtonPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the badge's DOM element.
|
||||
*/
|
||||
badge?: ButtonPassThroughOptionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough attributes for each DOM elements
|
||||
*/
|
||||
export interface ButtonPassThroughAttributes {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines valid properties in Button component.
|
||||
*/
|
||||
|
@ -94,6 +137,11 @@ export interface ButtonProps extends ButtonHTMLAttributes {
|
|||
* @defaultValue false
|
||||
*/
|
||||
plain?: boolean | undefined;
|
||||
/**
|
||||
* Uses to pass attributes to DOM elements inside the component.
|
||||
* @type {ButtonPassThroughOptions}
|
||||
*/
|
||||
pt?: ButtonPassThroughOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
<template>
|
||||
<button v-ripple :class="buttonClass" type="button" :aria-label="defaultAriaLabel" :disabled="disabled">
|
||||
<button v-ripple :class="buttonClass" type="button" :aria-label="defaultAriaLabel" :disabled="disabled" v-bind="ptm('root')">
|
||||
<slot></slot>
|
||||
<template v-if="!$slots.default">
|
||||
<slot v-if="loading" name="loadingicon" :class="loadingIconStyleClass">
|
||||
<span v-if="loadingIcon" :class="[loadingIconStyleClass, loadingIcon]" />
|
||||
<SpinnerIcon v-else :class="loadingIconStyleClass" spin />
|
||||
<span v-if="loadingIcon" :class="[loadingIconStyleClass, loadingIcon]" v-bind="ptm('loadingIcon')" />
|
||||
<SpinnerIcon v-else :class="loadingIconStyleClass" spin v-bind="ptm('loadingIcon')" />
|
||||
</slot>
|
||||
<slot v-else name="icon" :class="iconStyleClass">
|
||||
<span v-if="icon" :class="[iconStyleClass, icon]"></span>
|
||||
<span v-if="icon" :class="[iconStyleClass, icon]" v-bind="ptm('icon')"></span>
|
||||
</slot>
|
||||
<span class="p-button-label">{{ label || ' ' }}</span>
|
||||
<span v-if="badge" :class="badgeStyleClass">{{ badge }}</span>
|
||||
<span class="p-button-label" v-bind="ptm('label')">{{ label || ' ' }}</span>
|
||||
<span v-if="badge" :class="badgeStyleClass" v-bind="ptm('badge')">{{ badge }}</span>
|
||||
</template>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
import SpinnerIcon from 'primevue/icons/spinner';
|
||||
import Ripple from 'primevue/ripple';
|
||||
|
||||
export default {
|
||||
name: 'Button',
|
||||
extends: BaseComponent,
|
||||
props: {
|
||||
label: {
|
||||
type: String,
|
||||
|
|
Loading…
Reference in New Issue