signal-desktop/ts/components/conversation/ImageGrid.stories.tsx

324 lines
7.9 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-26 18:32:24 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type { Props } from './ImageGrid';
import { ImageGrid } from './ImageGrid';
2020-08-26 18:32:24 +00:00
import {
AUDIO_MP3,
IMAGE_JPEG,
IMAGE_PNG,
IMAGE_WEBP,
VIDEO_MP4,
2021-08-09 20:06:21 +00:00
stringToMIMEType,
2020-08-26 18:32:24 +00:00
} from '../../types/MIME';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
2020-08-26 18:32:24 +00:00
import enMessages from '../../../_locales/en/messages.json';
import { pngUrl, squareStickerUrl } from '../../storybook/Fixtures';
import { fakeAttachment } from '../../test-both/helpers/fakeAttachment';
2020-09-14 19:51:27 +00:00
2020-08-26 18:32:24 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/ImageGrid',
argTypes: {
bottomOverlay: { control: { type: 'boolean' } },
isSticker: { control: { type: 'boolean' } },
stickerSize: { control: { type: 'number' } },
withContentAbove: { control: { type: 'boolean' } },
withContentBelow: { control: { type: 'boolean' } },
},
args: {
2020-08-26 18:32:24 +00:00
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
2020-08-26 18:32:24 +00:00
],
bottomOverlay: false,
direction: 'incoming',
i18n,
isSticker: false,
onClick: action('onClick'),
onError: action('onError'),
stickerSize: 0,
tabIndex: 0,
withContentAbove: false,
withContentBelow: false,
},
} satisfies Meta<Props>;
2020-08-26 18:32:24 +00:00
export function OneImage(args: Props): JSX.Element {
return <ImageGrid {...args} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:32:24 +00:00
export function TwoImages(args: Props): JSX.Element {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
]}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:32:24 +00:00
export function ThreeImages(args: Props): JSX.Element {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
]}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:32:24 +00:00
export function FourImages(args: Props): JSX.Element {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
]}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:32:24 +00:00
export function FiveImages(args: Props): JSX.Element {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
]}
/>
);
}
2022-06-07 00:48:02 +00:00
export const _6Images = (args: Props): JSX.Element => {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
]}
/>
);
2022-06-07 00:48:02 +00:00
};
export function MixedContentTypes(args: Props): JSX.Element {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
2020-08-26 18:32:24 +00:00
height: 112,
screenshot: {
height: 112,
width: 112,
url: '/fixtures/kitten-4-112-112.jpg',
contentType: IMAGE_JPEG,
path: 'originalpath',
},
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
2020-08-26 18:32:24 +00:00
width: 112,
}),
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
contentType: stringToMIMEType('text/plain'),
fileName: 'lorem-ipsum.txt',
url: '/fixtures/lorem-ipsum.txt',
}),
fakeAttachment({
contentType: AUDIO_MP3,
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
url: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
}),
]}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:32:24 +00:00
export function Sticker(args: Props): JSX.Element {
return (
<ImageGrid
{...args}
attachments={[
fakeAttachment({
contentType: IMAGE_WEBP,
fileName: 'sticker.webp',
height: 512,
url: squareStickerUrl,
width: 512,
}),
]}
isSticker
stickerSize={128}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:32:24 +00:00
export function ContentAboveAndBelow(args: Props): JSX.Element {
return <ImageGrid {...args} withContentAbove withContentBelow />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function BottomOverlay(args: Props): JSX.Element {
return <ImageGrid {...args} bottomOverlay />;
2022-11-18 00:45:19 +00:00
}