Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
feat(confact-info): add showAvatar and avatarIcon props (Vue3) (#983
Browse files Browse the repository at this point in the history
)

* feat(confact-info): add `showAvatar` and `avatarIcon` props

* simplify avatar display logic and remove `showAvatar` args in stories

* Address code review comments

* Replace text filed with item selection filed for avatar icon
  • Loading branch information
tonydialpad authored May 18, 2023
1 parent 31daed2 commit 86fed3b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
13 changes: 12 additions & 1 deletion recipes/list_items/contact_info/contact_info.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */
import { action } from '@storybook/addon-actions';
import { createTemplateFromVueFile } from '@/common/storybook_utils';
import { createTemplateFromVueFile, getIconNames } from '@/common/storybook_utils';
import DtRecipeContactInfo from './contact_info.vue';

import DtRecipeContactInfoDefaultTemplate from './contact_info_default.story.vue';
Expand All @@ -9,6 +9,7 @@ import { AVATAR_SIZE_MODIFIERS } from '@/components/avatar';
import { PRESENCE_STATES_LIST } from '@/components/presence';

import avatarImage from './avatar.png';
const iconsList = getIconNames();

// Default Prop Values
export const argsData = {
Expand Down Expand Up @@ -36,6 +37,16 @@ export const argTypesData = {
options: Object.keys(AVATAR_SIZE_MODIFIERS),
},

avatarIcon: {
options: iconsList,
control: {
type: 'select',
labels: {
undefined: '(empty)',
},
},
},

presence: {
options: [...PRESENCE_STATES_LIST],
control: {
Expand Down
5 changes: 2 additions & 3 deletions recipes/list_items/contact_info/contact_info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ describe('DtRecipeContactInfo Tests', () => {
});
});

describe('When both `avatarSrc` and `avatarInitials` are empty', () => {
describe('When `showAvatar` is false', () => {
beforeEach(async () => {
await wrapper.setProps({
avatarSrc: '',
avatarInitials: '',
showAvatar: false,
});
_setChildWrappers();
});
Expand Down
60 changes: 36 additions & 24 deletions recipes/list_items/contact_info/contact_info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
>
<template #left>
<div
v-if="showAvatar"
class="d-ps-relative"
data-qa="contact-info-left"
>
Expand All @@ -19,7 +20,6 @@
:key="index"
>
<dt-avatar
v-if="avatar.src"
:size="avatarSize"
:seed="avatar.seed"
:initials="avatar.initials"
Expand All @@ -29,48 +29,43 @@
:avatar-class="['d-ba d-baw4 d-bc-white d-bar-pill', { 'd-mln24': index > 0 }]"
>
<img
v-if="avatar.src"
data-qa="dt-contact-avatar"
:src="avatar.src"
:alt="avatar.initials"
>
</dt-avatar>
<dt-avatar
v-else-if="avatar.initials"
:size="avatarSize"
:seed="avatar.seed"
:initials="avatar.initials"
:overlay-icon="avatar.icon"
:overlay-text="avatar.text"
overlay-class="d-mn4 d-ba d-baw4 d-bc-white d-box-unset"
:avatar-class="['d-ba d-baw4 d-bc-white d-bar-pill', { 'd-mln24': index > 0 }]"
>
{{ avatar.initials }}
<div v-else-if="avatar.initials">
{{ avatar.initials }}
</div>
<dt-icon
v-else
:name="avatarIcon"
/>
</dt-avatar>
</div>
</div>
<dt-avatar
v-else-if="avatarSrc"
v-else
:size="avatarSize"
:initials="avatarInitials"
:seed="avatarSeed"
:presence="presence"
>
<img
v-if="avatarSrc"
data-qa="dt-contact-avatar"
:src="avatarSrc"
:initials="avatarInitials"
:seed="avatarSeed"
:alt="avatarInitials"
>
</dt-avatar>
<dt-avatar
v-else-if="avatarInitials"
:size="avatarSize"
:initials="avatarInitials"
:seed="avatarSeed"
:presence="presence"
>
{{ avatarInitials }}
<div v-else-if="avatarInitials">
{{ avatarInitials }}
</div>
<dt-icon
v-else
:name="avatarIcon"
/>
</dt-avatar>
</div>
</template>
Expand Down Expand Up @@ -107,13 +102,15 @@
<script>
import DtListItem from '@/components/list_item/list_item.vue';
import DtAvatar from '@/components/avatar/avatar.vue';
import DtIcon from '@/components/icon/icon.vue';
import utils from '@/common/utils';
export default {
name: 'DtRecipeContactInfo',
components: {
DtAvatar,
DtIcon,
DtListItem,
},
Expand All @@ -140,6 +137,14 @@ export default {
default: '',
},
/**
* Display avatar if `showAvatar` property is true.
*/
showAvatar: {
type: Boolean,
default: true,
},
/**
* Optional avatar image url.
* if provided, it's also required to provide a value in the `avatarInitials` prop to use
Expand Down Expand Up @@ -167,7 +172,14 @@ export default {
},
/**
* Status color of user from contact.
* Avatar icon to display if `avatarSrc` and `avatarInitials` are empty.
*/
avatarIcon: {
type: String,
default: 'user',
},
/**
* The size of the avatar
* @values xs, sm, md, lg, xl
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<dt-recipe-contact-info
:show-avatar="$attrs.showAvatar"
:avatar-src="$attrs.avatarSrc"
:avatar-initials="$attrs.avatarInitials"
:avatar-icon="$attrs.avatarIcon"
:avatar-size="$attrs.avatarSize"
:avatar-color="$attrs.avatarColor"
:avatar-seed="$attrs.avatarSeed"
Expand Down

0 comments on commit 86fed3b

Please sign in to comment.