// Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { DecoratorFunction } from '@storybook/addons'; import * as React from 'react'; import { action } from '@storybook/addon-actions'; import { boolean, select } from '@storybook/addon-knobs'; import { IMAGE_JPEG } from '../types/MIME'; import type { Props } from './CompositionArea'; import { CompositionArea } from './CompositionArea'; import { setupI18n } from '../util/setupI18n'; import enMessages from '../../_locales/en/messages.json'; import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext'; import { fakeDraftAttachment } from '../test-both/helpers/fakeAttachment'; import { landscapeGreenUrl } from '../storybook/Fixtures'; import { RecordingState } from '../state/ducks/audioRecorder'; import { ConversationColors } from '../types/Colors'; import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation'; import { PaymentEventKind } from '../types/Payment'; const i18n = setupI18n('en', enMessages); export default { title: 'Components/CompositionArea', decorators: [ // necessary for the add attachment button to render properly storyFn =>
{storyFn()}
, ] as Array>, }; const useProps = (overrideProps: Partial = {}): Props => ({ addAttachment: action('addAttachment'), addPendingAttachment: action('addPendingAttachment'), conversationId: '123', i18n, onSendMessage: action('onSendMessage'), processAttachments: action('processAttachments'), removeAttachment: action('removeAttachment'), theme: React.useContext(StorybookThemeContext), // AttachmentList draftAttachments: overrideProps.draftAttachments || [], onClearAttachments: action('onClearAttachments'), // AudioCapture cancelRecording: action('cancelRecording'), completeRecording: action('completeRecording'), errorRecording: action('errorRecording'), recordingState: select( 'recordingState', RecordingState, overrideProps.recordingState || RecordingState.Idle ), startRecording: action('startRecording'), // StagedLinkPreview linkPreviewLoading: Boolean(overrideProps.linkPreviewLoading), linkPreviewResult: overrideProps.linkPreviewResult, onCloseLinkPreview: action('onCloseLinkPreview'), // Quote quotedMessageProps: overrideProps.quotedMessageProps, onClickQuotedMessage: action('onClickQuotedMessage'), setQuotedMessage: action('setQuotedMessage'), // MediaEditor imageToBlurHash: async () => 'LDA,FDBnm+I=p{tkIUI;~UkpELV]', // MediaQualitySelector onSelectMediaQuality: action('onSelectMediaQuality'), shouldSendHighQualityAttachments: Boolean( overrideProps.shouldSendHighQualityAttachments ), // CompositionInput onEditorStateChange: action('onEditorStateChange'), onTextTooLong: action('onTextTooLong'), draftText: overrideProps.draftText || undefined, clearQuotedMessage: action('clearQuotedMessage'), getPreferredBadge: () => undefined, getQuotedMessage: action('getQuotedMessage'), sortedGroupMembers: [], // EmojiButton onPickEmoji: action('onPickEmoji'), onSetSkinTone: action('onSetSkinTone'), recentEmojis: [], skinTone: 1, // StickerButton knownPacks: overrideProps.knownPacks || [], receivedPacks: [], installedPacks: [], blessedPacks: [], recentStickers: [], clearInstalledStickerPack: action('clearInstalledStickerPack'), onClickAddPack: action('onClickAddPack'), onPickSticker: action('onPickSticker'), clearShowIntroduction: action('clearShowIntroduction'), showPickerHint: false, clearShowPickerHint: action('clearShowPickerHint'), // Message Requests conversationType: 'direct', onAccept: action('onAccept'), onBlock: action('onBlock'), onBlockAndReportSpam: action('onBlockAndReportSpam'), onDelete: action('onDelete'), onUnblock: action('onUnblock'), messageRequestsEnabled: boolean( 'messageRequestsEnabled', overrideProps.messageRequestsEnabled || false ), title: '', // GroupV1 Disabled Actions onStartGroupMigration: action('onStartGroupMigration'), // GroupV2 announcementsOnly: boolean( 'announcementsOnly', Boolean(overrideProps.announcementsOnly) ), areWeAdmin: boolean('areWeAdmin', Boolean(overrideProps.areWeAdmin)), groupAdmins: [], openConversation: action('openConversation'), onCancelJoinRequest: action('onCancelJoinRequest'), // SMS-only isSMSOnly: overrideProps.isSMSOnly || false, isFetchingUUID: overrideProps.isFetchingUUID || false, }); export function Default(): JSX.Element { const props = useProps(); return ; } export function StartingText(): JSX.Element { const props = useProps({ draftText: "here's some starting text", }); return ; } export function StickerButton(): JSX.Element { const props = useProps({ // eslint-disable-next-line @typescript-eslint/no-explicit-any knownPacks: [{} as any], }); return ; } export function MessageRequest(): JSX.Element { const props = useProps({ messageRequestsEnabled: true, }); return ; } export function SmsOnlyFetchingUuid(): JSX.Element { const props = useProps({ isSMSOnly: true, isFetchingUUID: true, }); return ; } SmsOnlyFetchingUuid.story = { name: 'SMS-only fetching UUID', }; export function SmsOnly(): JSX.Element { const props = useProps({ isSMSOnly: true, }); return ; } SmsOnly.story = { name: 'SMS-only', }; export function Attachments(): JSX.Element { const props = useProps({ draftAttachments: [ fakeDraftAttachment({ contentType: IMAGE_JPEG, url: landscapeGreenUrl, }), ], }); return ; } export function AnnouncementsOnlyGroup(): JSX.Element { return ( ); } AnnouncementsOnlyGroup.story = { name: 'Announcements Only group', }; export function Quote(): JSX.Element { return ( ); } export function QuoteWithPayment(): JSX.Element { return ( ); } QuoteWithPayment.story = { name: 'Quote with payment', };