2023-01-03 11:55:46 -08:00
|
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
2020-08-18 10:21:53 -07:00
|
|
|
|
import * as React from 'react';
|
2020-10-21 09:53:32 -07:00
|
|
|
|
import 'react-quill/dist/quill.core.css';
|
2020-08-18 10:21:53 -07:00
|
|
|
|
import { action } from '@storybook/addon-actions';
|
2023-10-11 12:06:43 -07:00
|
|
|
|
import type { Meta } from '@storybook/react';
|
2021-05-07 17:21:10 -05:00
|
|
|
|
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
|
2021-10-26 14:15:33 -05:00
|
|
|
|
import type { Props } from './CompositionInput';
|
|
|
|
|
import { CompositionInput } from './CompositionInput';
|
2021-09-17 20:30:08 -04:00
|
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2023-08-10 18:43:33 +02:00
|
|
|
|
import { generateAci } from '../types/ServiceId';
|
2020-08-18 10:21:53 -07:00
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
2021-11-17 12:38:52 -06:00
|
|
|
|
import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext';
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
2022-06-06 20:48:02 -04:00
|
|
|
|
export default {
|
|
|
|
|
title: 'Components/CompositionInput',
|
2023-10-11 12:06:43 -07:00
|
|
|
|
argTypes: {},
|
|
|
|
|
args: {},
|
|
|
|
|
} satisfies Meta<Props>;
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2024-03-12 09:29:31 -07:00
|
|
|
|
const useProps = (overrideProps: Partial<Props> = {}): Props => {
|
|
|
|
|
const conversation = getDefaultConversation();
|
|
|
|
|
return {
|
|
|
|
|
i18n,
|
|
|
|
|
conversationId: conversation.id,
|
|
|
|
|
disabled: overrideProps.disabled ?? false,
|
|
|
|
|
draftText: overrideProps.draftText ?? null,
|
|
|
|
|
draftEditMessage: overrideProps.draftEditMessage ?? null,
|
|
|
|
|
draftBodyRanges: overrideProps.draftBodyRanges || [],
|
|
|
|
|
clearQuotedMessage: action('clearQuotedMessage'),
|
|
|
|
|
getPreferredBadge: () => undefined,
|
|
|
|
|
getQuotedMessage: action('getQuotedMessage'),
|
2024-06-13 16:22:07 -07:00
|
|
|
|
isActive: true,
|
2024-03-12 09:29:31 -07:00
|
|
|
|
isFormattingEnabled:
|
|
|
|
|
overrideProps.isFormattingEnabled === false
|
|
|
|
|
? overrideProps.isFormattingEnabled
|
|
|
|
|
: true,
|
|
|
|
|
large: overrideProps.large ?? false,
|
|
|
|
|
onCloseLinkPreview: action('onCloseLinkPreview'),
|
|
|
|
|
onEditorStateChange: action('onEditorStateChange'),
|
|
|
|
|
onPickEmoji: action('onPickEmoji'),
|
|
|
|
|
onSubmit: action('onSubmit'),
|
|
|
|
|
onTextTooLong: action('onTextTooLong'),
|
|
|
|
|
platform: 'darwin',
|
|
|
|
|
sendCounter: 0,
|
|
|
|
|
sortedGroupMembers: overrideProps.sortedGroupMembers ?? [],
|
|
|
|
|
skinTone: overrideProps.skinTone ?? null,
|
|
|
|
|
theme: React.useContext(StorybookThemeContext),
|
|
|
|
|
inputApi: null,
|
|
|
|
|
shouldHidePopovers: null,
|
|
|
|
|
linkPreviewResult: null,
|
|
|
|
|
};
|
|
|
|
|
};
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function Default(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps();
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function Large(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps({
|
2020-08-18 10:21:53 -07:00
|
|
|
|
large: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function Disabled(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps({
|
2020-08-18 10:21:53 -07:00
|
|
|
|
disabled: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function StartingText(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps({
|
2020-11-02 17:19:52 -08:00
|
|
|
|
draftText: "here's some starting text",
|
2020-08-18 10:21:53 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function MultilineText(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps({
|
2020-11-02 17:19:52 -08:00
|
|
|
|
draftText: `here's some starting text
|
2020-08-18 10:21:53 -07:00
|
|
|
|
and more on another line
|
|
|
|
|
and yet another line
|
|
|
|
|
and yet another line
|
|
|
|
|
and yet another line
|
|
|
|
|
and yet another line
|
|
|
|
|
and yet another line
|
|
|
|
|
and yet another line
|
|
|
|
|
and we're done`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2020-08-18 10:21:53 -07:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function Emojis(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps({
|
2020-11-02 17:19:52 -08:00
|
|
|
|
draftText: `😐😐😐😐😐😐😐
|
2020-08-18 10:21:53 -07:00
|
|
|
|
😐😐😐😐😐😐😐
|
|
|
|
|
😐😐😐😂😐😐😐
|
|
|
|
|
😐😐😐😐😐😐😐
|
|
|
|
|
😐😐😐😐😐😐😐`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2020-11-02 17:19:52 -08:00
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
|
export function Mentions(): JSX.Element {
|
2021-11-17 12:38:52 -06:00
|
|
|
|
const props = useProps({
|
2021-01-29 16:19:24 -05:00
|
|
|
|
sortedGroupMembers: [
|
2021-05-07 17:21:10 -05:00
|
|
|
|
getDefaultConversation({
|
2020-11-02 17:19:52 -08:00
|
|
|
|
title: 'Kate Beaton',
|
2021-05-07 17:21:10 -05:00
|
|
|
|
}),
|
|
|
|
|
getDefaultConversation({
|
2020-11-02 17:19:52 -08:00
|
|
|
|
title: 'Parry Gripp',
|
2021-05-07 17:21:10 -05:00
|
|
|
|
}),
|
2020-11-02 17:19:52 -08:00
|
|
|
|
],
|
|
|
|
|
draftText: 'send _ a message',
|
|
|
|
|
draftBodyRanges: [
|
|
|
|
|
{
|
|
|
|
|
start: 5,
|
|
|
|
|
length: 1,
|
2023-08-16 22:54:39 +02:00
|
|
|
|
mentionAci: generateAci(),
|
2023-04-14 11:16:28 -07:00
|
|
|
|
conversationID: 'k',
|
2020-11-02 17:19:52 -08:00
|
|
|
|
replacementText: 'Kate Beaton',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <CompositionInput {...props} />;
|
2022-11-17 16:45:19 -08:00
|
|
|
|
}
|
2023-04-14 11:16:28 -07:00
|
|
|
|
|
2023-05-09 17:40:19 -07:00
|
|
|
|
export function NoFormattingMenu(): JSX.Element {
|
2023-04-14 11:16:28 -07:00
|
|
|
|
return <CompositionInput {...useProps({ isFormattingEnabled: false })} />;
|
|
|
|
|
}
|