Skip to content

Commit b6f7dfc

Browse files
docs: update to storybook 7 beta (#4155)
1 parent a5b63c9 commit b6f7dfc

File tree

218 files changed

+8467
-12153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+8467
-12153
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ overrides:
4949
parserOptions:
5050
project:
5151
- './tsconfig.spec.json'
52+
- './tsconfig.node.json'
5253
- './packages/*/tsconfig.json'
5354
plugins:
5455
- '@typescript-eslint'

.github/workflows/chromatic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ jobs:
3131
skip: 'dependabot/**'
3232
env:
3333
STORYBOOK_ENV: chromatic
34+
NODE_OPTIONS: '--max-old-space-size=4096'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Controls } from '@storybook/blocks';
2+
import { MessageStrip, MessageStripDesign } from '@ui5/webcomponents-react';
3+
import React, { ComponentProps, ReactNode, useEffect, useRef } from 'react';
4+
import { createUseStyles } from 'react-jss';
5+
6+
const useStyles = createUseStyles({
7+
tableContainer: {
8+
marginTop: '25px',
9+
'& table': {
10+
marginTop: '0 !important'
11+
}
12+
},
13+
strip: { marginBottom: '10px' }
14+
});
15+
16+
interface ControlsWithNotePropTypes {
17+
hideHTMLPropsNote?: boolean;
18+
/**
19+
* Customize the text of the note above the table.
20+
*
21+
* Defaults to: "This component supports all HTML attributes."
22+
*/
23+
noteText?: ReactNode | ReactNode[];
24+
}
25+
26+
export function ControlsWithNote(props: ComponentProps<typeof Controls> & ControlsWithNotePropTypes) {
27+
const { hideHTMLPropsNote, noteText, ...rest } = props;
28+
const classes = useStyles();
29+
30+
if (hideHTMLPropsNote) {
31+
return <Controls {...rest} />;
32+
}
33+
return (
34+
<div className={classes.tableContainer}>
35+
<MessageStrip design={MessageStripDesign.Information} hideCloseButton className={classes.strip}>
36+
{noteText ?? 'This component supports all HTML attributes.'}
37+
</MessageStrip>
38+
<Controls {...rest} />
39+
</div>
40+
);
41+
}

.storybook/components/DocsHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Description, DocsContext, Subtitle, Title } from '@storybook/addon-docs';
22
import { FlexBox, FlexBoxAlignItems, Label, Link, Text } from '@ui5/webcomponents-react';
33
import React, { useContext } from 'react';
4-
import { GitHubLogo } from '../../.storybook/components/GitHub-Mark';
5-
import { Import } from '../../.storybook/components/Import';
6-
import { TableOfContent } from '../../.storybook/components/TableOfContent';
4+
import { GitHubLogo } from './GitHub-Mark';
5+
import { Import } from './Import';
6+
import { TableOfContent } from './TableOfContent';
77

