Skip to content

Commit 4e2fffe

Browse files
authored
docs: add DOM properties/method table for ui5wc subcomps (#7588)
Add the "DOM methods and properties" and "Shadow Parts" tables to subcomponents as well. Related issue: #4369
1 parent e26f690 commit 4e2fffe

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

.storybook/components/ArgTypesWithNote.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DomRefTable } from '@sb/components/DomRefTable.js';
12
import { ArgTypes } from '@storybook/blocks';
23
import MessageStripDesign from '@ui5/webcomponents/dist/types/MessageStripDesign.js';
34
import { MessageStrip } from '@ui5/webcomponents-react';
@@ -12,20 +13,30 @@ interface ArgTypesWithNotePropTypes {
1213
* Defaults to: "This component supports all HTML attributes."
1314
*/
1415
noteText?: ReactNode | ReactNode[];
16+
/**
17+
* If `true` all headings are rendered as `Heading`s instead of `Subheading`s.
18+
*/
19+
isHeading?: boolean;
1520
}
1621

1722
export function ArgTypesWithNote(props: ComponentProps<typeof ArgTypes> & ArgTypesWithNotePropTypes) {
18-
const { hideHTMLPropsNote, noteText, ...rest } = props;
23+
const { hideHTMLPropsNote, noteText, isHeading, ...rest } = props;
1924

2025
if (hideHTMLPropsNote) {
21-
return <ArgTypes {...rest} />;
26+
return (
27+
<>
28+
<ArgTypes {...rest} />
29+
<DomRefTable of={rest.of} isSubheading={!isHeading} />
30+
</>
31+
);
2232
}
2333
return (
2434
<div className={classes.tableContainer}>
2535
<MessageStrip design={MessageStripDesign.Information} hideCloseButton className={classes.strip}>
2636
{noteText ?? 'This component supports all HTML attributes.'}
2737
</MessageStrip>
2838
<ArgTypes {...rest} />
39+
<DomRefTable of={rest.of} isSubheading={!isHeading} />
2940
</div>
3041
);
3142
}

.storybook/components/DomRefTable.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { DocsContext, Heading } from '@storybook/blocks';
1+
import type { ArgTypes } from '@storybook/blocks';
2+
import { DocsContext, Heading, Subheading } from '@storybook/blocks';
23
import TagDesign from '@ui5/webcomponents/dist/types/TagDesign.js';
34
import { Tag, Link, MessageStrip, Popover } from '@ui5/webcomponents-react';
45
import type * as CEM from '@ui5/webcomponents-tools/lib/cem/types';
5-
import type { ReactNode } from 'react';
6+
import type { ComponentProps, ReactNode } from 'react';
67
import { Fragment, useContext, useRef } from 'react';
78
import { createPortal } from 'react-dom';
89
import { useGetCem } from '../utils';
@@ -47,14 +48,20 @@ function Name(props: CEM.ClassMember) {
4748
);
4849
}
4950

50-
export function DomRefTable() {
51+
export function DomRefTable({
52+
of,
53+
isSubheading,
54+
}: {
55+
of?: ComponentProps<typeof ArgTypes>['of'];
56+
isSubheading?: boolean;
57+
}) {
5158
const docsContext = useContext(DocsContext);
5259
const storyTags: string[] = docsContext.attachedCSFFile?.meta?.tags;
5360
const cemModuleName = storyTags?.find((tag) => tag.startsWith('cem-module:'));
54-
const componentName = docsContext.componentStories().at(0)?.component?.displayName;
61+
const componentName = of?.displayName ?? docsContext.componentStories().at(0)?.component?.displayName;
5562
const popoverRef = useRef(null);
5663

57-
const knownAttributes = new Set(Object.keys(docsContext.primaryStory?.argTypes ?? {}));
64+
const knownAttributes = new Set(Object.keys(of?.__docgenInfo?.props ?? docsContext.primaryStory?.argTypes ?? {}));
5865
const cem = useGetCem();
5966

6067
const moduleName = cemModuleName ? cemModuleName.split(':')[1] : componentName;
@@ -69,12 +76,13 @@ export function DomRefTable() {
6976
return !(knownAttributes.has(row.name) && !row.type?.text?.includes('HTMLElement'));
7077
}) ?? [];
7178
const cssParts: CEM.CssPart[] = componentMembers?.cssParts ?? [];
79+
const HeadingComponent = isSubheading ? Subheading : Heading;
7280

7381
return (
7482
<>
7583
{rows.length > 0 ? (
7684
<>
77-
<Heading>DOM Properties & Methods</Heading>
85+
<HeadingComponent>DOM Properties & Methods</HeadingComponent>
7886
<p>
7987
This component exposes public properties and methods. You can use them directly on the instance of the
8088
component, e.g. by using React Refs.
@@ -150,7 +158,7 @@ export function DomRefTable() {
150158

151159
{cssParts.length > 0 ? (
152160
<>
153-
<Heading>CSS Shadow Parts</Heading>
161+
<HeadingComponent>CSS Shadow Parts</HeadingComponent>
154162
<p>
155163
<Link target={'_blank'} href={'https://developer.mozilla.org/en-US/docs/Web/CSS/::part'}>
156164
CSS Shadow Parts

packages/main/src/webComponents/TabContainer/TabContainer.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import * as ComponentStories from './TabContainer.stories';
2020

2121
<ControlsWithNote of={ComponentStories.Default} />
2222

23-
# More Examples
23+
## More Examples
2424

25-
## TabContainer with TabSeparator
25+
### TabContainer with TabSeparator
2626

2727
The <code>TabSeparator</code> represents a vertical line to separate tabs inside a <code>TabContainer</code>
2828

2929
<Canvas of={ComponentStories.WithTabSeparator} />
3030

31-
## TabContainer with nested Tabs
31+
### TabContainer with nested Tabs
3232

3333
<Canvas of={ComponentStories.WithNestedTabs} />
3434

0 commit comments

Comments
 (0)