Signal-Desktop/ts/components/CompositionArea.stories.tsx

218 lines
6.2 KiB
TypeScript
Raw Permalink Normal View History

// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2022-06-07 00:48:02 +00:00
import type { DecoratorFunction } from '@storybook/addons';
2020-08-17 18:53:09 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import { boolean, select } from '@storybook/addon-knobs';
2020-08-17 18:53:09 +00:00
import { IMAGE_JPEG } from '../types/MIME';
import type { Props } from './CompositionArea';
import { CompositionArea } from './CompositionArea';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-08-17 18:53:09 +00:00
import enMessages from '../../_locales/en/messages.json';
2021-11-17 18:38:52 +00:00
import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext';
2020-08-17 18:53:09 +00:00
import { fakeDraftAttachment } from '../test-both/helpers/fakeAttachment';
import { landscapeGreenUrl } from '../storybook/Fixtures';
import { RecordingState } from '../state/ducks/audioRecorder';
import { ConversationColors } from '../types/Colors';
2020-08-17 18:53:09 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/CompositionArea',
decorators: [
// necessary for the add attachment button to render properly
storyFn => <div className="file-input">{storyFn()}</div>,
] as Array<DecoratorFunction<JSX.Element>>,
};
2020-08-17 18:53:09 +00:00
2021-11-17 18:38:52 +00:00
const useProps = (overrideProps: Partial<Props> = {}): Props => ({
2021-09-24 20:02:30 +00:00
addAttachment: action('addAttachment'),
addPendingAttachment: action('addPendingAttachment'),
2021-09-29 20:23:06 +00:00
conversationId: '123',
i18n,
onSendMessage: action('onSendMessage'),
2021-09-24 20:02:30 +00:00
processAttachments: action('processAttachments'),
removeAttachment: action('removeAttachment'),
2021-11-17 18:38:52 +00:00
theme: React.useContext(StorybookThemeContext),
2021-09-24 20:02:30 +00:00
2021-06-25 16:08:16 +00:00
// AttachmentList
draftAttachments: overrideProps.draftAttachments || [],
2021-06-25 16:08:16 +00:00
onClearAttachments: action('onClearAttachments'),
2021-09-29 20:23:06 +00:00
// AudioCapture
cancelRecording: action('cancelRecording'),
completeRecording: action('completeRecording'),
errorRecording: action('errorRecording'),
recordingState: select(
'recordingState',
RecordingState,
overrideProps.recordingState || RecordingState.Idle
),
2021-09-29 20:23:06 +00:00
startRecording: action('startRecording'),
2021-06-25 16:08:16 +00:00
// StagedLinkPreview
linkPreviewLoading: Boolean(overrideProps.linkPreviewLoading),
linkPreviewResult: overrideProps.linkPreviewResult,
onCloseLinkPreview: action('onCloseLinkPreview'),
// Quote
quotedMessageProps: overrideProps.quotedMessageProps,
onClickQuotedMessage: action('onClickQuotedMessage'),
setQuotedMessage: action('setQuotedMessage'),
// MediaQualitySelector
onSelectMediaQuality: action('onSelectMediaQuality'),
shouldSendHighQualityAttachments: Boolean(
overrideProps.shouldSendHighQualityAttachments
),
2020-08-17 18:53:09 +00:00
// CompositionInput
onEditorStateChange: action('onEditorStateChange'),
onTextTooLong: action('onTextTooLong'),
2020-11-03 01:19:52 +00:00
draftText: overrideProps.draftText || undefined,
2020-08-17 18:53:09 +00:00
clearQuotedMessage: action('clearQuotedMessage'),
2021-11-17 18:38:52 +00:00
getPreferredBadge: () => undefined,
2020-08-17 18:53:09 +00:00
getQuotedMessage: action('getQuotedMessage'),
sortedGroupMembers: [],
2020-08-17 18:53:09 +00:00
// 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'),
2020-08-17 18:53:09 +00:00
onDelete: action('onDelete'),
onUnblock: action('onUnblock'),
messageRequestsEnabled: boolean(
'messageRequestsEnabled',
overrideProps.messageRequestsEnabled || false
),
title: '',
// GroupV1 Disabled Actions
onStartGroupMigration: action('onStartGroupMigration'),
2021-07-20 20:18:35 +00:00
// 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,
2020-08-17 18:53:09 +00:00
});
2022-06-07 00:48:02 +00:00
export const Default = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps();
2020-08-17 18:53:09 +00:00
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-17 18:53:09 +00:00
2022-06-07 00:48:02 +00:00
export const StartingText = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps({
2020-11-03 01:19:52 +00:00
draftText: "here's some starting text",
2020-08-17 18:53:09 +00:00
});
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-17 18:53:09 +00:00
2022-06-07 00:48:02 +00:00
export const StickerButton = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps({
2020-09-12 00:46:52 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020-08-17 18:53:09 +00:00
knownPacks: [{} as any],
});
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-17 18:53:09 +00:00
2022-06-07 00:48:02 +00:00
export const MessageRequest = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps({
2020-08-17 18:53:09 +00:00
messageRequestsEnabled: true,
});
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const SmsOnlyFetchingUuid = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps({
isSMSOnly: true,
isFetchingUUID: true,
});
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
SmsOnlyFetchingUuid.story = {
name: 'SMS-only fetching UUID',
};
export const SmsOnly = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps({
isSMSOnly: true,
});
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
SmsOnly.story = {
name: 'SMS-only',
};
2022-06-07 00:48:02 +00:00
export const Attachments = (): JSX.Element => {
2021-11-17 18:38:52 +00:00
const props = useProps({
draftAttachments: [
fakeDraftAttachment({
contentType: IMAGE_JPEG,
url: landscapeGreenUrl,
}),
],
});
return <CompositionArea {...props} />;
2022-06-07 00:48:02 +00:00
};
2021-07-20 20:18:35 +00:00
2022-06-07 00:48:02 +00:00
export const AnnouncementsOnlyGroup = (): JSX.Element => (
2021-07-20 20:18:35 +00:00
<CompositionArea
2021-11-17 18:38:52 +00:00
{...useProps({
2021-07-20 20:18:35 +00:00
announcementsOnly: true,
areWeAdmin: false,
})}
/>
2022-06-07 00:48:02 +00:00
);
AnnouncementsOnlyGroup.story = {
name: 'Announcements Only group',
};
2022-06-07 00:48:02 +00:00
export const Quote = (): JSX.Element => (
<CompositionArea
{...useProps({
quotedMessageProps: {
text: 'something',
conversationColor: ConversationColors[10],
2022-05-11 20:59:58 +00:00
isGiftBadge: false,
isViewOnce: false,
referencedMessageNotFound: false,
authorTitle: 'Someone',
isFromMe: false,
},
})}
/>
2022-06-07 00:48:02 +00:00
);