import React from "react"; import { Info } from "lucide-react"; import type { ElementLibraryCategory, ElementType } from "../../../types/labelTemplate"; import { elementLibraryCategoryPanelTitle, LABEL_EDITOR_FONT_FAMILY, } from "../../../types/labelTemplate"; /** 左侧标签库:四类分组(与产品图一致);打印时输入项可带 config 以正确显示为 input */ const ELEMENT_CATEGORIES: { title: ElementLibraryCategory; subtitle?: string; items: { label: string; type: ElementType; config?: Record; disabled?: boolean }[]; }[] = [ { title: "Template", items: [ { label: "Text", type: "TEXT_STATIC" }, { label: "QR Code", type: "QRCODE" }, { label: "Barcode", type: "BARCODE" }, { label: "Blank Space", type: "BLANK" }, { label: "Price", type: "TEXT_PRICE" }, { label: "Image", type: "IMAGE" }, { label: "Logo", type: "IMAGE" }, ], }, { title: "Label", items: [ { label: "Label Name", type: "TEXT_PRODUCT" }, { label: "Text", type: "TEXT_STATIC" }, { label: "QR Code", type: "QRCODE" }, { label: "Barcode", type: "BARCODE" }, { label: "Nutrition Facts", type: "NUTRITION" }, { label: "Price", type: "TEXT_PRICE" }, { label: "Duration Date", type: "DATE" }, { label: "Duration Time", type: "TIME" }, { label: "Duration", type: "DURATION" }, { label: "Image", type: "IMAGE" }, { label: "Label Type", type: "TEXT_STATIC" }, { label: "How-to", type: "TEXT_STATIC", disabled: true }, { label: "Expiration Alert", type: "TEXT_STATIC", disabled: true }, ], }, { title: "Auto-generated", items: [ { label: "Company", type: "TEXT_STATIC", config: { companyIncludeFields: ["address", "city", "state", "zip", "email"] } }, { label: "Employee", type: "TEXT_STATIC" }, { label: "Current Date", type: "DATE" }, { label: "Current Time", type: "TIME" }, { label: "Label ID", type: "TEXT_STATIC", config: { prefix: "LABEL ID: ", text: "LABEL ID: ", fontSize: 10, textAlign: "left" } }, ], }, { title: "Print input", items: [ { label: "Text", type: "TEXT_STATIC", config: { inputType: "text" } }, { label: "Weight", type: "WEIGHT" }, { label: "Number", type: "TEXT_STATIC", config: { inputType: "number", text: "0" } }, { label: "Date & Time", type: "DATE", config: { inputType: "datetime", format: "YYYY-MM-DD HH:mm" } }, { label: "Multiple Options", type: "TEXT_STATIC", config: { inputType: "options", multipleOptionId: "", selectedOptionValues: [], text: "Text", fontFamily: LABEL_EDITOR_FONT_FAMILY, fontSize: 14, fontWeight: "normal", textAlign: "left", }, }, ], }, ]; interface ElementsPanelProps { onAddElement: ( type: ElementType, configOverride: Partial> | undefined, libraryCategory: ElementLibraryCategory, paletteItemLabel: string, ) => void; } /** 各分组:无底色,蓝色细实线边框 */ function sectionSurfaceStyle(): React.CSSProperties { return { backgroundColor: "transparent", border: "1px solid #93c5fd", borderRadius: 8, padding: 8, }; } const ELEMENT_LIBRARY_HELP_SECTIONS = [ { title: "For Template", body: "When you add these items to your template, the text will be the same on all labels that use this template.", }, { title: "For Label", body: "When you add these items to your template, the text will be different on each of the labels that use this template. For example, if you use Label Name as one of your items, one label may have the text 'Chicken' and another 'Pork.'", }, { title: "Entered Automatically", body: "When you add these items to your template, the printed text will be automatically changed according to various factors (location, employee, date, time, product, etc.).", }, { title: "Entered When Printing", body: "The person printing the label will use these items to add information to the label at the time of printing.", }, ] as const; function ElementsPanelHelp() { return (

Click on an item above to add it to your template. Once an item has been placed into your template, there may be additional options for you to select.

{ELEMENT_LIBRARY_HELP_SECTIONS.map((section) => (

{section.title}

{section.body}

))}
); } /** * 左侧元素库。纵向滚动由父级(index 左侧列容器)的 overflow-y:auto 负责, * 避免预编译 CSS 缺少 min-h-0 / flex-1 时内层滚动高度为 0 导致底部橙色区被裁切。 */ export function ElementsPanel({ onAddElement }: ElementsPanelProps) { return (
Elements
{ELEMENT_CATEGORIES.map((cat) => (
{elementLibraryCategoryPanelTitle(cat.title)}
{cat.subtitle ? (
{cat.subtitle}
) : null}
{cat.items.map((item, i) => { const isDisabled = item.disabled === true; return ( ); })}
))}
); }