Skip to content

Commit

Permalink
feat: [avatar] - remove color prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgoud committed Nov 3, 2023
1 parent 2bedbeb commit 75f36b9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 183 deletions.
14 changes: 0 additions & 14 deletions packages/components/avatar/src/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { buildProps } from '@puik/utils'
import type { ExtractPropTypes, PropType } from 'vue'
import type Avatar from './avatar.vue'

export const avatarColors = [
'neutral',
'blue',
'yellow',
'green',
'purple',
] as const
export type PuikAvatarBgColor = (typeof avatarColors)[number]

export const avatarModes = ['primary', 'reverse'] as const
export type PuikAvatarMode = (typeof avatarModes)[number]

Expand All @@ -26,11 +17,6 @@ export const avatarProps = buildProps({
required: false,
default: undefined,
},
color: {
type: String as PropType<PuikAvatarBgColor>,
required: false,
default: 'neutral',
},
mode: {
type: String as PropType<PuikAvatarMode>,
required: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/components/avatar/src/avatar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
:id="id"
:class="`puik-avatar puik-avatar--${size} puik-avatar--${type} puik-avatar--${mode} puik-avatar--${color}`"
:class="`puik-avatar puik-avatar--${size} puik-avatar--${type} puik-avatar--${mode}`"
>
<img v-if="src && type == 'photo'" :src="src" :alt="alt" />
<puik-icon
Expand All @@ -20,6 +20,7 @@
import { ref } from 'vue'
import PuikIcon from '../../icon'
import { avatarProps } from './avatar'
defineOptions({
name: 'PuikAvatar',
})
Expand Down
148 changes: 14 additions & 134 deletions packages/components/avatar/stories/avatar.stories.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { ref } from 'vue'
import { PuikIcon } from '@puik/components'
import {
avatarColors,
avatarModes,
avatarSizes,
avatarTypes,
} from '../src/avatar'
import { avatarModes, avatarSizes, avatarTypes } from '../src/avatar'
import PuikAvatar from './../src/avatar.vue'
import type { Meta, StoryFn, Args } from '@storybook/vue3'

const avatarColorsSummary = avatarColors.join('|')
const avatarModesSummary = avatarModes.join('|')
const avatarSizesSummary = avatarSizes.join('|')
const avatarTypesSummary = avatarTypes.join('|')
Expand All @@ -31,20 +25,6 @@ export default {
},
},
},
color: {
description:
'Color variants of avatar component (neutral by default, blue, yellow, green, purple)',
control: 'select',
options: avatarColors,
table: {
type: {
summary: avatarColorsSummary,
},
defaultValue: {
summary: 'neutral',
},
},
},
mode: {
description:
'Two possible variations (primary and reverse) : depending on a dark or light background of the container where the avatar is placed',
Expand Down Expand Up @@ -151,7 +131,6 @@ export default {
},
args: {
id: 'puik-avatar-id',
color: 'neutral',
mode: 'primary',
size: 'medium',
type: 'initials',
Expand Down Expand Up @@ -284,7 +263,7 @@ const SizesTemplate: StoryFn = (args: Args) => ({
`,
})

const ModesAndColorsTemplate: StoryFn = (args: Args) => ({
const ModesTemplate: StoryFn = (args: Args) => ({
components: {
PuikIcon,
PuikAvatar,
Expand All @@ -294,56 +273,10 @@ const ModesAndColorsTemplate: StoryFn = (args: Args) => ({
{
type: 'initials',
mode: 'primary',
color: 'neutral',
},
{
type: 'initials',
mode: 'primary',
color: 'blue',
},
{
type: 'initials',
mode: 'primary',
color: 'yellow',
},
{
type: 'initials',
mode: 'primary',
color: 'green',
},
{
type: 'initials',
mode: 'primary',
color: 'purple',
},
{
type: 'icon',
mode: 'primary',
color: 'neutral',
icon: 'home',
},
{
type: 'icon',
mode: 'primary',
color: 'blue',
icon: 'home',
},
{
type: 'icon',
mode: 'primary',
color: 'yellow',
icon: 'home',
},
{
type: 'icon',
mode: 'primary',
color: 'green',
icon: 'home',
},
{
type: 'icon',
mode: 'primary',
color: 'purple',
icon: 'home',
},
])
Expand All @@ -352,56 +285,10 @@ const ModesAndColorsTemplate: StoryFn = (args: Args) => ({
{
type: 'initials',
mode: 'reverse',
color: 'neutral',
},
{
type: 'initials',
mode: 'reverse',
color: 'blue',
},
{
type: 'initials',
mode: 'reverse',
color: 'yellow',
},
{
type: 'initials',
mode: 'reverse',
color: 'green',
},
{
type: 'initials',
mode: 'reverse',
color: 'purple',
},
{
type: 'icon',
mode: 'reverse',
color: 'neutral',
icon: 'home',
},
{
type: 'icon',
mode: 'reverse',
color: 'blue',
icon: 'home',
},
{
type: 'icon',
mode: 'reverse',
color: 'yellow',
icon: 'home',
},
{
type: 'icon',
mode: 'reverse',
color: 'green',
icon: 'home',
},
{
type: 'icon',
mode: 'reverse',
color: 'purple',
icon: 'home',
},
])
Expand All @@ -415,7 +302,6 @@ const ModesAndColorsTemplate: StoryFn = (args: Args) => ({
:key="index"
:type="avatar.type"
:mode="avatar.mode"
:color="avatar.color"
:icon="avatar.icon"
/>
</div>
Expand All @@ -425,7 +311,6 @@ const ModesAndColorsTemplate: StoryFn = (args: Args) => ({
:key="index"
:type="avatar.type"
:mode="avatar.mode"
:color="avatar.color"
:icon="avatar.icon"
/>
</div>
Expand All @@ -443,7 +328,6 @@ export const Default = {
<!-- Vue component with all possible props -->
<PuikAvatar
:id="args.id"
:color="args.color"
:size="args.size"
:type="args.type"
:mode="args.mode"
Expand All @@ -456,7 +340,7 @@ export const Default = {
<!-- HTML/CSS Snippet -->
<!-- Avatar (by default) -->
<div id="puik-avatar-id" class="puik-avatar puik-avatar--medium puik-avatar--initials puik-avatar--primary puik-avatar--neutral">
<div id="puik-avatar-id" class="puik-avatar puik-avatar--medium puik-avatar--initials puik-avatar--primary">
<div class="puik-avatar_initials puik-avatar_initials--medium">
PS
</div>
Expand Down Expand Up @@ -496,19 +380,19 @@ export const Types = {
<!-- HTML/CSS Snippet -->
<!-- type initials-->
<div class="puik-avatar puik-avatar--medium puik-avatar--initials puik-avatar--primary puik-avatar--neutral">
<div class="puik-avatar puik-avatar--medium puik-avatar--initials puik-avatar--primary">
<div class="puik-avatar_initials puik-avatar_initials--medium">
PS
</div>
</div>
<!-- type icon-->
<div class="puik-avatar puik-avatar--medium puik-avatar--icon puik-avatar--primary puik-avatar--neutral">
<div class="puik-avatar puik-avatar--medium puik-avatar--icon puik-avatar--primary">
<div class="puik-icon" style="font-size: 1.5rem; color: white;">
home
</div>
</div>
<!-- type photo-->
<div class="puik-avatar puik-avatar--medium puik-avatar--photo puik-avatar--primary puik-avatar--neutral">
<div class="puik-avatar puik-avatar--medium puik-avatar--photo puik-avatar--primary">
<img src="https://picsum.photos/200" alt="puik-avatar-alt">
</div>
`,
Expand Down Expand Up @@ -536,7 +420,7 @@ export const Sizes = {
<!-- HTML/CSS Snippet -->
<!-- initials type -->
<div class="puik-avatar puik-avatar--{$size} puik-avatar--initials puik-avatar--primary puik-avatar--neutral">
<div class="puik-avatar puik-avatar--{$size} puik-avatar--initials puik-avatar--primary">
<div class="puik-avatar_initials puik-avatar_initials--{$size}">
PS
</div>
Expand All @@ -549,13 +433,13 @@ NB: values of {$iconFontSize} to apply depending on the prop size:
large = 2rem
jumbo = 2.8rem
-->
<div class="puik-avatar puik-avatar--{$size} puik-avatar--icon puik-avatar--primary puik-avatar--neutral">
<div class="puik-avatar puik-avatar--{$size} puik-avatar--icon puik-avatar--primary">
<div class="puik-icon" style="font-size: {$iconFontSize}; color: white;">
home
</div>
</div>
<!-- photo type -->
<div class="puik-avatar puik-avatar--{$size} puik-avatar--photo puik-avatar--primary puik-avatar--neutral">
<div class="puik-avatar puik-avatar--{$size} puik-avatar--photo puik-avatar--primary">
<img src="https://picsum.photos/200" alt="puik-avatar-alt">
</div>
`,
Expand All @@ -565,25 +449,21 @@ NB: values of {$iconFontSize} to apply depending on the prop size:
},
}

export const ModesAndColors = {
render: ModesAndColorsTemplate,
export const Modes = {
render: ModesTemplate,
args: {},
parameters: {
docs: {
source: {
code: `
<!-- VueJS Snippet -->
<!-- $colors: ${avatarColorsSummary} -->
<!-- $modes: ${avatarModesSummary} -->
<puik-avatar
:mode="{$mode}"
:color="{$color}"
/>
<puik-avatar :mode="{$mode}"/>
<!-- HTML/CSS Snippet -->
<!-- initials type -->
<div class="puik-avatar puik-avatar--medium puik-avatar--initials puik-avatar--{$mode} puik-avatar--{$color}">
<div class="puik-avatar puik-avatar--medium puik-avatar--initials puik-avatar--{$mode}">
<div class="puik-avatar_initials puik-avatar_initials--{$mode}">
PS
</div>
Expand All @@ -594,7 +474,7 @@ NB: values of {$iconColor} to apply depending on the prop mode:
primary = white
reverse = black
-->
<div class="puik-avatar puik-avatar--medium puik-avatar--icon puik-avatar--{$mode} puik-avatar--{$color}">
<div class="puik-avatar puik-avatar--medium puik-avatar--icon puik-avatar--{$mode}">
<div class="puik-icon" style="font-size: 1.5rem; color: {$iconColor};">
home
</div>
Expand Down
5 changes: 0 additions & 5 deletions packages/components/avatar/test/avatar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ describe('Avatar tests', () => {
expect(findAvatar().attributes().id).toBe('puik-avatar-id')
})

it('should display a blue version of the avatar', () => {
factory({ color: 'blue' })
expect(findAvatar().classes()).toContain('puik-avatar--blue')
})

it('should display the avatar in reverse mode', () => {
factory({ mode: 'reverse' })
expect(findAvatar().classes()).toContain('puik-avatar--reverse')
Expand Down
31 changes: 2 additions & 29 deletions packages/theme/src/avatar.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use './common/typography.scss';

.puik-avatar {
@apply flex justify-center items-center rounded-full overflow-hidden;
@apply flex justify-center items-center bg-primary-800 rounded-full overflow-hidden;
}
.puik-avatar--small {
@apply w-6 h-6;
Expand Down Expand Up @@ -33,36 +33,9 @@
object-fit: cover;
}
}
.puik-avatar--neutral {
@apply bg-primary-800;
}
.puik-avatar--blue {
@apply bg-ocean-blue;
}
.puik-avatar--yellow {
@apply bg-amber;
}
.puik-avatar--green {
@apply bg-green;
}
.puik-avatar--purple {
@apply bg-purple;
}
.puik-avatar--reverse.puik-avatar--neutral {
.puik-avatar--reverse.puik-avatar {
@apply bg-white;
}
.puik-avatar--reverse.puik-avatar--blue {
@apply bg-ocean-blue-50;
}
.puik-avatar--reverse.puik-avatar--yellow {
@apply bg-amber-100;
}
.puik-avatar--reverse.puik-avatar--green {
@apply bg-green-50;
}
.puik-avatar--reverse.puik-avatar--purple {
@apply bg-purple-50;
}
.puik-avatar_initials {
@apply font-bold;
&--small {
Expand Down

0 comments on commit 75f36b9

Please sign in to comment.