Skip to content

Commit

Permalink
pkp/pkp-lib#9626 Add InitialsAvatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
blesildaramirez committed Oct 30, 2024
1 parent caeac06 commit fe5dcbf
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/InitialsAvatar/InitialsAvatar.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import InitialsAvatar from './InitialsAvatar.vue';

export default {
title: 'Components/InitialsAvatar',
component: InitialsAvatar,
render: (args) => ({
components: {InitialsAvatar},
setup() {
return {args};
},
template: `
<InitialsAvatar v-bind="args" />
`,
}),
};

export const Default = {
args: {givenName: 'Ramiro', familyName: 'Vaca'},
};

export const GivenNameOnly = {
args: {givenName: 'Daniel'},
};

export const IsSecondary = {
args: {givenName: 'David', familyName: 'Buskins', isSecondary: true},
};

export const Undefined = {
args: {},
};
54 changes: 54 additions & 0 deletions src/components/InitialsAvatar/InitialsAvatar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<div :class="classes">
<span v-if="initials">{{ initials }}</span>
<Icon v-else icon="User" class="h-5 w-5"></Icon>
</div>
</template>

<script setup>
import {computed} from 'vue';
import Icon from '../Icon/Icon.vue';
const props = defineProps({
givenName: {
type: String,
required: true,
},
familyName: {
type: String,
default: '',
},
isPrimary: {
type: Boolean,
default: true,
},
isSecondary: {
type: Boolean,
default: false,
},
isWarnable: {
type: Boolean,
default: false,
},
shrink: {
type: Boolean,
default: false,
},
});
const initials = computed(() => {
return `${props.givenName?.charAt(0) || ''}${props.familyName?.charAt(0) || ''}`.toUpperCase();
});
const classes = computed(() => ({
// Base
'inline-flex items-center justify-center align-middle rounded-full p-1 text-3xl-medium cursor-pointer': true,
'h-8 w-8': !props.shrink,
'h-5 w-5': props.shrink,
// Default
'bg-primary text-on-dark hover:text-on-dark hover:bg-hover':
props.isPrimary && !props.isSecondary && !props.isWarnable,
// Is secondary
'bg-secondary text-primary': props.isSecondary,
'bg-negative text-on-dark': props.isWarnable,
}));
</script>

0 comments on commit fe5dcbf

Please sign in to comment.