signal-desktop/ts/components/conversationList/MessageBodyHighlight.stories.tsx

88 lines
2.3 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
2022-06-07 00:48:02 +00:00
import { text } from '@storybook/addon-knobs';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
import enMessages from '../../../_locales/en/messages.json';
import type { Props } from './MessageBodyHighlight';
import { MessageBodyHighlight } from './MessageBodyHighlight';
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/MessageBodyHighlight',
};
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
bodyRanges: overrideProps.bodyRanges || [],
i18n,
text: text('text', overrideProps.text || ''),
});
2022-06-07 00:48:02 +00:00
export const Basic = (): JSX.Element => {
const props = createProps({
text: 'This is before <<left>>Inside<<right>> This is after.',
});
return <MessageBodyHighlight {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const NoReplacement = (): JSX.Element => {
const props = createProps({
text: 'All\nplain\ntext 🔥 http://somewhere.com',
});
return <MessageBodyHighlight {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const TwoReplacements = (): JSX.Element => {
const props = createProps({
2021-11-11 22:43:05 +00:00
text: 'Begin <<left>>Inside #1<<right>> This is between the two <<left>>Inside #2<<right>> End.',
});
return <MessageBodyHighlight {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const TwoReplacementsWithAnMention = (): JSX.Element => {
const props = createProps({
bodyRanges: [
{
length: 1,
mentionUuid: '0ca40892-7b1a-11eb-9439-0242ac130002',
replacementText: 'Jin Sakai',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2021-03-19 20:37:06 +00:00
start: 33,
},
],
2021-11-11 22:43:05 +00:00
text: 'Begin <<left>>Inside #1<<right>> \uFFFC This is between the two <<left>>Inside #2<<right>> End.',
});
return <MessageBodyHighlight {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
TwoReplacementsWithAnMention.story = {
name: 'Two Replacements with an @mention',
};
export const EmojiNewlinesUrLs = (): JSX.Element => {
const props = createProps({
2021-11-11 22:43:05 +00:00
text: '\nhttp://somewhere.com\n\n🔥 Before -- <<left>>A 🔥 inside<<right>> -- After 🔥',
});
return <MessageBodyHighlight {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
EmojiNewlinesUrLs.story = {
name: 'Emoji + Newlines + URLs',
};
export const NoJumbomoji = (): JSX.Element => {
const props = createProps({
text: '🔥',
});
return <MessageBodyHighlight {...props} />;
2022-06-07 00:48:02 +00:00
};