From f79e58348fe4bf82e98c76eb3b7fe31481d88cf9 Mon Sep 17 00:00:00 2001 From: Nina Date: Mon, 26 Aug 2024 17:28:14 -0300 Subject: [PATCH] remove dt-icon from Avatar vue 2 --- .../components/avatar/avatar.test.js | 12 ++-- .../components/avatar/avatar.vue | 67 +++++++++---------- .../avatar/avatar_variants.story.vue | 30 ++++++--- .../feed_item_row/feed_item_row.vue | 18 +++-- .../contact_info/contact_info.stories.js | 13 ++-- .../item_layout/contact_info/contact_info.vue | 35 ++++++++-- .../contact_info_variants.story.vue | 15 +++-- .../recipes/leftbar/callbox/callbox.vue | 13 +++- .../leftbar/contact_row/contact_row.vue | 19 ++++-- .../contact_row_variants.story.vue | 13 ++++ 10 files changed, 150 insertions(+), 85 deletions(-) diff --git a/packages/dialtone-vue2/components/avatar/avatar.test.js b/packages/dialtone-vue2/components/avatar/avatar.test.js index 771aa2508d..dd02a7bede 100644 --- a/packages/dialtone-vue2/components/avatar/avatar.test.js +++ b/packages/dialtone-vue2/components/avatar/avatar.test.js @@ -9,6 +9,7 @@ const MOCK_INITIALS = 'JN'; const MOCK_SIZE = 'lg'; const MOCK_GROUP = 25; const MOCK_CUSTOM_CLASS = 'my-custom-class'; +const MOCK_ICON_SLOT = ''; let MOCK_ELEMENT = null; const baseProps = { @@ -20,6 +21,7 @@ const baseListeners = {}; let mockProps = {}; let mockListeners = {}; const testContext = {}; +let mockSlots = {}; describe('DtAvatar Tests', () => { let wrapper; @@ -32,6 +34,7 @@ describe('DtAvatar Tests', () => { propsData: { ...baseProps, ...mockProps }, listeners: { ...baseListeners, ...mockListeners }, localVue: testContext.localVue, + slots: { ...mockSlots }, }); image = wrapper.find('[data-qa="dt-avatar-image"]'); @@ -50,6 +53,7 @@ describe('DtAvatar Tests', () => { afterEach(() => { mockProps = {}; mockListeners = {}; + mockSlots = {}; }); describe('Presentation Tests', () => { @@ -83,19 +87,19 @@ describe('DtAvatar Tests', () => { }); }); - describe('When the iconName is provided', () => { + describe('When the icon slot is provided', () => { beforeEach(() => { - mockProps = { iconName: 'accessibility' }; + mockSlots = { icon: MOCK_ICON_SLOT }; updateWrapper(); }); it('icon should exist', () => { - expect(wrapper.find('svg').exists()).toBeTruthy(); + expect(wrapper.find('[data-qa="dt-avatar-icon"]').exists()).toBeTruthy(); }); it('should have correct class', () => { - expect(wrapper.find('svg').classes(AVATAR_KIND_MODIFIERS.icon)).toBe(true); + expect(wrapper.find('[data-qa="dt-avatar-icon"]').classes(AVATAR_KIND_MODIFIERS.icon)).toBe(true); }); }); diff --git a/packages/dialtone-vue2/components/avatar/avatar.vue b/packages/dialtone-vue2/components/avatar/avatar.vue index 2913e9d65d..ee7bf5daf3 100644 --- a/packages/dialtone-vue2/components/avatar/avatar.vue +++ b/packages/dialtone-vue2/components/avatar/avatar.vue @@ -22,14 +22,19 @@ :src="imageSrc" :alt="imageAlt" > - + :aria-label="clickable ? iconAriaLabel : ''" + :data-qa="iconDataQa" + :role="clickable ? 'button' : ''" + > + + +
- +

import { getUniqueString, getRandomElement } from '@/common/utils'; import { DtPresence } from '../presence'; -import { DtIcon } from '@/components/icon'; import { AVATAR_KIND_MODIFIERS, AVATAR_SIZE_MODIFIERS, @@ -84,19 +88,16 @@ import { AVATAR_GROUP_VALIDATOR, AVATAR_ICON_SIZES, } from './avatar_constants'; -import { getIconNames } from '@/common/storybook_utils.js'; import { ICON_SIZE_MODIFIERS } from '@/components/icon/icon_constants.js'; import { extractInitialsFromName } from './utils'; -const ICONS_LIST = getIconNames(); - /** * An avatar is a visual representation of a user or object. * @see https://dialtone.dialpad.com/components/avatar.html */ export default { name: 'DtAvatar', - components: { DtPresence, DtIcon }, + components: { DtPresence }, inheritAttrs: false, @@ -194,14 +195,6 @@ export default { validator: (group) => AVATAR_GROUP_VALIDATOR(group), }, - /** - * The icon that overlays the avatar - */ - overlayIcon: { - type: String, - default: '', - }, - /** * The text that overlays the avatar */ @@ -236,15 +229,6 @@ export default { default: undefined, }, - /** - * Icon name to be displayed on the avatar - */ - iconName: { - type: String, - default: undefined, - validator: (name) => ICONS_LIST.includes(name), - }, - /** * Icon size to be displayed on the avatar * @values 100, 200, 300, 400, 500, 600, 700, 800 @@ -305,8 +289,16 @@ export default { }, computed: { - isNotIconType () { - return !this.iconName; + isIconType () { + return !!this.$slots.icon; + }, + + hasOverlayIcon () { + return !!this.$slots.overlayIcon; + }, + + iconDataQa () { + return 'dt-avatar-icon'; }, avatarClasses () { @@ -316,7 +308,7 @@ export default { this.avatarClass, { 'd-avatar--group': this.showGroup, - [`d-avatar--color-${this.getColor()}`]: this.isNotIconType, + [`d-avatar--color-${this.getColor()}`]: !this.isIconType, 'd-avatar--clickable': this.clickable, }, ]; @@ -326,6 +318,7 @@ export default { return [ 'd-avatar__overlay', this.overlayClass, + { 'd-avatar__overlay-icon': this.hasOverlayIcon }, ]; }, diff --git a/packages/dialtone-vue2/components/avatar/avatar_variants.story.vue b/packages/dialtone-vue2/components/avatar/avatar_variants.story.vue index b2ac1db739..cc07088d20 100644 --- a/packages/dialtone-vue2/components/avatar/avatar_variants.story.vue +++ b/packages/dialtone-vue2/components/avatar/avatar_variants.story.vue @@ -35,8 +35,11 @@ :seed="$attrs.seed" :size="size" full-name="Avatar Icon" - icon-name="user" - /> + > + +

@@ -64,7 +67,11 @@ :image-src="$attrs.imageSrc" :image-alt="$attrs.imageAlt" overlay-icon="hear" - /> + > + + + > + + + > + + diff --git a/packages/dialtone-vue2/recipes/leftbar/contact_row/contact_row_variants.story.vue b/packages/dialtone-vue2/recipes/leftbar/contact_row/contact_row_variants.story.vue index eec463bb83..34d4e0f4c7 100644 --- a/packages/dialtone-vue2/recipes/leftbar/contact_row/contact_row_variants.story.vue +++ b/packages/dialtone-vue2/recipes/leftbar/contact_row/contact_row_variants.story.vue @@ -86,6 +86,19 @@ call-button-tooltip="Call" />
+
+

+ With icon +

+ +

With emojis in the name