Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: Add API for addons to inject full-view 'pages' #23081

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2c46727
api
ndelangen Jun 14, 2023
500d31d
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 15, 2023
55d5fe2
improvements to experiment
ndelangen Jun 15, 2023
1b00de4
stop storybook from navigating away once the canvas loads
ndelangen Jun 15, 2023
436d475
prototype mobile view for pages
ndelangen Jun 15, 2023
c7e2649
add a bit of UI for demo
ndelangen Jun 15, 2023
5a869fb
improve and fix affected stories
ndelangen Jun 15, 2023
d11af89
prevent title component from losing state
ndelangen Jun 15, 2023
de87ce8
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 15, 2023
d6b78af
extra example with icon
ndelangen Jun 15, 2023
0f31c4c
cleanup
ndelangen Jun 15, 2023
75bd7db
Discard changes to code/addons/a11y/src/manager.tsx
ndelangen Jun 15, 2023
28ff657
fix broken stories module test, add an extra test for custom pages
ndelangen Jun 16, 2023
8df2b2f
cleanup
ndelangen Jun 16, 2023
047e153
first pass at migrating existing addons over
ndelangen Jun 16, 2023
d9faf16
start using addonState
ndelangen Jun 16, 2023
ead1dea
preserve state
ndelangen Jun 16, 2023
76d447a
add todo
ndelangen Jun 16, 2023
1ac2d96
fix types & fix e2e tests
ndelangen Jun 16, 2023
7d16b26
move state into addonState, bit by bit
ndelangen Jun 16, 2023
d458089
improvements
ndelangen Jun 16, 2023
fb30a3b
cleanup
ndelangen Jun 17, 2023
cbab27e
cleanup
ndelangen Jun 17, 2023
a446499
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 17, 2023
05b0879
make tasks slightly less verbose to type
ndelangen Jun 19, 2023
3bc12db
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 22, 2023
4cfa52e
fix types
ndelangen Jun 22, 2023
56a49b3
test e2e test with new UI not having parenthesis
ndelangen Jun 22, 2023
5f070e0
make app mobile story be captured like a mobile screen in chromatic
ndelangen Jun 22, 2023
237f8f9
fix e2e test
ndelangen Jun 23, 2023
6341130
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 23, 2023
93fde07
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 30, 2023
aa53aa4
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jun 30, 2023
e5af3fc
rename mains to pages
ndelangen Jul 3, 2023
40de10b
fix types
ndelangen Jul 3, 2023
e84876e
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jul 3, 2023
4b384e2
refactor types & layout components
ndelangen Jul 3, 2023
ebc3458
fixes with types & migrations
ndelangen Jul 3, 2023
9fd04fe
cleanup, make types more strict
ndelangen Jul 3, 2023
d648d6a
Merge branch 'next' into norbert/prototype-addon-page-api
ndelangen Jul 3, 2023
ea9d9d8
fix lockfile
ndelangen Jul 3, 2023
dfa88ee
fix story missing viewMode
ndelangen Jul 3, 2023
ff58a54
navigate to first story if pathname = `/`
ndelangen Jul 3, 2023
4629432
fix test
ndelangen Jul 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions code/addons/a11y/src/manager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('A11yManager', () => {

const panel = mockedAddons.add.mock.calls
.map(([_, def]) => def)
.find(({ type }) => type === 'panel');
.find(({ type }) => type === api.types.PANEL);
const tool = mockedAddons.add.mock.calls
.map(([_, def]) => def)
.find(({ type }) => type === 'tool');
.find(({ type }) => type === api.types.TOOL);
expect(panel).toBeDefined();
expect(tool).toBeDefined();
});
Expand All @@ -33,7 +33,7 @@ describe('A11yManager', () => {
registrationImpl(api as unknown as api.API);
const title = mockedAddons.add.mock.calls
.map(([_, def]) => def)
.find(({ type }) => type === 'panel')?.title as Function;
.find(({ type }) => type === api.types.PANEL)?.title as Function;

// when / then
expect(title()).toBe('Accessibility');
Expand All @@ -45,7 +45,7 @@ describe('A11yManager', () => {
registrationImpl(mockedApi);
const title = mockedAddons.add.mock.calls
.map(([_, def]) => def)
.find(({ type }) => type === 'panel')?.title as Function;
.find(({ type }) => type === api.types.PANEL)?.title as Function;

// when / then
expect(title()).toBe('Accessibility (3)');
Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ addons.register(ADDON_ID, (api) => {
countRef.current = 0;
});

addons.addPanel(PANEL_ID, {
addons.add(PANEL_ID, {
title: <Title count={countRef} />,
id: 'actions',
type: types.PANEL,
Expand Down
1 change: 1 addition & 0 deletions code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@storybook/global": "^5.0.0",
"@storybook/manager-api": "7.1.0-alpha.42",
"@storybook/preview-api": "7.1.0-alpha.42",
"@storybook/router": "7.1.0-alpha.42",
"@storybook/theming": "7.1.0-alpha.42",
"@storybook/types": "7.1.0-alpha.42",
"memoizerific": "^1.11.3",
Expand Down
96 changes: 95 additions & 1 deletion code/addons/backgrounds/src/manager.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { Fragment } from 'react';
import type { ComponentProps, FC } from 'react';
import React, { memo, Fragment } from 'react';
import { addons, types } from '@storybook/manager-api';

import { Icons, IconButton, Bar, TabButton } from '@storybook/components';
import { styled } from '@storybook/theming';
import { Route } from '@storybook/router';
import { ADDON_ID } from './constants';
import { BackgroundSelector } from './containers/BackgroundSelector';
import { GridSelector } from './containers/GridSelector';
Expand All @@ -19,3 +23,93 @@ addons.register(ADDON_ID, () => {
),
});
});

// TODO: remove after API is completed

const Toolbar = styled(
({ shown = true, ...props }: ComponentProps<typeof Bar> & { shown: boolean }) => (
<Bar {...props} />
)
)(
{
position: 'absolute',
left: 0,
right: 0,
top: 0,
transition: 'transform .2s linear',
},
({ shown }) => ({
transform: shown ? 'translateY(0px)' : 'translateY(-40px)',
})
);
const FrameWrap = styled.div<{ offset: number }>(({ offset }) => ({
position: 'absolute',
overflow: 'auto',
left: 0,
right: 0,
bottom: 0,
top: offset,
zIndex: 3,
transition: 'all 0.1s linear',
height: `calc(100% - ${offset}px)`,
background: 'transparent',
}));
const Centered = styled.div({
position: 'relative',

width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
});

addons.register('@storybook/addon-debugger', (api) => {
addons.add(ADDON_ID, {
title: 'Backgrounds',
type: types.TOOLEXTRA,
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
render: () => (
<Fragment>
<IconButton
key="debugger"
title="navigate to debugger-view"
onClick={() =>
api.navigateUrl(`/debugger/${api.getCurrentStoryData().id}`, { plain: false })
}
>
<Icons icon="lightning" />
</IconButton>
</Fragment>
),
});

const DebuggerPage: FC = () => {
return (
<Route path="/debugger" startsWith>
<Toolbar shown border>
<TabButton active>A tab</TabButton>
<IconButton
key="first"
title="Go to first story, for some reason. It's just a demo."
onClick={() => api.selectFirstStory()}
>
<Icons icon="star" />
</IconButton>
</Toolbar>
<FrameWrap offset={40}>
<Centered>
This is the contents of my addon, in a full viewport experience, what a joy!
</Centered>
</FrameWrap>
</Route>
);
};

addons.add('@storybook/addon-debugger/panel', {
title: 'Debugger',
type: types.experimental_PAGE,
url: '/debugger',
render: memo(DebuggerPage),
});
});
21 changes: 14 additions & 7 deletions code/addons/controls/src/manager.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { addons, types, type API, useArgTypes } from '@storybook/manager-api';
import { AddonPanel } from '@storybook/components';
import { addons, types, useArgTypes } from '@storybook/manager-api';
import { AddonPanel, Badge, Spaced } from '@storybook/components';
import { ControlsPanel } from './ControlsPanel';
import { ADDON_ID, PARAM_KEY } from './constants';

Expand All @@ -9,14 +9,21 @@ function Title() {
const controlsCount = Object.values(rows).filter(
(argType) => argType?.control && !argType?.table?.disable
).length;
const suffix = controlsCount === 0 ? '' : ` (${controlsCount})`;
const suffix = controlsCount === 0 ? '' : <Badge status="neutral">{controlsCount}</Badge>;

return <>Controls{suffix}</>;
return (
<div>
<Spaced col={1}>
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>Controls</span>
{suffix}
</Spaced>
</div>
);
}

addons.register(ADDON_ID, (api: API) => {
addons.addPanel(ADDON_ID, {
title: <Title />,
addons.register(ADDON_ID, (api) => {
addons.add(ADDON_ID, {
title: Title,
id: 'controls',
type: types.PANEL,
paramKey: PARAM_KEY,
Expand Down
Loading