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.

1.7 KB
Raw Blame
import { Suspense } from 'react'

import { Spinner } from 'lib/lemon-ui/Spinner/Spinner'
import { lazyWithRetry } from 'lib/utils/retryImport'

export interface TextCardModalBodyFieldProps {
    shouldUseLegacyMarkdownEditor: boolean
    value: string | undefined
    onChange: (value: string) => void
}

const LazyLegacyMarkdownEditor = lazyWithRetry(() =>
    import('lib/components/LemonTextAreaMarkdown/LemonTextAreaMarkdown').then((m) => ({
        default: m.LemonTextAreaMarkdown,
    }))
)

const LazyRichMarkdownEditor = lazyWithRetry(() =>
    import('lib/components/Cards/TextCard/TextCardMarkdownEditor').then((m) => ({
        default: m.TextCardMarkdownEditor,
    }))
)

export function TextCardModalBodyField({
    shouldUseLegacyMarkdownEditor,
    value,
    onChange,
}: TextCardModalBodyFieldProps): JSX.Element {
    return (
        <Suspense
            fallback={
                <div
                    className="flex min-h-[12rem] w-full items-center justify-center rounded border border-primary bg-surface-secondary"
                    aria-busy
                    data-attr="text-card-editor-suspense-fallback"
                >
                    <Spinner className="text-2xl" />
                </div>
            }
        >
            {shouldUseLegacyMarkdownEditor ? (
                <LazyLegacyMarkdownEditor
                    value={value}
                    onChange={onChange}
                    maxLength={4000}
                    minRows={8}
                    maxRows={36}
                    data-attr="text-card-edit-area"
                />
            ) : (
                <LazyRichMarkdownEditor value={value} onChange={onChange} minRows={8} maxRows={36} />
            )}
        </Suspense>
    )
}