Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.1 KB
Raw Blame
import clsx from 'clsx'
import React, { useState } from 'react'

import { backendAssetUrl } from 'lib/utils/apiHost'

import { LemonSkeleton } from '../LemonSkeleton'
import { Lettermark } from '../Lettermark'

export interface UploadedLogoProps {
    name: string
    /**
     * When mediaId is not provided, a lettermark is used for the logo.
     * The optional entity ID determines which lettermark color is used.
     * If a string is provided, it will be treated as a UUID (the last 4 bytes will be used as the entity ID).
     */
    entityId: number | string
    mediaId?: string | null
    /** @default 'medium' */
    size?: 'xsmall' | 'small' | 'medium' | 'xlarge'
    /** Use the outlined lettermark for signifying projects, to differentiate them from organizations. */
    outlinedLettermark?: boolean
}

export const UploadedLogo = React.forwardRef<HTMLDivElement, UploadedLogoProps>(function UploadedLogo(
    { name, mediaId, entityId, size = 'medium', outlinedLettermark },
    ref
) {
    const [isLoadingImage, setIsLoadingImage] = useState(true)

    if (!mediaId) {
        return <Lettermark index={entityId} name={name} size={size} outlined={outlinedLettermark} />
    }

    return (
        <div
            className={clsx(
                'relative flex shrink-0 overflow-hidden select-none',
                size === 'xlarge'
                    ? 'size-16 rounded before:absolute before:inset-0 before:border before:rounded'
                    : size === 'medium'
                      ? 'size-6 rounded-xs'
                      : size === 'small'
                        ? 'size-5 rounded-xs'
                        : 'size-4 rounded-xs'
            )}
            ref={ref}
        >
            {isLoadingImage && <LemonSkeleton className="absolute inset-0" />}
            <img
                className="size-full object-cover"
                src={mediaId.startsWith('data:') ? mediaId : backendAssetUrl(`/uploaded_media/${mediaId}`)}
                alt="Uploaded logo"
                onError={() => setIsLoadingImage(false)}
                onLoad={() => setIsLoadingImage(false)}
            />
        </div>
    )
})