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

326 lines
7.7 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 { boolean, number } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';
import { ImageGrid, Props } from './ImageGrid';
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);
const story = storiesOf('Components/Conversation/ImageGrid', module);
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
attachments: overrideProps.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: boolean('bottomOverlay', overrideProps.bottomOverlay || false),
i18n,
isSticker: boolean('isSticker', overrideProps.isSticker || false),
onClick: action('onClick'),
onError: action('onError'),
stickerSize: number('stickerSize', overrideProps.stickerSize || 0),
tabIndex: number('tabIndex', overrideProps.tabIndex || 0),
withContentAbove: boolean(
'withContentAbove',
overrideProps.withContentAbove || false
),
withContentBelow: boolean(
'withContentBelow',
overrideProps.withContentBelow || false
),
});
story.add('One Image', () => {
const props = createProps();
return <ImageGrid {...props} />;
});
story.add('Two Images', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
2020-08-26 18:32:24 +00:00
],
});
return <ImageGrid {...props} />;
});
story.add('Three Images', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
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
],
});
return <ImageGrid {...props} />;
});
story.add('Four Images', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
2020-08-26 18:32:24 +00:00
],
});
return <ImageGrid {...props} />;
});
story.add('Five Images', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
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
],
});
return <ImageGrid {...props} />;
});
story.add('6+ Images', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
height: 1680,
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
width: 3000,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
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
],
});
return <ImageGrid {...props} />;
});
story.add('Mixed Content Types', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
height: 112,
screenshot: {
height: 112,
width: 112,
url: '/fixtures/kitten-4-112-112.jpg',
contentType: IMAGE_JPEG,
path: 'originalpath',
2020-08-26 18:32:24 +00:00
},
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
width: 112,
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
height: 1200,
url: pngUrl,
width: 800,
}),
fakeAttachment({
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('text/plain'),
2020-08-26 18:32:24 +00:00
fileName: 'lorem-ipsum.txt',
url: '/fixtures/lorem-ipsum.txt',
}),
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: AUDIO_MP3,
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
url: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
}),
2020-08-26 18:32:24 +00:00
],
});
return <ImageGrid {...props} />;
});
story.add('Sticker', () => {
const props = createProps({
attachments: [
fakeAttachment({
2020-08-26 18:32:24 +00:00
contentType: IMAGE_WEBP,
fileName: 'sticker.webp',
height: 512,
url: squareStickerUrl,
width: 512,
}),
2020-08-26 18:32:24 +00:00
],
isSticker: true,
stickerSize: 128,
});
return <ImageGrid {...props} />;
});
story.add('Content Above and Below', () => {
const props = createProps({
withContentAbove: true,
withContentBelow: true,
});
return <ImageGrid {...props} />;
});
story.add('Bottom Overlay', () => {
const props = createProps({
bottomOverlay: true,
});
return <ImageGrid {...props} />;
});