Blame view

美国版/Food Labeling Management Platform/src/components/labels/LabelTemplateEditor/ElementsPanel.tsx 7.16 KB
6ce07406   杨鑫   提交
1
  import React from "react";
540ac0e3   杨鑫   前端修改bug
2
  import { Info } from "lucide-react";
6ce07406   杨鑫   提交
3
  import type { ElementLibraryCategory, ElementType } from "../../../types/labelTemplate";
540ac0e3   杨鑫   前端修改bug
4
5
6
7
  import {
    elementLibraryCategoryPanelTitle,
    LABEL_EDITOR_FONT_FAMILY,
  } from "../../../types/labelTemplate";
884054fb   “wangming”   项目初始化
8
9
10
  
  /** 左侧标签库:四类分组(与产品图一致);打印时输入项可带 config 以正确显示为 input */
  const ELEMENT_CATEGORIES: {
143afd59   杨鑫   打印,标签
11
    title: ElementLibraryCategory;
884054fb   “wangming”   项目初始化
12
    subtitle?: string;
540ac0e3   杨鑫   前端修改bug
13
    items: { label: string; type: ElementType; config?: Record<string, unknown>; disabled?: boolean }[];
884054fb   “wangming”   项目初始化
14
15
  }[] = [
    {
6ce07406   杨鑫   提交
16
      title: "Template",
884054fb   “wangming”   项目初始化
17
      items: [
6ce07406   杨鑫   提交
18
19
20
21
22
23
24
        { 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" },
884054fb   “wangming”   项目初始化
25
26
27
      ],
    },
    {
6ce07406   杨鑫   提交
28
      title: "Label",
884054fb   “wangming”   项目初始化
29
      items: [
6ce07406   杨鑫   提交
30
31
32
33
34
35
36
37
38
39
40
        { 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" },
540ac0e3   杨鑫   前端修改bug
41
42
        { label: "How-to", type: "TEXT_STATIC", disabled: true },
        { label: "Expiration Alert", type: "TEXT_STATIC", disabled: true },
884054fb   “wangming”   项目初始化
43
44
45
      ],
    },
    {
6ce07406   杨鑫   提交
46
      title: "Auto-generated",
884054fb   “wangming”   项目初始化
47
      items: [
540ac0e3   杨鑫   前端修改bug
48
        { label: "Company", type: "TEXT_STATIC", config: { companyIncludeFields: ["address", "city", "state", "zip", "email"] } },
6ce07406   杨鑫   提交
49
50
51
        { label: "Employee", type: "TEXT_STATIC" },
        { label: "Current Date", type: "DATE" },
        { label: "Current Time", type: "TIME" },
540ac0e3   杨鑫   前端修改bug
52
        { label: "Label ID", type: "TEXT_STATIC", config: { prefix: "LABEL ID: ", text: "LABEL ID: ", fontSize: 10, textAlign: "left" } },
884054fb   “wangming”   项目初始化
53
54
55
      ],
    },
    {
6ce07406   杨鑫   提交
56
      title: "Print input",
884054fb   “wangming”   项目初始化
57
      items: [
6ce07406   杨鑫   提交
58
59
60
61
        { 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" } },
3d4c10ac   杨鑫   对接,标签产品
62
        {
6ce07406   杨鑫   提交
63
64
          label: "Multiple Options",
          type: "TEXT_STATIC",
3d4c10ac   杨鑫   对接,标签产品
65
          config: {
6ce07406   杨鑫   提交
66
67
            inputType: "options",
            multipleOptionId: "",
3d4c10ac   杨鑫   对接,标签产品
68
            selectedOptionValues: [],
6ce07406   杨鑫   提交
69
            text: "Text",
540ac0e3   杨鑫   前端修改bug
70
            fontFamily: LABEL_EDITOR_FONT_FAMILY,
3d4c10ac   杨鑫   对接,标签产品
71
            fontSize: 14,
6ce07406   杨鑫   提交
72
73
            fontWeight: "normal",
            textAlign: "left",
3d4c10ac   杨鑫   对接,标签产品
74
75
          },
        },
884054fb   “wangming”   项目初始化
76
77
78
79
80
      ],
    },
  ];
  
  interface ElementsPanelProps {
143afd59   杨鑫   打印,标签
81
82
83
84
85
86
    onAddElement: (
      type: ElementType,
      configOverride: Partial<Record<string, unknown>> | undefined,
      libraryCategory: ElementLibraryCategory,
      paletteItemLabel: string,
    ) => void;
884054fb   “wangming”   项目初始化
87
88
  }
  
540ac0e3   杨鑫   前端修改bug
89
90
  /** 各分组:无底色,蓝色细实线边框 */
  function sectionSurfaceStyle(): React.CSSProperties {
63289723   杨鑫   提交
91
    return {
540ac0e3   杨鑫   前端修改bug
92
93
      backgroundColor: "transparent",
      border: "1px solid #93c5fd",
63289723   杨鑫   提交
94
95
96
97
98
      borderRadius: 8,
      padding: 8,
    };
  }
  
540ac0e3   杨鑫   前端修改bug
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  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 (
      <div className="mx-2 mb-3 flex gap-2 rounded-md bg-gray-100 px-3 py-3">
        <Info className="mt-0.5 h-4 w-4 shrink-0 text-gray-500" aria-hidden />
        <div className="min-w-0 space-y-3 text-[11px] leading-relaxed text-gray-600">
          <p>
            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.
          </p>
          {ELEMENT_LIBRARY_HELP_SECTIONS.map((section) => (
            <div key={section.title}>
              <p className="font-semibold text-gray-700">{section.title}</p>
              <p className="mt-0.5">{section.body}</p>
            </div>
          ))}
        </div>
      </div>
    );
  }
  
6ce07406   杨鑫   提交
142
143
144
145
  /**
   * 左侧元素库。纵向滚动由父级(index 左侧列容器)的 overflow-y:auto 负责,
   * 避免预编译 CSS 缺少 min-h-0 / flex-1 时内层滚动高度为 0 导致底部橙色区被裁切。
   */
884054fb   “wangming”   项目初始化
146
147
  export function ElementsPanel({ onAddElement }: ElementsPanelProps) {
    return (
6ce07406   杨鑫   提交
148
      <div className="border-r border-slate-200 bg-slate-50">
540ac0e3   杨鑫   前端修改bug
149
        <div className="border-b border-[#93c5fd] bg-white px-2 py-2 text-sm font-semibold text-slate-800">
884054fb   “wangming”   项目初始化
150
151
          Elements
        </div>
6ce07406   杨鑫   提交
152
153
        <div className="p-2 space-y-3">
          {ELEMENT_CATEGORIES.map((cat) => (
540ac0e3   杨鑫   前端修改bug
154
155
156
157
            <div key={cat.title} style={sectionSurfaceStyle()}>
              <div className="px-2 py-1 text-xs font-semibold leading-snug text-gray-700">
                {elementLibraryCategoryPanelTitle(cat.title)}
              </div>
6ce07406   杨鑫   提交
158
159
160
161
              {cat.subtitle ? (
                <div className="px-2 py-0.5 text-[10px] text-gray-400">{cat.subtitle}</div>
              ) : null}
              <div className="mt-0.5 grid grid-cols-2 gap-1">
540ac0e3   杨鑫   前端修改bug
162
163
164
                {cat.items.map((item, i) => {
                  const isDisabled = item.disabled === true;
                  return (
6ce07406   杨鑫   提交
165
166
167
                  <button
                    key={`${cat.title}-${item.label}-${i}`}
                    type="button"
540ac0e3   杨鑫   前端修改bug
168
169
170
171
172
173
174
175
176
177
178
179
180
                    disabled={isDisabled}
                    aria-disabled={isDisabled}
                    title={isDisabled ? "Not available in the US version" : undefined}
                    onClick={
                      isDisabled
                        ? undefined
                        : () => onAddElement(item.type, item.config, cat.title, item.label)
                    }
                    className={
                      isDisabled
                        ? "items-start justify-start whitespace-normal break-words rounded border border-transparent px-2 py-1.5 text-left text-xs leading-snug cursor-not-allowed text-gray-400 bg-gray-100/70 opacity-60"
                        : "items-start justify-start whitespace-normal break-words rounded border border-transparent px-2 py-1.5 text-left text-xs leading-snug hover:border-gray-200 hover:bg-gray-100"
                    }
6ce07406   杨鑫   提交
181
182
183
                  >
                    {item.label}
                  </button>
540ac0e3   杨鑫   前端修改bug
184
185
                  );
                })}
884054fb   “wangming”   项目初始化
186
              </div>
6ce07406   杨鑫   提交
187
188
            </div>
          ))}
540ac0e3   杨鑫   前端修改bug
189
          <ElementsPanelHelp />
6ce07406   杨鑫   提交
190
        </div>
884054fb   “wangming”   项目初始化
191
192
193
      </div>
    );
  }