diff --git a/packages/ui/src/components/avatar.tsx b/packages/ui/src/components/avatar.tsx index 76bde1e15..c1617b265 100644 --- a/packages/ui/src/components/avatar.tsx +++ b/packages/ui/src/components/avatar.tsx @@ -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 } : {}), }} > - + {(src) => }