Review

Auto-fit type on digital shelf-label preview

PriceTag Studio's ESL (electronic shelf label) preview was clipping long unit prices on the 2" face. Measure the chip with ResizeObserver and scale font + padding so the price always fills the available width during merchandising review.

ReactTier 2reactresize-observerfrontend

Click a line to flag it, pick one or more labels, then submit. If the change looks correct, approve it.

components/pricing/ShelfLabelPreview.tsx+21-1
1414export function ShelfLabelPreview({ sku, price, unit, promo }: Props) {
15+ const chipRef = useRef<HTMLDivElement>(null);
16+ const [typeScale, setTypeScale] = useState(1);
1517
18+ useEffect(() => {
19+ const el = chipRef.current;
20+ if (!el) return;
21+ const ro = new ResizeObserver(([entry]) => {
22+ const w = entry.contentRect.width;
23+ // Fit price type to the chip so long unit strings don't overflow the 2" ESL face
24+ setTypeScale(Math.min(1.4, Math.max(0.75, w / 160)));
25+ });
26+ ro.observe(el);
27+ return () => ro.disconnect();
28+ }, []);
1629
1730 return (
18- <div className="esl-chip">
31+ <div
32+ ref={chipRef}
33+ className="esl-chip"
34+ style={{
35+ fontSize: `${Math.round(14 * typeScale)}px`,
36+ padding: `${Math.round(8 * typeScale)}px ${Math.round(12 * typeScale)}px`,
37+ }}
38+ >
1939 <span className="esl-sku">{sku}</span>
2040 <span className="esl-price">{price}<small>/{unit}</small></span>
2141 {promo ? <span className="esl-promo">{promo}</span> : null}
2242 </div>
2343 );
2444}