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";
export const Heading1: BuilderComponent = {
type: "h1",
label: () => msg("Heading 1"),
group: "text",
defaultData: {
font: DEFAULT_FONT,
},
render: (data) => {
const font = data?.font ?? DEFAULT_FONT;
const color = data?.color ?? "#000000";
const content = data?.content ?? msg("Heading 1");
const fontWeight = data?.["font-weight"] ?? "normal";
const fontSize = data?.["font-size"] ?? "2em";
return html`
${content}
`;
},
bindings: () => [
{
key: "content",
label: msg("Heading text"),
kind: "text",
target: "h1",
placeholder: msg("Enter heading…"),
},
{
key: "color",
label: msg("Text color"),
kind: "style",
target: "h1",
name: "color",
placeholder: "#000000",
},
{
key: "font-weight",
label: msg("Font weight"),
kind: "style",
target: "h1",
name: "font-weight",
placeholder: `${msg("e.g.")} 400 ${msg("or")} bold`,
},
{
key: "font-size",
label: msg("Font size"),
kind: "style",
target: "h1",
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")}
`;
},
};