forked from pkp/ui-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#9626 Add InitialsAvatar component
- Loading branch information
1 parent
caeac06
commit fe5dcbf
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |