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 5 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'
78 changes: 78 additions & 0 deletions packages/components/avatar/src/avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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

Choose a reason for hiding this comment

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

Il faudrait pas un 'white' ?

Choose a reason for hiding this comment

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

C'est un vieux commentaire ca (il se peut que j'avais commencΓ© a review il y a longtemps et que j'avais pas fini)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oui il n'y a plus de color variants, la prop color a Γ©tΓ© supprimΓ©e.

export type PuikAvatarBgColor = (typeof avatarColors)[number]

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

export const avatarSizes = ['small', 'medium', 'large', 'jumbo'] as const
export type PuikAvatarSize = (typeof avatarSizes)[number]

export const avatarTypes = ['photo', 'icon', 'initials'] as const
export type PuikAvatarType = (typeof avatarTypes)[number]

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 ?

color: {
type: String as PropType<PuikAvatarBgColor>,
required: false,
default: 'neutral',

Choose a reason for hiding this comment

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

Si on veut une couleur 'white', est-ce que ce serait pas blanc la couleur par default ?

Choose a reason for hiding this comment

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

C'est un vieux commentaire ca (il se peut que j'avais commencΓ© a review il y a longtemps et que j'avais pas fini)

},
mode: {
type: String as PropType<PuikAvatarMode>,
required: false,
default: 'primary',
},
size: {
type: String as PropType<PuikAvatarSize>,
required: false,
default: 'medium',
},
type: {
type: String as PropType<PuikAvatarType>,
required: false,
default: '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: '',
},
} as const)

export type AvatarProps = ExtractPropTypes<typeof avatarProps>

export type AvatarInstance = InstanceType<typeof Avatar>
51 changes: 51 additions & 0 deletions packages/components/avatar/src/avatar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div
:id="id"
:class="`puik-avatar puik-avatar--${size} puik-avatar--${type} puik-avatar--${mode} puik-avatar--${color}`"
>
<img v-if="src && type == 'photo'" :src="src" :alt="alt" />
<puik-icon
v-else-if="icon && type == 'icon'"
:icon="icon"
:font-size="iconFontSize"
:color="mode === 'primary' ? 'white' : 'black'"
/>
<div v-else :class="`puik-avatar_initials puik-avatar_initials--${size}`">
{{ initials }}
</div>
</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import PuikIcon from '../../icon'
import { avatarProps } from './avatar'
defineOptions({
name: 'PuikAvatar',
})

const props = defineProps(avatarProps)
const iconFontSize = ref()
const initials = ref('PS')

props.size === 'small'
? (iconFontSize.value = '1rem')
: props.size === 'medium'
? (iconFontSize.value = '1.5rem')
: props.size === 'large'
? (iconFontSize.value = '2rem')
: props.size === 'jumbo'
? (iconFontSize.value = '2.8rem')
: '1rem'

props.firstname !== '' && props.lastname !== ''
? (initials.value =
props.firstname[0]?.toUpperCase() + props.lastname[0]?.toUpperCase())
: props.firstname.length > 1 && !props.lastname
? (initials.value =
props.firstname[0]?.toUpperCase() + props.firstname[1]?.toUpperCase())
: props.lastname.length > 1 && !props.firstname
? (initials.value =
props.lastname[0]?.toUpperCase() + props.lastname[1]?.toUpperCase())
: (initials.value = 'PS')
</script>
Loading
Loading