Skip to content

Commit dec304a

Browse files
committed
fix(app): emoji as avatar
1 parent c9719df commit dec304a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/ui/src/components/avatar.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { type ComponentProps, splitProps, Show } from "solid-js"
22

3+
const segmenter =
4+
typeof Intl !== "undefined" && "Segmenter" in Intl
5+
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
6+
: undefined
7+
8+
function first(value: string) {
9+
if (!value) return ""
10+
if (!segmenter) return Array.from(value)[0] ?? ""
11+
return segmenter.segment(value)[Symbol.iterator]().next().value?.segment ?? Array.from(value)[0] ?? ""
12+
}
13+
314
export interface AvatarProps extends ComponentProps<"div"> {
415
fallback: string
516
src?: string
@@ -36,7 +47,7 @@ export function Avatar(props: AvatarProps) {
3647
...(!src && split.foreground ? { "--avatar-fg": split.foreground } : {}),
3748
}}
3849
>
39-
<Show when={src} fallback={split.fallback?.[0]}>
50+
<Show when={src} fallback={first(split.fallback)}>
4051
{(src) => <img src={src()} draggable={false} data-slot="avatar-image" />}
4152
</Show>
4253
</div>

0 commit comments

Comments
 (0)