mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 01:51:05 +08:00
IMPROVE addon-design-assets
This commit is contained in:
parent
eae8b1d887
commit
3f4e864984
@ -13,10 +13,6 @@ interface AssetDescription {
|
|||||||
type Results = (string | AssetDescription)[];
|
type Results = (string | AssetDescription)[];
|
||||||
type Selected = number;
|
type Selected = number;
|
||||||
|
|
||||||
interface Props {
|
|
||||||
active: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Iframe = styled.iframe({
|
const Iframe = styled.iframe({
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
@ -49,7 +45,7 @@ const getUrl = (input: AssetDescription | string): string => {
|
|||||||
return typeof input === 'string' ? input : input.url;
|
return typeof input === 'string' ? input : input.url;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Panel = ({ active }: Props) => {
|
export const Panel = () => {
|
||||||
const results = useParameter<Results>(PARAM_KEY, []);
|
const results = useParameter<Results>(PARAM_KEY, []);
|
||||||
const [selected, setSelected] = useAddonState<Selected>(ADDON_ID, 0);
|
const [selected, setSelected] = useAddonState<Selected>(ADDON_ID, 0);
|
||||||
const { storyId } = useStorybookState();
|
const { storyId } = useStorybookState();
|
||||||
@ -63,10 +59,10 @@ export const Panel = ({ active }: Props) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = useMemo(() => {
|
return useMemo(() => {
|
||||||
const url = getUrl(results[selected]).replace('{id}', storyId);
|
const url = getUrl(results[selected]).replace('{id}', storyId);
|
||||||
return (
|
return (
|
||||||
<div hidden={!active}>
|
<Fragment>
|
||||||
<Asset url={url} />
|
<Asset url={url} />
|
||||||
{results.length > 1 ? (
|
{results.length > 1 ? (
|
||||||
<ActionBar
|
<ActionBar
|
||||||
@ -77,9 +73,7 @@ export const Panel = ({ active }: Props) => {
|
|||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</Fragment>
|
||||||
);
|
);
|
||||||
}, [active, results, selected, storyId]);
|
}, [results, selected, storyId]);
|
||||||
|
|
||||||
return <Fragment>{output}</Fragment>;
|
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { addons, types } from '@storybook/addons';
|
import { addons, types } from '@storybook/addons';
|
||||||
|
import { AddonPanel } from '@storybook/components';
|
||||||
import { ADDON_ID, PANEL_ID } from './constants';
|
import { ADDON_ID, PANEL_ID } from './constants';
|
||||||
import { Panel } from './panel';
|
import { Panel } from './panel';
|
||||||
|
|
||||||
@ -8,6 +9,10 @@ addons.register(ADDON_ID, () => {
|
|||||||
addons.add(PANEL_ID, {
|
addons.add(PANEL_ID, {
|
||||||
title: 'design assets',
|
title: 'design assets',
|
||||||
type: types.PANEL,
|
type: types.PANEL,
|
||||||
render: ({ active, key }) => <Panel key={key} active={active} />,
|
render: ({ active, key }) => (
|
||||||
|
<AddonPanel active={active} key={key}>
|
||||||
|
<Panel />
|
||||||
|
</AddonPanel>
|
||||||
|
),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user