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.3 KB
Raw Blame
import { useId } from 'react'

import { Field, Input } from '@posthog/quill'

import type { ChartOptionTextInputProps } from './ChartOptionTextInput'
import { QuillChartOptionLabel } from './QuillChartOptionLabel'

export interface QuillChartOptionTextInputProps extends ChartOptionTextInputProps {
    draft: string
    setDraft: (draft: string) => void
    commit: () => void
}

export function QuillChartOptionTextInput({
    label,
    info,
    placeholder,
    draft,
    setDraft,
    commit,
    'data-attr': dataAttr,
}: QuillChartOptionTextInputProps): JSX.Element {
    const id = useId()

    return (
        <Field orientation="horizontal" className="justify-between">
            {label && <QuillChartOptionLabel htmlFor={id} label={label} info={info} />}
            <Input
                id={id}
                className={label ? 'w-28' : undefined}
                value={draft}
                placeholder={placeholder}
                onChange={(event) => setDraft(event.target.value)}
                onBlur={commit}
                onKeyDown={(event) => {
                    if (event.key === 'Enter') {
                        commit()
                    }
                }}
                data-attr={dataAttr}
            />
        </Field>
    )
}