88
const Links = () => {
99
const docsContext = useContext(DocsContext);
10-
const isChart = docsContext.id.startsWith('charts-');
10+
const isChart = docsContext.componentStories().at(0).id.startsWith('charts-');
1111

1212
// const filePath = docsContext.parameters.fileName.replace(/^\.\//, '');
1313
// const folderPath = filePath.substr(0, filePath.lastIndexOf('/'));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.parameters:not(:last-child) {
2+
margin-block-end: 1rem;
3+
}
4+
5+
.parameterName {
6+
font-weight: bold;
7+
}
8+
9+
.parameterDetails {
10+
padding-inline: 1rem;
11+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { Heading } from '@storybook/blocks';
2+
import React from 'react';
3+
import classes from './DomRefTable.module.css';
4+
5+
function Name(props) {
6+
if (props.returnValue) {
7+
return (
8+
<>
9+
{props.name}({props.parameters?.map((param) => `${param.name}${param.optional ? '?' : ''}`).join(', ')}):{' '}
10+
<code>{props.returnValue.type}</code>
11+
</>
12+
);
13+
}
14+
15+
if (props.readonly) {
16+
return `${props.name} (readonly)`;
17+
}
18+
19+
return props.name;
20+
}
21+
22+
export function DomRefTable({ rows }: { rows: any[] }) {
23+
return (
24+
<>
25+
<Heading>Attributes & Methods</Heading>
26+
<p>
27+
This component exposes public attributes and methods. You can use them directly on the instance of the
28+
component, e.g. by using React Refs.
29+
</p>
30+
<table>
31+
<thead>
32+
<tr>
33+
<th>Name</th>
34+
<th>Parameters</th>
35+
<th>Description</th>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
{rows.map((row) => {
40+
return (
41+
<tr key={row.name}>
42+
<td>
43+
<b>
44+
<Name {...row} />
45+
</b>
46+
</td>
47+
<td>
48+
{!!row.parameters ? (
49+
row.parameters.map((parameter) => {
50+
return (
51+
<div key={parameter.name} className={classes.parameters}>
52+
<p className={classes.parameterName}>{parameter.name}</p>
53+
{parameter.description ? (
54+
<p
55+
className={classes.parameterDetails}
56+
dangerouslySetInnerHTML={{ __html: parameter.description }}
57+
/>
58+
) : null}
59+
{parameter.type ? (
60+
<p className={classes.parameterDetails}>
61+
<code>{parameter.type}</code>
62+
</p>
63+
) : null}
64+
</div>
65+
);
66+
})
67+
) : (
68+
<>&mdash;</>
69+
)}
70+
</td>
71+
<td dangerouslySetInnerHTML={{ __html: row.description }}></td>
72+
</tr>
73+
);
74+
})}
75+
</tbody>
76+
</table>
77+
</>
78+
);
79+
}

.storybook/components/Import.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ export const ImportStatement = ({ moduleName, packageName }: ImportStatementProp
2727
}}
2828
>
2929
<code style={{ whiteSpace: 'pre' }}>
30-
<span style={{ color: 'rgb(0, 0, 136)' }}>import</span>
31-
<span>
30+
<span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>import</span>
31+
<span style={{ fontSize: '14px' }}>
3232
{' '}
3333
{'{'} {moduleName} {'}'}{' '}
3434
</span>
35-
<span style={{ color: 'rgb(0, 0, 136)' }}>from</span>
35+
<span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>from</span>
3636
<span> </span>
37-
<span style={{ color: 'rgb(0, 136, 0)' }}>{packageName}</span>
38-
<span>;</span>
37+
<span style={{ color: 'rgb(0, 136, 0)', fontSize: '14px' }}>{packageName}</span>
38+
<span style={{ fontSize: '14px' }}>;</span>
3939
</code>
4040
</pre>
4141
);
4242
};
4343

