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