caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

90 lines
1.9 KiB
TypeScript

/**
* Avatar primitive — circular image or fallback initials.
* No emoji. Explicit types.
*/
import {
Image,
StyleSheet,
Text,
View,
type ImageStyle,
type StyleProp,
type ViewStyle,
} from "react-native";
import { colors } from "@/components/me/theme";
import { weight } from "@/src/shared/theme";
export type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl";
const SIZE_MAP: Record<AvatarSize, number> = {
xs: 24,
sm: 32,
md: 40,
lg: 56,
xl: 72,
};
export interface AvatarProps {
/** Remote image URI. */
uri?: string;
/** Name used to derive initials when no image is available. */
name?: string;
size?: AvatarSize;
style?: StyleProp<ImageStyle & ViewStyle>;
}
function initials(name: string): string {
const parts = name.trim().split(/\s+/).filter(Boolean);
if (parts.length === 0) return "?";
if (parts.length === 1) return (parts[0]?.slice(0, 2) ?? "?").toUpperCase();
return `${parts[0]?.charAt(0) ?? ""}${parts[parts.length - 1]?.charAt(0) ?? ""}`.toUpperCase();
}
export function Avatar({
uri,
name = "",
size = "md",
style,
}: AvatarProps): React.JSX.Element {
const dim = SIZE_MAP[size];
const circle = { width: dim, height: dim, borderRadius: dim / 2 };
if (uri) {
return (
<Image
source={{ uri }}
style={[styles.image, circle] as ImageStyle[]}
accessibilityLabel={name || "Avatar"}
/>
);
}
return (
<View
style={[styles.fallback, circle]}
accessibilityLabel={name || "Avatar"}
>
<Text style={[styles.initials, { fontSize: dim * 0.34 }]}>
{initials(name)}
</Text>
</View>
);
}
const styles = StyleSheet.create({
image: { backgroundColor: colors.cardAlt },
fallback: {
backgroundColor: colors.cardAlt,
borderWidth: 1,
borderColor: colors.border,
alignItems: "center",
justifyContent: "center",
},
initials: {
color: colors.textSecondary,
fontWeight: weight.bold,
},
});