import { html } from "lit"; import { msg } from "@lit/localize"; import type { BuilderComponent } from "../../types/BuilderComponent"; import { FONT_OPTIONS } from "../../builder/data/data"; const DEFAULT_FONT = "system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif"; const DEFAULT_WIDTH = "320px"; const DEFAULT_HEIGHT = "40px"; export const TextareaComponent: BuilderComponent = { type: "textarea", label: () => msg("Textarea"), group: "text", defaultData: { font: DEFAULT_FONT, color: "#000000", placeholder: msg("Enter text…"), "font-weight": "normal", width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, "font-size": "1em", }, render: (data) => { const font = typeof data?.font === "string" && data.font.trim() ? data.font : DEFAULT_FONT; const color = data?.color ?? "#000000"; const placeholder = data?.placeholder ?? msg("Enter text…"); const fontWeight = data?.["font-weight"] ?? "normal"; const width = data?.width ?? DEFAULT_WIDTH; const height = data?.height ?? DEFAULT_HEIGHT; const fontSize = data?.["font-size"] ?? "1em"; return html` `; }, bindings: () => [ { key: "placeholder", label: msg("Textarea placeholder"), kind: "text", target: "sl-textarea", placeholder: msg("Enter textarea placeholder…"), }, { key: "color", label: msg("Text color"), kind: "style", target: "sl-textarea", name: "color", placeholder: "#000000", }, { key: "font-weight", label: msg("Font weight"), kind: "style", target: "sl-textarea", name: "font-weight", placeholder: `${msg("e.g.")} 400 ${msg("or")} bold`, }, { key: "width", label: msg("Width (e.g. 320px, 60%)"), kind: "style", target: "sl-textarea", name: "width", placeholder: DEFAULT_WIDTH, }, { key: "height", label: msg("Height (e.g. 120px)"), kind: "style", target: "sl-textarea", name: "height", placeholder: DEFAULT_HEIGHT, }, { key: "font-size", label: msg("Font size"), kind: "style", target: "sl-textarea", name: "font-size", placeholder: `${msg("e.g.")} 32px ${msg("or")} 2em`, } ], settings: ({ data, setData }) => { const current = (data?.font as string) ?? DEFAULT_FONT; const currentLabel = FONT_OPTIONS.find((f) => f.value === current)?.label ?? msg("Choose font"); return html`

${msg("Typography")}

${msg("Font")}
${currentLabel} { const item = e.detail.item as any; const next = String(item?.value ?? ""); if (next) setData({ font: next }); }} > ${FONT_OPTIONS.map( (f) => html` ${f.label} `, )}
setData({ font: DEFAULT_FONT })} > ${msg("Reset font")}
`; }, };