Skip to content

Commit 3427221

Browse files
[Docs] Fix TooltipProvider missing from Tooltip API Reference section (#440)
* fix(kumo): surface TooltipProvider in Tooltip API Reference Register TooltipProvider in the component registry as a pass-through sub-component of Tooltip via a new SUB_COMPONENT_OVERRIDES map. No runtime change: TooltipProvider stays as a sibling named export. Adds TooltipBase.Provider props (delay, closeDelay, timeout) to PASSTHROUGH_COMPONENT_DOCS and a TooltipProvider section to the Tooltip docs page. * chore: remove tooltip provider changeset * chore: restore tooltip-provider-registry changeset --------- Co-authored-by: Matt Rothenberg <mattrothenberg@users.noreply.github.com>
1 parent f968b07 commit 3427221

5 files changed

Lines changed: 132 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/kumo": patch
3+
---
4+
5+
TooltipProvider props (`delay`, `closeDelay`, `timeout`) are now shown in the Tooltip component's API Reference on the docs site.

packages/kumo-docs-astro/src/pages/components/tooltip.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,12 @@ For delay grouping across multiple tooltips, see [TooltipProvider](#tooltipprovi
125125

126126
## API Reference
127127

128-
<PropsTable component="Tooltip" />
128+
### Tooltip
129+
130+
<PropsTable component="Tooltip" />
131+
132+
### TooltipProvider
133+
134+
<PropsTable component="Tooltip.Provider" />
135+
129136
</ComponentSection>

packages/kumo/scripts/component-registry/index.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,45 @@ interface GroupProps extends BaseProps {
943943
expect(props).toEqual({});
944944
});
945945
});
946+
947+
describe("SUB_COMPONENT_OVERRIDES", () => {
948+
it("declares a Tooltip.Provider entry that passes through to TooltipBase.Provider", async () => {
949+
const { SUB_COMPONENT_OVERRIDES, PASSTHROUGH_COMPONENT_DOCS } =
950+
await import("./metadata.js");
951+
952+
expect(SUB_COMPONENT_OVERRIDES.Tooltip).toBeDefined();
953+
const tooltipOverrides = SUB_COMPONENT_OVERRIDES.Tooltip;
954+
expect(tooltipOverrides).toHaveLength(1);
955+
956+
const provider = tooltipOverrides[0];
957+
expect(provider.name).toBe("Provider");
958+
expect(provider.valueName).toBe("TooltipProvider");
959+
expect(provider.isPassThrough).toBe(true);
960+
expect(provider.baseComponent).toBe("TooltipBase.Provider");
961+
expect(provider.propsType).toBeNull();
962+
963+
// The baseComponent must resolve to a documented passthrough entry so the
964+
// merge + lookup path in index.ts produces real docs, not an empty stub.
965+
expect(
966+
PASSTHROUGH_COMPONENT_DOCS[provider.baseComponent as string],
967+
).toBeDefined();
968+
});
969+
970+
it("entries have the same shape as detectSubComponents() results", async () => {
971+
const { SUB_COMPONENT_OVERRIDES } = await import("./metadata.js");
972+
973+
for (const overrides of Object.values(SUB_COMPONENT_OVERRIDES)) {
974+
for (const entry of overrides) {
975+
// Required fields of SubComponentConfig.
976+
expect(typeof entry.name).toBe("string");
977+
expect(typeof entry.valueName).toBe("string");
978+
expect(typeof entry.description).toBe("string");
979+
expect(typeof entry.isPassThrough).toBe("boolean");
980+
// propsType may be a string or null.
981+
expect(
982+
entry.propsType === null || typeof entry.propsType === "string",
983+
).toBe(true);
984+
}
985+
}
986+
});
987+
});

packages/kumo/scripts/component-registry/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
ADDITIONAL_COMPONENT_PROPS,
6363
PROP_TYPE_OVERRIDES,
6464
COMPONENT_STYLING_METADATA,
65+
SUB_COMPONENT_OVERRIDES,
6566
} from "./metadata.js";
6667

6768
// External imports - demo examples from kumo-docs-astro
@@ -598,14 +599,21 @@ async function processComponent(
598599
}
599600
}
600601

