Skip to content

Commit

Permalink
feat: initial checkin controls panel
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 4, 2020
1 parent d8ba649 commit 9a69eb4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions integrations/storybook/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default config({
'./src/preset.ts',
'./src/config.ts',
'./src/register.tsx',
'./src/register-panel.tsx',
],
});
1 change: 0 additions & 1 deletion integrations/storybook/src/page/PageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const PageContextContainer: FC<PageContainerProps> = ({
const channel = React.useMemo(() => addons.getChannel(), []);
React.useEffect(() => {
const onStoryChange = (id: string) => {
console.log('set story', id);
setStoryId(id);
};

Expand Down
3 changes: 1 addition & 2 deletions integrations/storybook/src/page/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const ADDON_ID = 'storybook/page';
export const PANEL_ID = `${ADDON_ID}/panel`;
export const ADDON_ID = 'controls/page';
2 changes: 2 additions & 0 deletions integrations/storybook/src/panel/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ADDON_ID = 'controls/panel';
export const PANEL_ID = 'controls/panel/panel';
1 change: 1 addition & 0 deletions integrations/storybook/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
managerEntries: (entry: any[] = [], options: any = {}) => {
const result = [...entry];
result.push(require.resolve('./register'));
result.push(require.resolve('./register-panel'));
return result;
},
};
14 changes: 14 additions & 0 deletions integrations/storybook/src/register-panel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable react/display-name */
import * as React from 'react';
import addons from '@storybook/addons';
import { ControlsTable } from './blocks/ControlsTable';
import { ADDON_ID, PANEL_ID } from './panel/constants';

addons.register(ADDON_ID, api => {
addons.addPanel(PANEL_ID, {
title: 'Controls',
render: ({ active, key }) => (
<ControlsTable id="." api={api} key={key} active={active} />
),
});
});
4 changes: 2 additions & 2 deletions integrations/storybook/src/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { BroadcastChannel } from 'broadcast-channel';
import { API } from '@storybook/api';
import { addons, types } from '@storybook/addons';
import { ADDON_ID, PANEL_ID } from './page/constants';
import { ADDON_ID } from './page/constants';

interface AddonPanelProps {
active?: boolean;
Expand Down Expand Up @@ -44,7 +44,7 @@ const AddonPanel: React.FC<AddonPanelProps> = ({ active, id, api }) => {
addons.register(ADDON_ID, api => {
const title = 'Page';
const key = title.toLowerCase();
addons.add(PANEL_ID, {
addons.add(`${ADDON_ID}/${key}`, {
type: types.TAB,
title,
route: ({ storyId }) => `/${key}/${storyId}`,
Expand Down

0 comments on commit 9a69eb4

Please sign in to comment.