Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/create avatar component #231

Merged
merged 22 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2f9c253
feat: create avatar component (wip)
mattgoud Oct 19, 2023
77ab4da
docs: storybook docs (wip)
mattgoud Oct 20, 2023
32ba3b4
docs: avatar storybook
mattgoud Oct 22, 2023
3444cfd
test: vitest specs
mattgoud Oct 22, 2023
39f4b79
fix: handle case where one of the firstname and lastname is missing
mattgoud Oct 24, 2023
2bedbeb
Merge branch 'main' into feat/create-avatar-component
mattgoud Nov 2, 2023
75f36b9
feat: [avatar] - remove color prop
mattgoud Nov 3, 2023
b38289d
feat: [avatar] - create enum alternatives for mode, size and type
mattgoud Nov 3, 2023
4b6e386
feat: [avatar] - rerender puik-icon and initials when they update
mattgoud Nov 3, 2023
86ac9fd
feat: [avatar/icon] computed functions for a better reactive behavior
mattgoud Nov 3, 2023
ca0ec1d
feat: [avatar] - add singleInitial prop and prohibit special characters
mattgoud Nov 6, 2023
dafcf29
docs: [avatar] - storybook update
mattgoud Nov 6, 2023
7cefab3
Merge branch 'main' into feat/create-avatar-component
mattgoud Nov 6, 2023
66d9c1e
test: [avatar] - add dataTest prop
mattgoud Nov 6, 2023
cd87675
feat: remove computed func for mode and fontsize (create const instead)
mattgoud Nov 6, 2023
43c024c
Merge branch 'main' into feat/create-avatar-component
mattgoud Nov 6, 2023
dd887b7
feat: [avatar] - create getInitialLetter func
mattgoud Nov 8, 2023
afcbd7c
Merge branch 'feat/create-avatar-component' of github.com:PrestaShopC…
mattgoud Nov 8, 2023
de0e346
feat: [avatar] - only enum type for mode, size and type props
mattgoud Nov 8, 2023
3cc46db
Merge branch 'main' into feat/create-avatar-component
mattgoud Nov 12, 2023
18d844e
feat: [avatar] - apply tailwind class object-cover for img type
mattgoud Nov 12, 2023
21764d0
Merge branch 'feat/create-avatar-component' of github.com:PrestaShopC…
mattgoud Nov 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/components/avatar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withInstall } from '@puik/utils'

import Avatar from './src/avatar.vue'

export const PuikAvatar = withInstall(Avatar)
export default PuikAvatar

export * from './src/avatar'
93 changes: 93 additions & 0 deletions packages/components/avatar/src/avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { buildProps } from '@puik/utils'
import type { ExtractPropTypes, PropType } from 'vue'
import type Avatar from './avatar.vue'

export enum PuikAvatarMode {
PRIMARY = 'primary',
REVERSE = 'reverse',
}
export const AVATAR_MODE = {
primary: 'white',
reverse: 'black',
}

export enum PuikAvatarSize {
SMALL = 'small',
MEDIUM = 'medium',
LARGE = 'large',
JUMBO = 'jumbo',
}
export const ICONS_FONTSIZE = {
small: '1rem',
medium: '1.5rem',
large: '2rem',
jumbo: '2.8rem',
}

export enum PuikAvatarType {
PHOTO = 'photo',
ICON = 'icon',
INITIALS = 'initials',
}

export const avatarProps = buildProps({
id: {
type: String,
required: false,
default: undefined,
},
Comment on lines +34 to +38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On en a besoin de l'id ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Γ§a peut toujours Γͺtre utile pour les utilisateurs si besoin de target facilement les Γ©lΓ©ments puik (dans la mΓͺme veine que data-test). C'est une prop qui n'est pas requise donc pas contraignant de la laisser. T'en pense quoi ?

mode: {
type: String as PropType<PuikAvatarMode>,
required: false,
default: PuikAvatarMode.PRIMARY,
},
size: {
type: String as PropType<PuikAvatarSize>,
required: false,
default: PuikAvatarSize.MEDIUM,
},
type: {
type: String as PropType<PuikAvatarType>,
required: false,
default: PuikAvatarType.INITIALS,
},
icon: {
type: String,
required: false,
default: '',
},
src: {
type: String,
required: false,
default: '',
},
Comment on lines +59 to +63

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour les avatars avec une photo/image, qu'est-ce qu'on veut comme comportement si je prend une photo avec du transparent ? Genre un png ?

Est-ce qu'on laisse la transparence ? Dans ce cas faudrait enlever la couleur par default :O

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bien vu ! le cas oΓΉ l'image est transparente n'a pas Γ©tΓ© prΓ©vu. Je vois Γ§a

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Après avoir testé, je pense que c'est à l'utilisateur de jouer sur le background avec la prop "mode" (soit fond noir si 'primary' soit fond blanc si 'reverse')

alt: {
type: String,
required: false,
default: '',
},
firstname: {
type: String,
required: false,
default: '',
},
lastname: {
type: String,
required: false,
default: '',
},
singleInitial: {
type: Boolean,
required: false,
default: false,
},
dataTest: {
type: String,
required: false,
default: undefined,
},
} as const)

export type AvatarProps = ExtractPropTypes<typeof avatarProps>

export type AvatarInstance = InstanceType<typeof Avatar>
66 changes: 66 additions & 0 deletions packages/components/avatar/src/avatar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<div
:id="id"
:class="`puik-avatar puik-avatar--${size} puik-avatar--${type} puik-avatar--${mode}`"
>
<img
v-if="src && type == PuikAvatarType.PHOTO"
:src="src"
:alt="alt"
:data-test="dataTest != undefined ? `image-${dataTest}` : undefined"
/>
<puik-icon
v-else-if="icon && type == PuikAvatarType.ICON"
:icon="icon"
:font-size="ICONS_FONTSIZE[props.size]"
:color="AVATAR_MODE[props.mode]"
:data-test="dataTest != undefined ? `icon-${dataTest}` : undefined"
/>
<div
v-else
:key="initials"
:class="`puik-avatar_initials puik-avatar_initials--${size}`"
:data-test="dataTest != undefined ? `initials-${dataTest}` : undefined"
>
{{ initials }}
</div>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { getInitialLetter } from '@puik/utils'
import PuikIcon from '../../icon'
import {
avatarProps,
PuikAvatarType,
ICONS_FONTSIZE,
AVATAR_MODE,
} from './avatar'

defineOptions({
name: 'PuikAvatar',
})

const props = defineProps(avatarProps)

const initials = computed(() => {
const firstInitial = props.firstname
? getInitialLetter(props.firstname, 0)
: ''

const lastInitial = props.lastname ? getInitialLetter(props.lastname, 0) : ''

const initialsValue = props.singleInitial
? firstInitial || lastInitial || 'P'
: firstInitial && lastInitial
? firstInitial + lastInitial
: firstInitial && props.firstname.length > 1
? firstInitial + getInitialLetter(props.firstname, 1)
: lastInitial && props.lastname.length > 1
? lastInitial + getInitialLetter(props.lastname, 1)
: 'PS'

return initialsValue
})
</script>
Loading
Loading