601-
// Detect and process sub-components
602+
// Merge SUB_COMPONENT_OVERRIDES after source detection.
603+
// Detected entries win on name conflict so source-level patterns aren't masked.
602604
const detectedSubComponents = detectSubComponents(sourcePath);
605+
const subComponentOverrides = SUB_COMPONENT_OVERRIDES[config.name] ?? [];
606+
const detectedNames = new Set(detectedSubComponents.map((sc) => sc.name));
607+
const mergedSubComponents = [
608+
...detectedSubComponents,
609+
...subComponentOverrides.filter((o) => !detectedNames.has(o.name)),
610+
];
603611
let subComponentSchemas: Record<string, SubComponentSchema> | undefined;
604612

605-
if (detectedSubComponents.length > 0) {
613+
if (mergedSubComponents.length > 0) {
606614
subComponentSchemas = {};
607615

608-
for (const subComp of detectedSubComponents) {
616+
for (const subComp of mergedSubComponents) {
609617
let subProps = extractSubComponentProps(sourcePath, subComp, CLI_FLAGS);
610618
let description = subComp.description;
611619
let usageExamples: string[] | undefined;

packages/kumo/scripts/component-registry/metadata.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
* - Styling metadata for Figma plugin
99
*/
1010

11-
import type { PropSchema, PassthroughDoc, ComponentStyling } from "./types.js";
11+
import type {
12+
PropSchema,
13+
PassthroughDoc,
14+
ComponentStyling,
15+
SubComponentConfig,
16+
} from "./types.js";
1217

1318
// =============================================================================
1419
// Pass-through Component Documentation
@@ -158,6 +163,66 @@ export const PASSTHROUGH_COMPONENT_DOCS: Record<string, PassthroughDoc> = {
158163
</Combobox.Collection>`,
159164
],
160165
},
166+
167+
// Tooltip sub-components
168+
"TooltipBase.Provider": {
169+
description:
170+
"Groups multiple tooltips so that after the first tooltip is shown, switching to another skips the open delay. Place once at your app root or layout.",
171+
props: {
172+
delay: {
173+
type: "number",
174+
description:
175+
"How long to wait (ms) before opening a tooltip once the pointer enters the trigger.",
176+
default: "600",
177+
},
178+
closeDelay: {
179+
type: "number",
180+
description: "How long to wait (ms) before closing a tooltip.",
181+
default: "0",
182+
},
183+
timeout: {
184+
type: "number",
185+
description:
186+
"Grace period (ms) during which a just-closed tooltip's delay is skipped when another tooltip opens.",
187+
default: "400",
188+
},
189+
},
190+
usageExamples: ["<TooltipProvider>\n <App />\n</TooltipProvider>"],
191+
},
192+
};
193+
194+
// =============================================================================
195+
// Sub-Component Overrides
196+
// =============================================================================
197+
198+
/**
199+
* Manual sub-component entries that are merged into the registry alongside
200+
* entries detected by `detectSubComponents()` in `sub-components.ts`.
201+
*
202+
* Use this when a component exposes a related API (e.g., a sibling named
203+
* export like `TooltipProvider`) that we want documented as a sub-component
204+
* (e.g., `Tooltip.Provider`) for the registry / docs, *without* changing the
205+
* component's runtime shape (no `Object.assign`, no attached property).
206+
*
207+
* Detected sub-components take precedence over overrides with the same
208+
* `name`, so a real source-level compound pattern will always win and
209+
* prevent silent masking of detector regressions.
210+
*
211+
* Keyed by the parent component name (e.g., "Tooltip"). Values have the same
212+
* shape as `detectSubComponents()` entries so they feed directly into the
213+
* existing processing loop in `index.ts`.
214+
*/
215+
export const SUB_COMPONENT_OVERRIDES: Record<string, SubComponentConfig[]> = {
216+
Tooltip: [
217+
{
218+
name: "Provider",
219+
valueName: "TooltipProvider",
220+
propsType: null,
221+
description: "Provider sub-component (wraps TooltipBase)",
222+
isPassThrough: true,
223+
baseComponent: "TooltipBase.Provider",
224+
},
225+
],
161226
};
162227

163228
// =============================================================================

0 commit comments

Comments
 (0)