Part identity trigger
What this solves
Self-explaining action container. A part number by itself does not say it opens anything; the icon or the mono link style, plus a tooltip, tells the reader a click opens a preview before they commit to it.
Use it when
- A table cell or list row naming a part.Walmart's PartName (PartName.tsx:10-31), reused across the parts table and preview modal.
- A SKU that both peeks and can still be opened as a full page.Speedway's ProductLink (ProductLink.tsx:25-69): plain click peeks, modifier-click or the glyph navigates.
patterns/part-identity/example.tsxCopy this into a fresh route and it renders as above.
"use client";import { useState } from "react";import { RenderIcon, Tooltip } from "@versable-git/ui";// The two shipping faces of one trigger: an icon-led button that opens a// preview, and a mono SKU link whose plain click peeks while modifier-clicks// and the trailing glyph still navigate. Clicking any trigger sets the// opened part below, standing in for the real preview host both apps mount.function PartName({ partNumber, disabled, onOpen,}: { partNumber: string; disabled?: boolean; onOpen?: (id: string) => void;}) { return ( <Tooltip content={disabled ? "No preview available for this part" : `Preview Part ${partNumber}`}> <button type="button" disabled={disabled} className="group hover:text-primary focus-visible:ring-primary/50 inline-flex cursor-pointer items-center gap-1 rounded-sm whitespace-nowrap transition-colors focus-visible:ring-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-40" onClick={() => onOpen?.(partNumber)} > <RenderIcon Icon="Settings" size={12} className="text-base-content/30 group-hover:text-primary shrink-0 transition-colors" /> {partNumber} </button> </Tooltip> );}function ProductLink({ sku, disabled, onOpen }: { sku: string; disabled?: boolean; onOpen?: (id: string) => void }) { return ( <span className="inline-flex items-center gap-1"> <Tooltip content={disabled ? "No preview available for this SKU" : "Open preview"} placement="top"> <a href="#part" aria-disabled={disabled} className={ disabled ? "text-base-content/30 pointer-events-none font-mono text-sm" : "text-primary font-mono text-sm hover:underline" } onClick={(e) => { e.preventDefault(); onOpen?.(sku); }} > {sku} </a> </Tooltip> {!disabled && ( <a href="#part" title="Open full page" className="text-base-content/45 hover:text-primary text-xs"> ↗ </a> )} </span> );}export function PartIdentity() { const [opened, setOpened] = useState<string | null>(null); return ( <div className="flex flex-col gap-6"> <div className="flex flex-col gap-2"> <span className="text-base-content/45 text-xs font-medium tracking-wide uppercase">Icon-led preview button</span> <div className="flex gap-6 text-sm"> <PartName partNumber="BRK-2214" onOpen={setOpened} /> <PartName partNumber="LGT-0087" onOpen={setOpened} /> </div> </div> <div className="flex flex-col gap-2"> <span className="text-base-content/45 text-xs font-medium tracking-wide uppercase">Mono SKU link, peek on click</span> <div className="flex gap-6"> <ProductLink sku="AC-83001" onOpen={setOpened} /> <ProductLink sku="CH-11940" onOpen={setOpened} /> </div> </div> <div className="flex flex-col gap-2"> <span className="text-base-content/45 text-xs font-medium tracking-wide uppercase">Both faces, side by side</span> <div className="flex items-center gap-6 text-sm"> <PartName partNumber="FLT-5502" onOpen={setOpened} /> <ProductLink sku="FLT-5502" onOpen={setOpened} /> </div> </div> <div className="flex flex-col gap-2"> <span className="text-base-content/45 text-xs font-medium tracking-wide uppercase">Disabled, no preview</span> <div className="flex items-center gap-6 text-sm"> <PartName partNumber="OEM-9001" disabled /> <ProductLink sku="OEM-9001" disabled /> </div> </div> <div className="text-base-content/65 text-xs"> {opened != null ? ( <> Preview open: <span className="font-mono">{opened}</span> </> ) : ( "Click a trigger to open its preview." )} </div> </div> );}Where it ships
walmart-mvp/frontend/src/components/PartName.tsx:10-31RenderIcon plus Tooltip around a button; the glyph rests quiet gray and follows the text's hover colorspeedway/app/components/ProductLink.tsx:25-69mono SKU link: plain click peeks in place, modifier-clicks and the trailing glyph still navigate
App-specific: Both faces wire their click into a real preview host (walmart's PartPreviewModal, speedway's peek panel via useFilePreview-style hooks), and speedway's version keeps native navigation for middle-click and the trailing glyph. The demo stubs the handlers.