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

119 lines
3.4 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-20 21:50:43 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type {
AttachmentDraftType,
AttachmentType,
} from '../../types/Attachment';
import type { Props } from './AttachmentList';
import { AttachmentList } from './AttachmentList';
2020-08-20 21:50:43 +00:00
import {
AUDIO_MP3,
IMAGE_GIF,
IMAGE_JPEG,
VIDEO_MP4,
2021-08-09 20:06:21 +00:00
stringToMIMEType,
2020-08-20 21:50:43 +00:00
} from '../../types/MIME';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
2020-08-20 21:50:43 +00:00
import enMessages from '../../../_locales/en/messages.json';
import { fakeDraftAttachment } from '../../test-both/helpers/fakeAttachment';
2020-08-20 21:50:43 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/AttachmentList',
} satisfies Meta<Props<AttachmentDraftType | AttachmentType>>;
2020-08-20 21:50:43 +00:00
2021-12-03 01:05:32 +00:00
const createProps = (
overrideProps: Partial<Props<AttachmentDraftType>> = {}
): Props<AttachmentDraftType> => ({
2020-08-20 21:50:43 +00:00
attachments: overrideProps.attachments || [],
i18n,
onAddAttachment: action('onAddAttachment'),
onClickAttachment: action('onClickAttachment'),
onClose: action('onClose'),
onCloseAttachment: action('onCloseAttachment'),
});
2022-11-18 00:45:19 +00:00
export function OneFile(): JSX.Element {
2020-08-20 21:50:43 +00:00
const props = createProps({
attachments: [
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
}),
2020-08-20 21:50:43 +00:00
],
});
2021-12-15 00:53:15 +00:00
return <AttachmentList {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-20 21:50:43 +00:00
2022-11-18 00:45:19 +00:00
export function MultipleVisualAttachments(): JSX.Element {
2020-08-20 21:50:43 +00:00
const props = createProps({
attachments: [
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
}),
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/kitten-4-112-112.jpg',
screenshotPath: '/fixtures/kitten-4-112-112.jpg',
}),
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: IMAGE_GIF,
fileName: 'giphy-GVNv0UpeYm17e',
url: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
}),
2020-08-20 21:50:43 +00:00
],
});
return <AttachmentList {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-20 21:50:43 +00:00
2022-11-18 00:45:19 +00:00
export function MultipleWithNonVisualTypes(): JSX.Element {
2020-08-20 21:50:43 +00:00
const props = createProps({
attachments: [
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
}),
fakeDraftAttachment({
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType('text/plain'),
2020-08-20 21:50:43 +00:00
fileName: 'lorem-ipsum.txt',
url: '/fixtures/lorem-ipsum.txt',
}),
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: AUDIO_MP3,
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
url: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
}),
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/kitten-4-112-112.jpg',
screenshotPath: '/fixtures/kitten-4-112-112.jpg',
}),
fakeDraftAttachment({
2020-08-20 21:50:43 +00:00
contentType: IMAGE_GIF,
fileName: 'giphy-GVNv0UpeYm17e',
url: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
}),
2020-08-20 21:50:43 +00:00
],
});
return <AttachmentList {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-20 21:50:43 +00:00
2022-11-18 00:45:19 +00:00
export function EmptyList(): JSX.Element {
2020-08-20 21:50:43 +00:00
const props = createProps();
return <AttachmentList {...props} />;
2022-11-18 00:45:19 +00:00
}