Skip to content

Commit

Permalink
Fixed #2670 - Avatar | New error event
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jun 14, 2022
1 parent bd8af92 commit 6386ffa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
10 changes: 9 additions & 1 deletion api-generator/components/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ const AvatarProps = [
}
];

const AvatarEvents = [
{
name: "error",
description: "Triggered when an error occurs while loading an image file."
}
];

module.exports = {
avatar: {
name: "Avatar",
description: "Avatar represents people using icons, labels and images.",
props: AvatarProps
props: AvatarProps,
events: AvatarEvents
}
};
4 changes: 4 additions & 0 deletions src/components/avatar/Avatar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface AvatarSlots {
}

export declare type AvatarEmits = {
/**
* Triggered when an error occurs while loading an image file.
*/
error: () => void;
}

declare class Avatar extends ClassComponent<AvatarProps, AvatarSlots, AvatarEmits> { }
Expand Down
7 changes: 6 additions & 1 deletion src/components/avatar/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<slot>
<span class="p-avatar-text" v-if="label">{{label}}</span>
<span :class="iconClass" v-else-if="icon"></span>
<img :src="image" v-else-if="image">
<img :src="image" v-else-if="image" @error="onError">
</slot>
</div>
</template>
Expand Down Expand Up @@ -33,6 +33,11 @@ export default {
default: "square"
}
},
methods: {
onError() {
this.$emit('error');
}
},
computed: {
containerClass() {
return ['p-avatar p-component', {
Expand Down
45 changes: 33 additions & 12 deletions src/views/avatar/AvatarDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import AvatarGroup from 'primevue/avatargroup';
&lt;Avatar image="user.png" /&gt;
&lt;Avatar label="+2" /&gt;
&lt;/AvatarGroup&gt;

</code></pre>

<h5>Shape</h5>
Expand All @@ -60,7 +61,7 @@ import AvatarGroup from 'primevue/avatargroup';
<p>Content can easily be customized with the default slot instead of using the built-in modes.</p>
<pre v-code><code>
&lt;Avatar&gt;
Content
Content
&lt;/Avatar&gt;

</code></pre>
Expand Down Expand Up @@ -114,6 +115,26 @@ import AvatarGroup from 'primevue/avatargroup';

<h5>Properties of AvatarGroup</h5>
<p>Any property as style and class are passed to the main container element. There are no additional properties.</p>

<h5>Events</h5>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Parameters</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>error</td>
<td>-</td>
<td>Triggered when an error occurs while loading an image file.</td>
</tr>
</tbody>
</table>
</div>

<h5>Styling of Avatar</h5>
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
Expand Down Expand Up @@ -216,7 +237,7 @@ export default {
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-4">
<div class="card">
Expand All @@ -236,7 +257,7 @@ export default {
</div>
</div>
<div class="col-12 md:col-4">
<div class="col-12 md:col-4">
<div class="card">
<h5>Icon - Badge</h5>
<Avatar icon="pi pi-user" size="xlarge" v-badge="4"/>
Expand Down Expand Up @@ -268,12 +289,12 @@ export default {
</div>
</div>
<div class="col-12 md:col-4">
<div class="card">
<h5>Image - Badge</h5>
<Avatar image="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" size="xlarge" v-badge.danger="4" />
</div>
</div>
<div class="col-12 md:col-4">
<div class="card">
<h5>Image - Badge</h5>
<Avatar image="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" size="xlarge" v-badge.danger="4" />
</div>
</div>
</div>
</template>
Expand Down Expand Up @@ -313,7 +334,7 @@ export default {
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-4">
<div class="card">
Expand All @@ -333,7 +354,7 @@ export default {
</div>
</div>
<div class="col-12 md:col-4">
<div class="col-12 md:col-4">
<div class="card">
<h5>Icon - Badge</h5>
<Avatar icon="pi pi-user" size="xlarge" v-badge="4"/>
Expand Down Expand Up @@ -411,7 +432,7 @@ export default {
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-4">
<div class="card">
Expand Down

0 comments on commit 6386ffa

Please sign in to comment.