fix(app): emoji as avatar

This commit is contained in:
Adam
2026-02-12 20:05:45 -06:00
parent c9719dff72
commit dec304a273

View File

@@ -1,5 +1,16 @@
import { type ComponentProps, splitProps, Show } from "solid-js"
const segmenter =
typeof Intl !== "undefined" && "Segmenter" in Intl
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
: undefined
function first(value: string) {
if (!value) return ""
if (!segmenter) return Array.from(value)[0] ?? ""
return segmenter.segment(value)[Symbol.iterator]().next().value?.segment ?? Array.from(value)[0] ?? ""
}
export interface AvatarProps extends ComponentProps<"div"> {
fallback: string
src?: string
@@ -36,7 +47,7 @@ export function Avatar(props: AvatarProps) {
...(!src && split.foreground ? { "--avatar-fg": split.foreground } : {}),
}}
>
<Show when={src} fallback={split.fallback?.[0]}>
<Show when={src} fallback={first(split.fallback)}>
{(src) => <img src={src()} draggable={false} data-slot="avatar-image" />}
</Show>
</div>