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

133 lines
3.2 KiB
TypeScript
Raw Normal View History

2020-10-30 15:34:04 -05:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-21 10:27:09 -07:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
2021-09-17 20:30:08 -04:00
import { setupI18n } from '../../../util/setupI18n';
2020-08-21 10:27:09 -07:00
import enMessages from '../../../../_locales/en/messages.json';
import type { MediaItemType } from '../../../types/MediaItem';
import type { AttachmentType } from '../../../types/Attachment';
2021-08-09 16:06:21 -04:00
import { stringToMIMEType } from '../../../types/MIME';
import type { Props } from './MediaGridItem';
import { MediaGridItem } from './MediaGridItem';
2020-08-21 10:27:09 -07:00
const i18n = setupI18n('en', enMessages);
2022-06-06 20:48:02 -04:00
export default {
title: 'Components/Conversation/MediaGallery/MediaGridItem',
} satisfies Meta<Props>;
2020-08-21 10:27:09 -07:00
const createProps = (
overrideProps: Partial<Props> & { mediaItem: MediaItemType }
): Props => ({
i18n,
mediaItem: overrideProps.mediaItem,
onClick: action('onClick'),
});
const createMediaItem = (
overrideProps: Partial<MediaItemType> = {}
): MediaItemType => ({
thumbnailObjectUrl: overrideProps.thumbnailObjectUrl || '',
contentType: overrideProps.contentType || stringToMIMEType(''),
2020-08-21 10:27:09 -07:00
index: 0,
attachment: {} as AttachmentType, // attachment not useful in the component
2021-08-23 19:14:53 -04:00
message: {
attachments: [],
conversationId: '1234',
id: 'id',
receivedAt: Date.now(),
receivedAtMs: Date.now(),
sentAt: Date.now(),
2021-08-23 19:14:53 -04:00
},
2020-08-21 10:27:09 -07:00
});
2022-11-17 16:45:19 -08:00
export function Image(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/fixtures/kitten-1-64-64.jpg',
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('image/jpeg'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}
2020-08-21 10:27:09 -07:00
2022-11-17 16:45:19 -08:00
export function Video(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/fixtures/kitten-2-64-64.jpg',
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('video/mp4'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}
2020-08-21 10:27:09 -07:00
2022-11-17 16:45:19 -08:00
export function MissingImage(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('image/jpeg'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}
2020-08-21 10:27:09 -07:00
2022-11-17 16:45:19 -08:00
export function MissingVideo(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('video/mp4'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}
2020-08-21 10:27:09 -07:00
2022-11-17 16:45:19 -08:00
export function BrokenImage(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/missing-fixtures/nope.jpg',
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('image/jpeg'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}
2020-08-21 10:27:09 -07:00
2022-11-17 16:45:19 -08:00
export function BrokenVideo(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
thumbnailObjectUrl: '/missing-fixtures/nope.mp4',
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('video/mp4'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}
2020-08-21 10:27:09 -07:00
2022-11-17 16:45:19 -08:00
export function OtherContentType(): JSX.Element {
2020-08-21 10:27:09 -07:00
const mediaItem = createMediaItem({
2021-08-09 16:06:21 -04:00
contentType: stringToMIMEType('application/text'),
2020-08-21 10:27:09 -07:00
});
const props = createProps({
mediaItem,
});
return <MediaGridItem {...props} />;
2022-11-17 16:45:19 -08:00
}