4444
export const Import = () => {
4545
const context = useContext(DocsContext);
46-
const isChart = context.id.startsWith('charts-');
47-
const groups = context.kind.split('/');
46+
const isChart = context.componentStories().at(0).id.startsWith('charts-');
47+
const groups = context.componentStories().at(0).kind.split('/');
4848
const moduleName = groups[groups.length - 1].trim();
4949

5050
return (
Lines changed: 29 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,34 @@
1-
import { createUseStyles } from 'react-jss';
2-
import { ThemingParameters } from '@ui5/webcomponents-react-base';
31
import React, { useEffect } from 'react';
42
import tocbot from 'tocbot';
3+
import classes from './ToC.module.css';
54

6-
const styles = {
7-
header: {
8-
width: '100%',
9-
borderBottom: '1px solid rgba(0, 0, 0, 0.1)',
10-
fontSize: '24px',
11-
'@media(min-width:1330px)': {
12-
display: 'none'
13-
}
14-
},
15-
fixedContainer: {
16-
'@media(min-width:1330px)': {
17-
width: '200px',
18-
position: 'fixed',
19-
top: 75,
20-
right: 6,
21-
overflow: 'hidden'
22-
}
23-
},
24-
toc: {
25-
fontFamily: ThemingParameters.sapFontFamily,
26-
fontSize: ThemingParameters.sapFontSize,
27-
backgroundColor: 'white',
28-
'& *': {
29-
textDecorationLine: 'none',
30-
listStyle: 'none'
31-
},
32-
'@media(max-width:1329px)': {
33-
borderBottom: '1px solid rgba(0, 0, 0, 0.1)',
34-
'& .toc-link': {
35-
textShadow: ThemingParameters.sapContent_TextShadow,
36-
color: ThemingParameters.sapLinkColor,
37-
'&:hover': {
38-
color: ThemingParameters.sapLink_Hover_Color
39-
},
40-
'&:active': {
41-
color: ThemingParameters.sapLink_Active_Color
42-
}
43-
},
44-
'& .toc-list-item': {
45-
margin: '4px 0'
46-
},
47-
'& .is-active-link': {
48-
fontWeight: 400,
49-
'&::before': {
50-
content: 'none'
51-
}
52-
}
53-
},
54-
'@media(min-width:1330px)': {
55-
'& > .toc-list': {
56-
paddingLeft: '10px'
57-
},
58-
'& .toc-list-item': {
59-
margin: '4px 0'
60-
},
61-
'& .toc-link::before': {
62-
width: '4px'
63-
},
64-
'& .is-active-link': {
65-
'&::before': {
66-
backgroundColor: '#0a6ed1'
67-
}
68-
}
69-
}
70-
}
71-
};
72-
const useStyles = createUseStyles(styles, { name: 'TableOfContent' });
5+
function makeIds(headingSelector) {
6+
const headings = document.querySelector('.sbdocs-wrapper').querySelectorAll(headingSelector);
7+
const headingMap = {};
738

74-
export const TableOfContent = ({ headingSelector = 'h2.sbdocs-h2, h3.sbdocs-h3, h4.sbdocs-h4' }) => {
75-
const classes = useStyles();
9+
headings.forEach(function (heading) {
10+
const id =
11+
heading.id ??
12+
heading.textContent
13+
.trim()
14+
.toLowerCase()
15+
.split(' ')
16+
.join('-')
17+
.replace(/[!@#$%^&*():]/gi, '')
18+
.replace(/\//gi, '-');
19+
headingMap[id] = !isNaN(headingMap[id]) ? ++headingMap[id] : 0;
20+
if (headingMap[id]) {
21+
heading.id = id + '-' + headingMap[id];
22+
} else {
23+
heading.id = id;
24+
}
25+
});
26+
}
7627

28+
export function TableOfContent({ headingSelector = 'h2:not(.noAnchor), h3:not(.noAnchor), h4:not(.noAnchor)' }) {
7729
useEffect(() => {
30+
makeIds(headingSelector);
31+
7832
tocbot.init({
7933
tocSelector: '.js-toc',
8034
contentSelector: '.sbdocs-wrapper',
@@ -83,20 +37,20 @@ export const TableOfContent = ({ headingSelector = 'h2.sbdocs-h2, h3.sbdocs-h3,
8337
collapseDepth: 6,
8438
hasInnerContainers: true
8539
});
40+
8641
document.querySelectorAll('.toc-link').forEach((x) => x.setAttribute('target', '_self'));
42+
8743
return () => {
8844
tocbot.destroy();
8945
};
9046
}, [headingSelector]);
9147

9248
return (
9349
<>
94-
<h3 className={classes.header}>Contents</h3>
50+
<h3 className={`${classes.header} noAnchor`}>Contents</h3>
9551
<div className={classes.fixedContainer}>
9652
<div className={`js-toc ${classes.toc}`} id="toc-container" />
9753
</div>
9854
</>
9955
);
100-
};
101-
102-
TableOfContent.displayName = 'TableOfContent';
56+
}

0 commit comments

Comments
 (0)