2021-05-27 20:17:05 +00:00
|
|
|
// 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';
|
2021-11-11 23:33:35 +00:00
|
|
|
import { boolean, select } from '@storybook/addon-knobs';
|
2020-08-17 18:53:09 +00:00
|
|
|
|
2021-07-07 17:05:03 +00:00
|
|
|
import { IMAGE_JPEG } from '../types/MIME';
|
2021-10-26 19:15:33 +00:00
|
|
|
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
|
|
|
|
2021-11-15 21:54:33 +00:00
|
|
|
import { fakeDraftAttachment } from '../test-both/helpers/fakeAttachment';
|
2021-10-05 22:10:08 +00:00
|
|
|
import { landscapeGreenUrl } from '../storybook/Fixtures';
|
2021-11-11 23:33:35 +00:00
|
|
|
import { RecordingState } from '../state/ducks/audioRecorder';
|
2022-04-07 16:58:15 +00:00
|
|
|
import { ConversationColors } from '../types/Colors';
|
2021-10-05 22:10:08 +00:00
|
|
|
|
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
|
2021-07-07 17:05:03 +00:00
|
|
|
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'),
|
2021-11-11 23:33:35 +00:00
|
|
|
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'),
|
2021-01-29 21:19:24 +00:00
|
|
|
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'),
|
2021-05-27 20:17:05 +00:00
|
|
|
onBlockAndReportSpam: action('onBlockAndReportSpam'),
|
2020-08-17 18:53:09 +00:00
|
|
|
onDelete: action('onDelete'),
|
|
|
|
onUnblock: action('onUnblock'),
|
|
|
|
messageRequestsEnabled: boolean(
|
|
|
|
'messageRequestsEnabled',
|
|
|
|
overrideProps.messageRequestsEnabled || false
|
|
|
|
),
|
|
|
|
title: '',
|
2020-12-01 16:42:35 +00:00
|
|
|
// 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'),
|
2021-01-29 22:16:48 +00:00
|
|
|
onCancelJoinRequest: action('onCancelJoinRequest'),
|
2021-05-13 20:57:27 +00:00
|
|
|
// 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
|
|
|
};
|
2021-05-13 20:57:27 +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({
|
2021-05-13 20:57:27 +00:00
|
|
|
isSMSOnly: true,
|
|
|
|
isFetchingUUID: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return <CompositionArea {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
2021-05-13 20:57:27 +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({
|
2021-05-13 20:57:27 +00:00
|
|
|
isSMSOnly: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return <CompositionArea {...props} />;
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SmsOnly.story = {
|
|
|
|
name: 'SMS-only',
|
|
|
|
};
|
2021-07-07 17:05:03 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const Attachments = (): JSX.Element => {
|
2021-11-17 18:38:52 +00:00
|
|
|
const props = useProps({
|
2021-07-07 17:05:03 +00:00
|
|
|
draftAttachments: [
|
2021-11-15 21:54:33 +00:00
|
|
|
fakeDraftAttachment({
|
2021-07-07 17:05:03 +00:00
|
|
|
contentType: IMAGE_JPEG,
|
2021-10-05 22:10:08 +00:00
|
|
|
url: landscapeGreenUrl,
|
|
|
|
}),
|
2021-07-07 17:05:03 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
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-04-07 16:58:15 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const Quote = (): JSX.Element => (
|
2022-04-07 16:58:15 +00:00
|
|
|
<CompositionArea
|
|
|
|
{...useProps({
|
|
|
|
quotedMessageProps: {
|
|
|
|
text: 'something',
|
|
|
|
conversationColor: ConversationColors[10],
|
2022-05-11 20:59:58 +00:00
|
|
|
isGiftBadge: false,
|
2022-04-07 16:58:15 +00:00
|
|
|
isViewOnce: false,
|
|
|
|
referencedMessageNotFound: false,
|
|
|
|
authorTitle: 'Someone',
|
|
|
|
isFromMe: false,
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|