-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
2f9c253
77ab4da
32ba3b4
3444cfd
39f4b79
2bedbeb
75f36b9
b38289d
4b6e386
86ac9fd
ca0ec1d
dafcf29
7cefab3
66d9c1e
cd87675
43c024c
dd887b7
afcbd7c
de0e346
3cc46db
18d844e
21764d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' |
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, | ||
}, | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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> |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 ?