2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-17 18:55:07 +00:00
import * as React from 'react' ;
import { storiesOf } from '@storybook/react' ;
import { text } from '@storybook/addon-knobs' ;
import { action } from '@storybook/addon-actions' ;
2021-10-26 19:15:33 +00:00
import type { Props } from './CaptionEditor' ;
import { CaptionEditor } from './CaptionEditor' ;
2020-08-17 18:55:07 +00:00
import { AUDIO_MP3 , IMAGE_JPEG , VIDEO_MP4 } from '../types/MIME' ;
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n' ;
2020-08-17 18:55:07 +00:00
import enMessages from '../../_locales/en/messages.json' ;
2021-10-05 22:10:08 +00:00
import { fakeAttachment } from '../test-both/helpers/fakeAttachment' ;
2020-08-17 18:55:07 +00:00
const i18n = setupI18n ( 'en' , enMessages ) ;
const stories = storiesOf ( 'Components/Caption Editor' , module ) ;
const createProps = ( overrideProps : Partial < Props > = { } ) : Props = > ( {
2021-10-05 22:10:08 +00:00
attachment : fakeAttachment ( {
2020-08-17 18:55:07 +00:00
contentType : IMAGE_JPEG ,
fileName : '' ,
url : '' ,
. . . overrideProps . attachment ,
2021-10-05 22:10:08 +00:00
} ) ,
2020-08-17 18:55:07 +00:00
caption : text ( 'caption' , overrideProps . caption || '' ) ,
close : action ( 'close' ) ,
i18n ,
onSave : action ( 'onSave' ) ,
url : text ( 'url' , overrideProps . url || '' ) ,
} ) ;
stories . add ( 'Image' , ( ) = > {
const props = createProps ( {
url : '/fixtures/tina-rolf-269345-unsplash.jpg' ,
} ) ;
return < CaptionEditor { ...props } / > ;
} ) ;
stories . add ( 'Image with Caption' , ( ) = > {
const props = createProps ( {
caption :
'This is the user-provided caption. We show it overlaid on the image. If it is really long, then it wraps, but it does not get too close to the edges of the image.' ,
url : '/fixtures/tina-rolf-269345-unsplash.jpg' ,
} ) ;
return < CaptionEditor { ...props } / > ;
} ) ;
stories . add ( 'Video' , ( ) = > {
const props = createProps ( {
2021-10-05 22:10:08 +00:00
attachment : fakeAttachment ( {
2020-08-17 18:55:07 +00:00
contentType : VIDEO_MP4 ,
fileName : 'pixabay-Soap-Bubble-7141.mp4' ,
url : '/fixtures/pixabay-Soap-Bubble-7141.mp4' ,
2021-10-05 22:10:08 +00:00
} ) ,
2020-08-17 18:55:07 +00:00
url : '/fixtures/pixabay-Soap-Bubble-7141.mp4' ,
} ) ;
return < CaptionEditor { ...props } / > ;
} ) ;
stories . add ( 'Video with Caption' , ( ) = > {
const props = createProps ( {
2021-10-05 22:10:08 +00:00
attachment : fakeAttachment ( {
2020-08-17 18:55:07 +00:00
contentType : VIDEO_MP4 ,
fileName : 'pixabay-Soap-Bubble-7141.mp4' ,
url : '/fixtures/pixabay-Soap-Bubble-7141.mp4' ,
2021-10-05 22:10:08 +00:00
} ) ,
2020-08-17 18:55:07 +00:00
caption :
'This is the user-provided caption. We show it overlaid on the image. If it is really long, then it wraps, but it does not get too close to the edges of the image.' ,
url : '/fixtures/pixabay-Soap-Bubble-7141.mp4' ,
} ) ;
return < CaptionEditor { ...props } / > ;
} ) ;
stories . add ( 'Unsupported Attachment Type' , ( ) = > {
const props = createProps ( {
2021-10-05 22:10:08 +00:00
attachment : fakeAttachment ( {
2020-08-17 18:55:07 +00:00
contentType : AUDIO_MP3 ,
fileName : 'incompetech-com-Agnus-Dei-X.mp3' ,
url : '/fixtures/incompetech-com-Agnus-Dei-X.mp3' ,
2021-10-05 22:10:08 +00:00
} ) ,
2020-08-17 18:55:07 +00:00
url : '/fixtures/incompetech-com-Agnus-Dei-X.mp3' ,
} ) ;
return < CaptionEditor { ...props } / > ;
} ) ;