mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 04:31:48 +08:00
ADD sections to state && REMOVE Preview from state
This commit is contained in:
parent
5d37313b99
commit
076aa114bb
@ -115,7 +115,7 @@ const Nav = ({ title, url, notifications = [], sections = [] }) => (
|
|||||||
</Heading>
|
</Heading>
|
||||||
{sections.length ? (
|
{sections.length ? (
|
||||||
<Bar>
|
<Bar>
|
||||||
{sections.map(({ id, name, active, path }) => (
|
{sections.map(({ id, name, path }) => (
|
||||||
<Match key={id} path={path}>
|
<Match key={id} path={path}>
|
||||||
{({ match }) => (
|
{({ match }) => (
|
||||||
<BarItem key={id} active={match} path={path}>
|
<BarItem key={id} active={match} path={path}>
|
||||||
@ -128,7 +128,7 @@ const Nav = ({ title, url, notifications = [], sections = [] }) => (
|
|||||||
) : null}
|
) : null}
|
||||||
</Head>
|
</Head>
|
||||||
<Main>
|
<Main>
|
||||||
{sections.map(({ id, path, render }) => (
|
{sections.map(({ id, path, nav: render }) => (
|
||||||
<Match key={id} path={path}>
|
<Match key={id} path={path}>
|
||||||
{({ match }) => (match ? render() : null)}
|
{({ match }) => (match ? render() : null)}
|
||||||
</Match>
|
</Match>
|
||||||
|
@ -32,7 +32,7 @@ class IFrame extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Frame = styled(IFrame)(
|
const Frame = styled('div')(
|
||||||
{
|
{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: 0,
|
top: 0,
|
||||||
@ -43,7 +43,16 @@ const Frame = styled(IFrame)(
|
|||||||
transformOrigin: 'top left',
|
transformOrigin: 'top left',
|
||||||
},
|
},
|
||||||
({ grid = defaults.grid }) => grid,
|
({ grid = defaults.grid }) => grid,
|
||||||
({ background = defaults.background }) => background
|
({ background = defaults.background }) => background,
|
||||||
|
{
|
||||||
|
'& > iframe': {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const FrameWrap = styled('div')(({ offset, full }) => ({
|
const FrameWrap = styled('div')(({ offset, full }) => ({
|
||||||
@ -72,6 +81,8 @@ class Preview extends Component {
|
|||||||
url = 'https://example.com',
|
url = 'https://example.com',
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
console.log(this.props, this.state);
|
||||||
|
|
||||||
const { zoom } = this.state;
|
const { zoom } = this.state;
|
||||||
|
|
||||||
const toolbarHeight = toolbar ? 40 : 0;
|
const toolbarHeight = toolbar ? 40 : 0;
|
||||||
@ -81,20 +92,23 @@ class Preview extends Component {
|
|||||||
<PointerBlock shown={isDragging} />
|
<PointerBlock shown={isDragging} />
|
||||||
<FrameWrap offset={toolbarHeight} full={full} id="storybook-preview-background">
|
<FrameWrap offset={toolbarHeight} full={full} id="storybook-preview-background">
|
||||||
<Frame
|
<Frame
|
||||||
id="storybook-preview-iframe"
|
|
||||||
title={id || 'preview'}
|
|
||||||
src={url}
|
|
||||||
allowFullScreen
|
|
||||||
style={{
|
style={{
|
||||||
width: `${100 * zoom}%`,
|
width: `${100 * zoom}%`,
|
||||||
height: `${100 * zoom}%`,
|
height: `${100 * zoom}%`,
|
||||||
transform: `scale(${1 / zoom})`,
|
transform: `scale(${1 / zoom})`,
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
|
<IFrame
|
||||||
|
id="storybook-preview-iframe"
|
||||||
|
title={id || 'preview'}
|
||||||
|
src={url}
|
||||||
|
allowFullScreen
|
||||||
|
/>
|
||||||
|
</Frame>
|
||||||
</FrameWrap>
|
</FrameWrap>
|
||||||
{toolbar && !full ? (
|
{toolbar && !full ? (
|
||||||
<Toolbar
|
<Toolbar
|
||||||
left={[<Address key="address" value={url} readonly />]}
|
left={[<Address key="address" value={url} readOnly />]}
|
||||||
right={[
|
right={[
|
||||||
<Zoom key="zoom" current={zoom} set={v => this.setState({ zoom: zoom * v })} />,
|
<Zoom key="zoom" current={zoom} set={v => this.setState({ zoom: zoom * v })} />,
|
||||||
]}
|
]}
|
||||||
|
@ -26,12 +26,15 @@ const Root = ({
|
|||||||
Nav,
|
Nav,
|
||||||
Preview,
|
Preview,
|
||||||
Panel,
|
Panel,
|
||||||
|
sections,
|
||||||
options = {
|
options = {
|
||||||
active: 0,
|
active: 0,
|
||||||
full: false,
|
full: false,
|
||||||
nav: true,
|
nav: true,
|
||||||
panel: 'bottom',
|
panel: 'bottom',
|
||||||
},
|
},
|
||||||
|
selectedKind,
|
||||||
|
selectedStory,
|
||||||
}) => (
|
}) => (
|
||||||
<Reset>
|
<Reset>
|
||||||
<ResizeDetector handleWidth>
|
<ResizeDetector handleWidth>
|
||||||
@ -43,7 +46,7 @@ const Root = ({
|
|||||||
case width < 500: {
|
case width < 500: {
|
||||||
return <Mobile {...{ Nav, Preview, Panel, options }} />;
|
return <Mobile {...{ Nav, Preview, Panel, options }} />;
|
||||||
}
|
}
|
||||||
case width > 500: {
|
case width >= 500: {
|
||||||
return <Desktop {...{ Nav, Preview, Panel, options }} />;
|
return <Desktop {...{ Nav, Preview, Panel, options }} />;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
import { location } from 'global';
|
|
||||||
import qs from 'qs';
|
|
||||||
import React from 'react';
|
|
||||||
import { Provider } from '@storybook/ui';
|
import { Provider } from '@storybook/ui';
|
||||||
import addons from '@storybook/addons';
|
import addons from '@storybook/addons';
|
||||||
import createChannel from '@storybook/channel-postmessage';
|
import createChannel from '@storybook/channel-postmessage';
|
||||||
import Events from '@storybook/core-events';
|
import Events from '@storybook/core-events';
|
||||||
import Preview from './preview';
|
|
||||||
|
|
||||||
export default class ReactProvider extends Provider {
|
export default class ReactProvider extends Provider {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -20,21 +16,21 @@ export default class ReactProvider extends Provider {
|
|||||||
return addons.getPanels();
|
return addons.getPanels();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPreview(selectedKind, selectedStory) {
|
// renderPreview(selectedKind, selectedStory, props) {
|
||||||
const queryParams = {
|
// const queryParams = {
|
||||||
selectedKind,
|
// selectedKind,
|
||||||
selectedStory,
|
// selectedStory,
|
||||||
};
|
// };
|
||||||
|
|
||||||
// Add the react-perf query string to the iframe if that present.
|
// // Add the react-perf query string to the iframe if that present.
|
||||||
if (/react_perf/.test(location.search)) {
|
// if (/react_perf/.test(location.search)) {
|
||||||
queryParams.react_perf = '1';
|
// queryParams.react_perf = '1';
|
||||||
}
|
// }
|
||||||
|
|
||||||
const queryString = qs.stringify(queryParams);
|
// const queryString = qs.stringify(queryParams);
|
||||||
const url = `iframe.html?${queryString}`;
|
// const url = `iframe.html?${queryString}`;
|
||||||
return <Preview url={url} />;
|
// return <Preview url={url} {...props} />;
|
||||||
}
|
// }
|
||||||
|
|
||||||
handleAPI(api) {
|
handleAPI(api) {
|
||||||
api.onStory((kind, story) => {
|
api.onStory((kind, story) => {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import Root from './containers/root';
|
import Root from './containers/root';
|
||||||
import Nav from './containers/nav';
|
|
||||||
|
|
||||||
import Preview from './containers/preview_panel';
|
import Nav from './containers/nav';
|
||||||
import Panel from './containers/addon_panel';
|
import Preview from './containers/preview';
|
||||||
|
import Panel from './containers/panel';
|
||||||
|
|
||||||
const App = () => <Root Preview={Preview} Nav={Nav} Panel={Panel} />;
|
const App = () => <Root Preview={Preview} Nav={Nav} Panel={Panel} />;
|
||||||
|
|
||||||
|
@ -3,37 +3,38 @@ import { inject } from 'mobx-react';
|
|||||||
|
|
||||||
import { Nav, Explorer } from '@storybook/components';
|
import { Nav, Explorer } from '@storybook/components';
|
||||||
|
|
||||||
import * as filters from '../libs/filters';
|
// import * as filters from '../libs/filters';
|
||||||
import {
|
// import {
|
||||||
prepareStoriesForHierarchy,
|
// prepareStoriesForHierarchy,
|
||||||
resolveStoryHierarchy,
|
// resolveStoryHierarchy,
|
||||||
resolveStoryHierarchyRoots,
|
// resolveStoryHierarchyRoots,
|
||||||
createHierarchies,
|
// createHierarchies,
|
||||||
} from '../libs/hierarchy';
|
// } from '../libs/hierarchy';
|
||||||
|
|
||||||
import { toNested } from '../libs/nav/nav';
|
// import { toNested } from '../libs/nav/nav';
|
||||||
|
|
||||||
export const mapper = store => {
|
export const mapper = store => {
|
||||||
const {
|
const {
|
||||||
stories: data,
|
sections,
|
||||||
selectedKind,
|
// stories: data,
|
||||||
selectedStory,
|
// selectedKind,
|
||||||
|
// selectedStory,
|
||||||
uiOptions: {
|
uiOptions: {
|
||||||
name,
|
name,
|
||||||
url,
|
url,
|
||||||
|
|
||||||
sortStoriesByKind,
|
// sortStoriesByKind,
|
||||||
hierarchySeparator,
|
// hierarchySeparator,
|
||||||
hierarchyRootSeparator,
|
// hierarchyRootSeparator,
|
||||||
sidebarAnimations,
|
// sidebarAnimations,
|
||||||
},
|
},
|
||||||
storyFilter,
|
// storyFilter,
|
||||||
} = store;
|
} = store;
|
||||||
|
|
||||||
const stories = toNested(data, {
|
// const stories = toNested(data, {
|
||||||
rootSeperator: hierarchyRootSeparator,
|
// rootSeperator: hierarchyRootSeparator,
|
||||||
groupSeperator: hierarchySeparator,
|
// groupSeperator: hierarchySeparator,
|
||||||
});
|
// });
|
||||||
|
|
||||||
//
|
//
|
||||||
// const preparedStories = prepareStoriesForHierarchy(
|
// const preparedStories = prepareStoriesForHierarchy(
|
||||||
@ -58,37 +59,36 @@ export const mapper = store => {
|
|||||||
return {
|
return {
|
||||||
title: name,
|
title: name,
|
||||||
url,
|
url,
|
||||||
sections: [
|
sections,
|
||||||
{
|
// sections: [
|
||||||
id: 'components',
|
// {
|
||||||
name: 'components',
|
// id: 'components',
|
||||||
path: '/components',
|
// name: 'components',
|
||||||
render: () => (
|
// path: '/components',
|
||||||
<Explorer
|
// render: () => (
|
||||||
stories={stories}
|
// <Explorer
|
||||||
storyFilter={storyFilter}
|
// stories={stories}
|
||||||
onStoryFilter={filter => store.setStoryFilter(filter)}
|
// storyFilter={storyFilter}
|
||||||
selectedKind={selectedKind}
|
// onStoryFilter={filter => store.setStoryFilter(filter)}
|
||||||
selectedStory={selectedStory}
|
// selectedKind={selectedKind}
|
||||||
/>
|
// selectedStory={selectedStory}
|
||||||
),
|
// />
|
||||||
active: true,
|
// ),
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
id: 'settings',
|
// id: 'settings',
|
||||||
name: 'settings',
|
// name: 'settings',
|
||||||
path: '/settings',
|
// path: '/settings',
|
||||||
render: () => <div>Settings NAV</div>,
|
// render: () => <div>Settings NAV</div>,
|
||||||
active: false,
|
// },
|
||||||
},
|
// ],
|
||||||
],
|
|
||||||
notification: [],
|
notification: [],
|
||||||
|
|
||||||
selectedKind,
|
// selectedKind,
|
||||||
selectedStory,
|
// selectedStory,
|
||||||
onSelectStory: (kind, story) => store.selectStory(kind, story),
|
onSelectStory: (kind, story) => store.selectStory(kind, story),
|
||||||
storyFilter,
|
// storyFilter,
|
||||||
onStoryFilter: filter => store.setStoryFilter(filter),
|
// onStoryFilter: filter => store.setStoryFilter(filter),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,4 +9,4 @@ export function mapper(store) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default inject(({ store }, props) => mapper(store, props))(AddonPanel);
|
export default inject(({ store }) => mapper(store))(AddonPanel);
|
@ -1,6 +1,6 @@
|
|||||||
import { mapper } from './addon_panel';
|
import { mapper } from './panel';
|
||||||
|
|
||||||
describe('manager.ui.containers.addon_panel', () => {
|
describe('manager.ui.containers.panel', () => {
|
||||||
describe('mapper', () => {
|
describe('mapper', () => {
|
||||||
test('should give correct data', () => {
|
test('should give correct data', () => {
|
||||||
const state = {
|
const state = {
|
20
lib/ui/src/containers/preview.js
Normal file
20
lib/ui/src/containers/preview.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { inject } from 'mobx-react';
|
||||||
|
import qs from 'qs';
|
||||||
|
import { Preview } from '@storybook/components';
|
||||||
|
|
||||||
|
export function mapper(store) {
|
||||||
|
const { selectedKind, selectedStory } = store;
|
||||||
|
const queryString = qs.stringify({
|
||||||
|
selectedKind,
|
||||||
|
selectedStory,
|
||||||
|
});
|
||||||
|
const url = `iframe.html?${queryString}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const P = inject(({ store }) => mapper(store))(Preview);
|
||||||
|
|
||||||
|
export default P;
|
@ -1,11 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { inject } from 'mobx-react';
|
|
||||||
// import { AddonPanel } from '@storybook/components';
|
|
||||||
|
|
||||||
export function mapper(store) {
|
|
||||||
return {
|
|
||||||
Preview: store.Preview,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default inject(({ store }, props) => mapper(store, props))(({ Preview }) => <Preview />);
|
|
@ -9,6 +9,7 @@ export default inject(stores => {
|
|||||||
const currentOptions = pick(shortcutOptions, 'panel', 'full', 'nav');
|
const currentOptions = pick(shortcutOptions, 'panel', 'full', 'nav');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
sections: state.sections,
|
||||||
options: {
|
options: {
|
||||||
...currentOptions,
|
...currentOptions,
|
||||||
...uiOptions,
|
...uiOptions,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
import { observable, action, set } from 'mobx';
|
import { observable, action, set } from 'mobx';
|
||||||
import pick from 'lodash.pick';
|
import pick from 'lodash.pick';
|
||||||
import { themes } from '@storybook/components';
|
import { themes, Explorer } from '@storybook/components';
|
||||||
|
|
||||||
import { features } from './libs/key_events';
|
import { features } from './libs/key_events';
|
||||||
|
import { toNested } from './libs/nav/nav';
|
||||||
|
|
||||||
function ensureKind(stories, selectedKind) {
|
function ensureKind(stories, selectedKind) {
|
||||||
if (stories.length === 0) return selectedKind;
|
if (stories.length === 0) return selectedKind;
|
||||||
@ -64,8 +66,34 @@ const createStore = ({ provider }) => {
|
|||||||
},
|
},
|
||||||
customQueryParams: {},
|
customQueryParams: {},
|
||||||
|
|
||||||
get Preview() {
|
get sections() {
|
||||||
return () => provider.renderPreview(this.selectedKind, this.selectedStory);
|
const {
|
||||||
|
stories: data,
|
||||||
|
uiOptions: { hierarchyRootSeparator, hierarchySeparator },
|
||||||
|
} = this;
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 'components',
|
||||||
|
name: 'components',
|
||||||
|
path: '/components',
|
||||||
|
nav: () => (
|
||||||
|
<Explorer
|
||||||
|
stories={toNested(data, {
|
||||||
|
rootSeperator: hierarchyRootSeparator,
|
||||||
|
groupSeperator: hierarchySeparator,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
main: () => 'WHOOHOOO',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'settings',
|
||||||
|
name: 'settings',
|
||||||
|
path: '/settings',
|
||||||
|
nav: () => <div>Settings NAV</div>,
|
||||||
|
main: () => <div>Settings MAIN</div>,
|
||||||
|
},
|
||||||
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
selectedPanelValue: null,
|
selectedPanelValue: null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user