Compare commits

..

1 Commits

Author SHA1 Message Date
Tim
229439aa05 style: enhance BaseUserAvatar presentation 2025-09-24 01:31:31 +08:00

View File

@@ -1,18 +1,13 @@
<template>
<component
:is="wrapperTag"
:to="isLink ? resolvedLink : undefined"
<NuxtLink
:to="resolvedLink"
class="base-user-avatar"
:class="wrapperClass"
:style="wrapperStyle"
v-bind="wrapperAttrs"
:role="isLink ? undefined : 'img'"
:aria-label="altText"
:title="altText"
>
<span class="base-user-avatar-backdrop" aria-hidden="true" />
<BaseImage :src="currentSrc" :alt="altText" class="base-user-avatar-img" @error="onError" />
</component>
</NuxtLink>
</template>
<script setup>
@@ -81,45 +76,15 @@ const sizeStyle = computed(() => {
return { width: value, height: value }
})
const accentHue = computed(() => {
const seed = props.userId ?? props.alt
const source = seed !== undefined && seed !== null ? String(seed) : ''
if (!source) return 198
let hash = 0
for (let index = 0; index < source.length; index += 1) {
hash = (hash << 5) - hash + source.charCodeAt(index)
hash |= 0
}
return Math.abs(hash) % 360
})
const accentStyles = computed(() => {
const hue = accentHue.value
return {
'--avatar-accent': `hsl(${hue}, 74%, 54%)`,
'--avatar-accent-light': `hsl(${hue}, 95%, 82%)`,
'--avatar-accent-soft': `hsl(${hue}, 96%, 95%)`,
'--avatar-accent-border': `hsla(${hue}, 70%, 48%, 0.28)`,
'--avatar-accent-shadow': `hsla(${hue}, 68%, 36%, 0.2)`,
}
})
const wrapperStyle = computed(() => {
const attrStyle = attrs.style
return [accentStyles.value, sizeStyle.value, attrStyle]
return [sizeStyle.value, attrStyle]
})
const isLink = computed(() => !props.disableLink && !!resolvedLink.value)
const wrapperTag = computed(() => (isLink.value ? 'NuxtLink' : 'div'))
const wrapperClass = computed(() => [
attrs.class,
{ 'is-rounded': props.rounded, 'is-interactive': isLink.value },
])
const wrapperClass = computed(() => [attrs.class, { 'is-rounded': props.rounded }])
const wrapperAttrs = computed(() => {
const { class: _class, style: _style, to: _to, href: _href, ...rest } = attrs
const { class: _class, style: _style, ...rest } = attrs
return rest
})
@@ -132,26 +97,33 @@ function onError() {
<style scoped>
.base-user-avatar {
position: relative;
--base-avatar-ring-width: var(--avatar-ring-width, 1.5px);
--base-avatar-ring: var(--avatar-ring, linear-gradient(135deg, #6366f1, #ec4899));
--base-avatar-surface: var(
--avatar-surface,
var(--avatar-placeholder-color, rgba(255, 255, 255, 0.88))
);
--base-avatar-shadow: var(--avatar-shadow, 0 12px 30px -18px rgba(15, 23, 42, 0.55));
display: inline-flex;
align-items: center;
justify-content: center;
overflow: hidden;
border-radius: 16px;
background: linear-gradient(
140deg,
var(--avatar-accent-soft, rgba(17, 182, 197, 0.12)) 0%,
var(--avatar-accent-light, rgba(17, 182, 197, 0.22)) 100%
);
border: 1px solid var(--avatar-accent-border, rgba(17, 182, 197, 0.2));
box-shadow:
0 1px 2px rgba(15, 52, 67, 0.08),
0 3px 8px var(--avatar-accent-shadow, rgba(17, 182, 197, 0.18));
position: relative;
box-sizing: border-box;
color: inherit;
border-radius: 50%;
border: var(--base-avatar-ring-width) solid transparent;
background:
var(--base-avatar-surface) padding-box,
var(--base-avatar-ring) border-box;
background-clip: padding-box, border-box;
background-origin: border-box;
box-shadow: var(--base-avatar-shadow);
transition:
transform 0.3s ease,
box-shadow 0.3s ease,
border-color 0.3s ease,
background 0.3s ease;
transform 0.25s ease,
box-shadow 0.25s ease,
filter 0.25s ease;
}
.base-user-avatar.is-rounded {
@@ -159,57 +131,59 @@ function onError() {
}
.base-user-avatar:not(.is-rounded) {
border-radius: 0;
}
.base-user-avatar-backdrop {
position: absolute;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 28% 28%, rgba(255, 255, 255, 0.72), transparent 62%),
linear-gradient(150deg, rgba(255, 255, 255, 0.08), transparent),
linear-gradient(
140deg,
var(--avatar-accent-soft, rgba(17, 182, 197, 0.08)) 0%,
var(--avatar-accent-light, rgba(17, 182, 197, 0.18)) 100%
);
opacity: 0.75;
transition:
opacity 0.35s ease,
transform 0.35s ease;
z-index: 0;
border-radius: var(--avatar-square-radius, 0);
}
.base-user-avatar-img {
position: relative;
width: 100%;
height: 100%;
object-fit: cover;
display: block;
z-index: 1;
border-radius: inherit;
transition: transform 0.35s ease;
position: relative;
z-index: 1;
transition:
transform 0.25s ease,
filter 0.25s ease;
backface-visibility: hidden;
}
.base-user-avatar.is-interactive:hover,
.base-user-avatar.is-interactive:focus-visible {
.base-user-avatar:hover,
.base-user-avatar:focus-visible {
transform: translateY(-1px) scale(1.02);
border-color: var(--avatar-accent, var(--primary-color, #0a6e78));
box-shadow:
0 6px 16px var(--avatar-accent-shadow, rgba(17, 182, 197, 0.24)),
0 3px 6px rgba(15, 52, 67, 0.18);
outline: none;
box-shadow: 0 18px 35px -20px rgba(15, 23, 42, 0.65);
}
.base-user-avatar.is-interactive:hover .base-user-avatar-backdrop,
.base-user-avatar.is-interactive:focus-visible .base-user-avatar-backdrop {
opacity: 1;
transform: scale(1.05);
.base-user-avatar:focus-visible {
outline: 2px solid rgba(96, 165, 250, 0.6);
outline-offset: 3px;
}
.base-user-avatar.is-interactive:hover .base-user-avatar-img,
.base-user-avatar.is-interactive:focus-visible .base-user-avatar-img {
transform: scale(1.02);
.base-user-avatar:active {
transform: translateY(0) scale(0.99);
}
.base-user-avatar:hover .base-user-avatar-img,
.base-user-avatar:focus-visible .base-user-avatar-img {
transform: scale(1.03);
filter: saturate(1.08);
}
@media (prefers-reduced-motion: reduce) {
.base-user-avatar,
.base-user-avatar-img {
transition: none;
}
.base-user-avatar:hover,
.base-user-avatar:focus-visible,
.base-user-avatar:active {
transform: none;
}
.base-user-avatar:hover .base-user-avatar-img,
.base-user-avatar:focus-visible .base-user-avatar-img {
transform: none;
}
}
</style>