Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion code/core/src/manager/components/preview/tools/share.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,31 @@ type Story = StoryObj<typeof meta>;

export const Default: Story = {
beforeEach: () => {
const originalConfigType = global.CONFIG_TYPE;
global.STORYBOOK_NETWORK_ADDRESS = 'http://127.0.0.1:6006';
global.CONFIG_TYPE = 'DEVELOPMENT';

return () => {
global.CONFIG_TYPE = originalConfigType;
};
},
play: async ({ userEvent, canvas }) => {
await waitFor(async () => {
await userEvent.click(canvas.getByRole('button'));
await expect(await screen.findByText('Scan me')).toBeVisible();
await expect(await screen.findByText('Scan to open')).toBeVisible();
});
},
};

export const Production: Story = {
...Default,
beforeEach: () => {
const originalConfigType = global.CONFIG_TYPE;
global.STORYBOOK_NETWORK_ADDRESS = 'http://127.0.0.1:6006';
global.CONFIG_TYPE = 'PRODUCTION';

return () => {
global.CONFIG_TYPE = originalConfigType;
};
},
};
21 changes: 15 additions & 6 deletions code/core/src/manager/components/preview/tools/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ function ShareMenu({
storyId,
queryParams,
qrUrl,
isDevelopment,
}: {
baseUrl: string;
storyId: string;
queryParams: Record<string, any>;
qrUrl: string;
isDevelopment: boolean;
}) {
const api = useStorybookApi();
const shortcutKeys = api.getShortcutKeys();
Expand Down Expand Up @@ -129,18 +131,22 @@ function ShareMenu({
<QRContainer>
<QRImage value={qrUrl} />
<QRContent>
<QRTitle>Scan me</QRTitle>
<QRDescription>Must be on the same network as this device.</QRDescription>
<QRTitle>Scan to open</QRTitle>
<QRDescription>
{isDevelopment
? 'Device must be on the same network.'
: 'View story on another device.'}
</QRDescription>
</QRContent>
</QRContainer>
),
},
]);

return baseLinks;
}, [baseUrl, storyId, queryParams, copied, qrUrl, enableShortcuts, copyStoryLink]);
}, [baseUrl, storyId, queryParams, copied, qrUrl, enableShortcuts, copyStoryLink, isDevelopment]);

return <TooltipLinkList links={links} />;
return <TooltipLinkList links={links} style={{ width: 210 }} />;
}

export const shareTool: Addon_BaseType = {
Expand All @@ -152,15 +158,18 @@ export const shareTool: Addon_BaseType = {
return (
<Consumer filter={mapper}>
{({ baseUrl, storyId, queryParams }) => {
const isDevelopment = global.CONFIG_TYPE === 'DEVELOPMENT';
const storyUrl = global.STORYBOOK_NETWORK_ADDRESS
? `${global.STORYBOOK_NETWORK_ADDRESS}${window.location.search}`
? new URL(window.location.search, global.STORYBOOK_NETWORK_ADDRESS).href
: window.location.href;

return storyId ? (
<WithTooltip
hasChrome
placement="bottom"
tooltip={<ShareMenu {...{ baseUrl, storyId, queryParams, qrUrl: storyUrl }} />}
tooltip={
<ShareMenu {...{ baseUrl, storyId, queryParams, qrUrl: storyUrl, isDevelopment }} />
}
>
<IconButton title="Share">
<ShareIcon />
Expand Down