Skip to content

Commit 1e635d5

Browse files
authored
Add a description addon to storybook (#2518)
1 parent 8dc33dc commit 1e635d5

File tree

6 files changed

+315
-10
lines changed

6 files changed

+315
-10
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
import { addons, types } from '@storybook/addons';
3+
import { AddonPanel } from '@storybook/components';
4+
import React from 'react';
5+
import { useParameter } from '@storybook/api';
6+
7+
const ADDON_ID = 'descriptionAddon';
8+
const PANEL_ID = `${ADDON_ID}/panel`;
9+
10+
const PARAM_KEY = 'description';
11+
12+
const MyPanel = () => {
13+
const value = useParameter(PARAM_KEY, null);
14+
const item = value ? value.data : 'No description for this story.';
15+
return <div style={{margin: '15px'}}>{item}</div>;
16+
};
17+
18+
addons.register(ADDON_ID, (api) => {
19+
addons.add(PANEL_ID, {
20+
type: types.PANEL,
21+
title: 'Description',
22+
render: ({ active, key }) => (
23+
<AddonPanel active={active} key={key}>
24+
<MyPanel />
25+
</AddonPanel>
26+
),
27+
});
28+
});

.storybook/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'@storybook/addon-knobs',
1111
'storybook-dark-mode',
1212
'./custom-addons/provider/register',
13+
'./custom-addons/descriptions/register',
1314
'./theme.register'
1415
],
1516
typescript: {

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@
7878
"@parcel/transformer-svg-react": "nightly",
7979
"@spectrum-css/component-builder": "^1.0.0",
8080
"@spectrum-css/vars": "^2.3.0",
81+
"@storybook/addons": "^6.1.10",
8182
"@storybook/addon-a11y": "^6.1.10",
8283
"@storybook/addon-actions": "^6.1.10",
8384
"@storybook/addon-knobs": "^6.1.10",
8485
"@storybook/addon-links": "^6.1.10",
86+
"@storybook/api": "^6.1.10",
87+
"@storybook/components": "^6.1.10",
8588
"@storybook/react": "^6.1.10",
8689
"@testing-library/dom": "^8.0.0",
8790
"@testing-library/jest-dom": "^5.14.1",

packages/@react-aria/focus/stories/FocusScope.stories.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ interface StoryProps {
2323

2424
const meta: Meta<StoryProps> = {
2525
title: 'FocusScope',
26-
component: FocusScope
26+
component: FocusScope,
27+
parameters: {
28+
description: {
29+
data: 'Should not be able to click or navigate back into inputs from previous "dialogs".'
30+
}
31+
}
2732
};
2833

2934
export default meta;

packages/@react-aria/selection/stories/useSelectableList.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ storiesOf('useSelectableList', module)
119119
<SelectableList isSubUlRelativelyPositioned={false} isUlRelativelyPositioned={false}>
120120
{options}
121121
</SelectableList>
122-
))
122+
), {description: {data: 'Built to test if focusing an element scrolls into view.'}})
123123
.add('Static ul, relative sub ul', () => (
124124
<SelectableList isSubUlRelativelyPositioned isUlRelativelyPositioned={false}>
125125
{options}

0 commit comments

Comments
 (0)