Skip to content

Commit

Permalink
Actually show the designs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed May 18, 2020
1 parent 3b1ac7b commit 60f8b0d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 30 deletions.
63 changes: 42 additions & 21 deletions .storybook/design-addon/register.js
@@ -1,31 +1,52 @@
import React, { Fragment } from 'react';
import { AddonPanel } from '@storybook/components';
import { useParameter } from '@storybook/api';
import { useParameter, useStorybookState } from '@storybook/api';
import { addons, types } from '@storybook/addons';
import { styled } from '@storybook/theming';

const getUrl = (input) => {
return typeof input === 'string' ? input : input.url;
};

const Iframe = styled.iframe({
width: '100%',
height: '100%',
border: '0 none',
});
const Img = styled.img({
width: '100%',
height: '100%',
border: '0 none',
objectFit: 'contain',
});

const Asset = ({ url }) => {
if (!url) {
return null;
}
if (url.match(/\.(png|gif|jpeg|tiff|svg|anpg|webp)/)) {
// do image viewer
return <Img alt="" src={url} />;
}

return <Iframe title={url} src={url} />;
};

const Content = () => {
const results = useParameter('assets', []); // story's parameter being retrieved here
// story's parameter being retrieved here
const results = useParameter('assets', []);
// the id of story retrieved from Storybook global state
const { storyId } = useStorybookState();

if (results.length === 0) {
return null;
}

const url = getUrl(results[0]).replace('{id}', storyId);

return (
<Fragment>
{results.length ? (
<ol>
{results.map((i) => (
<li>{i}</li>
))}
</ol>
) : null}
<Asset url={url} />
</Fragment>
);
};

addons.register('my/design-addon', () => {
addons.add('design-addon/panel', {
title: 'assets',
type: types.PANEL,
render: ({ active, key }) => (
<AddonPanel active={active} key={key}>
<Content />
</AddonPanel>
),
});
});
Binary file added public/designs/app.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/designs/items.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/designs/list-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/designs/list-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/InboxScreen.stories.js
Expand Up @@ -8,6 +8,7 @@ import { defaultTasksData } from './TaskList.stories';
export default {
component: PureInboxScreen,
title: 'InboxScreen',
parameters: { assets: ['designs/app.png'] },
decorators: [(story) => <Provider store={store}>{story()}</Provider>],
};

Expand Down
8 changes: 1 addition & 7 deletions src/components/Task.stories.js
Expand Up @@ -8,13 +8,7 @@ export default {
component: Task,
title: 'Task',
decorators: [withKnobs],
parameters: {
assets: [
'path/to/your/asset.png',
'path/to/another/asset.png',
'path/to/yet/another/asset.png',
],
},
parameters: { assets: ['designs/items.png'] },
// Our exports that end in "Data" are not stories.
excludeStories: /.*Data$/,
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/TaskList.stories.js
Expand Up @@ -6,7 +6,8 @@ import { taskData, actionsData } from './Task.stories';
export default {
component: PureTaskList,
title: 'TaskList',
decorators: [story => <div style={{ padding: '3rem' }}>{story()}</div>],
decorators: [(story) => <div style={{ padding: '3rem' }}>{story()}</div>],
parameters: { assets: ['designs/list-1.png', 'designs/list-2.png'] },
excludeStories: /.*Data$/,
};

Expand All @@ -30,4 +31,4 @@ export const WithPinnedTasks = () => <PureTaskList tasks={withPinnedTasksData} {

export const Loading = () => <PureTaskList loading tasks={[]} {...actionsData} />;

export const Empty = () => <PureTaskList tasks={[]} {...actionsData} />;
export const Empty = () => <PureTaskList tasks={[]} {...actionsData} />;

0 comments on commit 60f8b0d

Please sign in to comment.