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