Refactor #3879 - For Avatar & AvatarGroup

This commit is contained in:
Tuğçe Küçükoğlu 2023-04-21 15:04:27 +03:00
parent 69d0f98f26
commit 43c3f82ae5
6 changed files with 131 additions and 9 deletions

View file

@ -9,6 +9,45 @@
import { VNode } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type AvatarPassThroughOptionType = AvatarPassThroughAttributes | ((options: AvatarPassThroughMethodOptions) => AvatarPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface AvatarPassThroughMethodOptions {
props: AvatarProps;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface AvatarPassThroughAttributes {
[key: string]: any;
}
/**
* Custom passthrough(pt) options.
* @see {@link AvatarProps.pt}
*/
export interface AvatarPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: AvatarPassThroughOptionType;
/**
* Uses to pass attributes to the label's DOM element.
*/
label?: AvatarPassThroughOptionType;
/**
* Uses to pass attributes to the icon's DOM element.
*/
icon?: AvatarPassThroughOptionType;
/**
* Uses to pass attributes to the image's DOM element.
*/
image?: AvatarPassThroughOptionType;
}
/**
* Defines valid properties in Avatar component.
*/
@ -44,6 +83,11 @@ export interface AvatarProps {
* Establishes relationships between the component and label(s) where its value should be one or more element IDs.
*/
'aria-labelledby'?: string | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {AvatarPassThroughOptions}
*/
pt?: AvatarPassThroughOptions;
}
/**

View file

@ -1,18 +1,21 @@
<template>
<div :class="containerClass" :aria-labelledby="ariaLabelledby" :aria-label="ariaLabel">
<div :class="containerClass" :aria-labelledby="ariaLabelledby" :aria-label="ariaLabel" v-bind="ptm('root')">
<slot></slot>
<template v-if="!$slots.default">
<span v-if="label" class="p-avatar-text">{{ label }}</span>
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-avatar-icon" />
<span v-else-if="icon" :class="['p-avatar-icon', icon]" />
<img v-else-if="image" :src="image" :alt="ariaLabel" @error="onError" />
<span v-if="label" class="p-avatar-text" v-bind="ptm('label')">{{ label }}</span>
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-avatar-icon" v-bind="ptm('icon')" />
<span v-else-if="icon" :class="['p-avatar-icon', icon]" v-bind="ptm('icon')" />
<img v-else-if="image" :src="image" :alt="ariaLabel" @error="onError" v-bind="ptm('image')" />
</template>
</div>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
export default {
name: 'Avatar',
extends: BaseComponent,
emits: ['error'],
props: {
label: {