import { onMount, Show, splitProps, type JSX } from "solid-js" import { Button } from "./button" import { Icon } from "./icon" import { useI18n } from "../context/i18n" export type LineCommentVariant = "default" | "editor" export type LineCommentAnchorProps = { id?: string top?: number open: boolean variant?: LineCommentVariant onClick?: JSX.EventHandlerUnion onMouseEnter?: JSX.EventHandlerUnion onPopoverFocusOut?: JSX.EventHandlerUnion class?: string popoverClass?: string children: JSX.Element } export const LineCommentAnchor = (props: LineCommentAnchorProps) => { const hidden = () => props.top === undefined const variant = () => props.variant ?? "default" return (
{props.children}
) } export type LineCommentProps = Omit & { comment: JSX.Element selection: JSX.Element } export const LineComment = (props: LineCommentProps) => { const i18n = useI18n() const [split, rest] = splitProps(props, ["comment", "selection"]) return (
{split.comment}
{i18n.t("ui.lineComment.label.prefix")} {split.selection} {i18n.t("ui.lineComment.label.suffix")}
) } export type LineCommentEditorProps = Omit & { value: string selection: JSX.Element onInput: (value: string) => void onCancel: VoidFunction onSubmit: (value: string) => void placeholder?: string rows?: number autofocus?: boolean cancelLabel?: string submitLabel?: string } export const LineCommentEditor = (props: LineCommentEditorProps) => { const i18n = useI18n() const [split, rest] = splitProps(props, [ "value", "selection", "onInput", "onCancel", "onSubmit", "placeholder", "rows", "autofocus", "cancelLabel", "submitLabel", ]) const refs = { textarea: undefined as HTMLTextAreaElement | undefined, } const focus = () => refs.textarea?.focus() const submit = () => { const value = split.value.trim() if (!value) return split.onSubmit(value) } onMount(() => { if (split.autofocus === false) return requestAnimationFrame(focus) }) return ( focus()}>