import { html } from "lit"; import { msg } from "@lit/localize"; import type { BuilderComponent } from "../../types/BuilderComponent"; import "../../assets/shoelaceImports"; const DEFAULT_LABEL = "Button"; const DEFAULT_ICON = ""; const DEFAULT_ICON_COLOR = "#0f172a"; const DEFAULT_LABEL_COLOR = "#0f172a"; export const ButtonComponent: BuilderComponent = { type: "button", label: () => msg("Button"), group: "buttons", defaultData: { label: DEFAULT_LABEL, icon: DEFAULT_ICON, iconColor: DEFAULT_ICON_COLOR, labelColor: DEFAULT_LABEL_COLOR, borderless: false, }, render(data) { const labelRaw = data?.label ?? DEFAULT_LABEL; const label = String(labelRaw); const hasLabel = label.trim().length > 0; const icon = data?.icon ?? DEFAULT_ICON; const hasIcon = !!icon; const iconColor = data?.iconColor ?? DEFAULT_ICON_COLOR; const labelColor = data?.labelColor ?? DEFAULT_LABEL_COLOR; const borderless = !!data?.borderless; return html` `; }, bindings: () => [ { key: "label", label: msg("Button text"), kind: "text", target: "span", placeholder: msg("Button label"), }, ], settings: ({ data, setData }) => { const icon = data?.icon ?? DEFAULT_ICON; const iconColor = data?.iconColor ?? DEFAULT_ICON_COLOR; const labelColor = data?.labelColor ?? DEFAULT_LABEL_COLOR; const borderless = !!data?.borderless; const reset = () => { setData({ label: DEFAULT_LABEL, icon: DEFAULT_ICON, iconColor: DEFAULT_ICON_COLOR, labelColor: DEFAULT_LABEL_COLOR, }); }; return html`

${msg("Button")}

setData({ icon: e.detail?.name ?? "", iconColor: e.detail?.color ?? DEFAULT_ICON_COLOR, })} > ${msg("Reset button")}
setData({ labelColor: (e.target as HTMLInputElement).value })} style=" width: 32px; height: 32px; border: 1px solid var(--sl-color-neutral-300); border-radius: 6px; padding: 2px; cursor: pointer; background: none; " /> { const val = String(e.target.value ?? "").trim(); if (/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(val)) { setData({ labelColor: val }); } }} >
setData({ borderless: Boolean(e.target.checked) })} > ${msg("hide border")}
`; }, };