signal-desktop/ts/components/conversation/MessageBody.stories.tsx

174 lines
4.1 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-27 00:07:26 +00:00
import * as React from 'react';
import { boolean, text } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';
import type { Props } from './MessageBody';
import { MessageBody } from './MessageBody';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
2020-08-27 00:07:26 +00:00
import enMessages from '../../../_locales/en/messages.json';
2020-09-14 19:51:27 +00:00
2020-08-27 00:07:26 +00:00
const i18n = setupI18n('en', enMessages);
const story = storiesOf('Components/Conversation/MessageBody', module);
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
2020-09-16 22:42:48 +00:00
bodyRanges: overrideProps.bodyRanges,
2020-08-27 00:07:26 +00:00
disableJumbomoji: boolean(
'disableJumbomoji',
overrideProps.disableJumbomoji || false
),
disableLinks: boolean('disableLinks', overrideProps.disableLinks || false),
2020-09-16 22:42:48 +00:00
direction: 'incoming',
2020-08-27 00:07:26 +00:00
i18n,
text: text('text', overrideProps.text || ''),
textPending: boolean('textPending', overrideProps.textPending || false),
});
story.add('Links Enabled', () => {
const props = createProps({
text: 'Check out https://www.signal.org',
});
return <MessageBody {...props} />;
});
story.add('Links Disabled', () => {
const props = createProps({
disableLinks: true,
text: 'Check out https://www.signal.org',
});
return <MessageBody {...props} />;
});
story.add('Emoji Size Based On Count', () => {
const props = createProps();
return (
<>
<MessageBody {...props} text="😹" />
<br />
<MessageBody {...props} text="😹😹😹" />
<br />
<MessageBody {...props} text="😹😹😹😹😹" />
<br />
<MessageBody {...props} text="😹😹😹😹😹😹😹" />
<br />
<MessageBody {...props} text="😹😹😹😹😹😹😹😹😹" />
</>
);
});
story.add('Jumbomoji Enabled', () => {
const props = createProps({
text: '😹',
});
return <MessageBody {...props} />;
});
story.add('Jumbomoji Disabled', () => {
const props = createProps({
disableJumbomoji: true,
text: '😹',
});
return <MessageBody {...props} />;
});
story.add('Jumbomoji Disabled by Text', () => {
const props = createProps({
text: 'not a jumbo kitty 😹',
});
return <MessageBody {...props} />;
});
story.add('Text Pending', () => {
const props = createProps({
text: 'Check out https://www.signal.org',
textPending: true,
});
return <MessageBody {...props} />;
});
2020-09-16 22:42:48 +00:00
story.add('@Mention', () => {
const props = createProps({
bodyRanges: [
{
start: 5,
length: 1,
mentionUuid: 'tuv',
replacementText: 'Bender B Rodriguez 🤖',
},
],
2021-11-11 22:43:05 +00:00
text: 'Like \uFFFC once said: My story is a lot like yours, only more interesting because it involves robots',
2020-09-16 22:42:48 +00:00
});
return <MessageBody {...props} />;
});
story.add('Multiple @Mentions', () => {
const props = createProps({
2021-03-19 20:37:06 +00:00
// These are intentionally in a mixed order to test how we deal with that
2020-09-16 22:42:48 +00:00
bodyRanges: [
{
start: 2,
length: 1,
mentionUuid: 'def',
replacementText: 'Philip J Fry',
},
2021-03-19 20:37:06 +00:00
{
start: 4,
length: 1,
mentionUuid: 'abc',
replacementText: 'Professor Farnsworth',
},
2020-09-16 22:42:48 +00:00
{
start: 0,
length: 1,
mentionUuid: 'xyz',
replacementText: 'Yancy Fry',
},
],
text: '\uFFFC \uFFFC \uFFFC',
});
return <MessageBody {...props} />;
});
story.add('Complex MessageBody', () => {
const props = createProps({
bodyRanges: [
2021-03-19 20:37:06 +00:00
// These are intentionally in a mixed order to test how we deal with that
2020-09-16 22:42:48 +00:00
{
start: 78,
length: 1,
mentionUuid: 'wer',
replacementText: 'Acid Burn',
},
2021-03-19 20:37:06 +00:00
{
start: 80,
length: 1,
mentionUuid: 'xox',
replacementText: 'Cereal Killer',
},
2020-09-16 22:42:48 +00:00
{
start: 4,
length: 1,
mentionUuid: 'ldo',
replacementText: 'Zero Cool',
},
],
direction: 'outgoing',
2021-11-11 22:43:05 +00:00
text: 'Hey \uFFFC\nCheck out https://www.signal.org I think you will really like it 😍\n\ncc \uFFFC \uFFFC',
2020-09-16 22:42:48 +00:00
});
return <MessageBody {...props} />;
});