Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | 1x 1x 1x 1x 1x 15x 1x 14x 1x 13x 1x 12x 15x 15x 15x 1x 11x 22x 4x 12x 11x 11x 11x 11x 11x 11x 1x 2x 24x 24x 24x 24x 24x 24x 24x 35x 35x 35x 35x 35x 35x 35x 35x 35x 70x 70x 70x 70x 70x 35x 35x 31x 35x 35x 4x 35x 35x 35x 35x 35x 70x 70x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x | import { useEffect, useId, useRef, useState } from 'react';
import {
MECHANISM_PATHS,
recommendForHook,
resolveHookMetadata,
resolveHookPrefix,
} from '../property-metadata.js';
import type { DemandTier, MechanismPathKey, Recommendation, RiskTier } from '../property-metadata.js';
import {
CATEGORY_LABEL,
COMPONENT_ROOT_KEY,
buildHookTree,
buildThemeCoverage,
buildThemeScopedHookTree,
computeCoverage,
computeValueDivergence,
humanizeElement,
humanizeProperty,
orderedCategoryKeys,
orderedElementKeys,
orderedPropertyKeys,
totalHooksInCategory,
type ThemeCoverage,
type ThemeData,
} from '../hook-tree.js';
/**
* HookAPI — read-only, host-agnostic view of a component's public
* `--slds-c-*` hook API. Tree shape: category → element → property axis
* → hook (with risk, demand, theme coverage, value divergence). A
* second section below mirrors the shape for theme-scoped hooks (read
* by one theme only). Consumers fetch `themeData/<component>.json` and
* pass it in.
*/
export interface HookAPIProps {
/** camelCase component directory name (e.g. `pill`, `progressBar`). */
componentKey: string;
/** Theme-layer build output. `null` → guidance message. */
themeData: ThemeData | null;
/** Theme-scoped section projects against this; falls back to `cosmos` or the first theme. */
activeTheme?: string;
loading?: boolean;
}
// Risk and demand both color-code by tier but invert which tier is "good":
// risk low = good; demand high = good.
type Semantic = 'good' | 'caution' | 'bad' | 'neutral' | 'unknown';
const RISK_TIER_TO_SEMANTIC: Record<RiskTier, Semantic> = {
low: 'good',
medium: 'caution',
high: 'bad',
unknown: 'unknown',
};
const DEMAND_TIER_TO_SEMANTIC: Record<DemandTier, Semantic> = {
high: 'good',
medium: 'caution',
low: 'bad',
none: 'neutral',
unknown: 'unknown',
};
const TIER_LABELS: Record<RiskTier | DemandTier, string> = {
low: 'Low',
medium: 'Medium',
high: 'High',
none: 'None',
unknown: 'Unknown',
};
const POPOVER_OPEN_DELAY_MS = 120;
const POPOVER_CLOSE_DELAY_MS = 200;
// ─── Public API ────────────────────────────────────────────────────────
export function HookAPI({ componentKey, themeData, activeTheme, loading = false }: HookAPIProps) {
if (loading) {
return <EmptyState>Loading hook API…</EmptyState>;
}
if (!componentKey) {
return (
<EmptyState>
<code>componentKey</code> is required to resolve the hook API.
</EmptyState>
);
}
if (!themeData) {
return (
<EmptyState>
No theme-layer data for <code>{componentKey}</code>. Run the theme-layer build and reload.
</EmptyState>
);
}
// Directory name is camelCase (`progressBar`); hook names squash it
// (`--slds-c-progressbar-*`). Without this bridge, every hook resolves as `unknown`.
const componentPrefix = resolveHookPrefix(themeData.component ?? componentKey);
const tree = buildHookTree(themeData, componentPrefix);
const themeCoverage = buildThemeCoverage(themeData);
if (tree.size === 0) {
return (
<EmptyState>
This component does not expose any <code>--slds-c-*</code> hooks yet.
</EmptyState>
);
}
return (
<div className="scp-hook-api" data-component={componentKey}>
<SectionBanner
kind="public"
title="Component Hook API"
subtitle="Hooks the base contract reads. Every theme paints these; customer overrides reach the rendered DOM in every product surface."
/>
{orderedCategoryKeys(tree).map((category) => (
<CategoryBlock
key={category}
category={category}
byElement={tree.get(category)!}
themeCoverage={themeCoverage}
componentPrefix={componentPrefix}
/>
))}
<ThemeScopedSection
themeData={themeData}
componentPrefix={componentPrefix}
themeCoverage={themeCoverage}
activeTheme={activeTheme}
/>
</div>
);
}
// ─── Empty / banner ────────────────────────────────────────────────────
function EmptyState({ children }: { children: React.ReactNode }) {
return (
<div className="scp-hook-api">
<div className="scp-hook-api__empty">{children}</div>
</div>
);
}
interface SectionBannerProps {
kind: 'public' | 'theme-scoped';
title: string;
subtitle?: string;
activeTheme?: string;
}
function SectionBanner({ kind, title, subtitle, activeTheme }: SectionBannerProps) {
return (
<div className="scp-hook-api__banner" data-kind={kind}>
<span className="scp-hook-api__banner-icon" aria-hidden="true">
{kind === 'theme-scoped' ? '🎨' : '🌐'}
</span>
<span className="scp-hook-api__banner-body">
<span className="scp-hook-api__banner-title">{title}</span>
{subtitle && <span className="scp-hook-api__banner-subtitle">{subtitle}</span>}
</span>
{activeTheme && <span className="scp-hook-api__banner-active-theme">{activeTheme}</span>}
</div>
);
}
// ─── Theme-scoped (one-theme-only) hook surface ───────────────────────
interface ThemeScopedSectionProps {
themeData: ThemeData;
componentPrefix: string;
themeCoverage: ThemeCoverage;
activeTheme?: string;
}
function ThemeScopedSection({
themeData,
componentPrefix,
themeCoverage,
activeTheme,
}: ThemeScopedSectionProps) {
const themeNames = Object.keys(themeData?.themes ?? {});
const defaultTheme = themeNames.includes('cosmos') ? 'cosmos' : themeNames[0];
const active = activeTheme && themeNames.includes(activeTheme) ? activeTheme : defaultTheme;
Iif (!active) return null;
const tree = buildThemeScopedHookTree(themeData, active, componentPrefix);
if (tree.size === 0) return null;
return (
<div>
<SectionBanner
kind="theme-scoped"
title="Theme-Scoped Component Hook API"
subtitle="Hooks declared and read inside one theme only. Painted only when this theme is active; customer overrides reach the rendered DOM only on this product surface."
activeTheme={active}
/>
{orderedCategoryKeys(tree).map((category) => (
<CategoryBlock
key={category}
category={category}
byElement={tree.get(category)!}
themeCoverage={themeCoverage}
componentPrefix={componentPrefix}
isThemeScoped
/>
))}
</div>
);
}
// ─── Tree blocks (category → element → property → hook) ──────────────
interface CategoryBlockProps {
category: string;
byElement: Map<string, Map<string, string[]>>;
themeCoverage: ThemeCoverage;
componentPrefix: string;
isThemeScoped?: boolean;
}
function CategoryBlock({
category,
byElement,
themeCoverage,
componentPrefix,
isThemeScoped,
}: CategoryBlockProps) {
Iif (!byElement || byElement.size === 0) return null;
const total = totalHooksInCategory(byElement);
return (
<div className="scp-hook-api__category">
<div className="scp-hook-api__category-header">
<span>{CATEGORY_LABEL[category] ?? category}</span>
<span className="scp-hook-api__category-count">
{total} hook{total === 1 ? '' : 's'}
</span>
</div>
{orderedElementKeys(byElement).map((elKey) => (
<ElementBlock
key={elKey}
category={category}
elKey={elKey}
byProperty={byElement.get(elKey)!}
themeCoverage={themeCoverage}
componentPrefix={componentPrefix}
isThemeScoped={isThemeScoped}
/>
))}
</div>
);
}
interface ElementBlockProps {
category: string;
elKey: string;
byProperty: Map<string, string[]>;
themeCoverage: ThemeCoverage;
componentPrefix: string;
isThemeScoped?: boolean;
}
function ElementBlock({
category,
elKey,
byProperty,
themeCoverage,
componentPrefix,
isThemeScoped,
}: ElementBlockProps) {
const isComposition = elKey !== COMPONENT_ROOT_KEY;
const label = humanizeElement(isComposition ? elKey : null);
return (
<div className="scp-hook-api__element">
<div className="scp-hook-api__element-header">
{isComposition && <span className="scp-hook-api__element-prefix">Composition:</span>}
{label}
</div>
{orderedPropertyKeys(category, byProperty).map((propKey) => (
<PropertyGroup
key={propKey}
category={category}
propKey={propKey}
hooks={byProperty.get(propKey) ?? []}
themeCoverage={themeCoverage}
componentPrefix={componentPrefix}
isThemeScoped={isThemeScoped}
/>
))}
</div>
);
}
interface PropertyGroupProps {
category: string;
propKey: string;
hooks: string[];
themeCoverage: ThemeCoverage;
componentPrefix: string;
isThemeScoped?: boolean;
}
function PropertyGroup({
category,
propKey,
hooks,
themeCoverage,
componentPrefix,
isThemeScoped,
}: PropertyGroupProps) {
Iif (hooks.length === 0) return null;
const propLabel = humanizeProperty(category, propKey);
return (
<div className="scp-hook-api__property-group">
{propLabel && <div className="scp-hook-api__property-header">{propLabel}</div>}
<ul className="scp-hook-api__hook-list">
{hooks.map((name) => (
<HookListItem
key={name}
name={name}
category={category}
componentPrefix={componentPrefix}
themeCoverage={themeCoverage}
isThemeScoped={isThemeScoped}
/>
))}
</ul>
</div>
);
}
interface HookListItemProps {
name: string;
category: string;
componentPrefix: string;
themeCoverage: ThemeCoverage;
isThemeScoped?: boolean;
}
function HookListItem({ name, category, componentPrefix, themeCoverage, isThemeScoped }: HookListItemProps) {
const meta = resolveHookMetadata(name, componentPrefix, category);
const coverage = computeCoverage(name, themeCoverage);
const recommendation = recommendForHook({
risk: meta.risk,
demand: meta.demand,
coverage,
hookName: name,
property: meta.property ?? undefined,
isThemeScoped,
});
return (
<li className="scp-hook-api__hook">
<div className="scp-hook-api__row">
<span className="scp-hook-api__hook-name">{name}</span>
{/* Group wrappers exist for the container-query layout flip — see HookAPI.styles.css. */}
<span className="scp-hook-api__meta-group">
<RiskDemandBadge kind="risk" tier={meta.risk} property={meta.property} />
<RiskDemandBadge kind="demand" tier={meta.demand} property={meta.property} />
</span>
<span className="scp-hook-api__row-spacer" />
<span className="scp-hook-api__coverage-group">
<CoverageChip name={name} themeCoverage={themeCoverage} isThemeScoped={isThemeScoped} />
</span>
</div>
{recommendation && <RecommendationCallout recommendation={recommendation} />}
</li>
);
}
// ─── Risk / demand badge ──────────────────────────────────────────────
type RiskDemandBadgeProps =
| { kind: 'risk'; tier: RiskTier; property?: string | null }
| { kind: 'demand'; tier: DemandTier; property?: string | null };
function RiskDemandBadge({ kind, tier, property }: RiskDemandBadgeProps) {
const label = kind === 'risk' ? 'Risk' : 'Demand';
const semantic =
kind === 'risk'
? (RISK_TIER_TO_SEMANTIC[tier] ?? 'neutral')
: (DEMAND_TIER_TO_SEMANTIC[tier] ?? 'neutral');
const tierLabel = TIER_LABELS[tier] ?? tier;
const propertyLabel = property ? ` (${property})` : '';
return (
<span
className="scp-hook-api__meta-badge"
data-kind={kind}
data-tier={tier}
data-semantic={semantic}
title={`${label}: ${tierLabel}${propertyLabel}. See theme-layer-property-${kind}.md.`}
>
{label}: {tierLabel}
</span>
);
}
// ─── Coverage + value-divergence chips ────────────────────────────────
function coverageState(have: number, total: number): 'empty' | 'partial' | 'full' {
Iif (have === 0) return 'empty';
if (have < total) return 'partial';
return 'full';
}
function coverageTooltip(present: string[], missing: string[]): string {
Iif (present.length === 0) {
return 'No theme assigns this hook (defined on the component but unset across all themes).';
}
if (missing.length === 0) return `Assigned in every theme (${present.join(', ')}).`;
return `Assigned in ${present.join(', ')} only. Missing from ${missing.join(', ')}: risk of inconsistent rendering if a customer or another theme later sets this hook.`;
}
interface CoverageChipProps {
name: string;
themeCoverage: ThemeCoverage;
isThemeScoped?: boolean;
}
function CoverageChip({ name, themeCoverage, isThemeScoped }: CoverageChipProps) {
const themes = themeCoverage?.themes ?? [];
Iif (themes.length === 0) return null;
const setForHook = themeCoverage.coverage.get(name) ?? new Set<string>();
const have = setForHook.size;
const total = themes.length;
const present = themes.filter((t) => setForHook.has(t));
const missing = themes.filter((t) => !setForHook.has(t));
return (
<>
<span
className="scp-hook-api__coverage-chip"
data-coverage={coverageState(have, total)}
title={coverageTooltip(present, missing)}
>
Themes: {have}/{total}
</span>
<ValueDivergenceChip name={name} themeCoverage={themeCoverage} isThemeScoped={isThemeScoped} />
</>
);
}
/**
* "Same value" / "Varies" chip; hidden when coverage is partial (a
* comparison across themes is meaningless if one isn't driving the
* hook). Hover opens the popover, click pins it.
*/
function ValueDivergenceChip({ name, themeCoverage, isThemeScoped }: CoverageChipProps) {
const popover = useDivergencePopover();
const popoverId = `sds-hook-divergence-${useId()}`;
const verdict = computeValueDivergence(name, themeCoverage);
Iif (!verdict) return null;
const label = verdict.allSame ? 'Same value' : 'Value varies';
return (
<span
className="scp-hook-api__divergence-anchor"
onMouseEnter={popover.onMouseEnter}
onMouseLeave={popover.onMouseLeave}
>
<button
type="button"
className="scp-hook-api__divergence-trigger"
data-verdict={verdict.allSame ? 'same' : 'varies'}
aria-expanded={popover.open}
aria-controls={popoverId}
aria-label={`${label} for ${name}. Click for per-theme breakdown.`}
onClick={popover.onTriggerClick}
onFocus={popover.onFocus}
onBlur={popover.onBlur}
>
{label}
</button>
{popover.open && (
<ValueDivergencePopover
id={popoverId}
hookName={name}
verdict={verdict}
isThemeScoped={isThemeScoped}
onPointerDownOutside={popover.onPointerDownOutside}
onMouseEnter={popover.onPopoverMouseEnter}
onMouseLeave={popover.onMouseLeave}
/>
)}
</span>
);
}
// ─── Popover state machine ────────────────────────────────────────────
/**
* Hover-with-delay open/close + click-to-pin. The asymmetric delays
* (close > open) give the cursor time to cross from chip to popover.
*/
function useDivergencePopover() {
const [open, setOpen] = useState(false);
// Ref, not state — read inside timer callbacks without restarting them.
const pinnedRef = useRef(false);
const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const openTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const cancelClose = () => {
Iif (closeTimer.current) {
clearTimeout(closeTimer.current);
closeTimer.current = null;
}
};
const cancelOpen = () => {
Iif (openTimer.current) {
clearTimeout(openTimer.current);
openTimer.current = null;
}
};
const cancelTimers = () => {
cancelClose();
cancelOpen();
};
useEffect(() => cancelTimers, []);
const scheduleClose = () => {
if (pinnedRef.current) return;
cancelClose();
closeTimer.current = setTimeout(() => setOpen(false), POPOVER_CLOSE_DELAY_MS);
};
const scheduleOpen = () => {
cancelClose();
cancelOpen();
if (open) return;
openTimer.current = setTimeout(() => setOpen(true), POPOVER_OPEN_DELAY_MS);
};
return {
open,
onMouseEnter: scheduleOpen,
onMouseLeave: () => {
cancelOpen();
scheduleClose();
},
onPopoverMouseEnter: cancelClose,
onTriggerClick: (e: React.MouseEvent) => {
e.stopPropagation();
// Click wins over any in-flight hover timer.
cancelTimers();
if (pinnedRef.current) {
pinnedRef.current = false;
setOpen(false);
} else {
pinnedRef.current = true;
setOpen(true);
}
},
onFocus: () => {
cancelClose();
setOpen(true);
},
onBlur: () => {
if (!pinnedRef.current) scheduleClose();
},
onPointerDownOutside: () => {
pinnedRef.current = false;
setOpen(false);
},
};
}
// ─── Divergence popover view ──────────────────────────────────────────
interface ValueDivergencePopoverProps {
id: string;
hookName: string;
verdict: NonNullable<ReturnType<typeof computeValueDivergence>>;
isThemeScoped?: boolean;
onPointerDownOutside: () => void;
onMouseEnter: () => void;
onMouseLeave: () => void;
}
function ValueDivergencePopover({
id,
hookName,
verdict,
isThemeScoped,
onPointerDownOutside,
onMouseEnter,
onMouseLeave,
}: ValueDivergencePopoverProps) {
const popoverRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const handler = (e: PointerEvent) => {
if (popoverRef.current?.contains(e.target as Node)) return;
onPointerDownOutside();
};
globalThis.addEventListener('pointerdown', handler);
return () => globalThis.removeEventListener('pointerdown', handler);
}, [onPointerDownOutside]);
return (
// Not `role="dialog"`: not modal, no focus trap. The chip's
// `aria-controls` + `aria-expanded` describe the relationship.
/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */
<div
ref={popoverRef}
id={id}
aria-label={`Per-theme assignments for ${hookName}`}
className="scp-hook-api__popover"
data-verdict={verdict.allSame ? 'same' : 'varies'}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
<div className="scp-hook-api__popover-header">
<span className="scp-hook-api__popover-title" data-verdict={verdict.allSame ? 'same' : 'varies'}>
{verdict.allSame ? 'Same value' : 'Value varies'}
</span>
<span className="scp-hook-api__popover-hook-name">{hookName}</span>
</div>
{verdict.allSame ? (
<SameValueSummary verdict={verdict} />
) : (
<DivergenceRows verdict={verdict} isThemeScoped={isThemeScoped} />
)}
</div>
);
}
function SelectorBlock({
selector,
isFirst,
children,
}: {
selector: string;
isFirst: boolean;
children: React.ReactNode;
}) {
return (
<div className="scp-hook-api__popover-selector-block" data-position={isFirst ? 'first' : 'subsequent'}>
<code className="scp-hook-api__popover-selector-label">{selector}</code>
{children}
</div>
);
}
function SameValueSummary({ verdict }: { verdict: ValueDivergencePopoverProps['verdict'] }) {
return (
<>
{verdict.rows.map((row, i) => (
<SelectorBlock key={row.selector} selector={row.selector} isFirst={i === 0}>
<div className="scp-hook-api__popover-summary-row">
<span className="scp-hook-api__popover-summary-label">every theme</span>
<span className="scp-hook-api__popover-theme-value">{row.values[0]?.value ?? ''}</span>
</div>
</SelectorBlock>
))}
</>
);
}
/**
* Per-selector × per-theme breakdown. The "no value" copy distinguishes
* intent: `(not exposed)` is by design for theme-scoped hooks;
* `(not assigned)` flags a real coverage gap on a public hook.
*/
function DivergenceRows({
verdict,
isThemeScoped,
}: {
verdict: ValueDivergencePopoverProps['verdict'];
isThemeScoped?: boolean;
}) {
const unassignedCopy = isThemeScoped ? '(not exposed)' : '(not assigned)';
return (
<>
{verdict.rows.map((row, i) => (
<SelectorBlock key={row.selector} selector={row.selector} isFirst={i === 0}>
{row.values.map((tv, idx) => (
<ThemeRow
key={tv.theme}
themeValue={tv}
isFirstInBlock={idx === 0}
isUnassigned={tv.value === null}
valuesDiffer={!row.same}
unassignedCopy={unassignedCopy}
/>
))}
</SelectorBlock>
))}
</>
);
}
interface ThemeRowProps {
themeValue: { theme: string; value: string | null };
isFirstInBlock: boolean;
isUnassigned: boolean;
valuesDiffer: boolean;
unassignedCopy: string;
}
function ThemeRow({ themeValue, isFirstInBlock, isUnassigned, valuesDiffer, unassignedCopy }: ThemeRowProps) {
// unassigned (placeholder) > differs (real divergence) > value (default).
let valueState: 'value' | 'unassigned' | 'differs' = 'value';
if (isUnassigned) valueState = 'unassigned';
else if (valuesDiffer) valueState = 'differs';
return (
<div className="scp-hook-api__popover-theme-row" data-position={isFirstInBlock ? 'first' : 'subsequent'}>
<span className="scp-hook-api__popover-theme-name">{themeValue.theme}</span>
<span className="scp-hook-api__popover-theme-value" data-state={valueState}>
{isUnassigned ? unassignedCopy : themeValue.value}
</span>
</div>
);
}
// ─── Recommendation callout ───────────────────────────────────────────
function RecommendationCallout({ recommendation }: { recommendation: Recommendation }) {
const isCritical = recommendation.severity === 'critical';
const suggestedPaths = recommendation.suggestedPaths ?? [];
return (
<div className="scp-hook-api__reco" data-severity={isCritical ? 'critical' : 'advisory'}>
<div className="scp-hook-api__reco-label">{isCritical ? 'Recommendation' : 'Consider'}</div>
<div className="scp-hook-api__reco-action">{recommendation.headline}</div>
<div className="scp-hook-api__reco-rationale">{recommendation.rationale}</div>
{suggestedPaths.length > 0 && <SuggestedMechanisms paths={suggestedPaths} />}
</div>
);
}
function SuggestedMechanisms({ paths }: { paths: MechanismPathKey[] }) {
return (
<div className="scp-hook-api__reco-paths">
<div className="scp-hook-api__reco-paths-title">
{paths.length === 1 ? 'Suggested mechanism' : 'Suggested mechanisms'}
</div>
<ul className="scp-hook-api__reco-paths-list">
{paths.map((key) => {
const path = MECHANISM_PATHS[key];
if (!path) return null;
return (
<li key={key} className="scp-hook-api__reco-paths-item">
<span className="scp-hook-api__reco-path-name">{path.name}.</span>{' '}
<span className="scp-hook-api__reco-path-summary">{path.summary}</span>
</li>
);
})}
</ul>
</div>
);
}
|