功能迭代
This commit is contained in:
1 parent
8e03c99cab
commit
9e87a4002a
23 files changed
+553
-38
No files matched your search
+18
-9
@@ -118,6 +118,21 @@ function normalizeRichTextHtml(content?: string): string {
|
||||
decoded = decoded.replace(/^\s*<pre><code>/i, "").replace(/<\/code><\/pre>(?:<p><\/p>)?\s*$/i, "");
|
||||
return sanitizeRichTextHtml(decoded);
|
||||
}
|
||||
|
||||
/** 渲染富文本并允许点击其中的图片进行全屏放大。 */
|
||||
function ZoomableRichContent({ content, className = "content" }: { content?: string; className?: string }) {
|
||||
const [zoomUrl, setZoomUrl] = useState("");
|
||||
const openImage = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||
if (event.target instanceof HTMLImageElement) setZoomUrl(event.target.src);
|
||||
};
|
||||
return <>
|
||||
<div className={className} onClick={openImage} dangerouslySetInnerHTML={{ __html: normalizeRichTextHtml(content) }} />
|
||||
{zoomUrl && <div className="product-lightbox" role="presentation" onClick={() => setZoomUrl("")}>
|
||||
<button type="button" aria-label="Close enlarged image" onClick={() => setZoomUrl("")}><X size={22}/></button>
|
||||
<img src={zoomUrl} alt="Enlarged content" onClick={(event) => event.stopPropagation()} />
|
||||
</div>}
|
||||
</>;
|
||||
}
|
||||
function setMeta(name: string, content?: string) {
|
||||
const selector = `meta[name="${name}"]`;
|
||||
let element = document.head.querySelector<HTMLMetaElement>(selector);
|
||||
@@ -514,10 +529,7 @@ function Collection({
|
||||
<h1>{d.productName || d.title}</h1>
|
||||
<p className="lead">{d.summary}</p>
|
||||
{d.attributes?.length > 0 && <section className="specs"><h2>Product attributes</h2>{d.attributes.map((a:any,i:number)=><div key={i}><span>{a.name}</span><strong>{a.value} {a.unit}</strong></div>)}</section>}
|
||||
<div
|
||||
className="content"
|
||||
dangerouslySetInnerHTML={{ __html: normalizeRichTextHtml(d.content) }}
|
||||
/>
|
||||
<ZoomableRichContent content={d.content} />
|
||||
{d.specifications?.length > 0 && (
|
||||
<section className="specs">
|
||||
<h2>Technical specifications</h2>
|
||||
@@ -698,7 +710,7 @@ function ProductDetailView({ data: d, configuration }: { data: Record<string, an
|
||||
<button type="button" role="tab" aria-selected={activeProductTab === "SPECIFICATIONS"} className={activeProductTab === "SPECIFICATIONS" ? "active" : ""} onClick={() => setActiveProductTab("SPECIFICATIONS")}>Specifications</button>
|
||||
</div>
|
||||
{activeProductTab === "DETAILS" ? (
|
||||
<div className="content product-content" role="tabpanel" dangerouslySetInnerHTML={{__html:normalizeRichTextHtml(d.content)}}/>
|
||||
<ZoomableRichContent content={d.content} className="content product-content" />
|
||||
) : (
|
||||
<div className="product-specification-panel" role="tabpanel">
|
||||
{specifications.length > 0 ? specifications.map((spec:any,index:number)=><div className="product-specification-row" key={`${spec.groupName}-${spec.name}-${index}`}><span>{spec.groupName || "General"}</span><strong>{spec.name}</strong><em>{spec.value} {spec.unit}</em></div>) : <p className="product-tab-empty">Specifications are being prepared.</p>}
|
||||
@@ -794,10 +806,7 @@ function ConfiguredPage({ slug }: { slug: string }) {
|
||||
<p className="eyebrow">{agreementPage ? "LEGAL INFORMATION" : "COMPANY INFORMATION"}</p>
|
||||
<h1>{data.pageName}</h1>
|
||||
{data.summary && <p className="lead">{data.summary}</p>}
|
||||
<div
|
||||
className="content"
|
||||
dangerouslySetInnerHTML={{ __html: normalizeRichTextHtml(data.content) }}
|
||||
/>
|
||||
<ZoomableRichContent content={data.content} />
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user