signal-desktop/ts/components/CompositionInput.stories.tsx

131 lines
3.2 KiB
TypeScript
Raw Normal View History

2021-05-07 22:21:10 +00:00
// Copyright 2020-2021 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';
import 'react-quill/dist/quill.core.css';
2020-09-12 00:46:52 +00:00
import { boolean, select } from '@storybook/addon-knobs';
2020-08-18 17:21:53 +00:00
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
import type { Props } from './CompositionInput';
import { CompositionInput } from './CompositionInput';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-08-18 17:21:53 +00:00
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
const story = storiesOf('Components/CompositionInput', module);
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
i18n,
conversationId: 'conversation-id',
2020-08-18 17:21:53 +00:00
disabled: boolean('disabled', overrideProps.disabled || false),
onSubmit: action('onSubmit'),
onEditorStateChange: action('onEditorStateChange'),
onTextTooLong: action('onTextTooLong'),
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'),
getQuotedMessage: action('getQuotedMessage'),
onPickEmoji: action('onPickEmoji'),
large: boolean('large', overrideProps.large || false),
scrollToBottom: action('scrollToBottom'),
sortedGroupMembers: overrideProps.sortedGroupMembers || [],
2020-08-18 17:21:53 +00:00
skinTone: select(
'skinTone',
{
skinTone0: 0,
skinTone1: 1,
skinTone2: 2,
skinTone3: 3,
skinTone4: 4,
skinTone5: 5,
},
overrideProps.skinTone || undefined
),
});
story.add('Default', () => {
const props = createProps();
return <CompositionInput {...props} />;
});
story.add('Large', () => {
const props = createProps({
large: true,
});
return <CompositionInput {...props} />;
});
story.add('Disabled', () => {
const props = createProps({
disabled: true,
});
return <CompositionInput {...props} />;
});
story.add('Starting Text', () => {
const props = createProps({
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} />;
});
story.add('Multiline Text', () => {
const props = createProps({
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} />;
});
story.add('Emojis', () => {
const props = createProps({
2020-11-03 01:19:52 +00:00
draftText: `⁣😐😐😐😐😐😐😐
2020-08-18 17:21:53 +00:00
😐😐😐😐😐😐😐
😐😐😐😂😐😐😐
😐😐😐😐😐😐😐
😐😐😐😐😐😐😐`,
});
return <CompositionInput {...props} />;
});
2020-11-03 01:19:52 +00:00
story.add('Mentions', () => {
const props = createProps({
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,
mentionUuid: '0',
replacementText: 'Kate Beaton',
},
],
});
return <CompositionInput {...props} />;
});