signal-desktop/ts/components/conversation/media-gallery/MediaGridItem.stories.tsx

144 lines
3.3 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-21 17:27:09 +00:00
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { text, withKnobs } from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions';
import { setup as setupI18n } from '../../../../js/modules/i18n';
import enMessages from '../../../../_locales/en/messages.json';
2021-08-23 23:14:53 +00:00
import { MediaItemType } from '../../../types/MediaItem';
2020-08-21 17:27:09 +00:00
import { AttachmentType } from '../../../types/Attachment';
2021-08-09 20:06:21 +00:00
import { stringToMIMEType } from '../../../types/MIME';
2020-08-21 17:27:09 +00:00
import { MediaGridItem, Props } from './MediaGridItem';
const i18n = setupI18n('en', enMessages);
const story = storiesOf(
'Components/Conversation/MediaGallery/MediaGridItem',
module
);
2020-09-14 19:51:27 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020-08-21 17:27:09 +00:00
story.addDecorator((withKnobs as any)({ escapeHTML: false }));
const createProps = (
overrideProps: Partial<Props> & { mediaItem: MediaItemType }
): Props => ({
i18n,
mediaItem: overrideProps.mediaItem,
onClick: action('onClick'),
});
const createMediaItem = (
overrideProps: Partial<MediaItemType> = {}
): MediaItemType => ({
thumbnailObjectUrl: text(
'thumbnailObjectUrl',
overrideProps.thumbnailObjectUrl || ''
),
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType(
text('contentType', overrideProps.contentType || '')
),
2020-08-21 17:27:09 +00:00
index: 0,
attachment: {} as AttachmentType, // attachment not useful in the component
2021-08-23 23:14:53 +00:00
message: {
attachments: [],
conversationId: '1234',
id: 'id',
received_at: Date.now(),
received_at_ms: Date.now(),
2021-08-25 21:08:32 +00:00
sent_at: Date.now(),
2021-08-23 23:14:53 +00:00
},
2020-08-21 17:27:09 +00:00
});
story.add('Image', () => {
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/fixtures/kitten-1-64-64.jpg',
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('image/jpeg'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});
story.add('Video', () => {
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/fixtures/kitten-2-64-64.jpg',
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('video/mp4'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});
story.add('Missing Image', () => {
const mediaItem = createMediaItem({
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('image/jpeg'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});
story.add('Missing Video', () => {
const mediaItem = createMediaItem({
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('video/mp4'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});
story.add('Broken Image', () => {
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/missing-fixtures/nope.jpg',
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('image/jpeg'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});
story.add('Broken Video', () => {
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/missing-fixtures/nope.mp4',
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('video/mp4'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});
story.add('Other ContentType', () => {
const mediaItem = createMediaItem({
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('application/text'),
2020-08-21 17:27:09 +00:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
});