2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-21 22:05:32 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
import { boolean, text } from '@storybook/addon-knobs';
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
|
|
|
|
import { Lightbox, Props } from './Lightbox';
|
|
|
|
import {
|
|
|
|
AUDIO_MP3,
|
|
|
|
IMAGE_JPEG,
|
|
|
|
VIDEO_MP4,
|
|
|
|
VIDEO_QUICKTIME,
|
2021-08-09 20:06:21 +00:00
|
|
|
stringToMIMEType,
|
2020-08-21 22:05:32 +00:00
|
|
|
} from '../types/MIME';
|
|
|
|
import { setup as setupI18n } from '../../js/modules/i18n';
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
2020-09-12 00:46:52 +00:00
|
|
|
|
2020-08-21 22:05:32 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const story = storiesOf('Components/Lightbox', module);
|
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
|
|
|
caption: text('caption', overrideProps.caption || ''),
|
|
|
|
close: action('close'),
|
|
|
|
contentType: overrideProps.contentType || IMAGE_JPEG,
|
|
|
|
i18n,
|
|
|
|
isViewOnce: boolean('isViewOnce', overrideProps.isViewOnce || false),
|
|
|
|
objectURL: text('objectURL', overrideProps.objectURL || ''),
|
|
|
|
onNext: overrideProps.onNext,
|
|
|
|
onPrevious: overrideProps.onPrevious,
|
|
|
|
onSave: overrideProps.onSave,
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Image', () => {
|
|
|
|
const props = createProps({
|
|
|
|
objectURL: '/fixtures/tina-rolf-269345-unsplash.jpg',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
2021-06-29 21:13:36 +00:00
|
|
|
story.add('Image with Caption (normal image)', () => {
|
2020-08-21 22:05:32 +00:00
|
|
|
const props = createProps({
|
|
|
|
caption:
|
|
|
|
'This is the user-provided caption. It can get long and wrap onto multiple lines.',
|
|
|
|
objectURL: '/fixtures/tina-rolf-269345-unsplash.jpg',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
2021-06-29 21:13:36 +00:00
|
|
|
story.add('Image with Caption (all-white image)', () => {
|
|
|
|
const props = createProps({
|
|
|
|
caption:
|
|
|
|
'This is the user-provided caption. It should be visible on light backgrounds.',
|
|
|
|
objectURL: '/fixtures/2000x2000-white.png',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
2020-08-21 22:05:32 +00:00
|
|
|
story.add('Video', () => {
|
|
|
|
const props = createProps({
|
|
|
|
contentType: VIDEO_MP4,
|
|
|
|
objectURL: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Video with Caption', () => {
|
|
|
|
const props = createProps({
|
|
|
|
caption:
|
|
|
|
'This is the user-provided caption. It can get long and wrap onto multiple lines.',
|
|
|
|
contentType: VIDEO_MP4,
|
|
|
|
objectURL: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Video (View Once)', () => {
|
|
|
|
const props = createProps({
|
|
|
|
contentType: VIDEO_MP4,
|
|
|
|
isViewOnce: true,
|
|
|
|
objectURL: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Unsupported Image Type', () => {
|
|
|
|
const props = createProps({
|
2021-08-09 20:06:21 +00:00
|
|
|
contentType: stringToMIMEType('image/tiff'),
|
2020-08-21 22:05:32 +00:00
|
|
|
objectURL: 'unsupported-image.tiff',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Unsupported Video Type', () => {
|
|
|
|
const props = createProps({
|
|
|
|
contentType: VIDEO_QUICKTIME,
|
|
|
|
objectURL: 'unsupported-video.mov',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Unsupported ContentType', () => {
|
|
|
|
const props = createProps({
|
|
|
|
contentType: AUDIO_MP3,
|
|
|
|
objectURL: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Including Next/Previous/Save Callbacks', () => {
|
|
|
|
const props = createProps({
|
|
|
|
objectURL: '/fixtures/tina-rolf-269345-unsplash.jpg',
|
|
|
|
onNext: action('onNext'),
|
|
|
|
onPrevious: action('onPrevious'),
|
|
|
|
onSave: action('onSave'),
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Lightbox {...props} />;
|
|
|
|
});
|
2021-08-06 00:17:05 +00:00
|
|
|
|
|
|
|
story.add('Custom children', () => (
|
|
|
|
<Lightbox {...createProps({})} contentType={undefined}>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
color: 'white',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
I am middle child
|
|
|
|
</div>
|
|
|
|
</Lightbox>
|
|
|
|
));
|