1- import { Description , DocsContext , Subtitle , Title } from '@storybook/addon-docs' ;
1+ import type { Controls } from '@storybook/addon-docs/blocks' ;
2+ import { Description , Subtitle , Title , useOf } from '@storybook/addon-docs/blocks' ;
23import ButtonDesign from '@ui5/webcomponents/dist/types/ButtonDesign.js' ;
34import MessageStripDesign from '@ui5/webcomponents/dist/types/MessageStripDesign.js' ;
45import copyIcon from '@ui5/webcomponents-icons/dist/copy.js' ;
@@ -13,21 +14,14 @@ import {
1314 ThemeProvider ,
1415} from '@ui5/webcomponents-react' ;
1516import { clsx } from 'clsx' ;
16- import { useContext } from 'react' ;
17+ import type { ComponentProps } from 'react' ;
1718import { useGetSubComponentsOfModule } from '../utils' ;
1819import classes from './DocsHeader.module.css' ;
1920import { GitHubLogo } from './GitHub-Mark' ;
2021import { Import } from './Import' ;
2122import { TableOfContent } from './TableOfContent' ;
2223
23- const Links = ( ) => {
24- const docsContext = useContext ( DocsContext ) ;
25- const isChart = docsContext . componentStories ( ) . at ( 0 ) . id . startsWith ( 'charts-' ) ;
26-
27- // const filePath = docsContext.parameters.fileName.replace(/^\.\//, '');
28- // const folderPath = filePath.substr(0, filePath.lastIndexOf('/'));
29-
30- // const githubUrl = `https://github.com/SAP/ui5-webcomponents-react/tree/main/${folderPath}`;
24+ const Links = ( { isChart } : { isChart ?: boolean } ) => {
3125 const githubUrl = `https://github.com/SAP/ui5-webcomponents-react` ;
3226
3327 const packageName = `@ui5/webcomponents-react${ isChart ? '-charts' : '' } ` ;
@@ -50,14 +44,15 @@ interface InfoTableProps {
5044 mergeSubComponents ?: boolean ;
5145 isChart ?: boolean ;
5246 experimental ?: boolean ;
47+ of : ComponentProps < typeof Controls > [ 'of' ] ;
5348}
5449
55- export const InfoTable = ( { since, subComponents, mergeSubComponents } : InfoTableProps ) => {
56- const context = useContext ( DocsContext ) ;
57- const groups = context . componentStories ( ) . at ( 0 ) . kind . split ( '/' ) ;
58- const moduleName = groups [ groups . length - 1 ] . replace ( '(experimental)' , '' ) . trim ( ) ;
50+ export const InfoTable = ( { of , since, subComponents, mergeSubComponents } : InfoTableProps ) => {
51+ const context = useOf < 'meta' > ( of ) ;
52+ const { csfFile , preparedMeta } = context ;
53+ const moduleName = csfFile . meta . component . displayName ;
5954
60- const wcSubComponents = useGetSubComponentsOfModule ( moduleName . replace ( 'V2' , '' ) ) ;
55+ const wcSubComponents = useGetSubComponentsOfModule ( moduleName . replace ( 'V2' , '' ) , preparedMeta . tags ) ;
6156 const subComps = mergeSubComponents
6257 ? [ ...( subComponents ?? [ ] ) , ...( wcSubComponents ?? [ ] ) ]
6358 : ( subComponents ?? wcSubComponents ) ;
@@ -81,7 +76,7 @@ export const InfoTable = ({ since, subComponents, mergeSubComponents }: InfoTabl
8176 < Label > Usage</ Label >
8277 </ th >
8378 < td data-import-cell = { supportsClipboardApi } >
84- < Import />
79+ < Import moduleNames = { [ moduleName ] } componentId = { preparedMeta . componentId } />
8580 { supportsClipboardApi && (
8681 < Button
8782 design = { ButtonDesign . Transparent }
@@ -110,7 +105,7 @@ export const InfoTable = ({ since, subComponents, mergeSubComponents }: InfoTabl
110105 < Label > Subcomponents</ Label >
111106 </ th >
112107 < td data-import-cell = { supportsClipboardApi } >
113- < Import moduleNames = { subComps } />
108+ < Import moduleNames = { subComps } componentId = { preparedMeta . componentId } />
114109 { supportsClipboardApi && (
115110 < Button
116111 design = { ButtonDesign . Transparent }
@@ -129,17 +124,17 @@ export const InfoTable = ({ since, subComponents, mergeSubComponents }: InfoTabl
129124 ) ;
130125} ;
131126
132- export const DocsHeader = ( { since, subComponents, mergeSubComponents, isChart, experimental } : InfoTableProps ) => {
127+ export const DocsHeader = ( { of , since, subComponents, mergeSubComponents, isChart, experimental } : InfoTableProps ) => {
133128 return (
134129 < ThemeProvider >
135130 < FlexBox alignItems = { FlexBoxAlignItems . Center } className = { classes . titleRow } >
136131 < Title />
137132 { experimental && < Label className = { classes . experimentalLabel } > experimental</ Label > }
138133 < span style = { { flexGrow : 1 } } />
139- < Links />
134+ < Links isChart = { isChart } />
140135 </ FlexBox >
141136 < Subtitle />
142- < InfoTable since = { since } subComponents = { subComponents } mergeSubComponents = { mergeSubComponents } />
137+ < InfoTable of = { of } since = { since } subComponents = { subComponents } mergeSubComponents = { mergeSubComponents } />
143138 < TableOfContent />
144139 < Description />
145140 { isChart && (
0 commit comments