-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request is intended to add the Avatar component.
- Loading branch information
Selemondev
authored and
Selemondev
committed
Jul 27, 2023
1 parent
3087bec
commit 97843b2
Showing
13 changed files
with
275 additions
and
10 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
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
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="icon" href="/favicon.ico"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
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
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
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
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
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
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,130 @@ | ||
<script setup lang='ts'> | ||
import type { PropType } from 'vue' | ||
import { computed, defineComponent, ref, watchEffect } from 'vue' | ||
import classNames from 'classnames' | ||
import { getVariantPropsWithClassesList } from '../../utils/getVariantProps' | ||
import type { WAvatar } from '../../Types/componentsTypes/components' | ||
import { Components } from '../../Types/enums/Components' | ||
import { useVariants } from '../../composables/useVariants' | ||
import windiTheme from '../../theme/windiTheme' | ||
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | ||
export type AvatarChipPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | ||
const props = defineProps({ | ||
...getVariantPropsWithClassesList<WAvatar>(), | ||
name: { | ||
type: String, | ||
required: true, | ||
default: '?', | ||
}, | ||
src: { | ||
type: String, | ||
default: '', | ||
}, | ||
size: { | ||
type: String as PropType<AvatarSize>, | ||
default: 'md', | ||
}, | ||
initials: { | ||
type: String, | ||
default: null, | ||
}, | ||
chipColor: { | ||
type: String, | ||
default: '', | ||
}, | ||
chipSize: { | ||
type: String, | ||
default: 'md', | ||
}, | ||
chipPosition: { | ||
type: String as PropType<AvatarChipPosition>, | ||
default: 'bottom-right', | ||
}, | ||
chipText: { | ||
type: String, | ||
default: '', | ||
}, | ||
}) | ||
const avatarUrl = ref('') | ||
watchEffect(() => { | ||
const img = new Image() | ||
img.src = props.src | ||
img.decode().then(() => (avatarUrl.value = props.src)).catch((err: string) => { | ||
avatarUrl.value = '' | ||
throw err | ||
}) | ||
}) | ||
const fallback = computed(() => { | ||
return props.initials || props.name.charAt(0) || '?' | ||
}) | ||
const variant = useVariants<WAvatar>(Components.WAvatar, props) | ||
const avatarWrapperClasses = computed<string>(() => { | ||
return classNames( | ||
variant.root, | ||
variant.avatarSize && variant[props.size], | ||
) | ||
}) | ||
const avatarClasses = computed(() => { | ||
let sizeClass = '' | ||
if (typeof props.size === 'number') { | ||
return props.size | ||
} | ||
else { | ||
sizeClass += variant[props.size] || '' | ||
return classNames(variant.rounded, sizeClass, variant.root) | ||
} | ||
}) | ||
const avatarChipSize = computed(() => { | ||
let sizeClass = '' | ||
if (typeof props.size === 'number') { | ||
return props.size | ||
} | ||
else { | ||
sizeClass += windiTheme.WAvatar.base.avatarChipSize[props.size] || '' | ||
return classNames(sizeClass) | ||
} | ||
}) | ||
const avatarChipClass = computed(() => { | ||
return classNames( | ||
variant.avatarChipClass, | ||
windiTheme.WAvatar.base.avatarChipPosition[props.chipPosition], | ||
) | ||
}) | ||
const avatarChipColorStyles = computed(() => ({ | ||
'background-color': props.chipColor || '', | ||
})) | ||
</script> | ||
|
||
<script lang="ts"> | ||
export default defineComponent({ | ||
name: Components.WAvatar, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<span :class="[avatarWrapperClasses, avatarClasses]" :title="props.name"> | ||
<img v-if="avatarUrl" :class="avatarClasses" :src="avatarUrl" :alt="props.name"> | ||
<span v-else-if="!avatarUrl" :class="variant.placeholderClass">{{ fallback }}</span> | ||
<span v-if="props.chipColor" :style="avatarChipColorStyles" :class="[avatarChipClass, avatarChipSize]"> | ||
{{ chipText }} | ||
</span> | ||
<slot /> | ||
</span> | ||
</template> |
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,5 @@ | ||
import Avatar from './WAvatar.vue' | ||
|
||
export default { | ||
Avatar, | ||
} |
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
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,9 @@ | ||
import './assets/css/tailwind.css' | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
import config from './theme/windiTheme' | ||
import install from './index' | ||
|
||
const app = createApp(App) | ||
app.use(install, config) | ||
app.mount('#app') |
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