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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const FileCard: FunctionComponent<Props> = ({ file }) => {
`}
meta={file.meta as FileImageMetadata}
src={client.getDownloadHref({ id: file.id, fileKind: kind })}
loading={'lazy'}
/>
) : (
<div
Expand Down
64 changes: 0 additions & 64 deletions src/plugins/files/public/components/image/components/blurhash.tsx

This file was deleted.

61 changes: 0 additions & 61 deletions src/plugins/files/public/components/image/components/img.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions src/plugins/files/public/components/image/components/index.ts

This file was deleted.

67 changes: 27 additions & 40 deletions src/plugins/files/public/components/image/image.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@

import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { css } from '@emotion/react';

import { FilesContext } from '../context';
import { getImageMetadata } from '../util';
import { Image, Props } from './image';
import { getImageData as getBlob, base64dLogo } from './image.constants.stories';
import { FilesClient } from '../../types';

const defaultArgs: Props = { alt: 'test', src: `data:image/png;base64,${base64dLogo}` };

Expand All @@ -24,41 +20,38 @@ export default {
component: Image,
args: defaultArgs,
decorators: [
(Story) => (
<FilesContext client={{} as unknown as FilesClient}>
<Story />
</FilesContext>
),
(Story) => {
React.useLayoutEffect(() => {
// @ts-ignore
window.__image_stories_simulate_slow_load = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice hack 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally adding hack code into production for stories/tests should be avoided, but I see why you have done it in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that such hacks must be avoided.
I thought of also using process.env.NODE_ENV !== 'production but looks like env is production is storybook :(

return () => {
// @ts-ignore
window.__image_stories_simulate_slow_load = false;
};
}, []);

return (
<>
<Story />
</>
);
},
],
} as ComponentMeta<typeof Image>;

const Template: ComponentStory<typeof Image> = (props: Props, { loaded: { meta } }) => (
<Image size="original" {...props} meta={meta} ref={action('ref')} />
<Image {...props} meta={meta} />
);

export const Basic = Template.bind({});

export const WithBlurhash = Template.bind({});
WithBlurhash.storyName = 'With blurhash';
WithBlurhash.args = {
style: { visibility: 'hidden' },
};
WithBlurhash.loaders = [
async () => ({
meta: await getImageMetadata(getBlob()),
}),
];
WithBlurhash.decorators = [
(Story) => {
const alwaysShowBlurhash = `img:nth-of-type(1) { opacity: 1 !important; }`;
return (
<>
<style>{alwaysShowBlurhash}</style>
<Story />
</>
);
},
];

export const BrokenSrc = Template.bind({});
BrokenSrc.storyName = 'Broken src';
Expand All @@ -71,26 +64,20 @@ WithBlurhashAndBrokenSrc.storyName = 'With blurhash and broken src';
WithBlurhashAndBrokenSrc.args = {
src: 'foo',
};

WithBlurhashAndBrokenSrc.loaders = [
async () => ({
blurhash: await getImageMetadata(getBlob()),
}),
];

export const OffScreen = Template.bind({});
OffScreen.storyName = 'Offscreen';
OffScreen.args = { onFirstVisible: action('visible') };
OffScreen.decorators = [
(Story) => (
<>
<p>Scroll down</p>
<div
css={css`
margin-top: 100vh;
`}
>
<Story />
</div>
</>
),
export const WithCustomSizing = Template.bind({});
WithCustomSizing.storyName = 'With custom sizing';
WithCustomSizing.loaders = [
async () => ({
meta: await getImageMetadata(getBlob()),
}),
];
WithCustomSizing.args = {
css: `width: 100px; height: 500px; object-fit: fill`,
};
Loading