Refactor #3879 - For Chip
parent
c50efe4bbf
commit
b228f30c52
|
@ -28,6 +28,12 @@ const ChipProps = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'pi pi-times-circle',
|
default: 'pi pi-times-circle',
|
||||||
description: 'Icon of the remove element.'
|
description: 'Icon of the remove element.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pt',
|
||||||
|
type: 'any',
|
||||||
|
default: 'null',
|
||||||
|
description: 'Uses to pass attributes to DOM elements inside the component.'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,61 @@
|
||||||
import { VNode } from 'vue';
|
import { VNode } from 'vue';
|
||||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||||
|
|
||||||
|
export declare type ChipPassThroughOptionType = ChipPassThroughAttributes | ((options: ChipPassThroughMethodOptions) => ChipPassThroughAttributes) | null | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) option method.
|
||||||
|
*/
|
||||||
|
export interface ChipPassThroughMethodOptions {
|
||||||
|
props: ChipProps;
|
||||||
|
state: ChipState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) options.
|
||||||
|
* @see {@link ChipProps.pt}
|
||||||
|
*/
|
||||||
|
export interface ChipPassThroughOptions {
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the root's DOM element.
|
||||||
|
*/
|
||||||
|
root?: ChipPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the image's DOM element.
|
||||||
|
*/
|
||||||
|
image?: ChipPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the icon's DOM element.
|
||||||
|
*/
|
||||||
|
icon?: ChipPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the label' DOM element.
|
||||||
|
*/
|
||||||
|
label?: ChipPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the removeIcon's DOM element.
|
||||||
|
*/
|
||||||
|
removeIcon?: ChipPassThroughOptionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough attributes for each DOM elements
|
||||||
|
*/
|
||||||
|
export interface ChipPassThroughAttributes {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines current inline state in Chip component.
|
||||||
|
*/
|
||||||
|
export interface ChipState {
|
||||||
|
/**
|
||||||
|
* Current visible state as a boolean.
|
||||||
|
* @defaultValue true
|
||||||
|
*/
|
||||||
|
visible: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines valid properties in Chip component.
|
* Defines valid properties in Chip component.
|
||||||
*/
|
*/
|
||||||
|
@ -37,6 +92,11 @@ export interface ChipProps {
|
||||||
* @deprecated since v3.27.0. Use 'removeicon' slot.
|
* @deprecated since v3.27.0. Use 'removeicon' slot.
|
||||||
*/
|
*/
|
||||||
removeIcon?: string;
|
removeIcon?: string;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to DOM elements inside the component.
|
||||||
|
* @type {ChipPassThroughOptions}
|
||||||
|
*/
|
||||||
|
pt?: ChipPassThroughOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-if="visible" :class="containerClass" :aria-label="label">
|
<div v-if="visible" :class="containerClass" :aria-label="label" v-bind="ptm('root')">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<template v-if="!$slots.default">
|
<template v-if="!$slots.default">
|
||||||
<img v-if="image" :src="image" />
|
<img v-if="image" :src="image" v-bind="ptm('image')" />
|
||||||
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-chip-icon" />
|
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-chip-icon" v-bind="ptm('icon')" />
|
||||||
<span v-else-if="icon" :class="['p-chip-icon', icon]" />
|
<span v-else-if="icon" :class="['p-chip-icon', icon]" v-bind="ptm('icon')" />
|
||||||
<div v-if="label" class="p-chip-text">{{ label }}</div>
|
<div v-if="label" class="p-chip-text" v-bind="ptm('label')">{{ label }}</div>
|
||||||
</template>
|
</template>
|
||||||
<slot v-if="removable" name="removeicon" :onClick="close" :onKeydown="onKeydown">
|
<slot v-if="removable" name="removeicon" :onClick="close" :onKeydown="onKeydown">
|
||||||
<component :is="removeIcon ? 'span' : 'TimesCircleIcon'" tabindex="0" :class="['p-chip-remove-icon', removeIcon]" @click="close" @keydown="onKeydown"></component>
|
<component :is="removeIcon ? 'span' : 'TimesCircleIcon'" tabindex="0" :class="['p-chip-remove-icon', removeIcon]" @click="close" @keydown="onKeydown" v-bind="ptm('removeIcon')"></component>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import BaseComponent from 'primevue/basecomponent';
|
||||||
import TimesCircleIcon from 'primevue/icons/timescircle';
|
import TimesCircleIcon from 'primevue/icons/timescircle';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Chip',
|
name: 'Chip',
|
||||||
|
extends: BaseComponent,
|
||||||
emits: ['remove'],
|
emits: ['remove'],
|
||||||
props: {
|
props: {
|
||||||
label: {
|
label: {
|
||||||
|
|
Loading…
Reference in New Issue