Skip to content

Commit

Permalink
Refactor #3965 - For Avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jun 23, 2023
1 parent 810894d commit 386c7d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions components/lib/avatar/Avatar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @module avatar
*/
import { VNode } from 'vue';
import { AvatarGroupPassThroughOptions } from '../avatargroup';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';

export declare type AvatarPassThroughOptionType = AvatarPassThroughAttributes | ((options: AvatarPassThroughMethodOptions) => AvatarPassThroughAttributes) | null | undefined;
Expand All @@ -16,6 +17,7 @@ export declare type AvatarPassThroughOptionType = AvatarPassThroughAttributes |
*/
export interface AvatarPassThroughMethodOptions {
props: AvatarProps;
parent: AvatarGroupPassThroughOptions;
}

/**
Expand Down
17 changes: 12 additions & 5 deletions components/lib/avatar/Avatar.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div :class="cx('root')" :aria-labelledby="ariaLabelledby" :aria-label="ariaLabel" v-bind="ptm('root', { $parentInstance })" data-pc-name="avatar">
<div :class="cx('root')" :aria-labelledby="ariaLabelledby" :aria-label="ariaLabel" v-bind="getPTOptions('root')" data-pc-name="avatar">
<slot>
<span v-if="label" :class="cx('label')" v-bind="ptm('label')">{{ label }}</span>
<component v-else-if="$slots.icon" :is="$slots.icon" :class="cx('icon')" v-bind="ptm('icon')" />
<span v-else-if="icon" :class="[cx('icon'), icon]" v-bind="ptm('icon')" />
<img v-else-if="image" :src="image" :alt="ariaLabel" @error="onError" v-bind="ptm('image')" />
<span v-if="label" :class="cx('label')" v-bind="getPTOptions('label')">{{ label }}</span>
<component v-else-if="$slots.icon" :is="$slots.icon" :class="cx('icon')" />
<span v-else-if="icon" :class="[cx('icon'), icon]" v-bind="getPTOptions('icon')" />
<img v-else-if="image" :src="image" :alt="ariaLabel" @error="onError" v-bind="getPTOptions('image')" />
</slot>
</div>
</template>
Expand All @@ -19,6 +19,13 @@ export default {
methods: {
onError() {
this.$emit('error');
},
getPTOptions(key) {
return this.ptm(key, {
parent: {
instance: this.$parent
}
});
}
}
};
Expand Down
12 changes: 12 additions & 0 deletions components/lib/button/Button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export declare type ButtonPassThroughOptionType = ButtonPassThroughAttributes |
*/
export interface ButtonPassThroughMethodOptions {
props: ButtonProps;
context: ButtonContext;
}

/**
Expand Down Expand Up @@ -149,6 +150,17 @@ export interface ButtonProps extends ButtonHTMLAttributes {
unstyled?: boolean;
}

/**
* Defines current options in Button component.
*/
export interface ButtonContext {
/**
* Current disabled state of the element as a boolean.
* @defaultValue false
*/
disabled: boolean;
}

/**
* Defines valid slots in Button component.
*/
Expand Down

0 comments on commit 386c7d8

Please sign in to comment.